Merge pull request #5561 from SparkiDev/sp_math_openssl_fix

SP math: fix build configuration with opensslall
This commit is contained in:
David Garske
2022-09-07 07:12:13 -07:00
committed by GitHub
2 changed files with 24 additions and 20 deletions

View File

@ -4339,7 +4339,8 @@ WOLFSSL_LOCAL int sp_ModExp_4096(sp_int* base, sp_int* exp, sp_int* mod,
#endif /* WOLFSSL_HAVE_SP_DH || WOLFSSL_HAVE_SP_RSA */ #endif /* WOLFSSL_HAVE_SP_DH || WOLFSSL_HAVE_SP_RSA */
#if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \
defined(OPENSSL_ALL)
static int _sp_mont_red(sp_int* a, sp_int* m, sp_int_digit mp); static int _sp_mont_red(sp_int* a, sp_int* m, sp_int_digit mp);
#endif #endif
@ -10427,7 +10428,7 @@ int sp_mul(sp_int* a, sp_int* b, sp_int* r)
#if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \ #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \
defined(WOLFCRYPT_HAVE_ECCSI) || \ defined(WOLFCRYPT_HAVE_ECCSI) || \
(!defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)) (!defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)) || defined(OPENSSL_ALL)
/* Multiply a by b mod m and store in r: r = (a * b) mod m /* Multiply a by b mod m and store in r: r = (a * b) mod m
* *
* @param [in] a SP integer to multiply. * @param [in] a SP integer to multiply.
@ -10748,7 +10749,8 @@ int sp_invmod_mont_ct(sp_int* a, sp_int* m, sp_int* r, sp_int_digit mp)
**************************/ **************************/
#if (defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY) && \ #if (defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY) && \
!defined(WOLFSSL_RSA_PUBLIC_ONLY)) || !defined(NO_DH) !defined(WOLFSSL_RSA_PUBLIC_ONLY)) || !defined(NO_DH) || \
defined(OPENSSL_ALL)
/* Internal. Exponentiates b to the power of e modulo m into r: r = b ^ e mod m /* 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. * Process the exponent one bit at a time.
* Is constant time and can be cache attack resistant. * Is constant time and can be cache attack resistant.
@ -10849,11 +10851,11 @@ static int _sp_exptmod_ex(sp_int* b, sp_int* e, int bits, sp_int* m, sp_int* r)
FREE_SP_INT_ARRAY(t, NULL); FREE_SP_INT_ARRAY(t, NULL);
return err; return err;
} }
#endif /* (WOLFSSL_SP_MATH_ALL && !WOLFSSL_RSA_VERIFY_ONLY) || #endif
* WOLFSSL_HAVE_SP_DH */
#if defined(WOLFSSL_SP_MATH_ALL) && ((!defined(WOLFSSL_RSA_VERIFY_ONLY) && \ #if (defined(WOLFSSL_SP_MATH_ALL) && ((!defined(WOLFSSL_RSA_VERIFY_ONLY) && \
!defined(WOLFSSL_RSA_PUBLIC_ONLY)) || !defined(NO_DH)) !defined(WOLFSSL_RSA_PUBLIC_ONLY)) || !defined(NO_DH))) || \
defined(OPENSSL_ALL)
#ifndef WC_NO_HARDEN #ifndef WC_NO_HARDEN
#if !defined(WC_NO_CACHE_RESISTANT) #if !defined(WC_NO_CACHE_RESISTANT)
/* Internal. Exponentiates b to the power of e modulo m into r: r = b ^ e mod m /* Internal. Exponentiates b to the power of e modulo m into r: r = b ^ e mod m
@ -11303,10 +11305,11 @@ static int _sp_exptmod_base_2(sp_int* e, int digits, sp_int* m, sp_int* r)
FREE_SP_INT_ARRAY(d, NULL); FREE_SP_INT_ARRAY(d, NULL);
return err; return err;
} }
#endif /* WOLFSSL_SP_MATH_ALL && !WOLFSSL_RSA_VERIFY_ONLY */ #endif
#if (defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \ #if (defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
!defined(NO_DH) || (!defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)) !defined(NO_DH) || (!defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)) || \
defined(OPENSSL_ALL)
/* Exponentiates b to the power of e modulo m into r: r = b ^ e mod m /* 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. * @param [in] b SP integer that is the base.
@ -11426,14 +11429,14 @@ 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(NO_DH) #if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_DH) || defined(OPENSSL_ALL)
#if (defined(WOLFSSL_RSA_VERIFY_ONLY) || defined(WOLFSSL_RSA_PUBLIC_ONLY)) && \ #if (defined(WOLFSSL_RSA_VERIFY_ONLY) || defined(WOLFSSL_RSA_PUBLIC_ONLY)) && \
defined(NO_DH) defined(NO_DH)
if ((!done) && (err == MP_OKAY)) if ((!done) && (err == MP_OKAY))
err = sp_exptmod_nct(b, e, m, r); err = sp_exptmod_nct(b, e, m, r);
} }
#else #else
#if defined(WOLFSSL_SP_MATH_ALL) #if defined(WOLFSSL_SP_MATH_ALL) || defined(OPENSSL_ALL)
if ((!done) && (err == MP_OKAY) && (b->used == 1) && (b->dp[0] == 2) && if ((!done) && (err == MP_OKAY) && (b->used == 1) && (b->dp[0] == 2) &&
mp_isodd(m)) { mp_isodd(m)) {
/* Use the generic base 2 implementation. */ /* Use the generic base 2 implementation. */
@ -11447,7 +11450,7 @@ int sp_exptmod_ex(sp_int* b, sp_int* e, int digits, sp_int* m, sp_int* r)
#endif #endif
} }
else else
#endif /* WOLFSSL_SP_MATH_ALL */ #endif /* WOLFSSL_SP_MATH_ALL || OPENSSL_ALL */
if ((!done) && (err == MP_OKAY)) { if ((!done) && (err == MP_OKAY)) {
/* Otherwise use the generic implementation. */ /* Otherwise use the generic implementation. */
err = _sp_exptmod_ex(b, e, digits * SP_WORD_SIZE, m, r); err = _sp_exptmod_ex(b, e, digits * SP_WORD_SIZE, m, r);
@ -11471,10 +11474,11 @@ int sp_exptmod_ex(sp_int* b, sp_int* e, int digits, sp_int* m, sp_int* r)
#endif #endif
return err; return err;
} }
#endif /* WOLFSSL_SP_MATH_ALL || WOLFSSL_HAVE_SP_DH */ #endif
#if (defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \ #if (defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
!defined(NO_DH) || (!defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)) !defined(NO_DH) || (!defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)) || \
defined(OPENSSL_ALL)
/* Exponentiates b to the power of e modulo m into r: r = b ^ e mod m /* 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. * @param [in] b SP integer that is the base.
@ -11500,8 +11504,7 @@ int sp_exptmod(sp_int* b, sp_int* e, sp_int* m, sp_int* r)
RESTORE_VECTOR_REGISTERS(); RESTORE_VECTOR_REGISTERS();
return err; return err;
} }
#endif /* (WOLFSSL_SP_MATH_ALL && !WOLFSSL_RSA_VERIFY_ONLY) || #endif
* WOLFSSL_HAVE_SP_DH */
#if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH)
#if defined(WOLFSSL_SP_FAST_NCT_EXPTMOD) || !defined(WOLFSSL_SP_SMALL) #if defined(WOLFSSL_SP_FAST_NCT_EXPTMOD) || !defined(WOLFSSL_SP_SMALL)
@ -12035,8 +12038,8 @@ int sp_mod_2d(sp_int* a, int e, sp_int* r)
} }
#endif /* WOLFSSL_SP_MATH_ALL && !WOLFSSL_RSA_VERIFY_ONLY */ #endif /* WOLFSSL_SP_MATH_ALL && !WOLFSSL_RSA_VERIFY_ONLY */
#if defined(WOLFSSL_SP_MATH_ALL) && (!defined(WOLFSSL_RSA_VERIFY_ONLY) || \ #if (defined(WOLFSSL_SP_MATH_ALL) && (!defined(WOLFSSL_RSA_VERIFY_ONLY) || \
!defined(NO_DH)) !defined(NO_DH))) || defined(OPENSSL_ALL)
/* Multiply by 2^e: r = a << e /* Multiply by 2^e: r = a << e
* *
* @param [in] a SP integer to multiply. * @param [in] a SP integer to multiply.
@ -14548,7 +14551,8 @@ int sp_sqrmod(sp_int* a, sp_int* m, sp_int* r)
**********************/ **********************/
#if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \ #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \
defined(WOLFCRYPT_HAVE_ECCSI) || defined(WOLFCRYPT_HAVE_SAKKE) defined(WOLFCRYPT_HAVE_ECCSI) || defined(WOLFCRYPT_HAVE_SAKKE) || \
defined(OPENSSL_ALL)
/* Reduce a number in montgomery form. /* Reduce a number in montgomery form.
* *
* Assumes a and m are not NULL and m is not 0. * Assumes a and m are not NULL and m is not 0.

View File

@ -884,7 +884,7 @@ MP_API int sp_exptmod(sp_int* b, sp_int* e, sp_int* m, sp_int* r);
MP_API int sp_exptmod_nct(sp_int* b, sp_int* e, sp_int* m, sp_int* r); MP_API int sp_exptmod_nct(sp_int* b, sp_int* e, sp_int* m, sp_int* r);
#endif #endif
#ifdef WOLFSSL_SP_MATH_ALL #if defined(WOLFSSL_SP_MATH_ALL) || defined(OPENSSL_ALL)
MP_API int sp_div_2d(sp_int* a, int e, sp_int* r, sp_int* rem); MP_API int sp_div_2d(sp_int* a, int e, sp_int* r, sp_int* rem);
MP_API int sp_mod_2d(sp_int* a, int e, sp_int* r); MP_API int sp_mod_2d(sp_int* a, int e, sp_int* r);
MP_API int sp_mul_2d(sp_int* a, int e, sp_int* r); MP_API int sp_mul_2d(sp_int* a, int e, sp_int* r);