@@ -377,11 +377,7 @@ static int kyberkey_encapsulate(KyberKey* key, const byte* msg, byte* coins,
377377 sword16 * epp = NULL ;
378378 unsigned int kp = 0 ;
379379 unsigned int compVecSz = 0 ;
380- #ifndef USE_INTEL_SPEEDUP
381380 sword16 * at = NULL ;
382- #else
383- sword16 at [((KYBER_MAX_K + 3 ) * KYBER_MAX_K + 3 ) * KYBER_N ];
384- #endif
385381
386382 /* Establish parameters based on key type. */
387383 switch (key -> type ) {
@@ -409,16 +405,20 @@ static int kyberkey_encapsulate(KyberKey* key, const byte* msg, byte* coins,
409405 break ;
410406 }
411407
412- #ifndef USE_INTEL_SPEEDUP
413408 if (ret == 0 ) {
414409 /* Allocate dynamic memory for all matrices, vectors and polynomials. */
410+ #ifndef USE_INTEL_SPEEDUP
415411 at = (sword16 * )XMALLOC (((kp + 3 ) * kp + 3 ) * KYBER_N * sizeof (sword16 ),
416412 key -> heap , DYNAMIC_TYPE_TMP_BUFFER );
413+ #else
414+ at = (sword16 * )XMALLOC (
415+ ((KYBER_MAX_K + 3 ) * KYBER_MAX_K + 3 ) * KYBER_N * sizeof (sword16 ),
416+ key -> heap , DYNAMIC_TYPE_TMP_BUFFER );
417+ #endif
417418 if (at == NULL ) {
418419 ret = MEMORY_E ;
419420 }
420421 }
421- #endif
422422
423423 if (ret == 0 ) {
424424 /* Assign allocated dynamic memory to pointers.
@@ -472,10 +472,8 @@ static int kyberkey_encapsulate(KyberKey* key, const byte* msg, byte* coins,
472472 #endif
473473 }
474474
475- #ifndef USE_INTEL_SPEEDUP
476475 /* Dispose of dynamic memory allocated in function. */
477476 XFREE (at , key -> heap , DYNAMIC_TYPE_TMP_BUFFER );
478- #endif
479477
480478 return ret ;
481479}
0 commit comments