exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

commit 66c7ef82491070d40275ed1ab787be0a3151d31a
parent 19040e4288e9909c648350f8a2defdb626048313
Author: Özgür Kesim <oec@codeblau.de>
Date:   Mon, 12 Oct 2026 12:48:39 +0200

[util/crypto] fix refresh commitment hash: add transfer public keys to hash

Diffstat:
Msrc/util/crypto.c | 164++++++++++++++++++++++++++++++++++++++++++++-----------------------------------
1 file changed, 91 insertions(+), 73 deletions(-)

diff --git a/src/util/crypto.c b/src/util/crypto.c @@ -70,8 +70,9 @@ TALER_gcrypt_init () enum GNUNET_GenericReturnValue -TALER_test_coin_valid (const struct TALER_CoinPublicInfo *coin_public_info, - const struct TALER_DenominationPublicKey *denom_pub) +TALER_test_coin_valid ( + const struct TALER_CoinPublicInfo *coin_public_info, + const struct TALER_DenominationPublicKey *denom_pub) { struct TALER_CoinPubHashP c_hash; #if ENABLE_SANITY_CHECKS @@ -86,8 +87,8 @@ TALER_test_coin_valid (const struct TALER_CoinPublicInfo *coin_public_info, TALER_coin_pub_hash (&coin_public_info->coin_pub, coin_public_info->no_age_commitment - ? NULL - : &coin_public_info->h_age_commitment, + ? NULL + : &coin_public_info->h_age_commitment, &c_hash); if (GNUNET_OK != @@ -152,14 +153,14 @@ TALER_withdraw_expand_secrets ( const struct TALER_WithdrawMasterSeedP *seed, struct TALER_PlanchetMasterSecretP secrets[static num_coins]) { - _Static_assert (sizeof(seed->seed_data) == sizeof(secrets->key_data)); + _Static_assert (sizeof (seed->seed_data) == sizeof (secrets->key_data)); GNUNET_assert (0 < num_coins); if (1 == num_coins) { GNUNET_memcpy (&secrets[0].key_data, &seed->seed_data, - sizeof(secrets[0].key_data)); + sizeof (secrets[0].key_data)); } else { @@ -256,7 +257,7 @@ TALER_cs_withdraw_seed_to_blinding_seed ( "withdraw-blinding", strlen ("withdraw-blinding"), seed, - sizeof(*seed))); + sizeof (*seed))); } @@ -349,31 +350,31 @@ TALER_cs_derive_blind_nonces_from_seed ( for (size_t i = 0; i < num; i++) { if (is_cs[i]) - TALER_cs_nonce_derive_indexed ( - seed, - for_melt, - i, - &nonces[i].cs_nonce); + TALER_cs_nonce_derive_indexed (seed, + for_melt, + i, + &nonces[i].cs_nonce); } } void -TALER_rsa_pub_hash (const struct GNUNET_CRYPTO_RsaPublicKey *rsa, - struct TALER_RsaPubHashP *h_rsa) +TALER_rsa_pub_hash ( + const struct GNUNET_CRYPTO_RsaPublicKey *rsa, + struct TALER_RsaPubHashP *h_rsa) { GNUNET_CRYPTO_rsa_public_key_hash (rsa, &h_rsa->hash); - } void -TALER_cs_pub_hash (const struct GNUNET_CRYPTO_CsPublicKey *cs, - struct TALER_CsPubHashP *h_cs) +TALER_cs_pub_hash ( + const struct GNUNET_CRYPTO_CsPublicKey *cs, + struct TALER_CsPubHashP *h_cs) { GNUNET_CRYPTO_hash (cs, - sizeof(*cs), + sizeof (*cs), &h_cs->hash); } @@ -471,7 +472,6 @@ TALER_planchet_to_coin ( } -// FIXME-Oec: k_tpbs is dead in the code below! void TALER_refresh_get_commitment ( struct TALER_RefreshCommitmentP *rc, @@ -484,14 +484,30 @@ TALER_refresh_get_commitment ( { struct GNUNET_HashContext *hash_context; + /** + * We follow + * https://docs.taler.net/core/api-common.html#taler-refreshcommitmentp + */ + hash_context = GNUNET_CRYPTO_hash_context_start (); /* First, the refresh master seed (from which the nonces, then signatures and finally private keys of the fresh coins are derived from) */ GNUNET_assert (NULL != refresh_seed); - GNUNET_CRYPTO_hash_context_read (hash_context, - refresh_seed, - sizeof (*refresh_seed)); + GNUNET_CRYPTO_hash_context_read ( + hash_context, + refresh_seed, + sizeof (*refresh_seed)); + + /* Then, we add the transfer public keys */ + if (NULL != k_tpbs) + { + for (unsigned int k = 0; k < TALER_CNC_KAPPA; k++) + GNUNET_CRYPTO_hash_context_read ( + hash_context, + k_tpbs->batch[k], + sizeof (struct TALER_TransferPublicKeyP) * k_tpbs->num_transfer_pubs); + } /* Then, in case of CS denominations, the blinding_seed from which all nonces are derived from, and therefore public R-values */ @@ -501,9 +517,11 @@ TALER_refresh_get_commitment ( if (NULL != blinding_seed) pbms = blinding_seed; - GNUNET_CRYPTO_hash_context_read (hash_context, - pbms, - sizeof(*pbms)); + + GNUNET_CRYPTO_hash_context_read ( + hash_context, + pbms, + sizeof (*pbms)); } /* Next, add public key of coin and amount being refreshed */ @@ -522,10 +540,10 @@ TALER_refresh_get_commitment ( /* Finally, add all the hashes of the blinded coins * (containing information about denominations), depths first */ - for (unsigned int k = 0; k<TALER_CNC_KAPPA; k++) + for (unsigned int k = 0; k < TALER_CNC_KAPPA; k++) GNUNET_CRYPTO_hash_context_read (hash_context, &k_bps_h->tuple[k], - sizeof(k_bps_h->tuple[k])); + sizeof (k_bps_h->tuple[k])); /* Conclude */ GNUNET_CRYPTO_hash_context_finish (hash_context, @@ -583,12 +601,10 @@ TALER_refresh_expand_batch_seed_to_transfer_secrets ( transfer_pks); for (size_t i = 0; i < num_transfer_secrets; i++) - { TALER_link_reveal_transfer_secret ( &transfer_pks[i], coin_pub, &transfer_secrets[i]); - } } @@ -644,12 +660,10 @@ TALER_refresh_expand_batch_seed_to_transfer_data ( &transfer_pks[i], coin_pub, &transfer_secrets[i]); - TALER_transfer_secret_to_planchet_secret ( &transfer_secrets[i], i, &planchet_secrets[i]); - GNUNET_CRYPTO_ecdhe_key_get_public ( &transfer_pks[i].ecdhe_priv, &transfer_pubs[i].ecdhe_pub); @@ -686,40 +700,39 @@ TALER_refresh_signature_to_secrets_v27 ( "refresh-planchet-secret", strlen ("refresh-planchet-secret"), sig, - sizeof(*sig))); + sizeof (*sig))); } void -TALER_coin_pub_hash (const struct TALER_CoinSpendPublicKeyP *coin_pub, - const struct TALER_AgeCommitmentHashP *ach, - struct TALER_CoinPubHashP *coin_h) +TALER_coin_pub_hash ( + const struct TALER_CoinSpendPublicKeyP *coin_pub, + const struct TALER_AgeCommitmentHashP *ach, + struct TALER_CoinPubHashP *coin_h) { if (TALER_AgeCommitmentHashP_isNullOrZero (ach)) { /* No age commitment was set */ - GNUNET_CRYPTO_hash (&coin_pub->eddsa_pub, - sizeof (coin_pub->eddsa_pub), - &coin_h->hash); + GNUNET_CRYPTO_hash ( + &coin_pub->eddsa_pub, + sizeof (coin_pub->eddsa_pub), + &coin_h->hash); } else { - /* Coin comes with age commitment. Take the hash of the age commitment - * into account */ + /* Coin comes with age commitment. + * Take the hash of the age commitment into account. */ struct GNUNET_HashContext *hash_context; hash_context = GNUNET_CRYPTO_hash_context_start (); - GNUNET_CRYPTO_hash_context_read ( hash_context, &coin_pub->eddsa_pub, - sizeof(coin_pub->eddsa_pub)); - + sizeof (coin_pub->eddsa_pub)); GNUNET_CRYPTO_hash_context_read ( hash_context, ach, - sizeof(struct TALER_AgeCommitmentHashP)); - + sizeof (struct TALER_AgeCommitmentHashP)); GNUNET_CRYPTO_hash_context_finish ( hash_context, &coin_h->hash); @@ -728,20 +741,24 @@ TALER_coin_pub_hash (const struct TALER_CoinSpendPublicKeyP *coin_pub, void -TALER_coin_ev_hash (const struct TALER_BlindedPlanchet *blinded_planchet, - const struct TALER_DenominationHashP *denom_hash, - struct TALER_BlindedCoinHashP *bch) +TALER_coin_ev_hash ( + const struct TALER_BlindedPlanchet *blinded_planchet, + const struct TALER_DenominationHashP *denom_hash, + struct TALER_BlindedCoinHashP *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)); - TALER_blinded_planchet_hash_ (blinded_planchet, - hash_context); - GNUNET_CRYPTO_hash_context_finish (hash_context, - &bch->hash); + GNUNET_CRYPTO_hash_context_read ( + hash_context, + denom_hash, + sizeof (*denom_hash)); + TALER_blinded_planchet_hash_ ( + blinded_planchet, + hash_context); + GNUNET_CRYPTO_hash_context_finish ( + hash_context, + &bch->hash); } @@ -774,7 +791,6 @@ struct DenominationGroupP }; GNUNET_NETWORK_STRUCT_END - void TALER_denomination_group_get_key ( const struct TALER_DenominationGroup *dg, @@ -785,13 +801,16 @@ TALER_denomination_group_get_key ( .cipher = htonl (dg->cipher) }; - TALER_amount_hton (&dgp.value, - &dg->value); - TALER_denom_fee_set_hton (&dgp.fees, - &dg->fees); - GNUNET_CRYPTO_hash (&dgp, - sizeof (dgp), - key); + TALER_amount_hton ( + &dgp.value, + &dg->value); + TALER_denom_fee_set_hton ( + &dgp.fees, + &dg->fees); + GNUNET_CRYPTO_hash ( + &dgp, + sizeof (dgp), + key); } @@ -805,16 +824,15 @@ TALER_kyc_measure_authorization_hash ( uint64_t be64 = GNUNET_htonll (row); uint32_t be32 = htonl ((uint32_t) offset); - GNUNET_assert ( - GNUNET_YES == - GNUNET_CRYPTO_hkdf_gnunet ( - mah, - sizeof (*mah), - &be64, - sizeof (be64), - access_token, - sizeof (*access_token), - GNUNET_CRYPTO_kdf_arg_auto (&be32))); + GNUNET_assert (GNUNET_YES == + GNUNET_CRYPTO_hkdf_gnunet ( + mah, + sizeof (*mah), + &be64, + sizeof (be64), + access_token, + sizeof (*access_token), + GNUNET_CRYPTO_kdf_arg_auto (&be32))); }