Skip to content

Commit 4b33c93

Browse files
ccli8cmonr
authored andcommitted
Support internal self-test for ECP alter.
1 parent 6c962c7 commit 4b33c93

File tree

1 file changed

+38
-30
lines changed

1 file changed

+38
-30
lines changed

features/mbedtls/targets/TARGET_NUVOTON/TARGET_M480/ecp/ecp_internal_alt.c

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@
2020
#include MBEDTLS_CONFIG_FILE
2121
#endif
2222

23+
/* Some internal functions are used for Nuvoton internal self-test.
24+
* Remove the static modifier for self-test compile. */
25+
#if defined(NU_CRYPTO_SELF_TEST) && NU_CRYPTO_SELF_TEST
26+
#define NU_STATIC
27+
#else
28+
#define NU_STATIC static
29+
#endif
30+
2331
#if defined(MBEDTLS_ECP_C)
2432

2533
#include "mbedtls/ecp.h"
@@ -139,13 +147,13 @@
139147
* n is kept with unused modifier.
140148
*
141149
*/
142-
int internal_run_eccop(const mbedtls_ecp_group *grp,
143-
mbedtls_ecp_point *R,
144-
const mbedtls_mpi *m,
145-
const mbedtls_ecp_point *P,
146-
MBED_UNUSED const mbedtls_mpi *n,
147-
const mbedtls_ecp_point *Q,
148-
uint32_t eccop);
150+
NU_STATIC int internal_run_eccop(const mbedtls_ecp_group *grp,
151+
mbedtls_ecp_point *R,
152+
const mbedtls_mpi *m,
153+
const mbedtls_ecp_point *P,
154+
MBED_UNUSED const mbedtls_mpi *n,
155+
const mbedtls_ecp_point *Q,
156+
uint32_t eccop);
149157

150158
/**
151159
* \brief Configure MODOP operation and wait for its completion
@@ -165,12 +173,12 @@ int internal_run_eccop(const mbedtls_ecp_group *grp,
165173
*
166174
* \note o1/o2 must be normalized (within [0, p - 1]). r would be normalized.
167175
*/
168-
int internal_run_modop(mbedtls_mpi *r,
169-
const mbedtls_mpi *o1,
170-
const mbedtls_mpi *o2,
171-
const mbedtls_mpi *p,
172-
uint32_t pbits,
173-
uint32_t modop);
176+
NU_STATIC int internal_run_modop(mbedtls_mpi *r,
177+
const mbedtls_mpi *o1,
178+
const mbedtls_mpi *o2,
179+
const mbedtls_mpi *p,
180+
uint32_t pbits,
181+
uint32_t modop);
174182

175183
/**
176184
* \brief Import X from ECC registers, little endian
@@ -183,7 +191,7 @@ int internal_run_modop(mbedtls_mpi *r,
183191
*
184192
* \note Destination MPI is always non-negative.
185193
*/
186-
static int internal_mpi_read_eccreg( mbedtls_mpi *X, const volatile uint32_t *eccreg, size_t eccreg_num );
194+
NU_STATIC int internal_mpi_read_eccreg( mbedtls_mpi *X, const volatile uint32_t *eccreg, size_t eccreg_num );
187195

188196
/**
189197
* \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
197205
* \note Source MPI cannot be negative.
198206
* \note Fills the remaining MSB ECC registers with zeros if X doesn't cover all.
199207
*/
200-
static int internal_mpi_write_eccreg( const mbedtls_mpi *X, volatile uint32_t *eccreg, size_t eccreg_num );
208+
NU_STATIC int internal_mpi_write_eccreg( const mbedtls_mpi *X, volatile uint32_t *eccreg, size_t eccreg_num );
201209

202210
unsigned char mbedtls_internal_ecp_grp_capable( const mbedtls_ecp_group *grp )
203211
{
@@ -456,13 +464,13 @@ int mbedtls_internal_ecp_normalize_jac_many(const mbedtls_ecp_group *grp,
456464
}
457465
#endif
458466

459-
int internal_run_eccop(const mbedtls_ecp_group *grp,
460-
mbedtls_ecp_point *R,
461-
const mbedtls_mpi *m,
462-
const mbedtls_ecp_point *P,
463-
MBED_UNUSED const mbedtls_mpi *n,
464-
const mbedtls_ecp_point *Q,
465-
uint32_t eccop)
467+
NU_STATIC int internal_run_eccop(const mbedtls_ecp_group *grp,
468+
mbedtls_ecp_point *R,
469+
const mbedtls_mpi *m,
470+
const mbedtls_ecp_point *P,
471+
MBED_UNUSED const mbedtls_mpi *n,
472+
const mbedtls_ecp_point *Q,
473+
uint32_t eccop)
466474
{
467475
/* Check necessary arguments for all ECC operations */
468476
if (grp == NULL || R == NULL) {
@@ -640,12 +648,12 @@ int internal_run_eccop(const mbedtls_ecp_group *grp,
640648
return ret;
641649
}
642650

643-
int internal_run_modop(mbedtls_mpi *r,
644-
const mbedtls_mpi *o1,
645-
const mbedtls_mpi *o2,
646-
const mbedtls_mpi *p,
647-
uint32_t pbits,
648-
uint32_t modop)
651+
NU_STATIC int internal_run_modop(mbedtls_mpi *r,
652+
const mbedtls_mpi *o1,
653+
const mbedtls_mpi *o2,
654+
const mbedtls_mpi *p,
655+
uint32_t pbits,
656+
uint32_t modop)
649657
{
650658
if (r == NULL ||
651659
o1 == NULL ||
@@ -734,7 +742,7 @@ int internal_run_modop(mbedtls_mpi *r,
734742

735743
#endif // ECP_SHORTWEIERSTRASS
736744

737-
static int internal_mpi_read_eccreg(mbedtls_mpi *x, const volatile uint32_t *eccreg, size_t eccreg_num)
745+
NU_STATIC int internal_mpi_read_eccreg(mbedtls_mpi *x, const volatile uint32_t *eccreg, size_t eccreg_num)
738746
{
739747
if (x == NULL) {
740748
return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
@@ -761,7 +769,7 @@ static int internal_mpi_read_eccreg(mbedtls_mpi *x, const volatile uint32_t *ecc
761769
return ret;
762770
}
763771

764-
static int internal_mpi_write_eccreg( const mbedtls_mpi *x, volatile uint32_t *eccreg, size_t eccreg_num )
772+
NU_STATIC int internal_mpi_write_eccreg( const mbedtls_mpi *x, volatile uint32_t *eccreg, size_t eccreg_num )
765773
{
766774
if (x == NULL) {
767775
return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;

0 commit comments

Comments
 (0)