Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
nettle
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
5
Merge Requests
5
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Nettle
nettle
Commits
07a31f84
Commit
07a31f84
authored
Nov 26, 2018
by
Niels Möller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rsa-compute-root-test: Fix qsize. Try more keys.
parent
898ce4be
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
35 deletions
+47
-35
ChangeLog
ChangeLog
+7
-0
testsuite/rsa-compute-root-test.c
testsuite/rsa-compute-root-test.c
+40
-35
No files found.
ChangeLog
View file @
07a31f84
2018-11-26 Niels Möller <nisse@lysator.liu.se>
* testsuite/rsa-compute-root-test.c (generate_keypair): Simplify
selection of psize and qsize, and fix so that qsize is used.
(test_main): Add outer loop, to test with more than one key.
Deallocate storage before exiting.
2018-11-25 Niels Möller <nisse@lysator.liu.se>
* testsuite/rsa-compute-root-test.c: Renamed, from ...
...
...
testsuite/rsa-compute-root-test.c
View file @
07a31f84
...
...
@@ -7,7 +7,8 @@
#include "rsa.h"
#define COUNT 5000
#define KEY_COUNT 20
#define COUNT 100
static
void
random_fn
(
void
*
ctx
,
size_t
n
,
uint8_t
*
dst
)
...
...
@@ -55,26 +56,32 @@ test_one (gmp_randstate_t *rands, struct rsa_public_key *pub,
fprintf
(
stderr
,
"
\n
"
);
fprintf
(
stderr
,
"plaintext(%lu) = "
,
mpz_sizeinbase
(
plaintext
,
2
));
mpn_out_str
(
stderr
,
16
,
mpz_limbs_read
(
plaintext
),
mpz_size
(
plaintext
));
mpz_out_str
(
stderr
,
10
,
plaintext
);
fprintf
(
stderr
,
"
\n
"
);
fprintf
(
stderr
,
"ciphertext(%lu) = "
,
mpz_sizeinbase
(
ciphertext
,
2
));
mpz_out_str
(
stderr
,
10
,
ciphertext
);
fprintf
(
stderr
,
"
\n
"
);
fprintf
(
stderr
,
"decrypted(%lu) = "
,
mpz_sizeinbase
(
decrypted
,
2
));
mp
n_out_str
(
stderr
,
16
,
mpz_limbs_read
(
decrypted
),
mpz_size
(
decrypted
)
);
mp
z_out_str
(
stderr
,
10
,
decrypted
);
fprintf
(
stderr
,
"
\n
"
);
abort
();
}
mpz_clear
(
ciphertext
);
mpz_clear
(
decrypted
);
}
#if !NETTLE_USE_MINI_GMP
/*
w
e want to generate keypairs that are not "standard" but have more size
/*
W
e want to generate keypairs that are not "standard" but have more size
* variance between q and p.
* Function is other
iw
se the same as standard rsa_generate_keypair()
* Function is other
wi
se the same as standard rsa_generate_keypair()
*/
static
void
generate_keypair
(
gmp_randstate_t
*
rands
,
generate_keypair
(
gmp_randstate_t
rands
,
struct
rsa_public_key
*
pub
,
struct
rsa_private_key
*
key
)
{
unsigned
long
int
psize
=
0
;
unsigned
long
int
qsize
=
0
;
unsigned
long
int
psize
;
unsigned
long
int
qsize
;
mpz_t
p1
;
mpz_t
q1
;
mpz_t
phi
;
...
...
@@ -85,18 +92,8 @@ generate_keypair (gmp_randstate_t *rands,
mpz_init
(
phi
);
mpz_init
(
tmp
);
while
(
psize
<
100
)
{
mpz_set_ui
(
tmp
,
500
);
mpz_urandomm
(
tmp
,
*
rands
,
tmp
);
psize
=
mpz_get_ui
(
tmp
);
}
while
(
qsize
<
100
)
{
mpz_set_ui
(
tmp
,
500
);
mpz_urandomm
(
tmp
,
*
rands
,
tmp
);
qsize
=
mpz_get_ui
(
tmp
);
}
psize
=
100
+
gmp_urandomm_ui
(
rands
,
400
);
qsize
=
100
+
gmp_urandomm_ui
(
rands
,
400
);
mpz_set_ui
(
pub
->
e
,
65537
);
...
...
@@ -104,7 +101,7 @@ generate_keypair (gmp_randstate_t *rands,
{
for
(;;)
{
mpz_rrandomb
(
key
->
p
,
*
rands
,
psize
);
mpz_rrandomb
(
key
->
p
,
rands
,
psize
);
mpz_nextprime
(
key
->
p
,
key
->
p
);
mpz_sub_ui
(
p1
,
key
->
p
,
1
);
mpz_gcd
(
tmp
,
pub
->
e
,
p1
);
...
...
@@ -114,7 +111,7 @@ generate_keypair (gmp_randstate_t *rands,
for
(;;)
{
mpz_rrandomb
(
key
->
q
,
*
rands
,
p
size
);
mpz_rrandomb
(
key
->
q
,
rands
,
q
size
);
mpz_nextprime
(
key
->
q
,
key
->
q
);
mpz_sub_ui
(
q1
,
key
->
q
,
1
);
mpz_gcd
(
tmp
,
pub
->
e
,
q1
);
...
...
@@ -181,10 +178,11 @@ test_main (void)
struct
rsa_public_key
pub
;
struct
rsa_private_key
key
;
mpz_t
plaintext
;
unsigned
i
;
unsigned
i
,
j
;
rsa_private_key_init
(
&
key
);
rsa_public_key_init
(
&
pub
);
mpz_init
(
plaintext
);
gmp_randinit_default
(
rands
);
...
...
@@ -207,13 +205,16 @@ test_main (void)
gmp_randseed
(
rands
,
seed
);
mpz_clear
(
seed
);
}
#endif
generate_keypair
(
&
rands
,
&
pub
,
&
key
);
for
(
j
=
0
;
j
<
KEY_COUNT
;
j
++
)
{
#if !NETTLE_USE_MINI_GMP
generate_keypair
(
rands
,
&
pub
,
&
key
);
#else
rsa_generate_keypair
(
&
pub
,
&
key
,
&
rands
,
random_fn
,
NULL
,
NULL
,
512
,
16
);
#endif
/* !NETTLE_USE_MINI_GMP */
mpz_init
(
plaintext
);
for
(
i
=
0
;
i
<
COUNT
;
i
++
)
{
mpz_urandomb
(
plaintext
,
rands
,
mpz_sizeinbase
(
pub
.
n
,
2
)
-
1
);
...
...
@@ -224,6 +225,10 @@ test_main (void)
mpz_rrandomb
(
plaintext
,
rands
,
mpz_sizeinbase
(
pub
.
n
,
2
)
-
1
);
test_one
(
&
rands
,
&
pub
,
&
key
,
plaintext
);
}
}
mpz_clear
(
plaintext
);
rsa_public_key_clear
(
&
pub
);
rsa_private_key_clear
(
&
key
);
gmp_randclear
(
rands
);
}
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