-swap argument/rval for nicer code

This commit is contained in:
Christian Grothoff 2022-02-12 11:42:25 +01:00
parent 8a3e88fbf1
commit ea4be7ba6f
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
9 changed files with 94 additions and 122 deletions

View File

@ -2411,54 +2411,40 @@ TEH_keys_denomination_by_hash2 (
}
struct TALER_BlindedDenominationSignature
enum TALER_ErrorCode
TEH_keys_denomination_sign (const struct TALER_DenominationHash *h_denom_pub,
const struct TALER_BlindedPlanchet *bp,
enum TALER_ErrorCode *ec)
struct TALER_BlindedDenominationSignature *bs)
{
struct TEH_KeyStateHandle *ksh;
struct TALER_BlindedDenominationSignature none;
struct HelperDenomination *hd;
memset (&none,
0,
sizeof (none));
ksh = TEH_keys_get_state ();
if (NULL == ksh)
{
*ec = TALER_EC_EXCHANGE_GENERIC_KEYS_MISSING;
return none;
}
return TALER_EC_EXCHANGE_GENERIC_KEYS_MISSING;
hd = GNUNET_CONTAINER_multihashmap_get (ksh->helpers->denom_keys,
&h_denom_pub->hash);
if (NULL == hd)
{
*ec = TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN;
return none;
}
return TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN;
if (bp->cipher != hd->denom_pub.cipher)
{
*ec = TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE;
return none;
}
return TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE;
switch (hd->denom_pub.cipher)
{
case TALER_DENOMINATION_RSA:
return TALER_CRYPTO_helper_rsa_sign (ksh->helpers->rsadh,
&hd->h_details.h_rsa,
bp->details.rsa_blinded_planchet.
blinded_msg,
bp->details.rsa_blinded_planchet.
blinded_msg_size,
ec);
return TALER_CRYPTO_helper_rsa_sign (
ksh->helpers->rsadh,
&hd->h_details.h_rsa,
bp->details.rsa_blinded_planchet.blinded_msg,
bp->details.rsa_blinded_planchet.blinded_msg_size,
bs);
case TALER_DENOMINATION_CS:
return TALER_CRYPTO_helper_cs_sign (ksh->helpers->csdh,
&hd->h_details.h_cs,
&bp->details.cs_blinded_planchet,
ec);
return TALER_CRYPTO_helper_cs_sign (
ksh->helpers->csdh,
&hd->h_details.h_cs,
&bp->details.cs_blinded_planchet,
bs);
default:
*ec = TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE;
return none;
return TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE;
}
}

View File

