diff options
author | Lucien Heuzeveldt <lucienclaude.heuzeveldt@students.bfh.ch> | 2021-12-31 15:24:41 +0100 |
---|---|---|
committer | Gian Demarmels <gian@demarmels.org> | 2022-02-04 15:33:09 +0100 |
commit | cf4fd36cc481d3af369a059df213ef00212046d5 (patch) | |
tree | f284f4333baf80f7282b2d2dcf371e7a29bb0f54 | |
parent | 4bcbd704df54515789239962ffe6d09864c285b0 (diff) |
remove varargs in cs crypto implementation
-rw-r--r-- | src/include/taler_crypto_lib.h | 64 | ||||
-rw-r--r-- | src/util/crypto.c | 42 | ||||
-rw-r--r-- | src/util/denom.c | 19 | ||||
-rw-r--r-- | src/util/test_crypto.c | 27 |
4 files changed, 68 insertions, 84 deletions
diff --git a/src/include/taler_crypto_lib.h b/src/include/taler_crypto_lib.h index 850d259ac..bf82b8f0e 100644 --- a/src/include/taler_crypto_lib.h +++ b/src/include/taler_crypto_lib.h @@ -753,6 +753,18 @@ struct TALER_BlindedRsaPlanchet /** + * Withdraw nonce for CS denominations + */ +struct TALER_WithdrawNonce +{ + /** + * 32 bit nonce to include in withdrawals + */ + struct GNUNET_CRYPTO_CsNonce nonce; +}; + + +/** * @brief CS Parameters to create blinded signature * */ @@ -762,6 +774,11 @@ struct TALER_BlindedCsPlanchet * The Clause Schnorr c_0 and c_1 containing the blinded message */ struct GNUNET_CRYPTO_CsC c[2]; + + /** + * Public Nonce + */ + struct TALER_WithdrawNonce nonce; }; /** @@ -796,17 +813,6 @@ struct TALER_BlindedPlanchet /** * Withdraw nonce for CS denominations */ -struct TALER_WithdrawNonce -{ - /** - * 32 bit nonce to include in withdrawals - */ - struct GNUNET_CRYPTO_CsNonce nonce; -}; - -/** - * Withdraw nonce for CS denominations - */ struct TALER_RefreshNonce { /** @@ -1016,8 +1022,7 @@ TALER_denom_blind (const struct TALER_DenominationPublicKey *dk, enum GNUNET_GenericReturnValue TALER_denom_sign_blinded (struct TALER_BlindedDenominationSignature *denom_sig, const struct TALER_DenominationPrivateKey *denom_priv, - const struct TALER_BlindedPlanchet *blinded_planchet, - ...); + const struct TALER_BlindedPlanchet *blinded_planchet); /** @@ -1235,6 +1240,17 @@ struct TALER_PlanchetSecretsP */ union TALER_DenominationBlindingKeyP blinding_key; + // only used in case of CS: + + /** + * (non-blinded) r_pub + */ + struct TALER_DenominationCsPublicR cs_r_pub; + + /** + * blinded r_pub + */ + struct TALER_DenominationCsPublicR cs_r_pub_blinded; }; @@ -1406,16 +1422,13 @@ TALER_planchet_setup_random (struct TALER_PlanchetSecretsP *ps, * @param[out] c_hash set to the hash of the public key of the coin (needed later) * @param[out] pd set to the planchet detail for TALER_MERCHANT_tip_pickup() and * other withdraw operations - * @param ... if CS algorithm, r_pub (TALER_DenominationCsPublicR) is needed to blind and - * r_pub_blind (TALER_DenominationCsPublicR) is an additional out parameter. * @return #GNUNET_OK on success */ enum GNUNET_GenericReturnValue TALER_planchet_prepare (const struct TALER_DenominationPublicKey *dk, - const struct TALER_PlanchetSecretsP *ps, + struct TALER_PlanchetSecretsP *ps, struct TALER_CoinPubHash *c_hash, - struct TALER_PlanchetDetail *pd, - ...); + struct TALER_PlanchetDetail *pd); /** @@ -1427,18 +1440,15 @@ TALER_planchet_prepare (const struct TALER_DenominationPublicKey *dk, * @param ps secrets from #TALER_planchet_prepare() * @param c_hash hash of the coin's public key for verification of the signature * @param[out] coin set to the details of the fresh coin - * @param ... If CS algorithm, r_pub_blind (TALER_DenominationCsPublicR) is an additional param - * @return #GNUNET_OK on success */ enum GNUNET_GenericReturnValue -TALER_planchet_to_coin ( - const struct TALER_DenominationPublicKey *dk, - const struct TALER_BlindedDenominationSignature *blind_sig, - const struct TALER_PlanchetSecretsP *ps, - const struct TALER_CoinPubHash *c_hash, - struct TALER_FreshCoin *coin, - ...); +TALER_planchet_to_coin (const struct TALER_DenominationPublicKey *dk, + const struct + TALER_BlindedDenominationSignature *blind_sig, + const struct TALER_PlanchetSecretsP *ps, + const struct TALER_CoinPubHash *c_hash, + struct TALER_FreshCoin *coin); /* ****************** Refresh crypto primitives ************* */ diff --git a/src/util/crypto.c b/src/util/crypto.c index 1e5033a0c..2d3099a44 100644 --- a/src/util/crypto.c +++ b/src/util/crypto.c @@ -262,6 +262,7 @@ TALER_planchet_setup_random (struct TALER_PlanchetSecretsP *ps, GNUNET_break (0); return; case TALER_DENOMINATION_RSA: + // TODO: replace with call to TALER_blinding_secret_create GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG, &ps->blinding_key.rsa_bks, sizeof (struct @@ -278,10 +279,9 @@ TALER_planchet_setup_random (struct TALER_PlanchetSecretsP *ps, enum GNUNET_GenericReturnValue TALER_planchet_prepare (const struct TALER_DenominationPublicKey *dk, - const struct TALER_PlanchetSecretsP *ps, + struct TALER_PlanchetSecretsP *ps, struct TALER_CoinPubHash *c_hash, - struct TALER_PlanchetDetail *pd, - ...) + struct TALER_PlanchetDetail *pd) { struct TALER_CoinSpendPublicKeyP coin_pub; @@ -305,14 +305,6 @@ TALER_planchet_prepare (const struct TALER_DenominationPublicKey *dk, break; case TALER_DENOMINATION_CS: { - va_list ap; - va_start (ap, pd); - struct TALER_DenominationCsPublicR *r_pub; - struct TALER_DenominationCsPublicR *blinded_r_pub; - - r_pub = va_arg (ap, struct TALER_DenominationCsPublicR *); - blinded_r_pub = va_arg (ap, struct TALER_DenominationCsPublicR *); - if (GNUNET_OK != TALER_denom_blind (dk, &ps->blinding_key, @@ -320,14 +312,12 @@ TALER_planchet_prepare (const struct TALER_DenominationPublicKey *dk, &coin_pub, c_hash, &pd->blinded_planchet, - r_pub, - blinded_r_pub)) + &ps->cs_r_pub, + &ps->cs_r_pub_blinded)) { - va_end (ap); GNUNET_break (0); return GNUNET_SYSERR; } - va_end (ap); break; } default: @@ -342,13 +332,12 @@ TALER_planchet_prepare (const struct TALER_DenominationPublicKey *dk, enum GNUNET_GenericReturnValue -TALER_planchet_to_coin ( - const struct TALER_DenominationPublicKey *dk, - const struct TALER_BlindedDenominationSignature *blind_sig, - const struct TALER_PlanchetSecretsP *ps, - const struct TALER_CoinPubHash *c_hash, - struct TALER_FreshCoin *coin, - ...) +TALER_planchet_to_coin (const struct TALER_DenominationPublicKey *dk, + const struct + TALER_BlindedDenominationSignature *blind_sig, + const struct TALER_PlanchetSecretsP *ps, + const struct TALER_CoinPubHash *c_hash, + struct TALER_FreshCoin *coin) { struct TALER_DenominationSignature sig; @@ -367,23 +356,16 @@ TALER_planchet_to_coin ( break; case TALER_DENOMINATION_CS: { - va_list ap; - va_start (ap, coin); - - struct TALER_DenominationCsPublicR *r_pub_blind; - r_pub_blind = va_arg (ap, struct TALER_DenominationCsPublicR *); if (GNUNET_OK != TALER_denom_sig_unblind (&sig, blind_sig, &ps->blinding_key, dk, - r_pub_blind)) + &ps->cs_r_pub_blinded)) { GNUNET_break_op (0); - va_end (ap); return GNUNET_SYSERR; } - va_end (ap); } break; default: diff --git a/src/util/denom.c b/src/util/denom.c index 4b62f4cc0..9d8acfcae 100644 --- a/src/util/denom.c +++ b/src/util/denom.c @@ -107,8 +107,7 @@ TALER_denom_cs_derive_r_public (const struct TALER_WithdrawNonce *nonce, enum GNUNET_GenericReturnValue TALER_denom_sign_blinded (struct TALER_BlindedDenominationSignature *denom_sig, const struct TALER_DenominationPrivateKey *denom_priv, - const struct TALER_BlindedPlanchet *blinded_planchet, - ...) + const struct TALER_BlindedPlanchet *blinded_planchet) { memset (denom_sig, 0, @@ -133,27 +132,23 @@ TALER_denom_sign_blinded (struct TALER_BlindedDenominationSignature *denom_sig, return GNUNET_OK; case TALER_DENOMINATION_CS: { - va_list ap; - va_start (ap, blinded_planchet); - struct TALER_WithdrawNonce *nonce; - nonce = va_arg (ap, struct TALER_WithdrawNonce *); - struct GNUNET_CRYPTO_CsRSecret r[2]; - GNUNET_CRYPTO_cs_r_derive (&nonce->nonce, - &denom_priv->details.cs_private_key, - r); + GNUNET_CRYPTO_cs_r_derive ( + &blinded_planchet->details.cs_blinded_planchet.nonce.nonce, + &denom_priv->details.cs_private_key, + r); denom_sig->details.blinded_cs_answer.b = GNUNET_CRYPTO_cs_sign_derive (&denom_priv->details.cs_private_key, r, blinded_planchet->details. cs_blinded_planchet.c, - &nonce->nonce, + &blinded_planchet->details. + cs_blinded_planchet.nonce.nonce, &denom_sig->details.blinded_cs_answer. s_scalar); denom_sig->cipher = TALER_DENOMINATION_CS; - va_end (ap); } return GNUNET_OK; default: diff --git a/src/util/test_crypto.c b/src/util/test_crypto.c index 760ec0fa3..513fbbad8 100644 --- a/src/util/test_crypto.c +++ b/src/util/test_crypto.c @@ -146,9 +146,6 @@ test_planchets_cs (void) struct TALER_DenominationPublicKey dk_pub; struct TALER_PlanchetDetail pd; struct TALER_CoinPubHash c_hash; - struct TALER_WithdrawNonce nonce; - struct TALER_DenominationCsPublicR r_pub; - struct TALER_DenominationCsPublicR r_pub_blind; struct TALER_BlindedDenominationSignature blind_sig; struct TALER_FreshCoin coin; @@ -158,37 +155,37 @@ test_planchets_cs (void) TALER_DENOMINATION_CS)); TALER_planchet_setup_random (&ps, TALER_DENOMINATION_CS); - TALER_cs_withdraw_nonce_derive (&ps.coin_priv, &nonce); + TALER_cs_withdraw_nonce_derive (&ps.coin_priv, + &pd.blinded_planchet.details. + cs_blinded_planchet.nonce); GNUNET_assert (GNUNET_OK == - TALER_denom_cs_derive_r_public (&nonce, - &dk_priv, - &r_pub)); + TALER_denom_cs_derive_r_public ( + &pd.blinded_planchet.details.cs_blinded_planchet.nonce, + &dk_priv, + &ps.cs_r_pub)); + // TODO: eliminate r_pubs parameter TALER_blinding_secret_create (&ps.blinding_key, TALER_DENOMINATION_CS, &ps.coin_priv, - &r_pub); + &ps.cs_r_pub); GNUNET_assert (GNUNET_OK == TALER_planchet_prepare (&dk_pub, &ps, &c_hash, - &pd, - &r_pub, - &r_pub_blind)); + &pd)); GNUNET_assert (GNUNET_OK == TALER_denom_sign_blinded (&blind_sig, &dk_priv, - &pd.blinded_planchet, - &nonce)); + &pd.blinded_planchet)); GNUNET_assert (GNUNET_OK == TALER_planchet_to_coin (&dk_pub, &blind_sig, &ps, &c_hash, - &coin, - &r_pub_blind)); + &coin)); TALER_blinded_denom_sig_free (&blind_sig); TALER_denom_sig_free (&coin.sig); |