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