1515#include  <string.h> 
1616#include  "crypto_api.h" 
1717
18+ #ifdef  WINDOWS 
19+ #include  "xmalloc.h" 
20+ #endif  /* WINDOWS */ 
21+ 1822#define  int8  crypto_int8
1923#define  uint8  crypto_uint8
2024#define  int16  crypto_int16
@@ -296,11 +300,25 @@ static void Decode(uint16 *out,const unsigned char *S,const uint16 *M,long long
296300 else 
297301 * out  =  uint32_mod_uint14 (S [0 ]+ (((uint16 )S [1 ])<<8 ),M [0 ]);
298302 }
303+ #ifdef  WINDOWS 
304+  uint16_t  * R2  =  NULL , * M2  =  NULL , * bottomr  =  NULL ;
305+  uint32_t  * bottomt  =  NULL ;
306+  size_t  MR_len  =  0 , bottom_len  =  0 ;
307+ #endif  /* WINDOWS */ 
299308 if  (len  >  1 ) {
309+ #ifdef  WINDOWS 
310+  MR_len  =  (len  +  1 ) / 2 ;
311+  bottom_len  =  len  / 2 ;
312+  R2  =  xcalloc (MR_len , sizeof (* R2 ));
313+  M2  =  xcalloc (MR_len , sizeof (* M2 ));
314+  bottomr  =  xcalloc (bottom_len , sizeof (* bottomr ));
315+  bottomt  =  xcalloc (bottom_len , sizeof (* bottomt ));
316+ #else 
300317 uint16  R2 [(len + 1 )/2 ];
301318 uint16  M2 [(len + 1 )/2 ];
302319 uint16  bottomr [len /2 ];
303320 uint32  bottomt [len /2 ];
321+ #endif  /* WINDOWS */ 
304322 long long  i ;
305323 for  (i  =  0 ;i  <  len - 1 ;i  +=  2 ) {
306324 uint32  m  =  M [i ]* (uint32 ) M [i + 1 ];
@@ -336,6 +354,12 @@ static void Decode(uint16 *out,const unsigned char *S,const uint16 *M,long long
336354 if  (i  <  len )
337355 * out ++  =  R2 [i /2 ];
338356 }
357+ #ifdef  WINDOWS 
358+  freezero (R2 , MR_len  *  sizeof (* R2 ));
359+  freezero (M2 , MR_len  *  sizeof (* M2 ));
360+  freezero (bottomr , bottom_len  *  sizeof (* bottomr ));
361+  freezero (bottomt , bottom_len  *  sizeof (* bottomt ));
362+ #endif  /* WINDOWS */ 
339363}
340364
341365/* from supercop-20201130/crypto_kem/sntrup761/ref/Encode.h */ 
@@ -362,9 +386,19 @@ static void Encode(unsigned char *out,const uint16 *R,const uint16 *M,long long
362386 m  =  (m + 255 )>>8 ;
363387 }
364388 }
389+ #ifdef  WINDOWS 
390+  uint16_t  * R2  =  NULL , * M2  =  NULL ;
391+  size_t  MR_len  =  0 ;
392+ #endif  /* WINDOWS */ 
365393 if  (len  >  1 ) {
394+ #ifdef  WINDOWS 
395+  MR_len  =  (len  +  1 ) / 2 ;
396+  R2  =  xcalloc (MR_len , sizeof (* R2 ));
397+  M2  =  xcalloc (MR_len , sizeof (* M2 ));
398+ #else 
366399 uint16  R2 [(len + 1 )/2 ];
367400 uint16  M2 [(len + 1 )/2 ];
401+ #endif  /* WINDOWS */ 
368402 long long  i ;
369403 for  (i  =  0 ;i  <  len - 1 ;i  +=  2 ) {
370404 uint32  m0  =  M [i ];
@@ -384,6 +418,10 @@ static void Encode(unsigned char *out,const uint16 *R,const uint16 *M,long long
384418 }
385419 Encode (out ,R2 ,M2 ,(len + 1 )/2 );
386420 }
421+ #ifdef  WINDOWS 
422+  freezero (R2 , MR_len  *  sizeof (* R2 ));
423+  freezero (M2 , MR_len  *  sizeof (* M2 ));
424+ #endif  /* WINDOWS */ 
387425}
388426
389427/* from supercop-20201130/crypto_kem/sntrup761/ref/kem.c */ 
@@ -685,14 +723,22 @@ static void Short_fromlist(small *out,const uint32 *in)
685723/* e.g., b = 0 means out = Hash0(in) */ 
686724static  void  Hash_prefix (unsigned char   * out ,int  b ,const  unsigned char   * in ,int  inlen )
687725{
726+ #ifdef  WINDOWS 
727+  unsigned char  *  x ;
728+  x  =  xcalloc (inlen  +  1 , sizeof (* x ));
729+ #else 
688730 unsigned char   x [inlen + 1 ];
731+ #endif  /* WINDOWS */ 
689732 unsigned char   h [64 ];
690733 int  i ;
691734
692735 x [0 ] =  b ;
693736 for  (i  =  0 ;i  <  inlen ;++ i ) x [i + 1 ] =  in [i ];
694737 crypto_hash_sha512 (h ,x ,inlen + 1 );
695738 for  (i  =  0 ;i  <  32 ;++ i ) out [i ] =  h [i ];
739+ #ifdef  WINDOWS 
740+  freezero (x , (inlen  +  1 ) *  sizeof (* x ));
741+ #endif  /* WINDOWS */ 
696742}
697743
698744/* ----- higher-level randomness */ 
0 commit comments