Commit 05d62ef8 authored by Niels Möller's avatar Niels Möller

(test_dsa160): Added argument for expected signature.

(test_dsa256): Likewise.

Rev: nettle/testsuite/dsa-keygen-test.c:1.5
Rev: nettle/testsuite/testutils.c:1.8
Rev: nettle/testsuite/testutils.h:1.5
parent b910a8b8
...@@ -28,7 +28,7 @@ test_main(void) ...@@ -28,7 +28,7 @@ test_main(void)
FAIL(); FAIL();
test_dsa_key(&pub, &key, 160); test_dsa_key(&pub, &key, 160);
test_dsa160(&pub, &key); test_dsa160(&pub, &key, NULL);
if (!dsa_generate_keypair(&pub, &key, if (!dsa_generate_keypair(&pub, &key,
&lfib, (nettle_random_func *) knuth_lfib_random, &lfib, (nettle_random_func *) knuth_lfib_random,
...@@ -37,7 +37,7 @@ test_main(void) ...@@ -37,7 +37,7 @@ test_main(void)
FAIL(); FAIL();
test_dsa_key(&pub, &key, 256); test_dsa_key(&pub, &key, 256);
test_dsa256(&pub, &key); test_dsa256(&pub, &key, NULL);
dsa_public_key_clear(&pub); dsa_public_key_clear(&pub);
dsa_private_key_clear(&key); dsa_private_key_clear(&key);
......
...@@ -826,7 +826,8 @@ test_rsa_key(struct rsa_public_key *pub, ...@@ -826,7 +826,8 @@ test_rsa_key(struct rsa_public_key *pub,
void void
test_dsa160(const struct dsa_public_key *pub, test_dsa160(const struct dsa_public_key *pub,
const struct dsa_private_key *key) const struct dsa_private_key *key,
const struct dsa_signature *expected)
{ {
struct sha1_ctx sha1; struct sha1_ctx sha1;
struct dsa_signature signature; struct dsa_signature signature;
...@@ -840,7 +841,7 @@ test_dsa160(const struct dsa_public_key *pub, ...@@ -840,7 +841,7 @@ test_dsa160(const struct dsa_public_key *pub,
ASSERT (dsa_sha1_sign(pub, key, ASSERT (dsa_sha1_sign(pub, key,
&lfib, (nettle_random_func *) knuth_lfib_random, &lfib, (nettle_random_func *) knuth_lfib_random,
&sha1, &signature)); &sha1, &signature));
if (verbose) if (verbose)
{ {
fprintf(stderr, "dsa160 signature: "); fprintf(stderr, "dsa160 signature: ");
...@@ -849,6 +850,11 @@ test_dsa160(const struct dsa_public_key *pub, ...@@ -849,6 +850,11 @@ test_dsa160(const struct dsa_public_key *pub,
mpz_out_str(stderr, 16, signature.s); mpz_out_str(stderr, 16, signature.s);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
} }
if (expected)
if (mpz_cmp (signature.r, expected->r)
|| mpz_cmp (signature.s, expected->s))
FAIL();
/* Try bad data */ /* Try bad data */
if (DSA_VERIFY(pub, sha1, if (DSA_VERIFY(pub, sha1,
...@@ -872,7 +878,8 @@ test_dsa160(const struct dsa_public_key *pub, ...@@ -872,7 +878,8 @@ test_dsa160(const struct dsa_public_key *pub,
void void
test_dsa256(const struct dsa_public_key *pub, test_dsa256(const struct dsa_public_key *pub,
const struct dsa_private_key *key) const struct dsa_private_key *key,
const struct dsa_signature *expected)
{ {
struct sha256_ctx sha256; struct sha256_ctx sha256;
struct dsa_signature signature; struct dsa_signature signature;
...@@ -896,10 +903,10 @@ test_dsa256(const struct dsa_public_key *pub, ...@@ -896,10 +903,10 @@ test_dsa256(const struct dsa_public_key *pub,
fprintf(stderr, "\n"); fprintf(stderr, "\n");
} }
#if 0 if (expected)
if (mpz_cmp(signature, expected)) if (mpz_cmp (signature.r, expected->r)
FAIL(); || mpz_cmp (signature.s, expected->s))
#endif FAIL();
/* Try bad data */ /* Try bad data */
if (DSA_VERIFY(pub, sha256, if (DSA_VERIFY(pub, sha256,
......
...@@ -168,11 +168,13 @@ test_rsa_key(struct rsa_public_key *pub, ...@@ -168,11 +168,13 @@ test_rsa_key(struct rsa_public_key *pub,
void void
test_dsa160(const struct dsa_public_key *pub, test_dsa160(const struct dsa_public_key *pub,
const struct dsa_private_key *key); const struct dsa_private_key *key,
const struct dsa_signature *expected);
void void
test_dsa256(const struct dsa_public_key *pub, test_dsa256(const struct dsa_public_key *pub,
const struct dsa_private_key *key); const struct dsa_private_key *key,
const struct dsa_signature *expected);
void void
test_dsa_key(struct dsa_public_key *pub, test_dsa_key(struct dsa_public_key *pub,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment