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_CRYPTO_DILITHIUM_INTERNAL_H 16 #define OPENSSL_HEADER_CRYPTO_DILITHIUM_INTERNAL_H 17 18 #include <openssl/base.h> 19 #include <openssl/experimental/dilithium.h> 20 21 #if defined(__cplusplus) 22 extern "C" { 23 #endif 24 25 26 // DILITHIUM_GENERATE_KEY_ENTROPY is the number of bytes of uniformly random 27 // entropy necessary to generate a key pair. 28 #define DILITHIUM_GENERATE_KEY_ENTROPY 32 29 30 // DILITHIUM_SIGNATURE_RANDOMIZER_BYTES is the number of bytes of uniformly 31 // random entropy necessary to generate a signature in randomized mode. 32 #define DILITHIUM_SIGNATURE_RANDOMIZER_BYTES 32 33 34 // DILITHIUM_generate_key_external_entropy generates a public/private key pair 35 // using the given seed, writes the encoded public key to 36 // |out_encoded_public_key| and sets |out_private_key| to the private key, 37 // returning 1 on success and 0 on failure. Returns 1 on success and 0 on 38 // failure. 39 OPENSSL_EXPORT int DILITHIUM_generate_key_external_entropy( 40 uint8_t out_encoded_public_key[DILITHIUM_PUBLIC_KEY_BYTES], 41 struct DILITHIUM_private_key *out_private_key, 42 const uint8_t entropy[DILITHIUM_GENERATE_KEY_ENTROPY]); 43 44 // DILITHIUM_sign_deterministic generates a signature for the message |msg| of 45 // length |msg_len| using |private_key| following the deterministic algorithm, 46 // and writes the encoded signature to |out_encoded_signature|. Returns 1 on 47 // success and 0 on failure. 48 OPENSSL_EXPORT int DILITHIUM_sign_deterministic( 49 uint8_t out_encoded_signature[DILITHIUM_SIGNATURE_BYTES], 50 const struct DILITHIUM_private_key *private_key, const uint8_t *msg, 51 size_t msg_len); 52 53 54 #if defined(__cplusplus) 55 } // extern C 56 #endif 57 58 #endif // OPENSSL_HEADER_CRYPTO_DILITHIUM_INTERNAL_H 59