@ -173,14 +173,13 @@ TEH_keys_denomination_by_hash2 (
*
* @param h_denom_pub hash of the public key to use to sign
* @param bp blinded planchet to sign
* @param[out] ec set to the error code (or #TALER_EC_NONE on success)
* @return signature, the value inside the structure will be NULL on failure,
* see @a ec for details about the failure
* @param[out] bs set to the blind signature on success
* @return #TALER_EC_NONE on success
*/
struct TALER_BlindedDenominationSignature
enum TALER_ErrorCode
TEH_keys_denomination_sign (const struct TALER_DenominationHash *h_denom_pub,
const struct TALER_BlindedPlanchet *bp,
enum TALER_ErrorCode *ec);
struct TALER_BlindedDenominationSignature *bs);
/**

View File

@ -607,13 +607,12 @@ resolve_refreshes_reveal_denominations (struct MHD_Connection *connection,
/* create fresh coin signatures */
for (unsigned int i = 0; i<rctx->num_fresh_coins; i++)
{
enum TALER_ErrorCode ec = TALER_EC_NONE;
enum TALER_ErrorCode ec;
rrcs[i].coin_sig
= TEH_keys_denomination_sign (
&rrcs[i].h_denom_pub,
&rcds[i].blinded_planchet,
&ec);
ec = TEH_keys_denomination_sign (
&rrcs[i].h_denom_pub,
&rcds[i].blinded_planchet,
&rrcs[i].coin_sig);
if (TALER_EC_NONE != ec)
{
GNUNET_break (0);

View File

@ -499,12 +499,10 @@ TEH_handler_withdraw (struct TEH_RequestContext *rc,
// TODO: if CS: check nonce for reuse
/* Sign before transaction! */
ec = TALER_EC_NONE;
// FIXME: swap arguments!
wc.collectable.sig = TEH_keys_denomination_sign (
ec = TEH_keys_denomination_sign (
&wc.collectable.denom_pub_hash,
&wc.blinded_planchet,
&ec);
&wc.collectable.sig);
if (TALER_EC_NONE != ec)
{
GNUNET_break (0);

View File

@ -1791,17 +1791,16 @@ TALER_CRYPTO_helper_rsa_poll (struct TALER_CRYPTO_RsaDenominationHelper *dh);
* @param h_rsa hash of the RSA public key to use to sign
* @param msg message to sign
* @param msg_size number of bytes in @a msg
* @param[out] ec set to the error code (or #TALER_EC_NONE on success)
* @return signature, the value inside the structure will be NULL on failure,
* see @a ec for details about the failure
* @param[out] bs set to the blind signature
* @return #TALER_EC_NONE on success
*/
struct TALER_BlindedDenominationSignature
enum TALER_ErrorCode
TALER_CRYPTO_helper_rsa_sign (
struct TALER_CRYPTO_RsaDenominationHelper *dh,
const struct TALER_RsaPubHashP *h_rsa,
const void *msg,
size_t msg_size,
enum TALER_ErrorCode *ec);
struct TALER_BlindedDenominationSignature *bs);
/**
@ -1912,16 +1911,15 @@ TALER_CRYPTO_helper_cs_poll (struct TALER_CRYPTO_CsDenominationHelper *dh);
* @param dh helper process connection
* @param h_cs hash of the CS public key to use to sign
* @param blinded_planchet blinded planchet containing c and nonce
* @param[out] ec set to the error code (or #TALER_EC_NONE on success)
* @return signature, the value inside the structure will be NULL on failure,
* see @a ec for details about the failure
* @param[out] bs set to the blind signature
* @return #TALER_EC_NONE on success
*/
struct TALER_BlindedDenominationSignature
enum TALER_ErrorCode
TALER_CRYPTO_helper_cs_sign (
struct TALER_CRYPTO_CsDenominationHelper *dh,
const struct TALER_CsPubHashP *h_cs,
const struct TALER_BlindedCsPlanchet *blinded_planchet,
enum TALER_ErrorCode *ec);
struct TALER_BlindedDenominationSignature *bs);
/**

View File

@ -378,17 +378,16 @@ more:
}
struct TALER_BlindedDenominationSignature
enum TALER_ErrorCode
TALER_CRYPTO_helper_cs_sign (
struct TALER_CRYPTO_CsDenominationHelper *dh,
const struct TALER_CsPubHashP *h_cs,
const struct TALER_BlindedCsPlanchet *blinded_planchet,
enum TALER_ErrorCode *ec)
struct TALER_BlindedDenominationSignature *bs)
{
struct TALER_BlindedDenominationSignature ds = {
.cipher = TALER_DENOMINATION_INVALID
};
enum TALER_ErrorCode ec = TALER_EC_INVALID;
bs->cipher = TALER_DENOMINATION_INVALID;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Starting signature process\n");
if (GNUNET_OK !=
@ -396,8 +395,7 @@ TALER_CRYPTO_helper_cs_sign (
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Failed to connect to helper\n");
*ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_UNAVAILABLE;
return ds;
return TALER_EC_EXCHANGE_DENOMINATION_HELPER_UNAVAILABLE;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@ -420,8 +418,7 @@ TALER_CRYPTO_helper_cs_sign (
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
"send");
do_disconnect (dh);
*ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_UNAVAILABLE;
return ds;
return TALER_EC_EXCHANGE_DENOMINATION_HELPER_UNAVAILABLE;
}
}
@ -434,7 +431,6 @@ TALER_CRYPTO_helper_cs_sign (
= (const struct GNUNET_MessageHeader *) buf;
bool finished = false;
*ec = TALER_EC_INVALID;
while (1)
{
uint16_t msize;
@ -454,20 +450,20 @@ TALER_CRYPTO_helper_cs_sign (
{
GNUNET_assert (finished);
GNUNET_assert (0 == off);
return ds;
return ec;
}
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
"recv");
do_disconnect (dh);
*ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_UNAVAILABLE;
ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_UNAVAILABLE;
break;
}
if (0 == ret)
{
GNUNET_break (0 == off);
if (! finished)
*ec = TALER_EC_EXCHANGE_SIGNKEY_HELPER_BUG;
return ds;
ec = TALER_EC_EXCHANGE_SIGNKEY_HELPER_BUG;
return ec;
}
off += ret;
more:
@ -483,26 +479,26 @@ more:
{
GNUNET_break_op (0);
do_disconnect (dh);
*ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
goto end;
}
if (finished)
{
GNUNET_break_op (0);
do_disconnect (dh);
*ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
goto end;
}
{
const struct TALER_CRYPTO_SignResponse *sr =
(const struct TALER_CRYPTO_SignResponse *) buf;
// TODO: add nullcheck
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received signature\n");
*ec = TALER_EC_NONE;
ec = TALER_EC_NONE;
finished = true;
ds.cipher = TALER_DENOMINATION_CS;
ds.details.blinded_cs_answer = sr->cs_answer;
bs->cipher = TALER_DENOMINATION_CS;
bs->details.blinded_cs_answer = sr->cs_answer;
break;
}
case TALER_HELPER_CS_MT_RES_SIGN_FAILURE:
@ -510,14 +506,14 @@ more:
{
GNUNET_break_op (0);
do_disconnect (dh);
*ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
goto end;
}
{
const struct TALER_CRYPTO_SignFailure *sf =
(const struct TALER_CRYPTO_SignFailure *) buf;
*ec = (enum TALER_ErrorCode) ntohl (sf->ec);
ec = (enum TALER_ErrorCode) ntohl (sf->ec);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Signing failed!\n");
finished = true;
@ -532,7 +528,7 @@ more:
{
GNUNET_break_op (0);
do_disconnect (dh);
*ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
goto end;
}
break; /* while(1) loop ensures we recvfrom() again */
@ -545,7 +541,7 @@ more:
{
GNUNET_break_op (0);
do_disconnect (dh);
*ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
goto end;
}
break; /* while(1) loop ensures we recvfrom() again */
@ -560,7 +556,7 @@ more:
"Received unexpected message of type %u\n",
ntohs (hdr->type));
do_disconnect (dh);
*ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
goto end;
}
memmove (buf,
@ -571,8 +567,8 @@ more:
} /* while(1) */
end:
if (finished)
TALER_blinded_denom_sig_free (&ds);
return ds;
TALER_blinded_denom_sig_free (bs);
return ec;
}
}

