Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
N
nettle
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Wim Lewis
nettle
Commits
d8b586f5
Commit
d8b586f5
authored
Nov 15, 2015
by
Niels Möller
Browse files
Options
Downloads
Patches
Plain Diff
Extended rsa signature test cases.
parent
38f11b9b
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
ChangeLog
+3
-0
3 additions, 0 deletions
ChangeLog
testsuite/testutils.c
+43
-43
43 additions, 43 deletions
testsuite/testutils.c
with
46 additions
and
43 deletions
ChangeLog
+
3
−
0
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.
...
...
This diff is collapsed.
Click to expand it.
testsuite/testutils.c
+
43
−
43
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 */
#define SIGN(hash, msg, expected) do { \
hash##_update(&hash, LDATA(msg)); \
hash##_update(&hash, LDATA(msg)); \
ASSERT(rsa_##hash##_sign(key, &hash, signature)); \
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,21 +794,15 @@ test_rsa_md5(struct rsa_public_key *pub,
...
@@ -770,21 +794,15 @@ 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
);
SIGN
(
md5
,
"The magic words are squeamish ossifrage"
,
expected
);
if
(
verbose
)
{
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
,
...
@@ -808,21 +826,15 @@ test_rsa_sha1(struct rsa_public_key *pub,
...
@@ -808,21 +826,15 @@ 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
,
...
@@ -846,21 +858,15 @@ test_rsa_sha256(struct rsa_public_key *pub,
...
@@ -846,21 +858,15 @@ 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
,
...
@@ -884,21 +890,15 @@ test_rsa_sha512(struct rsa_public_key *pub,
...
@@ -884,21 +890,15 @@ 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
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment