-fix use of uninit memory in test

This commit is contained in:
Christian Grothoff 2022-02-11 17:44:18 +01:00
parent 0eb5b08d50
commit 9f77398fe2
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
4 changed files with 77 additions and 103 deletions

View File

@ -2473,7 +2473,6 @@ TEH_keys_denomination_cs_r_pub (const struct
{ {
struct TEH_KeyStateHandle *ksh; struct TEH_KeyStateHandle *ksh;
struct HelperDenomination *hd; struct HelperDenomination *hd;
enum TALER_ErrorCode r_derive_ec;
ksh = TEH_keys_get_state (); ksh = TEH_keys_get_state ();
if (NULL == ksh) if (NULL == ksh)
@ -2491,11 +2490,10 @@ TEH_keys_denomination_cs_r_pub (const struct
return TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE; return TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE;
} }
*r_pub = TALER_CRYPTO_helper_cs_r_derive (ksh->helpers->csdh, return TALER_CRYPTO_helper_cs_r_derive (ksh->helpers->csdh,
&hd->h_details.h_cs, &hd->h_details.h_cs,
nonce, nonce,
&r_derive_ec); r_pub);
return r_derive_ec;
} }

View File

@ -1982,16 +1982,14 @@ TALER_CRYPTO_helper_cs_revoke (
* @param dh helper to process connection * @param dh helper to process connection
* @param h_cs hash of the CS public key to revoke * @param h_cs hash of the CS public key to revoke
* @param nonce witdhraw nonce * @param nonce witdhraw nonce
* @param[out] ec set to the error code (or #TALER_EC_NONE on success) * @param[out] crp set to the pair of R values
* @return R, the value inside the structure will be NULL on failure, * @return set to the error code (or #TALER_EC_NONE on success)
* see @a ec for details about the failure
*/ */
// FIXME: swap rval and ec! enum TALER_ErrorCode
struct TALER_DenominationCSPublicRPairP
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_CsNonce *nonce, const struct TALER_CsNonce *nonce,
enum TALER_ErrorCode *ec); struct TALER_DenominationCSPublicRPairP *crp);
/** /**

View File

@ -607,18 +607,17 @@ TALER_CRYPTO_helper_cs_revoke (
} }
struct TALER_DenominationCSPublicRPairP enum TALER_ErrorCode
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_CsNonce *nonce, const struct TALER_CsNonce *nonce,
enum TALER_ErrorCode *ec) struct TALER_DenominationCSPublicRPairP *crp)
{ {
struct TALER_DenominationCSPublicRPairP r_pub; enum TALER_ErrorCode ec = TALER_EC_INVALID;
memset (&r_pub, memset (crp,
0, 0,
sizeof (r_pub)); sizeof (*crp));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Starting R derivation process\n"); "Starting R derivation process\n");
if (GNUNET_OK != if (GNUNET_OK !=
@ -626,8 +625,7 @@ TALER_CRYPTO_helper_cs_r_derive (struct TALER_CRYPTO_CsDenominationHelper *dh,
{ {
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Failed to connect to helper\n"); "Failed to connect to helper\n");
*ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_UNAVAILABLE; return TALER_EC_EXCHANGE_DENOMINATION_HELPER_UNAVAILABLE;
return r_pub;
} }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@ -649,8 +647,7 @@ TALER_CRYPTO_helper_cs_r_derive (struct TALER_CRYPTO_CsDenominationHelper *dh,
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
"send"); "send");
do_disconnect (dh); do_disconnect (dh);
*ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_UNAVAILABLE; return TALER_EC_EXCHANGE_DENOMINATION_HELPER_UNAVAILABLE;
return r_pub;
} }
} }
@ -663,7 +660,6 @@ TALER_CRYPTO_helper_cs_r_derive (struct TALER_CRYPTO_CsDenominationHelper *dh,
= (const struct GNUNET_MessageHeader *) buf; = (const struct GNUNET_MessageHeader *) buf;
bool finished = false; bool finished = false;
*ec = TALER_EC_INVALID;
while (1) while (1)
{ {
uint16_t msize; uint16_t msize;
@ -683,20 +679,19 @@ TALER_CRYPTO_helper_cs_r_derive (struct TALER_CRYPTO_CsDenominationHelper *dh,
{ {
GNUNET_assert (finished); GNUNET_assert (finished);
GNUNET_assert (0 == off); GNUNET_assert (0 == off);
return r_pub; return ec;
} }
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
"recv"); "recv");
do_disconnect (dh); do_disconnect (dh);
*ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_UNAVAILABLE; return TALER_EC_EXCHANGE_DENOMINATION_HELPER_UNAVAILABLE;
break;
} }
if (0 == ret) if (0 == ret)
{ {
GNUNET_break (0 == off); GNUNET_break (0 == off);
if (! finished) if (! finished)
*ec = TALER_EC_EXCHANGE_SIGNKEY_HELPER_BUG; return TALER_EC_EXCHANGE_SIGNKEY_HELPER_BUG;
return r_pub; return ec;
} }
off += ret; off += ret;
more: more:
@ -712,15 +707,13 @@ more:
{ {
GNUNET_break_op (0); GNUNET_break_op (0);
do_disconnect (dh); do_disconnect (dh);
*ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG; return TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
goto end;
} }
if (finished) if (finished)
{ {
GNUNET_break_op (0); GNUNET_break_op (0);
do_disconnect (dh); do_disconnect (dh);
*ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG; return TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
goto end;
} }
{ {
const struct TALER_CRYPTO_RDeriveResponse *rdr = const struct TALER_CRYPTO_RDeriveResponse *rdr =
@ -728,9 +721,9 @@ more:
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received R\n"); "Received R\n");
*ec = TALER_EC_NONE;
finished = true; finished = true;
r_pub = rdr->r_pub; ec = TALER_EC_NONE;
*crp = rdr->r_pub;
break; break;
} }
case TALER_HELPER_CS_MT_RES_RDERIVE_FAILURE: case TALER_HELPER_CS_MT_RES_RDERIVE_FAILURE:
@ -738,14 +731,13 @@ more:
{ {
GNUNET_break_op (0); GNUNET_break_op (0);
do_disconnect (dh); do_disconnect (dh);
*ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG; return TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
goto end;
} }
{ {
const struct TALER_CRYPTO_RDeriveFailure *rdf = const struct TALER_CRYPTO_RDeriveFailure *rdf =
(const struct TALER_CRYPTO_RDeriveFailure *) buf; (const struct TALER_CRYPTO_RDeriveFailure *) buf;
*ec = (enum TALER_ErrorCode) ntohl (rdf->ec); ec = (enum TALER_ErrorCode) ntohl (rdf->ec);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"R derivation failed!\n"); "R derivation failed!\n");
finished = true; finished = true;
@ -760,8 +752,7 @@ more:
{ {
GNUNET_break_op (0); GNUNET_break_op (0);
do_disconnect (dh); do_disconnect (dh);
*ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG; return TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
goto end;
} }
break; /* while(1) loop ensures we recvfrom() again */ break; /* while(1) loop ensures we recvfrom() again */
case TALER_HELPER_CS_MT_PURGE: case TALER_HELPER_CS_MT_PURGE:
@ -773,8 +764,7 @@ more:
{ {
GNUNET_break_op (0); GNUNET_break_op (0);
do_disconnect (dh); do_disconnect (dh);
*ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG; return TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
goto end;
} }
break; /* while(1) loop ensures we recvfrom() again */ break; /* while(1) loop ensures we recvfrom() again */
case TALER_HELPER_CS_SYNCED: case TALER_HELPER_CS_SYNCED:
@ -788,8 +778,7 @@ more:
"Received unexpected message of type %u\n", "Received unexpected message of type %u\n",
ntohs (hdr->type)); ntohs (hdr->type));
do_disconnect (dh); do_disconnect (dh);
*ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG; return TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
goto end;
} }
memmove (buf, memmove (buf,
&buf[msize], &buf[msize],
@ -797,8 +786,6 @@ more:
off -= msize; off -= msize;
goto more; goto more;
} /* while(1) */ } /* while(1) */
end:
return r_pub;
} }
} }

