diff options
author | Christian Grothoff <christian@grothoff.org> | 2022-11-14 05:34:19 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2022-11-14 05:34:19 +0100 |
commit | 053faa252c2afed8ecbb65bdd6fe8ec6f9ad9ef9 (patch) | |
tree | cefe2776cbfb9b9be508158d2be2eec2a1f82d78 /src | |
parent | d876a950739e66533af168a55439a8652f018d1f (diff) |
-refactoring in preparation of fixing #7272
Diffstat (limited to 'src')
-rw-r--r-- | src/exchange/taler-exchange-httpd_batch-withdraw.c | 7 | ||||
-rw-r--r-- | src/exchange/taler-exchange-httpd_keys.c | 64 | ||||
-rw-r--r-- | src/exchange/taler-exchange-httpd_keys.h | 64 | ||||
-rw-r--r-- | src/exchange/taler-exchange-httpd_refreshes_reveal.c | 7 | ||||
-rw-r--r-- | src/exchange/taler-exchange-httpd_withdraw.c | 16 |
5 files changed, 133 insertions, 25 deletions
diff --git a/src/exchange/taler-exchange-httpd_batch-withdraw.c b/src/exchange/taler-exchange-httpd_batch-withdraw.c index 541d65728..7352edfdd 100644 --- a/src/exchange/taler-exchange-httpd_batch-withdraw.c +++ b/src/exchange/taler-exchange-httpd_batch-withdraw.c @@ -422,10 +422,13 @@ prepare_transaction (const struct TEH_RequestContext *rc, { struct PlanchetContext *pc = &wc->planchets[i]; enum TALER_ErrorCode ec; + struct TEH_CoinSignData csds = { + .h_denom_pub = &pc->collectable.denom_pub_hash, + .bp = &pc->blinded_planchet + }; ec = TEH_keys_denomination_sign_withdraw ( - &pc->collectable.denom_pub_hash, - &pc->blinded_planchet, + &csds, &pc->collectable.sig); if (TALER_EC_NONE != ec) { diff --git a/src/exchange/taler-exchange-httpd_keys.c b/src/exchange/taler-exchange-httpd_keys.c index cf20985c5..d430946cf 100644 --- a/src/exchange/taler-exchange-httpd_keys.c +++ b/src/exchange/taler-exchange-httpd_keys.c @@ -2747,12 +2747,66 @@ TEH_keys_denomination_by_hash2 ( enum TALER_ErrorCode TEH_keys_denomination_sign_withdraw ( - const struct TALER_DenominationHashP *h_denom_pub, - const struct TALER_BlindedPlanchet *bp, + const struct TEH_CoinSignData *csd, struct TALER_BlindedDenominationSignature *bs) { struct TEH_KeyStateHandle *ksh; struct HelperDenomination *hd; + const struct TALER_DenominationHashP *h_denom_pub = csd->h_denom_pub; + const struct TALER_BlindedPlanchet *bp = csd->bp; + + 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]++; + { + 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_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); + } + default: + return TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE; + } +} + + +enum TALER_ErrorCode +TEH_keys_denomination_batch_sign_withdraw ( + const struct TEH_CoinSignData *csds, + unsigned int csds_length, + struct TALER_BlindedDenominationSignature *bss) +{ + struct TEH_KeyStateHandle *ksh; + struct HelperDenomination *hd; +#if 0 ksh = TEH_keys_get_state (); if (NULL == ksh) @@ -2794,15 +2848,17 @@ TEH_keys_denomination_sign_withdraw ( default: return TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE; } +#endif } enum TALER_ErrorCode TEH_keys_denomination_sign_melt ( - const struct TALER_DenominationHashP *h_denom_pub, - const struct TALER_BlindedPlanchet *bp, + 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; diff --git a/src/exchange/taler-exchange-httpd_keys.h b/src/exchange/taler-exchange-httpd_keys.h index 01ba1f951..24ba1467c 100644 --- a/src/exchange/taler-exchange-httpd_keys.h +++ b/src/exchange/taler-exchange-httpd_keys.h @@ -246,40 +246,80 @@ TEH_keys_denomination_by_hash2 ( struct MHD_Connection *conn, MHD_RESULT *mret); +/** + * Information needed to create a blind signature. + */ +struct TEH_CoinSignData +{ + /** + * Hash of key to sign with. + */ + const struct TALER_DenominationHashP *h_denom_pub; + + /** + * Blinded planchet to sign over. + */ + const struct TALER_BlindedPlanchet *bp; +}; + /** - * Request to sign @a msg using the public key corresponding to - * @a h_denom_pub during a withdraw operation. + * Request to sign @a csd for regular withdrawing. * - * @param h_denom_pub hash of the public key to use to sign - * @param bp blinded planchet to sign + * @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 */ enum TALER_ErrorCode TEH_keys_denomination_sign_withdraw ( - const struct TALER_DenominationHashP *h_denom_pub, - const struct TALER_BlindedPlanchet *bp, + const struct TEH_CoinSignData *csd, struct TALER_BlindedDenominationSignature *bs); /** - * Request to sign @a msg using the public key corresponding to - * @a h_denom_pub during a refresh operation. + * Request to sign @a csds for regular withdrawing. + * + * @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_withdraw ( + const struct TEH_CoinSignData *csds, + unsigned int csds_length, + struct TALER_BlindedDenominationSignature *bss); + + +/** + * Request to sign @a csd for melting. * - * @param h_denom_pub hash of the public key to use to sign - * @param bp blinded planchet to sign + * @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 */ enum TALER_ErrorCode TEH_keys_denomination_sign_melt ( - const struct TALER_DenominationHashP *h_denom_pub, - const struct TALER_BlindedPlanchet *bp, + const struct TEH_CoinSignData *csd, struct TALER_BlindedDenominationSignature *bs); /** + * 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); + + +/** * Request to derive CS @a r_pub using the denomination corresponding to @a h_denom_pub * and @a nonce for withdrawing. * diff --git a/src/exchange/taler-exchange-httpd_refreshes_reveal.c b/src/exchange/taler-exchange-httpd_refreshes_reveal.c index 85090cedc..a0c8a6667 100644 --- a/src/exchange/taler-exchange-httpd_refreshes_reveal.c +++ b/src/exchange/taler-exchange-httpd_refreshes_reveal.c @@ -749,12 +749,15 @@ clean_age: for (unsigned int i = 0; i<rctx->num_fresh_coins; i++) { enum TALER_ErrorCode ec; + struct TEH_CoinSignData csd = { + .h_denom_pub = &rrcs[i].h_denom_pub, + .bp = &rcds[i].blinded_planchet + }; // FIXME #7272: replace with a batch call that // passes all coins in once go! ec = TEH_keys_denomination_sign_melt ( - &rrcs[i].h_denom_pub, - &rcds[i].blinded_planchet, + &csd, &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 27b176722..71128bf53 100644 --- a/src/exchange/taler-exchange-httpd_withdraw.c +++ b/src/exchange/taler-exchange-httpd_withdraw.c @@ -448,11 +448,17 @@ TEH_handler_withdraw (struct TEH_RequestContext *rc, NULL); } - /* Sign before transaction! */ - ec = TEH_keys_denomination_sign_withdraw ( - &wc.collectable.denom_pub_hash, - &wc.blinded_planchet, - &wc.collectable.sig); + { + struct TEH_CoinSignData csd = { + .h_denom_pub = &wc.collectable.denom_pub_hash, + .bp = &wc.blinded_planchet + }; + + /* Sign before transaction! */ + ec = TEH_keys_denomination_sign_withdraw ( + &csd, + &wc.collectable.sig); + } if (TALER_EC_NONE != ec) { GNUNET_break (0); |