@@ -516,16 +516,17 @@ int wc_MlKemKey_MakeKeyWithRandom(MlKemKey* key, const unsigned char* rand,
516516#ifndef WOLFSSL_MLKEM_MAKEKEY_SMALL_MEM
517517#ifndef WOLFSSL_MLKEM_CACHE_A
518518 /* e (v) | a (m) */
519- e = (sword16 * )XMALLOC ((k + 1 ) * k * MLKEM_N * sizeof (sword16 ),
519+ e = (sword16 * )XMALLOC ((size_t )(k + 1 ) * (size_t )k *
520+ (size_t )MLKEM_N * sizeof (sword16 ),
520521 key -> heap , DYNAMIC_TYPE_TMP_BUFFER );
521522#else
522523 /* e (v) */
523- e = (sword16 * )XMALLOC (k * MLKEM_N * sizeof (sword16 ),
524+ e = (sword16 * )XMALLOC (( size_t ) k * ( size_t ) MLKEM_N * sizeof (sword16 ),
524525 key -> heap , DYNAMIC_TYPE_TMP_BUFFER );
525526#endif
526527#else
527528 /* e (v) */
528- e = (sword16 * )XMALLOC (k * MLKEM_N * sizeof (sword16 ),
529+ e = (sword16 * )XMALLOC (( size_t ) k * ( size_t ) MLKEM_N * sizeof (sword16 ),
529530 key -> heap , DYNAMIC_TYPE_TMP_BUFFER );
530531#endif
531532 if (e == NULL ) {
@@ -557,7 +558,7 @@ int wc_MlKemKey_MakeKeyWithRandom(MlKemKey* key, const unsigned char* rand,
557558#endif
558559#ifndef WOLFSSL_NO_ML_KEM
559560 {
560- buf [0 ] = k ;
561+ buf [0 ] = ( byte ) k ;
561562 /* Expand 33 bytes of random to 32.
562563 * Alg 13: Step 1: (rho,sigma) <- G(d||k)
563564 */
@@ -582,7 +583,7 @@ int wc_MlKemKey_MakeKeyWithRandom(MlKemKey* key, const unsigned char* rand,
582583 /* Generate noise using PRF.
583584 * Alg 13: Steps 8-15: generate s and e
584585 */
585- ret = mlkem_get_noise (& key -> prf , k , s , e , NULL , sigma );
586+ ret = mlkem_get_noise (& key -> prf , ( int ) k , s , e , NULL , sigma );
586587 }
587588 if (ret == 0 ) {
588589 /* Generate the matrix A.
@@ -819,10 +820,12 @@ static int mlkemkey_encapsulate(MlKemKey* key, const byte* m, byte* r, byte* c)
819820 if (ret == 0 ) {
820821 /* Allocate dynamic memory for all matrices, vectors and polynomials. */
821822#ifndef WOLFSSL_MLKEM_ENCAPSULATE_SMALL_MEM
822- y = (sword16 * )XMALLOC (((k + 3 ) * k + 3 ) * MLKEM_N * sizeof (sword16 ),
823+ y = (sword16 * )XMALLOC (((size_t )(k + 3 ) * (size_t )k + 3 ) *
824+ (size_t )MLKEM_N * sizeof (sword16 ),
823825 key -> heap , DYNAMIC_TYPE_TMP_BUFFER );
824826#else
825- y = (sword16 * )XMALLOC (3 * k * MLKEM_N * sizeof (sword16 ), key -> heap ,
827+ y = (sword16 * )XMALLOC ((size_t )3 * (size_t )k *
828+ (size_t )MLKEM_N * sizeof (sword16 ), key -> heap ,
826829 DYNAMIC_TYPE_TMP_BUFFER );
827830#endif
828831 if (y == NULL ) {
@@ -849,7 +852,7 @@ static int mlkemkey_encapsulate(MlKemKey* key, const byte* m, byte* r, byte* c)
849852 /* Generate noise using PRF.
850853 * Steps 9-17: generate y, e_1, e_2
851854 */
852- ret = mlkem_get_noise (& key -> prf , k , y , e1 , e2 , r );
855+ ret = mlkem_get_noise (& key -> prf , ( int ) k , y , e1 , e2 , r );
853856 }
854857 #ifdef WOLFSSL_MLKEM_CACHE_A
855858 if ((ret == 0 ) && ((key -> flags & MLKEM_FLAG_A_SET ) != 0 )) {
@@ -870,7 +873,7 @@ static int mlkemkey_encapsulate(MlKemKey* key, const byte* m, byte* r, byte* c)
870873 if (ret == 0 ) {
871874 /* Generate the transposed matrix.
872875 * Step 4-8: generate matrix A_hat */
873- ret = mlkem_gen_matrix (& key -> prf , a , k , key -> pubSeed , 1 );
876+ ret = mlkem_gen_matrix (& key -> prf , a , ( int ) k , key -> pubSeed , 1 );
874877 }
875878 if (ret == 0 ) {
876879 /* Assign remaining allocated dynamic memory to pointers.
@@ -880,7 +883,7 @@ static int mlkemkey_encapsulate(MlKemKey* key, const byte* m, byte* r, byte* c)
880883
881884 /* Perform encapsulation maths.
882885 * Steps 18-19, 21: calculate u and v */
883- mlkem_encapsulate (key -> pub , u , v , a , y , e1 , e2 , mu , k );
886+ mlkem_encapsulate (key -> pub , u , v , a , y , e1 , e2 , mu , ( int ) k );
884887 }
885888#else /* WOLFSSL_MLKEM_ENCAPSULATE_SMALL_MEM */
886889 if (ret == 0 ) {
@@ -892,7 +895,7 @@ static int mlkemkey_encapsulate(MlKemKey* key, const byte* m, byte* r, byte* c)
892895 mlkem_prf_init (& key -> prf );
893896 /* Generate noise using PRF.
894897 * Steps 9-12: generate y */
895- ret = mlkem_get_noise (& key -> prf , k , y , NULL , NULL , r );
898+ ret = mlkem_get_noise (& key -> prf , ( int ) k , y , NULL , NULL , r );
896899 }
897900 if (ret == 0 ) {
898901 /* Assign remaining allocated dynamic memory to pointers.
@@ -903,7 +906,7 @@ static int mlkemkey_encapsulate(MlKemKey* key, const byte* m, byte* r, byte* c)
903906 /* Perform encapsulation maths.
904907 * Steps 13-17: generate e_1 and e_2
905908 * Steps 18-19, 21: calculate u and v */
906- ret = mlkem_encapsulate_seeds (key -> pub , & key -> prf , u , a , y , k , m ,
909+ ret = mlkem_encapsulate_seeds (key -> pub , & key -> prf , u , a , y , ( int ) k , m ,
907910 key -> pubSeed , r );
908911 }
909912#endif /* WOLFSSL_MLKEM_ENCAPSULATE_SMALL_MEM */
@@ -1344,7 +1347,7 @@ static MLKEM_NOINLINE int mlkemkey_decapsulate(MlKemKey* key, byte* m,
13441347
13451348 /* Decapsulate the cipher text into polynomial.
13461349 * Step 6: w <- v' - InvNTT(s_hat_trans o NTT(u')) */
1347- mlkem_decapsulate (key -> priv , w , u , v , k );
1350+ mlkem_decapsulate (key -> priv , w , u , v , ( int ) k );
13481351
13491352 /* Convert the polynomial into a array of bytes (message).
13501353 * Step 7: m <- ByteEncode_1(Compress_1(w)) */
@@ -1498,7 +1501,7 @@ int wc_MlKemKey_Decapsulate(MlKemKey* key, unsigned char* ss,
14981501 }
14991502 if (ret == 0 ) {
15001503 /* Compare generated cipher text with that passed in. */
1501- fail = mlkem_cmp (ct , cmp , ctSz );
1504+ fail = mlkem_cmp (ct , cmp , ( int ) ctSz );
15021505
15031506#if defined(WOLFSSL_MLKEM_KYBER ) && !defined(WOLFSSL_NO_ML_KEM )
15041507 if (key -> type & MLKEM_KYBER )
@@ -1527,7 +1530,7 @@ int wc_MlKemKey_Decapsulate(MlKemKey* key, unsigned char* ss,
15271530 if (ret == 0 ) {
15281531 /* Set secret to kr or fake secret on comparison failure. */
15291532 for (i = 0 ; i < WC_ML_KEM_SYM_SZ ; i ++ ) {
1530- ss [i ] = kr [i ] ^ ((kr [i ] ^ msg [i ]) & fail );
1533+ ss [i ] = ( byte )( kr [i ] ^ ((kr [i ] ^ msg [i ]) & fail ) );
15311534 }
15321535 }
15331536 }
@@ -1568,7 +1571,7 @@ static void mlkemkey_decode_public(sword16* pub, byte* pubSeed, const byte* p,
15681571
15691572 /* Decode public key that is vector of polynomials.
15701573 * Step 2: t <- ByteDecode_12(ek_PKE[0 : 384k]) */
1571- mlkem_from_bytes (pub , p , k );
1574+ mlkem_from_bytes (pub , p , ( int ) k );
15721575 p += k * WC_ML_KEM_POLY_SIZE ;
15731576
15741577 /* Read public key seed.
@@ -1684,7 +1687,7 @@ int wc_MlKemKey_DecodePrivateKey(MlKemKey* key, const unsigned char* in,
16841687 /* Decode private key that is vector of polynomials.
16851688 * Alg 18 Step 1: dk_PKE <- dk[0 : 384k]
16861689 * Alg 15 Step 5: s_hat <- ByteDecode_12(dk_PKE) */
1687- mlkem_from_bytes (key -> priv , p , k );
1690+ mlkem_from_bytes (key -> priv , p , ( int ) k );
16881691 p += k * WC_ML_KEM_POLY_SIZE ;
16891692
16901693 /* Decode the public key that is after the private key. */
@@ -1793,7 +1796,7 @@ int wc_MlKemKey_DecodePublicKey(MlKemKey* key, const unsigned char* in,
17931796
17941797 if (ret == 0 ) {
17951798 mlkemkey_decode_public (key -> pub , key -> pubSeed , p , k );
1796- ret = mlkem_check_public (key -> pub , k );
1799+ ret = mlkem_check_public (key -> pub , ( int ) k );
17971800 }
17981801 if (ret == 0 ) {
17991802 /* Calculate public hash. */
@@ -2038,7 +2041,7 @@ int wc_MlKemKey_EncodePrivateKey(MlKemKey* key, unsigned char* out, word32 len)
20382041
20392042 if (ret == 0 ) {
20402043 /* Encode private key that is vector of polynomials. */
2041- mlkem_to_bytes (p , key -> priv , k );
2044+ mlkem_to_bytes (p , key -> priv , ( int ) k );
20422045 p += WC_ML_KEM_POLY_SIZE * k ;
20432046
20442047 /* Encode public key. */
@@ -2155,7 +2158,7 @@ int wc_MlKemKey_EncodePublicKey(MlKemKey* key, unsigned char* out, word32 len)
21552158 int i ;
21562159
21572160 /* Encode public key polynomial by polynomial. */
2158- mlkem_to_bytes (p , key -> pub , k );
2161+ mlkem_to_bytes (p , key -> pub , ( int ) k );
21592162 p += k * WC_ML_KEM_POLY_SIZE ;
21602163
21612164 /* Append public seed. */
0 commit comments