1 // SPDX-License-Identifier: MIT
2
3 #include <stdlib.h>
4
5 #include <oqs/kem_ntruprime.h>
6
7 #if defined(OQS_ENABLE_KEM_ntruprime_sntrup761)
8
OQS_KEM_ntruprime_sntrup761_new()9 OQS_KEM *OQS_KEM_ntruprime_sntrup761_new() {
10
11 OQS_KEM *kem = malloc(sizeof(OQS_KEM));
12 if (kem == NULL) {
13 return NULL;
14 }
15 kem->method_name = OQS_KEM_alg_ntruprime_sntrup761;
16 kem->alg_version = "supercop-20210604 via https://github.com/jschanck/package-pqclean/tree/4d9f08c3/ntruprime";
17
18 kem->claimed_nist_level = 3;
19 kem->ind_cca = true;
20
21 kem->length_public_key = OQS_KEM_ntruprime_sntrup761_length_public_key;
22 kem->length_secret_key = OQS_KEM_ntruprime_sntrup761_length_secret_key;
23 kem->length_ciphertext = OQS_KEM_ntruprime_sntrup761_length_ciphertext;
24 kem->length_shared_secret = OQS_KEM_ntruprime_sntrup761_length_shared_secret;
25
26 kem->keypair = OQS_KEM_ntruprime_sntrup761_keypair;
27 kem->encaps = OQS_KEM_ntruprime_sntrup761_encaps;
28 kem->decaps = OQS_KEM_ntruprime_sntrup761_decaps;
29
30 return kem;
31 }
32
33 extern int PQCLEAN_SNTRUP761_CLEAN_crypto_kem_keypair(uint8_t *pk, uint8_t *sk);
34 extern int PQCLEAN_SNTRUP761_CLEAN_crypto_kem_enc(uint8_t *ct, uint8_t *ss, const uint8_t *pk);
35 extern int PQCLEAN_SNTRUP761_CLEAN_crypto_kem_dec(uint8_t *ss, const uint8_t *ct, const uint8_t *sk);
36
37 #if defined(OQS_ENABLE_KEM_ntruprime_sntrup761_avx2)
38 extern int PQCLEAN_SNTRUP761_AVX2_crypto_kem_keypair(uint8_t *pk, uint8_t *sk);
39 extern int PQCLEAN_SNTRUP761_AVX2_crypto_kem_enc(uint8_t *ct, uint8_t *ss, const uint8_t *pk);
40 extern int PQCLEAN_SNTRUP761_AVX2_crypto_kem_dec(uint8_t *ss, const uint8_t *ct, const uint8_t *sk);
41 #endif
42
OQS_KEM_ntruprime_sntrup761_keypair(uint8_t * public_key,uint8_t * secret_key)43 OQS_API OQS_STATUS OQS_KEM_ntruprime_sntrup761_keypair(uint8_t *public_key, uint8_t *secret_key) {
44 #if defined(OQS_ENABLE_KEM_ntruprime_sntrup761_avx2)
45 #if defined(OQS_DIST_BUILD)
46 if (OQS_CPU_has_extension(OQS_CPU_EXT_AVX2)) {
47 #endif /* OQS_DIST_BUILD */
48 return (OQS_STATUS) PQCLEAN_SNTRUP761_AVX2_crypto_kem_keypair(public_key, secret_key);
49 #if defined(OQS_DIST_BUILD)
50 } else {
51 return (OQS_STATUS) PQCLEAN_SNTRUP761_CLEAN_crypto_kem_keypair(public_key, secret_key);
52 }
53 #endif /* OQS_DIST_BUILD */
54 #else
55 return (OQS_STATUS) PQCLEAN_SNTRUP761_CLEAN_crypto_kem_keypair(public_key, secret_key);
56 #endif
57 }
58
OQS_KEM_ntruprime_sntrup761_encaps(uint8_t * ciphertext,uint8_t * shared_secret,const uint8_t * public_key)59 OQS_API OQS_STATUS OQS_KEM_ntruprime_sntrup761_encaps(uint8_t *ciphertext, uint8_t *shared_secret, const uint8_t *public_key) {
60 #if defined(OQS_ENABLE_KEM_ntruprime_sntrup761_avx2)
61 #if defined(OQS_DIST_BUILD)
62 if (OQS_CPU_has_extension(OQS_CPU_EXT_AVX2)) {
63 #endif /* OQS_DIST_BUILD */
64 return (OQS_STATUS) PQCLEAN_SNTRUP761_AVX2_crypto_kem_enc(ciphertext, shared_secret, public_key);
65 #if defined(OQS_DIST_BUILD)
66 } else {
67 return (OQS_STATUS) PQCLEAN_SNTRUP761_CLEAN_crypto_kem_enc(ciphertext, shared_secret, public_key);
68 }
69 #endif /* OQS_DIST_BUILD */
70 #else
71 return (OQS_STATUS) PQCLEAN_SNTRUP761_CLEAN_crypto_kem_enc(ciphertext, shared_secret, public_key);
72 #endif
73 }
74
OQS_KEM_ntruprime_sntrup761_decaps(uint8_t * shared_secret,const uint8_t * ciphertext,const uint8_t * secret_key)75 OQS_API OQS_STATUS OQS_KEM_ntruprime_sntrup761_decaps(uint8_t *shared_secret, const uint8_t *ciphertext, const uint8_t *secret_key) {
76 #if defined(OQS_ENABLE_KEM_ntruprime_sntrup761_avx2)
77 #if defined(OQS_DIST_BUILD)
78 if (OQS_CPU_has_extension(OQS_CPU_EXT_AVX2)) {
79 #endif /* OQS_DIST_BUILD */
80 return (OQS_STATUS) PQCLEAN_SNTRUP761_AVX2_crypto_kem_dec(shared_secret, ciphertext, secret_key);
81 #if defined(OQS_DIST_BUILD)
82 } else {
83 return (OQS_STATUS) PQCLEAN_SNTRUP761_CLEAN_crypto_kem_dec(shared_secret, ciphertext, secret_key);
84 }
85 #endif /* OQS_DIST_BUILD */
86 #else
87 return (OQS_STATUS) PQCLEAN_SNTRUP761_CLEAN_crypto_kem_dec(shared_secret, ciphertext, secret_key);
88 #endif
89 }
90
91 #endif
92