View File

@ -387,18 +387,17 @@ more:
}
struct TALER_BlindedDenominationSignature
enum TALER_ErrorCode
TALER_CRYPTO_helper_rsa_sign (
struct TALER_CRYPTO_RsaDenominationHelper *dh,
const struct TALER_RsaPubHashP *h_rsa,
const void *msg,
size_t msg_size,
enum TALER_ErrorCode *ec)
struct TALER_BlindedDenominationSignature *bs)
{
struct TALER_BlindedDenominationSignature ds = {
.cipher = TALER_DENOMINATION_INVALID
};
enum TALER_ErrorCode ec = TALER_EC_INVALID;
bs->cipher = TALER_DENOMINATION_INVALID;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Starting signature process\n");
if (GNUNET_OK !=
@ -406,8 +405,7 @@ TALER_CRYPTO_helper_rsa_sign (
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Failed to connect to helper\n");
*ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_UNAVAILABLE;
return ds;
return TALER_EC_EXCHANGE_DENOMINATION_HELPER_UNAVAILABLE;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@ -432,8 +430,7 @@ TALER_CRYPTO_helper_rsa_sign (
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
"send");
do_disconnect (dh);
*ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_UNAVAILABLE;
return ds;
return TALER_EC_EXCHANGE_DENOMINATION_HELPER_UNAVAILABLE;
}
}
@ -446,7 +443,6 @@ TALER_CRYPTO_helper_rsa_sign (
= (const struct GNUNET_MessageHeader *) buf;
bool finished = false;
*ec = TALER_EC_INVALID;
while (1)
{
uint16_t msize;
@ -466,20 +462,20 @@ TALER_CRYPTO_helper_rsa_sign (
{
GNUNET_assert (finished);
GNUNET_assert (0 == off);
return ds;
return ec;
}
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
"recv");
do_disconnect (dh);
*ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_UNAVAILABLE;
ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_UNAVAILABLE;
break;
}
if (0 == ret)
{
GNUNET_break (0 == off);
if (! finished)
*ec = TALER_EC_EXCHANGE_SIGNKEY_HELPER_BUG;
return ds;
ec = TALER_EC_EXCHANGE_SIGNKEY_HELPER_BUG;
return ec;
}
off += ret;
more:
@ -495,14 +491,14 @@ more:
{
GNUNET_break_op (0);
do_disconnect (dh);
*ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
goto end;
}
if (finished)
{
GNUNET_break_op (0);
do_disconnect (dh);
*ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
goto end;
}
{
@ -517,15 +513,15 @@ more:
{
GNUNET_break_op (0);
do_disconnect (dh);
*ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
goto end;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received signature\n");
*ec = TALER_EC_NONE;
ec = TALER_EC_NONE;
finished = true;
ds.cipher = TALER_DENOMINATION_RSA;
ds.details.blinded_rsa_signature = rsa_signature;
bs->cipher = TALER_DENOMINATION_RSA;
bs->details.blinded_rsa_signature = rsa_signature;
break;
}
case TALER_HELPER_RSA_MT_RES_SIGN_FAILURE:
@ -533,14 +529,14 @@ more:
{
GNUNET_break_op (0);
do_disconnect (dh);
*ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
goto end;
}
{
const struct TALER_CRYPTO_SignFailure *sf =
(const struct TALER_CRYPTO_SignFailure *) buf;
*ec = (enum TALER_ErrorCode) ntohl (sf->ec);
ec = (enum TALER_ErrorCode) ntohl (sf->ec);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Signing failed!\n");
finished = true;
@ -555,7 +551,7 @@ more:
{
GNUNET_break_op (0);
do_disconnect (dh);
*ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
goto end;
}
break; /* while(1) loop ensures we recvfrom() again */
@ -568,7 +564,7 @@ more:
{
GNUNET_break_op (0);
do_disconnect (dh);
*ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
goto end;
}
break; /* while(1) loop ensures we recvfrom() again */
@ -583,7 +579,7 @@ more:
"Received unexpected message of type %u\n",
ntohs (hdr->type));
do_disconnect (dh);
*ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
goto end;
}
memmove (buf,
@ -594,8 +590,8 @@ more:
} /* while(1) */
end:
if (finished)
TALER_blinded_denom_sig_free (&ds);
return ds;
TALER_blinded_denom_sig_free (bs);
return ec;
}
}

