From df0d3fc61e2f88ef4ea04c72e8e336de83cd98d8 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Wed, 6 Sep 2017 15:06:57 +1000 Subject: [PATCH] mbedtls: Re-apply MBEDTLS_BIGNUM_ALT & related macros for custom bignum functions (IDF-specific patch.) --- include/mbedtls/bignum.h | 5 +++++ library/bignum.c | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/include/mbedtls/bignum.h b/include/mbedtls/bignum.h index 5277f56d9..69f4f7ffa 100644 --- a/include/mbedtls/bignum.h +++ b/include/mbedtls/bignum.h @@ -109,6 +109,8 @@ #define MBEDTLS_LN_2_DIV_LN_10_SCALE100 332 #define MBEDTLS_MPI_RW_BUFFER_SIZE ( ((MBEDTLS_MPI_MAX_BITS_SCALE100 + 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. * @@ -1010,6 +1012,9 @@ typedef enum { int mbedtls_mpi_gen_prime( mbedtls_mpi *X, size_t nbits, int flags, int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ); +#else /* MBEDTLS_BIGNUM_ALT */ +#include "bignum_alt.h" +#endif /* MBEDTLS_BIGNUM_ALT */ #if defined(MBEDTLS_SELF_TEST) diff --git a/library/bignum.c b/library/bignum.c index 8717c8abc..673eb36cb 100644 --- a/library/bignum.c +++ b/library/bignum.c @@ -57,6 +57,8 @@ #define mbedtls_free free #endif +#if !defined(MBEDTLS_BIGNUM_ALT) + #define MPI_VALIDATE_RET( cond ) \ MBEDTLS_INTERNAL_VALIDATE_RET( cond, MBEDTLS_ERR_MPI_BAD_INPUT_DATA ) #define MPI_VALIDATE( cond ) \ @@ -1402,6 +1404,7 @@ mbedtls_mpi_uint mbedtls_mpi_core_mla( mbedtls_mpi_uint *d, size_t d_len, return( c ); } +#if !defined(MBEDTLS_MPI_MUL_MPI_ALT) /* * Baseline multiplication: X = A * B (HAC 14.12) */ @@ -1496,6 +1499,7 @@ int mbedtls_mpi_mul_int( mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_uint cleanup: return( ret ); } +#endif /* * Unsigned integer divide - double mbedtls_mpi_uint dividend, u1/u0, and @@ -1825,6 +1829,8 @@ int mbedtls_mpi_mod_int( mbedtls_mpi_uint *r, const mbedtls_mpi *A, mbedtls_mpi_ return( 0 ); } +#if !defined(MBEDTLS_MPI_EXP_MOD_ALT) + /* * Fast Montgomery initialization (thanks to Tom St Denis) */ @@ -2198,6 +2204,7 @@ cleanup: return( ret ); } +#endif /* * Greatest common divisor: G = gcd(A, B) (HAC 14.54) @@ -2856,6 +2863,7 @@ cleanup: } #endif /* MBEDTLS_GENPRIME */ +#endif /* MBEDTLS_BIGNUM_ALT */ #if defined(MBEDTLS_SELF_TEST)