[M487] Support internal self-test for ECP alter.

pull/5812/head
ccli8 2018-02-06 11:15:48 +08:00
parent 95d4110e31
commit 25253529ae
1 changed files with 38 additions and 30 deletions

View File

@ -20,6 +20,14 @@
#include MBEDTLS_CONFIG_FILE
#endif
/* Some internal functions are used for Nuvoton internal self-test.
* Remove the static modifier for self-test compile. */
#if defined(NU_CRYPTO_SELF_TEST) && NU_CRYPTO_SELF_TEST
#define NU_STATIC
#else
#define NU_STATIC static
#endif
#if defined(MBEDTLS_ECP_C)
#include "mbedtls/ecp.h"
@ -139,7 +147,7 @@
* n is kept with unused modifier.
*
*/
int internal_run_eccop(const mbedtls_ecp_group *grp,
NU_STATIC int internal_run_eccop(const mbedtls_ecp_group *grp,
mbedtls_ecp_point *R,
const mbedtls_mpi *m,
const mbedtls_ecp_point *P,
@ -165,7 +173,7 @@ int internal_run_eccop(const mbedtls_ecp_group *grp,
*
* \note o1/o2 must be normalized (within [0, p - 1]). r would be normalized.
*/
int internal_run_modop(mbedtls_mpi *r,
NU_STATIC int internal_run_modop(mbedtls_mpi *r,
const mbedtls_mpi *o1,
const mbedtls_mpi *o2,
const mbedtls_mpi *p,
@ -183,7 +191,7 @@ int internal_run_modop(mbedtls_mpi *r,
*
* \note Destination MPI is always non-negative.
*/
static int internal_mpi_read_eccreg( mbedtls_mpi *X, const volatile uint32_t *eccreg, size_t eccreg_num );
NU_STATIC int internal_mpi_read_eccreg( mbedtls_mpi *X, const volatile uint32_t *eccreg, size_t eccreg_num );
/**
* \brief Export X into ECC registers, little endian
@ -197,7 +205,7 @@ static int internal_mpi_read_eccreg( mbedtls_mpi *X, const volatile uint32_t *ec
* \note Source MPI cannot be negative.
* \note Fills the remaining MSB ECC registers with zeros if X doesn't cover all.
*/
static int internal_mpi_write_eccreg( const mbedtls_mpi *X, volatile uint32_t *eccreg, size_t eccreg_num );
NU_STATIC int internal_mpi_write_eccreg( const mbedtls_mpi *X, volatile uint32_t *eccreg, size_t eccreg_num );
unsigned char mbedtls_internal_ecp_grp_capable( const mbedtls_ecp_group *grp )
{
@ -456,7 +464,7 @@ cleanup:
}
#endif
int internal_run_eccop(const mbedtls_ecp_group *grp,
NU_STATIC int internal_run_eccop(const mbedtls_ecp_group *grp,
mbedtls_ecp_point *R,
const mbedtls_mpi *m,
const mbedtls_ecp_point *P,
@ -640,7 +648,7 @@ cleanup:
return ret;
}
int internal_run_modop(mbedtls_mpi *r,
NU_STATIC int internal_run_modop(mbedtls_mpi *r,
const mbedtls_mpi *o1,
const mbedtls_mpi *o2,
const mbedtls_mpi *p,
@ -734,7 +742,7 @@ cleanup:
#endif // ECP_SHORTWEIERSTRASS
static int internal_mpi_read_eccreg(mbedtls_mpi *x, const volatile uint32_t *eccreg, size_t eccreg_num)
NU_STATIC int internal_mpi_read_eccreg(mbedtls_mpi *x, const volatile uint32_t *eccreg, size_t eccreg_num)
{
if (x == NULL) {
return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
@ -761,7 +769,7 @@ cleanup:
return ret;
}
static int internal_mpi_write_eccreg( const mbedtls_mpi *x, volatile uint32_t *eccreg, size_t eccreg_num )
NU_STATIC int internal_mpi_write_eccreg( const mbedtls_mpi *x, volatile uint32_t *eccreg, size_t eccreg_num )
{
if (x == NULL) {
return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;