mirror of
https://github.com/espressif/mbedtls.git
synced 2026-06-05 21:14:47 +00:00
mbedtls: Re-apply MBEDTLS_BIGNUM_ALT & related macros for custom bignum functions
(IDF-specific patch.)
(cherry picked from commit f859b9bc75)
This commit is contained in:
committed by
Mahavir Jain
parent
0bebf8b8c7
commit
e8f1d22d65
@@ -100,6 +100,8 @@
|
||||
MBEDTLS_LN_2_DIV_LN_10_SCALE100 - 1) / \
|
||||
MBEDTLS_LN_2_DIV_LN_10_SCALE100) + 10 + 6)
|
||||
|
||||
#if !defined(MBEDTLS_BIGNUM_ALT)
|
||||
|
||||
/*
|
||||
* Define the base integer type, architecture-wise.
|
||||
*
|
||||
@@ -1069,6 +1071,9 @@ typedef enum {
|
||||
int mbedtls_mpi_gen_prime(mbedtls_mpi *X, size_t nbits, int flags,
|
||||
mbedtls_f_rng_t *f_rng,
|
||||
void *p_rng);
|
||||
#else /* MBEDTLS_BIGNUM_ALT */
|
||||
#include "bignum_alt.h"
|
||||
#endif /* MBEDTLS_BIGNUM_ALT */
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
|
||||
|
||||
+12
-2
@@ -38,7 +38,7 @@
|
||||
|
||||
#include "mbedtls/platform.h"
|
||||
|
||||
|
||||
#if !defined(MBEDTLS_BIGNUM_ALT)
|
||||
|
||||
/*
|
||||
* Conditionally select an MPI sign in constant time.
|
||||
@@ -1192,6 +1192,7 @@ int mbedtls_mpi_sub_int(mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_sint b
|
||||
return mbedtls_mpi_sub_mpi(X, A, &B);
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_MPI_MUL_MPI_ALT)
|
||||
/*
|
||||
* Baseline multiplication: X = A * B (HAC 14.12)
|
||||
*/
|
||||
@@ -1287,6 +1288,7 @@ int mbedtls_mpi_mul_int(mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_uint b
|
||||
cleanup:
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Unsigned integer divide - double mbedtls_mpi_uint dividend, u1/u0, and
|
||||
@@ -1733,13 +1735,19 @@ cleanup:
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
#if !defined(MBEDTLS_MPI_EXP_MOD_ALT)
|
||||
|
||||
/*
|
||||
* Sliding-window exponentiation: X = A^E mod N (HAC 14.85)
|
||||
*/
|
||||
int mbedtls_mpi_exp_mod(mbedtls_mpi *X, const mbedtls_mpi *A,
|
||||
const mbedtls_mpi *E, const mbedtls_mpi *N,
|
||||
mbedtls_mpi *prec_RR)
|
||||
{
|
||||
return mbedtls_mpi_exp_mod_optionally_safe(X, A, E, MBEDTLS_MPI_IS_SECRET, N, prec_RR);
|
||||
}
|
||||
#endif
|
||||
|
||||
int mbedtls_mpi_exp_mod_unsafe(mbedtls_mpi *X, const mbedtls_mpi *A,
|
||||
const mbedtls_mpi *E, const mbedtls_mpi *N,
|
||||
@@ -1747,6 +1755,7 @@ int mbedtls_mpi_exp_mod_unsafe(mbedtls_mpi *X, const mbedtls_mpi *A,
|
||||
{
|
||||
return mbedtls_mpi_exp_mod_optionally_safe(X, A, E, MBEDTLS_MPI_IS_PUBLIC, N, prec_RR);
|
||||
}
|
||||
|
||||
|
||||
/* Constant-time GCD and/or modinv with odd modulus and A <= N */
|
||||
int mbedtls_mpi_gcd_modinv_odd(mbedtls_mpi *G,
|
||||
@@ -2369,6 +2378,7 @@ cleanup:
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_GENPRIME */
|
||||
#endif /* MBEDTLS_BIGNUM_ALT */
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user