2626#include <stdint.h>
2727
2828/* Allow one single sp_point to be allocated at one time */
29- #ifdef WOLFSSL_SP_ASM
29+ #ifdef FREESCALE_USE_LTC
30+ # define SP_POINT_SIZE (132)
31+ # define MAX_POINTS (3)
32+ # define SP_BIGINT_SIZE (128)
33+ # define MAX_BIGINTS (4)
34+ #elif defined(WOLFSSL_SP_ASM )
3035# define SP_POINT_SIZE (196)
3136# define SCRATCHBOARD_SIZE (512)
3237# define SP_DIGITS_SIZE (320)
4247#define TMP_BUFFER_SIZE (124)
4348#define SP_NORMALIZER_SIZE (128)
4449
45- static uint8_t sp_scratchboard [SCRATCHBOARD_SIZE ];
46- static int sp_scratchboard_in_use = 0 ;
4750
4851static int sp_point_in_use [MAX_POINTS ] = { };
4952static uint8_t sp_point_buffer [MAX_POINTS ][SP_POINT_SIZE ];
5053
54+ #ifdef FREESCALE_USE_LTC
55+ static int sp_bigint_in_use [MAX_BIGINTS ] = { };
56+ static uint8_t sp_bigint_buffer [MAX_BIGINTS ][SP_BIGINT_SIZE ];
57+ #else
5158static uint8_t tmp_buffer [TMP_BUFFER_SIZE ];
5259static uint8_t sp_multipoint [SP_POINT_SIZE * MULTIPOINT_SIZE ];
5360static uint8_t sp_digits [SP_DIGITS_SIZE ];
5461static uint8_t sp_normalizer [SP_NORMALIZER_SIZE ];
55-
62+ static uint8_t sp_scratchboard [SCRATCHBOARD_SIZE ];
63+ static int sp_scratchboard_in_use = 0 ;
5664static int tmp_buffer_in_use = 0 ;
5765static int sp_multipoint_in_use = 0 ;
5866static int sp_digits_in_use = 0 ;
5967static int sp_normalizer_in_use = 0 ;
68+ #endif
6069
6170static void * xmalloc_sp_point (void )
6271{
@@ -70,6 +79,20 @@ static void* xmalloc_sp_point(void)
7079 return NULL ;
7180}
7281
82+ #ifdef FREESCALE_USE_LTC
83+ static void * xmalloc_sp_bigint (void )
84+ {
85+ int i ;
86+ for (i = 0 ; i < MAX_BIGINTS ; i ++ ) {
87+ if (sp_bigint_in_use [i ] == 0 ) {
88+ sp_bigint_in_use [i ]++ ;
89+ return sp_bigint_buffer [i ];
90+ }
91+ }
92+ return NULL ;
93+ }
94+ #else
95+
7396static void * xmalloc_sp_scratchboard (void )
7497{
7598 if (sp_scratchboard_in_use )
@@ -111,10 +134,16 @@ static void* xmalloc_sp_normalizer(void)
111134}
112135
113136
137+ #endif
138+
114139void * XMALLOC (size_t n , void * heap , int type )
115140{
116141 if (n == SP_POINT_SIZE )
117142 return xmalloc_sp_point ();
143+ #ifdef FREESCALE_USE_LTC
144+ if (n == SP_BIGINT_SIZE )
145+ return xmalloc_sp_bigint ();
146+ #else
118147 if (n == SCRATCHBOARD_SIZE )
119148 return xmalloc_sp_scratchboard ();
120149 if (n == TMP_BUFFER_SIZE )
@@ -125,12 +154,27 @@ void* XMALLOC(size_t n, void* heap, int type)
125154 return xmalloc_sp_digits ();
126155 if (n == SP_NORMALIZER_SIZE )
127156 return xmalloc_sp_normalizer ();
157+ #endif
128158 return NULL ;
129159}
130160
131161void XFREE (void * ptr )
132162{
133163 int i ;
164+ for (i = 0 ; i < MAX_POINTS ; i ++ ) {
165+ if (ptr == sp_point_buffer [i ]) {
166+ sp_point_in_use [i ] = 0 ;
167+ return ;
168+ }
169+ }
170+ #ifdef FREESCALE_USE_LTC
171+ for (i = 0 ; i < MAX_BIGINTS ; i ++ ) {
172+ if (ptr == sp_bigint_buffer [i ]) {
173+ sp_bigint_in_use [i ] = 0 ;
174+ return ;
175+ }
176+ }
177+ #else
134178 if (ptr == sp_scratchboard )
135179 sp_scratchboard_in_use = 0 ;
136180 if (ptr == tmp_buffer )
@@ -141,10 +185,5 @@ void XFREE(void *ptr)
141185 sp_digits_in_use = 0 ;
142186 if (ptr == sp_normalizer )
143187 sp_normalizer_in_use = 0 ;
144- for (i = 0 ; i < MAX_POINTS ; i ++ ) {
145- if (ptr == sp_point_buffer [i ]) {
146- sp_point_in_use [i ] = 0 ;
147- return ;
148- }
149- }
188+ #endif
150189}
0 commit comments