Skip to content

Commit e14efd6

Browse files
committed
ECC verification: added support for ASM optimization, enabled by default
(turn off with NO_ASM=1)
1 parent a5b15bc commit e14efd6

3 files changed

Lines changed: 49 additions & 34 deletions

File tree

Makefile

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ DEBUG?=0
1414
VTOR?=1
1515
SWAP?=1
1616
CORTEX_M0?=0
17+
NO_ASM=0
1718

1819
LSCRIPT:=hal/$(TARGET).ld
1920

@@ -53,9 +54,13 @@ ifeq ($(CORTEX_M0),1)
5354
CFLAGS:=-mcpu=cortex-m0
5455
MATH_OBJS += ./lib/wolfssl/wolfcrypt/src/sp_c32.o
5556
else
56-
CFLAGS:=-mcpu=cortex-m3
57-
#MATH_OBJS += ./lib/wolfssl/wolfcrypt/src/sp_cortexm.o
58-
MATH_OBJS += ./lib/wolfssl/wolfcrypt/src/sp_c32.o
57+
ifeq ($(NO_ASM),1)
58+
MATH_OBJS += ./lib/wolfssl/wolfcrypt/src/sp_c32.o
59+
CFLAGS:=-mcpu=cortex-m3
60+
else
61+
CFLAGS:=-mcpu=cortex-m3 -DWOLFSSL_SP_ASM -DWOLFSSL_SP_ARM_CORTEX_M_ASM -fomit-frame-pointer
62+
MATH_OBJS += ./lib/wolfssl/wolfcrypt/src/sp_cortexm.o
63+
endif
5964
endif
6065

6166
ifeq ($(FASTMATH),1)

lib/wolfssl

Submodule wolfssl updated 84 files

src/xmalloc.c

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,48 @@
22
#include <stdint.h>
33

44
/* Allow one single sp_point to be allocated at one time */
5-
6-
#define SP_POINT_SIZE (244)
7-
#define MAX_POINTS 2
8-
#define SCRATCHBOARD_SIZE (640)
5+
#ifdef WOLFSSL_SP_ASM
6+
# define SP_POINT_SIZE (196)
7+
# define SCRATCHBOARD_SIZE (512)
8+
# define SP_DIGITS_SIZE (320)
9+
# define MAX_POINTS (4)
10+
# define MULTIPOINT_SIZE (16)
11+
#else
12+
# define SP_POINT_SIZE (244)
13+
# define SCRATCHBOARD_SIZE (640)
14+
# define SP_DIGITS_SIZE (400)
15+
# define MAX_POINTS (2)
16+
# define MULTIPOINT_SIZE (3)
17+
#endif
918
#define TMP_BUFFER_SIZE (124)
10-
#define SP_DIGITS_SIZE (400)
1119
#define SP_NORMALIZER_SIZE (128)
1220

1321
static uint8_t sp_scratchboard[SCRATCHBOARD_SIZE];
1422
static int sp_scratchboard_in_use = 0;
1523

16-
static uint8_t sp_point_buffer0[SP_POINT_SIZE];
17-
static uint8_t sp_point_buffer1[SP_POINT_SIZE];
24+
static int sp_point_in_use[MAX_POINTS] = { };
25+
static uint8_t sp_point_buffer[MAX_POINTS][SP_POINT_SIZE];
26+
1827
static uint8_t tmp_buffer[TMP_BUFFER_SIZE];
19-
static uint8_t sp_three_points[SP_POINT_SIZE * 3];
28+
static uint8_t sp_multipoint[SP_POINT_SIZE * MULTIPOINT_SIZE];
2029
static uint8_t sp_digits[SP_DIGITS_SIZE];
2130
static uint8_t sp_normalizer[SP_NORMALIZER_SIZE];
2231

23-
static int point_0_in_use = 0;
24-
static int point_1_in_use = 0;
2532
static int tmp_buffer_in_use = 0;
26-
static int sp_three_points_in_use = 0;
33+
static int sp_multipoint_in_use = 0;
2734
static int sp_digits_in_use = 0;
2835
static int sp_normalizer_in_use = 0;
2936

3037
static void* xmalloc_sp_point(void)
3138
{
32-
if (point_0_in_use) {
33-
if (point_1_in_use)
34-
return NULL;
35-
point_1_in_use++;
36-
return sp_point_buffer1;
39+
int i;
40+
for (i = 0; i < MAX_POINTS; i++) {
41+
if (sp_point_in_use[i] == 0) {
42+
sp_point_in_use[i]++;
43+
return sp_point_buffer[i];
44+
}
3745
}
38-
point_0_in_use++;
39-
return sp_point_buffer0;
46+
return NULL;
4047
}
4148

4249
static void* xmalloc_sp_scratchboard(void)
@@ -55,12 +62,12 @@ static void* xmalloc_sp_tmpbuffer(void)
5562
return tmp_buffer;
5663
}
5764

58-
static void* xmalloc_sp_three_points(void)
65+
static void* xmalloc_sp_multipoint(void)
5966
{
60-
if (sp_three_points_in_use)
67+
if (sp_multipoint_in_use)
6168
return NULL;
62-
sp_three_points_in_use++;
63-
return sp_three_points;
69+
sp_multipoint_in_use++;
70+
return sp_multipoint;
6471
}
6572

6673
static void* xmalloc_sp_digits(void)
@@ -88,8 +95,8 @@ void* XMALLOC(size_t n, void* heap, int type)
8895
return xmalloc_sp_scratchboard();
8996
if (n == TMP_BUFFER_SIZE)
9097
return xmalloc_sp_tmpbuffer();
91-
if (n == 3 * SP_POINT_SIZE)
92-
return xmalloc_sp_three_points();
98+
if (n == MULTIPOINT_SIZE * SP_POINT_SIZE)
99+
return xmalloc_sp_multipoint();
93100
if (n == SP_DIGITS_SIZE)
94101
return xmalloc_sp_digits();
95102
if (n == SP_NORMALIZER_SIZE)
@@ -99,18 +106,21 @@ void* XMALLOC(size_t n, void* heap, int type)
99106

100107
void XFREE(void *ptr)
101108
{
102-
if (ptr == sp_point_buffer0)
103-
point_0_in_use = 0;
104-
if (ptr == sp_point_buffer1)
105-
point_1_in_use = 0;
109+
int i;
106110
if (ptr == sp_scratchboard)
107111
sp_scratchboard_in_use = 0;
108112
if (ptr == tmp_buffer)
109113
tmp_buffer_in_use = 0;
110-
if (ptr == sp_three_points)
111-
sp_three_points_in_use = 0;
114+
if (ptr == sp_multipoint)
115+
sp_multipoint_in_use = 0;
112116
if (ptr == sp_digits)
113117
sp_digits_in_use = 0;
114118
if (ptr == sp_normalizer)
115119
sp_normalizer_in_use = 0;
120+
for (i = 0; i < MAX_POINTS; i++) {
121+
if (ptr == sp_point_buffer[i]) {
122+
sp_point_in_use[i] = 0;
123+
return;
124+
}
125+
}
116126
}

0 commit comments

Comments
 (0)