View File

@ -273,38 +273,28 @@ test_r_derive (struct TALER_CRYPTO_CsDenominationHelper *dh)
struct TALER_ExchangeWithdrawValues alg_values; struct TALER_ExchangeWithdrawValues alg_values;
TALER_planchet_master_setup_random (&ps); TALER_planchet_master_setup_random (&ps);
alg_values.cipher = TALER_DENOMINATION_CS;
TALER_planchet_setup_coin_priv (&ps,
&alg_values,
&coin_priv);
TALER_planchet_blinding_secret_create (&ps,
&alg_values,
&bks);
for (unsigned int i = 0; i<MAX_KEYS; i++) for (unsigned int i = 0; i<MAX_KEYS; i++)
{ {
struct TALER_PlanchetDetail pd; struct TALER_PlanchetDetail pd;
if (! keys[i].valid) if (! keys[i].valid)
continue; continue;
// TODO: insert assertion into other checks // TODO: insert assertion into other checks
GNUNET_assert (TALER_DENOMINATION_CS == keys[i].denom_pub.cipher); GNUNET_assert (TALER_DENOMINATION_CS ==
{ keys[i].denom_pub.cipher);
pd.blinded_planchet.cipher = TALER_DENOMINATION_CS; pd.blinded_planchet.cipher = TALER_DENOMINATION_CS;
TALER_cs_withdraw_nonce_derive (
TALER_cs_withdraw_nonce_derive (&ps, &ps,
&pd.blinded_planchet.details. &pd.blinded_planchet.details.cs_blinded_planchet.nonce);
cs_blinded_planchet.nonce); GNUNET_log (GNUNET_ERROR_TYPE_INFO,
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Requesting R derivation with key %s\n",
"Requesting R derivation with key %s\n", GNUNET_h2s (&keys[i].h_cs.hash));
GNUNET_h2s (&keys[i].h_cs.hash)); alg_values.cipher = TALER_DENOMINATION_CS;
ec = TALER_CRYPTO_helper_cs_r_derive (
alg_values.details.cs_values dh,
= TALER_CRYPTO_helper_cs_r_derive (dh, &keys[i].h_cs,
&keys[i].h_cs, &pd.blinded_planchet.details.cs_blinded_planchet.nonce,
&pd.blinded_planchet. &alg_values.details.cs_values);
details.
cs_blinded_planchet.nonce,
&ec);
}
switch (ec) switch (ec)
{ {
case TALER_EC_NONE: case TALER_EC_NONE:
@ -330,7 +320,9 @@ test_r_derive (struct TALER_CRYPTO_CsDenominationHelper *dh)
GNUNET_log (GNUNET_ERROR_TYPE_INFO, GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Received valid R for key %s\n", "Received valid R for key %s\n",
GNUNET_h2s (&keys[i].h_cs.hash)); GNUNET_h2s (&keys[i].h_cs.hash));
TALER_planchet_setup_coin_priv (&ps,
&alg_values,
&coin_priv);
TALER_planchet_blinding_secret_create (&ps, TALER_planchet_blinding_secret_create (&ps,
&alg_values, &alg_values,
&bks); &bks);
@ -381,6 +373,7 @@ test_r_derive (struct TALER_CRYPTO_CsDenominationHelper *dh)
{ {
struct TALER_CsPubHashP rnd; struct TALER_CsPubHashP rnd;
struct TALER_CsNonce nonce; struct TALER_CsNonce nonce;
struct TALER_DenominationCSPublicRPairP crp;
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
&rnd, &rnd,
@ -388,10 +381,10 @@ test_r_derive (struct TALER_CRYPTO_CsDenominationHelper *dh)
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
&nonce, &nonce,
sizeof (nonce)); sizeof (nonce));
TALER_CRYPTO_helper_cs_r_derive (dh, ec = TALER_CRYPTO_helper_cs_r_derive (dh,
&rnd, &rnd,
&nonce, &nonce,
&ec); &crp);
if (TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN != ec) if (TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN != ec)
{ {
GNUNET_break (0); GNUNET_break (0);
@ -424,29 +417,31 @@ test_signing (struct TALER_CRYPTO_CsDenominationHelper *dh)
struct TALER_ExchangeWithdrawValues alg_values; struct TALER_ExchangeWithdrawValues alg_values;
TALER_planchet_master_setup_random (&ps); TALER_planchet_master_setup_random (&ps);
alg_values.cipher = TALER_DENOMINATION_CS;
TALER_planchet_setup_coin_priv (&ps, &alg_values, &coin_priv);
TALER_planchet_blinding_secret_create (&ps, &alg_values, &bks);
for (unsigned int i = 0; i<MAX_KEYS; i++) for (unsigned int i = 0; i<MAX_KEYS; i++)
{ {
if (! keys[i].valid) if (! keys[i].valid)
continue; continue;
{ {
struct TALER_PlanchetDetail pd; struct TALER_PlanchetDetail pd;
pd.blinded_planchet.cipher = TALER_DENOMINATION_CS; pd.blinded_planchet.cipher = TALER_DENOMINATION_CS;
// keys[i].denom_pub.cipher = TALER_DENOMINATION_CS; // keys[i].denom_pub.cipher = TALER_DENOMINATION_CS;
TALER_cs_withdraw_nonce_derive (&ps, TALER_cs_withdraw_nonce_derive (&ps,
&pd.blinded_planchet.details. &pd.blinded_planchet.details.
cs_blinded_planchet.nonce); cs_blinded_planchet.nonce);
alg_values.details.cs_values alg_values.cipher = TALER_DENOMINATION_CS;
= TALER_CRYPTO_helper_cs_r_derive (dh, ec = TALER_CRYPTO_helper_cs_r_derive (dh,
&keys[i].h_cs, &keys[i].h_cs,
&pd.blinded_planchet. &pd.blinded_planchet.
details. details.
cs_blinded_planchet.nonce, cs_blinded_planchet.nonce,
&ec); &alg_values.details.cs_values);
if (TALER_EC_NONE != ec)
continue;
TALER_planchet_setup_coin_priv (&ps,
&alg_values,
&coin_priv);
TALER_planchet_blinding_secret_create (&ps, TALER_planchet_blinding_secret_create (&ps,
&alg_values, &alg_values,
&bks); &bks);
@ -596,13 +591,6 @@ perf_signing (struct TALER_CRYPTO_CsDenominationHelper *dh,
struct TALER_ExchangeWithdrawValues alg_values; struct TALER_ExchangeWithdrawValues alg_values;
TALER_planchet_master_setup_random (&ps); TALER_planchet_master_setup_random (&ps);
alg_values.cipher = TALER_DENOMINATION_CS;
TALER_planchet_setup_coin_priv (&ps,
&alg_values,
&coin_priv);
TALER_planchet_blinding_secret_create (&ps,
&alg_values,
&bks);
duration = GNUNET_TIME_UNIT_ZERO; duration = GNUNET_TIME_UNIT_ZERO;
TALER_CRYPTO_helper_cs_poll (dh); TALER_CRYPTO_helper_cs_poll (dh);
for (unsigned int j = 0; j<NUM_SIGN_PERFS;) for (unsigned int j = 0; j<NUM_SIGN_PERFS;)
@ -629,18 +617,21 @@ perf_signing (struct TALER_CRYPTO_CsDenominationHelper *dh,
TALER_cs_withdraw_nonce_derive (&ps, TALER_cs_withdraw_nonce_derive (&ps,
&pd.blinded_planchet.details. &pd.blinded_planchet.details.
cs_blinded_planchet.nonce); cs_blinded_planchet.nonce);
alg_values.cipher = TALER_DENOMINATION_CS;
alg_values.details.cs_values ec = TALER_CRYPTO_helper_cs_r_derive (dh,
= TALER_CRYPTO_helper_cs_r_derive (dh, &keys[i].h_cs,
&keys[i].h_cs, &pd.blinded_planchet.
&pd.blinded_planchet. details.
details. cs_blinded_planchet.nonce,
cs_blinded_planchet.nonce, &alg_values.details.cs_values);
&ec); if (TALER_EC_NONE != ec)
continue;
TALER_planchet_setup_coin_priv (&ps,
&alg_values,
&coin_priv);
TALER_planchet_blinding_secret_create (&ps, TALER_planchet_blinding_secret_create (&ps,
&alg_values, &alg_values,
&bks); &bks);
GNUNET_assert (GNUNET_YES == GNUNET_assert (GNUNET_YES ==
TALER_planchet_prepare (&keys[i].denom_pub, TALER_planchet_prepare (&keys[i].denom_pub,
&alg_values, &alg_values,