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

View File

@ -1982,16 +1982,14 @@ TALER_CRYPTO_helper_cs_revoke (
* @param dh helper to process connection
* @param h_cs hash of the CS public key to revoke
* @param nonce witdhraw nonce
* @param[out] ec set to the error code (or #TALER_EC_NONE on success)
* @return R, the value inside the structure will be NULL on failure,
* see @a ec for details about the failure
* @param[out] crp set to the pair of R values
* @return set to the error code (or #TALER_EC_NONE on success)
*/
// FIXME: swap rval and ec!
struct TALER_DenominationCSPublicRPairP
enum TALER_ErrorCode
TALER_CRYPTO_helper_cs_r_derive (struct TALER_CRYPTO_CsDenominationHelper *dh,
const struct TALER_CsPubHashP *h_cs,
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,
const struct TALER_CsPubHashP *h_cs,
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,
sizeof (r_pub));
sizeof (*crp));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Starting R derivation process\n");
if (GNUNET_OK !=
@ -626,8 +625,7 @@ TALER_CRYPTO_helper_cs_r_derive (struct TALER_CRYPTO_CsDenominationHelper *dh,
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Failed to connect to helper\n");
*ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_UNAVAILABLE;
return r_pub;
return TALER_EC_EXCHANGE_DENOMINATION_HELPER_UNAVAILABLE;
}
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,
"send");
do_disconnect (dh);
*ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_UNAVAILABLE;
return r_pub;
return TALER_EC_EXCHANGE_DENOMINATION_HELPER_UNAVAILABLE;
}
}
@ -663,7 +660,6 @@ TALER_CRYPTO_helper_cs_r_derive (struct TALER_CRYPTO_CsDenominationHelper *dh,
= (const struct GNUNET_MessageHeader *) buf;
bool finished = false;
*ec = TALER_EC_INVALID;
while (1)
{
uint16_t msize;
@ -683,20 +679,19 @@ TALER_CRYPTO_helper_cs_r_derive (struct TALER_CRYPTO_CsDenominationHelper *dh,
{
GNUNET_assert (finished);
GNUNET_assert (0 == off);
return r_pub;
return ec;
}
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
"recv");
do_disconnect (dh);
*ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_UNAVAILABLE;
break;
return TALER_EC_EXCHANGE_DENOMINATION_HELPER_UNAVAILABLE;
}
if (0 == ret)
{
GNUNET_break (0 == off);
if (! finished)
*ec = TALER_EC_EXCHANGE_SIGNKEY_HELPER_BUG;
return r_pub;
return TALER_EC_EXCHANGE_SIGNKEY_HELPER_BUG;
return ec;
}
off += ret;
more:
@ -712,15 +707,13 @@ more:
{
GNUNET_break_op (0);
do_disconnect (dh);
*ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
goto end;
return TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
}
if (finished)
{
GNUNET_break_op (0);
do_disconnect (dh);
*ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
goto end;
return TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
}
{
const struct TALER_CRYPTO_RDeriveResponse *rdr =
@ -728,9 +721,9 @@ more:
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received R\n");
*ec = TALER_EC_NONE;
finished = true;
r_pub = rdr->r_pub;
ec = TALER_EC_NONE;
*crp = rdr->r_pub;
break;
}
case TALER_HELPER_CS_MT_RES_RDERIVE_FAILURE:
@ -738,14 +731,13 @@ more:
{
GNUNET_break_op (0);
do_disconnect (dh);
*ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
goto end;
return TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
}
{
const struct TALER_CRYPTO_RDeriveFailure *rdf =
(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,
"R derivation failed!\n");
finished = true;
@ -760,8 +752,7 @@ more:
{
GNUNET_break_op (0);
do_disconnect (dh);
*ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
goto end;
return TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
}
break; /* while(1) loop ensures we recvfrom() again */
case TALER_HELPER_CS_MT_PURGE:
@ -773,8 +764,7 @@ more:
{
GNUNET_break_op (0);
do_disconnect (dh);
*ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
goto end;
return TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
}
break; /* while(1) loop ensures we recvfrom() again */
case TALER_HELPER_CS_SYNCED:
@ -788,8 +778,7 @@ more:
"Received unexpected message of type %u\n",
ntohs (hdr->type));
do_disconnect (dh);
*ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
goto end;
return TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
}
memmove (buf,
&buf[msize],
@ -797,8 +786,6 @@ more:
off -= msize;
goto more;
} /* 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;
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++)
{
struct TALER_PlanchetDetail pd;
if (! keys[i].valid)
continue;
// TODO: insert assertion into other checks
GNUNET_assert (TALER_DENOMINATION_CS == keys[i].denom_pub.cipher);
{
pd.blinded_planchet.cipher = TALER_DENOMINATION_CS;
TALER_cs_withdraw_nonce_derive (&ps,
&pd.blinded_planchet.details.
cs_blinded_planchet.nonce);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Requesting R derivation with key %s\n",
GNUNET_h2s (&keys[i].h_cs.hash));
alg_values.details.cs_values
= TALER_CRYPTO_helper_cs_r_derive (dh,
&keys[i].h_cs,
&pd.blinded_planchet.
details.
cs_blinded_planchet.nonce,
&ec);
}
GNUNET_assert (TALER_DENOMINATION_CS ==
keys[i].denom_pub.cipher);
pd.blinded_planchet.cipher = TALER_DENOMINATION_CS;
TALER_cs_withdraw_nonce_derive (
&ps,
&pd.blinded_planchet.details.cs_blinded_planchet.nonce);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Requesting R derivation with key %s\n",
GNUNET_h2s (&keys[i].h_cs.hash));
alg_values.cipher = TALER_DENOMINATION_CS;
ec = TALER_CRYPTO_helper_cs_r_derive (
dh,
&keys[i].h_cs,
&pd.blinded_planchet.details.cs_blinded_planchet.nonce,
&alg_values.details.cs_values);
switch (ec)
{
case TALER_EC_NONE:
@ -330,7 +320,9 @@ test_r_derive (struct TALER_CRYPTO_CsDenominationHelper *dh)
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Received valid R for key %s\n",
GNUNET_h2s (&keys[i].h_cs.hash));
TALER_planchet_setup_coin_priv (&ps,
&alg_values,
&coin_priv);
TALER_planchet_blinding_secret_create (&ps,
&alg_values,
&bks);
@ -381,6 +373,7 @@ test_r_derive (struct TALER_CRYPTO_CsDenominationHelper *dh)
{
struct TALER_CsPubHashP rnd;
struct TALER_CsNonce nonce;
struct TALER_DenominationCSPublicRPairP crp;
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
&rnd,
@ -388,10 +381,10 @@ test_r_derive (struct TALER_CRYPTO_CsDenominationHelper *dh)
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
&nonce,
sizeof (nonce));
TALER_CRYPTO_helper_cs_r_derive (dh,
&rnd,
&nonce,
&ec);
ec = TALER_CRYPTO_helper_cs_r_derive (dh,
&rnd,
&nonce,
&crp);
if (TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN != ec)
{
GNUNET_break (0);
@ -424,29 +417,31 @@ test_signing (struct TALER_CRYPTO_CsDenominationHelper *dh)
struct TALER_ExchangeWithdrawValues alg_values;
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++)
{
if (! keys[i].valid)
continue;
{
struct TALER_PlanchetDetail pd;
pd.blinded_planchet.cipher = TALER_DENOMINATION_CS;
// keys[i].denom_pub.cipher = TALER_DENOMINATION_CS;
TALER_cs_withdraw_nonce_derive (&ps,
&pd.blinded_planchet.details.
cs_blinded_planchet.nonce);
alg_values.details.cs_values
= TALER_CRYPTO_helper_cs_r_derive (dh,
&keys[i].h_cs,
&pd.blinded_planchet.
details.
cs_blinded_planchet.nonce,
&ec);
alg_values.cipher = TALER_DENOMINATION_CS;
ec = TALER_CRYPTO_helper_cs_r_derive (dh,
&keys[i].h_cs,
&pd.blinded_planchet.
details.
cs_blinded_planchet.nonce,
&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,
&alg_values,
&bks);
@ -596,13 +591,6 @@ perf_signing (struct TALER_CRYPTO_CsDenominationHelper *dh,
struct TALER_ExchangeWithdrawValues alg_values;
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;
TALER_CRYPTO_helper_cs_poll (dh);
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,
&pd.blinded_planchet.details.
cs_blinded_planchet.nonce);
alg_values.details.cs_values
= TALER_CRYPTO_helper_cs_r_derive (dh,
&keys[i].h_cs,
&pd.blinded_planchet.
details.
cs_blinded_planchet.nonce,
&ec);
alg_values.cipher = TALER_DENOMINATION_CS;
ec = TALER_CRYPTO_helper_cs_r_derive (dh,
&keys[i].h_cs,
&pd.blinded_planchet.
details.
cs_blinded_planchet.nonce,
&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,
&alg_values,
&bks);
GNUNET_assert (GNUNET_YES ==
TALER_planchet_prepare (&keys[i].denom_pub,
&alg_values,