-clean up of crypto.c

This commit is contained in:
Christian Grothoff 2022-02-07 11:33:58 +01:00
parent d850ed9ca1
commit 0d03f55282
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC

View File

@ -1,6 +1,6 @@
/* /*
This file is part of TALER This file is part of TALER
Copyright (C) 2014-2017 Taler Systems SA Copyright (C) 2014-2022 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software terms of the GNU General Public License as published by the Free Software
@ -116,7 +116,6 @@ TALER_link_derive_transfer_secret (
GNUNET_CRYPTO_ecdh_eddsa (&trans_priv->ecdhe_priv, GNUNET_CRYPTO_ecdh_eddsa (&trans_priv->ecdhe_priv,
&coin_pub.eddsa_pub, &coin_pub.eddsa_pub,
&ts->key)); &ts->key));
} }
@ -177,29 +176,6 @@ TALER_planchet_setup_refresh (const struct TALER_TransferSecretP *secret_seed,
} }
// FIXME: bad name!
void
cs_blinding_seed_derive (
const struct TALER_PlanchetSecretsP *ps,
const struct GNUNET_CRYPTO_CsRPublic r_pub[2],
struct GNUNET_CRYPTO_CsNonce *blind_seed)
{
GNUNET_assert (GNUNET_YES ==
GNUNET_CRYPTO_hkdf (blind_seed,
sizeof (*blind_seed),
GCRY_MD_SHA512,
GCRY_MD_SHA256,
"bseed",
strlen ("bseed"),
ps,
sizeof(*ps),
r_pub,
sizeof(struct GNUNET_CRYPTO_CsRPublic) * 2,
NULL,
0));
}
void void
TALER_cs_withdraw_nonce_derive ( TALER_cs_withdraw_nonce_derive (
const struct TALER_PlanchetSecretsP *ps, const struct TALER_PlanchetSecretsP *ps,
@ -252,24 +228,28 @@ TALER_planchet_blinding_secret_create (
return; return;
case TALER_DENOMINATION_RSA: case TALER_DENOMINATION_RSA:
GNUNET_assert (GNUNET_YES == GNUNET_assert (GNUNET_YES ==
GNUNET_CRYPTO_hkdf (&bks->rsa_bks, GNUNET_CRYPTO_kdf (&bks->rsa_bks,
sizeof (bks->rsa_bks), sizeof (bks->rsa_bks),
GCRY_MD_SHA512, "bks",
GCRY_MD_SHA256, strlen ("bks"),
"bks", ps,
strlen ("bks"), sizeof(*ps),
ps, NULL,
sizeof(*ps), 0));
NULL,
0));
return; return;
case TALER_DENOMINATION_CS: case TALER_DENOMINATION_CS:
{ GNUNET_assert (GNUNET_YES ==
cs_blinding_seed_derive (ps, GNUNET_CRYPTO_kdf (&bks->nonce,
alg_values->details.cs_values.r_pub.r_pub, sizeof (bks->nonce),
&bks->nonce); "bseed",
return; strlen ("bseed"),
} ps,
sizeof(*ps),
&alg_values->details.cs_values,
sizeof(alg_values->details.cs_values),
NULL,
0));
return;
default: default:
GNUNET_break (0); GNUNET_break (0);
} }
@ -285,37 +265,29 @@ TALER_planchet_setup_coin_priv (
switch (alg_values->cipher) switch (alg_values->cipher)
{ {
case TALER_DENOMINATION_RSA: case TALER_DENOMINATION_RSA:
{ GNUNET_assert (GNUNET_YES ==
GNUNET_assert (GNUNET_YES == GNUNET_CRYPTO_kdf (coin_priv,
GNUNET_CRYPTO_hkdf (coin_priv, sizeof (*coin_priv),
sizeof (*coin_priv), "coin",
GCRY_MD_SHA512, strlen ("coin"),
GCRY_MD_SHA256, ps,
"coin", sizeof(*ps),
strlen ("coin"), NULL,
ps, 0));
sizeof(*ps), break;
NULL,
0));
break;
}
case TALER_DENOMINATION_CS: case TALER_DENOMINATION_CS:
{ GNUNET_assert (GNUNET_YES ==
GNUNET_assert (GNUNET_YES == GNUNET_CRYPTO_kdf (coin_priv,
GNUNET_CRYPTO_hkdf (coin_priv, sizeof (*coin_priv),
sizeof (*coin_priv), "coin",
GCRY_MD_SHA512, strlen ("coin"),
GCRY_MD_SHA256, ps,
"coin", sizeof(*ps),
strlen ("coin"), &alg_values->details, /* Could be null on RSA case*/
ps, sizeof(alg_values->details),
sizeof(*ps), NULL,
&alg_values->details, /* Could be null on RSA case*/ 0));
sizeof(alg_values->details), break;
NULL,
0));
break;
}
default: default:
GNUNET_break (0); GNUNET_break (0);
return; return;
@ -400,7 +372,7 @@ TALER_blinded_planchet_free (struct TALER_BlindedPlanchet *blinded_planchet)
GNUNET_free (blinded_planchet->details.rsa_blinded_planchet.blinded_msg); GNUNET_free (blinded_planchet->details.rsa_blinded_planchet.blinded_msg);
break; break;
case TALER_DENOMINATION_CS: case TALER_DENOMINATION_CS:
// nothing to do for CS /* nothing to do for CS */
break; break;
default: default:
GNUNET_break (0); GNUNET_break (0);
@ -565,47 +537,34 @@ TALER_coin_ev_hash (const struct TALER_BlindedPlanchet *blinded_planchet,
const struct TALER_DenominationHash *denom_hash, const struct TALER_DenominationHash *denom_hash,
struct TALER_BlindedCoinHash *bch) struct TALER_BlindedCoinHash *bch)
{ {
struct GNUNET_HashContext *hash_context;
hash_context = GNUNET_CRYPTO_hash_context_start ();
GNUNET_CRYPTO_hash_context_read (hash_context,
denom_hash,
sizeof(*denom_hash));
switch (blinded_planchet->cipher) switch (blinded_planchet->cipher)
{ {
case TALER_DENOMINATION_RSA: case TALER_DENOMINATION_RSA:
{ GNUNET_CRYPTO_hash_context_read (
struct GNUNET_HashContext *hash_context; hash_context,
hash_context = GNUNET_CRYPTO_hash_context_start (); blinded_planchet->details.rsa_blinded_planchet.blinded_msg,
blinded_planchet->details.rsa_blinded_planchet.blinded_msg_size);
// // FIXME: Include denom_pub into hash break;
// GNUNET_CRYPTO_hash_context_read (hash_context,
// &denom_hash->hash,
// sizeof(denom_hash->hash));
GNUNET_CRYPTO_hash_context_read (hash_context,
blinded_planchet->details.
rsa_blinded_planchet.blinded_msg,
blinded_planchet->details.
rsa_blinded_planchet.blinded_msg_size);
GNUNET_CRYPTO_hash_context_finish (hash_context,
&bch->hash);
return GNUNET_OK;
}
case TALER_DENOMINATION_CS: case TALER_DENOMINATION_CS:
{ GNUNET_CRYPTO_hash_context_read (
struct GNUNET_HashContext *hash_context; hash_context,
hash_context = GNUNET_CRYPTO_hash_context_start (); &blinded_planchet->details.cs_blinded_planchet.nonce,
sizeof (blinded_planchet->details.cs_blinded_planchet.nonce));
GNUNET_CRYPTO_hash_context_read (hash_context, break;
&denom_hash->hash,
sizeof(denom_hash->hash));
GNUNET_CRYPTO_hash_context_read (hash_context,
&blinded_planchet->details.
cs_blinded_planchet.nonce,
sizeof (blinded_planchet->details.
cs_blinded_planchet.nonce));
GNUNET_CRYPTO_hash_context_finish (hash_context,
&bch->hash);
return GNUNET_OK;
}
default: default:
GNUNET_break (0); GNUNET_break (0);
GNUNET_CRYPTO_hash_context_abort (hash_context);
return GNUNET_SYSERR; return GNUNET_SYSERR;
} }
GNUNET_CRYPTO_hash_context_finish (hash_context,
&bch->hash);
return GNUNET_OK;
} }
@ -632,11 +591,9 @@ TALER_coin_pub_hash (const struct TALER_CoinSpendPublicKeyP *coin_pub,
GNUNET_memcpy (&data[0], GNUNET_memcpy (&data[0],
&coin_pub->eddsa_pub, &coin_pub->eddsa_pub,
key_s); key_s);
GNUNET_memcpy (&data[key_s], GNUNET_memcpy (&data[key_s],
age_commitment_hash, age_commitment_hash,
age_s); age_s);
GNUNET_CRYPTO_hash (&data, GNUNET_CRYPTO_hash (&data,
key_s + age_s, key_s + age_s,
&coin_h->hash); &coin_h->hash);