Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Nettle
nettle
Commits
d8b586f5
Commit
d8b586f5
authored
Nov 15, 2015
by
Niels Möller
Browse files
Extended rsa signature test cases.
parent
38f11b9b
Changes
2
Hide whitespace changes
Inline
Side-by-side
ChangeLog
View file @
d8b586f5
...
...
@@ -11,6 +11,9 @@
* rsa.h: Added corresponding prototypes.
* Makefile.in (hogweed_SOURCES): Added new files.
* testsuite/testutils.c (SIGN): Extend macro to test new
functions, and the rsa_*_sign_digest functions. Updated callers.
2015-09-14 Niels Möller <nisse@lysator.liu.se>
* rsa-decrypt-tr.c (rsa_decrypt_tr): Use rsa_compute_root_tr.
...
...
testsuite/testutils.c
View file @
d8b586f5
...
...
@@ -663,9 +663,33 @@ xalloc_limbs (mp_size_t n)
return
xalloc
(
n
*
sizeof
(
mp_limb_t
));
}
#define SIGN(key, hash, msg, signature) do { \
hash##_update(&hash, LDATA(msg)); \
ASSERT(rsa_##hash##_sign(key, &hash, signature)); \
/* Expects local variables pub, key, rstate, digest, signature */
#define SIGN(hash, msg, expected) do { \
hash##_update(&hash, LDATA(msg)); \
ASSERT(rsa_##hash##_sign(key, &hash, signature)); \
if (verbose) \
{ \
fprintf(stderr, "rsa-%s signature: ", #hash); \
mpz_out_str(stderr, 16, signature); \
fprintf(stderr, "\n"); \
} \
ASSERT(mpz_cmp (signature, expected) == 0); \
\
hash##_update(&hash, LDATA(msg)); \
ASSERT(rsa_##hash##_sign_tr(pub, key, &rstate, \
(nettle_random_func *) knuth_lfib_random, \
&hash, signature)); \
ASSERT(mpz_cmp (signature, expected) == 0); \
\
hash##_update(&hash, LDATA(msg)); \
hash##_digest(&hash, sizeof(digest), digest); \
ASSERT(rsa_##hash##_sign_digest(key, digest, signature)); \
ASSERT(mpz_cmp (signature, expected) == 0); \
\
ASSERT(rsa_##hash##_sign_digest_tr(pub, key, &rstate, \
(nettle_random_func *)knuth_lfib_random, \
digest, signature)); \
ASSERT(mpz_cmp (signature, expected) == 0); \
} while(0)
#define VERIFY(key, hash, msg, signature) ( \
...
...
@@ -770,22 +794,16 @@ test_rsa_md5(struct rsa_public_key *pub,
mpz_t
expected
)
{
struct
md5_ctx
md5
;
struct
knuth_lfib_ctx
rstate
;
uint8_t
digest
[
MD5_DIGEST_SIZE
];
mpz_t
signature
;
md5_init
(
&
md5
);
mpz_init
(
signature
);
SIGN
(
key
,
md5
,
"The magic words are squeamish ossifrage"
,
signature
);
knuth_lfib_init
(
&
rstate
,
15
);
if
(
verbose
)
{
fprintf
(
stderr
,
"rsa-md5 signature: "
);
mpz_out_str
(
stderr
,
16
,
signature
);
fprintf
(
stderr
,
"
\n
"
);
}
SIGN
(
md5
,
"The magic words are squeamish ossifrage"
,
expected
);
ASSERT
(
mpz_cmp
(
signature
,
expected
)
==
0
);
/* Try bad data */
ASSERT
(
!
VERIFY
(
pub
,
md5
,
"The magick words are squeamish ossifrage"
,
signature
));
...
...
@@ -808,22 +826,16 @@ test_rsa_sha1(struct rsa_public_key *pub,
mpz_t
expected
)
{
struct
sha1_ctx
sha1
;
struct
knuth_lfib_ctx
rstate
;
uint8_t
digest
[
SHA1_DIGEST_SIZE
];
mpz_t
signature
;
sha1_init
(
&
sha1
);
mpz_init
(
signature
);
knuth_lfib_init
(
&
rstate
,
16
);
SIGN
(
key
,
sha1
,
"The magic words are squeamish ossifrage"
,
signature
);
SIGN
(
sha1
,
"The magic words are squeamish ossifrage"
,
expected
);
if
(
verbose
)
{
fprintf
(
stderr
,
"rsa-sha1 signature: "
);
mpz_out_str
(
stderr
,
16
,
signature
);
fprintf
(
stderr
,
"
\n
"
);
}
ASSERT
(
mpz_cmp
(
signature
,
expected
)
==
0
);
/* Try bad data */
ASSERT
(
!
VERIFY
(
pub
,
sha1
,
"The magick words are squeamish ossifrage"
,
signature
));
...
...
@@ -846,22 +858,16 @@ test_rsa_sha256(struct rsa_public_key *pub,
mpz_t
expected
)
{
struct
sha256_ctx
sha256
;
struct
knuth_lfib_ctx
rstate
;
uint8_t
digest
[
SHA256_DIGEST_SIZE
];
mpz_t
signature
;
sha256_init
(
&
sha256
);
mpz_init
(
signature
);
knuth_lfib_init
(
&
rstate
,
17
);
SIGN
(
key
,
sha256
,
"The magic words are squeamish ossifrage"
,
signature
);
SIGN
(
sha256
,
"The magic words are squeamish ossifrage"
,
expected
);
if
(
verbose
)
{
fprintf
(
stderr
,
"rsa-sha256 signature: "
);
mpz_out_str
(
stderr
,
16
,
signature
);
fprintf
(
stderr
,
"
\n
"
);
}
ASSERT
(
mpz_cmp
(
signature
,
expected
)
==
0
);
/* Try bad data */
ASSERT
(
!
VERIFY
(
pub
,
sha256
,
"The magick words are squeamish ossifrage"
,
signature
));
...
...
@@ -884,22 +890,16 @@ test_rsa_sha512(struct rsa_public_key *pub,
mpz_t
expected
)
{
struct
sha512_ctx
sha512
;
struct
knuth_lfib_ctx
rstate
;
uint8_t
digest
[
SHA512_DIGEST_SIZE
];
mpz_t
signature
;
sha512_init
(
&
sha512
);
mpz_init
(
signature
);
knuth_lfib_init
(
&
rstate
,
18
);
SIGN
(
key
,
sha512
,
"The magic words are squeamish ossifrage"
,
signature
);
SIGN
(
sha512
,
"The magic words are squeamish ossifrage"
,
expected
);
if
(
verbose
)
{
fprintf
(
stderr
,
"rsa-sha512 signature: "
);
mpz_out_str
(
stderr
,
16
,
signature
);
fprintf
(
stderr
,
"
\n
"
);
}
ASSERT
(
mpz_cmp
(
signature
,
expected
)
==
0
);
/* Try bad data */
ASSERT
(
!
VERIFY
(
pub
,
sha512
,
"The magick words are squeamish ossifrage"
,
signature
));
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment