diff options
author | Christian Grothoff <christian@grothoff.org> | 2022-11-14 06:19:35 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2022-11-14 06:19:35 +0100 |
commit | 8bfc6583e799d8f7d0e55262b593183daed7f4fe (patch) | |
tree | 40226cdf86d5ceee7978c846250555d6eaa7b327 /src/exchange | |
parent | 053faa252c2afed8ecbb65bdd6fe8ec6f9ad9ef9 (diff) |
more refactoring towards #7272
Diffstat (limited to 'src/exchange')
-rw-r--r-- | src/exchange/taler-exchange-httpd_batch-withdraw.c | 3 | ||||
-rw-r--r-- | src/exchange/taler-exchange-httpd_csr.c | 23 | ||||
-rw-r--r-- | src/exchange/taler-exchange-httpd_keys.c | 246 | ||||
-rw-r--r-- | src/exchange/taler-exchange-httpd_keys.h | 80 | ||||
-rw-r--r-- | src/exchange/taler-exchange-httpd_refreshes_reveal.c | 15 | ||||
-rw-r--r-- | src/exchange/taler-exchange-httpd_withdraw.c | 3 |
6 files changed, 204 insertions, 166 deletions
diff --git a/src/exchange/taler-exchange-httpd_batch-withdraw.c b/src/exchange/taler-exchange-httpd_batch-withdraw.c index 7352edfd..de1b67e5 100644 --- a/src/exchange/taler-exchange-httpd_batch-withdraw.c +++ b/src/exchange/taler-exchange-httpd_batch-withdraw.c @@ -427,8 +427,9 @@ prepare_transaction (const struct TEH_RequestContext *rc, .bp = &pc->blinded_planchet }; - ec = TEH_keys_denomination_sign_withdraw ( + ec = TEH_keys_denomination_sign ( &csds, + false, &pc->collectable.sig); if (TALER_EC_NONE != ec) { diff --git a/src/exchange/taler-exchange-httpd_csr.c b/src/exchange/taler-exchange-httpd_csr.c index 14d82ef1..7e9e7a58 100644 --- a/src/exchange/taler-exchange-httpd_csr.c +++ b/src/exchange/taler-exchange-httpd_csr.c @@ -179,9 +179,16 @@ TEH_handler_csr_melt (struct TEH_RequestContext *rc, /* derive r_pub */ // FIXME-#7272: bundle all requests into one derivation request (TEH_keys_..., crypto helper, security module) - ec = TEH_keys_denomination_cs_r_pub_melt (denom_pub_hash, - nonce, - r_pub); + { + const struct TEH_CsDeriveData cdd = { + .h_denom_pub = denom_pub_hash, + .nonce = nonce + }; + + ec = TEH_keys_denomination_cs_r_pub (&cdd, + true, + r_pub); + } if (TALER_EC_NONE != ec) { GNUNET_break (0); @@ -315,10 +322,14 @@ TEH_handler_csr_withdraw (struct TEH_RequestContext *rc, /* derive r_pub */ { enum TALER_ErrorCode ec; + const struct TEH_CsDeriveData cdd = { + .h_denom_pub = &denom_pub_hash, + .nonce = &nonce + }; - ec = TEH_keys_denomination_cs_r_pub_withdraw (&denom_pub_hash, - &nonce, - &ewv.details.cs_values); + ec = TEH_keys_denomination_cs_r_pub (&cdd, + false, + &ewv.details.cs_values); if (TALER_EC_NONE != ec) { GNUNET_break (0); diff --git a/src/exchange/taler-exchange-httpd_keys.c b/src/exchange/taler-exchange-httpd_keys.c index d430946c..edfe50e5 100644 --- a/src/exchange/taler-exchange-httpd_keys.c +++ b/src/exchange/taler-exchange-httpd_keys.c @@ -2746,8 +2746,9 @@ TEH_keys_denomination_by_hash2 ( enum TALER_ErrorCode -TEH_keys_denomination_sign_withdraw ( +TEH_keys_denomination_sign ( const struct TEH_CoinSignData *csd, + bool for_melt, struct TALER_BlindedDenominationSignature *bs) { struct TEH_KeyStateHandle *ksh; @@ -2787,9 +2788,10 @@ TEH_keys_denomination_sign_withdraw ( csr.h_cs = &hd->h_details.h_cs; csr.blinded_planchet = &bp->details.cs_blinded_planchet; - return TALER_CRYPTO_helper_cs_sign_withdraw ( + return TALER_CRYPTO_helper_cs_sign ( ksh->helpers->csdh, &csr, + for_melt, bs); } default: @@ -2799,118 +2801,135 @@ TEH_keys_denomination_sign_withdraw ( enum TALER_ErrorCode -TEH_keys_denomination_batch_sign_withdraw ( +TEH_keys_denomination_batch_sign ( const struct TEH_CoinSignData *csds, unsigned int csds_length, + bool for_melt, struct TALER_BlindedDenominationSignature *bss) { struct TEH_KeyStateHandle *ksh; struct HelperDenomination *hd; -#if 0 + struct TALER_CRYPTO_RsaSignRequest rsrs[csds_length]; + struct TALER_CRYPTO_CsSignRequest csrs[csds_length]; + struct TALER_BlindedDenominationSignature rs[csds_length]; + struct TALER_BlindedDenominationSignature cs[csds_length]; + unsigned int rsrs_pos = 0; + unsigned int csrs_pos = 0; + enum TALER_ErrorCode ec; ksh = TEH_keys_get_state (); if (NULL == ksh) return TALER_EC_EXCHANGE_GENERIC_KEYS_MISSING; - hd = GNUNET_CONTAINER_multihashmap_get (ksh->helpers->denom_keys, - &h_denom_pub->hash); - if (NULL == hd) - return TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN; - if (bp->cipher != hd->denom_pub.cipher) - return TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE; - switch (hd->denom_pub.cipher) - { - case TALER_DENOMINATION_RSA: - TEH_METRICS_num_signatures[TEH_MT_SIGNATURE_RSA]++; + for (unsigned int i = 0; i<csds_length; i++) + { + const struct TALER_DenominationHashP *h_denom_pub = csds[i].h_denom_pub; + const struct TALER_BlindedPlanchet *bp = csds[i].bp; + + hd = GNUNET_CONTAINER_multihashmap_get (ksh->helpers->denom_keys, + &h_denom_pub->hash); + if (NULL == hd) + return TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN; + if (bp->cipher != hd->denom_pub.cipher) + return TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE; + switch (hd->denom_pub.cipher) { - struct TALER_CRYPTO_RsaSignRequest rsr = { - .h_rsa = &hd->h_details.h_rsa, - .msg = bp->details.rsa_blinded_planchet.blinded_msg, - .msg_size = bp->details.rsa_blinded_planchet.blinded_msg_size - }; - - return TALER_CRYPTO_helper_rsa_sign ( - ksh->helpers->rsadh, - &rsr, - bs); + case TALER_DENOMINATION_RSA: + rsrs[rsrs_pos].h_rsa = &hd->h_details.h_rsa; + rsrs[rsrs_pos].msg + = bp->details.rsa_blinded_planchet.blinded_msg; + rsrs[rsrs_pos].msg_size + = bp->details.rsa_blinded_planchet.blinded_msg_size; + rsrs_pos++; + break; + case TALER_DENOMINATION_CS: + csrs[csrs_pos].h_cs = &hd->h_details.h_cs; + csrs[csrs_pos].blinded_planchet = &bp->details.cs_blinded_planchet; + csrs_pos++; + break; + default: + return TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE; } - case TALER_DENOMINATION_CS: - TEH_METRICS_num_signatures[TEH_MT_SIGNATURE_CS]++; - { - struct TALER_CRYPTO_CsSignRequest csr; + } - csr.h_cs = &hd->h_details.h_cs; - csr.blinded_planchet = &bp->details.cs_blinded_planchet; - return TALER_CRYPTO_helper_cs_sign_withdraw ( - ksh->helpers->csdh, - &csr, - bs); + if ( (0 != csrs_pos) && + (0 != rsrs_pos) ) + { + memset (rs, + 0, + sizeof (rs)); + memset (cs, + 0, + sizeof (cs)); + } + ec = TALER_EC_NONE; + if (0 != csrs_pos) + { + ec = TALER_CRYPTO_helper_cs_batch_sign ( + ksh->helpers->csdh, + csrs, + csrs_pos, + for_melt, + (0 == rsrs_pos) ? bss : cs); + if (TALER_EC_NONE != ec) + { + for (unsigned int i = 0; i<csrs_pos; i++) + TALER_blinded_denom_sig_free (&cs[i]); + return ec; } - default: - return TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE; + TEH_METRICS_num_signatures[TEH_MT_SIGNATURE_CS] += csrs_pos; } -#endif -} - - -enum TALER_ErrorCode -TEH_keys_denomination_sign_melt ( - const struct TEH_CoinSignData *csd, - struct TALER_BlindedDenominationSignature *bs) -{ - const struct TALER_DenominationHashP *h_denom_pub = csd->h_denom_pub; - const struct TALER_BlindedPlanchet *bp = csd->bp; - struct TEH_KeyStateHandle *ksh; - struct HelperDenomination *hd; - - ksh = TEH_keys_get_state (); - if (NULL == ksh) - return TALER_EC_EXCHANGE_GENERIC_KEYS_MISSING; - hd = GNUNET_CONTAINER_multihashmap_get (ksh->helpers->denom_keys, - &h_denom_pub->hash); - if (NULL == hd) - return TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN; - if (bp->cipher != hd->denom_pub.cipher) - return TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE; - switch (hd->denom_pub.cipher) + if (0 != rsrs_pos) { - case TALER_DENOMINATION_RSA: - TEH_METRICS_num_signatures[TEH_MT_SIGNATURE_RSA]++; + ec = TALER_CRYPTO_helper_rsa_batch_sign ( + ksh->helpers->rsadh, + rsrs, + rsrs_pos, + (0 == csrs_pos) ? bss : rs); + if (TALER_EC_NONE != ec) { - struct TALER_CRYPTO_RsaSignRequest rsr = { - .h_rsa = &hd->h_details.h_rsa, - .msg = bp->details.rsa_blinded_planchet.blinded_msg, - .msg_size = bp->details.rsa_blinded_planchet.blinded_msg_size - }; - - return TALER_CRYPTO_helper_rsa_sign ( - ksh->helpers->rsadh, - &rsr, - bs); + for (unsigned int i = 0; i<csrs_pos; i++) + TALER_blinded_denom_sig_free (&cs[i]); + for (unsigned int i = 0; i<rsrs_pos; i++) + TALER_blinded_denom_sig_free (&rs[i]); + return ec; } - case TALER_DENOMINATION_CS: + TEH_METRICS_num_signatures[TEH_MT_SIGNATURE_RSA] += rsrs_pos; + } + + if ( (0 != csrs_pos) && + (0 != rsrs_pos) ) + { + rsrs_pos = 0; + csrs_pos = 0; + for (unsigned int i = 0; i<csds_length; i++) { - struct TALER_CRYPTO_CsSignRequest csr; + const struct TALER_BlindedPlanchet *bp = csds[i].bp; - csr.h_cs = &hd->h_details.h_cs; - csr.blinded_planchet = &bp->details.cs_blinded_planchet; - TEH_METRICS_num_signatures[TEH_MT_SIGNATURE_CS]++; - return TALER_CRYPTO_helper_cs_sign_melt ( - ksh->helpers->csdh, - &csr, - bs); + switch (bp->cipher) + { + case TALER_DENOMINATION_RSA: + bss[i] = rs[rsrs_pos++]; + break; + case TALER_DENOMINATION_CS: + bss[i] = cs[csrs_pos++]; + break; + default: + GNUNET_assert (0); + } } - default: - return TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE; } + return TALER_EC_NONE; } enum TALER_ErrorCode -TEH_keys_denomination_cs_r_pub_melt ( - const struct TALER_DenominationHashP *h_denom_pub, - const struct TALER_CsNonce *nonce, +TEH_keys_denomination_cs_r_pub ( + const struct TEH_CsDeriveData *cdd, + bool for_melt, struct TALER_DenominationCSPublicRPairP *r_pub) { + const struct TALER_DenominationHashP *h_denom_pub = cdd->h_denom_pub; + const struct TALER_CsNonce *nonce = cdd->nonce; struct TEH_KeyStateHandle *ksh; struct HelperDenomination *hd; @@ -2935,47 +2954,54 @@ TEH_keys_denomination_cs_r_pub_melt ( .h_cs = &hd->h_details.h_cs, .nonce = nonce }; - return TALER_CRYPTO_helper_cs_r_derive_melt (ksh->helpers->csdh, - &cdr, - r_pub); + return TALER_CRYPTO_helper_cs_r_derive (ksh->helpers->csdh, + &cdr, + for_melt, + r_pub); } } enum TALER_ErrorCode -TEH_keys_denomination_cs_r_pub_withdraw ( - const struct TALER_DenominationHashP *h_denom_pub, - const struct TALER_CsNonce *nonce, - struct TALER_DenominationCSPublicRPairP *r_pub) +TEH_keys_denomination_cs_batch_r_pub ( + const struct TEH_CsDeriveData *cdds, + unsigned int cdds_length, + bool for_melt, + struct TALER_DenominationCSPublicRPairP *r_pubs) { struct TEH_KeyStateHandle *ksh; struct HelperDenomination *hd; + struct TALER_CRYPTO_CsDeriveRequest cdrs[cdds_length]; ksh = TEH_keys_get_state (); if (NULL == ksh) { return TALER_EC_EXCHANGE_GENERIC_KEYS_MISSING; } - hd = GNUNET_CONTAINER_multihashmap_get (ksh->helpers->denom_keys, - &h_denom_pub->hash); - if (NULL == hd) + for (unsigned int i = 0; i<cdds_length; i++) { - return TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN; - } - if (TALER_DENOMINATION_CS != hd->denom_pub.cipher) - { - return TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE; - } - { - struct TALER_CRYPTO_CsDeriveRequest cdr = { - .h_cs = &hd->h_details.h_cs, - .nonce = nonce - }; + const struct TALER_DenominationHashP *h_denom_pub = cdds[i].h_denom_pub; + const struct TALER_CsNonce *nonce = cdds[i].nonce; - return TALER_CRYPTO_helper_cs_r_derive_withdraw (ksh->helpers->csdh, - &cdr, - r_pub); + hd = GNUNET_CONTAINER_multihashmap_get (ksh->helpers->denom_keys, + &h_denom_pub->hash); + if (NULL == hd) + { + return TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN; + } + if (TALER_DENOMINATION_CS != hd->denom_pub.cipher) + { + return TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE; + } + cdrs[i].h_cs = &hd->h_details.h_cs; + cdrs[i].nonce = nonce; } + + return TALER_CRYPTO_helper_cs_r_batch_derive (ksh->helpers->csdh, + cdrs, + cdds_length, + for_melt, + r_pubs); } diff --git a/src/exchange/taler-exchange-httpd_keys.h b/src/exchange/taler-exchange-httpd_keys.h index 24ba1467..7e8c1e99 100644 --- a/src/exchange/taler-exchange-httpd_keys.h +++ b/src/exchange/taler-exchange-httpd_keys.h @@ -264,91 +264,85 @@ struct TEH_CoinSignData /** - * Request to sign @a csd for regular withdrawing. + * Request to sign @a csd for melting. * * @param csd identifies data to blindly sign and key to sign with + * @param for_melt true if this is for a melt operation * @param[out] bs set to the blind signature on success * @return #TALER_EC_NONE on success */ enum TALER_ErrorCode -TEH_keys_denomination_sign_withdraw ( +TEH_keys_denomination_sign ( const struct TEH_CoinSignData *csd, + bool for_melt, struct TALER_BlindedDenominationSignature *bs); /** - * Request to sign @a csds for regular withdrawing. + * Request to sign @a csds for melting. * * @param csds array with data to blindly sign (and keys to sign with) * @param csds_length length of @a csds array + * @param for_melt true if this is for a melt operation * @param[out] bss array set to the blind signature on success; must be of length @a csds_length * @return #TALER_EC_NONE on success */ enum TALER_ErrorCode -TEH_keys_denomination_batch_sign_withdraw ( +TEH_keys_denomination_batch_sign ( const struct TEH_CoinSignData *csds, unsigned int csds_length, + bool for_melt, struct TALER_BlindedDenominationSignature *bss); /** - * Request to sign @a csd for melting. - * - * @param csd identifies data to blindly sign and key to sign with - * @param[out] bs set to the blind signature on success - * @return #TALER_EC_NONE on success + * Information needed to derive the CS r_pub. */ -enum TALER_ErrorCode -TEH_keys_denomination_sign_melt ( - const struct TEH_CoinSignData *csd, - struct TALER_BlindedDenominationSignature *bs); - +struct TEH_CsDeriveData +{ + /** + * Hash of key to sign with. + */ + const struct TALER_DenominationHashP *h_denom_pub; -/** - * Request to sign @a csds for melting. - * - * @param csds array with data to blindly sign (and keys to sign with) - * @param csds_length length of @a csds array - * @param[out] bss array set to the blind signature on success; must be of length @a csds_length - * @return #TALER_EC_NONE on success - */ -enum TALER_ErrorCode -TEH_keys_denomination_batch_sign_melt ( - const struct TEH_CoinSignData *csds, - unsigned int csds_length, - struct TALER_BlindedDenominationSignature *bss); + /** + * Nonce to use. + */ + const struct TALER_CsNonce *nonce; +}; /** - * Request to derive CS @a r_pub using the denomination corresponding to @a h_denom_pub - * and @a nonce for withdrawing. + * Request to derive CS @a r_pub using the denomination and nonce from @a cdd. * - * @param h_denom_pub hash of the public key to use to derive r_pub - * @param nonce withdraw/refresh nonce + * @param cdd data to compute @a r_pub from + * @param for_melt true if this is for a melt operation * @param[out] r_pub where to write the result * @return #TALER_EC_NONE on success */ enum TALER_ErrorCode -TEH_keys_denomination_cs_r_pub_withdraw ( - const struct TALER_DenominationHashP *h_denom_pub, - const struct TALER_CsNonce *nonce, +TEH_keys_denomination_cs_r_pub ( + const struct TEH_CsDeriveData *cdd, + bool for_melt, struct TALER_DenominationCSPublicRPairP *r_pub); /** - * Request to derive CS @a r_pub using the denomination corresponding to @a h_denom_pub - * and @a nonce for melting. + * Request to derive a bunch of CS @a r_pubs using the + * denominations and nonces from @a cdds. * - * @param h_denom_pub hash of the public key to use to derive r_pub - * @param nonce withdraw/refresh nonce - * @param[out] r_pub where to write the result + * @param cdds array to compute @a r_pubs from + * @param cdds_length length of the @a cdds array + * @param for_melt true if this is for a melt operation + * @param[out] r_pubs array where to write the result; must be of length @a cdds_length * @return #TALER_EC_NONE on success */ enum TALER_ErrorCode -TEH_keys_denomination_cs_r_pub_melt ( - const struct TALER_DenominationHashP *h_denom_pub, - const struct TALER_CsNonce *nonce, - struct TALER_DenominationCSPublicRPairP *r_pub); +TEH_keys_denomination_cs_batch_r_pub ( + const struct TEH_CsDeriveData *cdds, + unsigned int cdds_length, + bool for_melt, + struct TALER_DenominationCSPublicRPairP *r_pubs); /** diff --git a/src/exchange/taler-exchange-httpd_refreshes_reveal.c b/src/exchange/taler-exchange-httpd_refreshes_reveal.c index a0c8a666..56848d58 100644 --- a/src/exchange/taler-exchange-httpd_refreshes_reveal.c +++ b/src/exchange/taler-exchange-httpd_refreshes_reveal.c @@ -215,10 +215,14 @@ check_commitment (struct RevealContext *rctx, case TALER_DENOMINATION_CS: { enum TALER_ErrorCode ec; - - ec = TEH_keys_denomination_cs_r_pub_melt ( - &rctx->rrcs[j].h_denom_pub, - &nonces[aoff], + const struct TEH_CsDeriveData cdd = { + .h_denom_pub = &rctx->rrcs[j].h_denom_pub, + .nonce = &nonces[aoff] + }; + + ec = TEH_keys_denomination_cs_r_pub ( + &cdd, + true, &alg_values->details.cs_values); if (TALER_EC_NONE != ec) { @@ -756,8 +760,9 @@ clean_age: // FIXME #7272: replace with a batch call that // passes all coins in once go! - ec = TEH_keys_denomination_sign_melt ( + ec = TEH_keys_denomination_sign ( &csd, + true, &rrcs[i].coin_sig); if (TALER_EC_NONE != ec) { diff --git a/src/exchange/taler-exchange-httpd_withdraw.c b/src/exchange/taler-exchange-httpd_withdraw.c index 71128bf5..25377363 100644 --- a/src/exchange/taler-exchange-httpd_withdraw.c +++ b/src/exchange/taler-exchange-httpd_withdraw.c @@ -455,8 +455,9 @@ TEH_handler_withdraw (struct TEH_RequestContext *rc, }; /* Sign before transaction! */ - ec = TEH_keys_denomination_sign_withdraw ( + ec = TEH_keys_denomination_sign ( &csd, + false, &wc.collectable.sig); } if (TALER_EC_NONE != ec) |