diff --git a/src/exchange/taler-exchange-httpd_keys.c b/src/exchange/taler-exchange-httpd_keys.c index e5a54447b..4b1a6213c 100644 --- a/src/exchange/taler-exchange-httpd_keys.c +++ b/src/exchange/taler-exchange-httpd_keys.c @@ -2411,54 +2411,40 @@ TEH_keys_denomination_by_hash2 ( } -struct TALER_BlindedDenominationSignature +enum TALER_ErrorCode TEH_keys_denomination_sign (const struct TALER_DenominationHash *h_denom_pub, const struct TALER_BlindedPlanchet *bp, - enum TALER_ErrorCode *ec) + struct TALER_BlindedDenominationSignature *bs) { struct TEH_KeyStateHandle *ksh; - struct TALER_BlindedDenominationSignature none; struct HelperDenomination *hd; - memset (&none, - 0, - sizeof (none)); ksh = TEH_keys_get_state (); if (NULL == ksh) - { - *ec = TALER_EC_EXCHANGE_GENERIC_KEYS_MISSING; - return none; - } + return TALER_EC_EXCHANGE_GENERIC_KEYS_MISSING; hd = GNUNET_CONTAINER_multihashmap_get (ksh->helpers->denom_keys, &h_denom_pub->hash); if (NULL == hd) - { - *ec = TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN; - return none; - } + return TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN; if (bp->cipher != hd->denom_pub.cipher) - { - *ec = TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE; - return none; - } + return TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE; switch (hd->denom_pub.cipher) { case TALER_DENOMINATION_RSA: - return TALER_CRYPTO_helper_rsa_sign (ksh->helpers->rsadh, - &hd->h_details.h_rsa, - bp->details.rsa_blinded_planchet. - blinded_msg, - bp->details.rsa_blinded_planchet. - blinded_msg_size, - ec); + return TALER_CRYPTO_helper_rsa_sign ( + ksh->helpers->rsadh, + &hd->h_details.h_rsa, + bp->details.rsa_blinded_planchet.blinded_msg, + bp->details.rsa_blinded_planchet.blinded_msg_size, + bs); case TALER_DENOMINATION_CS: - return TALER_CRYPTO_helper_cs_sign (ksh->helpers->csdh, - &hd->h_details.h_cs, - &bp->details.cs_blinded_planchet, - ec); + return TALER_CRYPTO_helper_cs_sign ( + ksh->helpers->csdh, + &hd->h_details.h_cs, + &bp->details.cs_blinded_planchet, + bs); default: - *ec = TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE; - return none; + return TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE; } } diff --git a/src/exchange/taler-exchange-httpd_keys.h b/src/exchange/taler-exchange-httpd_keys.h index 07925f7fd..a329c4f12 100644 --- a/src/exchange/taler-exchange-httpd_keys.h +++ b/src/exchange/taler-exchange-httpd_keys.h @@ -173,14 +173,13 @@ TEH_keys_denomination_by_hash2 ( * * @param h_denom_pub hash of the public key to use to sign * @param bp blinded planchet to sign - * @param[out] ec set to the error code (or #TALER_EC_NONE on success) - * @return signature, the value inside the structure will be NULL on failure, - * see @a ec for details about the failure + * @param[out] bs set to the blind signature on success + * @return #TALER_EC_NONE on success */ -struct TALER_BlindedDenominationSignature +enum TALER_ErrorCode TEH_keys_denomination_sign (const struct TALER_DenominationHash *h_denom_pub, const struct TALER_BlindedPlanchet *bp, - enum TALER_ErrorCode *ec); + struct TALER_BlindedDenominationSignature *bs); /** diff --git a/src/exchange/taler-exchange-httpd_refreshes_reveal.c b/src/exchange/taler-exchange-httpd_refreshes_reveal.c index ce56ebb10..0d8f7bf9b 100644 --- a/src/exchange/taler-exchange-httpd_refreshes_reveal.c +++ b/src/exchange/taler-exchange-httpd_refreshes_reveal.c @@ -607,13 +607,12 @@ resolve_refreshes_reveal_denominations (struct MHD_Connection *connection, /* create fresh coin signatures */ for (unsigned int i = 0; inum_fresh_coins; i++) { - enum TALER_ErrorCode ec = TALER_EC_NONE; + enum TALER_ErrorCode ec; - rrcs[i].coin_sig - = TEH_keys_denomination_sign ( - &rrcs[i].h_denom_pub, - &rcds[i].blinded_planchet, - &ec); + ec = TEH_keys_denomination_sign ( + &rrcs[i].h_denom_pub, + &rcds[i].blinded_planchet, + &rrcs[i].coin_sig); if (TALER_EC_NONE != ec) { GNUNET_break (0); diff --git a/src/exchange/taler-exchange-httpd_withdraw.c b/src/exchange/taler-exchange-httpd_withdraw.c index 8598f1322..7572f85d2 100644 --- a/src/exchange/taler-exchange-httpd_withdraw.c +++ b/src/exchange/taler-exchange-httpd_withdraw.c @@ -499,12 +499,10 @@ TEH_handler_withdraw (struct TEH_RequestContext *rc, // TODO: if CS: check nonce for reuse /* Sign before transaction! */ - ec = TALER_EC_NONE; - // FIXME: swap arguments! - wc.collectable.sig = TEH_keys_denomination_sign ( + ec = TEH_keys_denomination_sign ( &wc.collectable.denom_pub_hash, &wc.blinded_planchet, - &ec); + &wc.collectable.sig); if (TALER_EC_NONE != ec) { GNUNET_break (0); diff --git a/src/include/taler_crypto_lib.h b/src/include/taler_crypto_lib.h index dc721436b..d6014259d 100644 --- a/src/include/taler_crypto_lib.h +++ b/src/include/taler_crypto_lib.h @@ -1791,17 +1791,16 @@ TALER_CRYPTO_helper_rsa_poll (struct TALER_CRYPTO_RsaDenominationHelper *dh); * @param h_rsa hash of the RSA public key to use to sign * @param msg message to sign * @param msg_size number of bytes in @a msg - * @param[out] ec set to the error code (or #TALER_EC_NONE on success) - * @return signature, the value inside the structure will be NULL on failure, - * see @a ec for details about the failure + * @param[out] bs set to the blind signature + * @return #TALER_EC_NONE on success */ -struct TALER_BlindedDenominationSignature +enum TALER_ErrorCode TALER_CRYPTO_helper_rsa_sign ( struct TALER_CRYPTO_RsaDenominationHelper *dh, const struct TALER_RsaPubHashP *h_rsa, const void *msg, size_t msg_size, - enum TALER_ErrorCode *ec); + struct TALER_BlindedDenominationSignature *bs); /** @@ -1912,16 +1911,15 @@ TALER_CRYPTO_helper_cs_poll (struct TALER_CRYPTO_CsDenominationHelper *dh); * @param dh helper process connection * @param h_cs hash of the CS public key to use to sign * @param blinded_planchet blinded planchet containing c and nonce - * @param[out] ec set to the error code (or #TALER_EC_NONE on success) - * @return signature, the value inside the structure will be NULL on failure, - * see @a ec for details about the failure + * @param[out] bs set to the blind signature + * @return #TALER_EC_NONE on success */ -struct TALER_BlindedDenominationSignature +enum TALER_ErrorCode TALER_CRYPTO_helper_cs_sign ( struct TALER_CRYPTO_CsDenominationHelper *dh, const struct TALER_CsPubHashP *h_cs, const struct TALER_BlindedCsPlanchet *blinded_planchet, - enum TALER_ErrorCode *ec); + struct TALER_BlindedDenominationSignature *bs); /** diff --git a/src/util/crypto_helper_cs.c b/src/util/crypto_helper_cs.c index 019d1902b..874679cf0 100644 --- a/src/util/crypto_helper_cs.c +++ b/src/util/crypto_helper_cs.c @@ -378,17 +378,16 @@ more: } -struct TALER_BlindedDenominationSignature +enum TALER_ErrorCode TALER_CRYPTO_helper_cs_sign ( struct TALER_CRYPTO_CsDenominationHelper *dh, const struct TALER_CsPubHashP *h_cs, const struct TALER_BlindedCsPlanchet *blinded_planchet, - enum TALER_ErrorCode *ec) + struct TALER_BlindedDenominationSignature *bs) { - struct TALER_BlindedDenominationSignature ds = { - .cipher = TALER_DENOMINATION_INVALID - }; + enum TALER_ErrorCode ec = TALER_EC_INVALID; + bs->cipher = TALER_DENOMINATION_INVALID; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting signature process\n"); if (GNUNET_OK != @@ -396,8 +395,7 @@ TALER_CRYPTO_helper_cs_sign ( { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to connect to helper\n"); - *ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_UNAVAILABLE; - return ds; + return TALER_EC_EXCHANGE_DENOMINATION_HELPER_UNAVAILABLE; } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -420,8 +418,7 @@ TALER_CRYPTO_helper_cs_sign ( GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "send"); do_disconnect (dh); - *ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_UNAVAILABLE; - return ds; + return TALER_EC_EXCHANGE_DENOMINATION_HELPER_UNAVAILABLE; } } @@ -434,7 +431,6 @@ TALER_CRYPTO_helper_cs_sign ( = (const struct GNUNET_MessageHeader *) buf; bool finished = false; - *ec = TALER_EC_INVALID; while (1) { uint16_t msize; @@ -454,20 +450,20 @@ TALER_CRYPTO_helper_cs_sign ( { GNUNET_assert (finished); GNUNET_assert (0 == off); - return ds; + return ec; } GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "recv"); do_disconnect (dh); - *ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_UNAVAILABLE; + ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_UNAVAILABLE; break; } if (0 == ret) { GNUNET_break (0 == off); if (! finished) - *ec = TALER_EC_EXCHANGE_SIGNKEY_HELPER_BUG; - return ds; + ec = TALER_EC_EXCHANGE_SIGNKEY_HELPER_BUG; + return ec; } off += ret; more: @@ -483,26 +479,26 @@ more: { GNUNET_break_op (0); do_disconnect (dh); - *ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG; + ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG; goto end; } if (finished) { GNUNET_break_op (0); do_disconnect (dh); - *ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG; + ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG; goto end; } { const struct TALER_CRYPTO_SignResponse *sr = (const struct TALER_CRYPTO_SignResponse *) buf; - // TODO: add nullcheck + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received signature\n"); - *ec = TALER_EC_NONE; + ec = TALER_EC_NONE; finished = true; - ds.cipher = TALER_DENOMINATION_CS; - ds.details.blinded_cs_answer = sr->cs_answer; + bs->cipher = TALER_DENOMINATION_CS; + bs->details.blinded_cs_answer = sr->cs_answer; break; } case TALER_HELPER_CS_MT_RES_SIGN_FAILURE: @@ -510,14 +506,14 @@ more: { GNUNET_break_op (0); do_disconnect (dh); - *ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG; + ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG; goto end; } { const struct TALER_CRYPTO_SignFailure *sf = (const struct TALER_CRYPTO_SignFailure *) buf; - *ec = (enum TALER_ErrorCode) ntohl (sf->ec); + ec = (enum TALER_ErrorCode) ntohl (sf->ec); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Signing failed!\n"); finished = true; @@ -532,7 +528,7 @@ more: { GNUNET_break_op (0); do_disconnect (dh); - *ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG; + ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG; goto end; } break; /* while(1) loop ensures we recvfrom() again */ @@ -545,7 +541,7 @@ more: { GNUNET_break_op (0); do_disconnect (dh); - *ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG; + ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG; goto end; } break; /* while(1) loop ensures we recvfrom() again */ @@ -560,7 +556,7 @@ more: "Received unexpected message of type %u\n", ntohs (hdr->type)); do_disconnect (dh); - *ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG; + ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG; goto end; } memmove (buf, @@ -571,8 +567,8 @@ more: } /* while(1) */ end: if (finished) - TALER_blinded_denom_sig_free (&ds); - return ds; + TALER_blinded_denom_sig_free (bs); + return ec; } } diff --git a/src/util/crypto_helper_rsa.c b/src/util/crypto_helper_rsa.c index 75fe33c03..d3f498c07 100644 --- a/src/util/crypto_helper_rsa.c +++ b/src/util/crypto_helper_rsa.c @@ -387,18 +387,17 @@ more: } -struct TALER_BlindedDenominationSignature +enum TALER_ErrorCode TALER_CRYPTO_helper_rsa_sign ( struct TALER_CRYPTO_RsaDenominationHelper *dh, const struct TALER_RsaPubHashP *h_rsa, const void *msg, size_t msg_size, - enum TALER_ErrorCode *ec) + struct TALER_BlindedDenominationSignature *bs) { - struct TALER_BlindedDenominationSignature ds = { - .cipher = TALER_DENOMINATION_INVALID - }; + enum TALER_ErrorCode ec = TALER_EC_INVALID; + bs->cipher = TALER_DENOMINATION_INVALID; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting signature process\n"); if (GNUNET_OK != @@ -406,8 +405,7 @@ TALER_CRYPTO_helper_rsa_sign ( { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to connect to helper\n"); - *ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_UNAVAILABLE; - return ds; + return TALER_EC_EXCHANGE_DENOMINATION_HELPER_UNAVAILABLE; } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -432,8 +430,7 @@ TALER_CRYPTO_helper_rsa_sign ( GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "send"); do_disconnect (dh); - *ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_UNAVAILABLE; - return ds; + return TALER_EC_EXCHANGE_DENOMINATION_HELPER_UNAVAILABLE; } } @@ -446,7 +443,6 @@ TALER_CRYPTO_helper_rsa_sign ( = (const struct GNUNET_MessageHeader *) buf; bool finished = false; - *ec = TALER_EC_INVALID; while (1) { uint16_t msize; @@ -466,20 +462,20 @@ TALER_CRYPTO_helper_rsa_sign ( { GNUNET_assert (finished); GNUNET_assert (0 == off); - return ds; + return ec; } GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "recv"); do_disconnect (dh); - *ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_UNAVAILABLE; + ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_UNAVAILABLE; break; } if (0 == ret) { GNUNET_break (0 == off); if (! finished) - *ec = TALER_EC_EXCHANGE_SIGNKEY_HELPER_BUG; - return ds; + ec = TALER_EC_EXCHANGE_SIGNKEY_HELPER_BUG; + return ec; } off += ret; more: @@ -495,14 +491,14 @@ more: { GNUNET_break_op (0); do_disconnect (dh); - *ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG; + ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG; goto end; } if (finished) { GNUNET_break_op (0); do_disconnect (dh); - *ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG; + ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG; goto end; } { @@ -517,15 +513,15 @@ more: { GNUNET_break_op (0); do_disconnect (dh); - *ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG; + ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG; goto end; } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received signature\n"); - *ec = TALER_EC_NONE; + ec = TALER_EC_NONE; finished = true; - ds.cipher = TALER_DENOMINATION_RSA; - ds.details.blinded_rsa_signature = rsa_signature; + bs->cipher = TALER_DENOMINATION_RSA; + bs->details.blinded_rsa_signature = rsa_signature; break; } case TALER_HELPER_RSA_MT_RES_SIGN_FAILURE: @@ -533,14 +529,14 @@ more: { GNUNET_break_op (0); do_disconnect (dh); - *ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG; + ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG; goto end; } { const struct TALER_CRYPTO_SignFailure *sf = (const struct TALER_CRYPTO_SignFailure *) buf; - *ec = (enum TALER_ErrorCode) ntohl (sf->ec); + ec = (enum TALER_ErrorCode) ntohl (sf->ec); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Signing failed!\n"); finished = true; @@ -555,7 +551,7 @@ more: { GNUNET_break_op (0); do_disconnect (dh); - *ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG; + ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG; goto end; } break; /* while(1) loop ensures we recvfrom() again */ @@ -568,7 +564,7 @@ more: { GNUNET_break_op (0); do_disconnect (dh); - *ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG; + ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG; goto end; } break; /* while(1) loop ensures we recvfrom() again */ @@ -583,7 +579,7 @@ more: "Received unexpected message of type %u\n", ntohs (hdr->type)); do_disconnect (dh); - *ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG; + ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG; goto end; } memmove (buf, @@ -594,8 +590,8 @@ more: } /* while(1) */ end: if (finished) - TALER_blinded_denom_sig_free (&ds); - return ds; + TALER_blinded_denom_sig_free (bs); + return ec; } } diff --git a/src/util/test_helper_cs.c b/src/util/test_helper_cs.c index dd807b254..a0dbebd62 100644 --- a/src/util/test_helper_cs.c +++ b/src/util/test_helper_cs.c @@ -456,11 +456,11 @@ test_signing (struct TALER_CRYPTO_CsDenominationHelper *dh) GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Requesting signature with key %s\n", GNUNET_h2s (&keys[i].h_cs.hash)); - ds = TALER_CRYPTO_helper_cs_sign (dh, + ec = TALER_CRYPTO_helper_cs_sign (dh, &keys[i].h_cs, &pd.blinded_planchet.details. cs_blinded_planchet, - &ec); + &ds); } switch (ec) { @@ -552,11 +552,11 @@ test_signing (struct TALER_CRYPTO_CsDenominationHelper *dh) &c_hash, &pd)); - ds = TALER_CRYPTO_helper_cs_sign (dh, + ec = TALER_CRYPTO_helper_cs_sign (dh, &rnd, &pd.blinded_planchet.details. cs_blinded_planchet, - &ec); + &ds); if (TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN != ec) { if (TALER_EC_NONE == ec) @@ -645,11 +645,11 @@ perf_signing (struct TALER_CRYPTO_CsDenominationHelper *dh, struct GNUNET_TIME_Absolute start = GNUNET_TIME_absolute_get (); struct GNUNET_TIME_Relative delay; - ds = TALER_CRYPTO_helper_cs_sign (dh, + ec = TALER_CRYPTO_helper_cs_sign (dh, &keys[i].h_cs, &pd.blinded_planchet.details. cs_blinded_planchet, - &ec); + &ds); if (TALER_EC_NONE != ec) break; delay = GNUNET_TIME_absolute_get_duration (start); diff --git a/src/util/test_helper_rsa.c b/src/util/test_helper_rsa.c index 33363b1fb..679f5d7f4 100644 --- a/src/util/test_helper_rsa.c +++ b/src/util/test_helper_rsa.c @@ -304,13 +304,13 @@ test_signing (struct TALER_CRYPTO_RsaDenominationHelper *dh) int) pd.blinded_planchet.details.rsa_blinded_planchet. blinded_msg_size, GNUNET_h2s (&keys[i].h_rsa.hash)); - ds = TALER_CRYPTO_helper_rsa_sign (dh, + ec = TALER_CRYPTO_helper_rsa_sign (dh, &keys[i].h_rsa, pd.blinded_planchet.details. rsa_blinded_planchet.blinded_msg, pd.blinded_planchet.details. rsa_blinded_planchet.blinded_msg_size, - &ec); + &ds); TALER_blinded_planchet_free (&pd.blinded_planchet); } switch (ec) @@ -405,11 +405,11 @@ test_signing (struct TALER_CRYPTO_RsaDenominationHelper *dh) GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, &rnd, sizeof (rnd)); - ds = TALER_CRYPTO_helper_rsa_sign (dh, + ec = TALER_CRYPTO_helper_rsa_sign (dh, &rnd, "Hello", strlen ("Hello"), - &ec); + &ds); if (TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN != ec) { if (TALER_EC_NONE == ec) @@ -485,14 +485,14 @@ perf_signing (struct TALER_CRYPTO_RsaDenominationHelper *dh, struct GNUNET_TIME_Absolute start = GNUNET_TIME_absolute_get (); struct GNUNET_TIME_Relative delay; - ds = TALER_CRYPTO_helper_rsa_sign (dh, + ec = TALER_CRYPTO_helper_rsa_sign (dh, &keys[i].h_rsa, pd.blinded_planchet.details. rsa_blinded_planchet.blinded_msg, pd.blinded_planchet.details. rsa_blinded_planchet. blinded_msg_size, - &ec); + &ds); if (TALER_EC_NONE != ec) break; delay = GNUNET_TIME_absolute_get_duration (start);