ext_kyber.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  1. /* ext_kyber.c
  2. *
  3. * Copyright (C) 2006-2022 wolfSSL Inc.
  4. *
  5. * This file is part of wolfSSL.
  6. *
  7. * wolfSSL is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * wolfSSL is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  20. */
  21. #ifdef HAVE_CONFIG_H
  22. #include <config.h>
  23. #endif
  24. #include <wolfssl/wolfcrypt/settings.h>
  25. #include <wolfssl/wolfcrypt/error-crypt.h>
  26. #ifdef WOLFSSL_HAVE_KYBER
  27. #include <wolfssl/wolfcrypt/ext_kyber.h>
  28. #ifdef NO_INLINE
  29. #include <wolfssl/wolfcrypt/misc.h>
  30. #else
  31. #define WOLFSSL_MISC_INCLUDED
  32. #include <wolfcrypt/src/misc.c>
  33. #endif
  34. #if defined (HAVE_LIBOQS)
  35. static const char* OQS_ID2name(int id) {
  36. switch (id) {
  37. case KYBER_LEVEL1: return OQS_KEM_alg_kyber_512;
  38. case KYBER_LEVEL3: return OQS_KEM_alg_kyber_768;
  39. case KYBER_LEVEL5: return OQS_KEM_alg_kyber_1024;
  40. default: break;
  41. }
  42. return NULL;
  43. }
  44. int ext_kyber_enabled(int id)
  45. {
  46. const char * name = OQS_ID2name(id);
  47. return OQS_KEM_alg_is_enabled(name);
  48. }
  49. #endif
  50. /******************************************************************************/
  51. /* Initializer and cleanup functions. */
  52. /**
  53. * Initialize the Kyber key.
  54. *
  55. * @param [in] type Type of key: KYBER512, KYBER768, KYBER1024.
  56. * @param [out] key Kyber key object to initialize.
  57. * @param [in] heap Dynamic memory hint.
  58. * @param [in] devId Device Id.
  59. * @return 0 on success.
  60. * @return BAD_FUNC_ARG when key is NULL or type is unrecognized.
  61. * @return NOT_COMPILED_IN when key type is not supported.
  62. */
  63. int wc_KyberKey_Init(int type, KyberKey* key, void* heap, int devId)
  64. {
  65. int ret = 0;
  66. /* Validate key. */
  67. if (key == NULL) {
  68. ret = BAD_FUNC_ARG;
  69. }
  70. if (ret == 0) {
  71. /* Validate type. */
  72. switch (type) {
  73. case KYBER_LEVEL1:
  74. #ifdef HAVE_LIBOQS
  75. case KYBER_LEVEL3:
  76. case KYBER_LEVEL5:
  77. #endif /* HAVE_LIBOQS */
  78. break;
  79. default:
  80. /* No other values supported. */
  81. ret = BAD_FUNC_ARG;
  82. break;
  83. }
  84. }
  85. if (ret == 0) {
  86. /* Zero out all data. */
  87. XMEMSET(key, 0, sizeof(*key));
  88. /* Keep type for parameters. */
  89. key->type = type;
  90. }
  91. (void)devId;
  92. (void)heap;
  93. return ret;
  94. }
  95. /**
  96. * Free the Kyber key object.
  97. *
  98. * @param [in, out] key Kyber key object to dispose of.
  99. */
  100. void wc_KyberKey_Free(KyberKey* key)
  101. {
  102. if (key != NULL) {
  103. /* Ensure all private data is zeroed. */
  104. ForceZero(key, sizeof(*key));
  105. }
  106. }
  107. /******************************************************************************/
  108. /* Data size getters. */
  109. /**
  110. * Get the size in bytes of encoded private key for the key.
  111. *
  112. * @param [in] key Kyber key object.
  113. * @param [out] len Length of encoded private key in bytes.
  114. * @return 0 on success.
  115. * @return BAD_FUNC_ARG when key or len is NULL.
  116. * @return NOT_COMPILED_IN when key type is not supported.
  117. */
  118. int wc_KyberKey_PrivateKeySize(KyberKey* key, word32* len)
  119. {
  120. int ret = 0;
  121. /* Validate parameters. */
  122. if ((key == NULL) || (len == NULL)) {
  123. ret = BAD_FUNC_ARG;
  124. }
  125. #ifdef HAVE_LIBOQS
  126. /* NOTE: SHAKE and AES variants have the same length private key. */
  127. if (ret == 0) {
  128. switch (key->type) {
  129. case KYBER_LEVEL1:
  130. *len = OQS_KEM_kyber_512_length_secret_key;
  131. break;
  132. case KYBER_LEVEL3:
  133. *len = OQS_KEM_kyber_768_length_secret_key;
  134. break;
  135. case KYBER_LEVEL5:
  136. *len = OQS_KEM_kyber_1024_length_secret_key;
  137. break;
  138. default:
  139. /* No other values supported. */
  140. ret = BAD_FUNC_ARG;
  141. break;
  142. }
  143. }
  144. #endif /* HAVE_LIBOQS */
  145. #ifdef HAVE_PQM4
  146. (void)key;
  147. if (ret == 0) {
  148. *len = PQM4_PRIVATE_KEY_LENGTH;
  149. }
  150. #endif /* HAVE_PQM4 */
  151. return ret;
  152. }
  153. /**
  154. * Get the size in bytes of encoded public key for the key.
  155. *
  156. * @param [in] key Kyber key object.
  157. * @param [out] len Length of encoded public key in bytes.
  158. * @return 0 on success.
  159. * @return BAD_FUNC_ARG when key or len is NULL.
  160. * @return NOT_COMPILED_IN when key type is not supported.
  161. */
  162. int wc_KyberKey_PublicKeySize(KyberKey* key, word32* len)
  163. {
  164. int ret = 0;
  165. /* Validate parameters. */
  166. if ((key == NULL) || (len == NULL)) {
  167. ret = BAD_FUNC_ARG;
  168. }
  169. #ifdef HAVE_LIBOQS
  170. /* NOTE: SHAKE and AES variants have the same length public key. */
  171. if (ret == 0) {
  172. switch (key->type) {
  173. case KYBER_LEVEL1:
  174. *len = OQS_KEM_kyber_512_length_public_key;
  175. break;
  176. case KYBER_LEVEL3:
  177. *len = OQS_KEM_kyber_768_length_public_key;
  178. break;
  179. case KYBER_LEVEL5:
  180. *len = OQS_KEM_kyber_1024_length_public_key;
  181. break;
  182. default:
  183. /* No other values supported. */
  184. ret = BAD_FUNC_ARG;
  185. break;
  186. }
  187. }
  188. #endif /* HAVE_LIBOQS */
  189. #ifdef HAVE_PQM4
  190. (void)key;
  191. if (ret == 0) {
  192. *len = PQM4_PUBLIC_KEY_LENGTH;
  193. }
  194. #endif /* HAVE_PQM4 */
  195. return ret;
  196. }
  197. /**
  198. * Get the size in bytes of cipher text for key.
  199. *
  200. * @param [in] key Kyber key object.
  201. * @param [out] len Length of cipher text in bytes.
  202. * @return 0 on success.
  203. * @return BAD_FUNC_ARG when key or len is NULL.
  204. * @return NOT_COMPILED_IN when key type is not supported.
  205. */
  206. int wc_KyberKey_CipherTextSize(KyberKey* key, word32* len)
  207. {
  208. int ret = 0;
  209. /* Validate parameters. */
  210. if ((key == NULL) || (len == NULL)) {
  211. ret = BAD_FUNC_ARG;
  212. }
  213. #ifdef HAVE_LIBOQS
  214. /* NOTE: SHAKE and AES variants have the same length ciphertext. */
  215. if (ret == 0) {
  216. switch (key->type) {
  217. case KYBER_LEVEL1:
  218. *len = OQS_KEM_kyber_512_length_ciphertext;
  219. break;
  220. case KYBER_LEVEL3:
  221. *len = OQS_KEM_kyber_768_length_ciphertext;
  222. break;
  223. case KYBER_LEVEL5:
  224. *len = OQS_KEM_kyber_1024_length_ciphertext;
  225. break;
  226. default:
  227. /* No other values supported. */
  228. ret = BAD_FUNC_ARG;
  229. break;
  230. }
  231. }
  232. #endif /* HAVE_LIBOQS */
  233. #ifdef HAVE_PQM4
  234. (void)key;
  235. if (ret == 0) {
  236. *len = PQM4_CIPHERTEXT_LENGTH;
  237. }
  238. #endif /* HAVE_PQM4 */
  239. return ret;
  240. }
  241. /**
  242. * Size of a shared secret in bytes. Always KYBER_SS_SZ.
  243. *
  244. * @param [in] key Kyber key object. Not used.
  245. * @param [out] Size of the shared secret created with a Kyber key.
  246. * @return 0 on success.
  247. * @return 0 to indicate success.
  248. */
  249. int wc_KyberKey_SharedSecretSize(KyberKey* key, word32* len)
  250. {
  251. (void)key;
  252. /* Validate parameters. */
  253. if (len == NULL) {
  254. return BAD_FUNC_ARG;
  255. }
  256. *len = KYBER_SS_SZ;
  257. return 0;
  258. }
  259. /******************************************************************************/
  260. /* Cryptographic operations. */
  261. /**
  262. * Make a Kyber key object using a random number generator.
  263. *
  264. * NOTE: rng is ignored. OQS and PQM4 don't use our RNG.
  265. *
  266. * @param [in, out] key Kyber key ovject.
  267. * @param [in] rng Random number generator.
  268. * @return 0 on success.
  269. * @return BAD_FUNC_ARG when key or rng is NULL.
  270. * @return MEMORY_E when dynamic memory allocation failed.
  271. */
  272. int wc_KyberKey_MakeKey(KyberKey* key, WC_RNG* rng)
  273. {
  274. int ret = 0;
  275. const char* algName = NULL;
  276. OQS_KEM *kem = NULL;
  277. (void)rng;
  278. /* Validate parameter. */
  279. if (key == NULL) {
  280. return BAD_FUNC_ARG;
  281. }
  282. #ifdef HAVE_LIBOQS
  283. if (ret == 0) {
  284. algName = OQS_ID2name(key->type);
  285. if (algName == NULL) {
  286. ret = BAD_FUNC_ARG;
  287. }
  288. }
  289. if (ret == 0) {
  290. algName = OQS_ID2name(key->type);
  291. if (algName == NULL) {
  292. ret = BAD_FUNC_ARG;
  293. }
  294. }
  295. if (ret == 0) {
  296. kem = OQS_KEM_new(algName);
  297. if (kem == NULL) {
  298. ret = BAD_FUNC_ARG;
  299. }
  300. }
  301. if (ret == 0) {
  302. if (OQS_KEM_keypair(kem, key->pub, key->priv) !=
  303. OQS_SUCCESS) {
  304. ret = BAD_FUNC_ARG;
  305. }
  306. }
  307. #endif /* HAVE_LIBOQS */
  308. #ifdef HAVE_PQM4
  309. if (ret == 0) {
  310. if (crypto_kem_keypair(key->pub, key->priv) != 0) {
  311. WOLFSSL_MSG("PQM4 keygen failure");
  312. ret = BAD_FUNC_ARG;
  313. }
  314. }
  315. #endif /* HAVE_PQM4 */
  316. if (ret != 0) {
  317. ForceZero(key, sizeof(*key));
  318. }
  319. OQS_KEM_free(kem);
  320. return ret;
  321. }
  322. /**
  323. * Make a Kyber key object using random data.
  324. *
  325. * @param [in, out] key Kyber key ovject.
  326. * @param [in] rng Random number generator.
  327. * @return 0 on success.
  328. * @return BAD_FUNC_ARG when key or rand is NULL.
  329. * @return BUFFER_E when length is not KYBER_MAKEKEY_RAND_SZ.
  330. * @return NOT_COMPILED_IN when key type is not supported.
  331. * @return MEMORY_E when dynamic memory allocation failed.
  332. */
  333. int wc_KyberKey_MakeKeyWithRandom(KyberKey* key, const unsigned char* rand,
  334. int len)
  335. {
  336. (void)rand;
  337. (void)len;
  338. /* OQS and PQM4 don't support external randomness. */
  339. return wc_KyberKey_MakeKey(key, NULL);
  340. }
  341. /**
  342. * Encapsulate with random number generator and derive secret.
  343. *
  344. * @param [in] key Kyber key object.
  345. * @param [out] ct Cipher text.
  346. * @param [out] ss Shared secret generated.
  347. * @param [in] rng Random number generator.
  348. * @return 0 on success.
  349. * @return BAD_FUNC_ARG when key, ct, ss or RNG is NULL.
  350. * @return NOT_COMPILED_IN when key type is not supported.
  351. * @return MEMORY_E when dynamic memory allocation failed.
  352. */
  353. int wc_KyberKey_Encapsulate(KyberKey* key, unsigned char* ct, unsigned char* ss,
  354. WC_RNG* rng)
  355. {
  356. int ret = 0;
  357. const char * algName = NULL;
  358. OQS_KEM *kem = NULL;
  359. (void)rng;
  360. /* Validate parameters. */
  361. if ((key == NULL) || (ct == NULL) || (ss == NULL)) {
  362. ret = BAD_FUNC_ARG;
  363. }
  364. #ifdef HAVE_LIBOQS
  365. if (ret == 0) {
  366. algName = OQS_ID2name(key->type);
  367. if (algName == NULL) {
  368. ret = BAD_FUNC_ARG;
  369. }
  370. }
  371. if (ret == 0) {
  372. kem = OQS_KEM_new(algName);
  373. if (kem == NULL) {
  374. ret = BAD_FUNC_ARG;
  375. }
  376. }
  377. if (ret == 0) {
  378. if (OQS_KEM_encaps(kem, ct, ss, key->pub) != OQS_SUCCESS) {
  379. ret = BAD_FUNC_ARG;
  380. }
  381. }
  382. #endif /* HAVE_LIBOQS */
  383. #ifdef HAVE_PQM4
  384. if (ret == 0) {
  385. if (crypto_kem_enc(ct, ss, key->pub) != 0) {
  386. WOLFSSL_MSG("PQM4 Encapsulation failure.");
  387. ret = BAD_FUNC_ARG;
  388. }
  389. }
  390. #endif /* HAVE_PQM4 */
  391. OQS_KEM_free(kem);
  392. return ret;
  393. }
  394. /**
  395. * Encapsulate with random data and derive secret.
  396. *
  397. * @param [out] ct Cipher text.
  398. * @param [out] ss Shared secret generated.
  399. * @param [in] rand Random data.
  400. * @param [in] len Random data.
  401. * @return 0 on success.
  402. * @return BAD_FUNC_ARG when key, ct, ss or RNG is NULL.
  403. * @return BUFFER_E when len is not KYBER_ENC_RAND_SZ.
  404. * @return NOT_COMPILED_IN when key type is not supported.
  405. * @return MEMORY_E when dynamic memory allocation failed.
  406. */
  407. int wc_KyberKey_EncapsulateWithRandom(KyberKey* key, unsigned char* ct,
  408. unsigned char* ss, const unsigned char* rand, int len)
  409. {
  410. (void)rand;
  411. (void)len;
  412. /* OQS and PQM4 don't support external randomness. */
  413. return wc_KyberKey_Encapsulate(key, ct, ss, NULL);
  414. }
  415. /**
  416. * Decapsulate the cipher text to calculate the shared secret.
  417. *
  418. * Validates the cipher text by encapsulating and comparing with data passed in.
  419. *
  420. * @param [in] key Kyber key object.
  421. * @param [out] ss Shared secret.
  422. * @param [in] ct Cipher text.
  423. * @param [in] len Length of cipher text.
  424. * @return 0 on success.
  425. * @return BAD_FUNC_ARG when key, ss or cr are NULL.
  426. * @return NOT_COMPILED_IN when key type is not supported.
  427. * @return BUFFER_E when len is not the length of cipher text for the key type.
  428. * @return MEMORY_E when dynamic memory allocation failed.
  429. */
  430. int wc_KyberKey_Decapsulate(KyberKey* key, unsigned char* ss,
  431. const unsigned char* ct, word32 len)
  432. {
  433. int ret = 0;
  434. const char * algName = NULL;
  435. word32 ctlen = 0;
  436. OQS_KEM *kem = NULL;
  437. /* Validate parameters. */
  438. if ((key == NULL) || (ss == NULL) || (ct == NULL)) {
  439. ret = BAD_FUNC_ARG;
  440. }
  441. if (ret == 0) {
  442. ret = wc_KyberKey_CipherTextSize(key, &ctlen);
  443. }
  444. if ((ret == 0) && (len != ctlen)) {
  445. ret = BUFFER_E;
  446. }
  447. #ifdef HAVE_LIBOQS
  448. if (ret == 0) {
  449. algName = OQS_ID2name(key->type);
  450. if (algName == NULL) {
  451. ret = BAD_FUNC_ARG;
  452. }
  453. }
  454. if (ret == 0) {
  455. kem = OQS_KEM_new(algName);
  456. if (kem == NULL) {
  457. ret = BAD_FUNC_ARG;
  458. }
  459. }
  460. if (ret == 0) {
  461. if (OQS_KEM_decaps(kem, ss, ct, key->priv) != OQS_SUCCESS) {
  462. ret = BAD_FUNC_ARG;
  463. }
  464. }
  465. #endif /* HAVE_LIBOQS */
  466. #ifdef HAVE_PQM4
  467. if (ret == 0) {
  468. if (crypto_kem_enc(ss, ct, key->priv) != 0) {
  469. WOLFSSL_MSG("PQM4 Decapsulation failure.");
  470. ret = BAD_FUNC_ARG;
  471. }
  472. }
  473. #endif /* HAVE_PQM4 */
  474. OQS_KEM_free(kem);
  475. return ret;
  476. }
  477. /******************************************************************************/
  478. /* Encoding and decoding functions. */
  479. /**
  480. * Decode the private key.
  481. *
  482. * We store the whole thing in the private key buffer. Note this means we cannot
  483. * do the encapsulation operation with the private key. But generally speaking
  484. * this is never done.
  485. *
  486. * @param [in, out] key Kyber key object.
  487. * @param [in] in Buffer holding encoded key.
  488. * @param [in] len Length of data in buffer.
  489. * @return 0 on success.
  490. * @return BAD_FUNC_ARG when key ot in is NULL.
  491. * @return NOT_COMPILED_IN when key type is not supported.
  492. * @return BUFFER_E when len is not the correct size.
  493. */
  494. int wc_KyberKey_DecodePrivateKey(KyberKey* key, unsigned char* in, word32 len)
  495. {
  496. int ret = 0;
  497. word32 privLen = 0;
  498. /* Validate parameters. */
  499. if ((key == NULL) || (in == NULL)) {
  500. ret = BAD_FUNC_ARG;
  501. }
  502. if (ret == 0) {
  503. ret = wc_KyberKey_PrivateKeySize(key, &privLen);
  504. }
  505. /* Ensure the data is the correct length for the key type. */
  506. if ((ret == 0) && (len != privLen)) {
  507. ret = BUFFER_E;
  508. }
  509. if (ret == 0) {
  510. XMEMCPY(key->priv, in, privLen);
  511. }
  512. return ret;
  513. }
  514. /**
  515. * Decode public key.
  516. *
  517. * We store the whole thing in the public key buffer.
  518. *
  519. * @param [in, out] key Kyber key object.
  520. * @param [in] in Buffer holding encoded key.
  521. * @param [in] len Length of data in buffer.
  522. * @return 0 on success.
  523. * @return BAD_FUNC_ARG when key or in is NULL.
  524. * @return NOT_COMPILED_IN when key type is not supported.
  525. * @return BUFFER_E when len is not the correct size.
  526. */
  527. int wc_KyberKey_DecodePublicKey(KyberKey* key, unsigned char* in, word32 len)
  528. {
  529. int ret = 0;
  530. word32 pubLen = 0;
  531. /* Validate parameters. */
  532. if ((key == NULL) || (in == NULL)) {
  533. ret = BAD_FUNC_ARG;
  534. }
  535. if (ret == 0) {
  536. ret = wc_KyberKey_PublicKeySize(key, &pubLen);
  537. }
  538. /* Ensure the data is the correct length for the key type. */
  539. if ((ret == 0) && (len != pubLen)) {
  540. ret = BUFFER_E;
  541. }
  542. if (ret == 0) {
  543. XMEMCPY(key->pub, in, pubLen);
  544. }
  545. return ret;
  546. }
  547. /**
  548. * Encode the private key.
  549. *
  550. * We stored it as a blob so we can just copy it over.
  551. *
  552. * @param [in] key Kyber key object.
  553. * @param [out] out Buffer to hold data.
  554. * @param [in] len Size of buffer in bytes.
  555. * @return 0 on success.
  556. * @return BAD_FUNC_ARG when key or out is NULL or private/public key not
  557. * available.
  558. * @return NOT_COMPILED_IN when key type is not supported.
  559. */
  560. int wc_KyberKey_EncodePrivateKey(KyberKey* key, unsigned char* out, word32 len)
  561. {
  562. int ret = 0;
  563. unsigned int privLen = 0;
  564. if ((key == NULL) || (out == NULL)) {
  565. ret = BAD_FUNC_ARG;
  566. }
  567. if (ret == 0) {
  568. ret = wc_KyberKey_PrivateKeySize(key, &privLen);
  569. }
  570. /* Check buffer is big enough for encoding. */
  571. if ((ret == 0) && (len != privLen)) {
  572. ret = BUFFER_E;
  573. }
  574. if (ret == 0) {
  575. XMEMCPY(out, key->priv, privLen);
  576. }
  577. return ret;
  578. }
  579. /**
  580. * Encode the public key.
  581. *
  582. * We stored it as a blob so we can just copy it over.
  583. *
  584. * @param [in] key Kyber key object.
  585. * @param [out] out Buffer to hold data.
  586. * @param [in] len Size of buffer in bytes.
  587. * @return 0 on success.
  588. * @return BAD_FUNC_ARG when key or out is NULL or public key not available.
  589. * @return NOT_COMPILED_IN when key type is not supported.
  590. */
  591. int wc_KyberKey_EncodePublicKey(KyberKey* key, unsigned char* out, word32 len)
  592. {
  593. int ret = 0;
  594. unsigned int pubLen = 0;
  595. if ((key == NULL) || (out == NULL)) {
  596. ret = BAD_FUNC_ARG;
  597. }
  598. if (ret == 0) {
  599. ret = wc_KyberKey_PublicKeySize(key, &pubLen);
  600. }
  601. /* Check buffer is big enough for encoding. */
  602. if ((ret == 0) && (len != pubLen)) {
  603. ret = BUFFER_E;
  604. }
  605. if (ret == 0) {
  606. XMEMCPY(out, key->pub, pubLen);
  607. }
  608. return ret;
  609. }
  610. #endif /* WOLFSSL_HAVE_KYBER */