From 63fb3948c54f885c2a3b8989556b93621190f601 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20M=C3=B6ller?= <nisse@lysator.liu.se> Date: Wed, 9 Oct 2002 23:16:10 +0200 Subject: [PATCH] * testsuite/testutils.c (test_dsa_key): New function to sanity check a dsa keypair. Rev: src/nettle/testsuite/testutils.c:1.16 Rev: src/nettle/testsuite/testutils.h:1.14 --- testsuite/testutils.c | 28 ++++++++++++++++++++++++++++ testsuite/testutils.h | 4 ++++ 2 files changed, 32 insertions(+) diff --git a/testsuite/testutils.c b/testsuite/testutils.c index 87cec2ff..9cb06989 100644 --- a/testsuite/testutils.c +++ b/testsuite/testutils.c @@ -507,5 +507,33 @@ test_dsa(const struct dsa_public_key *pub, dsa_signature_clear(&signature); } +void +test_dsa_key(struct dsa_public_key *pub, + struct dsa_private_key *key) +{ + mpz_t t; + + mpz_init(t); + + ASSERT(mpz_sizeinbase(pub->q, 2) == 160); + ASSERT(mpz_sizeinbase(pub->p, 2) >= DSA_MINIMUM_BITS); + + ASSERT(mpz_probab_prime_p(pub->p, 10)); + + ASSERT(mpz_probab_prime_p(pub->q, 10)); + + mpz_fdiv_r(t, pub->p, pub->q); + + ASSERT(0 == mpz_cmp_ui(t, 1)); + + ASSERT(mpz_cmp_ui(pub->g, 1) > 0); + + mpz_powm(t, pub->g, pub->q, pub->p); + ASSERT(0 == mpz_cmp_ui(t, 1)); + + mpz_powm(t, pub->g, key->x, pub->p); + ASSERT(0 == mpz_cmp(t, pub->y)); +}; + #endif /* WITH_PUBLIC_KEY */ diff --git a/testsuite/testutils.h b/testsuite/testutils.h index 8defa091..64d22eeb 100644 --- a/testsuite/testutils.h +++ b/testsuite/testutils.h @@ -91,6 +91,10 @@ void test_dsa(const struct dsa_public_key *pub, const struct dsa_private_key *key); +void +test_dsa_key(struct dsa_public_key *pub, + struct dsa_private_key *key); + #endif /* WITH_PUBLIC_KEY */ #define H2(d, s) decode_hex((d), (s)) -- GitLab