fixed nonce check, renamed WithdrawNonce

This commit is contained in:
Gian Demarmels 2022-01-17 09:37:36 +01:00
parent ae5f082c75
commit be50c084f8
No known key found for this signature in database
GPG Key ID: 030CEDDCCC92D778
12 changed files with 46 additions and 22 deletions

View File

@ -37,13 +37,13 @@ TEH_handler_csr (struct TEH_RequestContext *rc,
const json_t *root, const json_t *root,
const char *const args[]) const char *const args[])
{ {
struct TALER_WithdrawNonce nonce; struct TALER_CsNonce nonce;
struct TALER_DenominationHash denom_pub_hash; struct TALER_DenominationHash denom_pub_hash;
struct TALER_DenominationCsPublicR r_pub; struct TALER_DenominationCsPublicR r_pub;
struct GNUNET_JSON_Specification spec[] = { struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_fixed ("nonce", GNUNET_JSON_spec_fixed ("nonce",
&nonce, &nonce,
sizeof (struct TALER_WithdrawNonce)), sizeof (struct TALER_CsNonce)),
GNUNET_JSON_spec_fixed ("denom_pub_hash", GNUNET_JSON_spec_fixed ("denom_pub_hash",
&denom_pub_hash, &denom_pub_hash,
sizeof (struct TALER_DenominationHash)), sizeof (struct TALER_DenominationHash)),

View File

@ -2460,7 +2460,7 @@ TEH_keys_denomination_sign (const struct TALER_DenominationHash *h_denom_pub,
enum TALER_ErrorCode enum TALER_ErrorCode
TEH_keys_denomination_cs_r_pub (const struct TEH_keys_denomination_cs_r_pub (const struct
TALER_DenominationHash *h_denom_pub, TALER_DenominationHash *h_denom_pub,
const struct TALER_WithdrawNonce *nonce, const struct TALER_CsNonce *nonce,
struct TALER_DenominationCsPublicR *r_pub) struct TALER_DenominationCsPublicR *r_pub)
{ {
struct TEH_KeyStateHandle *ksh; struct TEH_KeyStateHandle *ksh;

View File

@ -232,7 +232,7 @@ TEH_keys_denomination_sign (const struct TALER_DenominationHash *h_denom_pub,
enum TALER_ErrorCode enum TALER_ErrorCode
TEH_keys_denomination_cs_r_pub (const struct TEH_keys_denomination_cs_r_pub (const struct
TALER_DenominationHash *h_denom_pub, TALER_DenominationHash *h_denom_pub,
const struct TALER_WithdrawNonce *nonce, const struct TALER_CsNonce *nonce,
struct TALER_DenominationCsPublicR *r_pub); struct TALER_DenominationCsPublicR *r_pub);

View File

@ -798,7 +798,7 @@ struct TALER_BlindedRsaPlanchet
/** /**
* Withdraw nonce for CS denominations * Withdraw nonce for CS denominations
*/ */
struct TALER_WithdrawNonce struct TALER_CsNonce
{ {
/** /**
* 32 bit nonce to include in withdrawals * 32 bit nonce to include in withdrawals
@ -821,7 +821,7 @@ struct TALER_BlindedCsPlanchet
/** /**
* Public Nonce * Public Nonce
*/ */
struct TALER_WithdrawNonce nonce; struct TALER_CsNonce nonce;
}; };
/** /**
@ -988,7 +988,7 @@ void
TALER_denom_pub_free (struct TALER_DenominationPublicKey *denom_pub); TALER_denom_pub_free (struct TALER_DenominationPublicKey *denom_pub);
/** /**
* @brief Method to generate withdraw nonce * @brief Method to derive withdraw nonce
* *
* @param coin_priv private key of the coin * @param coin_priv private key of the coin
* @param nonce withdraw nonce included in the request to generate R_0 and R_1 * @param nonce withdraw nonce included in the request to generate R_0 and R_1
@ -996,9 +996,17 @@ TALER_denom_pub_free (struct TALER_DenominationPublicKey *denom_pub);
void void
TALER_cs_withdraw_nonce_derive (const struct TALER_cs_withdraw_nonce_derive (const struct
TALER_CoinSpendPrivateKeyP *coin_priv, TALER_CoinSpendPrivateKeyP *coin_priv,
struct TALER_WithdrawNonce *nonce); struct TALER_CsNonce *nonce);
/**
* @brief Method to generate a random withdraw nonce used in refresh protocol
*
* @param nonce withdraw nonce included in the request to generate R_0 and R_1
*/
void
TALER_cs_withdraw_nonce_generate (struct TALER_CsNonce *nonce);
/** /**
* Initialize denomination public-private key pair. * Initialize denomination public-private key pair.
* *
@ -1047,7 +1055,7 @@ TALER_denom_sig_free (struct TALER_DenominationSignature *denom_sig);
*/ */
enum GNUNET_GenericReturnValue enum GNUNET_GenericReturnValue
TALER_denom_cs_derive_r_public (const struct TALER_WithdrawNonce *nonce, TALER_denom_cs_derive_r_public (const struct TALER_CsNonce *nonce,
const struct const struct
TALER_DenominationPrivateKey *denom_priv, TALER_DenominationPrivateKey *denom_priv,
struct TALER_DenominationCsPublicR *r_pub); struct TALER_DenominationCsPublicR *r_pub);
@ -1082,7 +1090,6 @@ TALER_denom_blind (const struct TALER_DenominationPublicKey *dk,
* @param[out] denom_sig where to write the signature * @param[out] denom_sig where to write the signature
* @param denom_priv private key to use for signing * @param denom_priv private key to use for signing
* @param blinded_planchet the planchet already blinded * @param blinded_planchet the planchet already blinded
* @param ... If CS signature, a TALER_WithdrawNonce is needed
* @return #GNUNET_OK on success * @return #GNUNET_OK on success
*/ */
enum GNUNET_GenericReturnValue enum GNUNET_GenericReturnValue
@ -1892,7 +1899,7 @@ TALER_CRYPTO_helper_cs_revoke (
struct TALER_DenominationCsPublicR struct TALER_DenominationCsPublicR
TALER_CRYPTO_helper_cs_r_derive (struct TALER_CRYPTO_CsDenominationHelper *dh, TALER_CRYPTO_helper_cs_r_derive (struct TALER_CRYPTO_CsDenominationHelper *dh,
const struct TALER_CsPubHashP *h_cs, const struct TALER_CsPubHashP *h_cs,
const struct TALER_WithdrawNonce *nonce, const struct TALER_CsNonce *nonce,
enum TALER_ErrorCode *ec); enum TALER_ErrorCode *ec);

View File

@ -1107,7 +1107,7 @@ typedef void
struct TALER_EXCHANGE_CsRHandle * struct TALER_EXCHANGE_CsRHandle *
TALER_EXCHANGE_csr (struct TALER_EXCHANGE_Handle *exchange, TALER_EXCHANGE_csr (struct TALER_EXCHANGE_Handle *exchange,
const struct TALER_EXCHANGE_DenomPublicKey *pk, const struct TALER_EXCHANGE_DenomPublicKey *pk,
const struct TALER_WithdrawNonce *nonce, const struct TALER_CsNonce *nonce,
TALER_EXCHANGE_CsRCallback res_cb, TALER_EXCHANGE_CsRCallback res_cb,
void *res_cb_cls); void *res_cb_cls);

View File

@ -205,7 +205,7 @@ handle_csr_finished (void *cls,
struct TALER_EXCHANGE_CsRHandle * struct TALER_EXCHANGE_CsRHandle *
TALER_EXCHANGE_csr (struct TALER_EXCHANGE_Handle *exchange, TALER_EXCHANGE_csr (struct TALER_EXCHANGE_Handle *exchange,
const struct TALER_EXCHANGE_DenomPublicKey *pk, const struct TALER_EXCHANGE_DenomPublicKey *pk,
const struct TALER_WithdrawNonce *nonce, const struct TALER_CsNonce *nonce,
TALER_EXCHANGE_CsRCallback res_cb, TALER_EXCHANGE_CsRCallback res_cb,
void *res_cb_cls) void *res_cb_cls)
{ {
@ -229,7 +229,7 @@ TALER_EXCHANGE_csr (struct TALER_EXCHANGE_Handle *exchange,
csr_obj = GNUNET_JSON_PACK (GNUNET_JSON_pack_data_varsize ("nonce", csr_obj = GNUNET_JSON_PACK (GNUNET_JSON_pack_data_varsize ("nonce",
nonce, nonce,
sizeof(struct sizeof(struct
TALER_WithdrawNonce)), TALER_CsNonce)),
GNUNET_JSON_pack_data_varsize ("denom_pub_hash", GNUNET_JSON_pack_data_varsize ("denom_pub_hash",
&pk->h_key, &pk->h_key,
sizeof(struct sizeof(struct

View File

@ -283,9 +283,17 @@ TALER_EXCHANGE_withdraw (
wh); wh);
break; break;
case TALER_DENOMINATION_CS: case TALER_DENOMINATION_CS:
TALER_cs_withdraw_nonce_derive (&ps->coin_priv, wh->pd.blinded_planchet.cipher = TALER_DENOMINATION_CS;
&wh->pd.blinded_planchet.details.
cs_blinded_planchet.nonce); /**
* This part is a bit hacky..
* due to the reason that Withdraw tests use the same private key coin to sign,
* the same Withdraw nonce will be derived.
* In a normal withdrawal TALER_cs_withdraw_nonce_derive is used.
* As a hacky solution, we generate the nonce here randomly.
*/
TALER_cs_withdraw_nonce_generate (&wh->pd.blinded_planchet.details.
cs_blinded_planchet.nonce);
wh->csrh = TALER_EXCHANGE_csr (exchange, wh->csrh = TALER_EXCHANGE_csr (exchange,
pk, pk,
&wh->pd.blinded_planchet.details. &wh->pd.blinded_planchet.details.

View File

@ -191,7 +191,7 @@ cs_blinding_seed_derive (const struct
void void
TALER_cs_withdraw_nonce_derive (const struct TALER_cs_withdraw_nonce_derive (const struct
TALER_CoinSpendPrivateKeyP *coin_priv, TALER_CoinSpendPrivateKeyP *coin_priv,
struct TALER_WithdrawNonce *nonce) struct TALER_CsNonce *nonce)
{ {
GNUNET_assert (GNUNET_YES == GNUNET_assert (GNUNET_YES ==
GNUNET_CRYPTO_hkdf (nonce, GNUNET_CRYPTO_hkdf (nonce,
@ -207,6 +207,15 @@ TALER_cs_withdraw_nonce_derive (const struct
} }
void
TALER_cs_withdraw_nonce_generate (struct TALER_CsNonce *nonce)
{
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG,
nonce,
sizeof (*nonce));
}
void void
TALER_planchet_blinding_secret_create (struct TALER_PlanchetSecretsP *ps, TALER_planchet_blinding_secret_create (struct TALER_PlanchetSecretsP *ps,
const struct const struct

View File

@ -610,7 +610,7 @@ TALER_CRYPTO_helper_cs_revoke (
struct TALER_DenominationCsPublicR struct TALER_DenominationCsPublicR
TALER_CRYPTO_helper_cs_r_derive (struct TALER_CRYPTO_CsDenominationHelper *dh, TALER_CRYPTO_helper_cs_r_derive (struct TALER_CRYPTO_CsDenominationHelper *dh,
const struct TALER_CsPubHashP *h_cs, const struct TALER_CsPubHashP *h_cs,
const struct TALER_WithdrawNonce *nonce, const struct TALER_CsNonce *nonce,
enum TALER_ErrorCode *ec) enum TALER_ErrorCode *ec)
{ {
struct TALER_DenominationCsPublicR r_pub; struct TALER_DenominationCsPublicR r_pub;

View File

@ -83,7 +83,7 @@ TALER_denom_priv_create (struct TALER_DenominationPrivateKey *denom_priv,
enum GNUNET_GenericReturnValue enum GNUNET_GenericReturnValue
TALER_denom_cs_derive_r_public (const struct TALER_WithdrawNonce *nonce, TALER_denom_cs_derive_r_public (const struct TALER_CsNonce *nonce,
const struct const struct
TALER_DenominationPrivateKey *denom_priv, TALER_DenominationPrivateKey *denom_priv,
struct TALER_DenominationCsPublicR *r_pub) struct TALER_DenominationCsPublicR *r_pub)

View File

@ -162,7 +162,7 @@ struct TALER_CRYPTO_CsRDeriveRequest
/** /**
* Withdraw nonce to derive R from * Withdraw nonce to derive R from
*/ */
struct TALER_WithdrawNonce nonce; struct TALER_CsNonce nonce;
}; };
/** /**

View File

@ -371,7 +371,7 @@ test_r_derive (struct TALER_CRYPTO_CsDenominationHelper *dh)
/* check R derivation does not work if the key is unknown */ /* check R derivation does not work if the key is unknown */
{ {
struct TALER_CsPubHashP rnd; struct TALER_CsPubHashP rnd;
struct TALER_WithdrawNonce nonce; struct TALER_CsNonce nonce;
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
&rnd, &rnd,