1 /* Copyright (c) 2023, Google LLC 2 * 3 * Permission to use, copy, modify, and/or distribute this software for any 4 * purpose with or without fee is hereby granted, provided that the above 5 * copyright notice and this permission notice appear in all copies. 6 * 7 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 10 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 12 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 13 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ 14 15 #ifndef OPENSSL_HEADER_SPX_H 16 #define OPENSSL_HEADER_SPX_H 17 18 #include <openssl/base.h> 19 20 #if defined(__cplusplus) 21 extern "C" { 22 #endif 23 24 25 // SPX_N is the number of bytes in the hash output 26 #define SPX_N 16 27 28 // SPX_PUBLIC_KEY_BYTES is the nNumber of bytes in the public key of 29 // SPHINCS+-SHA2-128s 30 #define SPX_PUBLIC_KEY_BYTES 32 31 32 // SPX_SECRET_KEY_BYTES is the number of bytes in the private key of 33 // SPHINCS+-SHA2-128s 34 #define SPX_SECRET_KEY_BYTES 64 35 36 // SPX_SIGNATURE_BYTES is the number of bytes in a signature of 37 // SPHINCS+-SHA2-128s 38 #define SPX_SIGNATURE_BYTES 7856 39 40 // spx_generate_key generates a SPHINCS+-SHA2-128s key pair and writes the 41 // result to |out_public_key| and |out_secret_key|. 42 // Private key: SK.seed || SK.prf || PK.seed || PK.root 43 // Public key: PK.seed || PK.root 44 OPENSSL_EXPORT void spx_generate_key( 45 uint8_t out_public_key[SPX_PUBLIC_KEY_BYTES], 46 uint8_t out_secret_key[SPX_SECRET_KEY_BYTES]); 47 48 // spx_generate_key_from_seed generates a SPHINCS+-SHA2-128s key pair from a 49 // 48-byte seed and writes the result to |out_public_key| and |out_secret_key|. 50 // Secret key: SK.seed || SK.prf || PK.seed || PK.root 51 // Public key: PK.seed || PK.root 52 OPENSSL_EXPORT void spx_generate_key_from_seed( 53 uint8_t out_public_key[SPX_PUBLIC_KEY_BYTES], 54 uint8_t out_secret_key[SPX_SECRET_KEY_BYTES], 55 const uint8_t seed[3 * SPX_N]); 56 57 // spx_sign generates a SPHINCS+-SHA2-128s signature over |msg| or length 58 // |msg_len| using |secret_key| and writes the output to |out_signature|. 59 // 60 // if |randomized| is 0, deterministic signing is performed, otherwise, 61 // non-deterministic signing is performed. 62 OPENSSL_EXPORT void spx_sign(uint8_t out_snignature[SPX_SIGNATURE_BYTES], 63 const uint8_t secret_key[SPX_SECRET_KEY_BYTES], 64 const uint8_t *msg, size_t msg_len, 65 int randomized); 66 67 // spx_verify verifies a SPHINCS+-SHA2-128s signature in |signature| over |msg| 68 // or length |msg_len| using |public_key|. 1 is returned if the signature 69 // matches, 0 otherwise. 70 OPENSSL_EXPORT int spx_verify(const uint8_t signature[SPX_SIGNATURE_BYTES], 71 const uint8_t public_key[SPX_SECRET_KEY_BYTES], 72 const uint8_t *msg, size_t msg_len); 73 74 75 #if defined(__cplusplus) 76 } // extern C 77 #endif 78 79 #endif // OPENSSL_HEADER_SPX_H 80