28#include "libssh/libssh.h"
29#include <openssl/rsa.h>
30#include <openssl/sha.h>
31#include <openssl/md5.h>
32#include <openssl/hmac.h>
33#include <openssl/evp.h>
34#include <openssl/crypto.h>
35#include <openssl/ec.h>
37typedef EVP_MD_CTX* SHACTX;
38typedef EVP_MD_CTX* SHA256CTX;
39typedef EVP_MD_CTX* SHA384CTX;
40typedef EVP_MD_CTX* SHA512CTX;
41typedef EVP_MD_CTX* MD5CTX;
42typedef EVP_MD_CTX* HMACCTX;
44#define SHA_DIGEST_LEN SHA_DIGEST_LENGTH
45#define SHA256_DIGEST_LEN SHA256_DIGEST_LENGTH
46#define SHA384_DIGEST_LEN SHA384_DIGEST_LENGTH
47#define SHA512_DIGEST_LEN SHA512_DIGEST_LENGTH
51#define MD5_DIGEST_LEN MD5_DIGEST_LENGTH
53#ifdef HAVE_OPENSSL_ECC
54#define EVP_DIGEST_LEN EVP_MAX_MD_SIZE
61#define ssh_crypto_free(x) OPENSSL_free(x)
63#include <openssl/bn.h>
64#include <openssl/opensslv.h>
66typedef BIGNUM* bignum;
67typedef const BIGNUM* const_bignum;
68typedef BN_CTX* bignum_CTX;
70#define bignum_new() BN_new()
71#define bignum_safe_free(num) do { \
72 if ((num) != NULL) { \
73 BN_clear_free((num)); \
77#define bignum_set_word(bn,n) BN_set_word(bn,n)
78#define bignum_bin2bn(data, datalen, dest) \
81 if ((*dest) != NULL) { \
82 BN_bin2bn(data,datalen,(*dest)); \
85#define bignum_bn2dec(num) BN_bn2dec(num)
86#define bignum_dec2bn(data, bn) BN_dec2bn(bn, data)
87#define bignum_hex2bn(data, bn) BN_hex2bn(bn, data)
88#define bignum_bn2hex(num, dest) (*dest)=(unsigned char *)BN_bn2hex(num)
89#define bignum_rand(rnd, bits) BN_rand(rnd, bits, 0, 1)
90#define bignum_rand_range(rnd, max) BN_rand_range(rnd, max)
91#define bignum_ctx_new() BN_CTX_new()
92#define bignum_ctx_free(num) BN_CTX_free(num)
93#define bignum_ctx_invalid(ctx) ((ctx) == NULL)
94#define bignum_mod_exp(dest,generator,exp,modulo,ctx) BN_mod_exp(dest,generator,exp,modulo,ctx)
95#define bignum_add(dest, a, b) BN_add(dest, a, b)
96#define bignum_sub(dest, a, b) BN_sub(dest, a, b)
97#define bignum_mod(dest, a, b, ctx) BN_mod(dest, a, b, ctx)
98#define bignum_num_bytes(num) (size_t)BN_num_bytes(num)
99#define bignum_num_bits(num) (size_t)BN_num_bits(num)
100#define bignum_is_bit_set(num,bit) BN_is_bit_set(num, (int)bit)
101#define bignum_bn2bin(num,len, ptr) BN_bn2bin(num, ptr)
102#define bignum_cmp(num1,num2) BN_cmp(num1,num2)
103#define bignum_rshift1(dest, src) BN_rshift1(dest, src)
104#define bignum_dup(orig, dest) do { \
105 if (*(dest) == NULL) { \
106 *(dest) = BN_dup(orig); \
108 BN_copy(*(dest), orig); \
114#ifdef HAVE_OPENSSL_FIPS_MODE
115#define ssh_fips_mode() (FIPS_mode() != 0)
116#elif OPENSSL_VERSION_NUMBER >= 0x30000000L
117#define ssh_fips_mode() EVP_default_properties_is_fips_enabled(NULL)
119#define ssh_fips_mode() false
122ssh_string pki_key_make_ecpoint_string(
const EC_GROUP *g,
const EC_POINT *p);
123int pki_key_ecgroup_name_to_nid(
const char *group);
125#if defined(WITH_PKCS11_URI)
126#if defined(WITH_PKCS11_PROVIDER)
127int pki_load_pkcs11_provider(
void);
129ENGINE *pki_get_engine(
void);