refactor CS derive API in preparation for batch API

This commit is contained in:
Christian Grothoff 2022-11-13 19:52:09 +01:00
parent 18aba0abbb
commit de2fdc2a9a
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
6 changed files with 101 additions and 42 deletions

View File

@ -2874,10 +2874,15 @@ TEH_keys_denomination_cs_r_pub_melt (
return TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE; return TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE;
} }
return TALER_CRYPTO_helper_cs_r_derive_melt (ksh->helpers->csdh, {
&hd->h_details.h_cs, struct TALER_CRYPTO_CsDeriveRequest cdr = {
nonce, .h_cs = &hd->h_details.h_cs,
r_pub); .nonce = nonce
};
return TALER_CRYPTO_helper_cs_r_derive_melt (ksh->helpers->csdh,
&cdr,
r_pub);
}
} }
@ -2905,11 +2910,16 @@ TEH_keys_denomination_cs_r_pub_withdraw (
{ {
return TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE; return TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE;
} }
{
struct TALER_CRYPTO_CsDeriveRequest cdr = {
.h_cs = &hd->h_details.h_cs,
.nonce = nonce
};
return TALER_CRYPTO_helper_cs_r_derive_withdraw (ksh->helpers->csdh, return TALER_CRYPTO_helper_cs_r_derive_withdraw (ksh->helpers->csdh,
&hd->h_details.h_cs, &cdr,
nonce, r_pub);
r_pub); }
} }

View File

