From faf0f96de180ba94eb99e8a2d760c40fd1bfcc9e Mon Sep 17 00:00:00 2001 From: Giovanni Bajo Date: Tue, 27 Sep 2011 01:57:58 +0200 Subject: [PATCH] Fix a bug in case the most significants bits were generated as zero. --- src/numtheory/fp_prime_random_ex.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/numtheory/fp_prime_random_ex.c b/src/numtheory/fp_prime_random_ex.c index 8ade165..e320f6c 100644 --- a/src/numtheory/fp_prime_random_ex.c +++ b/src/numtheory/fp_prime_random_ex.c @@ -55,6 +55,10 @@ int fp_prime_random_ex(fp_int *a, int size, int flags, tfm_prime_callback cb, vo /* make sure the MSbyte has the required number of bits */ a->dp[dsize-1] &= maskAND_msb; + /* Force a->used as well, it could be smaller if the highest bits were + generated as 0 by the callback. */ + a->used = dsize; + /* modify the LSbyte as requested */ a->dp[0] |= maskOR_lsb;