mbedtls: Re-apply MBEDTLS_BIGNUM_ALT & related macros for custom bignum functions

(IDF-specific patch.)

(cherry picked from commit 1981b54621)
This commit is contained in:
Angus Gratton
2017-09-06 15:06:57 +10:00
committed by Mahavir Jain
parent aeb97a1891
commit 5107328ffb
2 changed files with 16 additions and 0 deletions
+5
View File
@@ -114,6 +114,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.
*
@@ -1086,6 +1088,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)
+11
View File
@@ -48,6 +48,7 @@
#include "mbedtls/platform.h"
#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) \
@@ -1397,6 +1398,8 @@ 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) || !defined(MBEDTLS_MPI_EXP_MOD_ALT)
/** Helper for mbedtls_mpi multiplication.
*
* Add \p b * \p s to \p d.
@@ -1478,6 +1481,9 @@ void mpi_mul_hlp(size_t i,
}
}
#endif
#if !defined(MBEDTLS_MPI_MUL_MPI_ALT)
/*
* Baseline multiplication: X = A * B (HAC 14.12)
*/
@@ -1579,6 +1585,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
@@ -1916,6 +1923,8 @@ int mbedtls_mpi_mod_int(mbedtls_mpi_uint *r, const mbedtls_mpi *A, mbedtls_mpi_s
return 0;
}
#if !defined(MBEDTLS_MPI_EXP_MOD_ALT)
/*
* Fast Montgomery initialization (thanks to Tom St Denis)
*/
@@ -2350,6 +2359,7 @@ cleanup:
return ret;
}
#endif
/*
* Greatest common divisor: G = gcd(A, B) (HAC 14.54)
@@ -3022,6 +3032,7 @@ cleanup:
}
#endif /* MBEDTLS_GENPRIME */
#endif /* MBEDTLS_BIGNUM_ALT */
#if defined(MBEDTLS_SELF_TEST)