Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Nettle
nettle
Commits
d8b586f5
Commit
d8b586f5
authored
Nov 15, 2015
by
Niels Möller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extended rsa signature test cases.
parent
38f11b9b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
43 deletions
+46
-43
ChangeLog
ChangeLog
+3
-0
testsuite/testutils.c
testsuite/testutils.c
+43
-43
No files found.
ChangeLog
View file @
d8b586f5
...
@@ -11,6 +11,9 @@
...
@@ -11,6 +11,9 @@
* rsa.h: Added corresponding prototypes.
* rsa.h: Added corresponding prototypes.
* Makefile.in (hogweed_SOURCES): Added new files.
* 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>
2015-09-14 Niels Möller <nisse@lysator.liu.se>
* rsa-decrypt-tr.c (rsa_decrypt_tr): Use rsa_compute_root_tr.
* 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)
...
@@ -663,9 +663,33 @@ xalloc_limbs (mp_size_t n)
return
xalloc
(
n
*
sizeof
(
mp_limb_t
));
return
xalloc
(
n
*
sizeof
(
mp_limb_t
));
}
}
#define SIGN(key, hash, msg, signature) do { \
/* Expects local variables pub, key, rstate, digest, signature */
hash##_update(&hash, LDATA(msg)); \
#define SIGN(hash, msg, expected) do { \
ASSERT(rsa_##hash##_sign(key, &hash, signature)); \
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)
} while(0)
#define VERIFY(key, hash, msg, signature) ( \
#define VERIFY(key, hash, msg, signature) ( \
...
@@ -770,22 +794,16 @@ test_rsa_md5(struct rsa_public_key *pub,
...
@@ -770,22 +794,16 @@ test_rsa_md5(struct rsa_public_key *pub,
mpz_t
expected
)
mpz_t
expected
)
{
{
struct
md5_ctx
md5
;
struct
md5_ctx
md5
;
struct
knuth_lfib_ctx
rstate
;
uint8_t
digest
[
MD5_DIGEST_SIZE
];
mpz_t
signature
;
mpz_t
signature
;
md5_init
(
&
md5
);
md5_init
(
&
md5
);
mpz_init
(
signature
);
mpz_init
(
signature
);
knuth_lfib_init
(
&
rstate
,
15
);
SIGN
(
key
,
md5
,
"The magic words are squeamish ossifrage"
,
signature
);
if
(
verbose
)
SIGN
(
md5
,
"The magic words are squeamish ossifrage"
,
expected
);
{
fprintf
(
stderr
,
"rsa-md5 signature: "
);
mpz_out_str
(
stderr
,
16
,
signature
);
fprintf
(
stderr
,
"
\n
"
);
}
ASSERT
(
mpz_cmp
(
signature
,
expected
)
==
0
);
/* Try bad data */
/* Try bad data */
ASSERT
(
!
VERIFY
(
pub
,
md5
,
ASSERT
(
!
VERIFY
(
pub
,
md5
,
"The magick words are squeamish ossifrage"
,
signature
));
"The magick words are squeamish ossifrage"
,
signature
));
...
@@ -808,22 +826,16 @@ test_rsa_sha1(struct rsa_public_key *pub,
...
@@ -808,22 +826,16 @@ test_rsa_sha1(struct rsa_public_key *pub,
mpz_t
expected
)
mpz_t
expected
)
{
{
struct
sha1_ctx
sha1
;
struct
sha1_ctx
sha1
;
struct
knuth_lfib_ctx
rstate
;
uint8_t
digest
[
SHA1_DIGEST_SIZE
];
mpz_t
signature
;
mpz_t
signature
;
sha1_init
(
&
sha1
);
sha1_init
(
&
sha1
);
mpz_init
(
signature
);
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 */
/* Try bad data */
ASSERT
(
!
VERIFY
(
pub
,
sha1
,
ASSERT
(
!
VERIFY
(
pub
,
sha1
,
"The magick words are squeamish ossifrage"
,
signature
));
"The magick words are squeamish ossifrage"
,
signature
));
...
@@ -846,22 +858,16 @@ test_rsa_sha256(struct rsa_public_key *pub,
...
@@ -846,22 +858,16 @@ test_rsa_sha256(struct rsa_public_key *pub,
mpz_t
expected
)
mpz_t
expected
)
{
{
struct
sha256_ctx
sha256
;
struct
sha256_ctx
sha256
;
struct
knuth_lfib_ctx
rstate
;
uint8_t
digest
[
SHA256_DIGEST_SIZE
];
mpz_t
signature
;
mpz_t
signature
;
sha256_init
(
&
sha256
);
sha256_init
(
&
sha256
);
mpz_init
(
signature
);
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 */
/* Try bad data */
ASSERT
(
!
VERIFY
(
pub
,
sha256
,
ASSERT
(
!
VERIFY
(
pub
,
sha256
,
"The magick words are squeamish ossifrage"
,
signature
));
"The magick words are squeamish ossifrage"
,
signature
));
...
@@ -884,22 +890,16 @@ test_rsa_sha512(struct rsa_public_key *pub,
...
@@ -884,22 +890,16 @@ test_rsa_sha512(struct rsa_public_key *pub,
mpz_t
expected
)
mpz_t
expected
)
{
{
struct
sha512_ctx
sha512
;
struct
sha512_ctx
sha512
;
struct
knuth_lfib_ctx
rstate
;
uint8_t
digest
[
SHA512_DIGEST_SIZE
];
mpz_t
signature
;
mpz_t
signature
;
sha512_init
(
&
sha512
);
sha512_init
(
&
sha512
);
mpz_init
(
signature
);
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 */
/* Try bad data */
ASSERT
(
!
VERIFY
(
pub
,
sha512
,
ASSERT
(
!
VERIFY
(
pub
,
sha512
,
"The magick words are squeamish ossifrage"
,
signature
));
"The magick words are squeamish ossifrage"
,
signature
));
...
...
Write
Preview
Markdown
is supported
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