| 6 | // |
| 7 | // https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 |
| 15 | #ifndef OPENSSL_HEADER_CRYPTO_FIPSMODULE_BCM_INTERFACE_H |
| 16 | #define OPENSSL_HEADER_CRYPTO_FIPSMODULE_BCM_INTERFACE_H |
| 17 |
| 18 | // For the moment, we reach out for AES_KEY. |
| 19 | #include <openssl/aes.h> |
| 20 | #include <openssl/bcm_public.h> |
| 21 |
| 22 |
| 23 | // This header will eventually become the interface between BCM and the |
| 24 | // rest of libcrypto. More cleanly separating the two is still a work in |
| 25 | // progress (see https://crbug.com/boringssl/722) so, at the moment, we |
| 26 | // consider this no different from any other header in BCM. |
| 27 | // |
| 28 | // Over time, calls from libcrypto to BCM will all move to this header |
| 29 | // and the separation will become more meaningful. |
| 30 |
| 31 | #if defined(__cplusplus) |
| 32 | extern "C" { |
| 33 | #endif |
| 34 |
| 35 | // Enumerated types for return values from bcm functions, both infallible |
| 36 | // and fallible functions. Two success values are used to correspond to the |
| 37 | // FIPS service indicator. For the moment, the official service indicator |
| 38 | // remains the counter, not these values. Once we fully transition to |
| 39 | // these return values from bcm we will change that. |
| 40 | enum class bcm_infallible_t { |
| 41 | approved, |
| 42 | not_approved, |
| 43 | }; |
| 44 |
| 45 | enum class bcm_status_t { |
| 46 | approved, |
| 47 | not_approved, |
| 48 | failure, |
| 49 | }; |
| 50 | typedef enum bcm_status_t bcm_status; |
| 51 | typedef enum bcm_infallible_t bcm_infallible; |
| 52 |
| 53 | inline int bcm_success(bcm_status status) { |
| 54 | return status == bcm_status::approved || status == bcm_status::not_approved; |
| 55 | } |
| 56 |
| 57 | inline bcm_status_t bcm_as_approved_status(int result) { |
| 58 | return result ? bcm_status::approved : bcm_status::failure; |
| 59 | } |
| 60 |
| 61 | inline bcm_status_t bcm_as_not_approved_status(int result) { |
| 62 | return result ? bcm_status::not_approved : bcm_status::failure; |
| 63 | } |
| 64 |
| 65 | // Random number generator. |
| 66 |
| 67 | #if defined(BORINGSSL_FIPS) |
| 68 |
| 69 | // We overread from /dev/urandom or RDRAND by a factor of 10 and XOR to whiten. |
| 70 | // TODO(bbe): disentangle this value which is used to calculate the size of the |
| 71 | // stack buffer in RAND_need entropy based on a calculation. |
| 72 | #define BORINGSSL_FIPS_OVERREAD 10 |
| 73 |
| 74 | #endif // BORINGSSL_FIPS |
| 75 |
| 76 | // BCM_rand_load_entropy supplies |entropy_len| bytes of entropy to the BCM |
| 77 | // module. The |want_additional_input| parameter is true iff the entropy was |
| 78 | // obtained from a source other than the system, e.g. directly from the CPU. |
| 79 | bcm_infallible BCM_rand_load_entropy(const uint8_t *entropy, size_t entropy_len, |
| 80 | int want_additional_input); |
| 81 |
| 82 | // BCM_rand_bytes is the same as the public |RAND_bytes| function, other |
| 83 | // than returning a bcm_infallible status indicator. |
| 84 | OPENSSL_EXPORT bcm_infallible BCM_rand_bytes(uint8_t *out, size_t out_len); |
| 85 |
| 86 | // BCM_rand_bytes_hwrng attempts to fill |out| with |len| bytes of entropy from |
| 87 | // the CPU hardware random number generator if one is present. |
| 88 | // bcm_status_approved is returned on success, and a failure status is |
| 89 | // returned otherwise. |
| 90 | bcm_status BCM_rand_bytes_hwrng(uint8_t *out, size_t len); |
| 91 |
| 92 | // BCM_rand_bytes_with_additional_data samples from the RNG after mixing 32 |
| 93 | // bytes from |user_additional_data| in. |
| 94 | bcm_infallible BCM_rand_bytes_with_additional_data( |
| 95 | uint8_t *out, size_t out_len, const uint8_t user_additional_data[32]); |
| 96 |
| 97 |
| 98 | // SHA-1 |
| 99 |
| 100 | // BCM_SHA_DIGEST_LENGTH is the length of a SHA-1 digest. |
| 101 | #define BCM_SHA_DIGEST_LENGTH 20 |
| 102 |
| 103 | // BCM_sha1_init initialises |sha|. |
| 104 | bcm_infallible BCM_sha1_init(SHA_CTX *sha); |
| 105 |
| 106 | // BCM_SHA1_transform is a low-level function that performs a single, SHA-1 |
| 107 | // block transformation using the state from |sha| and |SHA_CBLOCK| bytes from |
| 108 | // |block|. |
| 109 | bcm_infallible BCM_sha1_transform(SHA_CTX *c, |
| 110 | const uint8_t data[BCM_SHA_CBLOCK]); |
| 111 |
| 112 | // BCM_sha1_update adds |len| bytes from |data| to |sha|. |
| 113 | bcm_infallible BCM_sha1_update(SHA_CTX *c, const void *data, size_t len); |
| 114 |
| 115 | // BCM_sha1_final adds the final padding to |sha| and writes the resulting |
| 116 | // digest to |out|, which must have at least |SHA_DIGEST_LENGTH| bytes of space. |
| 117 | bcm_infallible BCM_sha1_final(uint8_t out[BCM_SHA_DIGEST_LENGTH], SHA_CTX *c); |
| 118 |
| 119 |
| 120 | // BCM_fips_186_2_prf derives |out_len| bytes from |xkey| using the PRF |
| 121 | // defined in FIPS 186-2, Appendix 3.1, with change notice 1 applied. The b |
| 122 | // parameter is 160 and seed, XKEY, is also 160 bits. The optional XSEED user |
| 123 | // input is all zeros. |
| 124 | // |
| 125 | // The PRF generates a sequence of 320-bit numbers. Each number is encoded as a |
| 126 | // 40-byte string in big-endian and then concatenated to form |out|. If |
| 127 | // |out_len| is not a multiple of 40, the result is truncated. This matches the |
| 128 | // construction used in Section 7 of RFC 4186 and Section 7 of RFC 4187. |
| 129 | // |
| 130 | // This PRF is based on SHA-1, a weak hash function, and should not be used |
| 131 | // in new protocols. It is provided for compatibility with some legacy EAP |
| 132 | // methods. |
| 133 | bcm_infallible BCM_fips_186_2_prf(uint8_t *out, size_t out_len, |
| 134 | const uint8_t xkey[BCM_SHA_DIGEST_LENGTH]); |
| 135 |
| 136 |
| 137 | // SHA-224 |
| 138 |
| 139 | // SHA224_DIGEST_LENGTH is the length of a SHA-224 digest. |
| 140 | #define BCM_SHA224_DIGEST_LENGTH 28 |
| 141 |
| 142 | // BCM_sha224_unit initialises |sha|. |
| 143 | bcm_infallible BCM_sha224_init(SHA256_CTX *sha); |
| 144 |
| 145 | // BCM_sha224_update adds |len| bytes from |data| to |sha|. |
| 146 | bcm_infallible BCM_sha224_update(SHA256_CTX *sha, const void *data, size_t len); |
| 147 |
| 148 | // BCM_sha224_final adds the final padding to |sha| and writes the resulting |
| 149 | // digest to |out|, which must have at least |SHA224_DIGEST_LENGTH| bytes of |
| 150 | // space. It aborts on programmer error. |
| 151 | bcm_infallible BCM_sha224_final(uint8_t out[BCM_SHA224_DIGEST_LENGTH], |
| 152 | SHA256_CTX *sha); |
| 153 |
| 154 |
| 155 | // SHA-256 |
| 156 |
| 157 | // BCM_SHA256_DIGEST_LENGTH is the length of a SHA-256 digest. |
| 158 | #define BCM_SHA256_DIGEST_LENGTH 32 |
| 159 |
| 160 | // BCM_sha256_init initialises |sha|. |
| 161 | bcm_infallible BCM_sha256_init(SHA256_CTX *sha); |
| 162 |
| 163 | // BCM_sha256_update adds |len| bytes from |data| to |sha|. |
| 164 | bcm_infallible BCM_sha256_update(SHA256_CTX *sha, const void *data, size_t len); |
| 165 |
| 166 | // BCM_sha256_final adds the final padding to |sha| and writes the resulting |
| 167 | // digest to |out|, which must have at least |BCM_SHA256_DIGEST_LENGTH| bytes of |
| 168 | // space. It aborts on programmer error. |
| 169 | bcm_infallible BCM_sha256_final(uint8_t out[BCM_SHA256_DIGEST_LENGTH], |
| 170 | SHA256_CTX *sha); |
| 171 |
| 172 | // BCM_sha256_transform is a low-level function that performs a single, SHA-256 |
| 173 | // block transformation using the state from |sha| and |BCM_SHA256_CBLOCK| bytes |
| 174 | // from |block|. |
| 175 | bcm_infallible BCM_sha256_transform(SHA256_CTX *sha, |
| 176 | const uint8_t block[BCM_SHA256_CBLOCK]); |
| 177 |
| 178 | // BCM_sha256_transform_blocks is a low-level function that takes |num_blocks| * |
| 179 | // |BCM_SHA256_CBLOCK| bytes of data and performs SHA-256 transforms on it to |
| 180 | // update |state|. |
| 181 | bcm_infallible BCM_sha256_transform_blocks(uint32_t state[8], |
| 182 | const uint8_t *data, |
| 183 | size_t num_blocks); |
| 184 |
| 185 |
| 186 | // SHA-384. |
| 187 |
| 188 | // BCM_SHA384_DIGEST_LENGTH is the length of a SHA-384 digest. |
| 189 | #define BCM_SHA384_DIGEST_LENGTH 48 |
| 190 |
| 191 | // BCM_sha384_init initialises |sha|. |
| 192 | bcm_infallible BCM_sha384_init(SHA512_CTX *sha); |
| 193 |
| 194 | // BCM_sha384_update adds |len| bytes from |data| to |sha|. |
| 195 | bcm_infallible BCM_sha384_update(SHA512_CTX *sha, const void *data, size_t len); |
| 196 |
| 197 | // BCM_sha384_final adds the final padding to |sha| and writes the resulting |
| 198 | // digest to |out|, which must have at least |BCM_sha384_DIGEST_LENGTH| bytes of |
| 199 | // space. It may abort on programmer error. |
| 200 | bcm_infallible BCM_sha384_final(uint8_t out[BCM_SHA384_DIGEST_LENGTH], |
| 201 | SHA512_CTX *sha); |
| 202 |
| 203 |
| 204 | // SHA-512. |
| 205 |
| 206 | // BCM_SHA512_DIGEST_LENGTH is the length of a SHA-512 digest. |
| 207 | #define BCM_SHA512_DIGEST_LENGTH 64 |
| 208 |
| 209 | // BCM_sha512_init initialises |sha|. |
| 210 | bcm_infallible BCM_sha512_init(SHA512_CTX *sha); |
| 211 |
| 212 | // BCM_sha512_update adds |len| bytes from |data| to |sha|. |
| 213 | bcm_infallible BCM_sha512_update(SHA512_CTX *sha, const void *data, size_t len); |
| 214 |
| 215 | // BCM_sha512_final adds the final padding to |sha| and writes the resulting |
| 216 | // digest to |out|, which must have at least |BCM_sha512_DIGEST_LENGTH| bytes of |
| 217 | // space. |
| 218 | bcm_infallible BCM_sha512_final(uint8_t out[BCM_SHA512_DIGEST_LENGTH], |
| 219 | SHA512_CTX *sha); |
| 220 |
| 221 | // BCM_sha512_transform is a low-level function that performs a single, SHA-512 |
| 222 | // block transformation using the state from |sha| and |BCM_sha512_CBLOCK| bytes |
| 223 | // from |block|. |
| 224 | bcm_infallible BCM_sha512_transform(SHA512_CTX *sha, |
| 225 | const uint8_t block[BCM_SHA512_CBLOCK]); |
| 226 |
| 227 |
| 228 | // SHA-512-256 |
| 229 | // |
| 230 | // See https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf section 5.3.6 |
| 231 |
| 232 | #define BCM_SHA512_256_DIGEST_LENGTH 32 |
| 233 |
| 234 | // BCM_sha512_256_init initialises |sha|. |
| 235 | bcm_infallible BCM_sha512_256_init(SHA512_CTX *sha); |
| 236 |
| 237 | // BCM_sha512_256_update adds |len| bytes from |data| to |sha|. |
| 238 | bcm_infallible BCM_sha512_256_update(SHA512_CTX *sha, const void *data, |
| 239 | size_t len); |
| 240 |
| 241 | // BCM_sha512_256_final adds the final padding to |sha| and writes the resulting |
| 242 | // digest to |out|, which must have at least |BCM_sha512_256_DIGEST_LENGTH| |
| 243 | // bytes of space. It may abort on programmer error. |
| 244 | bcm_infallible BCM_sha512_256_final(uint8_t out[BCM_SHA512_256_DIGEST_LENGTH], |
| 245 | SHA512_CTX *sha); |
| 246 |
| 247 |
| 248 | // ML-DSA |
| 249 | // |
| 250 | // Where not commented, these functions have the same signature as the |
| 251 | // corresponding public function. |
| 252 |
| 253 | // BCM_MLDSA_SIGNATURE_RANDOMIZER_BYTES is the number of bytes of uniformly |
| 254 | // random entropy necessary to generate a signature in randomized mode. |
| 255 | #define BCM_MLDSA_SIGNATURE_RANDOMIZER_BYTES 32 |
| 256 |
| 257 | // BCM_MLDSA_SEED_BYTES is the number of bytes in an ML-DSA seed value. |
| 258 | #define BCM_MLDSA_SEED_BYTES 32 |
| 259 |
| 260 | // BCM_MLDSA65_PRIVATE_KEY_BYTES is the number of bytes in an encoded ML-DSA-65 |
| 261 | // private key. |
| 262 | #define BCM_MLDSA65_PRIVATE_KEY_BYTES 4032 |
| 263 |
| 264 | // BCM_MLDSA65_PUBLIC_KEY_BYTES is the number of bytes in an encoded ML-DSA-65 |
| 265 | // public key. |
| 266 | #define BCM_MLDSA65_PUBLIC_KEY_BYTES 1952 |
| 267 |
| 268 | // BCM_MLDSA65_SIGNATURE_BYTES is the number of bytes in an encoded ML-DSA-65 |
| 269 | // signature. |
| 270 | #define BCM_MLDSA65_SIGNATURE_BYTES 3309 |
| 271 |
| 272 | struct BCM_mldsa65_private_key { |
| 273 | union { |
| 274 | uint8_t bytes[32 + 32 + 64 + 256 * 4 * (5 + 6 + 6)]; |
| 275 | uint32_t alignment; |
| 276 | } opaque; |
| 277 | }; |
| 278 |
| 279 | struct BCM_mldsa65_public_key { |
| 280 | union { |
| 281 | uint8_t bytes[32 + 64 + 256 * 4 * 6]; |
| 282 | uint32_t alignment; |
| 283 | } opaque; |
| 284 | }; |
| 285 |
| 286 | OPENSSL_EXPORT bcm_status BCM_mldsa65_generate_key( |
| 287 | uint8_t out_encoded_public_key[BCM_MLDSA65_PUBLIC_KEY_BYTES], |
| 288 | uint8_t out_seed[BCM_MLDSA_SEED_BYTES], |
| 289 | struct BCM_mldsa65_private_key *out_private_key); |
| 290 |
| 291 | OPENSSL_EXPORT bcm_status BCM_mldsa65_private_key_from_seed( |
| 292 | struct BCM_mldsa65_private_key *out_private_key, |
| 293 | const uint8_t seed[BCM_MLDSA_SEED_BYTES]); |
| 294 |
| 295 | OPENSSL_EXPORT bcm_status BCM_mldsa65_public_from_private( |
| 296 | struct BCM_mldsa65_public_key *out_public_key, |
| 297 | const struct BCM_mldsa65_private_key *private_key); |
| 298 |
| 299 | OPENSSL_EXPORT bcm_status |
| 300 | BCM_mldsa65_check_key_fips(struct BCM_mldsa65_private_key *private_key); |
| 301 |
| 302 | OPENSSL_EXPORT bcm_status BCM_mldsa65_generate_key_fips( |
| 303 | uint8_t out_encoded_public_key[BCM_MLDSA65_PUBLIC_KEY_BYTES], |
| 304 | uint8_t out_seed[BCM_MLDSA_SEED_BYTES], |
| 305 | struct BCM_mldsa65_private_key *out_private_key); |
| 306 |
| 307 | OPENSSL_EXPORT bcm_status BCM_mldsa65_private_key_from_seed_fips( |
| 308 | struct BCM_mldsa65_private_key *out_private_key, |
| 309 | const uint8_t seed[BCM_MLDSA_SEED_BYTES]); |
| 310 |
| 311 | OPENSSL_EXPORT bcm_status BCM_mldsa65_sign( |
| 312 | uint8_t out_encoded_signature[BCM_MLDSA65_SIGNATURE_BYTES], |
| 313 | const struct BCM_mldsa65_private_key *private_key, const uint8_t *msg, |
| 314 | size_t msg_len, const uint8_t *context, size_t context_len); |
| 315 |
| 316 | OPENSSL_EXPORT bcm_status BCM_mldsa65_verify( |
| 317 | const struct BCM_mldsa65_public_key *public_key, |
| 318 | const uint8_t signature[BCM_MLDSA65_SIGNATURE_BYTES], const uint8_t *msg, |
| 319 | size_t msg_len, const uint8_t *context, size_t context_len); |
| 320 |
| 321 | OPENSSL_EXPORT bcm_status BCM_mldsa65_marshal_public_key( |
| 322 | CBB *out, const struct BCM_mldsa65_public_key *public_key); |
| 323 |
| 324 | OPENSSL_EXPORT bcm_status BCM_mldsa65_parse_public_key( |
| 325 | struct BCM_mldsa65_public_key *public_key, CBS *in); |
| 326 |
| 327 | OPENSSL_EXPORT bcm_status BCM_mldsa65_parse_private_key( |
| 328 | struct BCM_mldsa65_private_key *private_key, CBS *in); |
| 329 |
| 330 | // BCM_mldsa65_generate_key_external_entropy generates a public/private key pair |
| 331 | // using the given seed, writes the encoded public key to |
| 332 | // |out_encoded_public_key| and sets |out_private_key| to the private key. |
| 333 | OPENSSL_EXPORT bcm_status BCM_mldsa65_generate_key_external_entropy( |
| 334 | uint8_t out_encoded_public_key[BCM_MLDSA65_PUBLIC_KEY_BYTES], |
| 335 | struct BCM_mldsa65_private_key *out_private_key, |
| 336 | const uint8_t entropy[BCM_MLDSA_SEED_BYTES]); |
| 337 |
| 338 | OPENSSL_EXPORT bcm_status BCM_mldsa65_generate_key_external_entropy_fips( |
| 339 | uint8_t out_encoded_public_key[BCM_MLDSA65_PUBLIC_KEY_BYTES], |
| 340 | struct BCM_mldsa65_private_key *out_private_key, |
| 341 | const uint8_t entropy[BCM_MLDSA_SEED_BYTES]); |
| 342 |
| 343 | // BCM_mldsa5_sign_internal signs |msg| using |private_key| and writes the |
| 344 | // signature to |out_encoded_signature|. The |context_prefix| and |context| are |
| 345 | // prefixed to the message, in that order, before signing. The |randomizer| |
| 346 | // value can be set to zero bytes in order to make a deterministic signature, or |
| 347 | // else filled with entropy for the usual |MLDSA_sign| behavior. |
| 348 | OPENSSL_EXPORT bcm_status BCM_mldsa65_sign_internal( |
| 349 | uint8_t out_encoded_signature[BCM_MLDSA65_SIGNATURE_BYTES], |
| 350 | const struct BCM_mldsa65_private_key *private_key, const uint8_t *msg, |
| 351 | size_t msg_len, const uint8_t *context_prefix, size_t context_prefix_len, |
| 352 | const uint8_t *context, size_t context_len, |
| 353 | const uint8_t randomizer[BCM_MLDSA_SIGNATURE_RANDOMIZER_BYTES]); |
| 354 |
| 355 | // BCM_mldsa5_verify_internal verifies that |encoded_signature| is a valid |
| 356 | // signature of |msg| by |public_key|. The |context_prefix| and |context| are |
| 357 | // prefixed to the message before verification, in that order. |
| 358 | OPENSSL_EXPORT bcm_status BCM_mldsa65_verify_internal( |
| 359 | const struct BCM_mldsa65_public_key *public_key, |
| 360 | const uint8_t encoded_signature[BCM_MLDSA65_SIGNATURE_BYTES], |
| 361 | const uint8_t *msg, size_t msg_len, const uint8_t *context_prefix, |
| 362 | size_t context_prefix_len, const uint8_t *context, size_t context_len); |
| 363 |
| 364 | // BCM_mldsa65_marshal_private_key serializes |private_key| to |out| in the |
| 365 | // NIST format for ML-DSA-65 private keys. |
| 366 | OPENSSL_EXPORT bcm_status BCM_mldsa65_marshal_private_key( |
| 367 | CBB *out, const struct BCM_mldsa65_private_key *private_key); |
| 368 |
| 369 |
| 370 | // BCM_MLDSA87_PRIVATE_KEY_BYTES is the number of bytes in an encoded ML-DSA-87 |
| 371 | // private key. |
| 372 | #define BCM_MLDSA87_PRIVATE_KEY_BYTES 4896 |
| 373 |
| 374 | // BCM_MLDSA87_PUBLIC_KEY_BYTES is the number of bytes in an encoded ML-DSA-87 |
| 375 | // public key. |
| 376 | #define BCM_MLDSA87_PUBLIC_KEY_BYTES 2592 |
| 377 |
| 378 | // BCM_MLDSA87_SIGNATURE_BYTES is the number of bytes in an encoded ML-DSA-87 |
| 379 | // signature. |
| 380 | #define BCM_MLDSA87_SIGNATURE_BYTES 4627 |
| 381 |
| 382 | struct BCM_mldsa87_private_key { |
| 383 | union { |
| 384 | uint8_t bytes[32 + 32 + 64 + 256 * 4 * (7 + 8 + 8)]; |
| 385 | uint32_t alignment; |
| 386 | } opaque; |
| 387 | }; |
| 388 |
| 389 | struct BCM_mldsa87_public_key { |
| 390 | union { |
| 391 | uint8_t bytes[32 + 64 + 256 * 4 * 8]; |
| 392 | uint32_t alignment; |
| 393 | } opaque; |
| 394 | }; |
| 395 |
| 396 | OPENSSL_EXPORT bcm_status BCM_mldsa87_generate_key( |
| 397 | uint8_t out_encoded_public_key[BCM_MLDSA87_PUBLIC_KEY_BYTES], |
| 398 | uint8_t out_seed[BCM_MLDSA_SEED_BYTES], |
| 399 | struct BCM_mldsa87_private_key *out_private_key); |
| 400 |
| 401 | OPENSSL_EXPORT bcm_status BCM_mldsa87_private_key_from_seed( |
| 402 | struct BCM_mldsa87_private_key *out_private_key, |
| 403 | const uint8_t seed[BCM_MLDSA_SEED_BYTES]); |
| 404 |
| 405 | OPENSSL_EXPORT bcm_status BCM_mldsa87_public_from_private( |
| 406 | struct BCM_mldsa87_public_key *out_public_key, |
| 407 | const struct BCM_mldsa87_private_key *private_key); |
| 408 |
| 409 | OPENSSL_EXPORT bcm_status |
| 410 | BCM_mldsa87_check_key_fips(struct BCM_mldsa87_private_key *private_key); |
| 411 |
| 412 | OPENSSL_EXPORT bcm_status BCM_mldsa87_generate_key_fips( |
| 413 | uint8_t out_encoded_public_key[BCM_MLDSA87_PUBLIC_KEY_BYTES], |
| 414 | uint8_t out_seed[BCM_MLDSA_SEED_BYTES], |
| 415 | struct BCM_mldsa87_private_key *out_private_key); |
| 416 |
| 417 | OPENSSL_EXPORT bcm_status BCM_mldsa87_private_key_from_seed_fips( |
| 418 | struct BCM_mldsa87_private_key *out_private_key, |
| 419 | const uint8_t seed[BCM_MLDSA_SEED_BYTES]); |
| 420 |
| 421 | OPENSSL_EXPORT bcm_status BCM_mldsa87_sign( |
| 422 | uint8_t out_encoded_signature[BCM_MLDSA87_SIGNATURE_BYTES], |
| 423 | const struct BCM_mldsa87_private_key *private_key, const uint8_t *msg, |
| 424 | size_t msg_len, const uint8_t *context, size_t context_len); |
| 425 |
| 426 | OPENSSL_EXPORT bcm_status |
| 427 | BCM_mldsa87_verify(const struct BCM_mldsa87_public_key *public_key, |
| 428 | const uint8_t *signature, const uint8_t *msg, size_t msg_len, |
| 429 | const uint8_t *context, size_t context_len); |
| 430 |
| 431 | OPENSSL_EXPORT bcm_status BCM_mldsa87_marshal_public_key( |
| 432 | CBB *out, const struct BCM_mldsa87_public_key *public_key); |
| 433 |
| 434 | OPENSSL_EXPORT bcm_status BCM_mldsa87_parse_public_key( |
| 435 | struct BCM_mldsa87_public_key *public_key, CBS *in); |
| 436 |
| 437 | OPENSSL_EXPORT bcm_status BCM_mldsa87_parse_private_key( |
| 438 | struct BCM_mldsa87_private_key *private_key, CBS *in); |
| 439 |
| 440 | // BCM_mldsa87_generate_key_external_entropy generates a public/private key pair |
| 441 | // using the given seed, writes the encoded public key to |
| 442 | // |out_encoded_public_key| and sets |out_private_key| to the private key. |
| 443 | OPENSSL_EXPORT bcm_status BCM_mldsa87_generate_key_external_entropy( |
| 444 | uint8_t out_encoded_public_key[BCM_MLDSA87_PUBLIC_KEY_BYTES], |
| 445 | struct BCM_mldsa87_private_key *out_private_key, |
| 446 | const uint8_t entropy[BCM_MLDSA_SEED_BYTES]); |
| 447 |
| 448 | OPENSSL_EXPORT bcm_status BCM_mldsa87_generate_key_external_entropy_fips( |
| 449 | uint8_t out_encoded_public_key[BCM_MLDSA87_PUBLIC_KEY_BYTES], |
| 450 | struct BCM_mldsa87_private_key *out_private_key, |
| 451 | const uint8_t entropy[BCM_MLDSA_SEED_BYTES]); |
| 452 |
| 453 | // BCM_mldsa87_sign_internal signs |msg| using |private_key| and writes the |
| 454 | // signature to |out_encoded_signature|. The |context_prefix| and |context| are |
| 455 | // prefixed to the message, in that order, before signing. The |randomizer| |
| 456 | // value can be set to zero bytes in order to make a deterministic signature, or |
| 457 | // else filled with entropy for the usual |MLDSA_sign| behavior. |
| 458 | OPENSSL_EXPORT bcm_status BCM_mldsa87_sign_internal( |
| 459 | uint8_t out_encoded_signature[BCM_MLDSA87_SIGNATURE_BYTES], |
| 460 | const struct BCM_mldsa87_private_key *private_key, const uint8_t *msg, |
| 461 | size_t msg_len, const uint8_t *context_prefix, size_t context_prefix_len, |
| 462 | const uint8_t *context, size_t context_len, |
| 463 | const uint8_t randomizer[BCM_MLDSA_SIGNATURE_RANDOMIZER_BYTES]); |
| 464 |
| 465 | // BCM_mldsa87_verify_internal verifies that |encoded_signature| is a valid |
| 466 | // signature of |msg| by |public_key|. The |context_prefix| and |context| are |
| 467 | // prefixed to the message before verification, in that order. |
| 468 | OPENSSL_EXPORT bcm_status BCM_mldsa87_verify_internal( |
| 469 | const struct BCM_mldsa87_public_key *public_key, |
| 470 | const uint8_t encoded_signature[BCM_MLDSA87_SIGNATURE_BYTES], |
| 471 | const uint8_t *msg, size_t msg_len, const uint8_t *context_prefix, |
| 472 | size_t context_prefix_len, const uint8_t *context, size_t context_len); |
| 473 |
| 474 | // BCM_mldsa87_marshal_private_key serializes |private_key| to |out| in the |
| 475 | // NIST format for ML-DSA-87 private keys. |
| 476 | OPENSSL_EXPORT bcm_status BCM_mldsa87_marshal_private_key( |
| 477 | CBB *out, const struct BCM_mldsa87_private_key *private_key); |
| 478 |
| 479 |
| 480 | // ML-KEM |
| 481 | // |
| 482 | // Where not commented, these functions have the same signature as the |
| 483 | // corresponding public function. |
| 484 |
| 485 | // BCM_MLKEM_ENCAP_ENTROPY is the number of bytes of uniformly random entropy |
| 486 | // necessary to encapsulate a secret. The entropy will be leaked to the |
| 487 | // decapsulating party. |
| 488 | #define BCM_MLKEM_ENCAP_ENTROPY 32 |
| 489 |
| 490 | // BCM_MLKEM768_PUBLIC_KEY_BYTES is the number of bytes in an encoded ML-KEM-768 |
| 491 | // public key. |
| 492 | #define BCM_MLKEM768_PUBLIC_KEY_BYTES 1184 |
| 493 |
| 494 | // BCM_MLKEM1024_PUBLIC_KEY_BYTES is the number of bytes in an encoded |
| 495 | // ML-KEM-1024 public key. |
| 496 | #define BCM_MLKEM1024_PUBLIC_KEY_BYTES 1568 |
| 497 |
| 498 | // BCM_MLKEM768_CIPHERTEXT_BYTES is number of bytes in the ML-KEM-768 |
| 499 | // ciphertext. |
| 500 | #define BCM_MLKEM768_CIPHERTEXT_BYTES 1088 |
| 501 |
| 502 | // BCM_MLKEM1024_CIPHERTEXT_BYTES is number of bytes in the ML-KEM-1024 |
| 503 | // ciphertext. |
| 504 | #define BCM_MLKEM1024_CIPHERTEXT_BYTES 1568 |
| 505 |
| 506 | // BCM_MLKEM768_PRIVATE_KEY_BYTES is the length of the data produced by |
| 507 | // |BCM_mlkem768_marshal_private_key|. |
| 508 | #define BCM_MLKEM768_PRIVATE_KEY_BYTES 2400 |
| 509 |
| 510 | // BCM_MLKEM1024_PRIVATE_KEY_BYTES is the length of the data produced by |
| 511 | // |BCM_mlkem1024_marshal_private_key|. |
| 512 | #define BCM_MLKEM1024_PRIVATE_KEY_BYTES 3168 |
| 513 |
| 514 | // BCM_MLKEM_SEED_BYTES is the number of bytes in an ML-KEM seed. |
| 515 | #define BCM_MLKEM_SEED_BYTES 64 |
| 516 |
| 517 | // BCM_mlkem_SHARED_SECRET_BYTES is the number of bytes in an ML-KEM shared |
| 518 | // secret. |
| 519 | #define BCM_MLKEM_SHARED_SECRET_BYTES 32 |
| 520 |
| 521 | struct BCM_mlkem768_public_key { |
| 522 | union { |
| 523 | uint8_t bytes[512 * (3 + 9) + 32 + 32]; |
| 524 | uint16_t alignment; |
| 525 | } opaque; |
| 526 | }; |
| 527 |
| 528 | struct BCM_mlkem768_private_key { |
| 529 | union { |
| 530 | uint8_t bytes[512 * (3 + 3 + 9) + 32 + 32 + 32]; |
| 531 | uint16_t alignment; |
| 532 | } opaque; |
| 533 | }; |
| 534 |
| 535 |
| 536 |
| 537 | OPENSSL_EXPORT bcm_infallible BCM_mlkem768_generate_key( |
| 538 | uint8_t out_encoded_public_key[BCM_MLKEM768_PUBLIC_KEY_BYTES], |
| 539 | uint8_t optional_out_seed[BCM_MLKEM_SEED_BYTES], |
| 540 | struct BCM_mlkem768_private_key *out_private_key); |
| 541 |
| 542 | OPENSSL_EXPORT bcm_status BCM_mlkem768_private_key_from_seed( |
| 543 | struct BCM_mlkem768_private_key *out_private_key, const uint8_t *seed, |
| 544 | size_t seed_len); |
| 545 |
| 546 | OPENSSL_EXPORT bcm_status BCM_mlkem768_generate_key_fips( |
| 547 | uint8_t out_encoded_public_key[BCM_MLKEM768_PUBLIC_KEY_BYTES], |
| 548 | uint8_t optional_out_seed[BCM_MLKEM_SEED_BYTES], |
| 549 | struct BCM_mlkem768_private_key *out_private_key); |
| 550 |
| 551 | OPENSSL_EXPORT bcm_status |
| 552 | BCM_mlkem768_check_fips(const struct BCM_mlkem768_private_key *private_key); |
| 553 |
| 554 | OPENSSL_EXPORT bcm_infallible BCM_mlkem768_public_from_private( |
| 555 | struct BCM_mlkem768_public_key *out_public_key, |
| 556 | const struct BCM_mlkem768_private_key *private_key); |
| 557 |
| 558 | OPENSSL_EXPORT bcm_infallible |
| 559 | BCM_mlkem768_encap(uint8_t out_ciphertext[BCM_MLKEM768_CIPHERTEXT_BYTES], |
| 560 | uint8_t out_shared_secret[BCM_MLKEM_SHARED_SECRET_BYTES], |
| 561 | const struct BCM_mlkem768_public_key *public_key); |
| 562 |
| 563 | OPENSSL_EXPORT bcm_status |
| 564 | BCM_mlkem768_decap(uint8_t out_shared_secret[BCM_MLKEM_SHARED_SECRET_BYTES], |
| 565 | const uint8_t *ciphertext, size_t ciphertext_len, |
| 566 | const struct BCM_mlkem768_private_key *private_key); |
| 567 |
| 568 | OPENSSL_EXPORT bcm_status BCM_mlkem768_marshal_public_key( |
| 569 | CBB *out, const struct BCM_mlkem768_public_key *public_key); |
| 570 |
| 571 | OPENSSL_EXPORT bcm_status BCM_mlkem768_parse_public_key( |
| 572 | struct BCM_mlkem768_public_key *out_public_key, CBS *in); |
| 573 |
| 574 | // BCM_mlkem768_parse_private_key parses a private key, in NIST's format for |
| 575 | // private keys, from |in| and writes the result to |out_private_key|. It |
| 576 | // returns one on success or zero on parse error or if there are trailing bytes |
| 577 | // in |in|. This format is verbose and should be avoided. Private keys should be |
| 578 | // stored as seeds and parsed using |BCM_mlkem768_private_key_from_seed|. |
| 579 | OPENSSL_EXPORT bcm_status BCM_mlkem768_parse_private_key( |
| 580 | struct BCM_mlkem768_private_key *out_private_key, CBS *in); |
| 581 |
| 582 | // BCM_mlkem768_generate_key_external_seed is a deterministic function to create |
| 583 | // a pair of ML-KEM-768 keys, using the supplied seed. The seed needs to be |
| 584 | // uniformly random. This function should only be used for tests; regular |
| 585 | // callers should use the non-deterministic |BCM_mlkem768_generate_key| |
| 586 | // directly. |
| 587 | OPENSSL_EXPORT bcm_infallible BCM_mlkem768_generate_key_external_seed( |
| 588 | uint8_t out_encoded_public_key[BCM_MLKEM768_PUBLIC_KEY_BYTES], |
| 589 | struct BCM_mlkem768_private_key *out_private_key, |
| 590 | const uint8_t seed[BCM_MLKEM_SEED_BYTES]); |
| 591 |
| 592 | // BCM_mlkem768_encap_external_entropy behaves like |MLKEM768_encap|, but uses |
| 593 | // |MLKEM_ENCAP_ENTROPY| bytes of |entropy| for randomization. The decapsulating |
| 594 | // side will be able to recover |entropy| in full. This function should only be |
| 595 | // used for tests, regular callers should use the non-deterministic |
| 596 | // |BCM_mlkem768_encap| directly. |
| 597 | OPENSSL_EXPORT bcm_infallible BCM_mlkem768_encap_external_entropy( |
| 598 | uint8_t out_ciphertext[BCM_MLKEM768_CIPHERTEXT_BYTES], |
| 599 | uint8_t out_shared_secret[BCM_MLKEM_SHARED_SECRET_BYTES], |
| 600 | const struct BCM_mlkem768_public_key *public_key, |
| 601 | const uint8_t entropy[BCM_MLKEM_ENCAP_ENTROPY]); |
| 602 |
| 603 | // BCM_mlkem768_marshal_private_key serializes |private_key| to |out| in the |
| 604 | // NIST format for ML-KEM-768 private keys. (Note that one can also save just |
| 605 | // the seed value produced by |BCM_mlkem768_generate_key|, which is |
| 606 | // significantly smaller.) |
| 607 | OPENSSL_EXPORT bcm_status BCM_mlkem768_marshal_private_key( |
| 608 | CBB *out, const struct BCM_mlkem768_private_key *private_key); |
| 609 |
| 610 | struct BCM_mlkem1024_public_key { |
| 611 | union { |
| 612 | uint8_t bytes[512 * (4 + 16) + 32 + 32]; |
| 613 | uint16_t alignment; |
| 614 | } opaque; |
| 615 | }; |
| 616 |
| 617 | struct BCM_mlkem1024_private_key { |
| 618 | union { |
| 619 | uint8_t bytes[512 * (4 + 4 + 16) + 32 + 32 + 32]; |
| 620 | uint16_t alignment; |
| 621 | } opaque; |
| 622 | }; |
| 623 |
| 624 | OPENSSL_EXPORT bcm_infallible BCM_mlkem1024_generate_key( |
| 625 | uint8_t out_encoded_public_key[BCM_MLKEM1024_PUBLIC_KEY_BYTES], |
| 626 | uint8_t optional_out_seed[BCM_MLKEM_SEED_BYTES], |
| 627 | struct BCM_mlkem1024_private_key *out_private_key); |
| 628 |
| 629 | OPENSSL_EXPORT bcm_status BCM_mlkem1024_generate_key_fips( |
| 630 | uint8_t out_encoded_public_key[BCM_MLKEM1024_PUBLIC_KEY_BYTES], |
| 631 | uint8_t optional_out_seed[BCM_MLKEM_SEED_BYTES], |
| 632 | struct BCM_mlkem1024_private_key *out_private_key); |
| 633 |
| 634 | OPENSSL_EXPORT bcm_status |
| 635 | BCM_mlkem1024_check_fips(const struct BCM_mlkem1024_private_key *private_key); |
| 636 |
| 637 | OPENSSL_EXPORT bcm_status BCM_mlkem1024_private_key_from_seed( |
| 638 | struct BCM_mlkem1024_private_key *out_private_key, const uint8_t *seed, |
| 639 | size_t seed_len); |
| 640 |
| 641 | OPENSSL_EXPORT bcm_infallible BCM_mlkem1024_public_from_private( |
| 642 | struct BCM_mlkem1024_public_key *out_public_key, |
| 643 | const struct BCM_mlkem1024_private_key *private_key); |
| 644 |
| 645 | OPENSSL_EXPORT bcm_infallible |
| 646 | BCM_mlkem1024_encap(uint8_t out_ciphertext[BCM_MLKEM1024_CIPHERTEXT_BYTES], |
| 647 | uint8_t out_shared_secret[BCM_MLKEM_SHARED_SECRET_BYTES], |
| 648 | const struct BCM_mlkem1024_public_key *public_key); |
| 649 |
| 650 | OPENSSL_EXPORT bcm_status |
| 651 | BCM_mlkem1024_decap(uint8_t out_shared_secret[BCM_MLKEM_SHARED_SECRET_BYTES], |
| 652 | const uint8_t *ciphertext, size_t ciphertext_len, |
| 653 | const struct BCM_mlkem1024_private_key *private_key); |
| 654 |
| 655 | OPENSSL_EXPORT bcm_status BCM_mlkem1024_marshal_public_key( |
| 656 | CBB *out, const struct BCM_mlkem1024_public_key *public_key); |
| 657 |
| 658 | OPENSSL_EXPORT bcm_status BCM_mlkem1024_parse_public_key( |
| 659 | struct BCM_mlkem1024_public_key *out_public_key, CBS *in); |
| 660 |
| 661 | // BCM_mlkem1024_parse_private_key parses a private key, in NIST's format for |
| 662 | // private keys, from |in| and writes the result to |out_private_key|. It |
| 663 | // returns one on success or zero on parse error or if there are trailing bytes |
| 664 | // in |in|. This format is verbose and should be avoided. Private keys should be |
| 665 | // stored as seeds and parsed using |BCM_mlkem1024_private_key_from_seed|. |
| 666 | OPENSSL_EXPORT bcm_status BCM_mlkem1024_parse_private_key( |
| 667 | struct BCM_mlkem1024_private_key *out_private_key, CBS *in); |
| 668 |
| 669 | // BCM_mlkem1024_generate_key_external_seed is a deterministic function to |
| 670 | // create a pair of ML-KEM-1024 keys, using the supplied seed. The seed needs to |
| 671 | // be uniformly random. This function should only be used for tests, regular |
| 672 | // callers should use the non-deterministic |BCM_mlkem1024_generate_key| |
| 673 | // directly. |
| 674 | OPENSSL_EXPORT bcm_infallible BCM_mlkem1024_generate_key_external_seed( |
| 675 | uint8_t out_encoded_public_key[BCM_MLKEM1024_PUBLIC_KEY_BYTES], |
| 676 | struct BCM_mlkem1024_private_key *out_private_key, |
| 677 | const uint8_t seed[BCM_MLKEM_SEED_BYTES]); |
| 678 |
| 679 | // BCM_mlkem1024_encap_external_entropy behaves like |MLKEM1024_encap|, but uses |
| 680 | // |MLKEM_ENCAP_ENTROPY| bytes of |entropy| for randomization. The |
| 681 | // decapsulating side will be able to recover |entropy| in full. This function |
| 682 | // should only be used for tests, regular callers should use the |
| 683 | // non-deterministic |BCM_mlkem1024_encap| directly. |
| 684 | OPENSSL_EXPORT bcm_infallible BCM_mlkem1024_encap_external_entropy( |
| 685 | uint8_t out_ciphertext[BCM_MLKEM1024_CIPHERTEXT_BYTES], |
| 686 | uint8_t out_shared_secret[BCM_MLKEM_SHARED_SECRET_BYTES], |
| 687 | const struct BCM_mlkem1024_public_key *public_key, |
| 688 | const uint8_t entropy[BCM_MLKEM_ENCAP_ENTROPY]); |
| 689 |
| 690 | // BCM_mlkem1024_marshal_private_key serializes |private_key| to |out| in the |
| 691 | // NIST format for ML-KEM-1024 private keys. (Note that one can also save just |
| 692 | // the seed value produced by |BCM_mlkem1024_generate_key|, which is |
| 693 | // significantly smaller.) |
| 694 | OPENSSL_EXPORT bcm_status BCM_mlkem1024_marshal_private_key( |
| 695 | CBB *out, const struct BCM_mlkem1024_private_key *private_key); |
| 696 |
| 697 |
| 698 | // SLH-DSA |
| 699 |
| 700 | // Output length of the hash function. |
| 701 | #define BCM_SLHDSA_SHA2_128S_N 16 |
| 702 |
| 703 | // The number of bytes at the beginning of M', the augmented message, before the |
| 704 | // context. |
| 705 | #define BCM_SLHDSA_M_PRIME_HEADER_LEN 2 |
| 706 |
| 707 | // SLHDSA_SHA2_128S_PUBLIC_KEY_BYTES is the number of bytes in an |
| 708 | // SLH-DSA-SHA2-128s public key. |
| 709 | #define BCM_SLHDSA_SHA2_128S_PUBLIC_KEY_BYTES 32 |
| 710 |
| 711 | // BCM_SLHDSA_SHA2_128S_PRIVATE_KEY_BYTES is the number of bytes in an |
| 712 | // SLH-DSA-SHA2-128s private key. |
| 713 | #define BCM_SLHDSA_SHA2_128S_PRIVATE_KEY_BYTES 64 |
| 714 |
| 715 | // BCM_SLHDSA_SHA2_128S_SIGNATURE_BYTES is the number of bytes in an |
| 716 | // SLH-DSA-SHA2-128s signature. |
| 717 | #define BCM_SLHDSA_SHA2_128S_SIGNATURE_BYTES 7856 |
| 718 |
| 719 | // BCM_slhdsa_sha2_128s_generate_key_from_seed generates an SLH-DSA-SHA2-128s |
| 720 | // key pair from a 48-byte seed and writes the result to |out_public_key| and |
| 721 | // |out_secret_key|. |
| 722 | OPENSSL_EXPORT bcm_infallible BCM_slhdsa_sha2_128s_generate_key_from_seed( |
| 723 | uint8_t out_public_key[BCM_SLHDSA_SHA2_128S_PUBLIC_KEY_BYTES], |
| 724 | uint8_t out_secret_key[BCM_SLHDSA_SHA2_128S_PRIVATE_KEY_BYTES], |
| 725 | const uint8_t seed[3 * BCM_SLHDSA_SHA2_128S_N]); |
| 726 |
| 727 | // BCM_slhdsa_sha2_128s_generate_key_from_seed_fips does the same thing as |
| 728 | // `BCM_slhdsa_sha2_128s_generate_key_from_seed` but implements the required |
| 729 | // second check before generating a key by testing for nullptr arguments. |
| 730 | OPENSSL_EXPORT bcm_status BCM_slhdsa_sha2_128s_generate_key_from_seed_fips( |
| 731 | uint8_t out_public_key[BCM_SLHDSA_SHA2_128S_PUBLIC_KEY_BYTES], |
| 732 | uint8_t out_secret_key[BCM_SLHDSA_SHA2_128S_PRIVATE_KEY_BYTES], |
| 733 | const uint8_t seed[3 * BCM_SLHDSA_SHA2_128S_N]); |
| 734 |
| 735 | // BCM_slhdsa_sha2_128s_sign_internal acts like |SLHDSA_SHA2_128S_sign| but |
| 736 | // accepts an explicit entropy input, which can be PK.seed (bytes 32..48 of |
| 737 | // the private key) to generate deterministic signatures. It also takes the |
| 738 | // input message in three parts so that the "internal" version of the signing |
| 739 | // function, from section 9.2, can be implemented. The |header| argument may be |
| 740 | // NULL to omit it. |
| 741 | OPENSSL_EXPORT bcm_infallible BCM_slhdsa_sha2_128s_sign_internal( |
| 742 | uint8_t out_signature[BCM_SLHDSA_SHA2_128S_SIGNATURE_BYTES], |
| 743 | const uint8_t secret_key[BCM_SLHDSA_SHA2_128S_PRIVATE_KEY_BYTES], |
| 744 | const uint8_t header[BCM_SLHDSA_M_PRIME_HEADER_LEN], const uint8_t *context, |
| 745 | size_t context_len, const uint8_t *msg, size_t msg_len, |
| 746 | const uint8_t entropy[BCM_SLHDSA_SHA2_128S_N]); |
| 747 |
| 748 | // BCM_slhdsa_sha2_128s_verify_internal acts like |SLHDSA_SHA2_128S_verify| but |
| 749 | // takes the input message in three parts so that the "internal" version of the |
| 750 | // verification function, from section 9.3, can be implemented. The |header| |
| 751 | // argument may be NULL to omit it. |
| 752 | OPENSSL_EXPORT bcm_status BCM_slhdsa_sha2_128s_verify_internal( |
| 753 | const uint8_t *signature, size_t signature_len, |
| 754 | const uint8_t public_key[BCM_SLHDSA_SHA2_128S_PUBLIC_KEY_BYTES], |
| 755 | const uint8_t header[BCM_SLHDSA_M_PRIME_HEADER_LEN], const uint8_t *context, |
| 756 | size_t context_len, const uint8_t *msg, size_t msg_len); |
| 757 |
| 758 | OPENSSL_EXPORT bcm_infallible BCM_slhdsa_sha2_128s_generate_key( |
| 759 | uint8_t out_public_key[BCM_SLHDSA_SHA2_128S_PUBLIC_KEY_BYTES], |
| 760 | uint8_t out_private_key[BCM_SLHDSA_SHA2_128S_PRIVATE_KEY_BYTES]); |
| 761 |
| 762 | OPENSSL_EXPORT bcm_status BCM_slhdsa_sha2_128s_generate_key_fips( |
| 763 | uint8_t out_public_key[BCM_SLHDSA_SHA2_128S_PUBLIC_KEY_BYTES], |
| 764 | uint8_t out_private_key[BCM_SLHDSA_SHA2_128S_PRIVATE_KEY_BYTES]); |
| 765 |
| 766 | OPENSSL_EXPORT bcm_infallible BCM_slhdsa_sha2_128s_public_from_private( |
| 767 | uint8_t out_public_key[BCM_SLHDSA_SHA2_128S_PUBLIC_KEY_BYTES], |
| 768 | const uint8_t private_key[BCM_SLHDSA_SHA2_128S_PRIVATE_KEY_BYTES]); |
| 769 |
| 770 | OPENSSL_EXPORT bcm_status BCM_slhdsa_sha2_128s_sign( |
| 771 | uint8_t out_signature[BCM_SLHDSA_SHA2_128S_SIGNATURE_BYTES], |
| 772 | const uint8_t private_key[BCM_SLHDSA_SHA2_128S_PRIVATE_KEY_BYTES], |
| 773 | const uint8_t *msg, size_t msg_len, const uint8_t *context, |
| 774 | size_t context_len); |
| 775 |
| 776 | OPENSSL_EXPORT bcm_status BCM_slhdsa_sha2_128s_verify( |
| 777 | const uint8_t *signature, size_t signature_len, |
| 778 | const uint8_t public_key[BCM_SLHDSA_SHA2_128S_PUBLIC_KEY_BYTES], |
| 779 | const uint8_t *msg, size_t msg_len, const uint8_t *context, |
| 780 | size_t context_len); |
| 781 |
| 782 | OPENSSL_EXPORT bcm_status BCM_slhdsa_sha2_128s_prehash_sign( |
| 783 | uint8_t out_signature[BCM_SLHDSA_SHA2_128S_SIGNATURE_BYTES], |
| 784 | const uint8_t private_key[BCM_SLHDSA_SHA2_128S_PRIVATE_KEY_BYTES], |
| 785 | const uint8_t *hashed_msg, size_t hashed_msg_len, int hash_nid, |
| 786 | const uint8_t *context, size_t context_len); |
| 787 |
| 788 | OPENSSL_EXPORT bcm_status BCM_slhdsa_sha2_128s_prehash_verify( |
| 789 | const uint8_t *signature, size_t signature_len, |
| 790 | const uint8_t public_key[BCM_SLHDSA_SHA2_128S_PUBLIC_KEY_BYTES], |
| 791 | const uint8_t *hashed_msg, size_t hashed_msg_len, int hash_nid, |
| 792 | const uint8_t *context, size_t context_len); |
| 793 |
| 794 |
| 795 | // AES |
| 796 |
| 797 | // BCM_aes_encrypt encrypts a single block from |in| to |out| with |key|. The |
| 798 | // |in| and |out| pointers may overlap. |
| 799 | OPENSSL_EXPORT bcm_infallible BCM_aes_encrypt(const uint8_t *in, uint8_t *out, |
| 800 | const AES_KEY *key); |
| 801 | // BCM_aes_decrypt decrypts a single block from |in| to |out| with |key|. The |
| 802 | // |in| and |out| pointers may overlap. |
| 803 | OPENSSL_EXPORT bcm_infallible BCM_aes_decrypt(const uint8_t *in, uint8_t *out, |
| 804 | const AES_KEY *key); |
| 805 |
| 806 | // BCM_aes_set_encrypt_key configures |aeskey| to encrypt with the |bits|-bit |
| 807 | // key, |key|. |key| must point to |bits|/8 bytes. It will return failure if |
| 808 | // |bits| is an invalid AES key size. |
| 809 | OPENSSL_EXPORT bcm_status BCM_aes_set_encrypt_key(const uint8_t *key, |
| 810 | unsigned bits, |
| 811 | AES_KEY *aeskey); |
| 812 |
| 813 | // BCM_aes_set_decrypt_key configures |aeskey| to decrypt with the |bits|-bit |
| 814 | // key, |key|. |key| must point to |bits|/8 bytes. It will return failure if |
| 815 | // |bits| is an invalid AES key size. |
| 816 | OPENSSL_EXPORT bcm_status BCM_aes_set_decrypt_key(const uint8_t *key, |
| 817 | unsigned bits, |
| 818 | AES_KEY *aeskey); |
| 819 |
| 820 |
| 821 | #if defined(__cplusplus) |
| 822 | } // extern C |
| 823 | #endif |
| 824 |
| 825 | #endif // OPENSSL_HEADER_CRYPTO_FIPSMODULE_BCM_INTERFACE_H |
| 826 |