migrate test_helper_rsa to latest API

This commit is contained in:
Christian Grothoff 2021-11-17 23:05:14 +01:00
parent b61f601028
commit fa65f8fd7d
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC

View File

@ -74,7 +74,7 @@ struct KeyData
/** /**
* Hash of the public key. * Hash of the public key.
*/ */
struct TALER_DenominationHash h_denom_pub; struct TALER_RsaPubHashP h_rsa;
/** /**
* Full public key. * Full public key.
@ -111,7 +111,7 @@ static struct KeyData keys[MAX_KEYS];
* zero if the key has been revoked or purged * zero if the key has been revoked or purged
* @param validity_duration how long does the key remain available for signing; * @param validity_duration how long does the key remain available for signing;
* zero if the key has been revoked or purged * zero if the key has been revoked or purged
* @param h_denom_pub hash of the @a denom_pub that is available (or was purged) * @param h_rsa hash of the @a denom_pub that is available (or was purged)
* @param denom_pub the public key itself, NULL if the key was revoked or purged * @param denom_pub the public key itself, NULL if the key was revoked or purged
* @param sm_pub public key of the security module, NULL if the key was revoked or purged * @param sm_pub public key of the security module, NULL if the key was revoked or purged
* @param sm_sig signature from the security module, NULL if the key was revoked or purged * @param sm_sig signature from the security module, NULL if the key was revoked or purged
@ -122,7 +122,7 @@ key_cb (void *cls,
const char *section_name, const char *section_name,
struct GNUNET_TIME_Absolute start_time, struct GNUNET_TIME_Absolute start_time,
struct GNUNET_TIME_Relative validity_duration, struct GNUNET_TIME_Relative validity_duration,
const struct TALER_DenominationHash *h_denom_pub, const struct TALER_RsaPubHashP *h_rsa,
const struct TALER_DenominationPublicKey *denom_pub, const struct TALER_DenominationPublicKey *denom_pub,
const struct TALER_SecurityModulePublicKeyP *sm_pub, const struct TALER_SecurityModulePublicKeyP *sm_pub,
const struct TALER_SecurityModuleSignatureP *sm_sig) const struct TALER_SecurityModuleSignatureP *sm_sig)
@ -131,7 +131,7 @@ key_cb (void *cls,
(void) sm_sig; (void) sm_sig;
GNUNET_log (GNUNET_ERROR_TYPE_INFO, GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Key notification about key %s in `%s'\n", "Key notification about key %s in `%s'\n",
GNUNET_h2s (&h_denom_pub->hash), GNUNET_h2s (&h_rsa->hash),
section_name); section_name);
if (0 == validity_duration.rel_value_us) if (0 == validity_duration.rel_value_us)
{ {
@ -140,8 +140,8 @@ key_cb (void *cls,
GNUNET_break (NULL == denom_pub); GNUNET_break (NULL == denom_pub);
GNUNET_break (NULL == section_name); GNUNET_break (NULL == section_name);
for (unsigned int i = 0; i<MAX_KEYS; i++) for (unsigned int i = 0; i<MAX_KEYS; i++)
if (0 == GNUNET_memcmp (h_denom_pub, if (0 == GNUNET_memcmp (h_rsa,
&keys[i].h_denom_pub)) &keys[i].h_rsa))
{ {
keys[i].valid = false; keys[i].valid = false;
keys[i].revoked = false; keys[i].revoked = false;
@ -163,7 +163,7 @@ key_cb (void *cls,
if (! keys[i].valid) if (! keys[i].valid)
{ {
keys[i].valid = true; keys[i].valid = true;
keys[i].h_denom_pub = *h_denom_pub; keys[i].h_rsa = *h_rsa;
keys[i].start_time = start_time; keys[i].start_time = start_time;
keys[i].validity_duration = validity_duration; keys[i].validity_duration = validity_duration;
TALER_denom_pub_deep_copy (&keys[i].denom_pub, TALER_denom_pub_deep_copy (&keys[i].denom_pub,
@ -185,7 +185,7 @@ key_cb (void *cls,
* @return 0 on success * @return 0 on success
*/ */
static int static int
test_revocation (struct TALER_CRYPTO_DenominationHelper *dh) test_revocation (struct TALER_CRYPTO_RsaDenominationHelper *dh)
{ {
struct timespec req = { struct timespec req = {
.tv_nsec = 250000000 .tv_nsec = 250000000
@ -210,12 +210,12 @@ test_revocation (struct TALER_CRYPTO_DenominationHelper *dh)
keys[j].revoked = true; keys[j].revoked = true;
fprintf (stderr, fprintf (stderr,
"Revoking key %s ...", "Revoking key %s ...",
GNUNET_h2s (&keys[j].h_denom_pub.hash)); GNUNET_h2s (&keys[j].h_rsa.hash));
TALER_CRYPTO_helper_denom_revoke (dh, TALER_CRYPTO_helper_rsa_revoke (dh,
&keys[j].h_denom_pub); &keys[j].h_rsa);
for (unsigned int k = 0; k<1000; k++) for (unsigned int k = 0; k<1000; k++)
{ {
TALER_CRYPTO_helper_denom_poll (dh); TALER_CRYPTO_helper_rsa_poll (dh);
if (! keys[j].revoked) if (! keys[j].revoked)
break; break;
nanosleep (&req, NULL); nanosleep (&req, NULL);
@ -226,7 +226,7 @@ test_revocation (struct TALER_CRYPTO_DenominationHelper *dh)
fprintf (stderr, fprintf (stderr,
"\nFAILED: timeout trying to revoke key %u\n", "\nFAILED: timeout trying to revoke key %u\n",
j); j);
TALER_CRYPTO_helper_denom_disconnect (dh); TALER_CRYPTO_helper_rsa_disconnect (dh);
return 2; return 2;
} }
fprintf (stderr, "\n"); fprintf (stderr, "\n");
@ -244,7 +244,7 @@ test_revocation (struct TALER_CRYPTO_DenominationHelper *dh)
* @return 0 on success * @return 0 on success
*/ */
static int static int
test_signing (struct TALER_CRYPTO_DenominationHelper *dh) test_signing (struct TALER_CRYPTO_RsaDenominationHelper *dh)
{ {
struct TALER_BlindedDenominationSignature ds; struct TALER_BlindedDenominationSignature ds;
enum TALER_ErrorCode ec; enum TALER_ErrorCode ec;
@ -268,12 +268,12 @@ test_signing (struct TALER_CRYPTO_DenominationHelper *dh)
GNUNET_log (GNUNET_ERROR_TYPE_INFO, GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Requesting signature over %u bytes with key %s\n", "Requesting signature over %u bytes with key %s\n",
(unsigned int) pd.coin_ev_size, (unsigned int) pd.coin_ev_size,
GNUNET_h2s (&keys[i].h_denom_pub.hash)); GNUNET_h2s (&keys[i].h_rsa.hash));
ds = TALER_CRYPTO_helper_denom_sign (dh, ds = TALER_CRYPTO_helper_rsa_sign (dh,
&keys[i].h_denom_pub, &keys[i].h_rsa,
pd.coin_ev, pd.coin_ev,
pd.coin_ev_size, pd.coin_ev_size,
&ec); &ec);
GNUNET_free (pd.coin_ev); GNUNET_free (pd.coin_ev);
} }
switch (ec) switch (ec)
@ -320,7 +320,7 @@ test_signing (struct TALER_CRYPTO_DenominationHelper *dh)
} }
GNUNET_log (GNUNET_ERROR_TYPE_INFO, GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Received valid signature for key %s\n", "Received valid signature for key %s\n",
GNUNET_h2s (&keys[i].h_denom_pub.hash)); GNUNET_h2s (&keys[i].h_rsa.hash));
success = true; success = true;
break; break;
case TALER_EC_EXCHANGE_DENOMINATION_HELPER_TOO_EARLY: case TALER_EC_EXCHANGE_DENOMINATION_HELPER_TOO_EARLY:
@ -355,16 +355,16 @@ test_signing (struct TALER_CRYPTO_DenominationHelper *dh)
/* check signing does not work if the key is unknown */ /* check signing does not work if the key is unknown */
{ {
struct TALER_DenominationHash rnd; struct TALER_RsaPubHashP rnd;
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
&rnd, &rnd,
sizeof (rnd)); sizeof (rnd));
ds = TALER_CRYPTO_helper_denom_sign (dh, ds = TALER_CRYPTO_helper_rsa_sign (dh,
&rnd, &rnd,
"Hello", "Hello",
strlen ("Hello"), strlen ("Hello"),
&ec); &ec);
if (TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN != ec) if (TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN != ec)
{ {
if (TALER_EC_NONE == ec) if (TALER_EC_NONE == ec)
@ -387,7 +387,7 @@ test_signing (struct TALER_CRYPTO_DenominationHelper *dh)
* @return 0 on success * @return 0 on success
*/ */
static int static int
perf_signing (struct TALER_CRYPTO_DenominationHelper *dh, perf_signing (struct TALER_CRYPTO_RsaDenominationHelper *dh,
const char *type) const char *type)
{ {
struct TALER_BlindedDenominationSignature ds; struct TALER_BlindedDenominationSignature ds;
@ -397,7 +397,7 @@ perf_signing (struct TALER_CRYPTO_DenominationHelper *dh,
TALER_planchet_setup_random (&ps); TALER_planchet_setup_random (&ps);
duration = GNUNET_TIME_UNIT_ZERO; duration = GNUNET_TIME_UNIT_ZERO;
TALER_CRYPTO_helper_denom_poll (dh); TALER_CRYPTO_helper_rsa_poll (dh);
for (unsigned int j = 0; j<NUM_SIGN_PERFS;) for (unsigned int j = 0; j<NUM_SIGN_PERFS;)
{ {
for (unsigned int i = 0; i<MAX_KEYS; i++) for (unsigned int i = 0; i<MAX_KEYS; i++)
@ -425,11 +425,11 @@ perf_signing (struct TALER_CRYPTO_DenominationHelper *dh,
struct GNUNET_TIME_Absolute start = GNUNET_TIME_absolute_get (); struct GNUNET_TIME_Absolute start = GNUNET_TIME_absolute_get ();
struct GNUNET_TIME_Relative delay; struct GNUNET_TIME_Relative delay;
ds = TALER_CRYPTO_helper_denom_sign (dh, ds = TALER_CRYPTO_helper_rsa_sign (dh,
&keys[i].h_denom_pub, &keys[i].h_rsa,
pd.coin_ev, pd.coin_ev,
pd.coin_ev_size, pd.coin_ev_size,
&ec); &ec);
if (TALER_EC_NONE != ec) if (TALER_EC_NONE != ec)
break; break;
delay = GNUNET_TIME_absolute_get_duration (start); delay = GNUNET_TIME_absolute_get_duration (start);
@ -466,7 +466,7 @@ par_signing (struct GNUNET_CONFIGURATION_Handle *cfg)
struct GNUNET_TIME_Absolute start; struct GNUNET_TIME_Absolute start;
struct GNUNET_TIME_Relative duration; struct GNUNET_TIME_Relative duration;
pid_t pids[NUM_CORES]; pid_t pids[NUM_CORES];
struct TALER_CRYPTO_DenominationHelper *dh; struct TALER_CRYPTO_RsaDenominationHelper *dh;
start = GNUNET_TIME_absolute_get (); start = GNUNET_TIME_absolute_get ();
for (unsigned int i = 0; i<NUM_CORES; i++) for (unsigned int i = 0; i<NUM_CORES; i++)
@ -481,13 +481,13 @@ par_signing (struct GNUNET_CONFIGURATION_Handle *cfg)
{ {
int ret; int ret;
dh = TALER_CRYPTO_helper_denom_connect (cfg, dh = TALER_CRYPTO_helper_rsa_connect (cfg,
&key_cb, &key_cb,
NULL); NULL);
GNUNET_assert (NULL != dh); GNUNET_assert (NULL != dh);
ret = perf_signing (dh, ret = perf_signing (dh,
"parallel"); "parallel");
TALER_CRYPTO_helper_denom_disconnect (dh); TALER_CRYPTO_helper_rsa_disconnect (dh);
exit (ret); exit (ret);
} }
} }
@ -517,7 +517,7 @@ static int
run_test (void) run_test (void)
{ {
struct GNUNET_CONFIGURATION_Handle *cfg; struct GNUNET_CONFIGURATION_Handle *cfg;
struct TALER_CRYPTO_DenominationHelper *dh; struct TALER_CRYPTO_RsaDenominationHelper *dh;
struct timespec req = { struct timespec req = {
.tv_nsec = 250000000 .tv_nsec = 250000000
}; };
@ -537,9 +537,9 @@ run_test (void)
{ {
nanosleep (&req, nanosleep (&req,
NULL); NULL);
dh = TALER_CRYPTO_helper_denom_connect (cfg, dh = TALER_CRYPTO_helper_rsa_connect (cfg,
&key_cb, &key_cb,
NULL); NULL);
if (NULL != dh) if (NULL != dh)
break; break;
fprintf (stderr, "."); fprintf (stderr, ".");
@ -555,7 +555,7 @@ run_test (void)
{ {
fprintf (stderr, fprintf (stderr,
"\nFAILED: timeout trying to connect to helper\n"); "\nFAILED: timeout trying to connect to helper\n");
TALER_CRYPTO_helper_denom_disconnect (dh); TALER_CRYPTO_helper_rsa_disconnect (dh);
GNUNET_CONFIGURATION_destroy (cfg); GNUNET_CONFIGURATION_destroy (cfg);
return 1; return 1;
} }
@ -570,7 +570,7 @@ run_test (void)
if (0 == ret) if (0 == ret)
ret = perf_signing (dh, ret = perf_signing (dh,
"sequential"); "sequential");
TALER_CRYPTO_helper_denom_disconnect (dh); TALER_CRYPTO_helper_rsa_disconnect (dh);
if (0 == ret) if (0 == ret)
ret = par_signing (cfg); ret = par_signing (cfg);
/* clean up our state */ /* clean up our state */