Merge pull request #3714 from SparkiDev/sp_int_rsavfy

This commit is contained in:
David Garske
2021-02-09 07:28:40 -08:00
committed by GitHub
8 changed files with 175 additions and 115 deletions

View File

@ -2441,6 +2441,7 @@ then
fi
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_RSA_PUBLIC_ONLY -DWOLFSSL_RSA_VERIFY_ONLY"
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_RSA_VERIFY_INLINE -DNO_SIG_WRAPPER"
AM_CFLAGS="$AM_CFLAGS -DNO_CHECK_PRIVATE_KEY"
fi

View File

@ -594,7 +594,8 @@ static const char* bench_result_words1[][4] = {
#endif
};
#if !defined(NO_RSA) || defined(HAVE_NTRU) || \
#if (!defined(NO_RSA) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
!defined(WOLFSSL_RSA_VERIFY_ONLY)) || defined(HAVE_NTRU) || \
defined(HAVE_ECC) || !defined(NO_DH) || defined(HAVE_ECC_ENCRYPT) || \
defined(HAVE_CURVE25519) || defined(HAVE_CURVE25519_SHARED_SECRET) || \
defined(HAVE_ED25519) || defined(HAVE_CURVE448) || \
@ -738,8 +739,9 @@ static const char* bench_desc_words[][9] = {
#endif
#if defined(BENCH_ASYM)
#if defined(HAVE_ECC) || !defined(WOLFSSL_RSA_PUBLIC_ONLY) || \
defined(WOLFSSL_PUBLIC_MP) || !defined(NO_DH)
#if defined(HAVE_ECC) || (!defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
!defined(WOLFSSL_RSA_VERIFY_ONLY)) || defined(WOLFSSL_PUBLIC_MP) || \
!defined(NO_DH)
static const char* bench_result_words2[][5] = {
{ "ops took", "sec" , "avg" , "ops/sec", NULL }, /* 0 English */
#ifndef NO_MULTIBYTE_PRINT
@ -1276,8 +1278,9 @@ static void bench_stats_sym_finish(const char* desc, int doAsync, int count,
}
#ifdef BENCH_ASYM
#if defined(HAVE_ECC) || !defined(WOLFSSL_RSA_PUBLIC_ONLY) || \
defined(WOLFSSL_PUBLIC_MP) || !defined(NO_DH)
#if defined(HAVE_ECC) || (!defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
!defined(WOLFSSL_RSA_VERIFY_ONLY)) || defined(WOLFSSL_PUBLIC_MP) || \
!defined(NO_DH)
static void bench_stats_asym_finish(const char* algo, int strength,
const char* desc, int doAsync, int count, double start, int ret)
{
@ -4554,7 +4557,8 @@ static unsigned char rsa_3072_sig[] = {
#endif
#endif
#if !defined(WOLFSSL_RSA_PUBLIC_ONLY) || defined(WOLFSSL_PUBLIC_MP)
#if (!defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
!defined(WOLFSSL_RSA_VERIFY_ONLY)) || defined(WOLFSSL_PUBLIC_MP)
static void bench_rsa_helper(int doAsync, RsaKey rsaKey[BENCH_MAX_PENDING],
int rsaKeySz)
{
@ -4676,7 +4680,7 @@ exit:
#endif
}
else {
#ifndef WOLFSSL_RSA_PUBLIC_ONLY
#if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
/* begin RSA sign */
bench_stats_start(&count, &start);
do {
@ -4772,7 +4776,8 @@ void bench_rsa(int doAsync)
#endif
int i;
RsaKey rsaKey[BENCH_MAX_PENDING];
#if !defined(WOLFSSL_RSA_PUBLIC_ONLY) || defined(WOLFSSL_PUBLIC_MP)
#if (!defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
!defined(WOLFSSL_RSA_VERIFY_ONLY)) || defined(WOLFSSL_PUBLIC_MP)
int rsaKeySz; /* used in printf */
size_t bytes;
const byte* tmp;
@ -4814,7 +4819,7 @@ void bench_rsa(int doAsync)
#endif
#endif
#ifndef WOLFSSL_RSA_PUBLIC_ONLY
#if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
/* decode the private key */
idx = 0;
if ((ret = wc_RsaPrivateKeyDecode(tmp, &idx, &rsaKey[i],
@ -4843,7 +4848,8 @@ void bench_rsa(int doAsync)
}
#if !defined(WOLFSSL_RSA_PUBLIC_ONLY) || defined(WOLFSSL_PUBLIC_MP)
#if (!defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
!defined(WOLFSSL_RSA_VERIFY_ONLY)) || defined(WOLFSSL_PUBLIC_MP)
bench_rsa_helper(doAsync, rsaKey, rsaKeySz);
#endif
exit_bench_rsa:

View File

@ -2273,6 +2273,7 @@ static int wc_RsaFunctionSync(const byte* in, word32 inLen, byte* out,
tmp = (mp_int*)XMALLOC(sizeof(mp_int), key->heap, DYNAMIC_TYPE_RSA);
if (tmp == NULL)
return MEMORY_E;
#if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
#ifdef WC_RSA_BLINDING
rnd = (mp_int*)XMALLOC(sizeof(mp_int) * 2, key->heap, DYNAMIC_TYPE_RSA);
if (rnd == NULL) {
@ -2281,11 +2282,13 @@ static int wc_RsaFunctionSync(const byte* in, word32 inLen, byte* out,
}
rndi = rnd + 1;
#endif /* WC_RSA_BLINDING */
#endif
#endif /* WOLFSSL_SMALL_STACK */
if (mp_init(tmp) != MP_OKAY)
ret = MP_INIT_E;
#if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
#ifdef WC_RSA_BLINDING
if (ret == 0) {
if (type == RSA_PRIVATE_DECRYPT || type == RSA_PRIVATE_ENCRYPT) {
@ -2296,6 +2299,7 @@ static int wc_RsaFunctionSync(const byte* in, word32 inLen, byte* out,
}
}
#endif
#endif
#ifndef TEST_UNPAD_CONSTANT_TIME
if (ret == 0 && mp_read_unsigned_bin(tmp, (byte*)in, inLen) != MP_OKAY)
@ -2303,7 +2307,7 @@ static int wc_RsaFunctionSync(const byte* in, word32 inLen, byte* out,
if (ret == 0) {
switch(type) {
#ifndef WOLFSSL_RSA_PUBLIC_ONLY
#if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
case RSA_PRIVATE_DECRYPT:
case RSA_PRIVATE_ENCRYPT:
{
@ -2762,6 +2766,7 @@ int wc_RsaFunction(const byte* in, word32 inLen, byte* out,
}
#endif
#ifndef WOLFSSL_RSA_VERIFY_ONLY
#ifndef TEST_UNPAD_CONSTANT_TIME
#ifndef NO_RSA_BOUNDS_CHECK
if (type == RSA_PRIVATE_DECRYPT &&
@ -2812,6 +2817,7 @@ int wc_RsaFunction(const byte* in, word32 inLen, byte* out,
}
#endif /* NO_RSA_BOUNDS_CHECK */
#endif
#endif
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_RSA)
if (key->asyncDev.marker == WOLFSSL_ASYNC_MARKER_RSA &&

View File

@ -394,7 +394,8 @@ int wc_SignatureGenerateHash_ex(
case WC_SIGNATURE_TYPE_RSA_W_ENC:
case WC_SIGNATURE_TYPE_RSA:
#if !defined(NO_RSA) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)
#if !defined(NO_RSA) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
!defined(WOLFSSL_RSA_VERIFY_ONLY)
#ifdef WOLFSSL_CRYPTOCELL
/* use expected signature size (incoming sig_len could be larger buffer */
*sig_len = wc_SignatureGetSize(sig_type, key, key_len);

View File

@ -1952,7 +1952,7 @@ static WC_INLINE sp_int_digit sp_div_word(sp_int_digit hi, sp_int_digit lo,
#if (!defined(NO_RSA) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)) || \
!defined(NO_DSA) || !defined(NO_DH) || \
(defined(HAVE_ECC) && defined(HAVE_COMP_KEY)) || defined(OPENSSL_EXTRA) || \
defined(WOLFSSL_SP_MATH_ALL)
(defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_PUBLIC_ONLY))
#ifndef WC_NO_CACHE_RESISTANT
/* Mask of address for constant time operations. */
const size_t sp_off_on_addr[2] =
@ -1987,7 +1987,7 @@ WOLFSSL_LOCAL int sp_ModExp_4096(sp_int* base, sp_int* exp, sp_int* mod,
#endif
#if defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
#if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH)
static int _sp_mont_red(sp_int* a, sp_int* m, sp_int_digit mp);
#endif
@ -2255,7 +2255,8 @@ int sp_init_copy(sp_int* r, sp_int* a)
}
#endif /* WOLSSL_SP_MATH_ALL || (HAVE_ECC && FP_ECC) */
#if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_DH) || !defined(NO_DSA)
#if (defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
!defined(NO_DH) || !defined(NO_DSA)
/* Exchange the values in a and b.
*
* @param [in,out] a SP integer to swap.
@ -2300,7 +2301,8 @@ int sp_exch(sp_int* a, sp_int* b)
#endif
return err;
}
#endif /* defined(WOLFSSL_SP_MATH_ALL) || !NO_DH || !NO_DSA */
#endif /* (WOLFSSL_SP_MATH_ALL && !WOLFSSL_RSA_VERIFY_ONLY) || !NO_DH ||
* !NO_DSA */
#if defined(HAVE_ECC) && defined(ECC_TIMING_RESISTANT) && \
!defined(WC_NO_CACHE_RESISTANT)
@ -2362,6 +2364,8 @@ int sp_abs(sp_int* a, sp_int* r)
}
#endif /* WOLFSSL_SP_INT_NEGATIVE */
#if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_DH) || defined(HAVE_ECC) || \
(!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
/* Compare absolute value of two multi-precision numbers.
*
* @param [in] a SP integer.
@ -2398,8 +2402,9 @@ static int _sp_cmp_abs(sp_int* a, sp_int* b)
return ret;
}
#endif
#ifdef WOLFSSL_SP_MATH_ALL
#if defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)
/* Compare absolute value of two multi-precision numbers.
*
* @param [in] a SP integer.
@ -2431,6 +2436,9 @@ int sp_cmp_mag(sp_int* a, sp_int* b)
}
#endif
#if defined(WOLFSSL_SP_MATH_ALL) || defined(HAVE_ECC) || !defined(NO_DSA) || \
defined(OPENSSL_EXTRA) || \
(!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
/* Compare two multi-precision numbers.
*
* Assumes a and b are not NULL.
@ -2462,8 +2470,9 @@ static int _sp_cmp(sp_int* a, sp_int* b)
return ret;
}
#endif
#ifndef WOLFSSL_RSA_VERIFY_ONLY
/* Compare two multi-precision numbers.
*
* Pointers are compared such that NULL is less than not NULL.
@ -2495,6 +2504,7 @@ int sp_cmp(sp_int* a, sp_int* b)
return ret;
}
#endif
/*************************
* Bit check/set functions
@ -2569,7 +2579,8 @@ int sp_count_bits(sp_int* a)
return r;
}
#if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \
#if (defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY) && \
!defined(WOLFSSL_RSA_PUBLIC_ONLY)) || defined(WOLFSSL_HAVE_SP_DH) || \
(defined(HAVE_ECC) && defined(FP_ECC))
/* Number of entries in array of number of least significant zero bits. */
@ -2685,7 +2696,8 @@ int sp_set_bit(sp_int* a, int i)
#endif /* WOLFSSL_SP_MATH_ALL || WOLFSSL_HAVE_SP_DH || HAVE_ECC ||
* WOLFSSL_KEY_GEN || OPENSSL_EXTRA || !NO_RSA */
#if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_KEY_GEN)
#if (defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
defined(WOLFSSL_KEY_GEN)
/* Exponentiate 2 to the power of e: a = 2^e
* This is done by setting the 'e'th bit.
*
@ -2709,13 +2721,13 @@ int sp_2expt(sp_int* a, int e)
return err;
}
#endif /* WOLFSSL_SP_MATH_ALL || WOLFSSL_KEY_GEN */
#endif /* (WOLFSSL_SP_MATH_ALL && !WOLFSSL_RSA_VERIFY_ONLY) ||
* WOLFSSL_KEY_GEN */
/**********************
* Digit/Long functions
**********************/
#if !defined(WOLFSSL_RSA_VERIFY_ONLY)
/* Set the multi-precision number to be the value of the digit.
*
* @param [out] a SP integer to become number.
@ -2741,7 +2753,6 @@ int sp_set(sp_int* a, sp_int_digit d)
return err;
}
#endif /* WOLFSSL_RSA_VERIFY_ONLY */
#if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_RSA)
/* Set a number into the multi-precision number.
@ -2788,6 +2799,7 @@ int sp_set_int(sp_int* a, unsigned long n)
}
#endif /* WOLFSSL_SP_MATH_ALL || !NO_RSA */
#ifndef WOLFSSL_RSA_VERIFY_ONLY
/* Compare a one digit number with a multi-precision number.
*
* When a is NULL, MP_LT is returned.
@ -2838,10 +2850,11 @@ int sp_cmp_d(sp_int* a, sp_int_digit d)
return ret;
}
#endif
#if defined(WOLFSSL_SP_INT_NEGATIVE) || !defined(NO_PWDBASED) || \
defined(WOLFSSL_KEY_GEN) || !defined(NO_DH) || !defined(NO_RSA) || \
defined(WOLFSSL_SP_MATH_ALL)
defined(WOLFSSL_KEY_GEN) || !defined(NO_DH) || (!defined(NO_RSA) && \
!defined(WOLFSSL_RSA_VERIFY_ONLY))
/* Add a one digit number to the multi-precision number.
*
* @param [in] a SP integer be added to.
@ -2889,9 +2902,10 @@ static int _sp_add_d(sp_int* a, sp_int_digit d, sp_int* r)
return err;
}
#endif /* WOLFSSL_SP_INT_NEGATIVE || !NO_PWDBASED || WOLFSSL_KEY_GEN ||
* !NO_DH || !NO_RSA */
* !NO_DH || !NO_RSA && !WOLFSSL_RSA_VERIFY_ONLY) */
#if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_SP_INT_NEGATIVE) || \
#if defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY) || \
defined(WOLFSSL_SP_INT_NEGATIVE) || \
!defined(NO_DH) || !defined(NO_DSA) || defined(HAVE_ECC) || \
(!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
/* Sub a one digit number from the multi-precision number.
@ -2933,7 +2947,7 @@ static void _sp_sub_d(sp_int* a, sp_int_digit d, sp_int* r)
* HAVE_ECC || (!NO_RSA && !WOLFSSL_RSA_VERIFY_ONLY) */
#if !defined(NO_PWDBASED) || defined(WOLFSSL_KEY_GEN) || !defined(NO_DH) || \
!defined(NO_DSA) || !defined(NO_RSA)
!defined(NO_DSA) || (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
/* Add a one digit number to the multi-precision number.
*
* @param [in] a SP integer be added to.
@ -3017,9 +3031,12 @@ int sp_sub_d(sp_int* a, sp_int_digit d, sp_int* r)
#endif /* (!NO_RSA && !WOLFSSL_RSA_VERIFY_ONLY) || !NO_DH || HAVE_ECC ||
* !NO_DSA */
#if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_SP_SMALL) && \
(!defined(NO_DH) || defined(HAVE_ECC) || \
(!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY)))
#if (defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
defined(WOLFSSL_SP_SMALL) && (defined(WOLFSSL_SP_MATH_ALL) || \
!defined(NO_DH) || defined(HAVE_ECC) || \
(!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY) && \
!defined(WOLFSSL_RSA_PUBLIC_ONLY))) || \
(defined(WOLFSSL_KEY_GEN) && !defined(NO_RSA))
/* Multiply a by digit n and put result into r shifting up o digits.
* r = (a * n) << (o * SP_WORD_SIZE)
*
@ -3052,11 +3069,11 @@ static void _sp_mul_d(sp_int* a, sp_int_digit n, sp_int* r, int o)
r->used = o;
sp_clamp(r);
}
#endif /* WOLFSSL_SP_MATH_ALL || WOLFSSL_SP_SMALL ||
* (WOLFSSL_KEY_GEN && !NO_RSA) */
#endif /* (WOLFSSL_SP_MATH_ALL && !WOLFSSL_RSA_VERIFY_ONLY) ||
* WOLFSSL_SP_SMALL || (WOLFSSL_KEY_GEN && !NO_RSA) */
#if defined(WOLFSSL_SP_MATH_ALL) || (defined(WOLFSSL_KEY_GEN) && \
!defined(NO_RSA))
#if (defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
(defined(WOLFSSL_KEY_GEN) && !defined(NO_RSA))
/* Multiply a by digit n and put result into r. r = a * n
*
* @param [in] a SP integer to multiply.
@ -3086,7 +3103,8 @@ int sp_mul_d(sp_int* a, sp_int_digit d, sp_int* r)
return err;
}
#endif /* WOLFSSL_SP_MATH_ALL || (WOLFSSL_KEY_GEN && !NO_RSA) */
#endif /* (WOLFSSL_SP_MATH_ALL && !WOLFSSL_RSA_VERIFY_ONLY) ||
* (WOLFSSL_KEY_GEN && !NO_RSA) */
#if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_DH) || defined(HAVE_ECC) || \
(!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
@ -3152,7 +3170,8 @@ static WC_INLINE sp_int_digit sp_div_word(sp_int_digit hi, sp_int_digit lo,
#endif /* WOLFSSL_SP_MATH_ALL || !NO_DH || HAVE_ECC ||
* (!NO_RSA && !WOLFSSL_RSA_VERIFY_ONLY) */
#if !defined(WOLFSSL_SP_SMALL) && (defined(WOLFSSL_SP_MATH_ALL) || \
#if !defined(WOLFSSL_SP_SMALL) && ((defined(WOLFSSL_SP_MATH_ALL) && \
!defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
defined(WOLFSSL_HAVE_SP_DH) || (defined(HAVE_ECC) && (defined(FP_ECC) || \
defined(HAVE_COMP_KEY))))
/* Divide by 3: r = a / 3 and rem = a % 3
@ -3266,10 +3285,12 @@ static void _sp_div_10(sp_int* a, sp_int* r, sp_int_digit* rem)
}
}
}
#endif /* !WOLFSSL_SP_SMALL && (WOLFSSL_SP_MATH_ALL || WOLFSSL_HAVE_SP_DH ||
#endif /* !WOLFSSL_SP_SMALL && ((WOLFSSL_SP_MATH_ALL &&
* !WOLFSSL_RSA_VERIFY_ONLY) || WOLFSSL_HAVE_SP_DH ||
* (HAVE_ECC && FP_ECC)) */
#if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \
#if (defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
defined(WOLFSSL_HAVE_SP_DH) || \
(defined(HAVE_ECC) && (defined(FP_ECC) || defined(HAVE_COMP_KEY)))
/* Divide by small number: r = a / d and rem = a % d
*
@ -3316,8 +3337,8 @@ static void _sp_div_small(sp_int* a, sp_int_digit d, sp_int* r,
}
#endif
#if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_KEY_GEN) || \
defined(HAVE_COMP_KEY)
#if (defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY)
/* Divide a multi-precision number by a digit size number and calcualte
* remainder.
* r = a / d; rem = a % d
@ -3386,7 +3407,8 @@ int sp_div_d(sp_int* a, sp_int_digit d, sp_int* r, sp_int_digit* rem)
}
#endif
#if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \
#if (defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
defined(WOLFSSL_HAVE_SP_DH) || \
(defined(HAVE_ECC) && (defined(FP_ECC) || defined(HAVE_COMP_KEY)))
/* Calculate a modulo the digit d into r: r = a mod d
*
@ -3462,8 +3484,8 @@ int sp_mod_d(sp_int* a, const sp_int_digit d, sp_int_digit* r)
return err;
}
#endif /* WOLFSSL_SP_MATH_ALL || WOLFSSL_HAVE_SP_DH ||
* (HAVE_ECC && (FP_ECC || HAVE_COMP_KEY)) */
#endif /* (WOLFSSL_SP_MATH_ALL && !WOLFSSL_RSA_VERFIY_ONLY) || \
* WOLFSSL_HAVE_SP_DH || (HAVE_ECC && (FP_ECC || HAVE_COMP_KEY)) */
#if defined(WOLFSSL_SP_MATH_ALL) && defined(HAVE_ECC)
/* Divides a by 2 mod m and stores in r: r = (a / 2) mod m
@ -3522,7 +3544,8 @@ int sp_div_2_mod_ct(sp_int* a, sp_int* m, sp_int* r)
#endif /* WOLFSSL_SP_MATH_ALL && HAVE_ECC */
#if defined(HAVE_ECC) || !defined(NO_DSA) || defined(OPENSSL_EXTRA) || \
(!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
(!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY) && \
!defined(WOLFSSL_RSA_PUBLIC_ONLY))
/* Divides a by 2 and stores in r: r = a >> 1
*
* @param [in] a SP integer to divide.
@ -3763,8 +3786,8 @@ int sp_sub(sp_int* a, sp_int* b, sp_int* r)
* Add/Subtract mod functions
****************************/
#if defined(WOLFSSL_SP_MATH_ALL) || (!defined(WOLFSSL_SP_MATH) && \
defined(WOLFSSL_CUSTOM_CURVES))
#if (defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
(!defined(WOLFSSL_SP_MATH) && defined(WOLFSSL_CUSTOM_CURVES))
/* Add two value and reduce: r = (a + b) % m
*
* @param [in] a SP integer to add.
@ -3824,7 +3847,7 @@ int sp_addmod(sp_int* a, sp_int* b, sp_int* m, sp_int* r)
}
#endif /* WOLFSSL_SP_MATH_ALL || (!WOLFSSL_SP_MATH && WOLFSSL_CUSTOM_CURVES) */
#ifdef WOLFSSL_SP_MATH_ALL
#if defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
/* Sub b from a and reduce: r = (a - b) % m
* Result is always positive.
*
@ -4089,8 +4112,8 @@ int sp_submod_ct(sp_int* a, sp_int* b, sp_int* m, sp_int* r)
* Shifting functoins
********************/
#if !defined(NO_DH) || defined(HAVE_ECC) || defined(WC_RSA_BLINDING) || \
!defined(WOLFSSL_RSA_VERIFY_ONLY)
#if !defined(NO_DH) || defined(HAVE_ECC) || (defined(WC_RSA_BLINDING) && \
!defined(WOLFSSL_RSA_VERIFY_ONLY))
/* Left shift the multi-precision number by a number of digits.
*
* @param [in,out] a SP integer to shift.
@ -4121,7 +4144,8 @@ int sp_lshd(sp_int* a, int s)
#endif
#if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_DH) || defined(HAVE_ECC) || \
(!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
(!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY) && \
!defined(WOLFSSL_RSA_PUBLIC_ONLY))
/* Left shift the multi-precision number by n bits.
* Bits may be larger than the word size.
*
@ -4165,7 +4189,8 @@ static int sp_lshb(sp_int* a, int n)
#endif /* WOLFSSL_SP_MATH_ALL || !NO_DH || HAVE_ECC ||
* (!NO_RSA && !WOLFSSL_RSA_VERIFY_ONLY) */
#if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_DH) || defined(HAVE_ECC) || \
#if (defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
!defined(NO_DH) || defined(HAVE_ECC) || \
(!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
/* Shift a right by n digits into r: r = a >> (n * SP_WORD_SIZE)
*
@ -4191,8 +4216,8 @@ void sp_rshd(sp_int* a, int c)
}
}
}
#endif /* WOLFSSL_SP_MATH_ALL || !NO_DH || HAVE_ECC ||
* (!NO_RSA && !WOLFSSL_RSA_VERIFY_ONLY) */
#endif /* (WOLFSSL_SP_MATH_ALL && !WOLFSSL_RSA_VERIFY_ONLY) || !NO_DH ||
* HAVE_ECC || (!NO_RSA && !WOLFSSL_RSA_VERIFY_ONLY) */
#if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_DH) || defined(HAVE_ECC) || \
(!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
@ -4239,7 +4264,8 @@ void sp_rshb(sp_int* a, int n, sp_int* r)
* (!NO_RSA && !WOLFSSL_RSA_VERIFY_ONLY) || WOLFSSL_HAVE_SP_DH */
#if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_DH) || defined(HAVE_ECC) || \
(!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
(!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY) && \
!defined(WOLFSSL_RSA_PUBLIC_ONLY))
/* Divide a by d and return the quotient in r and the remainder in rem.
* r = a / d; rem = a % d
*
@ -4495,7 +4521,8 @@ int sp_div(sp_int* a, sp_int* d, sp_int* r, sp_int* rem)
* (!NO_RSA && !WOLFSSL_RSA_VERIFY_ONLY) */
#if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_DH) || defined(HAVE_ECC) || \
(!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
(!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY) && \
!defined(WOLFSSL_RSA_PUBLIC_ONLY))
#ifndef FREESCALE_LTC_TFM
/* Calculate the remainder of dividing a by m: r = a mod m.
*
@ -7703,7 +7730,7 @@ int sp_mul(sp_int* a, sp_int* b, sp_int* r)
}
/* END SP_MUL implementations. */
#if !defined(WOLFSSL_RSA_VERIFY_ONLY)
#if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH)
/* Multiply a by b mod m and store in r: r = (a * b) mod m
*
* @param [in] a SP integer to multiply.
@ -7758,10 +7785,11 @@ int sp_mulmod(sp_int* a, sp_int* b, sp_int* m, sp_int* r)
#endif
return err;
}
#endif /* !WOLFSSL_RSA_VERIFY_ONLY */
#endif
#if defined(HAVE_ECC) || !defined(NO_DSA) || defined(OPENSSL_EXTRA) || \
(!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
(!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY) && \
!defined(WOLFSSL_RSA_PUBLIC_ONLY))
/* Calculates the multiplicative inverse in the field.
*
* @param [in] a SP integer to find inverse of.
@ -8049,7 +8077,8 @@ int sp_invmod_mont_ct(sp_int* a, sp_int* m, sp_int* r, sp_int_digit mp)
* Exponentiation functions
**************************/
#if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH)
#if (defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY) && \
!defined(WOLFSSL_RSA_PUBLIC_ONLY)) || defined(WOLFSSL_HAVE_SP_DH)
/* Internal. Exponentiates b to the power of e modulo m into r: r = b ^ e mod m
* Process the exponent one bit at a time.
* Is constant time and can be cache attack resistant.
@ -8165,9 +8194,11 @@ static int _sp_exptmod_ex(sp_int* b, sp_int* e, int bits, sp_int* m, sp_int* r)
#endif
return err;
}
#endif /* WOLFSSL_SP_MATH_ALL || WOLFSSL_HAVE_SP_DH */
#endif /* (WOLFSSL_SP_MATH_ALL && !WOLFSSL_RSA_VERIFY_ONLY) ||
* WOLFSSL_HAVE_SP_DH */
#ifdef WOLFSSL_SP_MATH_ALL
#if defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY) && \
!defined(WOLFSSL_RSA_PUBLIC_ONLY)
#ifndef WC_NO_HARDEN
#if !defined(WC_NO_CACHE_RESISTANT)
/* Internal. Exponentiates b to the power of e modulo m into r: r = b ^ e mod m
@ -8643,9 +8674,10 @@ static int _sp_exptmod_base_2(sp_int* e, int digits, sp_int* m, sp_int* r)
return err;
}
#endif /* WOLFSSL_SP_MATH_ALL */
#endif /* WOLFSSL_SP_MATH_ALL && !WOLFSSL_RSA_VERIFY_ONLY */
#if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH)
#if (defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
defined(WOLFSSL_HAVE_SP_DH)
/* Exponentiates b to the power of e modulo m into r: r = b ^ e mod m
*
* @param [in] b SP integer that is the base.
@ -8748,7 +8780,8 @@ int sp_exptmod_ex(sp_int* b, sp_int* e, int digits, sp_int* m, sp_int* r)
}
}
#if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH)
#if defined(WOLFSSL_SP_MATH_ALL)
#if defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY) && \
!defined(WOLFSSL_RSA_PUBLIC_ONLY)
if ((!done) && (err == MP_OKAY) && (b->used == 1) && (b->dp[0] == 2)) {
/* Use the generic base 2 implementation. */
err = _sp_exptmod_base_2(e, digits, m, r);
@ -8761,11 +8794,16 @@ int sp_exptmod_ex(sp_int* b, sp_int* e, int digits, sp_int* m, sp_int* r)
#endif
}
else
#elif defined(WOLFSSL_RSA_VERIFY_ONLY) || defined(WOLFSSL_RSA_PUBLIC_ONLY)
err = sp_exptmod_nct(b, e, m, r);
#endif
#if (defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY) && \
!defined(WOLFSSL_RSA_PUBLIC_ONLY)) || defined(WOLFSSL_HAVE_SP_DH)
if ((!done) && (err == MP_OKAY)) {
/* Otherwise use the generic implementation. */
err = _sp_exptmod_ex(b, e, digits * SP_WORD_SIZE, m, r);
}
#endif
#else
if ((!done) && (err == MP_OKAY)) {
err = MP_VAL;
@ -8784,7 +8822,8 @@ int sp_exptmod_ex(sp_int* b, sp_int* e, int digits, sp_int* m, sp_int* r)
}
#endif /* WOLFSSL_SP_MATH_ALL || WOLFSSL_HAVE_SP_DH */
#if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH)
#if (defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
defined(WOLFSSL_HAVE_SP_DH)
/* Exponentiates b to the power of e modulo m into r: r = b ^ e mod m
*
* @param [in] b SP integer that is the base.
@ -8808,9 +8847,10 @@ int sp_exptmod(sp_int* b, sp_int* e, sp_int* m, sp_int* r)
}
return err;
}
#endif /* WOLFSSL_SP_MATH_ALL || WOLFSSL_HAVE_SP_DH */
#endif /* (WOLFSSL_SP_MATH_ALL && !WOLFSSL_RSA_VERIFY_ONLY) ||
* WOLFSSL_HAVE_SP_DH */
#ifdef WOLFSSL_SP_MATH_ALL
#if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH)
#ifndef WOLFSSL_SP_SMALL
/* Internal. Exponentiates b to the power of e modulo m into r: r = b ^ e mod m
* Creates a window of precalculated exponents with base in montgomery form.
@ -9225,13 +9265,13 @@ int sp_exptmod_nct(sp_int* b, sp_int* e, sp_int* m, sp_int* r)
return err;
}
#endif /* WOLFSSL_SP_MATH_ALL */
#endif /* WOLFSSL_SP_MATH_ALL || WOLFSSL_HAVE_SP_DH */
/***************
* 2^e functions
***************/
#ifdef WOLFSSL_SP_MATH_ALL
#if defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
/* Divide by 2^e: r = a >> e and rem = bits shifted out
*
* @param [in] a SP integer to divide.
@ -9280,9 +9320,9 @@ int sp_div_2d(sp_int* a, int e, sp_int* r, sp_int* rem)
return err;
}
#endif /* WOLFSSL_SP_MATH_ALL */
#endif /* WOLFSSL_SP_MATH_ALL && !WOLFSSL_RSA_VERIFY_ONLY */
#ifdef WOLFSSL_SP_MATH_ALL
#if defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
/* The bottom e bits: r = a & ((1 << e) - 1)
*
* @param [in] a SP integer to reduce.
@ -9319,9 +9359,9 @@ int sp_mod_2d(sp_int* a, int e, sp_int* r)
return err;
}
#endif /* WOLFSSL_SP_MATH_ALL */
#endif /* WOLFSSL_SP_MATH_ALL && !WOLFSSL_RSA_VERIFY_ONLY */
#ifdef WOLFSSL_SP_MATH_ALL
#if defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
/* Multiply by 2^e: r = a << e
*
* @param [in] a SP integer to multiply.
@ -9364,7 +9404,7 @@ int sp_mul_2d(sp_int* a, int e, sp_int* r)
return err;
}
#endif /* WOLFSSL_SP_MATH_ALL */
#endif /* WOLFSSL_SP_MATH_ALL && !WOLFSSL_RSA_VERIFY_ONLY */
#if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \
defined(HAVE_ECC) || (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
@ -11915,7 +11955,7 @@ int sp_sqr(sp_int* a, sp_int* r)
#endif /* WOLFSSL_SP_MATH_ALL || WOLFSSL_HAVE_SP_DH || HAVE_ECC ||
* (!NO_RSA && !WOLFSSL_RSA_VERIFY_ONLY) */
#if !defined(WOLFSSL_RSA_VERIFY_ONLY)
#if !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)
/* Square a mod m and store in r: r = (a * a) mod m
*
* @param [in] a SP integer to square.
@ -11954,7 +11994,7 @@ int sp_sqrmod(sp_int* a, sp_int* m, sp_int* r)
* Montogmery functions
**********************/
#if defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
#if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH)
/* Reduce a number in montgomery form.
*
* Assumes a and m are not NULL and m is not 0.
@ -12001,7 +12041,6 @@ static int _sp_mont_red(sp_int* a, sp_int* m, sp_int_digit mp)
else {
sp_int_digit mask = (1UL << (bits & (SP_WORD_SIZE - 1))) - 1;
sp_int_word o = 0;
w = 0;
for (i = 0; i < m->used; i++) {
int j;
@ -12235,9 +12274,8 @@ static int _sp_mont_red(sp_int* a, sp_int* m, sp_int_digit mp)
return MP_OKAY;
#endif /* !SQR_MUL_ASM */
}
#endif /* WOLFSSL_SP_MATH_ALL && !WOLFSSL_RSA_VERIFY_ONLY */
#if defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
#ifndef WOLFSSL_RSA_VERIFY_ONLY
/* Reduce a number in montgomery form.
*
* @param [in,out] a SP integer to Montgomery reduce.
@ -12260,9 +12298,8 @@ int sp_mont_red(sp_int* a, sp_int* m, sp_int_digit mp)
return err;
}
#endif /* WOLFSSL_SP_MATH_ALL || !WOLFSSL_RSA_VERIFY_ONLY */
#endif
#if defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
/* Calculate the bottom digit of the inverse of negative m.
*
* Used when performing Montgomery Reduction.
@ -12307,9 +12344,7 @@ int sp_mont_setup(sp_int* m, sp_int_digit* rho)
return err;
}
#endif /* WOLFSSL_SP_MATH_ALL || !WOLFSSL_RSA_VERIFY_ONLY */
#if defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
/* Calculate the normalization value of m.
* norm = 2^k - m, where k is the number of bits in m
*
@ -12351,7 +12386,7 @@ int sp_mont_norm(sp_int* norm, sp_int* m)
return err;
}
#endif /* WOLFSSL_SP_MATH_ALL || !WOLFSSL_RSA_VERIFY_ONLY */
#endif
/*********************************
* To and from binary and strings.
@ -12485,7 +12520,6 @@ int sp_to_unsigned_bin(sp_int* a, byte* out)
}
#endif /* (!NO_DH || HAVE_ECC || WC_RSA_BLINDING) && !WOLFSSL_RSA_VERIFY_ONLY */
#if !defined(WOLFSSL_RSA_VERIFY_ONLY)
/* Convert the multi-precision number to an array of bytes in big-endian format.
*
* The array must be large enough for encoded number - use mp_unsigned_bin_size
@ -12528,9 +12562,8 @@ int sp_to_unsigned_bin_len(sp_int* a, byte* out, int outSz)
return err;
}
#endif /* !WOLFSSL_RSA_VERIFY_ONLY */
#ifdef WOLFSSL_SP_MATH_ALL
#if defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
/* Store the number in big-endian format in array at an offset.
* The array must be large enough for encoded number - use mp_unsigned_bin_size
* to calculate the number of bytes required.
@ -12554,7 +12587,8 @@ int sp_to_unsigned_bin_at_pos(int o, sp_int*a, unsigned char* out)
}
#endif /* WOLFSSL_SP_MATH_ALL */
#if defined(WOLFSSL_SP_MATH_ALL) || defined(HAVE_ECC)
#if (defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
defined(HAVE_ECC)
/* Convert hexadecimal number as string in big-endian format to a
* multi-precision number.
*
@ -12623,9 +12657,9 @@ static int _sp_read_radix_16(sp_int* a, const char* in)
return err;
}
#endif /* WOLFSSL_SP_MATH_ALL || HAVE_ECC */
#endif /* (WOLFSSL_SP_MATH_ALL && !WOLFSSL_RSA_VERIFY_ONLY) || HAVE_ECC */
#ifdef WOLFSSL_SP_MATH_ALL
#if defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
/* Convert decimal number as string in big-endian format to a multi-precision
* number.
*
@ -12678,9 +12712,10 @@ static int _sp_read_radix_10(sp_int* a, const char* in)
return err;
}
#endif /* WOLFSSL_SP_MATH_ALL */
#endif /* WOLFSSL_SP_MATH_ALL && !WOLFSSL_RSA_VERIFY_ONLY */
#if defined(WOLFSSL_SP_MATH_ALL) || defined(HAVE_ECC)
#if (defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
defined(HAVE_ECC)
/* Convert a number as string in big-endian format to a big number.
* Only supports base-16 (hexadecimal) and base-10 (decimal).
*
@ -12712,7 +12747,7 @@ int sp_read_radix(sp_int* a, const char* in, int radix)
if (radix == 16) {
err = _sp_read_radix_16(a, in);
}
#ifdef WOLFSSL_SP_MATH_ALL
#if defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
else if (radix == 10) {
err = _sp_read_radix_10(a, in);
}
@ -12724,9 +12759,10 @@ int sp_read_radix(sp_int* a, const char* in, int radix)
return err;
}
#endif /* WOLFSSL_SP_MATH_ALL || HAVE_ECC */
#endif /* (WOLFSSL_SP_MATH_ALL && !WOLFSSL_RSA_VERIFY_ONLY) || HAVE_ECC */
#if defined(WOLFSSL_SP_MATH_ALL) || defined(WC_MP_TO_RADIX)
#if (defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
defined(WC_MP_TO_RADIX)
/* Hex string characters. */
static const char sp_hex_char[16] = {
'0', '1', '2', '3', '4', '5', '6', '7',
@ -12807,10 +12843,10 @@ int sp_tohex(sp_int* a, char* str)
return err;
}
#endif /* WOLFSSL_SP_MATH_ALL || WC_MP_TO_RADIX */
#endif /* (WOLFSSL_SP_MATH_ALL && !WOLFSSL_RSA_VERIFY_ONLY) || WC_MP_TO_RADIX */
#if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_KEY_GEN) || \
defined(HAVE_COMP_KEY)
#if (defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY)
/* Put the big-endian, decimal string encoding of a into str.
*
* Assumes str is large enough for result.
@ -12887,7 +12923,7 @@ int sp_todecimal(sp_int* a, char* str)
}
#endif /* WOLFSSL_SP_MATH_ALL || WOLFSSL_KEY_GEN || HAVE_COMP_KEY */
#ifdef WOLFSSL_SP_MATH_ALL
#if defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
/* Put the string version, big-endian, of a in str using the given radix.
*
* @param [in] a SP integer to convert.
@ -12922,7 +12958,7 @@ int sp_toradix(sp_int* a, char* str, int radix)
}
#endif /* WOLFSSL_SP_MATH_ALL */
#ifdef WOLFSSL_SP_MATH_ALL
#if defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
/* Calculate the length of the string version, big-endian, of a using the given
* radix.
*
@ -13023,7 +13059,7 @@ int sp_radix_size(sp_int* a, int radix, int* size)
return err;
}
#endif /* WOLFSSL_SP_MATH_ALL */
#endif /* WOLFSSL_SP_MATH_ALL && !WOLFSSL_RSA_VERIFY_ONLY */
/***************************************
* Prime number generation and checking.
@ -13137,7 +13173,8 @@ int sp_rand_prime(sp_int* r, int len, WC_RNG* rng, void* heap)
}
#endif /* WOLFSSL_KEY_GEN && (!NO_DH || !NO_DSA) && !WC_NO_RNG */
#if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH)
#if (defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY) && \
!defined(WOLFSSL_RSA_PUBLIC_ONLY)) || defined(WOLFSSL_HAVE_SP_DH)
/* Miller-Rabin test of "a" to the base of "b" as described in
* HAC pp. 139 Algorithm 4.24
*
@ -13579,8 +13616,8 @@ int sp_prime_is_prime_ex(sp_int* a, int t, int* result, WC_RNG* rng)
}
#endif /* WOLFSSL_SP_MATH_ALL || WOLFSSL_HAVE_SP_DH */
#if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \
(defined(HAVE_ECC) && defined(FP_ECC))
#if (defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
defined(WOLFSSL_HAVE_SP_DH) || (defined(HAVE_ECC) && defined(FP_ECC))
/* Calculates the Greatest Common Denominator (GCD) of a and b into r.
*
@ -13701,7 +13738,8 @@ int sp_gcd(sp_int* a, sp_int* b, sp_int* r)
return err;
}
#endif /* WOLFSSL_SP_MATH_ALL || WOLFSSL_HAVE_SP_DH || (HAVE_ECC && FP_ECC) */
#endif /* (WOLFSSL_SP_MATH_ALL && !WOLFSSL_SP_RSA_VERIFY_ONLY) ||
* WOLFSSL_HAVE_SP_DH || (HAVE_ECC && FP_ECC) */
#if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)

View File

@ -87,6 +87,7 @@ mp_digit get_digit(mp_int* a, int n)
return (n >= a->used || n < 0) ? 0 : a->dp[n];
}
#if defined(HAVE_ECC) || defined(WOLFSSL_MP_COND_COPY)
/* Conditionally copy a into b. Performed in constant time.
*
* a MP integer to copy.
@ -125,6 +126,7 @@ int mp_cond_copy(mp_int* a, int copy, mp_int* b)
return err;
}
#endif
#ifndef WC_NO_RNG
int get_rand_digit(WC_RNG* rng, mp_digit* d)
@ -191,6 +193,7 @@ int mp_rand(mp_int* a, int digits, WC_RNG* rng)
#endif /* WC_RSA_BLINDING */
#endif
#if defined(HAVE_ECC) || defined(WOLFSSL_EXPORT_INT)
/* export an mp_int as unsigned char or hex string
* encType is WC_TYPE_UNSIGNED_BIN or WC_TYPE_HEX_STR
* return MP_OKAY on success */
@ -224,6 +227,7 @@ int wc_export_int(mp_int* mp, byte* buf, word32* len, word32 keySz,
return err;
}
#endif
#ifdef HAVE_WOLF_BIGINT

View File

@ -12451,7 +12451,8 @@ WOLFSSL_TEST_SUBROUTINE int decodedCertCache_test(void)
#define RSA_TEST_BYTES 512 /* up to 4096-bit key */
#if !defined(NO_ASN) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)
#if !defined(NO_ASN) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
!defined(WOLFSSL_RSA_VERIFY_ONLY)
static int rsa_flatten_test(RsaKey* key)
{
int ret;
@ -13805,7 +13806,7 @@ static int rsa_even_mod_test(WC_RNG* rng, RsaKey* key)
}
/* after loading in key use tmp as the test buffer */
#ifndef WOLFSSL_RSA_VERIFY_ONLY
#if !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)
inLen = 32;
outSz = wc_RsaEncryptSize(key);
XMEMSET(tmp, 7, plainSz);
@ -13828,7 +13829,7 @@ static int rsa_even_mod_test(WC_RNG* rng, RsaKey* key)
#endif
/* test encrypt and decrypt using WC_RSA_NO_PAD */
#ifndef WOLFSSL_RSA_VERIFY_ONLY
#if !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)
ret = wc_RsaPublicEncrypt(tmp, inLen, out, (int)outSz, key, rng);
if (ret != MP_VAL && ret != MP_EXPTMOD_E) {
ERROR_OUT(-7812, exit_rsa_even_mod);
@ -14549,7 +14550,8 @@ WOLFSSL_TEST_SUBROUTINE int rsa_test(void)
const word32 outSz = RSA_TEST_BYTES;
const word32 plainSz = RSA_TEST_BYTES;
#endif
#if !defined(WOLFSSL_RSA_PUBLIC_ONLY) || defined(WOLFSSL_PUBLIC_MP)
#if (!defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
!defined(WOLFSSL_RSA_VERIFY_ONLY)) || defined(WOLFSSL_PUBLIC_MP)
byte* res;
#endif
#ifndef NO_SIG_WRAPPER
@ -14580,7 +14582,9 @@ WOLFSSL_TEST_SUBROUTINE int rsa_test(void)
if (in == NULL || out == NULL || plain == NULL)
ERROR_OUT(MEMORY_E, exit_rsa);
#endif
#ifndef WOLFSSL_RSA_VERIFY_ONLY
XMEMCPY(in, inStr, inLen);
#endif
#ifdef WOLFSSL_SMALL_STACK
if (key == NULL)
@ -14834,7 +14838,8 @@ WOLFSSL_TEST_SUBROUTINE int rsa_test(void)
}
#endif
#if !defined(WOLFSSL_RSA_PUBLIC_ONLY) || defined(WOLFSSL_PUBLIC_MP)
#if (!defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
!defined(WOLFSSL_RSA_VERIFY_ONLY)) || defined(WOLFSSL_PUBLIC_MP)
idx = (word32)ret;
XMEMSET(plain, 0, plainSz);
do {
@ -15195,7 +15200,8 @@ WOLFSSL_TEST_SUBROUTINE int rsa_test(void)
return ret;
#endif
#if !defined(NO_ASN) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)
#if !defined(NO_ASN) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
!defined(WOLFSSL_RSA_VERIFY_ONLY)
ret = rsa_flatten_test(key);
if (ret != 0)
return ret;

View File

@ -776,7 +776,7 @@ MP_API int sp_invmod_mont_ct(sp_int* a, sp_int* m, sp_int* r, sp_int_digit mp);
MP_API int sp_exptmod_ex(sp_int* b, sp_int* e, int digits, sp_int* m,
sp_int* r);
MP_API int sp_exptmod(sp_int* b, sp_int* e, sp_int* m, sp_int* r);
#ifdef WOLFSSL_SP_MATH_ALL
#if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH)
MP_API int sp_exptmod_nct(sp_int* b, sp_int* e, sp_int* m, sp_int* r);
#endif
@ -789,11 +789,9 @@ MP_API int sp_mul_2d(sp_int* a, int e, sp_int* r);
MP_API int sp_sqr(sp_int* a, sp_int* r);
MP_API int sp_sqrmod(sp_int* a, sp_int* m, sp_int* r);
#if defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
MP_API int sp_mont_red(sp_int* a, sp_int* m, sp_int_digit mp);
MP_API int sp_mont_setup(sp_int* m, sp_int_digit* rho);
MP_API int sp_mont_norm(sp_int* norm, sp_int* m);
#endif
MP_API int sp_unsigned_bin_size(sp_int* a);
MP_API int sp_read_unsigned_bin(sp_int* a, const byte* in, word32 inSz);