diff --git a/testsuite/testutils.c b/testsuite/testutils.c index 0f2594e478ff062966c99000e7338832112625a1..4a316a60175e22c14a369ff62698b195706e7953 100644 --- a/testsuite/testutils.c +++ b/testsuite/testutils.c @@ -600,8 +600,8 @@ test_rsa_md5(struct rsa_public_key *pub, void test_rsa_sha1(struct rsa_public_key *pub, - struct rsa_private_key *key, - mpz_t expected) + struct rsa_private_key *key, + mpz_t expected) { struct sha1_ctx sha1; mpz_t signature; @@ -643,8 +643,8 @@ test_rsa_sha1(struct rsa_public_key *pub, void test_rsa_sha256(struct rsa_public_key *pub, - struct rsa_private_key *key, - mpz_t expected) + struct rsa_private_key *key, + mpz_t expected) { struct sha256_ctx sha256; mpz_t signature; @@ -684,6 +684,49 @@ test_rsa_sha256(struct rsa_public_key *pub, mpz_clear(signature); } +void +test_rsa_sha512(struct rsa_public_key *pub, + struct rsa_private_key *key, + mpz_t expected) +{ + struct sha512_ctx sha512; + mpz_t signature; + + sha512_init(&sha512); + mpz_init(signature); + + SIGN(key, sha512, "The magic words are squeamish ossifrage", signature); + + if (verbose) + { + fprintf(stderr, "rsa-sha512 signature: "); + mpz_out_str(stderr, 16, signature); + fprintf(stderr, "\n"); + } + + if (mpz_cmp(signature, expected)) + FAIL(); + + /* Try bad data */ + if (VERIFY(pub, sha512, + "The magick words are squeamish ossifrage", signature)) + FAIL(); + + /* Try correct data */ + if (!VERIFY(pub, sha512, + "The magic words are squeamish ossifrage", signature)) + FAIL(); + + /* Try bad signature */ + mpz_togglebit(signature, 17); + + if (VERIFY(pub, sha512, + "The magic words are squeamish ossifrage", signature)) + FAIL(); + + mpz_clear(signature); +} + #undef SIGN #undef VERIFY diff --git a/testsuite/testutils.h b/testsuite/testutils.h index 352e1e84a9e6e705cf14cb390d24617356816b52..d46b5d839d054f322a68a5e8e3b8b5dc501c053a 100644 --- a/testsuite/testutils.h +++ b/testsuite/testutils.h @@ -122,6 +122,11 @@ test_rsa_sha256(struct rsa_public_key *pub, struct rsa_private_key *key, mpz_t expected); +void +test_rsa_sha512(struct rsa_public_key *pub, + struct rsa_private_key *key, + mpz_t expected); + void test_rsa_key(struct rsa_public_key *pub, struct rsa_private_key *key);