kyber.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. /* kyber.c - the Kyber key encapsulation mechanism (main part)
  2. * Copyright (C) 2024 g10 Code GmbH
  3. *
  4. * This file was modified for use by Libgcrypt.
  5. *
  6. * This file is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as
  8. * published by the Free Software Foundation; either version 2.1 of
  9. * the License, or (at your option) any later version.
  10. *
  11. * This file is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this program; if not, see <https://www.gnu.org/licenses/>.
  18. * SPDX-License-Identifier: LGPL-2.1-or-later
  19. *
  20. * You can also use this file under the same licence of original code.
  21. * SPDX-License-Identifier: CC0 OR Apache-2.0
  22. *
  23. */
  24. /*
  25. Original code from:
  26. Repository: https://github.com/pq-crystals/kyber.git
  27. Branch: standard
  28. Commit: 11d00ff1f20cfca1f72d819e5a45165c1e0a2816
  29. Licence:
  30. Public Domain (https://creativecommons.org/share-your-work/public-domain/cc0/);
  31. or Apache 2.0 License (https://www.apache.org/licenses/LICENSE-2.0.html).
  32. Authors:
  33. Joppe Bos
  34. Léo Ducas
  35. Eike Kiltz
  36. Tancrède Lepoint
  37. Vadim Lyubashevsky
  38. John Schanck
  39. Peter Schwabe
  40. Gregor Seiler
  41. Damien Stehlé
  42. Kyber Home: https://www.pq-crystals.org/kyber/
  43. */
  44. /*
  45. * This implementation consists of four files: kyber.h (header),
  46. * kyber.c (this), kyber-common.c (common part), and kyber-kdep.c
  47. * (KYBER_K dependent part).
  48. *
  49. * It is for inclusion in libgcrypt library. Also, standalone use of
  50. * the implementation is possible. With KYBER_K defined, it can offer
  51. * the variant of that KYBER_K specified. Otherwise, three variants
  52. * are offered.
  53. *
  54. * From original code, following modification was made.
  55. *
  56. * - C++ style comments are changed to C-style.
  57. *
  58. * - No use of KYBER_NAMESPACE and FIPS202_NAMESPACE. Don't export
  59. * internal symbols.
  60. *
  61. * - "verify" routine is changed to return 1 on success, and now has
  62. * new name "verify1", so that the use of the routine won't need
  63. * negation (since negation might result non-constant-time code with
  64. * branch by some compiler).
  65. *
  66. * - For "xof" routines, definitions of xof_init and xof_close are
  67. * added, so that memory will be possible to be cleared after its
  68. * use.
  69. *
  70. * - Different external API for shake128, having _init and _close.
  71. *
  72. * - New implementation of kyber_shake128_absorb, with the shake128
  73. * API.
  74. *
  75. * - Added an external function: shake256v with variable arguments.
  76. *
  77. * - Macro definitions of xof_squeezeblocks, prf, and rkprf are
  78. * modified to use the shake128 API and the shake256v function.
  79. *
  80. */
  81. #ifdef HAVE_CONFIG_H
  82. #include <config.h>
  83. #endif
  84. #include <stddef.h>
  85. #include <stdint.h>
  86. #include <string.h>
  87. #ifdef _GCRYPT_IN_LIBGCRYPT
  88. #include <stdarg.h>
  89. #include <gpg-error.h>
  90. #include "types.h"
  91. #include "g10lib.h"
  92. #include "gcrypt-int.h"
  93. #include "const-time.h"
  94. #include "kyber.h"
  95. static int crypto_kem_keypair_2(uint8_t *pk, uint8_t *sk);
  96. static int crypto_kem_keypair_3(uint8_t *pk, uint8_t *sk);
  97. static int crypto_kem_keypair_4(uint8_t *pk, uint8_t *sk);
  98. static int crypto_kem_enc_2(uint8_t *ct, uint8_t *ss, const uint8_t *pk);
  99. static int crypto_kem_enc_3(uint8_t *ct, uint8_t *ss, const uint8_t *pk);
  100. static int crypto_kem_enc_4(uint8_t *ct, uint8_t *ss, const uint8_t *pk);
  101. static int crypto_kem_dec_2(uint8_t *ss, const uint8_t *ct, const uint8_t *sk);
  102. static int crypto_kem_dec_3(uint8_t *ss, const uint8_t *ct, const uint8_t *sk);
  103. static int crypto_kem_dec_4(uint8_t *ss, const uint8_t *ct, const uint8_t *sk);
  104. void
  105. kyber_keypair (int algo, uint8_t *pk, uint8_t *sk)
  106. {
  107. switch (algo)
  108. {
  109. case GCRY_KEM_MLKEM512:
  110. crypto_kem_keypair_2 (pk, sk);
  111. break;
  112. case GCRY_KEM_MLKEM768:
  113. default:
  114. crypto_kem_keypair_3 (pk, sk);
  115. break;
  116. case GCRY_KEM_MLKEM1024:
  117. crypto_kem_keypair_4 (pk, sk);
  118. break;
  119. }
  120. }
  121. void
  122. kyber_encap (int algo, uint8_t *ct, uint8_t *ss, const uint8_t *pk)
  123. {
  124. switch (algo)
  125. {
  126. case GCRY_KEM_MLKEM512:
  127. crypto_kem_enc_2 (ct, ss, pk);
  128. break;
  129. case GCRY_KEM_MLKEM768:
  130. default:
  131. crypto_kem_enc_3 (ct, ss, pk);
  132. break;
  133. case GCRY_KEM_MLKEM1024:
  134. crypto_kem_enc_4 (ct, ss, pk);
  135. break;
  136. }
  137. }
  138. void
  139. kyber_decap (int algo, uint8_t *ss, const uint8_t *ct, const uint8_t *sk)
  140. {
  141. switch (algo)
  142. {
  143. case GCRY_KEM_MLKEM512:
  144. crypto_kem_dec_2 (ss, ct, sk);
  145. break;
  146. case GCRY_KEM_MLKEM768:
  147. default:
  148. crypto_kem_dec_3 (ss, ct, sk);
  149. break;
  150. case GCRY_KEM_MLKEM1024:
  151. crypto_kem_dec_4 (ss, ct, sk);
  152. break;
  153. }
  154. }
  155. static void
  156. randombytes (uint8_t *out, size_t outlen)
  157. {
  158. _gcry_randomize (out, outlen, GCRY_VERY_STRONG_RANDOM);
  159. }
  160. typedef struct {
  161. gcry_md_hd_t h;
  162. } keccak_state;
  163. static void
  164. shake128_init (keccak_state *state)
  165. {
  166. gcry_err_code_t ec;
  167. ec = _gcry_md_open (&state->h, GCRY_MD_SHAKE128, 0);
  168. if (ec)
  169. log_fatal ("internal md_open failed: %d\n", ec);
  170. }
  171. static void
  172. shake128_absorb (keccak_state *state, const uint8_t *in, size_t inlen)
  173. {
  174. _gcry_md_write (state->h, in, inlen);
  175. }
  176. static void
  177. shake128_finalize (keccak_state *state)
  178. {
  179. (void)state;
  180. }
  181. static void
  182. shake128_squeeze (keccak_state *state, uint8_t *out, size_t outlen)
  183. {
  184. _gcry_md_extract (state->h, GCRY_MD_SHAKE128, out, outlen);
  185. }
  186. static void
  187. shake128_close (keccak_state *state)
  188. {
  189. _gcry_md_close (state->h);
  190. }
  191. #define MAX_ARGS 16
  192. static void
  193. shake256v (uint8_t *out, size_t outlen, ...)
  194. {
  195. gcry_buffer_t iov[MAX_ARGS];
  196. va_list ap;
  197. int i;
  198. void *p;
  199. size_t len;
  200. va_start (ap, outlen);
  201. for (i = 0; i < MAX_ARGS; i++)
  202. {
  203. p = va_arg (ap, void *);
  204. len = va_arg (ap, size_t);
  205. if (!p)
  206. break;
  207. iov[i].size = 0;
  208. iov[i].data = p;
  209. iov[i].off = 0;
  210. iov[i].len = len;
  211. }
  212. va_end (ap);
  213. _gcry_md_hash_buffers_extract (GCRY_MD_SHAKE256, 0, out, outlen,
  214. iov, i);
  215. }
  216. static void
  217. sha3_256 (uint8_t h[32], const uint8_t *in, size_t inlen)
  218. {
  219. _gcry_md_hash_buffer (GCRY_MD_SHA3_256, h, in, inlen);
  220. }
  221. static void
  222. sha3_512 (uint8_t h[64], const uint8_t *in, size_t inlen)
  223. {
  224. _gcry_md_hash_buffer (GCRY_MD_SHA3_512, h, in, inlen);
  225. }
  226. #define verify1 ct_memequal
  227. #define cmov ct_memmov_cond
  228. #else
  229. #include "kyber.h"
  230. void randombytes (uint8_t *out, size_t outlen);
  231. typedef struct {
  232. uint64_t s[25];
  233. unsigned int pos;
  234. } keccak_state;
  235. void shake128_init (keccak_state *state);
  236. void shake128_absorb (keccak_state *state, const uint8_t *in, size_t inlen);
  237. void shake128_finalize (keccak_state *state);
  238. void shake128_squeeze (keccak_state *state, uint8_t *out, size_t outlen);
  239. void shake128_close (keccak_state *state);
  240. void shake256v (uint8_t *out, size_t outlen, ...);
  241. void sha3_256 (uint8_t h[32], const uint8_t *in, size_t inlen);
  242. void sha3_512 (uint8_t h[64], const uint8_t *in, size_t inlen);
  243. /* Return 1 when success, 0 otherwise. */
  244. unsigned int verify1 (const uint8_t *a, const uint8_t *b, size_t len);
  245. /* Conditional move. */
  246. void cmov (uint8_t *r, const uint8_t *x, size_t len, uint8_t b);
  247. #endif
  248. /*************** kyber/ref/fips202.h */
  249. #define SHAKE128_RATE 168
  250. /*************** kyber/ref/params.h */
  251. #define KYBER_N 256
  252. #define KYBER_Q 3329
  253. #define KYBER_SYMBYTES 32 /* size in bytes of hashes, and seeds */
  254. #define KYBER_SSBYTES 32 /* size in bytes of shared key */
  255. #define KYBER_POLYBYTES 384
  256. #define KYBER_ETA2 2
  257. #define KYBER_INDCPA_MSGBYTES (KYBER_SYMBYTES)
  258. /* KYBER_K dependent values (part 1) */
  259. #define KYBER_ETA1_2 3
  260. #define KYBER_ETA1_3_4 2
  261. #define KYBER_POLYCOMPRESSEDBYTES_2_3 128
  262. #define KYBER_POLYCOMPRESSEDBYTES_4 160
  263. /*************** kyber/ref/poly.h */
  264. /*
  265. * Elements of R_q = Z_q[X]/(X^n + 1). Represents polynomial
  266. * coeffs[0] + X*coeffs[1] + X^2*coeffs[2] + ... + X^{n-1}*coeffs[n-1]
  267. */
  268. typedef struct{
  269. int16_t coeffs[KYBER_N];
  270. } poly;
  271. #if !defined(KYBER_K) || KYBER_K == 2 || KYBER_K == 3
  272. static void poly_compress_128(uint8_t r[KYBER_POLYCOMPRESSEDBYTES_2_3], const poly *a);
  273. static void poly_decompress_128(poly *r, const uint8_t a[KYBER_POLYCOMPRESSEDBYTES_2_3]);
  274. #endif
  275. #if !defined(KYBER_K) || KYBER_K == 4
  276. static void poly_compress_160(uint8_t r[KYBER_POLYCOMPRESSEDBYTES_4], const poly *a);
  277. static void poly_decompress_160(poly *r, const uint8_t a[KYBER_POLYCOMPRESSEDBYTES_4]);
  278. #endif
  279. static void poly_tobytes(uint8_t r[KYBER_POLYBYTES], const poly *a);
  280. static void poly_frombytes(poly *r, const uint8_t a[KYBER_POLYBYTES]);
  281. static void poly_frommsg(poly *r, const uint8_t msg[KYBER_INDCPA_MSGBYTES]);
  282. static void poly_tomsg(uint8_t msg[KYBER_INDCPA_MSGBYTES], const poly *r);
  283. #if !defined(KYBER_K) || KYBER_K == 2
  284. static void poly_getnoise_eta1_2(poly *r, const uint8_t seed[KYBER_SYMBYTES], uint8_t nonce);
  285. #endif
  286. #if !defined(KYBER_K) || KYBER_K == 3 || KYBER_K == 4
  287. static void poly_getnoise_eta1_3_4(poly *r, const uint8_t seed[KYBER_SYMBYTES], uint8_t nonce);
  288. #endif
  289. static void poly_getnoise_eta2(poly *r, const uint8_t seed[KYBER_SYMBYTES], uint8_t nonce);
  290. static void poly_ntt(poly *r);
  291. static void poly_invntt_tomont(poly *r);
  292. static void poly_basemul_montgomery(poly *r, const poly *a, const poly *b);
  293. static void poly_tomont(poly *r);
  294. static void poly_reduce(poly *r);
  295. static void poly_add(poly *r, const poly *a, const poly *b);
  296. static void poly_sub(poly *r, const poly *a, const poly *b);
  297. /*************** kyber/ref/ntt.h */
  298. static const int16_t zetas[128];
  299. static void ntt(int16_t poly[256]);
  300. static void invntt(int16_t poly[256]);
  301. static void basemul(int16_t r[2], const int16_t a[2], const int16_t b[2], int16_t zeta);
  302. /*************** kyber/ref/reduce.h */
  303. #define MONT -1044 /* 2^16 mod q */
  304. #define QINV -3327 /* q^-1 mod 2^16 */
  305. static int16_t montgomery_reduce(int32_t a);
  306. static int16_t barrett_reduce(int16_t a);
  307. /*************** kyber/ref/symmetric.h */
  308. typedef keccak_state xof_state;
  309. static void kyber_shake128_absorb (keccak_state *state,
  310. const uint8_t seed[KYBER_SYMBYTES],
  311. uint8_t x, uint8_t y)
  312. {
  313. shake128_absorb (state, seed, KYBER_SYMBYTES);
  314. shake128_absorb (state, &x, 1);
  315. shake128_absorb (state, &y, 1);
  316. shake128_finalize (state);
  317. }
  318. #define XOF_BLOCKBYTES SHAKE128_RATE
  319. #define hash_h(OUT, IN, INBYTES) sha3_256(OUT, IN, INBYTES)
  320. #define hash_g(OUT, IN, INBYTES) sha3_512(OUT, IN, INBYTES)
  321. #define xof_init(STATE) shake128_init(STATE)
  322. #define xof_close(STATE) shake128_close(STATE)
  323. #define xof_absorb(STATE, SEED, X, Y) kyber_shake128_absorb(STATE, SEED, X, Y)
  324. #define xof_squeezeblocks(OUT, OUTBLOCKS, STATE) shake128_squeeze(STATE, OUT, SHAKE128_RATE * OUTBLOCKS)
  325. #define prf(OUT, OUTBYTES, KEY, NONCE) \
  326. shake256v(OUT, OUTBYTES, (void *)(KEY), (size_t)KYBER_SYMBYTES, \
  327. (void *)&(NONCE), (size_t)1, \
  328. NULL, (size_t)0)
  329. #define rkprf(OUT, KEY, INPUT) \
  330. shake256v(OUT, KYBER_SSBYTES, (void *)(KEY), (size_t)KYBER_SYMBYTES, \
  331. (void *)(INPUT), (size_t)KYBER_CIPHERTEXTBYTES, \
  332. NULL, (size_t)0)
  333. #include "kyber-common.c"
  334. #define VARIANT2(name) name ## _2
  335. #define VARIANT3(name) name ## _3
  336. #define VARIANT4(name) name ## _4
  337. /* KYBER_K dependent values (part 2) */
  338. #define KYBER_POLYVECBYTES (KYBER_K * KYBER_POLYBYTES)
  339. #define KYBER_INDCPA_PUBLICKEYBYTES (KYBER_POLYVECBYTES + KYBER_SYMBYTES)
  340. #define KYBER_INDCPA_SECRETKEYBYTES (KYBER_POLYVECBYTES)
  341. #define KYBER_INDCPA_BYTES (KYBER_POLYVECCOMPRESSEDBYTES + KYBER_POLYCOMPRESSEDBYTES)
  342. #define KYBER_PUBLICKEYBYTES (KYBER_INDCPA_PUBLICKEYBYTES)
  343. /* 32 bytes of additional space to save H(pk) */
  344. #define KYBER_SECRETKEYBYTES (KYBER_INDCPA_SECRETKEYBYTES + KYBER_INDCPA_PUBLICKEYBYTES + 2*KYBER_SYMBYTES)
  345. #define KYBER_CIPHERTEXTBYTES (KYBER_INDCPA_BYTES)
  346. #ifdef KYBER_K
  347. # if KYBER_K == 2
  348. # define KYBER_POLYCOMPRESSEDBYTES 128
  349. # define KYBER_POLYVECCOMPRESSEDBYTES (KYBER_K * 320)
  350. # define poly_compress poly_compress_128
  351. # define poly_decompress poly_decompress_128
  352. # define poly_getnoise_eta1 poly_getnoise_eta1_2
  353. # elif KYBER_K == 3
  354. # define KYBER_POLYCOMPRESSEDBYTES 128
  355. # define KYBER_POLYVECCOMPRESSEDBYTES (KYBER_K * 320)
  356. # define poly_compress poly_compress_128
  357. # define poly_decompress poly_decompress_128
  358. # define poly_getnoise_eta1 poly_getnoise_eta1_3_4
  359. # elif KYBER_K == 4
  360. # define KYBER_POLYCOMPRESSEDBYTES 160
  361. # define KYBER_POLYVECCOMPRESSEDBYTES (KYBER_K * 352)
  362. # define poly_compress poly_compress_160
  363. # define poly_decompress poly_decompress_160
  364. # define poly_getnoise_eta1 poly_getnoise_eta1_3_4
  365. # endif
  366. # include "kyber-kdep.c"
  367. # else
  368. # define KYBER_K 2
  369. # define KYBER_POLYCOMPRESSEDBYTES 128
  370. # define KYBER_POLYVECCOMPRESSEDBYTES (KYBER_K * 320)
  371. # define poly_compress poly_compress_128
  372. # define poly_decompress poly_decompress_128
  373. # define poly_getnoise_eta1 poly_getnoise_eta1_2
  374. # define crypto_kem_keypair_derand VARIANT2(crypto_kem_keypair_derand)
  375. # define crypto_kem_enc_derand VARIANT2(crypto_kem_enc_derand)
  376. # define crypto_kem_keypair VARIANT2(crypto_kem_keypair)
  377. # define crypto_kem_enc VARIANT2(crypto_kem_enc)
  378. # define crypto_kem_dec VARIANT2(crypto_kem_dec)
  379. # define polyvec VARIANT2(polyvec)
  380. # define polyvec_compress VARIANT2(polyvec_compress)
  381. # define polyvec_decompress VARIANT2(polyvec_decompress)
  382. # define polyvec_tobytes VARIANT2(polyvec_tobytes)
  383. # define polyvec_frombytes VARIANT2(polyvec_frombytes)
  384. # define polyvec_ntt VARIANT2(polyvec_ntt)
  385. # define polyvec_invntt_tomont VARIANT2(polyvec_invntt_tomont)
  386. # define polyvec_basemul_acc_montgomery VARIANT2(polyvec_basemul_acc_montgomery)
  387. # define polyvec_reduce VARIANT2(polyvec_reduce)
  388. # define polyvec_add VARIANT2(polyvec_add)
  389. # define pack_pk VARIANT2(pack_pk)
  390. # define unpack_pk VARIANT2(unpack_pk)
  391. # define pack_sk VARIANT2(pack_sk)
  392. # define unpack_sk VARIANT2(unpack_sk)
  393. # define pack_ciphertext VARIANT2(pack_ciphertext)
  394. # define unpack_ciphertext VARIANT2(unpack_ciphertext)
  395. # define gen_matrix VARIANT2(gen_matrix)
  396. # define indcpa_keypair_derand VARIANT2(indcpa_keypair_derand)
  397. # define indcpa_enc VARIANT2(indcpa_enc)
  398. # define indcpa_dec VARIANT2(indcpa_dec)
  399. # include "kyber-kdep.c"
  400. # define KYBER_K 3
  401. # define KYBER_POLYCOMPRESSEDBYTES 128
  402. # define KYBER_POLYVECCOMPRESSEDBYTES (KYBER_K * 320)
  403. # define poly_compress poly_compress_128
  404. # define poly_decompress poly_decompress_128
  405. # define poly_getnoise_eta1 poly_getnoise_eta1_3_4
  406. # define crypto_kem_keypair_derand VARIANT3(crypto_kem_keypair_derand)
  407. # define crypto_kem_enc_derand VARIANT3(crypto_kem_enc_derand)
  408. # define crypto_kem_keypair VARIANT3(crypto_kem_keypair)
  409. # define crypto_kem_enc VARIANT3(crypto_kem_enc)
  410. # define crypto_kem_dec VARIANT3(crypto_kem_dec)
  411. # define polyvec VARIANT3(polyvec)
  412. # define polyvec_compress VARIANT3(polyvec_compress)
  413. # define polyvec_decompress VARIANT3(polyvec_decompress)
  414. # define polyvec_tobytes VARIANT3(polyvec_tobytes)
  415. # define polyvec_frombytes VARIANT3(polyvec_frombytes)
  416. # define polyvec_ntt VARIANT3(polyvec_ntt)
  417. # define polyvec_invntt_tomont VARIANT3(polyvec_invntt_tomont)
  418. # define polyvec_basemul_acc_montgomery VARIANT3(polyvec_basemul_acc_montgomery)
  419. # define polyvec_reduce VARIANT3(polyvec_reduce)
  420. # define polyvec_add VARIANT3(polyvec_add)
  421. # define pack_pk VARIANT3(pack_pk)
  422. # define unpack_pk VARIANT3(unpack_pk)
  423. # define pack_sk VARIANT3(pack_sk)
  424. # define unpack_sk VARIANT3(unpack_sk)
  425. # define pack_ciphertext VARIANT3(pack_ciphertext)
  426. # define unpack_ciphertext VARIANT3(unpack_ciphertext)
  427. # define gen_matrix VARIANT3(gen_matrix)
  428. # define indcpa_keypair_derand VARIANT3(indcpa_keypair_derand)
  429. # define indcpa_enc VARIANT3(indcpa_enc)
  430. # define indcpa_dec VARIANT3(indcpa_dec)
  431. # include "kyber-kdep.c"
  432. # define KYBER_K 4
  433. # define KYBER_POLYCOMPRESSEDBYTES 160
  434. # define KYBER_POLYVECCOMPRESSEDBYTES (KYBER_K * 352)
  435. # define poly_compress poly_compress_160
  436. # define poly_decompress poly_decompress_160
  437. # define poly_getnoise_eta1 poly_getnoise_eta1_3_4
  438. # define crypto_kem_keypair_derand VARIANT4(crypto_kem_keypair_derand)
  439. # define crypto_kem_enc_derand VARIANT4(crypto_kem_enc_derand)
  440. # define crypto_kem_keypair VARIANT4(crypto_kem_keypair)
  441. # define crypto_kem_enc VARIANT4(crypto_kem_enc)
  442. # define crypto_kem_dec VARIANT4(crypto_kem_dec)
  443. # define polyvec VARIANT4(polyvec)
  444. # define polyvec_compress VARIANT4(polyvec_compress)
  445. # define polyvec_decompress VARIANT4(polyvec_decompress)
  446. # define polyvec_tobytes VARIANT4(polyvec_tobytes)
  447. # define polyvec_frombytes VARIANT4(polyvec_frombytes)
  448. # define polyvec_ntt VARIANT4(polyvec_ntt)
  449. # define polyvec_invntt_tomont VARIANT4(polyvec_invntt_tomont)
  450. # define polyvec_basemul_acc_montgomery VARIANT4(polyvec_basemul_acc_montgomery)
  451. # define polyvec_reduce VARIANT4(polyvec_reduce)
  452. # define polyvec_add VARIANT4(polyvec_add)
  453. # define pack_pk VARIANT4(pack_pk)
  454. # define unpack_pk VARIANT4(unpack_pk)
  455. # define pack_sk VARIANT4(pack_sk)
  456. # define unpack_sk VARIANT4(unpack_sk)
  457. # define pack_ciphertext VARIANT4(pack_ciphertext)
  458. # define unpack_ciphertext VARIANT4(unpack_ciphertext)
  459. # define gen_matrix VARIANT4(gen_matrix)
  460. # define indcpa_keypair_derand VARIANT4(indcpa_keypair_derand)
  461. # define indcpa_enc VARIANT4(indcpa_enc)
  462. # define indcpa_dec VARIANT4(indcpa_dec)
  463. # include "kyber-kdep.c"
  464. #endif