From 4bcbd704df54515789239962ffe6d09864c285b0 Mon Sep 17 00:00:00 2001 From: Gian Demarmels Date: Mon, 27 Dec 2021 20:02:54 +0100 Subject: utility functions --- src/include/taler_crypto_lib.h | 15 ++++++----- src/util/denom.c | 58 ++++++++++++++++++++++++++++++------------ 2 files changed, 51 insertions(+), 22 deletions(-) diff --git a/src/include/taler_crypto_lib.h b/src/include/taler_crypto_lib.h index 3de843a22..850d259ac 100644 --- a/src/include/taler_crypto_lib.h +++ b/src/include/taler_crypto_lib.h @@ -918,7 +918,7 @@ TALER_cs_withdraw_nonce_derive (const struct * @param[out] bs blinding secret to initialize * @param cipher algorithm to use (CS or RSA) * @param ... If CS signature, R_0 and R_1 (TALER_DenominationCsPublicR) - * and the coins private key is needed + * and the coins private key (TALER_CoinSpendPrivateKeyP) is needed */ void TALER_blinding_secret_create (union TALER_DenominationBlindingKeyP *bs, @@ -936,7 +936,7 @@ TALER_blinding_secret_create (union TALER_DenominationBlindingKeyP *bs, * @param[out] denom_priv where to write the private key * @param[out] deonm_pub where to write the public key * @param cipher which type of cipher to use - * @param ... cipher-specific parameters + * @param ... RSA key size (eg. 2048/3072/4096) * @return #GNUNET_OK on success, #GNUNET_NO if parameters were invalid */ enum GNUNET_GenericReturnValue @@ -990,7 +990,8 @@ TALER_denom_cs_derive_r_public (const struct TALER_WithdrawNonce *nonce, * @param[out] c_hash resulting hashed coin * @param[out] coin_ev blinded coin to submit * @param[out] coin_ev_size number of bytes in @a coin_ev - * @param ... cipher-specific parameters + * @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 @@ -1026,7 +1027,7 @@ TALER_denom_sign_blinded (struct TALER_BlindedDenominationSignature *denom_sig, * @param bdenom_sig the blinded signature * @param bks blinding secret to use * @param denom_pub public key used for signing - * @param ... cipher-specific parameters + * @param ... If CS algorithm, r_pub_blind (TALER_DenominationCsPublicR) is an additional param * @return #GNUNET_OK on success */ enum GNUNET_GenericReturnValue @@ -1405,7 +1406,8 @@ 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 ... cipher-specific parameters + * @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 @@ -1425,7 +1427,8 @@ 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 ... cipher-specific parameters + * @param ... If CS algorithm, r_pub_blind (TALER_DenominationCsPublicR) is an additional param + * @return #GNUNET_OK on success */ enum GNUNET_GenericReturnValue diff --git a/src/util/denom.c b/src/util/denom.c index 12b499aa0..4b62f4cc0 100644 --- a/src/util/denom.c +++ b/src/util/denom.c @@ -35,9 +35,6 @@ TALER_denom_priv_create (struct TALER_DenominationPrivateKey *denom_priv, 0, sizeof (*denom_pub)); - denom_priv->cipher = cipher; - denom_pub->cipher = cipher; - switch (cipher) { case TALER_DENOMINATION_INVALID: @@ -67,12 +64,16 @@ TALER_denom_priv_create (struct TALER_DenominationPrivateKey *denom_priv, denom_pub->details.rsa_public_key = GNUNET_CRYPTO_rsa_private_key_get_public ( denom_priv->details.rsa_private_key); + denom_priv->cipher = TALER_DENOMINATION_RSA; + denom_pub->cipher = TALER_DENOMINATION_RSA; return GNUNET_OK; case TALER_DENOMINATION_CS: GNUNET_CRYPTO_cs_private_key_generate (&denom_priv->details.cs_private_key); GNUNET_CRYPTO_cs_private_key_get_public ( &denom_priv->details.cs_private_key, &denom_pub->details.cs_public_key); + denom_priv->cipher = TALER_DENOMINATION_CS; + denom_pub->cipher = TALER_DENOMINATION_CS; return GNUNET_OK; default: GNUNET_break (0); @@ -296,7 +297,13 @@ TALER_denom_priv_to_pub (const struct TALER_DenominationPrivateKey *denom_priv, = GNUNET_CRYPTO_rsa_private_key_get_public ( denom_priv->details.rsa_private_key); return; - // TODO: add case for Clause-Schnorr + case TALER_DENOMINATION_CS: + denom_pub->cipher = TALER_DENOMINATION_CS; + denom_pub->age_mask = age_mask; + GNUNET_CRYPTO_cs_private_key_get_public ( + &denom_priv->details.cs_private_key, + &denom_pub->details.cs_public_key); + return; default: GNUNET_assert (0); } @@ -312,13 +319,14 @@ TALER_denom_blind (const struct TALER_DenominationPublicKey *dk, struct TALER_BlindedPlanchet *blinded_planchet, ...) { - blinded_planchet->cipher = dk->cipher; TALER_coin_pub_hash (coin_pub, age_commitment_hash, c_hash); switch (dk->cipher) { case TALER_DENOMINATION_RSA: + blinded_planchet->cipher = dk->cipher; + if (GNUNET_YES != GNUNET_CRYPTO_rsa_blind (&c_hash->hash, &coin_bks->rsa_bks, @@ -334,6 +342,7 @@ TALER_denom_blind (const struct TALER_DenominationPublicKey *dk, return GNUNET_OK; case TALER_DENOMINATION_CS: { + blinded_planchet->cipher = dk->cipher; va_list ap; va_start (ap, blinded_planchet); struct TALER_DenominationCsPublicR *r_pub; @@ -399,7 +408,6 @@ TALER_denom_pub_verify (const struct TALER_DenominationPublicKey *denom_pub, { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Coin signature is invalid\n"); - // return GNUNET_YES; return GNUNET_NO; } return GNUNET_YES; @@ -425,7 +433,7 @@ TALER_denom_pub_free (struct TALER_DenominationPublicKey *denom_pub) denom_pub->cipher = TALER_DENOMINATION_INVALID; return; case TALER_DENOMINATION_CS: - // TODO: ATM nothing needs to be freed, but check again after implementation. + // ATM nothing needs to be freed, but check again after implementation. return; default: GNUNET_assert (0); @@ -449,7 +457,7 @@ TALER_denom_priv_free (struct TALER_DenominationPrivateKey *denom_priv) denom_priv->cipher = TALER_DENOMINATION_INVALID; return; case TALER_DENOMINATION_CS: - // TODO: ATM nothing needs to be freed, but check again after implementation. + // ATM nothing needs to be freed, but check again after implementation. return; default: GNUNET_assert (0); @@ -473,7 +481,7 @@ TALER_denom_sig_free (struct TALER_DenominationSignature *denom_sig) denom_sig->cipher = TALER_DENOMINATION_INVALID; return; case TALER_DENOMINATION_CS: - // TODO: ATM nothing needs to be freed, but check again after implementation. + // ATM nothing needs to be freed, but check again after implementation. return; default: GNUNET_assert (0); @@ -499,7 +507,7 @@ TALER_blinded_denom_sig_free ( denom_sig->cipher = TALER_DENOMINATION_INVALID; return; case TALER_DENOMINATION_CS: - // TODO: ATM nothing needs to be freed, but check again after implementation. + // ATM nothing needs to be freed, but check again after implementation. return; default: GNUNET_assert (0); @@ -526,7 +534,9 @@ TALER_denom_pub_deep_copy (struct TALER_DenominationPublicKey *denom_dst, = GNUNET_CRYPTO_rsa_public_key_dup ( denom_src->details.rsa_public_key); return; - // TODO: add case for Clause-Schnorr + case TALER_DENOMINATION_CS: + // In Case of CS, the above is already a deep copy *denom_dst = *denom_src; + return; default: GNUNET_assert (0); } @@ -547,7 +557,9 @@ TALER_denom_sig_deep_copy (struct TALER_DenominationSignature *denom_dst, = GNUNET_CRYPTO_rsa_signature_dup ( denom_src->details.rsa_signature); return; - // TODO: add case for Clause-Schnorr + case TALER_DENOMINATION_CS: + // In Case of CS, the above is already a deep copy *denom_dst = *denom_src; + return; default: GNUNET_assert (0); } @@ -569,7 +581,9 @@ TALER_blinded_denom_sig_deep_copy ( = GNUNET_CRYPTO_rsa_signature_dup ( denom_src->details.blinded_rsa_signature); return; - // TODO: add case for Clause-Schnorr + case TALER_DENOMINATION_CS: + // In Case of CS, the above is already a deep copy *denom_dst = *denom_src; + return; default: GNUNET_assert (0); } @@ -591,7 +605,11 @@ TALER_denom_pub_cmp (const struct TALER_DenominationPublicKey *denom1, case TALER_DENOMINATION_RSA: return GNUNET_CRYPTO_rsa_public_key_cmp (denom1->details.rsa_public_key, denom2->details.rsa_public_key); - // TODO: add case for Clause-Schnorr + case TALER_DENOMINATION_CS: + return 0 == GNUNET_memcmp (&denom1->details.cs_public_key, + &denom2->details.cs_public_key) + ? GNUNET_OK + : GNUNET_SYSERR; default: GNUNET_assert (0); } @@ -612,7 +630,11 @@ TALER_denom_sig_cmp (const struct TALER_DenominationSignature *sig1, case TALER_DENOMINATION_RSA: return GNUNET_CRYPTO_rsa_signature_cmp (sig1->details.rsa_signature, sig2->details.rsa_signature); - // TODO: add case for Clause-Schnorr + case TALER_DENOMINATION_CS: + return 0 == GNUNET_memcmp (&sig1->details.cs_signature, + &sig2->details.cs_signature) + ? GNUNET_OK + : GNUNET_SYSERR; default: GNUNET_assert (0); } @@ -634,7 +656,11 @@ TALER_blinded_denom_sig_cmp ( case TALER_DENOMINATION_RSA: return GNUNET_CRYPTO_rsa_signature_cmp (sig1->details.blinded_rsa_signature, sig2->details.blinded_rsa_signature); - // TODO: add case for Clause-Schnorr + case TALER_DENOMINATION_CS: + return 0 == GNUNET_memcmp (&sig1->details.blinded_cs_answer, + &sig2->details.blinded_cs_answer) + ? GNUNET_OK + : GNUNET_SYSERR; default: GNUNET_assert (0); } -- cgit v1.2.3