35#if defined(ENABLE_CRYPTO_OPENSSL)
44#include <openssl/conf.h>
45#include <openssl/des.h>
46#include <openssl/err.h>
47#include <openssl/evp.h>
48#include <openssl/objects.h>
49#include <openssl/rand.h>
50#include <openssl/ssl.h>
52#if !defined(LIBRESSL_VERSION_NUMBER)
53#include <openssl/kdf.h>
55#if OPENSSL_VERSION_NUMBER >= 0x30000000L
56#include <openssl/provider.h>
57#include <openssl/core_names.h>
60#if defined(_WIN32) && defined(OPENSSL_NO_EC)
61#error Windows build with OPENSSL_NO_EC: disabling EC key is not supported.
66#pragma warning(disable : 4996)
73#if MAX_CIPHER_KEY_LENGTH < EVP_MAX_KEY_LENGTH
74#warning Some OpenSSL EVP ciphers now support key lengths greater than MAX_CIPHER_KEY_LENGTH -- consider increasing MAX_CIPHER_KEY_LENGTH
77#if MAX_HMAC_KEY_LENGTH < EVP_MAX_MD_SIZE
78#warning Some OpenSSL HMAC message digests now support key lengths greater than MAX_HMAC_KEY_LENGTH -- consider increasing MAX_HMAC_KEY_LENGTH
81#if HAVE_OPENSSL_ENGINE
82#include <openssl/ui.h>
83#include <openssl/engine.h>
85static bool engine_initialized =
false;
87static ENGINE *engine_persist = NULL;
91try_load_engine(
const char *engine)
93 ENGINE *e = ENGINE_by_id(
"dynamic");
96 if (!ENGINE_ctrl_cmd_string(e,
"SO_PATH", engine, 0)
97 || !ENGINE_ctrl_cmd_string(e,
"LOAD", NULL, 0))
107setup_engine(
const char *engine)
111 ENGINE_load_builtin_engines();
115 if (strcmp(engine,
"auto") == 0)
117 msg(
M_INFO,
"Initializing OpenSSL auto engine support");
118 ENGINE_register_all_complete();
121 if ((e = ENGINE_by_id(engine)) == NULL && (e = try_load_engine(engine)) == NULL)
126 if (!ENGINE_set_default(e, ENGINE_METHOD_ALL))
128 crypto_msg(
M_FATAL,
"OpenSSL error: ENGINE_set_default failed on engine '%s'", engine);
131 msg(
M_INFO,
"Initializing OpenSSL support for engine '%s'", ENGINE_get_id(e));
141#if HAVE_OPENSSL_ENGINE
142 if (!engine_initialized)
146 engine_persist = setup_engine(engine_name);
147 engine_initialized =
true;
150 msg(
M_WARN,
"Note: OpenSSL hardware crypto engine functionality is not available");
157#if OPENSSL_VERSION_NUMBER >= 0x30000000L
166 msg(
M_WARN,
"Note: OpenSSL provider functionality is not available");
174#if OPENSSL_VERSION_NUMBER >= 0x30000000L
175 if (!OSSL_PROVIDER_unload(provider))
191 OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CONFIG, NULL);
199 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
207 FILE *fp = fopen(
"sdlog",
"w");
209 CRYPTO_mem_leaks_fp(fp);
213#if HAVE_OPENSSL_ENGINE
214 if (engine_initialized)
217 engine_persist = NULL;
218 engine_initialized =
false;
232 unsigned long err = 0;
234 const char *file, *data, *func;
238 if (!(errflags & ERR_TXT_STRING))
244 if (ERR_GET_REASON(err) == SSL_R_NO_SHARED_CIPHER)
247 "in common with the client. Your --tls-cipher setting might be "
250 else if (ERR_GET_REASON(err) == SSL_R_UNSUPPORTED_PROTOCOL)
253 "TLS error: Unsupported protocol. This typically "
254 "indicates that client and server have no common TLS version enabled. "
255 "This can be caused by mismatched tls-version-min and tls-version-max "
256 "options on client and server. "
257 "If your OpenVPN client is between v2.3.6 and v2.3.2 try adding "
258 "tls-version-min 1.0 to the client configuration to use TLS 1.0+ "
259 "instead of TLS 1.0 only");
265 msg(flags,
"OpenSSL: %s:%s", ERR_error_string(err, NULL), data);
269 msg(flags,
"OpenSSL: %s:%s:%s:%d:%s", ERR_error_string(err, NULL), data, file, line,
286crypto_malloc(
size_t size,
const char *file,
int line)
288 return dmalloc_malloc(file, line, size, DMALLOC_FUNC_MALLOC, 0, 0);
292crypto_realloc(
void *ptr,
size_t size,
const char *file,
int line)
294 return dmalloc_realloc(file, line, ptr, size, DMALLOC_FUNC_REALLOC, 0);
298crypto_free(
void *ptr)
300 dmalloc_free(__FILE__, __LINE__, ptr, DMALLOC_FUNC_FREE);
304crypto_init_dmalloc(
void)
306 CRYPTO_set_mem_ex_functions(crypto_malloc, crypto_realloc, crypto_free);
311 {
"AES-128-GCM",
"id-aes128-GCM" },
312 {
"AES-192-GCM",
"id-aes192-GCM" },
313 {
"AES-256-GCM",
"id-aes256-GCM" },
314 {
"CHACHA20-POLY1305",
"ChaCha20-Poly1305" },
323 const EVP_CIPHER *
const *cipher_a = a;
324 const EVP_CIPHER *
const *cipher_b = b;
346 msg(
M_WARN,
"WARNING: Too many ciphers, not showing all");
354#ifdef ENABLE_OFB_CFB_MODE
359 cipher_list->
list[cipher_list->
num++] = cipher;
369 printf(
"The following ciphers and cipher modes are available for use\n"
370 "with " PACKAGE_NAME
". Each cipher shown below may be used as a\n"
371 "parameter to the --data-ciphers (or --cipher) option. In static \n"
372 "key mode only CBC mode is allowed.\n");
373 printf(
"See also openssl list -cipher-algorithms\n\n");
376#if OPENSSL_VERSION_NUMBER >= 0x30000000L
379 for (
int nid = 0; nid < 10000; ++nid)
381#if defined(LIBRESSL_VERSION_NUMBER)
385 const EVP_CIPHER *cipher = NULL;
386 const char *name = OBJ_nid2sn(nid);
389 cipher = EVP_get_cipherbyname(name);
392 const EVP_CIPHER *cipher = EVP_get_cipherbynid(nid);
401 qsort((EVP_CIPHER *)cipher_list.
list, cipher_list.
num,
sizeof(*cipher_list.
list),
404 for (
size_t i = 0;
i < cipher_list.
num;
i++)
412 printf(
"\nThe following ciphers have a block size of less than 128 bits, \n"
413 "and are therefore deprecated. Do not use unless you have to.\n\n");
414 for (
int i = 0;
i < cipher_list.
num;
i++)
428 EVP_MD_size(digest) * 8);
435 printf(
"The following message digests are available for use with\n" PACKAGE_NAME
436 ". A message digest is used in conjunction with\n"
437 "the HMAC function, to authenticate received packets.\n"
438 "You can specify a message digest as parameter to\n"
439 "the --auth option.\n");
440 printf(
"See also openssl list -digest-algorithms\n\n");
443#if OPENSSL_VERSION_NUMBER >= 0x30000000L
446 for (
int nid = 0; nid < 10000; ++nid)
451#ifdef LIBRESSL_VERSION_NUMBER
452 const EVP_MD *digest = NULL;
453 const char *name = OBJ_nid2sn(nid);
456 digest = EVP_get_digestbyname(name);
459 const EVP_MD *digest = EVP_get_digestbynid(nid);
475#if HAVE_OPENSSL_ENGINE
478 printf(
"OpenSSL Crypto Engines\n\n");
480 ENGINE_load_builtin_engines();
482 e = ENGINE_get_first();
485 printf(
"%s [%s]\n", ENGINE_get_name(e), ENGINE_get_id(e));
486 e = ENGINE_get_next(e);
490 printf(
"Sorry, OpenSSL hardware crypto engine functionality is not available.\n");
500 BIO *bio = BIO_new(BIO_s_mem());
501 if (!bio || !PEM_write_bio(bio, name,
"",
BPTR(src),
BLEN(src)))
508 BIO_get_mem_ptr(bio, &bptr);
528 BIO *bio = BIO_new_mem_buf((
char *)
BPTR(src),
BLEN(src));
534 char *name_read = NULL;
535 char *header_read = NULL;
536 uint8_t *data_read = NULL;
537 long data_read_len = 0;
538 if (!PEM_read_bio(bio, &name_read, &header_read, &data_read, &data_read_len))
544 if (strcmp(name, name_read))
558 memcpy(dst_data, data_read, data_read_len);
562 OPENSSL_free(name_read);
563 OPENSSL_free(header_read);
564 OPENSSL_free(data_read);
585 if (
unlikely(1 != RAND_bytes(output, len)))
616 *reason =
"disabled because unknown";
624 if (FIPS_mode() && !(EVP_CIPHER_flags(cipher) & EVP_CIPH_FLAG_FIPS))
627 "Cipher algorithm '%s' is known by OpenSSL library but "
628 "currently disabled by running in FIPS mode.",
630 *reason =
"disabled by FIPS mode";
637 "Cipher algorithm '%s' uses a default key size (%d bytes) "
638 "which is larger than " PACKAGE_NAME
"'s current maximum key size "
641 *reason =
"disabled due to key size too large";
656 if (strcmp(
"none", ciphername) == 0)
658 return "[null-cipher]";
667 const char *name = EVP_CIPHER_name(cipher_kt);
676 int size = EVP_CIPHER_key_length(cipher);
685 int ivsize = EVP_CIPHER_iv_length(cipher);
700 char *mode_str = NULL;
701 const char *orig_name = NULL;
709 int block_size = EVP_CIPHER_block_size(cipher);
711 orig_name = EVP_CIPHER_name(cipher);
718 mode_str = strrchr(name,
'-');
719 if (!mode_str || strlen(mode_str) < 4)
724 strcpy(mode_str,
"-CBC");
729 block_size = EVP_CIPHER_block_size(cbc_cipher);
759#ifdef NID_chacha20_poly1305
763 bool ischachapoly = (EVP_CIPHER_nid(cipher) == NID_chacha20_poly1305);
777 ASSERT(NULL != cipher_kt);
778 return EVP_CIPHER_mode(cipher_kt);
789#ifdef EVP_CIPH_FLAG_CTS
790 && !(EVP_CIPHER_flags(cipher) & EVP_CIPH_FLAG_CTS)
792 && !(EVP_CIPHER_flags(cipher) & EVP_CIPH_FLAG_AEAD_CIPHER));
801 bool ofb_cfb = cipher
805 && !(EVP_CIPHER_flags(cipher) & EVP_CIPH_FLAG_AEAD_CIPHER);
823#ifdef NID_chacha20_poly1305
824 if (EVP_CIPHER_nid(cipher) == NID_chacha20_poly1305)
845 EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
853 EVP_CIPHER_CTX_free(ctx);
860 ASSERT(NULL != ciphername && NULL != ctx);
863 EVP_CIPHER_CTX_reset(ctx);
864 if (!EVP_CipherInit_ex(ctx, kt, NULL,
key, NULL, enc))
870 ASSERT(EVP_CIPHER_CTX_key_length(ctx) <= EVP_CIPHER_key_length(kt));
877 return EVP_CIPHER_CTX_iv_length(ctx);
883 return EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_GET_TAG, tag_size, tag_buf);
889 return EVP_CIPHER_CTX_block_size(ctx);
895 return EVP_CIPHER_CTX_mode(ctx);
907 int flags = EVP_CIPHER_CTX_flags(ctx);
908 int mode = EVP_CIPHER_CTX_mode(ctx);
910 return mode == EVP_CIPH_CBC_MODE
912#ifdef EVP_CIPH_FLAG_CTS
913 && !(flags & EVP_CIPH_FLAG_CTS)
915 && !(flags & EVP_CIPH_FLAG_AEAD_CIPHER);
928 return (mode == EVP_CIPH_OFB_MODE || mode == EVP_CIPH_CFB_MODE)
930 && !(EVP_CIPHER_CTX_flags(ctx) & EVP_CIPH_FLAG_AEAD_CIPHER);
938 int flags = EVP_CIPHER_CTX_flags(ctx);
939 if (flags & EVP_CIPH_FLAG_AEAD_CIPHER)
944#if defined(NID_chacha20_poly1305) && OPENSSL_VERSION_NUMBER < 0x30000000L
945 if (EVP_CIPHER_CTX_nid(ctx) == NID_chacha20_poly1305)
959 return EVP_CipherInit_ex(ctx, NULL, NULL, NULL, iv_buf, -1);
966 if (!EVP_CipherUpdate(ctx, NULL, &len, src, src_len))
976 if (!EVP_CipherUpdate(ctx, dst, dst_len, src, src_len))
986 return EVP_CipherFinal(ctx, dst, dst_len);
993 ASSERT(tag_len < SIZE_MAX);
994 if (!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, tag_len, tag))
1023 "Message hash algorithm '%s' uses a default hash "
1024 "size (%d bytes) which is larger than " PACKAGE_NAME
"'s current "
1025 "maximum hash size (%d bytes)",
1036 bool valid = (md != NULL);
1049 {
"BLAKE2s256",
"BLAKE2S-256" },
1050 {
"BLAKE2b512",
"BLAKE2B-512" },
1051 {
"RIPEMD160",
"RIPEMD-160" },
1052 {
"SHA224",
"SHA2-224" },
1053 {
"SHA256",
"SHA2-256" },
1054 {
"SHA384",
"SHA2-384" },
1055 {
"SHA512",
"SHA2-512" },
1056 {
"SHA512-224",
"SHA2-512/224" },
1057 {
"SHA512-256",
"SHA2-512/256" },
1058 {
"SHAKE128",
"SHAKE-128" },
1059 {
"SHAKE256",
"SHAKE-256" },
1067 if (!strcmp(
"none", mdname))
1069 return "[null-digest]";
1091 if (!strcmp(
"none", mdname))
1096 unsigned char size = (
unsigned char)EVP_MD_size(kt);
1109md_full(
const char *mdname,
const uint8_t *src,
int src_len, uint8_t *dst)
1111 unsigned int in_md_len = 0;
1114 int ret = EVP_Digest(src, src_len, dst, &in_md_len, kt, NULL);
1122 EVP_MD_CTX *ctx = EVP_MD_CTX_new();
1130 EVP_MD_CTX_free(ctx);
1137 ASSERT(NULL != ctx && NULL != kt);
1139 EVP_MD_CTX_init(ctx);
1140 if (!EVP_DigestInit(ctx, kt))
1150 EVP_MD_CTX_reset(ctx);
1156 return EVP_MD_CTX_size(ctx);
1162 EVP_DigestUpdate(ctx, src, src_len);
1168 unsigned int in_md_len = 0;
1170 EVP_DigestFinal(ctx, dst, &in_md_len);
1179#if OPENSSL_VERSION_NUMBER < 0x30000000L
1183 HMAC_CTX *ctx = HMAC_CTX_new();
1198 ASSERT(NULL != kt && NULL != ctx);
1200 int key_len = EVP_MD_size(kt);
1201 HMAC_CTX_reset(ctx);
1202 if (!HMAC_Init_ex(ctx,
key, key_len, kt, NULL))
1208 ASSERT(HMAC_size(ctx) <= key_len);
1214 HMAC_CTX_reset(ctx);
1220 return HMAC_size(ctx);
1226 if (!HMAC_Init_ex(ctx, NULL, 0, NULL, NULL))
1235 HMAC_Update(ctx, src, src_len);
1241 unsigned int in_hmac_len = 0;
1243 HMAC_Final(ctx, dst, &in_hmac_len);
1251 EVP_MAC *hmac = EVP_MAC_fetch(NULL,
"HMAC", NULL);
1252 ctx->ctx = EVP_MAC_CTX_new(hmac);
1263 EVP_MAC_CTX_free(ctx->ctx);
1272 ASSERT(NULL != kt && NULL != ctx && ctx->ctx != NULL);
1276 memcpy(ctx->key,
key, EVP_MD_size(kt));
1284 ctx->params[0] = OSSL_PARAM_construct_utf8_string(
"digest", (
char *)
EVP_MD_get0_name(kt), 0);
1285 ctx->params[1] = OSSL_PARAM_construct_octet_string(
"key", ctx->key, EVP_MD_size(kt));
1286 ctx->params[2] = OSSL_PARAM_construct_end();
1288 if (!EVP_MAC_init(ctx->ctx, NULL, 0, ctx->params))
1299 EVP_MAC_init(ctx->ctx, NULL, 0, NULL);
1305 return (
int)EVP_MAC_CTX_get_mac_size(ctx->ctx);
1314 if (!EVP_MAC_init(ctx->ctx, NULL, 0, ctx->params))
1323 EVP_MAC_update(ctx->ctx, src, src_len);
1331 size_t in_hmac_len = EVP_MAC_CTX_get_mac_size(ctx->ctx);
1333 EVP_MAC_final(ctx->ctx, dst, &in_hmac_len, in_hmac_len);
1340 return CRYPTO_memcmp(a, b, size);
1342#if (OPENSSL_VERSION_NUMBER >= 0x30000000L) && !defined(LIBRESSL_VERSION_NUMBER)
1344ssl_tls1_PRF(
const uint8_t *seed,
size_t seed_len,
const uint8_t *secret,
size_t secret_len,
1345 uint8_t *output,
size_t output_len)
1348 EVP_KDF_CTX *kctx = NULL;
1351 EVP_KDF *kdf = EVP_KDF_fetch(NULL,
"TLS1-PRF", NULL);
1357 kctx = EVP_KDF_CTX_new(kdf);
1364 OSSL_PARAM params[4];
1369 OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST, SN_md5_sha1, strlen(SN_md5_sha1));
1370 params[1] = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SECRET, (uint8_t *)secret,
1373 OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SEED, (uint8_t *)seed, seed_len);
1374 params[3] = OSSL_PARAM_construct_end();
1376 if (EVP_KDF_derive(kctx, output, output_len, params) <= 0)
1379 "EVP_KDF_derive failed");
1388 EVP_KDF_CTX_free(kctx);
1393#elif defined(OPENSSL_IS_AWSLC)
1395ssl_tls1_PRF(
const uint8_t *label,
size_t label_len,
const uint8_t *sec,
size_t slen, uint8_t *out1,
1398 CRYPTO_tls1_prf(EVP_md5_sha1(), out1, olen, sec, slen, label, label_len, NULL, 0, NULL, 0);
1400#elif !defined(LIBRESSL_VERSION_NUMBER) && !defined(ENABLE_CRYPTO_WOLFSSL)
1402ssl_tls1_PRF(
const uint8_t *seed,
size_t seed_len,
const uint8_t *secret,
size_t secret_len,
1403 uint8_t *output,
size_t output_len)
1405 EVP_PKEY_CTX *pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_TLS1_PRF, NULL);
1412 if (!EVP_PKEY_derive_init(pctx))
1417 if (!EVP_PKEY_CTX_set_tls1_prf_md(pctx, EVP_md5_sha1()))
1422 if (!EVP_PKEY_CTX_set1_tls1_prf_secret(pctx, secret, secret_len))
1427 if (!EVP_PKEY_CTX_add1_tls1_prf_seed(pctx, seed, seed_len))
1432 size_t out_len = output_len;
1433 if (!EVP_PKEY_derive(pctx, output, &out_len))
1437 if (out_len != output_len)
1443 EVP_PKEY_CTX_free(pctx);
1451ssl_tls1_PRF(
const uint8_t *label,
size_t label_len,
const uint8_t *sec,
size_t slen, uint8_t *out1,
struct buffer alloc_buf_gc(size_t size, struct gc_arena *gc)
char * string_alloc(const char *str, struct gc_arena *gc)
static void secure_memzero(void *data, size_t len)
Securely zeroise memory.
static uint8_t * buf_write_alloc(struct buffer *buf, size_t size)
static bool buf_write(struct buffer *dest, const void *src, size_t size)
static void check_malloc_return(void *p)
#define ALLOC_OBJ_CLEAR(dptr, type)
const char * translate_cipher_name_from_openvpn(const char *cipher_name)
Translate an OpenVPN cipher name to a crypto library cipher name.
const char * translate_cipher_name_to_openvpn(const char *cipher_name)
Translate a crypto library cipher name to an OpenVPN cipher name.
void print_cipher(const char *ciphername)
Print a cipher list entry.
Data Channel Cryptography Module.
Data Channel Cryptography SSL library-specific backend interface.
#define MAX_CIPHER_KEY_LENGTH
#define MAX_HMAC_KEY_LENGTH
#define OPENVPN_AEAD_TAG_LENGTH
mbedtls_cipher_context_t cipher_ctx_t
Generic cipher context.
mbedtls_md_context_t hmac_ctx_t
Generic HMAC context.
#define OPENVPN_MODE_OFB
Cipher is in OFB mode.
#define OPENVPN_MODE_CFB
Cipher is in CFB mode.
#define OPENVPN_MODE_CBC
Cipher is in CBC mode.
mbedtls_operation_t crypto_operation_t
#define OPENVPN_MODE_GCM
Cipher is in GCM mode.
void crypto_print_openssl_errors(const unsigned int flags)
Retrieve any occurred OpenSSL errors and print those errors.
bool ssl_tls1_PRF(const uint8_t *seed, size_t seed_len, const uint8_t *secret, size_t secret_len, uint8_t *output, size_t output_len)
Calculates the TLS 1.0-1.1 PRF function.
int md_full(const char *mdname, const uint8_t *src, int src_len, uint8_t *dst)
Calculates the message digest for the given buffer.
bool cipher_kt_mode_cbc(const char *ciphername)
Check if the supplied cipher is a supported CBC mode cipher.
void show_available_engines(void)
const cipher_name_pair digest_name_translation_table[]
void crypto_unload_provider(const char *provname, provider_t *provider)
Unloads the given (OpenSSL) provider.
void crypto_uninit_lib(void)
int cipher_kt_block_size(const char *ciphername)
Returns the block size of the cipher, in bytes.
void hmac_ctx_reset(HMAC_CTX *ctx)
bool cipher_kt_mode_aead(const char *ciphername)
Check if the supplied cipher is a supported AEAD mode cipher.
void show_available_ciphers(void)
bool md_valid(const char *digest)
Return if a message digest parameters is valid given the name of the digest.
bool cipher_ctx_mode_cbc(const cipher_ctx_t *ctx)
Check if the supplied cipher is a supported CBC mode cipher.
void crypto_init_lib(void)
cipher_ctx_t * cipher_ctx_new(void)
Generic cipher functions.
bool cipher_kt_mode_ofb_cfb(const char *ciphername)
Check if the supplied cipher is a supported OFB or CFB mode cipher.
int cipher_ctx_block_size(const EVP_CIPHER_CTX *ctx)
void print_digest(EVP_MD *digest, void *unused)
const char * md_kt_name(const char *mdname)
Retrieve a string describing the digest digest (e.g.
bool cipher_kt_insecure(const char *ciphername)
Returns true if we consider this cipher to be insecure.
int cipher_ctx_reset(EVP_CIPHER_CTX *ctx, const uint8_t *iv_buf)
static int cipher_name_cmp(const void *a, const void *b)
int cipher_kt_mode(const EVP_CIPHER *cipher_kt)
void crypto_clear_error(void)
const size_t digest_name_translation_table_count
int md_ctx_size(const EVP_MD_CTX *ctx)
bool crypto_pem_decode(const char *name, struct buffer *dst, const struct buffer *src)
Decode a PEM buffer to binary data.
provider_t * crypto_load_provider(const char *provider)
Load the given (OpenSSL) providers.
static evp_cipher_type * cipher_get(const char *ciphername)
int cipher_ctx_update_ad(EVP_CIPHER_CTX *ctx, const uint8_t *src, int src_len)
bool cipher_ctx_mode_ofb_cfb(const cipher_ctx_t *ctx)
Check if the supplied cipher is a supported OFB or CFB mode cipher.
bool cipher_ctx_mode_aead(const cipher_ctx_t *ctx)
Check if the supplied cipher is a supported AEAD mode cipher.
int cipher_ctx_mode(const EVP_CIPHER_CTX *ctx)
EVP_MD_CTX * md_ctx_new(void)
int cipher_kt_iv_size(const char *ciphername)
Returns the size of the IV used by the cipher, in bytes, or 0 if no IV is used.
int cipher_kt_tag_size(const char *ciphername)
Returns the MAC tag size of the cipher, in bytes.
int rand_bytes(uint8_t *output, int len)
Wrapper for secure random number generator.
void hmac_ctx_init(HMAC_CTX *ctx, const uint8_t *key, const char *mdname)
void cipher_ctx_init(EVP_CIPHER_CTX *ctx, const uint8_t *key, const char *ciphername, crypto_operation_t enc)
void md_ctx_free(EVP_MD_CTX *ctx)
HMAC_CTX * hmac_ctx_new(void)
const size_t cipher_name_translation_table_count
const char * cipher_kt_name(const char *ciphername)
Retrieve a normalised string describing the cipher (e.g.
void hmac_ctx_update(HMAC_CTX *ctx, const uint8_t *src, int src_len)
void hmac_ctx_free(HMAC_CTX *ctx)
void md_ctx_cleanup(EVP_MD_CTX *ctx)
void cipher_ctx_free(EVP_CIPHER_CTX *ctx)
void md_ctx_init(EVP_MD_CTX *ctx, const char *mdname)
void md_ctx_final(EVP_MD_CTX *ctx, uint8_t *dst)
int memcmp_constant_time(const void *a, const void *b, size_t size)
As memcmp(), but constant-time.
int cipher_kt_key_size(const char *ciphername)
Returns the size of keys used by the cipher, in bytes.
void crypto_init_lib_engine(const char *engine_name)
int cipher_ctx_final_check_tag(EVP_CIPHER_CTX *ctx, uint8_t *dst, int *dst_len, uint8_t *tag, size_t tag_len)
void md_ctx_update(EVP_MD_CTX *ctx, const uint8_t *src, int src_len)
int cipher_ctx_final(EVP_CIPHER_CTX *ctx, uint8_t *dst, int *dst_len)
const cipher_name_pair cipher_name_translation_table[]
Cipher name translation table.
int cipher_ctx_update(EVP_CIPHER_CTX *ctx, uint8_t *dst, int *dst_len, uint8_t *src, int src_len)
int cipher_ctx_iv_length(const EVP_CIPHER_CTX *ctx)
int cipher_ctx_get_tag(EVP_CIPHER_CTX *ctx, uint8_t *tag_buf, int tag_size)
int hmac_ctx_size(HMAC_CTX *ctx)
static evp_md_type * md_get(const char *digest)
void hmac_ctx_final(HMAC_CTX *ctx, uint8_t *dst)
void hmac_ctx_cleanup(HMAC_CTX *ctx)
unsigned char md_kt_size(const char *mdname)
Returns the size of the message digest, in bytes.
void show_available_digests(void)
bool cipher_valid_reason(const char *ciphername, const char **reason)
Returns if the cipher is valid, based on the given cipher name and provides a reason if invalid.
bool crypto_pem_encode(const char *name, struct buffer *dst, const struct buffer *src, struct gc_arena *gc)
Encode binary data as PEM.
#define crypto_msg(flags,...)
Retrieve any OpenSSL errors, then print the supplied error message.
const EVP_CIPHER evp_cipher_type
OpenSSL compatibility stub.
static void EVP_CIPHER_free(const EVP_CIPHER *cipher)
static const EVP_CIPHER * EVP_CIPHER_fetch(void *ctx, const char *algorithm, const char *properties)
static unsigned long ERR_get_error_all(const char **file, int *line, const char **func, const char **data, int *flags)
static void EVP_MD_free(const EVP_MD *md)
static const EVP_MD * EVP_MD_fetch(void *ctx, const char *algorithm, const char *properties)
#define EVP_CIPHER_get0_name
#define EVP_CIPHER_CTX_get_mode
static bool check_debug_level(unsigned int level)
Wrapper structure for dynamically allocated memory.
uint8_t * data
Pointer to the allocated memory.
Struct used in cipher name translation table.
const char * openvpn_name
Cipher name used by OpenVPN.
const char * lib_name
Cipher name used by crypto library.
const EVP_CIPHER * list[1000]
Garbage collection arena used to keep track of dynamically allocated memory.
Container for unidirectional cipher and HMAC key material.
static int cleanup(void **state)