-refactoring in preparation of fixing #7272

This commit is contained in:
Christian Grothoff 2022-11-14 05:34:19 +01:00
parent d876a95073
commit 053faa252c
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
5 changed files with 133 additions and 25 deletions

View File

@ -422,10 +422,13 @@ prepare_transaction (const struct TEH_RequestContext *rc,
{
struct PlanchetContext *pc = &wc->planchets[i];
enum TALER_ErrorCode ec;
struct TEH_CoinSignData csds = {
.h_denom_pub = &pc->collectable.denom_pub_hash,
.bp = &pc->blinded_planchet
};
ec = TEH_keys_denomination_sign_withdraw (
&pc->collectable.denom_pub_hash,
&pc->blinded_planchet,
&csds,
&pc->collectable.sig);
if (TALER_EC_NONE != ec)
{

View File

@ -2747,12 +2747,13 @@ TEH_keys_denomination_by_hash2 (
enum TALER_ErrorCode
TEH_keys_denomination_sign_withdraw (
const struct TALER_DenominationHashP *h_denom_pub,
const struct TALER_BlindedPlanchet *bp,
const struct TEH_CoinSignData *csd,
struct TALER_BlindedDenominationSignature *bs)
{
struct TEH_KeyStateHandle *ksh;
struct HelperDenomination *hd;
const struct TALER_DenominationHashP *h_denom_pub = csd->h_denom_pub;
const struct TALER_BlindedPlanchet *bp = csd->bp;
ksh = TEH_keys_get_state ();
if (NULL == ksh)
@ -2797,12 +2798,67 @@ TEH_keys_denomination_sign_withdraw (
}
enum TALER_ErrorCode
TEH_keys_denomination_batch_sign_withdraw (
const struct TEH_CoinSignData *csds,
unsigned int csds_length,
struct TALER_BlindedDenominationSignature *bss)
{
struct TEH_KeyStateHandle *ksh;
struct HelperDenomination *hd;
#if 0
ksh = TEH_keys_get_state ();
if (NULL == ksh)
return TALER_EC_EXCHANGE_GENERIC_KEYS_MISSING;
hd = GNUNET_CONTAINER_multihashmap_get (ksh->helpers->denom_keys,
&h_denom_pub->hash);
if (NULL == hd)
return TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN;
if (bp->cipher != hd->denom_pub.cipher)
return TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE;
switch (hd->denom_pub.cipher)
{
case TALER_DENOMINATION_RSA:
TEH_METRICS_num_signatures[TEH_MT_SIGNATURE_RSA]++;
{
struct TALER_CRYPTO_RsaSignRequest rsr = {
.h_rsa = &hd->h_details.h_rsa,
.msg = bp->details.rsa_blinded_planchet.blinded_msg,
.msg_size = bp->details.rsa_blinded_planchet.blinded_msg_size
};
return TALER_CRYPTO_helper_rsa_sign (
ksh->helpers->rsadh,
&rsr,
bs);
}
case TALER_DENOMINATION_CS:
TEH_METRICS_num_signatures[TEH_MT_SIGNATURE_CS]++;
{
struct TALER_CRYPTO_CsSignRequest csr;
csr.h_cs = &hd->h_details.h_cs;
csr.blinded_planchet = &bp->details.cs_blinded_planchet;
return TALER_CRYPTO_helper_cs_sign_withdraw (
ksh->helpers->csdh,
&csr,
bs);
}
default:
return TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE;
}
#endif
}
enum TALER_ErrorCode
TEH_keys_denomination_sign_melt (
const struct TALER_DenominationHashP *h_denom_pub,
const struct TALER_BlindedPlanchet *bp,
const struct TEH_CoinSignData *csd,
struct TALER_BlindedDenominationSignature *bs)
{
const struct TALER_DenominationHashP *h_denom_pub = csd->h_denom_pub;
const struct TALER_BlindedPlanchet *bp = csd->bp;
struct TEH_KeyStateHandle *ksh;
struct HelperDenomination *hd;

View File

@ -246,39 +246,79 @@ TEH_keys_denomination_by_hash2 (
struct MHD_Connection *conn,
MHD_RESULT *mret);
/**
* Information needed to create a blind signature.
*/
struct TEH_CoinSignData
{
/**
* Hash of key to sign with.
*/
const struct TALER_DenominationHashP *h_denom_pub;
/**
* Blinded planchet to sign over.
*/
const struct TALER_BlindedPlanchet *bp;
};
/**
* Request to sign @a msg using the public key corresponding to
* @a h_denom_pub during a withdraw operation.
* Request to sign @a csd for regular withdrawing.
*
* @param h_denom_pub hash of the public key to use to sign
* @param bp blinded planchet to sign
* @param csd identifies data to blindly sign and key to sign with
* @param[out] bs set to the blind signature on success
* @return #TALER_EC_NONE on success
*/
enum TALER_ErrorCode
TEH_keys_denomination_sign_withdraw (
const struct TALER_DenominationHashP *h_denom_pub,
const struct TALER_BlindedPlanchet *bp,
const struct TEH_CoinSignData *csd,
struct TALER_BlindedDenominationSignature *bs);
/**
* Request to sign @a msg using the public key corresponding to
* @a h_denom_pub during a refresh operation.
* Request to sign @a csds for regular withdrawing.
*
* @param h_denom_pub hash of the public key to use to sign
* @param bp blinded planchet to sign
* @param csds array with data to blindly sign (and keys to sign with)
* @param csds_length length of @a csds array
* @param[out] bss array set to the blind signature on success; must be of length @a csds_length
* @return #TALER_EC_NONE on success
*/
enum TALER_ErrorCode
TEH_keys_denomination_batch_sign_withdraw (
const struct TEH_CoinSignData *csds,
unsigned int csds_length,
struct TALER_BlindedDenominationSignature *bss);
/**
* Request to sign @a csd for melting.
*
* @param csd identifies data to blindly sign and key to sign with
* @param[out] bs set to the blind signature on success
* @return #TALER_EC_NONE on success
*/
enum TALER_ErrorCode
TEH_keys_denomination_sign_melt (
const struct TALER_DenominationHashP *h_denom_pub,
const struct TALER_BlindedPlanchet *bp,
const struct TEH_CoinSignData *csd,
struct TALER_BlindedDenominationSignature *bs);
/**
* Request to sign @a csds for melting.
*
* @param csds array with data to blindly sign (and keys to sign with)
* @param csds_length length of @a csds array
* @param[out] bss array set to the blind signature on success; must be of length @a csds_length
* @return #TALER_EC_NONE on success
*/
enum TALER_ErrorCode
TEH_keys_denomination_batch_sign_melt (
const struct TEH_CoinSignData *csds,
unsigned int csds_length,
struct TALER_BlindedDenominationSignature *bss);
/**
* Request to derive CS @a r_pub using the denomination corresponding to @a h_denom_pub
* and @a nonce for withdrawing.

View File

@ -749,12 +749,15 @@ clean_age:
for (unsigned int i = 0; i<rctx->num_fresh_coins; i++)
{
enum TALER_ErrorCode ec;
struct TEH_CoinSignData csd = {
.h_denom_pub = &rrcs[i].h_denom_pub,
.bp = &rcds[i].blinded_planchet
};
// FIXME #7272: replace with a batch call that
// passes all coins in once go!
ec = TEH_keys_denomination_sign_melt (
&rrcs[i].h_denom_pub,
&rcds[i].blinded_planchet,
&csd,
&rrcs[i].coin_sig);
if (TALER_EC_NONE != ec)
{

View File

@ -448,11 +448,17 @@ TEH_handler_withdraw (struct TEH_RequestContext *rc,
NULL);
}
/* Sign before transaction! */
ec = TEH_keys_denomination_sign_withdraw (
&wc.collectable.denom_pub_hash,
&wc.blinded_planchet,
&wc.collectable.sig);
{
struct TEH_CoinSignData csd = {
.h_denom_pub = &wc.collectable.denom_pub_hash,
.bp = &wc.blinded_planchet
};
/* Sign before transaction! */
ec = TEH_keys_denomination_sign_withdraw (
&csd,
&wc.collectable.sig);
}
if (TALER_EC_NONE != ec)
{
GNUNET_break (0);