View File

@ -456,11 +456,11 @@ test_signing (struct TALER_CRYPTO_CsDenominationHelper *dh)
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Requesting signature with key %s\n",
GNUNET_h2s (&keys[i].h_cs.hash));
ds = TALER_CRYPTO_helper_cs_sign (dh,
ec = TALER_CRYPTO_helper_cs_sign (dh,
&keys[i].h_cs,
&pd.blinded_planchet.details.
cs_blinded_planchet,
&ec);
&ds);
}
switch (ec)
{
@ -552,11 +552,11 @@ test_signing (struct TALER_CRYPTO_CsDenominationHelper *dh)
&c_hash,
&pd));
ds = TALER_CRYPTO_helper_cs_sign (dh,
ec = TALER_CRYPTO_helper_cs_sign (dh,
&rnd,
&pd.blinded_planchet.details.
cs_blinded_planchet,
&ec);
&ds);
if (TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN != ec)
{
if (TALER_EC_NONE == ec)
@ -645,11 +645,11 @@ perf_signing (struct TALER_CRYPTO_CsDenominationHelper *dh,
struct GNUNET_TIME_Absolute start = GNUNET_TIME_absolute_get ();
struct GNUNET_TIME_Relative delay;
ds = TALER_CRYPTO_helper_cs_sign (dh,
ec = TALER_CRYPTO_helper_cs_sign (dh,
&keys[i].h_cs,
&pd.blinded_planchet.details.
cs_blinded_planchet,
&ec);
&ds);
if (TALER_EC_NONE != ec)
break;
delay = GNUNET_TIME_absolute_get_duration (start);

View File

@ -304,13 +304,13 @@ test_signing (struct TALER_CRYPTO_RsaDenominationHelper *dh)
int) pd.blinded_planchet.details.rsa_blinded_planchet.
blinded_msg_size,
GNUNET_h2s (&keys[i].h_rsa.hash));
ds = TALER_CRYPTO_helper_rsa_sign (dh,
ec = TALER_CRYPTO_helper_rsa_sign (dh,
&keys[i].h_rsa,
pd.blinded_planchet.details.
rsa_blinded_planchet.blinded_msg,
pd.blinded_planchet.details.
rsa_blinded_planchet.blinded_msg_size,
&ec);
&ds);
TALER_blinded_planchet_free (&pd.blinded_planchet);
}
switch (ec)
@ -405,11 +405,11 @@ test_signing (struct TALER_CRYPTO_RsaDenominationHelper *dh)
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
&rnd,
sizeof (rnd));
ds = TALER_CRYPTO_helper_rsa_sign (dh,
ec = TALER_CRYPTO_helper_rsa_sign (dh,
&rnd,
"Hello",
strlen ("Hello"),
&ec);
&ds);
if (TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN != ec)
{
if (TALER_EC_NONE == ec)
@ -485,14 +485,14 @@ perf_signing (struct TALER_CRYPTO_RsaDenominationHelper *dh,
struct GNUNET_TIME_Absolute start = GNUNET_TIME_absolute_get ();
struct GNUNET_TIME_Relative delay;
ds = TALER_CRYPTO_helper_rsa_sign (dh,
ec = TALER_CRYPTO_helper_rsa_sign (dh,
&keys[i].h_rsa,
pd.blinded_planchet.details.
rsa_blinded_planchet.blinded_msg,
pd.blinded_planchet.details.
rsa_blinded_planchet.
blinded_msg_size,
&ec);
&ds);
if (TALER_EC_NONE != ec)
break;
delay = GNUNET_TIME_absolute_get_duration (start);