mirror of
https://github.com/espressif/mbedtls.git
synced 2025-05-09 11:21:21 +08:00
mbedtls: Re-apply MBEDTLS_BIGNUM_ALT & related macros for custom bignum functions
(IDF-specific patch.)
This commit is contained in:
parent
89f040a5c9
commit
1981b54621
@ -112,6 +112,8 @@
|
|||||||
#define MBEDTLS_LN_2_DIV_LN_10_SCALE100 332
|
#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 )
|
#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.
|
* Define the base integer type, architecture-wise.
|
||||||
*
|
*
|
||||||
@ -1085,6 +1087,9 @@ typedef enum {
|
|||||||
int mbedtls_mpi_gen_prime( mbedtls_mpi *X, size_t nbits, int flags,
|
int mbedtls_mpi_gen_prime( mbedtls_mpi *X, size_t nbits, int flags,
|
||||||
int (*f_rng)(void *, unsigned char *, size_t),
|
int (*f_rng)(void *, unsigned char *, size_t),
|
||||||
void *p_rng );
|
void *p_rng );
|
||||||
|
#else /* MBEDTLS_BIGNUM_ALT */
|
||||||
|
#include "bignum_alt.h"
|
||||||
|
#endif /* MBEDTLS_BIGNUM_ALT */
|
||||||
|
|
||||||
#if defined(MBEDTLS_SELF_TEST)
|
#if defined(MBEDTLS_SELF_TEST)
|
||||||
|
|
||||||
|
@ -48,6 +48,8 @@
|
|||||||
|
|
||||||
#include "mbedtls/platform.h"
|
#include "mbedtls/platform.h"
|
||||||
|
|
||||||
|
#if !defined(MBEDTLS_BIGNUM_ALT)
|
||||||
|
|
||||||
#define MPI_VALIDATE_RET( cond ) \
|
#define MPI_VALIDATE_RET( cond ) \
|
||||||
MBEDTLS_INTERNAL_VALIDATE_RET( cond, MBEDTLS_ERR_MPI_BAD_INPUT_DATA )
|
MBEDTLS_INTERNAL_VALIDATE_RET( cond, MBEDTLS_ERR_MPI_BAD_INPUT_DATA )
|
||||||
#define MPI_VALIDATE( cond ) \
|
#define MPI_VALIDATE( cond ) \
|
||||||
@ -1359,6 +1361,8 @@ int mbedtls_mpi_sub_int( mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_sint
|
|||||||
return( mbedtls_mpi_sub_mpi( X, A, &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.
|
/** Helper for mbedtls_mpi multiplication.
|
||||||
*
|
*
|
||||||
* Add \p b * \p s to \p d.
|
* Add \p b * \p s to \p d.
|
||||||
@ -1383,6 +1387,7 @@ static
|
|||||||
*/
|
*/
|
||||||
__attribute__ ((noinline))
|
__attribute__ ((noinline))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void mpi_mul_hlp( size_t i,
|
void mpi_mul_hlp( size_t i,
|
||||||
const mbedtls_mpi_uint *s,
|
const mbedtls_mpi_uint *s,
|
||||||
mbedtls_mpi_uint *d,
|
mbedtls_mpi_uint *d,
|
||||||
@ -1447,6 +1452,9 @@ void mpi_mul_hlp( size_t i,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(MBEDTLS_MPI_MUL_MPI_ALT)
|
||||||
/*
|
/*
|
||||||
* Baseline multiplication: X = A * B (HAC 14.12)
|
* Baseline multiplication: X = A * B (HAC 14.12)
|
||||||
*/
|
*/
|
||||||
@ -1536,6 +1544,7 @@ int mbedtls_mpi_mul_int( mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_uint
|
|||||||
cleanup:
|
cleanup:
|
||||||
return( ret );
|
return( ret );
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Unsigned integer divide - double mbedtls_mpi_uint dividend, u1/u0, and
|
* Unsigned integer divide - double mbedtls_mpi_uint dividend, u1/u0, and
|
||||||
@ -1865,6 +1874,8 @@ int mbedtls_mpi_mod_int( mbedtls_mpi_uint *r, const mbedtls_mpi *A, mbedtls_mpi_
|
|||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !defined(MBEDTLS_MPI_EXP_MOD_ALT)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Fast Montgomery initialization (thanks to Tom St Denis)
|
* Fast Montgomery initialization (thanks to Tom St Denis)
|
||||||
*/
|
*/
|
||||||
@ -2299,6 +2310,7 @@ cleanup:
|
|||||||
|
|
||||||
return( ret );
|
return( ret );
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Greatest common divisor: G = gcd(A, B) (HAC 14.54)
|
* Greatest common divisor: G = gcd(A, B) (HAC 14.54)
|
||||||
@ -2977,6 +2989,7 @@ cleanup:
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif /* MBEDTLS_GENPRIME */
|
#endif /* MBEDTLS_GENPRIME */
|
||||||
|
#endif /* MBEDTLS_BIGNUM_ALT */
|
||||||
|
|
||||||
#if defined(MBEDTLS_SELF_TEST)
|
#if defined(MBEDTLS_SELF_TEST)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user