1 // SPDX-License-Identifier: MIT
2 
3 #include <stdlib.h>
4 
5 #include <oqs/sig_sphincs.h>
6 
7 #if defined(OQS_ENABLE_SIG_sphincs_shake256_128s_robust)
8 
OQS_SIG_sphincs_shake256_128s_robust_new()9 OQS_SIG *OQS_SIG_sphincs_shake256_128s_robust_new() {
10 
11 	OQS_SIG *sig = malloc(sizeof(OQS_SIG));
12 	if (sig == NULL) {
13 		return NULL;
14 	}
15 	sig->method_name = OQS_SIG_alg_sphincs_shake256_128s_robust;
16 	sig->alg_version = "https://github.com/sphincs/sphincsplus/commit/77755c94d0bc744478044d6efbb888dc13156441";
17 
18 	sig->claimed_nist_level = 1;
19 	sig->euf_cma = true;
20 
21 	sig->length_public_key = OQS_SIG_sphincs_shake256_128s_robust_length_public_key;
22 	sig->length_secret_key = OQS_SIG_sphincs_shake256_128s_robust_length_secret_key;
23 	sig->length_signature = OQS_SIG_sphincs_shake256_128s_robust_length_signature;
24 
25 	sig->keypair = OQS_SIG_sphincs_shake256_128s_robust_keypair;
26 	sig->sign = OQS_SIG_sphincs_shake256_128s_robust_sign;
27 	sig->verify = OQS_SIG_sphincs_shake256_128s_robust_verify;
28 
29 	return sig;
30 }
31 
32 extern int PQCLEAN_SPHINCSSHAKE256128SROBUST_CLEAN_crypto_sign_keypair(uint8_t *pk, uint8_t *sk);
33 extern int PQCLEAN_SPHINCSSHAKE256128SROBUST_CLEAN_crypto_sign_signature(uint8_t *sig, size_t *siglen, const uint8_t *m, size_t mlen, const uint8_t *sk);
34 extern int PQCLEAN_SPHINCSSHAKE256128SROBUST_CLEAN_crypto_sign_verify(const uint8_t *sig, size_t siglen, const uint8_t *m, size_t mlen, const uint8_t *pk);
35 
36 #if defined(OQS_ENABLE_SIG_sphincs_shake256_128s_robust_avx2)
37 extern int PQCLEAN_SPHINCSSHAKE256128SROBUST_AVX2_crypto_sign_keypair(uint8_t *pk, uint8_t *sk);
38 extern int PQCLEAN_SPHINCSSHAKE256128SROBUST_AVX2_crypto_sign_signature(uint8_t *sig, size_t *siglen, const uint8_t *m, size_t mlen, const uint8_t *sk);
39 extern int PQCLEAN_SPHINCSSHAKE256128SROBUST_AVX2_crypto_sign_verify(const uint8_t *sig, size_t siglen, const uint8_t *m, size_t mlen, const uint8_t *pk);
40 #endif
41 
OQS_SIG_sphincs_shake256_128s_robust_keypair(uint8_t * public_key,uint8_t * secret_key)42 OQS_API OQS_STATUS OQS_SIG_sphincs_shake256_128s_robust_keypair(uint8_t *public_key, uint8_t *secret_key) {
43 #if defined(OQS_ENABLE_SIG_sphincs_shake256_128s_robust_avx2)
44 #if defined(OQS_DIST_BUILD)
45 	if (OQS_CPU_has_extension(OQS_CPU_EXT_AVX2)) {
46 #endif /* OQS_DIST_BUILD */
47 		return (OQS_STATUS) PQCLEAN_SPHINCSSHAKE256128SROBUST_AVX2_crypto_sign_keypair(public_key, secret_key);
48 #if defined(OQS_DIST_BUILD)
49 	} else {
50 		return (OQS_STATUS) PQCLEAN_SPHINCSSHAKE256128SROBUST_CLEAN_crypto_sign_keypair(public_key, secret_key);
51 	}
52 #endif /* OQS_DIST_BUILD */
53 #else
54 	return (OQS_STATUS) PQCLEAN_SPHINCSSHAKE256128SROBUST_CLEAN_crypto_sign_keypair(public_key, secret_key);
55 #endif
56 }
57 
OQS_SIG_sphincs_shake256_128s_robust_sign(uint8_t * signature,size_t * signature_len,const uint8_t * message,size_t message_len,const uint8_t * secret_key)58 OQS_API OQS_STATUS OQS_SIG_sphincs_shake256_128s_robust_sign(uint8_t *signature, size_t *signature_len, const uint8_t *message, size_t message_len, const uint8_t *secret_key) {
59 #if defined(OQS_ENABLE_SIG_sphincs_shake256_128s_robust_avx2)
60 #if defined(OQS_DIST_BUILD)
61 	if (OQS_CPU_has_extension(OQS_CPU_EXT_AVX2)) {
62 #endif /* OQS_DIST_BUILD */
63 		return (OQS_STATUS) PQCLEAN_SPHINCSSHAKE256128SROBUST_AVX2_crypto_sign_signature(signature, signature_len, message, message_len, secret_key);
64 #if defined(OQS_DIST_BUILD)
65 	} else {
66 		return (OQS_STATUS) PQCLEAN_SPHINCSSHAKE256128SROBUST_CLEAN_crypto_sign_signature(signature, signature_len, message, message_len, secret_key);
67 	}
68 #endif /* OQS_DIST_BUILD */
69 #else
70 	return (OQS_STATUS) PQCLEAN_SPHINCSSHAKE256128SROBUST_CLEAN_crypto_sign_signature(signature, signature_len, message, message_len, secret_key);
71 #endif
72 }
73 
OQS_SIG_sphincs_shake256_128s_robust_verify(const uint8_t * message,size_t message_len,const uint8_t * signature,size_t signature_len,const uint8_t * public_key)74 OQS_API OQS_STATUS OQS_SIG_sphincs_shake256_128s_robust_verify(const uint8_t *message, size_t message_len, const uint8_t *signature, size_t signature_len, const uint8_t *public_key) {
75 #if defined(OQS_ENABLE_SIG_sphincs_shake256_128s_robust_avx2)
76 #if defined(OQS_DIST_BUILD)
77 	if (OQS_CPU_has_extension(OQS_CPU_EXT_AVX2)) {
78 #endif /* OQS_DIST_BUILD */
79 		return (OQS_STATUS) PQCLEAN_SPHINCSSHAKE256128SROBUST_AVX2_crypto_sign_verify(signature, signature_len, message, message_len, public_key);
80 #if defined(OQS_DIST_BUILD)
81 	} else {
82 		return (OQS_STATUS) PQCLEAN_SPHINCSSHAKE256128SROBUST_CLEAN_crypto_sign_verify(signature, signature_len, message, message_len, public_key);
83 	}
84 #endif /* OQS_DIST_BUILD */
85 #else
86 	return (OQS_STATUS) PQCLEAN_SPHINCSSHAKE256128SROBUST_CLEAN_crypto_sign_verify(signature, signature_len, message, message_len, public_key);
87 #endif
88 }
89 
90 #endif
91