Skip to content

Commit

Permalink
mbedtls: Re-apply MBEDTLS_BIGNUM_ALT & related macros for custom bign…
Browse files Browse the repository at this point in the history
…um functions

(IDF-specific patch.)
  • Loading branch information
projectgus authored and igrr committed Sep 18, 2018
1 parent 53546ea commit 19eb57f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions include/mbedtls/bignum.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,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.
*
Expand Down Expand Up @@ -757,6 +759,9 @@ int mbedtls_mpi_is_prime( const mbedtls_mpi *X,
int mbedtls_mpi_gen_prime( mbedtls_mpi *X, size_t nbits, int dh_flag,
int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng );
#else /* MBEDTLS_BIGNUM_ALT */
#include "bignum_alt.h"
#endif /* MBEDTLS_BIGNUM_ALT */

/**
* \brief Checkup routine
Expand Down
13 changes: 13 additions & 0 deletions library/bignum.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
#define mbedtls_free free
#endif

#if !defined(MBEDTLS_BIGNUM_ALT)

#define ciL (sizeof(mbedtls_mpi_uint)) /* chars in limb */
#define biL (ciL << 3) /* bits in limb */
#define biH (ciL << 2) /* half limb size */
Expand Down Expand Up @@ -1107,6 +1109,8 @@ int mbedtls_mpi_sub_int( mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_sint
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
*/
Expand All @@ -1118,6 +1122,7 @@ static
*/
__attribute__ ((noinline))
#endif

void mpi_mul_hlp( size_t i, mbedtls_mpi_uint *s, mbedtls_mpi_uint *d, mbedtls_mpi_uint b )
{
mbedtls_mpi_uint c = 0, t = 0;
Expand Down Expand Up @@ -1179,6 +1184,9 @@ void mpi_mul_hlp( size_t i, mbedtls_mpi_uint *s, mbedtls_mpi_uint *d, mbedtls_mp
while( c != 0 );
}

#endif

#if !defined(MBEDTLS_MPI_MUL_MPI_ALT)
/*
* Baseline multiplication: X = A * B (HAC 14.12)
*/
Expand Down Expand Up @@ -1215,6 +1223,7 @@ int mbedtls_mpi_mul_mpi( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi

return( ret );
}
#endif

/*
* Baseline multiplication: X = A * b
Expand Down Expand Up @@ -1539,6 +1548,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)
*/
Expand Down Expand Up @@ -1820,6 +1831,7 @@ int mbedtls_mpi_exp_mod( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi

return( ret );
}
#endif

/*
* Greatest common divisor: G = gcd(A, B) (HAC 14.54)
Expand Down Expand Up @@ -2290,6 +2302,7 @@ int mbedtls_mpi_gen_prime( mbedtls_mpi *X, size_t nbits, int dh_flag,
}

#endif /* MBEDTLS_GENPRIME */
#endif /* MBEDTLS_BIGNUM_ALT */

#if defined(MBEDTLS_SELF_TEST)

Expand Down

0 comments on commit 19eb57f

Please sign in to comment.