@@ -367,6 +367,7 @@ int wc_MlKemKey_Free(MlKemKey* key)
367367 */
368368int wc_MlKemKey_MakeKey (MlKemKey * key , WC_RNG * rng )
369369{
370+ #ifndef WC_NO_RNG
370371 int ret = 0 ;
371372 unsigned char rand [WC_ML_KEM_MAKEKEY_RAND_SZ ];
372373
@@ -396,6 +397,11 @@ int wc_MlKemKey_MakeKey(MlKemKey* key, WC_RNG* rng)
396397
397398 /* Step 4: return ret != 0 on falsum or internal key generation failure. */
398399 return ret ;
400+ #else
401+ (void )key ;
402+ (void )rng ;
403+ return NOT_COMPILED_IN ;
404+ #endif /* WC_NO_RNG */
399405}
400406
401407/**
@@ -519,16 +525,16 @@ int wc_MlKemKey_MakeKeyWithRandom(MlKemKey* key, const unsigned char* rand,
519525#ifndef WOLFSSL_MLKEM_MAKEKEY_SMALL_MEM
520526#ifndef WOLFSSL_MLKEM_CACHE_A
521527 /* e (v) | a (m) */
522- e = (sword16 * )XMALLOC ((k + 1 ) * k * MLKEM_N * sizeof (sword16 ),
528+ e = (sword16 * )XMALLOC ((size_t )(( k + 1 ) * k * MLKEM_N ) * sizeof (sword16 ),
523529 key -> heap , DYNAMIC_TYPE_TMP_BUFFER );
524530#else
525531 /* e (v) */
526- e = (sword16 * )XMALLOC (k * MLKEM_N * sizeof (sword16 ),
532+ e = (sword16 * )XMALLOC (( size_t )( k * MLKEM_N ) * sizeof (sword16 ),
527533 key -> heap , DYNAMIC_TYPE_TMP_BUFFER );
528534#endif
529535#else
530536 /* e (v) */
531- e = (sword16 * )XMALLOC (k * MLKEM_N * sizeof (sword16 ),
537+ e = (sword16 * )XMALLOC (( size_t )( k * MLKEM_N ) * sizeof (sword16 ),
532538 key -> heap , DYNAMIC_TYPE_TMP_BUFFER );
533539#endif
534540 if (e == NULL ) {
@@ -560,7 +566,7 @@ int wc_MlKemKey_MakeKeyWithRandom(MlKemKey* key, const unsigned char* rand,
560566#endif
561567#ifndef WOLFSSL_NO_ML_KEM
562568 {
563- buf [0 ] = k ;
569+ buf [0 ] = ( byte ) k ;
564570 /* Expand 33 bytes of random to 64.
565571 * Alg 13: Step 1: (rho,sigma) <- G(d||k)
566572 */
@@ -871,7 +877,7 @@ static int mlkemkey_encapsulate(MlKemKey* key, const byte* m, byte* r, byte* c)
871877 /* Generate noise using PRF.
872878 * Steps 9-17: generate y, e_1, e_2
873879 */
874- ret = mlkem_get_noise (& key -> prf , k , y , e1 , e2 , r );
880+ ret = mlkem_get_noise (& key -> prf , ( int ) k , y , e1 , e2 , r );
875881 }
876882 #ifdef WOLFSSL_MLKEM_CACHE_A
877883 if ((ret == 0 ) && ((key -> flags & MLKEM_FLAG_A_SET ) != 0 )) {
@@ -892,7 +898,7 @@ static int mlkemkey_encapsulate(MlKemKey* key, const byte* m, byte* r, byte* c)
892898 if (ret == 0 ) {
893899 /* Generate the transposed matrix.
894900 * Step 4-8: generate matrix A_hat */
895- ret = mlkem_gen_matrix (& key -> prf , a , k , key -> pubSeed , 1 );
901+ ret = mlkem_gen_matrix (& key -> prf , a , ( int ) k , key -> pubSeed , 1 );
896902 }
897903 if (ret == 0 ) {
898904 /* Assign remaining allocated dynamic memory to pointers.
@@ -902,7 +908,7 @@ static int mlkemkey_encapsulate(MlKemKey* key, const byte* m, byte* r, byte* c)
902908
903909 /* Perform encapsulation maths.
904910 * Steps 18-19, 21: calculate u and v */
905- mlkem_encapsulate (key -> pub , u , v , a , y , e1 , e2 , mu , k );
911+ mlkem_encapsulate (key -> pub , u , v , a , y , e1 , e2 , mu , ( int ) k );
906912 }
907913#else /* WOLFSSL_MLKEM_ENCAPSULATE_SMALL_MEM */
908914 if (ret == 0 ) {
@@ -914,7 +920,7 @@ static int mlkemkey_encapsulate(MlKemKey* key, const byte* m, byte* r, byte* c)
914920 mlkem_prf_init (& key -> prf );
915921 /* Generate noise using PRF.
916922 * Steps 9-12: generate y */
917- ret = mlkem_get_noise (& key -> prf , k , y , NULL , NULL , r );
923+ ret = mlkem_get_noise (& key -> prf , ( int ) k , y , NULL , NULL , r );
918924 }
919925 if (ret == 0 ) {
920926 /* Assign remaining allocated dynamic memory to pointers.
@@ -925,7 +931,7 @@ static int mlkemkey_encapsulate(MlKemKey* key, const byte* m, byte* r, byte* c)
925931 /* Perform encapsulation maths.
926932 * Steps 13-17: generate e_1 and e_2
927933 * Steps 18-19, 21: calculate u and v */
928- ret = mlkem_encapsulate_seeds (key -> pub , & key -> prf , u , a , y , k , m ,
934+ ret = mlkem_encapsulate_seeds (key -> pub , & key -> prf , u , a , y , ( int ) k , m ,
929935 key -> pubSeed , r );
930936 }
931937#endif /* WOLFSSL_MLKEM_ENCAPSULATE_SMALL_MEM */
@@ -1048,6 +1054,7 @@ static int wc_mlkemkey_check_h(MlKemKey* key)
10481054int wc_MlKemKey_Encapsulate (MlKemKey * key , unsigned char * c , unsigned char * k ,
10491055 WC_RNG * rng )
10501056{
1057+ #ifndef WC_NO_RNG
10511058 int ret = 0 ;
10521059 unsigned char m [WC_ML_KEM_ENC_RAND_SZ ];
10531060
@@ -1072,6 +1079,13 @@ int wc_MlKemKey_Encapsulate(MlKemKey* key, unsigned char* c, unsigned char* k,
10721079
10731080 /* Step 3: return ret != 0 on falsum or internal key generation failure. */
10741081 return ret ;
1082+ #else
1083+ (void )key ;
1084+ (void )c ;
1085+ (void )k ;
1086+ (void )rng ;
1087+ return NOT_COMPILED_IN ;
1088+ #endif /* WC_NO_RNG */
10751089}
10761090
10771091/**
@@ -1382,7 +1396,7 @@ static MLKEM_NOINLINE int mlkemkey_decapsulate(MlKemKey* key, byte* m,
13821396
13831397 /* Decapsulate the cipher text into polynomial.
13841398 * Step 6: w <- v' - InvNTT(s_hat_trans o NTT(u')) */
1385- mlkem_decapsulate (key -> priv , w , u , v , k );
1399+ mlkem_decapsulate (key -> priv , w , u , v , ( int ) k );
13861400
13871401 /* Convert the polynomial into a array of bytes (message).
13881402 * Step 7: m <- ByteEncode_1(Compress_1(w)) */
@@ -1540,7 +1554,7 @@ int wc_MlKemKey_Decapsulate(MlKemKey* key, unsigned char* ss,
15401554 }
15411555 if (ret == 0 ) {
15421556 /* Compare generated cipher text with that passed in. */
1543- fail = mlkem_cmp (ct , cmp , ctSz );
1557+ fail = mlkem_cmp (ct , cmp , ( int ) ctSz );
15441558
15451559#if defined(WOLFSSL_MLKEM_KYBER ) && !defined(WOLFSSL_NO_ML_KEM )
15461560 if (key -> type & MLKEM_KYBER )
@@ -1569,7 +1583,7 @@ int wc_MlKemKey_Decapsulate(MlKemKey* key, unsigned char* ss,
15691583 if (ret == 0 ) {
15701584 /* Set secret to kr or fake secret on comparison failure. */
15711585 for (i = 0 ; i < WC_ML_KEM_SYM_SZ ; i ++ ) {
1572- ss [i ] = kr [i ] ^ ((kr [i ] ^ msg [i ]) & fail );
1586+ ss [i ] = ( byte )( kr [i ] ^ ((kr [i ] ^ msg [i ]) & fail ) );
15731587 }
15741588 }
15751589 }
@@ -1613,7 +1627,7 @@ static void mlkemkey_decode_public(sword16* pub, byte* pubSeed, const byte* p,
16131627
16141628 /* Decode public key that is vector of polynomials.
16151629 * Step 2: t <- ByteDecode_12(ek_PKE[0 : 384k]) */
1616- mlkem_from_bytes (pub , p , k );
1630+ mlkem_from_bytes (pub , p , ( int ) k );
16171631 p += k * WC_ML_KEM_POLY_SIZE ;
16181632
16191633 /* Read public key seed.
@@ -1729,7 +1743,7 @@ int wc_MlKemKey_DecodePrivateKey(MlKemKey* key, const unsigned char* in,
17291743 /* Decode private key that is vector of polynomials.
17301744 * Alg 18 Step 1: dk_PKE <- dk[0 : 384k]
17311745 * Alg 15 Step 5: s_hat <- ByteDecode_12(dk_PKE) */
1732- mlkem_from_bytes (key -> priv , p , k );
1746+ mlkem_from_bytes (key -> priv , p , ( int ) k );
17331747 p += k * WC_ML_KEM_POLY_SIZE ;
17341748
17351749 /* Decode the public key that is after the private key. */
@@ -1845,7 +1859,7 @@ int wc_MlKemKey_DecodePublicKey(MlKemKey* key, const unsigned char* in,
18451859
18461860 if (ret == 0 ) {
18471861 mlkemkey_decode_public (key -> pub , key -> pubSeed , p , k );
1848- ret = mlkem_check_public (key -> pub , k );
1862+ ret = mlkem_check_public (key -> pub , ( int ) k );
18491863 }
18501864 if (ret == 0 ) {
18511865 /* Calculate public hash. */
@@ -2090,7 +2104,7 @@ int wc_MlKemKey_EncodePrivateKey(MlKemKey* key, unsigned char* out, word32 len)
20902104
20912105 if (ret == 0 ) {
20922106 /* Encode private key that is vector of polynomials. */
2093- mlkem_to_bytes (p , key -> priv , k );
2107+ mlkem_to_bytes (p , key -> priv , ( int ) k );
20942108 p += WC_ML_KEM_POLY_SIZE * k ;
20952109
20962110 /* Encode public key. */
@@ -2207,7 +2221,7 @@ int wc_MlKemKey_EncodePublicKey(MlKemKey* key, unsigned char* out, word32 len)
22072221 int i ;
22082222
22092223 /* Encode public key polynomial by polynomial. */
2210- mlkem_to_bytes (p , key -> pub , k );
2224+ mlkem_to_bytes (p , key -> pub , ( int ) k );
22112225 p += k * WC_ML_KEM_POLY_SIZE ;
22122226
22132227 /* Append public seed. */
0 commit comments