ECC verification: added support for ASM optimization, enabled by default

(turn off with NO_ASM=1)
pull/3/head
Daniele Lacamera 2019-01-21 09:51:12 +01:00
parent a5b15bc40f
commit e14efd641a
3 changed files with 49 additions and 34 deletions

View File

@ -14,6 +14,7 @@ DEBUG?=0
VTOR?=1 VTOR?=1
SWAP?=1 SWAP?=1
CORTEX_M0?=0 CORTEX_M0?=0
NO_ASM=0
LSCRIPT:=hal/$(TARGET).ld LSCRIPT:=hal/$(TARGET).ld
@ -53,9 +54,13 @@ ifeq ($(CORTEX_M0),1)
CFLAGS:=-mcpu=cortex-m0 CFLAGS:=-mcpu=cortex-m0
MATH_OBJS += ./lib/wolfssl/wolfcrypt/src/sp_c32.o MATH_OBJS += ./lib/wolfssl/wolfcrypt/src/sp_c32.o
else else
CFLAGS:=-mcpu=cortex-m3 ifeq ($(NO_ASM),1)
#MATH_OBJS += ./lib/wolfssl/wolfcrypt/src/sp_cortexm.o MATH_OBJS += ./lib/wolfssl/wolfcrypt/src/sp_c32.o
MATH_OBJS += ./lib/wolfssl/wolfcrypt/src/sp_c32.o CFLAGS:=-mcpu=cortex-m3
else
CFLAGS:=-mcpu=cortex-m3 -DWOLFSSL_SP_ASM -DWOLFSSL_SP_ARM_CORTEX_M_ASM -fomit-frame-pointer
MATH_OBJS += ./lib/wolfssl/wolfcrypt/src/sp_cortexm.o
endif
endif endif
ifeq ($(FASTMATH),1) ifeq ($(FASTMATH),1)

@ -1 +1 @@
Subproject commit a506c6591dad47036508d55315d09bc13b799a1f Subproject commit 501a3a287b70a1daa982c016f843eb78b44b4857

View File

