Skip to content

Commit a5b15bc

Browse files
committed
Fixed static buffer allocation for ECC signature verification
1 parent 41c60f4 commit a5b15bc

2 files changed

Lines changed: 63 additions & 2 deletions

File tree

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ ifeq ($(CORTEX_M0),1)
5454
MATH_OBJS += ./lib/wolfssl/wolfcrypt/src/sp_c32.o
5555
else
5656
CFLAGS:=-mcpu=cortex-m3
57-
MATH_OBJS += ./lib/wolfssl/wolfcrypt/src/sp_cortexm.o
57+
#MATH_OBJS += ./lib/wolfssl/wolfcrypt/src/sp_cortexm.o
58+
MATH_OBJS += ./lib/wolfssl/wolfcrypt/src/sp_c32.o
5859
endif
5960

6061
ifeq ($(FASTMATH),1)

src/xmalloc.c

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,27 @@
55

66
#define SP_POINT_SIZE (244)
77
#define MAX_POINTS 2
8-
98
#define SCRATCHBOARD_SIZE (640)
9+
#define TMP_BUFFER_SIZE (124)
10+
#define SP_DIGITS_SIZE (400)
11+
#define SP_NORMALIZER_SIZE (128)
12+
1013
static uint8_t sp_scratchboard[SCRATCHBOARD_SIZE];
1114
static int sp_scratchboard_in_use = 0;
1215

1316
static uint8_t sp_point_buffer0[SP_POINT_SIZE];
1417
static uint8_t sp_point_buffer1[SP_POINT_SIZE];
18+
static uint8_t tmp_buffer[TMP_BUFFER_SIZE];
19+
static uint8_t sp_three_points[SP_POINT_SIZE * 3];
20+
static uint8_t sp_digits[SP_DIGITS_SIZE];
21+
static uint8_t sp_normalizer[SP_NORMALIZER_SIZE];
1522

1623
static int point_0_in_use = 0;
1724
static int point_1_in_use = 0;
25+
static int tmp_buffer_in_use = 0;
26+
static int sp_three_points_in_use = 0;
27+
static int sp_digits_in_use = 0;
28+
static int sp_normalizer_in_use = 0;
1829

1930
static void* xmalloc_sp_point(void)
2031
{
@@ -36,12 +47,53 @@ static void* xmalloc_sp_scratchboard(void)
3647
return sp_scratchboard;
3748
}
3849

50+
static void* xmalloc_sp_tmpbuffer(void)
51+
{
52+
if (tmp_buffer_in_use)
53+
return NULL;
54+
tmp_buffer_in_use++;
55+
return tmp_buffer;
56+
}
57+
58+
static void* xmalloc_sp_three_points(void)
59+
{
60+
if (sp_three_points_in_use)
61+
return NULL;
62+
sp_three_points_in_use++;
63+
return sp_three_points;
64+
}
65+
66+
static void* xmalloc_sp_digits(void)
67+
{
68+
if (sp_digits_in_use)
69+
return NULL;
70+
sp_digits_in_use++;
71+
return sp_digits;
72+
}
73+
74+
static void* xmalloc_sp_normalizer(void)
75+
{
76+
if (sp_normalizer_in_use)
77+
return NULL;
78+
sp_normalizer_in_use++;
79+
return sp_normalizer;
80+
}
81+
82+
3983
void* XMALLOC(size_t n, void* heap, int type)
4084
{
4185
if (n == SP_POINT_SIZE)
4286
return xmalloc_sp_point();
4387
if (n == SCRATCHBOARD_SIZE)
4488
return xmalloc_sp_scratchboard();
89+
if (n == TMP_BUFFER_SIZE)
90+
return xmalloc_sp_tmpbuffer();
91+
if (n == 3 * SP_POINT_SIZE)
92+
return xmalloc_sp_three_points();
93+
if (n == SP_DIGITS_SIZE)
94+
return xmalloc_sp_digits();
95+
if (n == SP_NORMALIZER_SIZE)
96+
return xmalloc_sp_normalizer();
4597
return NULL;
4698
}
4799

@@ -53,4 +105,12 @@ void XFREE(void *ptr)
53105
point_1_in_use = 0;
54106
if (ptr == sp_scratchboard)
55107
sp_scratchboard_in_use = 0;
108+
if (ptr == tmp_buffer)
109+
tmp_buffer_in_use = 0;
110+
if (ptr == sp_three_points)
111+
sp_three_points_in_use = 0;
112+
if (ptr == sp_digits)
113+
sp_digits_in_use = 0;
114+
if (ptr == sp_normalizer)
115+
sp_normalizer_in_use = 0;
56116
}

0 commit comments

Comments
 (0)