exchange

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

commit 560d10148b036677f41f624def3d4c95f966e886
parent c3f8fef67e3a946edce62ef29cccd8c910ca13ac
Author: Özgür Kesim <oec@codeblau.de>
Date:   Sun, 25 Oct 2026 16:08:52 +0100

[util] one refresh commitment hash per version (#11862)

The legacy ones are named so.  libtalerutil 18:0:0, as the output of
TALER_refresh_get_commitment() changed.

Diffstat:
Mmeson.build | 2+-
Msrc/exchange/taler-exchange-httpd_post-melt.c | 33+++++++++++++++++++++------------
Msrc/exchange/taler-exchange-httpd_post-reveal-melt.c | 16++++++++--------
Msrc/include/taler/taler_crypto_lib.h | 86+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------
Msrc/util/crypto.c | 78++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
Msrc/util/test_crypto.c | 145+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 322 insertions(+), 38 deletions(-)

diff --git a/meson.build b/meson.build @@ -277,7 +277,7 @@ if not get_option('only-doc') libltversions = [ - ['libtalerutil', '18:0:4'], + ['libtalerutil', '18:0:0'], ['libtalerjson', '10:1:6'], ['libtalercurl', '1:0:1'], ['libtalerpq', '2:0:1'], diff --git a/src/exchange/taler-exchange-httpd_post-melt.c b/src/exchange/taler-exchange-httpd_post-melt.c @@ -951,18 +951,27 @@ phase_check_coin_signature ( k_transfer_pubs.batch[k] = mc->request.transfer_pubs[k]; } - TALER_refresh_get_commitment ( - &mc->request.refresh.rc, - &mc->request.refresh.refresh_seed, - mc->request.refresh.no_blinding_seed - ? NULL - : &mc->request.refresh.blinding_seed, - mc->request.refresh.is_v27_refresh - ? NULL - : &k_transfer_pubs, - &k_bps_h, - &mc->request.refresh.coin.coin_pub, - &mc->request.refresh.amount_with_fee); + if (mc->request.refresh.is_v27_refresh) + TALER_refresh_get_commitment_legacy_v27 ( + &mc->request.refresh.rc, + &mc->request.refresh.refresh_seed, + mc->request.refresh.no_blinding_seed + ? NULL + : &mc->request.refresh.blinding_seed, + &k_bps_h, + &mc->request.refresh.coin.coin_pub, + &mc->request.refresh.amount_with_fee); + else + TALER_refresh_get_commitment ( + &mc->request.refresh.rc, + &mc->request.refresh.refresh_seed, + mc->request.refresh.no_blinding_seed + ? NULL + : &mc->request.refresh.blinding_seed, + &k_transfer_pubs, + &k_bps_h, + &mc->request.refresh.coin.coin_pub, + &mc->request.refresh.amount_with_fee); } TEH_METRICS_num_verifications[TEH_MT_SIGNATURE_EDDSA]++; diff --git a/src/exchange/taler-exchange-httpd_post-reveal-melt.c b/src/exchange/taler-exchange-httpd_post-reveal-melt.c @@ -645,14 +645,14 @@ verify_commitment ( if (rf->is_v27_refresh) { - TALER_refresh_get_commitment_v27 (&rc, - &rf->refresh_seed, - rf->no_blinding_seed - ? NULL - : &rf->blinding_seed, - &kappa_planchets_h, - &rf->coin.coin_pub, - &rf->amount_with_fee); + TALER_refresh_get_commitment_legacy_v27 (&rc, + &rf->refresh_seed, + rf->no_blinding_seed + ? NULL + : &rf->blinding_seed, + &kappa_planchets_h, + &rf->coin.coin_pub, + &rf->amount_with_fee); } else { diff --git a/src/include/taler/taler_crypto_lib.h b/src/include/taler/taler_crypto_lib.h @@ -801,6 +801,7 @@ struct TALER_KappaPublicRefreshNoncesP /** * Commitment value for the refresh protocol. * See #TALER_refresh_get_commitment() and + * `enum TALER_RefreshCommitmentVersion`. */ struct TALER_RefreshCommitmentP { @@ -3042,15 +3043,44 @@ struct TALER_KappaTransferPublicKeys /** + * Versions of the refresh commitment #TALER_RefreshCommitmentP. + * The exchange records with each melt which version the client used, + * so that it can verify the commitment during the reveal. + */ +enum TALER_RefreshCommitmentVersion +{ + /** + * v27 of the refresh protocol, see + * #TALER_refresh_get_commitment_legacy_v27(). + */ + TALER_REFRESH_COMMITMENT_VERSION_LEGACY_V27 = 0, + + /** + * vDOLDPLUS before the fix: the transfer public keys were + * not included in the hash, see + * #TALER_refresh_get_commitment_legacy_vDOLDPLUS_broken(). + */ + TALER_REFRESH_COMMITMENT_VERSION_LEGACY_VDOLDPLUS_BROKEN = 1, + + /** + * Current version, see #TALER_refresh_get_commitment(). + */ + TALER_REFRESH_COMMITMENT_VERSION_CURRENT = 2 +}; + + +/** * @since vDOLDPLUS * * Compute the commitment for a /melt operation from - * the respective public inputs. + * the respective public inputs, including the transfer + * public keys (#TALER_REFRESH_COMMITMENT_VERSION_CURRENT). * * @param[out] rc set to the value the wallet must commit to * @param refresh_seed refresh master seed to include * @param blinding_seed blinding master seed for CS denominations, might be NULL * @param k_transfer_pubs TALER_CNC_KAPPA many batches of n transfer public keys, + * must not be NULL * @param k_bps_h TALER_CNC_KAPPA many hashes of blinded coin envelopes, * one for each batch of n coin candidates. * Note that these were over planchets and denominations. @@ -3067,12 +3097,43 @@ TALER_refresh_get_commitment ( const struct TALER_CoinSpendPublicKeyP *coin_pub, const struct TALER_Amount *amount_with_fee); + +/** + * @since vDOLDPLUS + * @deprecated + * + * Note: this function is only relevant for the exchange as it has to + * verify melts of clients that implemented vDOLDPLUS before the fix + * (#TALER_REFRESH_COMMITMENT_VERSION_LEGACY_VDOLDPLUS_BROKEN). + * + * Compute the commitment for a /melt operation from the respective + * public inputs, erroneously without the transfer public keys. + * + * @param[out] rc set to the value the wallet must commit to + * @param refresh_seed refresh master seed to include + * @param blinding_seed blinding master seed for CS denominations, might be NULL + * @param k_bps_h TALER_CNC_KAPPA many hashes of blinded coin envelopes, + * one for each batch of n coin candidates. + * @param coin_pub public key of the coin to be melted + * @param amount_with_fee amount to be melted, including fee + */ +void +TALER_refresh_get_commitment_legacy_vDOLDPLUS_broken ( + struct TALER_RefreshCommitmentP *rc, + const struct TALER_PublicRefreshMasterSeedP *refresh_seed, + const struct TALER_BlindingMasterSeedP *blinding_seed, + const struct TALER_KappaHashBlindedPlanchetsP *k_bps_h, + const struct TALER_CoinSpendPublicKeyP *coin_pub, + const struct TALER_Amount *amount_with_fee); + + /** * @since v27 * @deprecated vDOLDPLUS * * Note: this function is only relevant for the exchange as it has to - * support clients that still use v27 of the refresh protocol. + * support clients that still use v27 of the refresh protocol + * (#TALER_REFRESH_COMMITMENT_VERSION_LEGACY_V27). * * Compute the commitment for a /melt operation from * the respective public inputs, for refreshes of v27. @@ -3086,19 +3147,14 @@ TALER_refresh_get_commitment ( * @param coin_pub public key of the coin to be melted * @param amount_with_fee amount to be melted, including fee */ -#define TALER_refresh_get_commitment_v27(rc, \ - refresh_seed, \ - blinding_seed, \ - k_bps_h, \ - coin_pub, \ - amount_with_fee) \ - TALER_refresh_get_commitment ((rc), \ - (refresh_seed), \ - (blinding_seed), \ - NULL, \ - (k_bps_h), \ - (coin_pub), \ - (amount_with_fee)) +void +TALER_refresh_get_commitment_legacy_v27 ( + struct TALER_RefreshCommitmentP *rc, + const struct TALER_PublicRefreshMasterSeedP *refresh_seed, + const struct TALER_BlindingMasterSeedP *blinding_seed, + const struct TALER_KappaHashBlindedPlanchetsP *k_bps_h, + const struct TALER_CoinSpendPublicKeyP *coin_pub, + const struct TALER_Amount *amount_with_fee); /** diff --git a/src/util/crypto.c b/src/util/crypto.c @@ -472,8 +472,22 @@ TALER_planchet_to_coin ( } -void -TALER_refresh_get_commitment ( +/** + * Compute the commitment for a /melt operation from the respective + * public inputs. Common implementation of all versions of the + * refresh commitment, see `enum TALER_RefreshCommitmentVersion`. + * + * @param[out] rc set to the value the wallet must commit to + * @param refresh_seed refresh master seed to include + * @param blinding_seed blinding master seed for CS denominations, might be NULL + * @param k_tpbs TALER_CNC_KAPPA many batches of n transfer public keys, + * NULL for the legacy versions which did not include them + * @param k_bps_h TALER_CNC_KAPPA many hashes of blinded coin envelopes + * @param coin_pub public key of the coin to be melted + * @param amount_with_fee amount to be melted, including fee + */ +static void +refresh_get_commitment ( struct TALER_RefreshCommitmentP *rc, const struct TALER_PublicRefreshMasterSeedP *refresh_seed, const struct TALER_BlindingMasterSeedP *blinding_seed, @@ -552,6 +566,66 @@ TALER_refresh_get_commitment ( void +TALER_refresh_get_commitment ( + struct TALER_RefreshCommitmentP *rc, + const struct TALER_PublicRefreshMasterSeedP *refresh_seed, + const struct TALER_BlindingMasterSeedP *blinding_seed, + const struct TALER_KappaTransferPublicKeys *k_tpbs, + const struct TALER_KappaHashBlindedPlanchetsP *k_bps_h, + const struct TALER_CoinSpendPublicKeyP *coin_pub, + const struct TALER_Amount *amount_with_fee) +{ + GNUNET_assert (NULL != k_tpbs); + refresh_get_commitment (rc, + refresh_seed, + blinding_seed, + k_tpbs, + k_bps_h, + coin_pub, + amount_with_fee); +} + + +void +TALER_refresh_get_commitment_legacy_vDOLDPLUS_broken ( + struct TALER_RefreshCommitmentP *rc, + const struct TALER_PublicRefreshMasterSeedP *refresh_seed, + const struct TALER_BlindingMasterSeedP *blinding_seed, + const struct TALER_KappaHashBlindedPlanchetsP *k_bps_h, + const struct TALER_CoinSpendPublicKeyP *coin_pub, + const struct TALER_Amount *amount_with_fee) +{ + /* The transfer public keys were sent, but erroneously not hashed */ + refresh_get_commitment (rc, + refresh_seed, + blinding_seed, + NULL, + k_bps_h, + coin_pub, + amount_with_fee); +} + + +void +TALER_refresh_get_commitment_legacy_v27 ( + struct TALER_RefreshCommitmentP *rc, + const struct TALER_PublicRefreshMasterSeedP *refresh_seed, + const struct TALER_BlindingMasterSeedP *blinding_seed, + const struct TALER_KappaHashBlindedPlanchetsP *k_bps_h, + const struct TALER_CoinSpendPublicKeyP *coin_pub, + const struct TALER_Amount *amount_with_fee) +{ + refresh_get_commitment (rc, + refresh_seed, + blinding_seed, + NULL, + k_bps_h, + coin_pub, + amount_with_fee); +} + + +void TALER_refresh_expand_seed_to_kappa_batch_seeds ( const struct TALER_PublicRefreshMasterSeedP *refresh_master_seed, const struct TALER_CoinSpendPrivateKeyP *coin_priv, diff --git a/src/util/test_crypto.c b/src/util/test_crypto.c @@ -735,6 +735,149 @@ test_attributes (void) } +/** + * Test the versions of the refresh commitment against fixed test + * vectors. The vectors were cross-checked with an independent + * implementation (SHA-512 over the concatenated inputs). + * + * @return 0 on success + */ +static int +test_refresh_commitment (void) +{ +#define NUM_COINS 2 + struct TALER_PublicRefreshMasterSeedP refresh_seed; + struct TALER_BlindingMasterSeedP blinding_seed; + struct TALER_CoinSpendPublicKeyP coin_pub; + struct TALER_KappaHashBlindedPlanchetsP k_bps_h; + struct TALER_TransferPublicKeyP tpbs[TALER_CNC_KAPPA][NUM_COINS]; + struct TALER_KappaTransferPublicKeys k_tpbs = { + .num_transfer_pubs = NUM_COINS + }; + struct TALER_Amount amount; + struct TALER_RefreshCommitmentP rc[TALER_REFRESH_COMMITMENT_VERSION_CURRENT + + 1]; + struct TALER_RefreshCommitmentP rc_no_cs; + const char *expected[] = { + [TALER_REFRESH_COMMITMENT_VERSION_LEGACY_V27] = + "RD0FC72D4B2MDG9NJPX2G0DAYN5JBKE29WT3DZN0G4A8C1WKTA5YV0JP74VFSGZ5BEFP1G71EVSGTQT2KB96ZBF2VZWB1RJXN8V1N3R", + [TALER_REFRESH_COMMITMENT_VERSION_LEGACY_VDOLDPLUS_BROKEN] = + "RD0FC72D4B2MDG9NJPX2G0DAYN5JBKE29WT3DZN0G4A8C1WKTA5YV0JP74VFSGZ5BEFP1G71EVSGTQT2KB96ZBF2VZWB1RJXN8V1N3R", + [TALER_REFRESH_COMMITMENT_VERSION_CURRENT] = + "2QQQ8DZ896HRSX59T82JY2KXVMRPHARC2RX79491KYE3AXBJR96PSYZ2R5SRN8EBDS3AT5SW3D501CY76VBKY5J17V19079DRH61NGG", + }; + + memset (&refresh_seed, + 0x01, + sizeof (refresh_seed)); + memset (&blinding_seed, + 0x02, + sizeof (blinding_seed)); + memset (&coin_pub, + 0x03, + sizeof (coin_pub)); + for (unsigned int k = 0; k < TALER_CNC_KAPPA; k++) + { + memset (&k_bps_h.tuple[k], + 0x10 + k, + sizeof (k_bps_h.tuple[k])); + memset (tpbs[k], + 0x20 + k, + sizeof (tpbs[k])); + k_tpbs.batch[k] = tpbs[k]; + } + GNUNET_assert (GNUNET_OK == + TALER_string_to_amount ("EUR:1.5", + &amount)); + + TALER_refresh_get_commitment_legacy_v27 ( + &rc[TALER_REFRESH_COMMITMENT_VERSION_LEGACY_V27], + &refresh_seed, + &blinding_seed, + &k_bps_h, + &coin_pub, + &amount); + TALER_refresh_get_commitment_legacy_vDOLDPLUS_broken ( + &rc[TALER_REFRESH_COMMITMENT_VERSION_LEGACY_VDOLDPLUS_BROKEN], + &refresh_seed, + &blinding_seed, + &k_bps_h, + &coin_pub, + &amount); + TALER_refresh_get_commitment ( + &rc[TALER_REFRESH_COMMITMENT_VERSION_CURRENT], + &refresh_seed, + &blinding_seed, + &k_tpbs, + &k_bps_h, + &coin_pub, + &amount); + for (unsigned int v = 0; v <= TALER_REFRESH_COMMITMENT_VERSION_CURRENT; v++) + { + struct TALER_RefreshCommitmentP rc_exp; + + if (GNUNET_OK != + GNUNET_STRINGS_string_to_data (expected[v], + strlen (expected[v]), + &rc_exp, + sizeof (rc_exp))) + { + GNUNET_break (0); + fprintf (stderr, + "version %u: %s\n", + v, + GNUNET_h2s_full (&rc[v].session_hash)); + return 1; + } + if (0 != GNUNET_memcmp (&rc_exp, + &rc[v])) + { + GNUNET_break (0); + fprintf (stderr, + "version %u: %s\n", + v, + GNUNET_h2s_full (&rc[v].session_hash)); + return 1; + } + } + /* The legacy versions only differ in the reveal, not in the hash */ + if (0 != GNUNET_memcmp (&rc[TALER_REFRESH_COMMITMENT_VERSION_LEGACY_V27], + &rc[ + TALER_REFRESH_COMMITMENT_VERSION_LEGACY_VDOLDPLUS_BROKEN + ])) + { + GNUNET_break (0); + return 1; + } + /* Without CS denominations, an all-zero blinding seed is hashed */ + memset (&blinding_seed, + 0, + sizeof (blinding_seed)); + TALER_refresh_get_commitment (&rc_no_cs, + &refresh_seed, + NULL, + &k_tpbs, + &k_bps_h, + &coin_pub, + &amount); + TALER_refresh_get_commitment (&rc[TALER_REFRESH_COMMITMENT_VERSION_CURRENT], + &refresh_seed, + &blinding_seed, + &k_tpbs, + &k_bps_h, + &coin_pub, + &amount); + if (0 != GNUNET_memcmp (&rc_no_cs, + &rc[TALER_REFRESH_COMMITMENT_VERSION_CURRENT])) + { + GNUNET_break (0); + return 1; + } + return 0; +#undef NUM_COINS +} + + int main (int argc, const char *const argv[]) @@ -760,6 +903,8 @@ main (int argc, return 6; if (0 != test_attributes ()) return 7; + if (0 != test_refresh_commitment ()) + return 8; return 0; }