diff --git a/wolfcrypt/src/sp_int.c b/wolfcrypt/src/sp_int.c index e7f22e93b..f9a957cbe 100644 --- a/wolfcrypt/src/sp_int.c +++ b/wolfcrypt/src/sp_int.c @@ -450,7 +450,6 @@ int sp_set(sp_int* a, sp_int_digit d) return MP_OKAY; } -#if !defined(WOLFSSL_RSA_VERIFY_ONLY) || (!defined(NO_DH) || defined(HAVE_ECC)) /* Recalculate the number of digits used. * * a SP integer. @@ -464,6 +463,7 @@ void sp_clamp(sp_int* a) a->used = i + 1; } +#if !defined(WOLFSSL_RSA_VERIFY_ONLY) || (!defined(NO_DH) || defined(HAVE_ECC)) /* Grow big number to be able to hold l digits. * This function does nothing as the number of digits is fixed. * @@ -987,14 +987,19 @@ int sp_tohex(sp_int* a, char* str) * i Index of bit to set. * returns MP_OKAY always. */ -static int sp_set_bit(sp_int* a, int i) +int sp_set_bit(sp_int* a, int i) { - if (i / SP_WORD_SIZE < SP_INT_DIGITS) { + int ret = MP_OKAY; + + if ((a == NULL) || (i / SP_WORD_SIZE >= SP_INT_DIGITS)) { + ret = BAD_FUNC_ARG; + } + else { a->dp[i/SP_WORD_SIZE] |= (sp_int_digit)1 << (i % SP_WORD_SIZE); if (a->used <= i / SP_WORD_SIZE) a->used = (i / SP_WORD_SIZE) + 1; } - return MP_OKAY; + return ret; } /* Exponentiate 2 to the power of e: a = 2^e @@ -2097,6 +2102,21 @@ int sp_exch(sp_int* a, sp_int* b) #endif #endif +#if defined(WOLFSSL_KEY_GEN) && !defined(NO_RSA) +/* Multiply a by digit n and put result into r. r = a * n + * + * a SP integer to be multiplied. + * n Number to multiply by. + * r SP integer result. + * returns MP_OKAY always. + */ +int sp_mul_d(sp_int* a, sp_int_digit n, sp_int* r) +{ + _sp_mul_d(a, n, r, 0); + return MP_OKAY; +} +#endif + /* Returns the run time settings. * * returns the settings value. diff --git a/wolfcrypt/src/wolfmath.c b/wolfcrypt/src/wolfmath.c index b02089b98..4d5a26d19 100644 --- a/wolfcrypt/src/wolfmath.c +++ b/wolfcrypt/src/wolfmath.c @@ -117,10 +117,10 @@ int mp_rand(mp_int* a, int digits, WC_RNG* rng) ret = mp_set_bit(a, digits * DIGIT_BIT - 1); } #else -#if defined(USE_FAST_MATH) - if ((ret == MP_OKAY) && (digits > FP_SIZE)) -#else +#if defined(WOLFSSL_SP_MATH) if ((ret == MP_OKAY) && (digits > SP_INT_DIGITS)) +#else + if ((ret == MP_OKAY) && (digits > FP_SIZE)) #endif { ret = BAD_FUNC_ARG; diff --git a/wolfcrypt/test/test.c b/wolfcrypt/test/test.c index 27dcecb50..3175f3ceb 100644 --- a/wolfcrypt/test/test.c +++ b/wolfcrypt/test/test.c @@ -11794,7 +11794,8 @@ int rsa_test(void) #if defined(HAVE_NTRU) RsaKey caKey; #endif -#ifndef NO_ASN +#if !defined(NO_ASN) || !defined(WOLFSSL_RSA_PUBLIC_ONLY) \ + || defined(WOLFSSL_PUBLIC_MP) word32 idx = 0; #endif #if !defined(WOLFSSL_RSA_VERIFY_ONLY) || defined(WOLFSSL_PUBLIC_MP) diff --git a/wolfssl/wolfcrypt/sp_int.h b/wolfssl/wolfcrypt/sp_int.h index fdd4e0128..fef9dd4ab 100644 --- a/wolfssl/wolfcrypt/sp_int.h +++ b/wolfssl/wolfcrypt/sp_int.h @@ -158,8 +158,8 @@ typedef struct sp_int { #endif } sp_int; -typedef sp_int mp_int; -typedef sp_digit mp_digit; +typedef sp_int mp_int; +typedef sp_int_digit mp_digit; #include @@ -191,6 +191,7 @@ MP_API int sp_lshd(sp_int* a, int s); MP_API int sp_add(sp_int* a, sp_int* b, sp_int* r); MP_API int sp_set_int(sp_int* a, unsigned long b); MP_API int sp_tohex(sp_int* a, char* str); +MP_API int sp_set_bit(sp_int* a, int i); MP_API int sp_2expt(sp_int* a, int e); MP_API int sp_rand_prime(sp_int* r, int len, WC_RNG* rng, void* heap); MP_API int sp_mul(sp_int* a, sp_int* b, sp_int* r); @@ -205,6 +206,7 @@ MP_API int sp_exch(sp_int* a, sp_int* b); MP_API int sp_get_digit_count(sp_int *a); MP_API int sp_init_copy (sp_int * a, sp_int * b); MP_API void sp_rshb(sp_int* a, int n, sp_int* r); +MP_API int sp_mul_d(sp_int* a, sp_int_digit n, sp_int* r); #define MP_OKAY 0 @@ -259,6 +261,7 @@ MP_API void sp_rshb(sp_int* a, int n, sp_int* r); #define mp_add sp_add #define mp_set_int sp_set_int #define mp_tohex sp_tohex +#define mp_set_bit sp_set_bit #define mp_2expt sp_2expt #define mp_rand_prime sp_rand_prime #define mp_mul sp_mul @@ -273,6 +276,7 @@ MP_API void sp_rshb(sp_int* a, int n, sp_int* r); #define get_digit_count sp_get_digit_count #define mp_init_copy sp_init_copy #define mp_rshb(A,x) sp_rshb(A,x,A) +#define mp_mul_d sp_mul_d #endif