@ -2593,8 +2593,25 @@ TALER_CRYPTO_helper_cs_revoke (
/** /**
* Ask the helper to derive R using the @a nonce and denomination key * Information about what we should derive for.
* associated with @a h_cs. */
struct TALER_CRYPTO_CsDeriveRequest
{
/**
* Hash of the CS public key to use to sign.
*/
const struct TALER_CsPubHashP *h_cs;
/**
* Nonce to use.
*/
const struct TALER_CsNonce *nonce;
};
/**
* Ask the helper to derive R using the information
* from @a cdr.
* *
* This operation will block until the R has been obtained. Should * This operation will block until the R has been obtained. Should
* this process receive a signal (that is not ignored) while the operation is * this process receive a signal (that is not ignored) while the operation is
@ -2603,7 +2620,7 @@ TALER_CRYPTO_helper_cs_revoke (
* differences in the signature counters. Retrying in this case may work. * differences in the signature counters. Retrying in this case may work.
* *
* @param dh helper to process connection * @param dh helper to process connection
* @param h_cs hash of the CS public key to revoke * @param cdr derivation input data
* @param nonce witdhraw nonce * @param nonce witdhraw nonce
* @param[out] crp set to the pair of R values * @param[out] crp set to the pair of R values
* @return set to the error code (or #TALER_EC_NONE on success) * @return set to the error code (or #TALER_EC_NONE on success)
@ -2611,14 +2628,13 @@ TALER_CRYPTO_helper_cs_revoke (
enum TALER_ErrorCode enum TALER_ErrorCode
TALER_CRYPTO_helper_cs_r_derive_withdraw ( TALER_CRYPTO_helper_cs_r_derive_withdraw (
struct TALER_CRYPTO_CsDenominationHelper *dh, struct TALER_CRYPTO_CsDenominationHelper *dh,
const struct TALER_CsPubHashP *h_cs, const struct TALER_CRYPTO_CsDeriveRequest *cdr,
const struct TALER_CsNonce *nonce,
struct TALER_DenominationCSPublicRPairP *crp); struct TALER_DenominationCSPublicRPairP *crp);
/** /**
* Ask the helper to derive R using the @a nonce and denomination key * Ask the helper to derive R using the information
* associated with @a h_cs. * from @a cdr.
* *
* This operation will block until the R has been obtained. Should * This operation will block until the R has been obtained. Should
* this process receive a signal (that is not ignored) while the operation is * this process receive a signal (that is not ignored) while the operation is
@ -2627,16 +2643,14 @@ TALER_CRYPTO_helper_cs_r_derive_withdraw (
* differences in the signature counters. Retrying in this case may work. * differences in the signature counters. Retrying in this case may work.
* *
* @param dh helper to process connection * @param dh helper to process connection
* @param h_cs hash of the CS public key to revoke * @param cdr derivation input data
* @param nonce witdhraw nonce
* @param[out] crp set to the pair of R values * @param[out] crp set to the pair of R values
* @return set to the error code (or #TALER_EC_NONE on success) * @return set to the error code (or #TALER_EC_NONE on success)
*/ */
enum TALER_ErrorCode enum TALER_ErrorCode
TALER_CRYPTO_helper_cs_r_derive_melt ( TALER_CRYPTO_helper_cs_r_derive_melt (
struct TALER_CRYPTO_CsDenominationHelper *dh, struct TALER_CRYPTO_CsDenominationHelper *dh,
const struct TALER_CsPubHashP *h_cs, const struct TALER_CRYPTO_CsDeriveRequest *cdr,
const struct TALER_CsNonce *nonce,
struct TALER_DenominationCSPublicRPairP *crp); struct TALER_DenominationCSPublicRPairP *crp);

View File

@ -853,13 +853,12 @@ more:
enum TALER_ErrorCode enum TALER_ErrorCode
TALER_CRYPTO_helper_cs_r_derive_withdraw ( TALER_CRYPTO_helper_cs_r_derive_withdraw (
struct TALER_CRYPTO_CsDenominationHelper *dh, struct TALER_CRYPTO_CsDenominationHelper *dh,
const struct TALER_CsPubHashP *h_cs, const struct TALER_CRYPTO_CsDeriveRequest *cdr,
const struct TALER_CsNonce *nonce,
struct TALER_DenominationCSPublicRPairP *crp) struct TALER_DenominationCSPublicRPairP *crp)
{ {
return helper_cs_r_derive (dh, return helper_cs_r_derive (dh,
h_cs, cdr->h_cs,
nonce, cdr->nonce,
false, false,
crp); crp);
} }
@ -868,18 +867,41 @@ TALER_CRYPTO_helper_cs_r_derive_withdraw (
enum TALER_ErrorCode enum TALER_ErrorCode
TALER_CRYPTO_helper_cs_r_derive_melt ( TALER_CRYPTO_helper_cs_r_derive_melt (
struct TALER_CRYPTO_CsDenominationHelper *dh, struct TALER_CRYPTO_CsDenominationHelper *dh,
const struct TALER_CsPubHashP *h_cs, const struct TALER_CRYPTO_CsDeriveRequest *cdr,
const struct TALER_CsNonce *nonce,
struct TALER_DenominationCSPublicRPairP *crp) struct TALER_DenominationCSPublicRPairP *crp)
{ {
return helper_cs_r_derive (dh, return helper_cs_r_derive (dh,
h_cs, cdr->h_cs,
nonce, cdr->nonce,
true, true,
crp); crp);
} }
enum TALER_ErrorCode
TALER_CRYPTO_helper_cs_batch_sign_melt (
struct TALER_CRYPTO_CsDenominationHelper *dh,
const struct TALER_CRYPTO_CsSignRequest *reqs,
unsigned int reqs_length,
struct TALER_BlindedDenominationSignature *bss)
{
GNUNET_break (0); // FIXME
return -1;
}
enum TALER_ErrorCode
TALER_CRYPTO_helper_cs_batch_sign_withdraw (
struct TALER_CRYPTO_CsDenominationHelper *dh,
const struct TALER_CRYPTO_CsSignRequest *reqs,
unsigned int reqs_length,
struct TALER_BlindedDenominationSignature *bss)
{
GNUNET_break (0); // FIXME
return -1;
}
void void
TALER_CRYPTO_helper_cs_disconnect ( TALER_CRYPTO_helper_cs_disconnect (
struct TALER_CRYPTO_CsDenominationHelper *dh) struct TALER_CRYPTO_CsDenominationHelper *dh)

View File

@ -2170,7 +2170,7 @@ run (void *cls,
GNUNET_SCHEDULER_add_shutdown (&do_shutdown, GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
NULL); NULL);
if (0 == max_workers) if (0 == max_workers)
max_workers = 1; /* FIXME-#7272: or determine from CPU? */ max_workers = sysconf (_SC_NPROCESSORS_CONF);
for (unsigned int i = 0; i<max_workers; i++) for (unsigned int i = 0; i<max_workers; i++)
if (GNUNET_OK != if (GNUNET_OK !=
start_worker ()) start_worker ())

View File

@ -1983,7 +1983,7 @@ run (void *cls,
GNUNET_SCHEDULER_add_shutdown (&do_shutdown, GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
NULL); NULL);
if (0 == max_workers) if (0 == max_workers)
max_workers = 1; /* FIXME-#7272: or determine from CPU? */ max_workers = sysconf (_SC_NPROCESSORS_CONF);
for (unsigned int i = 0; i<max_workers; i++) for (unsigned int i = 0; i<max_workers; i++)
if (GNUNET_OK != if (GNUNET_OK !=
start_worker ()) start_worker ())

View File

@ -289,11 +289,17 @@ test_r_derive (struct TALER_CRYPTO_CsDenominationHelper *dh)
"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; alg_values.cipher = TALER_DENOMINATION_CS;
ec = TALER_CRYPTO_helper_cs_r_derive_withdraw ( {
dh, struct TALER_CRYPTO_CsDeriveRequest cdr = {
&keys[i].h_cs, .h_cs = &keys[i].h_cs,
&pd.blinded_planchet.details.cs_blinded_planchet.nonce, .nonce = &pd.blinded_planchet.details.cs_blinded_planchet.nonce
&alg_values.details.cs_values); };
ec = TALER_CRYPTO_helper_cs_r_derive_withdraw (
dh,
&cdr,
&alg_values.details.cs_values);
}
switch (ec) switch (ec)
{ {
case TALER_EC_NONE: case TALER_EC_NONE:
@ -374,6 +380,10 @@ 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; struct TALER_DenominationCSPublicRPairP crp;
struct TALER_CRYPTO_CsDeriveRequest cdr = {
.h_cs = &rnd,
.nonce = &nonce,
};
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
&rnd, &rnd,
@ -382,8 +392,7 @@ test_r_derive (struct TALER_CRYPTO_CsDenominationHelper *dh)
&nonce, &nonce,
sizeof (nonce)); sizeof (nonce));
ec = TALER_CRYPTO_helper_cs_r_derive_withdraw (dh, ec = TALER_CRYPTO_helper_cs_r_derive_withdraw (dh,
&rnd, &cdr,
&nonce,
&crp); &crp);
if (TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN != ec) if (TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN != ec)
{ {
@ -424,6 +433,10 @@ test_signing (struct TALER_CRYPTO_CsDenominationHelper *dh)
{ {
struct TALER_PlanchetDetail pd; struct TALER_PlanchetDetail pd;
struct TALER_CRYPTO_CsSignRequest csr; struct TALER_CRYPTO_CsSignRequest csr;
struct TALER_CRYPTO_CsDeriveRequest cdr = {
.h_cs = &keys[i].h_cs,
.nonce = &pd.blinded_planchet.details.cs_blinded_planchet.nonce
};
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;
@ -434,10 +447,7 @@ test_signing (struct TALER_CRYPTO_CsDenominationHelper *dh)
alg_values.cipher = TALER_DENOMINATION_CS; alg_values.cipher = TALER_DENOMINATION_CS;
ec = TALER_CRYPTO_helper_cs_r_derive_withdraw ( ec = TALER_CRYPTO_helper_cs_r_derive_withdraw (
dh, dh,
&keys[i].h_cs, &cdr,
&pd.blinded_planchet.
details.
cs_blinded_planchet.nonce,
&alg_values.details.cs_values); &alg_values.details.cs_values);
if (TALER_EC_NONE != ec) if (TALER_EC_NONE != ec)
continue; continue;
@ -622,6 +632,10 @@ perf_signing (struct TALER_CRYPTO_CsDenominationHelper *dh,
{ {
struct TALER_CoinPubHashP c_hash; struct TALER_CoinPubHashP c_hash;
struct TALER_PlanchetDetail pd; struct TALER_PlanchetDetail pd;
struct TALER_CRYPTO_CsDeriveRequest cdr = {
.h_cs = &keys[i].h_cs,
.nonce = &pd.blinded_planchet.details.cs_blinded_planchet.nonce
};
pd.blinded_planchet.cipher = TALER_DENOMINATION_CS; pd.blinded_planchet.cipher = TALER_DENOMINATION_CS;
TALER_cs_withdraw_nonce_derive (&ps, TALER_cs_withdraw_nonce_derive (&ps,
@ -630,8 +644,7 @@ perf_signing (struct TALER_CRYPTO_CsDenominationHelper *dh,
alg_values.cipher = TALER_DENOMINATION_CS; alg_values.cipher = TALER_DENOMINATION_CS;
ec = TALER_CRYPTO_helper_cs_r_derive_melt ( ec = TALER_CRYPTO_helper_cs_r_derive_melt (
dh, dh,
&keys[i].h_cs, &cdr,
&pd.blinded_planchet.details.cs_blinded_planchet.nonce,
&alg_values.details.cs_values); &alg_values.details.cs_values);
if (TALER_EC_NONE != ec) if (TALER_EC_NONE != ec)
continue; continue;