1 // SPDX-License-Identifier: MIT
2
3 #include <stdlib.h>
4
5 #include <oqs/kem_sike.h>
6
7 #ifdef OQS_ENABLE_KEM_sike_p434
8
9 #include "external/P434/P434_api.h"
10
OQS_KEM_sike_p434_new()11 OQS_KEM *OQS_KEM_sike_p434_new() {
12
13 OQS_KEM *kem = malloc(sizeof(OQS_KEM));
14 if (kem == NULL) {
15 return NULL;
16 }
17 kem->method_name = OQS_KEM_alg_sike_p434;
18 kem->alg_version = "https://github.com/microsoft/PQCrypto-SIDH/commit/28b4b5d0a7926e0e7eb4f9c03f75887236e1cebd";
19
20 kem->claimed_nist_level = 1;
21 kem->ind_cca = true;
22
23 kem->length_public_key = OQS_KEM_sike_p434_length_public_key;
24 kem->length_secret_key = OQS_KEM_sike_p434_length_secret_key;
25 kem->length_ciphertext = OQS_KEM_sike_p434_length_ciphertext;
26 kem->length_shared_secret = OQS_KEM_sike_p434_length_shared_secret;
27
28 kem->keypair = OQS_KEM_sike_p434_keypair;
29 kem->encaps = OQS_KEM_sike_p434_encaps;
30 kem->decaps = OQS_KEM_sike_p434_decaps;
31
32 return kem;
33 }
34
35 #endif
36
37 #ifdef OQS_ENABLE_KEM_sike_p434_compressed
38
39 #include "external/P434/P434_compressed_api.h"
40
OQS_KEM_sike_p434_compressed_new()41 OQS_KEM *OQS_KEM_sike_p434_compressed_new() {
42
43 OQS_KEM *kem = malloc(sizeof(OQS_KEM));
44 if (kem == NULL) {
45 return NULL;
46 }
47 kem->method_name = OQS_KEM_alg_sike_p434_compressed;
48 kem->alg_version = "https://github.com/microsoft/PQCrypto-SIDH/commit/28b4b5d0a7926e0e7eb4f9c03f75887236e1cebd";
49
50 kem->claimed_nist_level = 1;
51 kem->ind_cca = true;
52
53 kem->length_public_key = OQS_KEM_sike_p434_compressed_length_public_key;
54 kem->length_secret_key = OQS_KEM_sike_p434_compressed_length_secret_key;
55 kem->length_ciphertext = OQS_KEM_sike_p434_compressed_length_ciphertext;
56 kem->length_shared_secret = OQS_KEM_sike_p434_compressed_length_shared_secret;
57
58 kem->keypair = OQS_KEM_sike_p434_compressed_keypair;
59 kem->encaps = OQS_KEM_sike_p434_compressed_encaps;
60 kem->decaps = OQS_KEM_sike_p434_compressed_decaps;
61
62 return kem;
63 }
64
65 #endif
66
67 #ifdef OQS_ENABLE_KEM_sike_p503
68
69 #include "external/P503/P503_api.h"
70
OQS_KEM_sike_p503_new()71 OQS_KEM *OQS_KEM_sike_p503_new() {
72
73 OQS_KEM *kem = malloc(sizeof(OQS_KEM));
74 if (kem == NULL) {
75 return NULL;
76 }
77 kem->method_name = OQS_KEM_alg_sike_p503;
78 kem->alg_version = "https://github.com/microsoft/PQCrypto-SIDH/commit/28b4b5d0a7926e0e7eb4f9c03f75887236e1cebd";
79
80 kem->claimed_nist_level = 2;
81 kem->ind_cca = true;
82
83 kem->length_public_key = OQS_KEM_sike_p503_length_public_key;
84 kem->length_secret_key = OQS_KEM_sike_p503_length_secret_key;
85 kem->length_ciphertext = OQS_KEM_sike_p503_length_ciphertext;
86 kem->length_shared_secret = OQS_KEM_sike_p503_length_shared_secret;
87
88 kem->keypair = OQS_KEM_sike_p503_keypair;
89 kem->encaps = OQS_KEM_sike_p503_encaps;
90 kem->decaps = OQS_KEM_sike_p503_decaps;
91
92 return kem;
93 }
94
95 #endif
96
97 #ifdef OQS_ENABLE_KEM_sike_p503_compressed
98
99 #include "external/P503/P503_compressed_api.h"
100
OQS_KEM_sike_p503_compressed_new()101 OQS_KEM *OQS_KEM_sike_p503_compressed_new() {
102
103 OQS_KEM *kem = malloc(sizeof(OQS_KEM));
104 if (kem == NULL) {
105 return NULL;
106 }
107 kem->method_name = OQS_KEM_alg_sike_p503_compressed;
108 kem->alg_version = "https://github.com/microsoft/PQCrypto-SIDH/commit/28b4b5d0a7926e0e7eb4f9c03f75887236e1cebd";
109
110 kem->claimed_nist_level = 2;
111 kem->ind_cca = true;
112
113 kem->length_public_key = OQS_KEM_sike_p503_compressed_length_public_key;
114 kem->length_secret_key = OQS_KEM_sike_p503_compressed_length_secret_key;
115 kem->length_ciphertext = OQS_KEM_sike_p503_compressed_length_ciphertext;
116 kem->length_shared_secret = OQS_KEM_sike_p503_compressed_length_shared_secret;
117
118 kem->keypair = OQS_KEM_sike_p503_compressed_keypair;
119 kem->encaps = OQS_KEM_sike_p503_compressed_encaps;
120 kem->decaps = OQS_KEM_sike_p503_compressed_decaps;
121
122 return kem;
123 }
124
125 #endif
126
127 #ifdef OQS_ENABLE_KEM_sike_p610
128
129 #include "external/P610/P610_api.h"
130
OQS_KEM_sike_p610_new()131 OQS_KEM *OQS_KEM_sike_p610_new() {
132
133 OQS_KEM *kem = malloc(sizeof(OQS_KEM));
134 if (kem == NULL) {
135 return NULL;
136 }
137 kem->method_name = OQS_KEM_alg_sike_p610;
138 kem->alg_version = "https://github.com/microsoft/PQCrypto-SIDH/commit/28b4b5d0a7926e0e7eb4f9c03f75887236e1cebd";
139
140 kem->claimed_nist_level = 3;
141 kem->ind_cca = true;
142
143 kem->length_public_key = OQS_KEM_sike_p610_length_public_key;
144 kem->length_secret_key = OQS_KEM_sike_p610_length_secret_key;
145 kem->length_ciphertext = OQS_KEM_sike_p610_length_ciphertext;
146 kem->length_shared_secret = OQS_KEM_sike_p610_length_shared_secret;
147
148 kem->keypair = OQS_KEM_sike_p610_keypair;
149 kem->encaps = OQS_KEM_sike_p610_encaps;
150 kem->decaps = OQS_KEM_sike_p610_decaps;
151
152 return kem;
153 }
154
155 #endif
156
157 #ifdef OQS_ENABLE_KEM_sike_p610_compressed
158
159 #include "external/P610/P610_compressed_api.h"
160
OQS_KEM_sike_p610_compressed_new()161 OQS_KEM *OQS_KEM_sike_p610_compressed_new() {
162
163 OQS_KEM *kem = malloc(sizeof(OQS_KEM));
164 if (kem == NULL) {
165 return NULL;
166 }
167 kem->method_name = OQS_KEM_alg_sike_p610_compressed;
168 kem->alg_version = "https://github.com/microsoft/PQCrypto-SIDH/commit/28b4b5d0a7926e0e7eb4f9c03f75887236e1cebd";
169
170 kem->claimed_nist_level = 3;
171 kem->ind_cca = true;
172
173 kem->length_public_key = OQS_KEM_sike_p610_compressed_length_public_key;
174 kem->length_secret_key = OQS_KEM_sike_p610_compressed_length_secret_key;
175 kem->length_ciphertext = OQS_KEM_sike_p610_compressed_length_ciphertext;
176 kem->length_shared_secret = OQS_KEM_sike_p610_compressed_length_shared_secret;
177
178 kem->keypair = OQS_KEM_sike_p610_compressed_keypair;
179 kem->encaps = OQS_KEM_sike_p610_compressed_encaps;
180 kem->decaps = OQS_KEM_sike_p610_compressed_decaps;
181
182 return kem;
183 }
184
185 #endif
186
187 #ifdef OQS_ENABLE_KEM_sike_p751
188
189 #include "external/P751/P751_api.h"
190
OQS_KEM_sike_p751_new()191 OQS_KEM *OQS_KEM_sike_p751_new() {
192
193 OQS_KEM *kem = malloc(sizeof(OQS_KEM));
194 if (kem == NULL) {
195 return NULL;
196 }
197 kem->method_name = OQS_KEM_alg_sike_p751;
198 kem->alg_version = "https://github.com/microsoft/PQCrypto-SIDH/commit/28b4b5d0a7926e0e7eb4f9c03f75887236e1cebd";
199
200 kem->claimed_nist_level = 5;
201 kem->ind_cca = true;
202
203 kem->length_public_key = OQS_KEM_sike_p751_length_public_key;
204 kem->length_secret_key = OQS_KEM_sike_p751_length_secret_key;
205 kem->length_ciphertext = OQS_KEM_sike_p751_length_ciphertext;
206 kem->length_shared_secret = OQS_KEM_sike_p751_length_shared_secret;
207
208 kem->keypair = OQS_KEM_sike_p751_keypair;
209 kem->encaps = OQS_KEM_sike_p751_encaps;
210 kem->decaps = OQS_KEM_sike_p751_decaps;
211
212 return kem;
213 }
214
215 #endif
216
217 #ifdef OQS_ENABLE_KEM_sike_p751_compressed
218
219 #include "external/P751/P751_compressed_api.h"
220
OQS_KEM_sike_p751_compressed_new()221 OQS_KEM *OQS_KEM_sike_p751_compressed_new() {
222
223 OQS_KEM *kem = malloc(sizeof(OQS_KEM));
224 if (kem == NULL) {
225 return NULL;
226 }
227 kem->method_name = OQS_KEM_alg_sike_p751_compressed;
228 kem->alg_version = "https://github.com/microsoft/PQCrypto-SIDH/commit/28b4b5d0a7926e0e7eb4f9c03f75887236e1cebd";
229
230 kem->claimed_nist_level = 5;
231 kem->ind_cca = true;
232
233 kem->length_public_key = OQS_KEM_sike_p751_compressed_length_public_key;
234 kem->length_secret_key = OQS_KEM_sike_p751_compressed_length_secret_key;
235 kem->length_ciphertext = OQS_KEM_sike_p751_compressed_length_ciphertext;
236 kem->length_shared_secret = OQS_KEM_sike_p751_compressed_length_shared_secret;
237
238 kem->keypair = OQS_KEM_sike_p751_compressed_keypair;
239 kem->encaps = OQS_KEM_sike_p751_compressed_encaps;
240 kem->decaps = OQS_KEM_sike_p751_compressed_decaps;
241
242 return kem;
243 }
244
245 #endif
246
247 #ifdef OQS_ENABLE_KEM_sidh_p434
248
249 #include "external/P434/P434_api.h"
250
OQS_KEM_sidh_p434_new()251 OQS_KEM *OQS_KEM_sidh_p434_new() {
252
253 OQS_KEM *kem = malloc(sizeof(OQS_KEM));
254 if (kem == NULL) {
255 return NULL;
256 }
257 kem->method_name = OQS_KEM_alg_sidh_p434;
258 kem->alg_version = "https://github.com/microsoft/PQCrypto-SIDH/commit/28b4b5d0a7926e0e7eb4f9c03f75887236e1cebd";
259
260 kem->claimed_nist_level = 1;
261 kem->ind_cca = false;
262
263 kem->length_public_key = OQS_KEM_sidh_p434_length_public_key;
264 kem->length_secret_key = OQS_KEM_sidh_p434_length_secret_key;
265 kem->length_ciphertext = OQS_KEM_sidh_p434_length_ciphertext;
266 kem->length_shared_secret = OQS_KEM_sidh_p434_length_shared_secret;
267
268 kem->keypair = OQS_KEM_sidh_p434_keypair;
269 kem->encaps = OQS_KEM_sidh_p434_encaps;
270 kem->decaps = OQS_KEM_sidh_p434_decaps;
271
272 return kem;
273 }
274
275 /* Forward KEM API calls to SIDH's API */
OQS_KEM_sidh_p434_keypair(uint8_t * public_key,uint8_t * secret_key)276 OQS_API OQS_STATUS OQS_KEM_sidh_p434_keypair(uint8_t *public_key, uint8_t *secret_key) {
277 oqs_kem_sidh_p434_random_mod_order_A((unsigned char *) secret_key);
278 if (oqs_kem_sidh_p434_EphemeralKeyGeneration_A((unsigned char *) secret_key, (unsigned char *) public_key) != 0) {
279 return OQS_ERROR;
280 }
281 return OQS_SUCCESS;
282 }
283
OQS_KEM_sidh_p434_encaps(uint8_t * ciphertext,uint8_t * shared_secret,const uint8_t * public_key)284 OQS_API OQS_STATUS OQS_KEM_sidh_p434_encaps(uint8_t *ciphertext, uint8_t *shared_secret, const uint8_t *public_key) {
285 OQS_STATUS ret = OQS_ERROR;
286 unsigned char *secret_key = malloc(OQS_KEM_sidh_p434_length_secret_key);
287 oqs_kem_sidh_p434_random_mod_order_B(secret_key);
288 if (oqs_kem_sidh_p434_EphemeralKeyGeneration_B(secret_key, (unsigned char *) ciphertext)) {
289 goto err;
290 }
291 if (oqs_kem_sidh_p434_EphemeralSecretAgreement_B(secret_key, (unsigned char *) public_key, (unsigned char *) shared_secret) != 0) {
292 goto err;
293 }
294 ret = OQS_SUCCESS;
295 goto cleanup;
296
297 err:
298 ret = OQS_ERROR;
299
300 cleanup:
301 if (secret_key != NULL) {
302 OQS_MEM_secure_free(secret_key, OQS_KEM_sidh_p434_length_secret_key);
303 }
304
305 return ret;
306 }
307
OQS_KEM_sidh_p434_decaps(uint8_t * shared_secret,const uint8_t * ciphertext,const uint8_t * secret_key)308 OQS_API OQS_STATUS OQS_KEM_sidh_p434_decaps(uint8_t *shared_secret, const uint8_t *ciphertext, const uint8_t *secret_key) {
309 if (oqs_kem_sidh_p434_EphemeralSecretAgreement_A((unsigned char *) secret_key, (unsigned char *) ciphertext, (unsigned char *) shared_secret) != 0) {
310 return OQS_ERROR;
311 }
312 return OQS_SUCCESS;
313 }
314
315 #endif
316
317 #ifdef OQS_ENABLE_KEM_sidh_p434_compressed
318
319 #include "external/P434/P434_compressed_api.h"
320
OQS_KEM_sidh_p434_compressed_new()321 OQS_KEM *OQS_KEM_sidh_p434_compressed_new() {
322
323 OQS_KEM *kem = malloc(sizeof(OQS_KEM));
324 if (kem == NULL) {
325 return NULL;
326 }
327 kem->method_name = OQS_KEM_alg_sidh_p434_compressed;
328 kem->alg_version = "https://github.com/microsoft/PQCrypto-SIDH/commit/28b4b5d0a7926e0e7eb4f9c03f75887236e1cebd";
329
330 kem->claimed_nist_level = 1;
331 kem->ind_cca = false;
332
333 kem->length_public_key = OQS_KEM_sidh_p434_compressed_length_public_key;
334 kem->length_secret_key = OQS_KEM_sidh_p434_compressed_length_secret_key;
335 kem->length_ciphertext = OQS_KEM_sidh_p434_compressed_length_ciphertext;
336 kem->length_shared_secret = OQS_KEM_sidh_p434_compressed_length_shared_secret;
337
338 kem->keypair = OQS_KEM_sidh_p434_compressed_keypair;
339 kem->encaps = OQS_KEM_sidh_p434_compressed_encaps;
340 kem->decaps = OQS_KEM_sidh_p434_compressed_decaps;
341
342 return kem;
343 }
344
345 /* Forward KEM API calls to SIDH's API */
OQS_KEM_sidh_p434_compressed_keypair(uint8_t * public_key,uint8_t * secret_key)346 OQS_API OQS_STATUS OQS_KEM_sidh_p434_compressed_keypair(uint8_t *public_key, uint8_t *secret_key) {
347 oqs_kem_sidh_p434_compressed_random_mod_order_A((unsigned char *) secret_key);
348 if (oqs_kem_sidh_p434_compressed_EphemeralKeyGeneration_A((unsigned char *) secret_key, (unsigned char *) public_key) != 0) {
349 return OQS_ERROR;
350 }
351 return OQS_SUCCESS;
352 }
353
OQS_KEM_sidh_p434_compressed_encaps(uint8_t * ciphertext,uint8_t * shared_secret,const uint8_t * public_key)354 OQS_API OQS_STATUS OQS_KEM_sidh_p434_compressed_encaps(uint8_t *ciphertext, uint8_t *shared_secret, const uint8_t *public_key) {
355 OQS_STATUS ret = OQS_ERROR;
356 unsigned char *secret_key = malloc(OQS_KEM_sidh_p434_compressed_length_secret_key);
357 oqs_kem_sidh_p434_compressed_random_mod_order_B(secret_key);
358 if (oqs_kem_sidh_p434_compressed_EphemeralKeyGeneration_B(secret_key, (unsigned char *) ciphertext)) {
359 goto err;
360 }
361 if (oqs_kem_sidh_p434_compressed_EphemeralSecretAgreement_B(secret_key, (unsigned char *) public_key, (unsigned char *) shared_secret) != 0) {
362 goto err;
363 }
364 ret = OQS_SUCCESS;
365 goto cleanup;
366
367 err:
368 ret = OQS_ERROR;
369
370 cleanup:
371 if (secret_key != NULL) {
372 OQS_MEM_secure_free(secret_key, OQS_KEM_sidh_p434_compressed_length_secret_key);
373 }
374
375 return ret;
376 }
377
OQS_KEM_sidh_p434_compressed_decaps(uint8_t * shared_secret,const uint8_t * ciphertext,const uint8_t * secret_key)378 OQS_API OQS_STATUS OQS_KEM_sidh_p434_compressed_decaps(uint8_t *shared_secret, const uint8_t *ciphertext, const uint8_t *secret_key) {
379 if (oqs_kem_sidh_p434_compressed_EphemeralSecretAgreement_A((unsigned char *) secret_key, (unsigned char *) ciphertext, (unsigned char *) shared_secret) != 0) {
380 return OQS_ERROR;
381 }
382 return OQS_SUCCESS;
383 }
384
385 #endif
386
387 #ifdef OQS_ENABLE_KEM_sidh_p503
388
389 #include "external/P503/P503_api.h"
390
OQS_KEM_sidh_p503_new()391 OQS_KEM *OQS_KEM_sidh_p503_new() {
392
393 OQS_KEM *kem = malloc(sizeof(OQS_KEM));
394 if (kem == NULL) {
395 return NULL;
396 }
397 kem->method_name = OQS_KEM_alg_sidh_p503;
398 kem->alg_version = "https://github.com/microsoft/PQCrypto-SIDH/commit/28b4b5d0a7926e0e7eb4f9c03f75887236e1cebd";
399
400 kem->claimed_nist_level = 2;
401 kem->ind_cca = false;
402
403 kem->length_public_key = OQS_KEM_sidh_p503_length_public_key;
404 kem->length_secret_key = OQS_KEM_sidh_p503_length_secret_key;
405 kem->length_ciphertext = OQS_KEM_sidh_p503_length_ciphertext;
406 kem->length_shared_secret = OQS_KEM_sidh_p503_length_shared_secret;
407
408 kem->keypair = OQS_KEM_sidh_p503_keypair;
409 kem->encaps = OQS_KEM_sidh_p503_encaps;
410 kem->decaps = OQS_KEM_sidh_p503_decaps;
411
412 return kem;
413 }
414
415 /* Forward KEM API calls to SIDH's API */
OQS_KEM_sidh_p503_keypair(uint8_t * public_key,uint8_t * secret_key)416 OQS_API OQS_STATUS OQS_KEM_sidh_p503_keypair(uint8_t *public_key, uint8_t *secret_key) {
417 oqs_kem_sidh_p503_random_mod_order_A((unsigned char *) secret_key);
418 if (oqs_kem_sidh_p503_EphemeralKeyGeneration_A((unsigned char *) secret_key, (unsigned char *) public_key) != 0) {
419 return OQS_ERROR;
420 }
421 return OQS_SUCCESS;
422 }
423
OQS_KEM_sidh_p503_encaps(uint8_t * ciphertext,uint8_t * shared_secret,const uint8_t * public_key)424 OQS_API OQS_STATUS OQS_KEM_sidh_p503_encaps(uint8_t *ciphertext, uint8_t *shared_secret, const uint8_t *public_key) {
425 OQS_STATUS ret = OQS_ERROR;
426 unsigned char *secret_key = malloc(OQS_KEM_sidh_p503_length_secret_key);
427 oqs_kem_sidh_p503_random_mod_order_B(secret_key);
428 if (oqs_kem_sidh_p503_EphemeralKeyGeneration_B(secret_key, (unsigned char *) ciphertext)) {
429 goto err;
430 }
431 if (oqs_kem_sidh_p503_EphemeralSecretAgreement_B(secret_key, (unsigned char *) public_key, (unsigned char *) shared_secret) != 0) {
432 goto err;
433 }
434 ret = OQS_SUCCESS;
435 goto cleanup;
436
437 err:
438 ret = OQS_ERROR;
439
440 cleanup:
441 if (secret_key != NULL) {
442 OQS_MEM_secure_free(secret_key, OQS_KEM_sidh_p503_length_secret_key);
443 }
444
445 return ret;
446 }
447
OQS_KEM_sidh_p503_decaps(uint8_t * shared_secret,const uint8_t * ciphertext,const uint8_t * secret_key)448 OQS_API OQS_STATUS OQS_KEM_sidh_p503_decaps(uint8_t *shared_secret, const uint8_t *ciphertext, const uint8_t *secret_key) {
449 if (oqs_kem_sidh_p503_EphemeralSecretAgreement_A((unsigned char *) secret_key, (unsigned char *) ciphertext, (unsigned char *) shared_secret) != 0) {
450 return OQS_ERROR;
451 }
452 return OQS_SUCCESS;
453 }
454
455 #endif
456
457 #ifdef OQS_ENABLE_KEM_sidh_p503_compressed
458
459 #include "external/P503/P503_compressed_api.h"
460
OQS_KEM_sidh_p503_compressed_new()461 OQS_KEM *OQS_KEM_sidh_p503_compressed_new() {
462
463 OQS_KEM *kem = malloc(sizeof(OQS_KEM));
464 if (kem == NULL) {
465 return NULL;
466 }
467 kem->method_name = OQS_KEM_alg_sidh_p503_compressed;
468 kem->alg_version = "https://github.com/microsoft/PQCrypto-SIDH/commit/28b4b5d0a7926e0e7eb4f9c03f75887236e1cebd";
469
470 kem->claimed_nist_level = 2;
471 kem->ind_cca = false;
472
473 kem->length_public_key = OQS_KEM_sidh_p503_compressed_length_public_key;
474 kem->length_secret_key = OQS_KEM_sidh_p503_compressed_length_secret_key;
475 kem->length_ciphertext = OQS_KEM_sidh_p503_compressed_length_ciphertext;
476 kem->length_shared_secret = OQS_KEM_sidh_p503_compressed_length_shared_secret;
477
478 kem->keypair = OQS_KEM_sidh_p503_compressed_keypair;
479 kem->encaps = OQS_KEM_sidh_p503_compressed_encaps;
480 kem->decaps = OQS_KEM_sidh_p503_compressed_decaps;
481
482 return kem;
483 }
484
485 /* Forward KEM API calls to SIDH's API */
OQS_KEM_sidh_p503_compressed_keypair(uint8_t * public_key,uint8_t * secret_key)486 OQS_API OQS_STATUS OQS_KEM_sidh_p503_compressed_keypair(uint8_t *public_key, uint8_t *secret_key) {
487 oqs_kem_sidh_p503_compressed_random_mod_order_A((unsigned char *) secret_key);
488 if (oqs_kem_sidh_p503_compressed_EphemeralKeyGeneration_A((unsigned char *) secret_key, (unsigned char *) public_key) != 0) {
489 return OQS_ERROR;
490 }
491 return OQS_SUCCESS;
492 }
493
OQS_KEM_sidh_p503_compressed_encaps(uint8_t * ciphertext,uint8_t * shared_secret,const uint8_t * public_key)494 OQS_API OQS_STATUS OQS_KEM_sidh_p503_compressed_encaps(uint8_t *ciphertext, uint8_t *shared_secret, const uint8_t *public_key) {
495 OQS_STATUS ret = OQS_ERROR;
496 unsigned char *secret_key = malloc(OQS_KEM_sidh_p503_compressed_length_secret_key);
497 oqs_kem_sidh_p503_compressed_random_mod_order_B(secret_key);
498 if (oqs_kem_sidh_p503_compressed_EphemeralKeyGeneration_B(secret_key, (unsigned char *) ciphertext)) {
499 goto err;
500 }
501 if (oqs_kem_sidh_p503_compressed_EphemeralSecretAgreement_B(secret_key, (unsigned char *) public_key, (unsigned char *) shared_secret) != 0) {
502 goto err;
503 }
504 ret = OQS_SUCCESS;
505 goto cleanup;
506
507 err:
508 ret = OQS_ERROR;
509
510 cleanup:
511 if (secret_key != NULL) {
512 OQS_MEM_secure_free(secret_key, OQS_KEM_sidh_p503_compressed_length_secret_key);
513 }
514
515 return ret;
516 }
517
OQS_KEM_sidh_p503_compressed_decaps(uint8_t * shared_secret,const uint8_t * ciphertext,const uint8_t * secret_key)518 OQS_API OQS_STATUS OQS_KEM_sidh_p503_compressed_decaps(uint8_t *shared_secret, const uint8_t *ciphertext, const uint8_t *secret_key) {
519 if (oqs_kem_sidh_p503_compressed_EphemeralSecretAgreement_A((unsigned char *) secret_key, (unsigned char *) ciphertext, (unsigned char *) shared_secret) != 0) {
520 return OQS_ERROR;
521 }
522 return OQS_SUCCESS;
523 }
524
525 #endif
526
527 #ifdef OQS_ENABLE_KEM_sidh_p610
528
529 #include "external/P610/P610_api.h"
530
OQS_KEM_sidh_p610_new()531 OQS_KEM *OQS_KEM_sidh_p610_new() {
532
533 OQS_KEM *kem = malloc(sizeof(OQS_KEM));
534 if (kem == NULL) {
535 return NULL;
536 }
537 kem->method_name = OQS_KEM_alg_sidh_p610;
538 kem->alg_version = "https://github.com/microsoft/PQCrypto-SIDH/commit/28b4b5d0a7926e0e7eb4f9c03f75887236e1cebd";
539
540 kem->claimed_nist_level = 3;
541 kem->ind_cca = false;
542
543 kem->length_public_key = OQS_KEM_sidh_p610_length_public_key;
544 kem->length_secret_key = OQS_KEM_sidh_p610_length_secret_key;
545 kem->length_ciphertext = OQS_KEM_sidh_p610_length_ciphertext;
546 kem->length_shared_secret = OQS_KEM_sidh_p610_length_shared_secret;
547
548 kem->keypair = OQS_KEM_sidh_p610_keypair;
549 kem->encaps = OQS_KEM_sidh_p610_encaps;
550 kem->decaps = OQS_KEM_sidh_p610_decaps;
551
552 return kem;
553 }
554
555 /* Forward KEM API calls to SIDH's API */
OQS_KEM_sidh_p610_keypair(uint8_t * public_key,uint8_t * secret_key)556 OQS_API OQS_STATUS OQS_KEM_sidh_p610_keypair(uint8_t *public_key, uint8_t *secret_key) {
557 oqs_kem_sidh_p610_random_mod_order_A((unsigned char *) secret_key);
558 if (oqs_kem_sidh_p610_EphemeralKeyGeneration_A((unsigned char *) secret_key, (unsigned char *) public_key) != 0) {
559 return OQS_ERROR;
560 }
561 return OQS_SUCCESS;
562 }
563
OQS_KEM_sidh_p610_encaps(uint8_t * ciphertext,uint8_t * shared_secret,const uint8_t * public_key)564 OQS_API OQS_STATUS OQS_KEM_sidh_p610_encaps(uint8_t *ciphertext, uint8_t *shared_secret, const uint8_t *public_key) {
565 OQS_STATUS ret = OQS_ERROR;
566 unsigned char *secret_key = malloc(OQS_KEM_sidh_p610_length_secret_key);
567 oqs_kem_sidh_p610_random_mod_order_B(secret_key);
568 if (oqs_kem_sidh_p610_EphemeralKeyGeneration_B(secret_key, (unsigned char *) ciphertext)) {
569 goto err;
570 }
571 if (oqs_kem_sidh_p610_EphemeralSecretAgreement_B(secret_key, (unsigned char *) public_key, (unsigned char *) shared_secret) != 0) {
572 goto err;
573 }
574 ret = OQS_SUCCESS;
575 goto cleanup;
576
577 err:
578 ret = OQS_ERROR;
579
580 cleanup:
581 if (secret_key != NULL) {
582 OQS_MEM_secure_free(secret_key, OQS_KEM_sidh_p610_length_secret_key);
583 }
584
585 return ret;
586 }
587
OQS_KEM_sidh_p610_decaps(uint8_t * shared_secret,const uint8_t * ciphertext,const uint8_t * secret_key)588 OQS_API OQS_STATUS OQS_KEM_sidh_p610_decaps(uint8_t *shared_secret, const uint8_t *ciphertext, const uint8_t *secret_key) {
589 if (oqs_kem_sidh_p610_EphemeralSecretAgreement_A((unsigned char *) secret_key, (unsigned char *) ciphertext, (unsigned char *) shared_secret) != 0) {
590 return OQS_ERROR;
591 }
592 return OQS_SUCCESS;
593 }
594
595 #endif
596
597 #ifdef OQS_ENABLE_KEM_sidh_p610_compressed
598
599 #include "external/P610/P610_compressed_api.h"
600
OQS_KEM_sidh_p610_compressed_new()601 OQS_KEM *OQS_KEM_sidh_p610_compressed_new() {
602
603 OQS_KEM *kem = malloc(sizeof(OQS_KEM));
604 if (kem == NULL) {
605 return NULL;
606 }
607 kem->method_name = OQS_KEM_alg_sidh_p610_compressed;
608 kem->alg_version = "https://github.com/microsoft/PQCrypto-SIDH/commit/28b4b5d0a7926e0e7eb4f9c03f75887236e1cebd";
609
610 kem->claimed_nist_level = 3;
611 kem->ind_cca = false;
612
613 kem->length_public_key = OQS_KEM_sidh_p610_compressed_length_public_key;
614 kem->length_secret_key = OQS_KEM_sidh_p610_compressed_length_secret_key;
615 kem->length_ciphertext = OQS_KEM_sidh_p610_compressed_length_ciphertext;
616 kem->length_shared_secret = OQS_KEM_sidh_p610_compressed_length_shared_secret;
617
618 kem->keypair = OQS_KEM_sidh_p610_compressed_keypair;
619 kem->encaps = OQS_KEM_sidh_p610_compressed_encaps;
620 kem->decaps = OQS_KEM_sidh_p610_compressed_decaps;
621
622 return kem;
623 }
624
625 /* Forward KEM API calls to SIDH's API */
OQS_KEM_sidh_p610_compressed_keypair(uint8_t * public_key,uint8_t * secret_key)626 OQS_API OQS_STATUS OQS_KEM_sidh_p610_compressed_keypair(uint8_t *public_key, uint8_t *secret_key) {
627 oqs_kem_sidh_p610_compressed_random_mod_order_A((unsigned char *) secret_key);
628 if (oqs_kem_sidh_p610_compressed_EphemeralKeyGeneration_A((unsigned char *) secret_key, (unsigned char *) public_key) != 0) {
629 return OQS_ERROR;
630 }
631 return OQS_SUCCESS;
632 }
633
OQS_KEM_sidh_p610_compressed_encaps(uint8_t * ciphertext,uint8_t * shared_secret,const uint8_t * public_key)634 OQS_API OQS_STATUS OQS_KEM_sidh_p610_compressed_encaps(uint8_t *ciphertext, uint8_t *shared_secret, const uint8_t *public_key) {
635 OQS_STATUS ret = OQS_ERROR;
636 unsigned char *secret_key = malloc(OQS_KEM_sidh_p610_compressed_length_secret_key);
637 oqs_kem_sidh_p610_compressed_random_mod_order_B(secret_key);
638 if (oqs_kem_sidh_p610_compressed_EphemeralKeyGeneration_B(secret_key, (unsigned char *) ciphertext)) {
639 goto err;
640 }
641 if (oqs_kem_sidh_p610_compressed_EphemeralSecretAgreement_B(secret_key, (unsigned char *) public_key, (unsigned char *) shared_secret) != 0) {
642 goto err;
643 }
644 ret = OQS_SUCCESS;
645 goto cleanup;
646
647 err:
648 ret = OQS_ERROR;
649
650 cleanup:
651 if (secret_key != NULL) {
652 OQS_MEM_secure_free(secret_key, OQS_KEM_sidh_p610_compressed_length_secret_key);
653 }
654
655 return ret;
656 }
657
OQS_KEM_sidh_p610_compressed_decaps(uint8_t * shared_secret,const uint8_t * ciphertext,const uint8_t * secret_key)658 OQS_API OQS_STATUS OQS_KEM_sidh_p610_compressed_decaps(uint8_t *shared_secret, const uint8_t *ciphertext, const uint8_t *secret_key) {
659 if (oqs_kem_sidh_p610_compressed_EphemeralSecretAgreement_A((unsigned char *) secret_key, (unsigned char *) ciphertext, (unsigned char *) shared_secret) != 0) {
660 return OQS_ERROR;
661 }
662 return OQS_SUCCESS;
663 }
664
665 #endif
666
667 #ifdef OQS_ENABLE_KEM_sidh_p751
668
669 #include "external/P751/P751_api.h"
670
OQS_KEM_sidh_p751_new()671 OQS_KEM *OQS_KEM_sidh_p751_new() {
672
673 OQS_KEM *kem = malloc(sizeof(OQS_KEM));
674 if (kem == NULL) {
675 return NULL;
676 }
677 kem->method_name = OQS_KEM_alg_sidh_p751;
678 kem->alg_version = "https://github.com/microsoft/PQCrypto-SIDH/commit/28b4b5d0a7926e0e7eb4f9c03f75887236e1cebd";
679
680 kem->claimed_nist_level = 5;
681 kem->ind_cca = false;
682
683 kem->length_public_key = OQS_KEM_sidh_p751_length_public_key;
684 kem->length_secret_key = OQS_KEM_sidh_p751_length_secret_key;
685 kem->length_ciphertext = OQS_KEM_sidh_p751_length_ciphertext;
686 kem->length_shared_secret = OQS_KEM_sidh_p751_length_shared_secret;
687
688 kem->keypair = OQS_KEM_sidh_p751_keypair;
689 kem->encaps = OQS_KEM_sidh_p751_encaps;
690 kem->decaps = OQS_KEM_sidh_p751_decaps;
691
692 return kem;
693 }
694
695 /* Forward KEM API calls to SIDH's API */
OQS_KEM_sidh_p751_keypair(uint8_t * public_key,uint8_t * secret_key)696 OQS_API OQS_STATUS OQS_KEM_sidh_p751_keypair(uint8_t *public_key, uint8_t *secret_key) {
697 oqs_kem_sidh_p751_random_mod_order_A((unsigned char *) secret_key);
698 if (oqs_kem_sidh_p751_EphemeralKeyGeneration_A((unsigned char *) secret_key, (unsigned char *) public_key) != 0) {
699 return OQS_ERROR;
700 }
701 return OQS_SUCCESS;
702 }
703
OQS_KEM_sidh_p751_encaps(uint8_t * ciphertext,uint8_t * shared_secret,const uint8_t * public_key)704 OQS_API OQS_STATUS OQS_KEM_sidh_p751_encaps(uint8_t *ciphertext, uint8_t *shared_secret, const uint8_t *public_key) {
705 OQS_STATUS ret = OQS_ERROR;
706 unsigned char *secret_key = malloc(OQS_KEM_sidh_p751_length_secret_key);
707 oqs_kem_sidh_p751_random_mod_order_B(secret_key);
708 if (oqs_kem_sidh_p751_EphemeralKeyGeneration_B(secret_key, (unsigned char *) ciphertext)) {
709 goto err;
710 }
711 if (oqs_kem_sidh_p751_EphemeralSecretAgreement_B(secret_key, (unsigned char *) public_key, (unsigned char *) shared_secret) != 0) {
712 goto err;
713 }
714 ret = OQS_SUCCESS;
715 goto cleanup;
716
717 err:
718 ret = OQS_ERROR;
719
720 cleanup:
721 if (secret_key != NULL) {
722 OQS_MEM_secure_free(secret_key, OQS_KEM_sidh_p751_length_secret_key);
723 }
724
725 return ret;
726 }
727
OQS_KEM_sidh_p751_decaps(uint8_t * shared_secret,const uint8_t * ciphertext,const uint8_t * secret_key)728 OQS_API OQS_STATUS OQS_KEM_sidh_p751_decaps(uint8_t *shared_secret, const uint8_t *ciphertext, const uint8_t *secret_key) {
729 if (oqs_kem_sidh_p751_EphemeralSecretAgreement_A((unsigned char *) secret_key, (unsigned char *) ciphertext, (unsigned char *) shared_secret) != 0) {
730 return OQS_ERROR;
731 }
732 return OQS_SUCCESS;
733 }
734
735 #endif
736
737 #ifdef OQS_ENABLE_KEM_sidh_p751_compressed
738
739 #include "external/P751/P751_compressed_api.h"
740
OQS_KEM_sidh_p751_compressed_new()741 OQS_KEM *OQS_KEM_sidh_p751_compressed_new() {
742
743 OQS_KEM *kem = malloc(sizeof(OQS_KEM));
744 if (kem == NULL) {
745 return NULL;
746 }
747 kem->method_name = OQS_KEM_alg_sidh_p751_compressed;
748 kem->alg_version = "https://github.com/microsoft/PQCrypto-SIDH/commit/28b4b5d0a7926e0e7eb4f9c03f75887236e1cebd";
749
750 kem->claimed_nist_level = 5;
751 kem->ind_cca = false;
752
753 kem->length_public_key = OQS_KEM_sidh_p751_compressed_length_public_key;
754 kem->length_secret_key = OQS_KEM_sidh_p751_compressed_length_secret_key;
755 kem->length_ciphertext = OQS_KEM_sidh_p751_compressed_length_ciphertext;
756 kem->length_shared_secret = OQS_KEM_sidh_p751_compressed_length_shared_secret;
757
758 kem->keypair = OQS_KEM_sidh_p751_compressed_keypair;
759 kem->encaps = OQS_KEM_sidh_p751_compressed_encaps;
760 kem->decaps = OQS_KEM_sidh_p751_compressed_decaps;
761
762 return kem;
763 }
764
765 /* Forward KEM API calls to SIDH's API */
OQS_KEM_sidh_p751_compressed_keypair(uint8_t * public_key,uint8_t * secret_key)766 OQS_API OQS_STATUS OQS_KEM_sidh_p751_compressed_keypair(uint8_t *public_key, uint8_t *secret_key) {
767 oqs_kem_sidh_p751_compressed_random_mod_order_A((unsigned char *) secret_key);
768 if (oqs_kem_sidh_p751_compressed_EphemeralKeyGeneration_A((unsigned char *) secret_key, (unsigned char *) public_key) != 0) {
769 return OQS_ERROR;
770 }
771 return OQS_SUCCESS;
772 }
773
OQS_KEM_sidh_p751_compressed_encaps(uint8_t * ciphertext,uint8_t * shared_secret,const uint8_t * public_key)774 OQS_API OQS_STATUS OQS_KEM_sidh_p751_compressed_encaps(uint8_t *ciphertext, uint8_t *shared_secret, const uint8_t *public_key) {
775 OQS_STATUS ret = OQS_ERROR;
776 unsigned char *secret_key = malloc(OQS_KEM_sidh_p751_compressed_length_secret_key);
777 oqs_kem_sidh_p751_compressed_random_mod_order_B(secret_key);
778 if (oqs_kem_sidh_p751_compressed_EphemeralKeyGeneration_B(secret_key, (unsigned char *) ciphertext)) {
779 goto err;
780 }
781 if (oqs_kem_sidh_p751_compressed_EphemeralSecretAgreement_B(secret_key, (unsigned char *) public_key, (unsigned char *) shared_secret) != 0) {
782 goto err;
783 }
784 ret = OQS_SUCCESS;
785 goto cleanup;
786
787 err:
788 ret = OQS_ERROR;
789
790 cleanup:
791 if (secret_key != NULL) {
792 OQS_MEM_secure_free(secret_key, OQS_KEM_sidh_p751_compressed_length_secret_key);
793 }
794
795 return ret;
796 }
797
OQS_KEM_sidh_p751_compressed_decaps(uint8_t * shared_secret,const uint8_t * ciphertext,const uint8_t * secret_key)798 OQS_API OQS_STATUS OQS_KEM_sidh_p751_compressed_decaps(uint8_t *shared_secret, const uint8_t *ciphertext, const uint8_t *secret_key) {
799 if (oqs_kem_sidh_p751_compressed_EphemeralSecretAgreement_A((unsigned char *) secret_key, (unsigned char *) ciphertext, (unsigned char *) shared_secret) != 0) {
800 return OQS_ERROR;
801 }
802 return OQS_SUCCESS;
803 }
804
805 #endif
806