1 /* $NetBSD: crypto_api.h,v 1.8 2026/04/09 06:36:39 christos Exp $ */ 2 /* $OpenBSD: crypto_api.h,v 1.10 2025/10/30 23:19:33 djm Exp $ */ 3 4 /* 5 * Assembled from generated headers and source files by Markus Friedl. 6 * Placed in the public domain. 7 */ 8 9 #ifndef crypto_api_h 10 #define crypto_api_h 11 12 #include <stdint.h> 13 #include <stdlib.h> 14 15 typedef int8_t crypto_int8; 16 typedef uint8_t crypto_uint8; 17 typedef int16_t crypto_int16; 18 typedef uint16_t crypto_uint16; 19 typedef int32_t crypto_int32; 20 typedef uint32_t crypto_uint32; 21 typedef int64_t crypto_int64; 22 typedef uint64_t crypto_uint64; 23 24 #define randombytes(buf, buf_len) arc4random_buf((buf), (buf_len)) 25 #define small_random32() arc4random() 26 27 #define crypto_hash_sha512_BYTES 64U 28 29 #ifdef WITH_OPENSSL 30 #include <openssl/evp.h> 31 static inline int 32 crypto_hash_sha512(unsigned char *out, const unsigned char *in, 33 unsigned long long inlen) 34 { 35 36 if (!EVP_Digest(in, inlen, out, NULL, EVP_sha512(), NULL)) 37 return -1; 38 return 0; 39 } 40 #else /* WITH_OPENSSL */ 41 # include <sha2.h> 42 static inline int 43 crypto_hash_sha512(unsigned char *out, const unsigned char *in, 44 unsigned long long inlen) 45 { 46 47 SHA512_CTX ctx; 48 49 SHA512Init(&ctx); 50 SHA512Update(&ctx, in, inlen); 51 SHA512Final(out, &ctx); 52 return 0; 53 } 54 #endif /* WITH_OPENSSL */ 55 56 #define crypto_sign_ed25519_SECRETKEYBYTES 64U 57 #define crypto_sign_ed25519_PUBLICKEYBYTES 32U 58 #define crypto_sign_ed25519_BYTES 64U 59 60 int crypto_sign_ed25519(unsigned char *, unsigned long long *, 61 const unsigned char *, unsigned long long, const unsigned char *); 62 int crypto_sign_ed25519_open(unsigned char *, unsigned long long *, 63 const unsigned char *, unsigned long long, const unsigned char *); 64 int crypto_sign_ed25519_keypair(unsigned char *, unsigned char *); 65 66 #define crypto_kem_sntrup761_PUBLICKEYBYTES 1158 67 #define crypto_kem_sntrup761_SECRETKEYBYTES 1763 68 #define crypto_kem_sntrup761_CIPHERTEXTBYTES 1039 69 #define crypto_kem_sntrup761_BYTES 32 70 71 int crypto_kem_sntrup761_enc(unsigned char *cstr, unsigned char *k, 72 const unsigned char *pk); 73 int crypto_kem_sntrup761_dec(unsigned char *k, 74 const unsigned char *cstr, const unsigned char *sk); 75 int crypto_kem_sntrup761_keypair(unsigned char *pk, unsigned char *sk); 76 77 #define crypto_kem_mlkem768_PUBLICKEYBYTES 1184 78 #define crypto_kem_mlkem768_SECRETKEYBYTES 2400 79 #define crypto_kem_mlkem768_CIPHERTEXTBYTES 1088 80 #define crypto_kem_mlkem768_BYTES 32 81 82 #endif /* crypto_api_h */ 83