@ -2,41 +2,48 @@
#include <stdint.h> #include <stdint.h>
/* Allow one single sp_point to be allocated at one time */ /* Allow one single sp_point to be allocated at one time */
#ifdef WOLFSSL_SP_ASM
#define SP_POINT_SIZE (244) # define SP_POINT_SIZE (196)
#define MAX_POINTS 2 # define SCRATCHBOARD_SIZE (512)
#define SCRATCHBOARD_SIZE (640) # define SP_DIGITS_SIZE (320)
# define MAX_POINTS (4)
# define MULTIPOINT_SIZE (16)
#else
# define SP_POINT_SIZE (244)
# define SCRATCHBOARD_SIZE (640)
# define SP_DIGITS_SIZE (400)
# define MAX_POINTS (2)
# define MULTIPOINT_SIZE (3)
#endif
#define TMP_BUFFER_SIZE (124) #define TMP_BUFFER_SIZE (124)
#define SP_DIGITS_SIZE (400)
#define SP_NORMALIZER_SIZE (128) #define SP_NORMALIZER_SIZE (128)
static uint8_t sp_scratchboard[SCRATCHBOARD_SIZE]; static uint8_t sp_scratchboard[SCRATCHBOARD_SIZE];
static int sp_scratchboard_in_use = 0; static int sp_scratchboard_in_use = 0;
static uint8_t sp_point_buffer0[SP_POINT_SIZE]; static int sp_point_in_use[MAX_POINTS] = { };
static uint8_t sp_point_buffer1[SP_POINT_SIZE]; static uint8_t sp_point_buffer[MAX_POINTS][SP_POINT_SIZE];
static uint8_t tmp_buffer[TMP_BUFFER_SIZE]; static uint8_t tmp_buffer[TMP_BUFFER_SIZE];
static uint8_t sp_three_points[SP_POINT_SIZE * 3]; static uint8_t sp_multipoint[SP_POINT_SIZE * MULTIPOINT_SIZE];
static uint8_t sp_digits[SP_DIGITS_SIZE]; static uint8_t sp_digits[SP_DIGITS_SIZE];
static uint8_t sp_normalizer[SP_NORMALIZER_SIZE]; static uint8_t sp_normalizer[SP_NORMALIZER_SIZE];
static int point_0_in_use = 0;
static int point_1_in_use = 0;
static int tmp_buffer_in_use = 0; static int tmp_buffer_in_use = 0;
static int sp_three_points_in_use = 0; static int sp_multipoint_in_use = 0;
static int sp_digits_in_use = 0; static int sp_digits_in_use = 0;
static int sp_normalizer_in_use = 0; static int sp_normalizer_in_use = 0;
static void* xmalloc_sp_point(void) static void* xmalloc_sp_point(void)
{ {
if (point_0_in_use) { int i;
if (point_1_in_use) for (i = 0; i < MAX_POINTS; i++) {
return NULL; if (sp_point_in_use[i] == 0) {
point_1_in_use++; sp_point_in_use[i]++;
return sp_point_buffer1; return sp_point_buffer[i];
}
} }
point_0_in_use++; return NULL;
return sp_point_buffer0;
} }
static void* xmalloc_sp_scratchboard(void) static void* xmalloc_sp_scratchboard(void)
@ -55,12 +62,12 @@ static void* xmalloc_sp_tmpbuffer(void)
return tmp_buffer; return tmp_buffer;
} }
static void* xmalloc_sp_three_points(void) static void* xmalloc_sp_multipoint(void)
{ {
if (sp_three_points_in_use) if (sp_multipoint_in_use)
return NULL; return NULL;
sp_three_points_in_use++; sp_multipoint_in_use++;
return sp_three_points; return sp_multipoint;
} }
static void* xmalloc_sp_digits(void) static void* xmalloc_sp_digits(void)
@ -88,8 +95,8 @@ void* XMALLOC(size_t n, void* heap, int type)
return xmalloc_sp_scratchboard(); return xmalloc_sp_scratchboard();
if (n == TMP_BUFFER_SIZE) if (n == TMP_BUFFER_SIZE)
return xmalloc_sp_tmpbuffer(); return xmalloc_sp_tmpbuffer();
if (n == 3 * SP_POINT_SIZE) if (n == MULTIPOINT_SIZE * SP_POINT_SIZE)
return xmalloc_sp_three_points(); return xmalloc_sp_multipoint();
if (n == SP_DIGITS_SIZE) if (n == SP_DIGITS_SIZE)
return xmalloc_sp_digits(); return xmalloc_sp_digits();
if (n == SP_NORMALIZER_SIZE) if (n == SP_NORMALIZER_SIZE)
@ -99,18 +106,21 @@ void* XMALLOC(size_t n, void* heap, int type)
void XFREE(void *ptr) void XFREE(void *ptr)
{ {
if (ptr == sp_point_buffer0) int i;
point_0_in_use = 0;
if (ptr == sp_point_buffer1)
point_1_in_use = 0;
if (ptr == sp_scratchboard) if (ptr == sp_scratchboard)
sp_scratchboard_in_use = 0; sp_scratchboard_in_use = 0;
if (ptr == tmp_buffer) if (ptr == tmp_buffer)
tmp_buffer_in_use = 0; tmp_buffer_in_use = 0;
if (ptr == sp_three_points) if (ptr == sp_multipoint)
sp_three_points_in_use = 0; sp_multipoint_in_use = 0;
if (ptr == sp_digits) if (ptr == sp_digits)
sp_digits_in_use = 0; sp_digits_in_use = 0;
if (ptr == sp_normalizer) if (ptr == sp_normalizer)
sp_normalizer_in_use = 0; sp_normalizer_in_use = 0;
for (i = 0; i < MAX_POINTS; i++) {
if (ptr == sp_point_buffer[i]) {
sp_point_in_use[i] = 0;
return;
}
}
} }