Skip to content

Commit 66662bc

Browse files
committed
ML-KEM/Kyber: mlkem_encapsulate not to return a value
Don't return a value from mlkem_encapsulate() to ensure code is just the maths.
1 parent 0cc0bb0 commit 66662bc

File tree

3 files changed

+6
-11
lines changed

3 files changed

+6
-11
lines changed

wolfcrypt/src/wc_mlkem.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ static int mlkemkey_encapsulate(MlKemKey* key, const byte* m, byte* r, byte* c)
788788

789789
/* Perform encapsulation maths.
790790
* Steps 18-19, 21: calculate u and v */
791-
ret = mlkem_encapsulate(key->pub, u, v, a, y, e1, e2, mu, k);
791+
mlkem_encapsulate(key->pub, u, v, a, y, e1, e2, mu, k);
792792
}
793793
#else /* WOLFSSL_MLKEM_ENCAPSULATE_SMALL_MEM */
794794
if (ret == 0) {

wolfcrypt/src/wc_mlkem_poly.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,7 +1348,7 @@ void mlkem_keygen(sword16* s, sword16* t, sword16* e, const sword16* a, int k)
13481348
* @return 0 on success.
13491349
*
13501350
*/
1351-
int mlkem_encapsulate(const sword16* t, sword16* u , sword16* v,
1351+
void mlkem_encapsulate(const sword16* t, sword16* u , sword16* v,
13521352
const sword16* a, sword16* y, const sword16* e1, const sword16* e2,
13531353
const sword16* m, int k)
13541354
{
@@ -1418,8 +1418,6 @@ int mlkem_encapsulate(const sword16* t, sword16* u , sword16* v,
14181418
/* Add errors and message to v and reduce.
14191419
* Step 21: v <- InvNTT(t_hat_trans o y_hat) + e_2 + mu) */
14201420
mlkem_add3_reduce(v, e2, m);
1421-
1422-
return 0;
14231421
}
14241422
#endif /* !WOLFSSL_MLKEM_NO_ENCAPSULATE || !WOLFSSL_MLKEM_NO_DECAPSULATE */
14251423

@@ -1666,7 +1664,7 @@ int mlkem_keygen_seeds(sword16* s, sword16* t, MLKEM_PRF_T* prf,
16661664
* @param [in] k Number of polynomials in vector.
16671665
* @return 0 on success.
16681666
*/
1669-
static int mlkem_encapsulate_c(const sword16* pub, sword16* u, sword16* v,
1667+
static void mlkem_encapsulate_c(const sword16* pub, sword16* u, sword16* v,
16701668
const sword16* a, sword16* y, const sword16* e1, const sword16* e2,
16711669
const sword16* m, int k)
16721670
{
@@ -1701,8 +1699,6 @@ static int mlkem_encapsulate_c(const sword16* pub, sword16* u, sword16* v,
17011699
sword16 t = v[i] + e2[i] + m[i];
17021700
v[i] = MLKEM_BARRETT_RED(t);
17031701
}
1704-
1705-
return 0;
17061702
}
17071703

17081704
/* Encapsulate message.
@@ -1718,20 +1714,19 @@ static int mlkem_encapsulate_c(const sword16* pub, sword16* u, sword16* v,
17181714
* @param [in] k Number of polynomials in vector.
17191715
* @return 0 on success.
17201716
*/
1721-
int mlkem_encapsulate(const sword16* pub, sword16* u, sword16* v,
1717+
void mlkem_encapsulate(const sword16* pub, sword16* u, sword16* v,
17221718
const sword16* a, sword16* y, const sword16* e1, const sword16* e2,
17231719
const sword16* m, int k)
17241720
{
17251721
#ifdef USE_INTEL_SPEEDUP
17261722
if (IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) {
17271723
mlkem_encapsulate_avx2(pub, u, v, a, y, e1, e2, m, k);
17281724
RESTORE_VECTOR_REGISTERS();
1729-
return 0;
17301725
}
17311726
else
17321727
#endif
17331728
{
1734-
return mlkem_encapsulate_c(pub, u, v, a, y, e1, e2, m, k);
1729+
mlkem_encapsulate_c(pub, u, v, a, y, e1, e2, m, k);
17351730
}
17361731
}
17371732

wolfssl/wolfcrypt/wc_mlkem.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ int mlkem_keygen_seeds(sword16* priv, sword16* pub, MLKEM_PRF_T* prf,
163163
#endif
164164
#ifndef WOLFSSL_MLKEM_ENCAPSULATE_SMALL_MEM
165165
WOLFSSL_LOCAL
166-
int mlkem_encapsulate(const sword16* pub, sword16* bp, sword16* v,
166+
void mlkem_encapsulate(const sword16* pub, sword16* bp, sword16* v,
167167
const sword16* at, sword16* sp, const sword16* ep, const sword16* epp,
168168
const sword16* m, int kp);
169169
#else

0 commit comments

Comments
 (0)