@@ -368,6 +368,7 @@ int wc_MlKemKey_Free(MlKemKey* key)
368368 */
369369int wc_MlKemKey_MakeKey (MlKemKey * key , WC_RNG * rng )
370370{
371+ #ifndef WC_NO_RNG
371372 int ret = 0 ;
372373 unsigned char rand [WC_ML_KEM_MAKEKEY_RAND_SZ ];
373374
@@ -397,6 +398,11 @@ int wc_MlKemKey_MakeKey(MlKemKey* key, WC_RNG* rng)
397398
398399 /* Step 4: return ret != 0 on falsum or internal key generation failure. */
399400 return ret ;
401+ #else
402+ (void )key ;
403+ (void )rng ;
404+ return NOT_COMPILED_IN ;
405+ #endif /* WC_NO_RNG */
400406}
401407
402408/**
@@ -516,16 +522,16 @@ int wc_MlKemKey_MakeKeyWithRandom(MlKemKey* key, const unsigned char* rand,
516522#ifndef WOLFSSL_MLKEM_MAKEKEY_SMALL_MEM
517523#ifndef WOLFSSL_MLKEM_CACHE_A
518524 /* e (v) | a (m) */
519- e = (sword16 * )XMALLOC ((k + 1 ) * k * MLKEM_N * sizeof (sword16 ),
525+ e = (sword16 * )XMALLOC ((size_t )(( k + 1 ) * k * MLKEM_N ) * sizeof (sword16 ),
520526 key -> heap , DYNAMIC_TYPE_TMP_BUFFER );
521527#else
522528 /* e (v) */
523- e = (sword16 * )XMALLOC (k * MLKEM_N * sizeof (sword16 ),
529+ e = (sword16 * )XMALLOC (( size_t )( k * MLKEM_N ) * sizeof (sword16 ),
524530 key -> heap , DYNAMIC_TYPE_TMP_BUFFER );
525531#endif
526532#else
527533 /* e (v) */
528- e = (sword16 * )XMALLOC (k * MLKEM_N * sizeof (sword16 ),
534+ e = (sword16 * )XMALLOC (( size_t )( k * MLKEM_N ) * sizeof (sword16 ),
529535 key -> heap , DYNAMIC_TYPE_TMP_BUFFER );
530536#endif
531537 if (e == NULL ) {
@@ -557,7 +563,7 @@ int wc_MlKemKey_MakeKeyWithRandom(MlKemKey* key, const unsigned char* rand,
557563#endif
558564#ifndef WOLFSSL_NO_ML_KEM
559565 {
560- buf [0 ] = k ;
566+ buf [0 ] = ( byte ) k ;
561567 /* Expand 33 bytes of random to 32.
562568 * Alg 13: Step 1: (rho,sigma) <- G(d||k)
563569 */
@@ -849,7 +855,7 @@ static int mlkemkey_encapsulate(MlKemKey* key, const byte* m, byte* r, byte* c)
849855 /* Generate noise using PRF.
850856 * Steps 9-17: generate y, e_1, e_2
851857 */
852- ret = mlkem_get_noise (& key -> prf , k , y , e1 , e2 , r );
858+ ret = mlkem_get_noise (& key -> prf , ( int ) k , y , e1 , e2 , r );
853859 }
854860 #ifdef WOLFSSL_MLKEM_CACHE_A
855861 if ((ret == 0 ) && ((key -> flags & MLKEM_FLAG_A_SET ) != 0 )) {
@@ -870,7 +876,7 @@ static int mlkemkey_encapsulate(MlKemKey* key, const byte* m, byte* r, byte* c)
870876 if (ret == 0 ) {
871877 /* Generate the transposed matrix.
872878 * Step 4-8: generate matrix A_hat */
873- ret = mlkem_gen_matrix (& key -> prf , a , k , key -> pubSeed , 1 );
879+ ret = mlkem_gen_matrix (& key -> prf , a , ( int ) k , key -> pubSeed , 1 );
874880 }
875881 if (ret == 0 ) {
876882 /* Assign remaining allocated dynamic memory to pointers.
@@ -880,7 +886,7 @@ static int mlkemkey_encapsulate(MlKemKey* key, const byte* m, byte* r, byte* c)
880886
881887 /* Perform encapsulation maths.
882888 * Steps 18-19, 21: calculate u and v */
883- mlkem_encapsulate (key -> pub , u , v , a , y , e1 , e2 , mu , k );
889+ mlkem_encapsulate (key -> pub , u , v , a , y , e1 , e2 , mu , ( int ) k );
884890 }
885891#else /* WOLFSSL_MLKEM_ENCAPSULATE_SMALL_MEM */
886892 if (ret == 0 ) {
@@ -892,7 +898,7 @@ static int mlkemkey_encapsulate(MlKemKey* key, const byte* m, byte* r, byte* c)
892898 mlkem_prf_init (& key -> prf );
893899 /* Generate noise using PRF.
894900 * Steps 9-12: generate y */
895- ret = mlkem_get_noise (& key -> prf , k , y , NULL , NULL , r );
901+ ret = mlkem_get_noise (& key -> prf , ( int ) k , y , NULL , NULL , r );
896902 }
897903 if (ret == 0 ) {
898904 /* Assign remaining allocated dynamic memory to pointers.
@@ -903,7 +909,7 @@ static int mlkemkey_encapsulate(MlKemKey* key, const byte* m, byte* r, byte* c)
903909 /* Perform encapsulation maths.
904910 * Steps 13-17: generate e_1 and e_2
905911 * Steps 18-19, 21: calculate u and v */
906- ret = mlkem_encapsulate_seeds (key -> pub , & key -> prf , u , a , y , k , m ,
912+ ret = mlkem_encapsulate_seeds (key -> pub , & key -> prf , u , a , y , ( int ) k , m ,
907913 key -> pubSeed , r );
908914 }
909915#endif /* WOLFSSL_MLKEM_ENCAPSULATE_SMALL_MEM */
@@ -1026,6 +1032,7 @@ static int wc_mlkemkey_check_h(MlKemKey* key)
10261032int wc_MlKemKey_Encapsulate (MlKemKey * key , unsigned char * c , unsigned char * k ,
10271033 WC_RNG * rng )
10281034{
1035+ #ifndef WC_NO_RNG
10291036 int ret = 0 ;
10301037 unsigned char m [WC_ML_KEM_ENC_RAND_SZ ];
10311038
@@ -1050,6 +1057,13 @@ int wc_MlKemKey_Encapsulate(MlKemKey* key, unsigned char* c, unsigned char* k,
10501057
10511058 /* Step 3: return ret != 0 on falsum or internal key generation failure. */
10521059 return ret ;
1060+ #else
1061+ (void )key ;
1062+ (void )c ;
1063+ (void )k ;
1064+ (void )rng ;
1065+ return NOT_COMPILED_IN ;
1066+ #endif /* WC_NO_RNG */
10531067}
10541068
10551069/**
@@ -1360,7 +1374,7 @@ static MLKEM_NOINLINE int mlkemkey_decapsulate(MlKemKey* key, byte* m,
13601374
13611375 /* Decapsulate the cipher text into polynomial.
13621376 * Step 6: w <- v' - InvNTT(s_hat_trans o NTT(u')) */
1363- mlkem_decapsulate (key -> priv , w , u , v , k );
1377+ mlkem_decapsulate (key -> priv , w , u , v , ( int ) k );
13641378
13651379 /* Convert the polynomial into a array of bytes (message).
13661380 * Step 7: m <- ByteEncode_1(Compress_1(w)) */
@@ -1518,7 +1532,7 @@ int wc_MlKemKey_Decapsulate(MlKemKey* key, unsigned char* ss,
15181532 }
15191533 if (ret == 0 ) {
15201534 /* Compare generated cipher text with that passed in. */
1521- fail = mlkem_cmp (ct , cmp , ctSz );
1535+ fail = mlkem_cmp (ct , cmp , ( int ) ctSz );
15221536
15231537#if defined(WOLFSSL_MLKEM_KYBER ) && !defined(WOLFSSL_NO_ML_KEM )
15241538 if (key -> type & MLKEM_KYBER )
@@ -1547,7 +1561,7 @@ int wc_MlKemKey_Decapsulate(MlKemKey* key, unsigned char* ss,
15471561 if (ret == 0 ) {
15481562 /* Set secret to kr or fake secret on comparison failure. */
15491563 for (i = 0 ; i < WC_ML_KEM_SYM_SZ ; i ++ ) {
1550- ss [i ] = kr [i ] ^ ((kr [i ] ^ msg [i ]) & fail );
1564+ ss [i ] = ( byte )( kr [i ] ^ ((kr [i ] ^ msg [i ]) & fail ) );
15511565 }
15521566 }
15531567 }
@@ -1591,7 +1605,7 @@ static void mlkemkey_decode_public(sword16* pub, byte* pubSeed, const byte* p,
15911605
15921606 /* Decode public key that is vector of polynomials.
15931607 * Step 2: t <- ByteDecode_12(ek_PKE[0 : 384k]) */
1594- mlkem_from_bytes (pub , p , k );
1608+ mlkem_from_bytes (pub , p , ( int ) k );
15951609 p += k * WC_ML_KEM_POLY_SIZE ;
15961610
15971611 /* Read public key seed.
@@ -1707,7 +1721,7 @@ int wc_MlKemKey_DecodePrivateKey(MlKemKey* key, const unsigned char* in,
17071721 /* Decode private key that is vector of polynomials.
17081722 * Alg 18 Step 1: dk_PKE <- dk[0 : 384k]
17091723 * Alg 15 Step 5: s_hat <- ByteDecode_12(dk_PKE) */
1710- mlkem_from_bytes (key -> priv , p , k );
1724+ mlkem_from_bytes (key -> priv , p , ( int ) k );
17111725 p += k * WC_ML_KEM_POLY_SIZE ;
17121726
17131727 /* Decode the public key that is after the private key. */
@@ -1816,7 +1830,7 @@ int wc_MlKemKey_DecodePublicKey(MlKemKey* key, const unsigned char* in,
18161830
18171831 if (ret == 0 ) {
18181832 mlkemkey_decode_public (key -> pub , key -> pubSeed , p , k );
1819- ret = mlkem_check_public (key -> pub , k );
1833+ ret = mlkem_check_public (key -> pub , ( int ) k );
18201834 }
18211835 if (ret == 0 ) {
18221836 /* Calculate public hash. */
@@ -2061,7 +2075,7 @@ int wc_MlKemKey_EncodePrivateKey(MlKemKey* key, unsigned char* out, word32 len)
20612075
20622076 if (ret == 0 ) {
20632077 /* Encode private key that is vector of polynomials. */
2064- mlkem_to_bytes (p , key -> priv , k );
2078+ mlkem_to_bytes (p , key -> priv , ( int ) k );
20652079 p += WC_ML_KEM_POLY_SIZE * k ;
20662080
20672081 /* Encode public key. */
@@ -2178,7 +2192,7 @@ int wc_MlKemKey_EncodePublicKey(MlKemKey* key, unsigned char* out, word32 len)
21782192 int i ;
21792193
21802194 /* Encode public key polynomial by polynomial. */
2181- mlkem_to_bytes (p , key -> pub , k );
2195+ mlkem_to_bytes (p , key -> pub , ( int ) k );
21822196 p += k * WC_ML_KEM_POLY_SIZE ;
21832197
21842198 /* Append public seed. */
0 commit comments