diff options
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/crypto.c | 58 | ||||
-rw-r--r-- | src/util/test_crypto.c | 15 | ||||
-rw-r--r-- | src/util/test_helper_cs.c | 44 | ||||
-rw-r--r-- | src/util/test_helper_rsa.c | 25 |
4 files changed, 94 insertions, 48 deletions
diff --git a/src/util/crypto.c b/src/util/crypto.c index 3e759e71b..50f2d97d3 100644 --- a/src/util/crypto.c +++ b/src/util/crypto.c @@ -209,11 +209,10 @@ TALER_cs_withdraw_nonce_derive (const struct void TALER_planchet_blinding_secret_create (struct TALER_PlanchetSecretsP *ps, - enum TALER_DenominationCipher cipher, const struct TALER_ExchangeWithdrawValues *alg_values) { - switch (cipher) + switch (alg_values->cipher) { case TALER_DENOMINATION_INVALID: GNUNET_break (0); @@ -244,18 +243,20 @@ TALER_planchet_blinding_secret_create (struct TALER_PlanchetSecretsP *ps, */ void TALER_planchet_setup_random (struct TALER_PlanchetSecretsP *ps, - enum TALER_DenominationCipher cipher) + const struct + TALER_ExchangeWithdrawValues *alg_values) { GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG, &ps->coin_priv, sizeof (struct TALER_CoinSpendPrivateKeyP)); - switch (cipher) + switch (alg_values->cipher) { case TALER_DENOMINATION_INVALID: GNUNET_break (0); return; case TALER_DENOMINATION_RSA: - TALER_planchet_blinding_secret_create (ps, TALER_DENOMINATION_RSA, NULL); + TALER_planchet_blinding_secret_create (ps, + alg_values); return; case TALER_DENOMINATION_CS: // Will be set in a later stage for Clause Blind Schnorr Scheme @@ -275,6 +276,8 @@ TALER_planchet_prepare (const struct TALER_DenominationPublicKey *dk, { struct TALER_CoinSpendPublicKeyP coin_pub; + GNUNET_assert (alg_values->cipher == dk->cipher); + GNUNET_CRYPTO_eddsa_key_get_public (&ps->coin_priv.eddsa_priv, &coin_pub.eddsa_pub); @@ -286,7 +289,7 @@ TALER_planchet_prepare (const struct TALER_DenominationPublicKey *dk, &ps->blinding_key, NULL, /* FIXME-Oec */ &coin_pub, - NULL, /* RSA has no alg Values */ + alg_values, c_hash, &pd->blinded_planchet)) { @@ -320,6 +323,23 @@ TALER_planchet_prepare (const struct TALER_DenominationPublicKey *dk, } +void +TALER_blinded_planchet_free (struct TALER_BlindedPlanchet *blinded_planchet) +{ + switch (blinded_planchet->cipher) + { + case TALER_DENOMINATION_RSA: + GNUNET_free (blinded_planchet->details.rsa_blinded_planchet.blinded_msg); + break; + case TALER_DENOMINATION_CS: + // nothing to do for CS + break; + default: + GNUNET_break (0); + } +} + + enum GNUNET_GenericReturnValue TALER_planchet_to_coin (const struct TALER_DenominationPublicKey *dk, const struct @@ -471,14 +491,28 @@ TALER_refresh_get_commitment (struct TALER_RefreshCommitmentP *rc, } -void -TALER_coin_ev_hash (const void *coin_ev, - size_t coin_ev_size, +enum GNUNET_GenericReturnValue +TALER_coin_ev_hash (const struct TALER_BlindedPlanchet *blinded_planchet, struct TALER_BlindedCoinHash *bch) { - GNUNET_CRYPTO_hash (coin_ev, - coin_ev_size, - &bch->hash); + switch (blinded_planchet->cipher) + { + case TALER_DENOMINATION_RSA: + GNUNET_CRYPTO_hash ( + blinded_planchet->details.rsa_blinded_planchet.blinded_msg, + blinded_planchet->details.rsa_blinded_planchet.blinded_msg_size, + &bch->hash); + return GNUNET_OK; + case TALER_DENOMINATION_CS: + GNUNET_CRYPTO_hash ( + &blinded_planchet->details.cs_blinded_planchet, + sizeof (blinded_planchet->details.cs_blinded_planchet), + &bch->hash); + return GNUNET_OK; + default: + GNUNET_break (0); + return GNUNET_SYSERR; + } } diff --git a/src/util/test_crypto.c b/src/util/test_crypto.c index 28352a678..9f01b74c7 100644 --- a/src/util/test_crypto.c +++ b/src/util/test_crypto.c @@ -87,6 +87,7 @@ test_planchets_rsa (void) struct TALER_PlanchetSecretsP ps; struct TALER_DenominationPrivateKey dk_priv; struct TALER_DenominationPublicKey dk_pub; + struct TALER_ExchangeWithdrawValues alg_values; struct TALER_PlanchetDetail pd; struct TALER_BlindedDenominationSignature blind_sig; struct TALER_FreshCoin coin; @@ -108,10 +109,12 @@ test_planchets_rsa (void) &dk_pub, TALER_DENOMINATION_RSA, 1024)); - TALER_planchet_setup_random (&ps, TALER_DENOMINATION_RSA); + alg_values.cipher = TALER_DENOMINATION_RSA; + TALER_planchet_setup_random (&ps, + &alg_values); GNUNET_assert (GNUNET_OK == TALER_planchet_prepare (&dk_pub, - NULL, /* not needed in RSA*/ + &alg_values, &ps, &c_hash, &pd)); @@ -124,7 +127,7 @@ test_planchets_rsa (void) &blind_sig, &ps, &c_hash, - NULL, /* Not needed in RSA case */ + &alg_values, &coin)); TALER_blinded_denom_sig_free (&blind_sig); TALER_denom_sig_free (&coin.sig); @@ -157,7 +160,9 @@ test_planchets_cs (void) &dk_pub, TALER_DENOMINATION_CS)); - TALER_planchet_setup_random (&ps, TALER_DENOMINATION_CS); + alg_values.cipher = TALER_DENOMINATION_CS; + TALER_planchet_setup_random (&ps, + &alg_values); TALER_cs_withdraw_nonce_derive (&ps.coin_priv, &pd.blinded_planchet.details. cs_blinded_planchet.nonce); @@ -166,9 +171,7 @@ test_planchets_cs (void) &pd.blinded_planchet.details.cs_blinded_planchet.nonce, &dk_priv, &alg_values.details.cs_values.r_pub)); - // TODO: eliminate r_pubs parameter TALER_planchet_blinding_secret_create (&ps, - TALER_DENOMINATION_CS, &alg_values); GNUNET_assert (GNUNET_OK == diff --git a/src/util/test_helper_cs.c b/src/util/test_helper_cs.c index 22f39b34f..5a41c7fa1 100644 --- a/src/util/test_helper_cs.c +++ b/src/util/test_helper_cs.c @@ -268,9 +268,11 @@ test_r_derive (struct TALER_CRYPTO_CsDenominationHelper *dh) bool success = false; struct TALER_PlanchetSecretsP ps; struct TALER_CoinPubHash c_hash; - struct TALER_ExchangeWithdrawValues values; + struct TALER_ExchangeWithdrawValues alg_values; - TALER_planchet_setup_random (&ps, TALER_DENOMINATION_CS); + alg_values.cipher = TALER_DENOMINATION_CS; + TALER_planchet_setup_random (&ps, + &alg_values); for (unsigned int i = 0; i<MAX_KEYS; i++) { struct TALER_PlanchetDetail pd; @@ -288,7 +290,7 @@ test_r_derive (struct TALER_CRYPTO_CsDenominationHelper *dh) "Requesting R derivation with key %s\n", GNUNET_h2s (&keys[i].h_cs.hash)); - values.details.cs_values.r_pub + alg_values.details.cs_values.r_pub = TALER_CRYPTO_helper_cs_r_derive (dh, &keys[i].h_cs, &pd.blinded_planchet. @@ -323,11 +325,10 @@ test_r_derive (struct TALER_CRYPTO_CsDenominationHelper *dh) GNUNET_h2s (&keys[i].h_cs.hash)); TALER_planchet_blinding_secret_create (&ps, - TALER_DENOMINATION_CS, - &values); + &alg_values); GNUNET_assert (GNUNET_OK == TALER_planchet_prepare (&keys[i].denom_pub, - &values, + &alg_values, &ps, &c_hash, &pd)); @@ -409,10 +410,11 @@ test_signing (struct TALER_CRYPTO_CsDenominationHelper *dh) bool success = false; struct TALER_PlanchetSecretsP ps; struct TALER_CoinPubHash c_hash; - struct TALER_ExchangeWithdrawValues values; + struct TALER_ExchangeWithdrawValues alg_values; - - TALER_planchet_setup_random (&ps, TALER_DENOMINATION_CS); + alg_values.cipher = TALER_DENOMINATION_CS; + TALER_planchet_setup_random (&ps, + &alg_values); for (unsigned int i = 0; i<MAX_KEYS; i++) { if (! keys[i].valid) @@ -425,7 +427,7 @@ test_signing (struct TALER_CRYPTO_CsDenominationHelper *dh) TALER_cs_withdraw_nonce_derive (&ps.coin_priv, &pd.blinded_planchet.details. cs_blinded_planchet.nonce); - values.details.cs_values.r_pub + alg_values.details.cs_values.r_pub = TALER_CRYPTO_helper_cs_r_derive (dh, &keys[i].h_cs, &pd.blinded_planchet. @@ -433,12 +435,11 @@ test_signing (struct TALER_CRYPTO_CsDenominationHelper *dh) cs_blinded_planchet.nonce, &ec); TALER_planchet_blinding_secret_create (&ps, - TALER_DENOMINATION_CS, - &values); + &alg_values); GNUNET_assert (GNUNET_YES == TALER_planchet_prepare (&keys[i].denom_pub, - &values, + &alg_values, &ps, &c_hash, &pd)); @@ -479,7 +480,7 @@ test_signing (struct TALER_CRYPTO_CsDenominationHelper *dh) &ds, &ps, &c_hash, - &values, + &alg_values, &coin)) { GNUNET_break (0); @@ -534,7 +535,7 @@ test_signing (struct TALER_CRYPTO_CsDenominationHelper *dh) pd.blinded_planchet.cipher = TALER_DENOMINATION_CS; GNUNET_assert (GNUNET_YES == TALER_planchet_prepare (&keys[0].denom_pub, - &values, + &alg_values, &ps, &c_hash, &pd)); @@ -573,8 +574,11 @@ perf_signing (struct TALER_CRYPTO_CsDenominationHelper *dh, enum TALER_ErrorCode ec; struct GNUNET_TIME_Relative duration; struct TALER_PlanchetSecretsP ps; + struct TALER_ExchangeWithdrawValues alg_values; - TALER_planchet_setup_random (&ps, TALER_DENOMINATION_CS); + alg_values.cipher = TALER_DENOMINATION_CS; + TALER_planchet_setup_random (&ps, + &alg_values); duration = GNUNET_TIME_UNIT_ZERO; TALER_CRYPTO_helper_cs_poll (dh); for (unsigned int j = 0; j<NUM_SIGN_PERFS;) @@ -596,7 +600,6 @@ perf_signing (struct TALER_CRYPTO_CsDenominationHelper *dh, { struct TALER_CoinPubHash c_hash; struct TALER_PlanchetDetail pd; - struct TALER_ExchangeWithdrawValues values; pd.blinded_planchet.cipher = TALER_DENOMINATION_CS; @@ -604,7 +607,7 @@ perf_signing (struct TALER_CRYPTO_CsDenominationHelper *dh, &pd.blinded_planchet.details. cs_blinded_planchet.nonce); - values.details.cs_values.r_pub + alg_values.details.cs_values.r_pub = TALER_CRYPTO_helper_cs_r_derive (dh, &keys[i].h_cs, &pd.blinded_planchet. @@ -612,12 +615,11 @@ perf_signing (struct TALER_CRYPTO_CsDenominationHelper *dh, cs_blinded_planchet.nonce, &ec); TALER_planchet_blinding_secret_create (&ps, - TALER_DENOMINATION_CS, - &values); + &alg_values); GNUNET_assert (GNUNET_YES == TALER_planchet_prepare (&keys[i].denom_pub, - &values, + &alg_values, &ps, &c_hash, &pd)); diff --git a/src/util/test_helper_rsa.c b/src/util/test_helper_rsa.c index 8cfea4bef..f9f1a860d 100644 --- a/src/util/test_helper_rsa.c +++ b/src/util/test_helper_rsa.c @@ -268,21 +268,25 @@ test_signing (struct TALER_CRYPTO_RsaDenominationHelper *dh) enum TALER_ErrorCode ec; bool success = false; struct TALER_PlanchetSecretsP ps; + struct TALER_ExchangeWithdrawValues alg_values; struct TALER_CoinPubHash c_hash; - TALER_planchet_setup_random (&ps, TALER_DENOMINATION_RSA); + alg_values.cipher = TALER_DENOMINATION_RSA; + TALER_planchet_setup_random (&ps, + &alg_values); for (unsigned int i = 0; i<MAX_KEYS; i++) { if (! keys[i].valid) continue; + if (TALER_DENOMINATION_RSA != keys[i].denom_pub.cipher) + continue; { struct TALER_PlanchetDetail pd; pd.blinded_planchet.cipher = TALER_DENOMINATION_RSA; - // keys[i].denom_pub.cipher = TALER_DENOMINATION_CS; GNUNET_assert (GNUNET_YES == TALER_planchet_prepare (&keys[i].denom_pub, - NULL, /* not needed in RSA*/ + &alg_values, &ps, &c_hash, &pd)); @@ -299,8 +303,7 @@ test_signing (struct TALER_CRYPTO_RsaDenominationHelper *dh) pd.blinded_planchet.details. rsa_blinded_planchet.blinded_msg_size, &ec); - GNUNET_free ( - pd.blinded_planchet.details.rsa_blinded_planchet.blinded_msg); + TALER_blinded_planchet_free (&pd.blinded_planchet); } switch (ec) { @@ -426,8 +429,11 @@ perf_signing (struct TALER_CRYPTO_RsaDenominationHelper *dh, enum TALER_ErrorCode ec; struct GNUNET_TIME_Relative duration; struct TALER_PlanchetSecretsP ps; + struct TALER_ExchangeWithdrawValues alg_values; - TALER_planchet_setup_random (&ps, TALER_DENOMINATION_RSA); + alg_values.cipher = TALER_DENOMINATION_RSA; + TALER_planchet_setup_random (&ps, + &alg_values); duration = GNUNET_TIME_UNIT_ZERO; TALER_CRYPTO_helper_rsa_poll (dh); for (unsigned int j = 0; j<NUM_SIGN_PERFS;) @@ -436,6 +442,8 @@ perf_signing (struct TALER_CRYPTO_RsaDenominationHelper *dh, { if (! keys[i].valid) continue; + if (TALER_DENOMINATION_RSA != keys[i].denom_pub.cipher) + continue; if (GNUNET_TIME_relative_cmp (GNUNET_TIME_absolute_get_remaining ( keys[i].start_time.abs_time), >, @@ -452,7 +460,7 @@ perf_signing (struct TALER_CRYPTO_RsaDenominationHelper *dh, GNUNET_assert (GNUNET_YES == TALER_planchet_prepare (&keys[i].denom_pub, - NULL, /* not needed in RSA*/ + &alg_values, &ps, &c_hash, &pd)); @@ -480,8 +488,7 @@ perf_signing (struct TALER_CRYPTO_RsaDenominationHelper *dh, if (NUM_SIGN_PERFS <= j) break; } - GNUNET_free ( - pd.blinded_planchet.details.rsa_blinded_planchet.blinded_msg); + TALER_blinded_planchet_free (&pd.blinded_planchet); } } /* for i */ } /* for j */ |