mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2026-01-30 05:42:12 +01:00
Merge pull request #5406 from SparkiDev/mp_int_size
Maths bit size: ensure size is right
This commit is contained in:
@@ -4221,7 +4221,7 @@ int wc_RsaExportKey(RsaKey* key,
|
||||
#ifdef WOLFSSL_KEY_GEN
|
||||
|
||||
/* Check that |p-q| > 2^((size/2)-100) */
|
||||
static int wc_CompareDiffPQ(mp_int* p, mp_int* q, int size)
|
||||
static int wc_CompareDiffPQ(mp_int* p, mp_int* q, int size, int* valid)
|
||||
{
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
mp_int *c = NULL, *d = NULL;
|
||||
@@ -4265,10 +4265,7 @@ static int wc_CompareDiffPQ(mp_int* p, mp_int* q, int size)
|
||||
|
||||
/* compare */
|
||||
if (ret == 0)
|
||||
ret = mp_cmp(d, c);
|
||||
|
||||
if (ret == MP_GT)
|
||||
ret = MP_OKAY;
|
||||
*valid = (mp_cmp(d, c) == MP_GT);
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
if (d != NULL) {
|
||||
@@ -4380,9 +4377,10 @@ static int _CheckProbablePrime(mp_int* p, mp_int* q, mp_int* e, int nlen,
|
||||
*isPrime = MP_NO;
|
||||
|
||||
if (q != NULL) {
|
||||
int valid = 0;
|
||||
/* 5.4 - check that |p-q| <= (2^(1/2))(2^((nlen/2)-1)) */
|
||||
ret = wc_CompareDiffPQ(p, q, nlen);
|
||||
if (ret != MP_OKAY) goto notOkay;
|
||||
ret = wc_CompareDiffPQ(p, q, nlen, &valid);
|
||||
if ((ret != MP_OKAY) || (!valid)) goto notOkay;
|
||||
prime = q;
|
||||
}
|
||||
else
|
||||
|
||||
@@ -5144,7 +5144,7 @@ int sp_set(sp_int* a, sp_int_digit d)
|
||||
return err;
|
||||
}
|
||||
|
||||
#if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_RSA)
|
||||
#if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_RSA) || defined(OPENSSL_EXTRA)
|
||||
/* Set a number into the multi-precision number.
|
||||
*
|
||||
* Number may be larger than the size of a digit.
|
||||
@@ -5579,7 +5579,7 @@ int sp_mul_d(sp_int* a, sp_int_digit d, sp_int* r)
|
||||
/* Predefine complicated rules of when to compile in sp_div_d and sp_mod_d. */
|
||||
#if (defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
|
||||
defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY) || \
|
||||
defined(WC_MP_TO_RADIX)
|
||||
defined(OPENSSL_EXTRA) || defined(WC_MP_TO_RADIX)
|
||||
#define WOLFSSL_SP_DIV_D
|
||||
#endif
|
||||
#if (defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
|
||||
@@ -5951,7 +5951,7 @@ int sp_div_d(sp_int* a, sp_int_digit d, sp_int* r, sp_int_digit* rem)
|
||||
* @return MP_VAL when a is NULL or d is 0.
|
||||
*/
|
||||
#if !defined(WOLFSSL_SP_MATH_ALL) && (!defined(HAVE_ECC) || \
|
||||
!defined(HAVE_COMP_KEY))
|
||||
!defined(HAVE_COMP_KEY)) && !defined(OPENSSL_EXTRA)
|
||||
static
|
||||
#endif /* !WOLFSSL_SP_MATH_ALL && (!HAVE_ECC || !HAVE_COMP_KEY) */
|
||||
int sp_mod_d(sp_int* a, const sp_int_digit d, sp_int_digit* r)
|
||||
|
||||
Reference in New Issue
Block a user