35#if defined(ENABLE_CRYPTO_OPENSSL)
45#include <openssl/conf.h>
46#include <openssl/des.h>
47#include <openssl/err.h>
48#include <openssl/evp.h>
49#include <openssl/objects.h>
50#include <openssl/rand.h>
51#include <openssl/ssl.h>
53#if !defined(LIBRESSL_VERSION_NUMBER)
54#include <openssl/kdf.h>
56#if OPENSSL_VERSION_NUMBER >= 0x30000000L
57#include <openssl/provider.h>
58#include <openssl/core_names.h>
61#if defined(_WIN32) && defined(OPENSSL_NO_EC)
62#error Windows build with OPENSSL_NO_EC: disabling EC key is not supported.
67#pragma warning(disable : 4996)
74#if MAX_CIPHER_KEY_LENGTH < EVP_MAX_KEY_LENGTH
75#warning Some OpenSSL EVP ciphers now support key lengths greater than MAX_CIPHER_KEY_LENGTH -- consider increasing MAX_CIPHER_KEY_LENGTH
78#if MAX_HMAC_KEY_LENGTH < EVP_MAX_MD_SIZE
79#warning Some OpenSSL HMAC message digests now support key lengths greater than MAX_HMAC_KEY_LENGTH -- consider increasing MAX_HMAC_KEY_LENGTH
82#if HAVE_OPENSSL_ENGINE
83#include <openssl/ui.h>
84#include <openssl/engine.h>
86static bool engine_initialized =
false;
88static ENGINE *engine_persist = NULL;
92try_load_engine(
const char *engine)
94 ENGINE *e = ENGINE_by_id(
"dynamic");
97 if (!ENGINE_ctrl_cmd_string(e,
"SO_PATH", engine, 0)
98 || !ENGINE_ctrl_cmd_string(e,
"LOAD", NULL, 0))
108setup_engine(
const char *engine)
112 ENGINE_load_builtin_engines();
116 if (strcmp(engine,
"auto") == 0)
118 msg(
M_INFO,
"Initializing OpenSSL auto engine support");
119 ENGINE_register_all_complete();
122 if ((e = ENGINE_by_id(engine)) == NULL && (e = try_load_engine(engine)) == NULL)
127 if (!ENGINE_set_default(e, ENGINE_METHOD_ALL))
129 crypto_msg(
M_FATAL,
"OpenSSL error: ENGINE_set_default failed on engine '%s'", engine);
132 msg(
M_INFO,
"Initializing OpenSSL support for engine '%s'", ENGINE_get_id(e));
142#if HAVE_OPENSSL_ENGINE
143 if (!engine_initialized)
147 engine_persist = setup_engine(engine_name);
148 engine_initialized =
true;
151 msg(
M_WARN,
"Note: OpenSSL hardware crypto engine functionality is not available");
158#if OPENSSL_VERSION_NUMBER >= 0x30000000L
167 msg(
M_WARN,
"Note: OpenSSL provider functionality is not available");
175#if OPENSSL_VERSION_NUMBER >= 0x30000000L
176 if (!OSSL_PROVIDER_unload(provider))
192 OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CONFIG, NULL);
200 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
208 FILE *fp = fopen(
"sdlog",
"w");
210 CRYPTO_mem_leaks_fp(fp);
214#if HAVE_OPENSSL_ENGINE
215 if (engine_initialized)
218 engine_persist = NULL;
219 engine_initialized =
false;
235 const char *file, *data, *func;
239 if (!(errflags & ERR_TXT_STRING))
245 if (ERR_GET_REASON(err) == SSL_R_NO_SHARED_CIPHER)
248 "in common with the client. Your --tls-cipher setting might be "
251 else if (ERR_GET_REASON(err) == SSL_R_UNSUPPORTED_PROTOCOL)
254 "TLS error: Unsupported protocol. This typically "
255 "indicates that client and server have no common TLS version enabled. "
256 "This can be caused by mismatched tls-version-min and tls-version-max "
257 "options on client and server. "
258 "If your OpenVPN client is between v2.3.6 and v2.3.2 try adding "
259 "tls-version-min 1.0 to the client configuration to use TLS 1.0+ "
260 "instead of TLS 1.0 only");
266 msg(flags,
"OpenSSL: %s:%s", ERR_error_string(err, NULL), data);
270 msg(flags,
"OpenSSL: %s:%s:%s:%d:%s", ERR_error_string(err, NULL), data, file, line,
278 {
"AES-128-GCM",
"id-aes128-GCM" },
279 {
"AES-192-GCM",
"id-aes192-GCM" },
280 {
"AES-256-GCM",
"id-aes256-GCM" },
281 {
"CHACHA20-POLY1305",
"ChaCha20-Poly1305" },
290 const EVP_CIPHER *
const *cipher_a = a;
291 const EVP_CIPHER *
const *cipher_b = b;
313 msg(
M_WARN,
"WARNING: Too many ciphers, not showing all");
321#ifdef ENABLE_OFB_CFB_MODE
326 cipher_list->
list[cipher_list->
num++] = cipher;
336 printf(
"The following ciphers and cipher modes are available for use\n"
337 "with " PACKAGE_NAME
". Each cipher shown below may be used as a\n"
338 "parameter to the --data-ciphers (or --cipher) option. In static \n"
339 "key mode only CBC mode is allowed.\n");
340 printf(
"See also openssl list -cipher-algorithms\n\n");
343#if OPENSSL_VERSION_NUMBER >= 0x30000000L
346 for (
int nid = 0; nid < 10000; ++nid)
348#if defined(LIBRESSL_VERSION_NUMBER)
352 const EVP_CIPHER *cipher = NULL;
353 const char *name = OBJ_nid2sn(nid);
356 cipher = EVP_get_cipherbyname(name);
359 const EVP_CIPHER *cipher = EVP_get_cipherbynid(nid);
368 qsort((EVP_CIPHER *)cipher_list.
list, cipher_list.
num,
sizeof(*cipher_list.
list),
371 for (
size_t i = 0; i < cipher_list.
num; i++)
379 printf(
"\nThe following ciphers have a block size of less than 128 bits, \n"
380 "and are therefore deprecated. Do not use unless you have to.\n\n");
381 for (
size_t i = 0; i < cipher_list.
num; i++)
395 (
int)EVP_MD_size(digest) * 8);
402 printf(
"The following message digests are available for use with\n" PACKAGE_NAME
403 ". A message digest is used in conjunction with\n"
404 "the HMAC function, to authenticate received packets.\n"
405 "You can specify a message digest as parameter to\n"
406 "the --auth option.\n");
407 printf(
"See also openssl list -digest-algorithms\n\n");
410#if OPENSSL_VERSION_NUMBER >= 0x30000000L
413 for (
int nid = 0; nid < 10000; ++nid)
418#ifdef LIBRESSL_VERSION_NUMBER
419 const EVP_MD *digest = NULL;
420 const char *name = OBJ_nid2sn(nid);
423 digest = EVP_get_digestbyname(name);
426 const EVP_MD *digest = EVP_get_digestbynid(nid);
442#if HAVE_OPENSSL_ENGINE
445 printf(
"OpenSSL Crypto Engines\n\n");
447 ENGINE_load_builtin_engines();
449 e = ENGINE_get_first();
452 printf(
"%s [%s]\n", ENGINE_get_name(e), ENGINE_get_id(e));
453 e = ENGINE_get_next(e);
457 printf(
"Sorry, OpenSSL hardware crypto engine functionality is not available.\n");
467 BIO *bio = BIO_new(BIO_s_mem());
468 if (!bio || !PEM_write_bio(bio, name,
"",
BPTR(src),
BLEN(src)))
475 BIO_get_mem_ptr(bio, &bptr);
495 BIO *bio = BIO_new_mem_buf((
char *)
BPTR(src),
BLEN(src));
501 char *name_read = NULL;
502 char *header_read = NULL;
503 uint8_t *data_read = NULL;
504 long data_read_len = 0;
505 if (!PEM_read_bio(bio, &name_read, &header_read, &data_read, &data_read_len))
511 if (strcmp(name, name_read))
525 memcpy(dst_data, data_read, data_read_len);
529 OPENSSL_free(name_read);
530 OPENSSL_free(header_read);
531 OPENSSL_free(data_read);
552 if (
unlikely(1 != RAND_bytes(output, len)))
583 *reason =
"disabled because unknown";
591 if (FIPS_mode() && !(EVP_CIPHER_flags(cipher) & EVP_CIPH_FLAG_FIPS))
594 "Cipher algorithm '%s' is known by OpenSSL library but "
595 "currently disabled by running in FIPS mode.",
597 *reason =
"disabled by FIPS mode";
604 "Cipher algorithm '%s' uses a default key size (%d bytes) "
605 "which is larger than " PACKAGE_NAME
"'s current maximum key size "
608 *reason =
"disabled due to key size too large";
623 if (strcmp(
"none", ciphername) == 0)
625 return "[null-cipher]";
634 const char *name = EVP_CIPHER_name(cipher_kt);
643 int size = EVP_CIPHER_key_length(cipher);
653 int ivsize = EVP_CIPHER_iv_length(cipher);
669 char *mode_str = NULL;
670 const char *orig_name = NULL;
678 int block_size = EVP_CIPHER_block_size(cipher);
680 orig_name = EVP_CIPHER_name(cipher);
687 mode_str = strrchr(name,
'-');
688 if (!mode_str || strlen(mode_str) < 4)
693 strcpy(mode_str,
"-CBC");
698 block_size = EVP_CIPHER_block_size(cbc_cipher);
729#ifdef NID_chacha20_poly1305
733 bool ischachapoly = (EVP_CIPHER_nid(cipher) == NID_chacha20_poly1305);
747 ASSERT(NULL != cipher_kt);
748 return EVP_CIPHER_mode(cipher_kt);
759#ifdef EVP_CIPH_FLAG_CTS
760 && !(EVP_CIPHER_flags(cipher) & EVP_CIPH_FLAG_CTS)
762 && !(EVP_CIPHER_flags(cipher) & EVP_CIPH_FLAG_AEAD_CIPHER)
772 bool ofb_cfb = cipher
776 && !(EVP_CIPHER_flags(cipher) & EVP_CIPH_FLAG_AEAD_CIPHER);
794#ifdef NID_chacha20_poly1305
795 if (EVP_CIPHER_nid(cipher) == NID_chacha20_poly1305)
816 EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
824 EVP_CIPHER_CTX_free(ctx);
831 ASSERT(NULL != ciphername && NULL != ctx);
834 EVP_CIPHER_CTX_reset(ctx);
835 if (!EVP_CipherInit_ex(ctx, kt, NULL,
key, NULL, enc))
841 ASSERT(EVP_CIPHER_CTX_key_length(ctx) <= EVP_CIPHER_key_length(kt));
848 return EVP_CIPHER_CTX_iv_length(ctx);
854 return EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_GET_TAG, tag_size, tag_buf);
860 return EVP_CIPHER_CTX_block_size(ctx);
866 return EVP_CIPHER_CTX_mode(ctx);
877 unsigned long flags = EVP_CIPHER_CTX_flags(ctx);
878 int mode = EVP_CIPHER_CTX_mode(ctx);
880 return mode == EVP_CIPH_CBC_MODE
882#ifdef EVP_CIPH_FLAG_CTS
883 && !(flags & EVP_CIPH_FLAG_CTS)
885 && !(flags & EVP_CIPH_FLAG_AEAD_CIPHER);
898 return (mode == EVP_CIPH_OFB_MODE || mode == EVP_CIPH_CFB_MODE)
900 && !(EVP_CIPHER_CTX_flags(ctx) & EVP_CIPH_FLAG_AEAD_CIPHER);
908 unsigned long flags = EVP_CIPHER_CTX_flags(ctx);
909 if (flags & EVP_CIPH_FLAG_AEAD_CIPHER)
914#if defined(NID_chacha20_poly1305) && OPENSSL_VERSION_NUMBER < 0x30000000L
915 if (EVP_CIPHER_CTX_nid(ctx) == NID_chacha20_poly1305)
929 return EVP_CipherInit_ex(ctx, NULL, NULL, NULL, iv_buf, -1);
936 if (!EVP_CipherUpdate(ctx, NULL, &len, src, src_len))
946 if (!EVP_CipherUpdate(ctx, dst, dst_len, src, src_len))
956 return EVP_CipherFinal(ctx, dst, dst_len);
963 ASSERT(tag_len < INT_MAX);
964 if (!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, (
int)tag_len, tag))
992 "Message hash algorithm '%s' uses a default hash "
993 "size (%d bytes) which is larger than " PACKAGE_NAME
"'s current "
994 "maximum hash size (%d bytes)",
1005 bool valid = (md != NULL);
1018 {
"BLAKE2s256",
"BLAKE2S-256" },
1019 {
"BLAKE2b512",
"BLAKE2B-512" },
1020 {
"RIPEMD160",
"RIPEMD-160" },
1021 {
"SHA224",
"SHA2-224" },
1022 {
"SHA256",
"SHA2-256" },
1023 {
"SHA384",
"SHA2-384" },
1024 {
"SHA512",
"SHA2-512" },
1025 {
"SHA512-224",
"SHA2-512/224" },
1026 {
"SHA512-256",
"SHA2-512/256" },
1027 {
"SHAKE128",
"SHAKE-128" },
1028 {
"SHAKE256",
"SHAKE-256" },
1036 if (!strcmp(
"none", mdname))
1038 return "[null-digest]";
1060 if (!strcmp(
"none", mdname))
1065 unsigned char size = (
unsigned char)EVP_MD_size(kt);
1080 EVP_MD_CTX *ctx = EVP_MD_CTX_new();
1088 EVP_MD_CTX_free(ctx);
1095 ASSERT(NULL != ctx && NULL != kt);
1097 EVP_MD_CTX_init(ctx);
1098 if (!EVP_DigestInit(ctx, kt))
1108 EVP_MD_CTX_reset(ctx);
1114 return (
int)EVP_MD_CTX_size(ctx);
1120 EVP_DigestUpdate(ctx, src, src_len);
1126 unsigned int in_md_len = 0;
1128 EVP_DigestFinal(ctx, dst, &in_md_len);
1137#if OPENSSL_VERSION_NUMBER < 0x30000000L
1141 HMAC_CTX *ctx = HMAC_CTX_new();
1156 ASSERT(NULL != kt && NULL != ctx);
1158 int key_len = (int)EVP_MD_size(kt);
1159 HMAC_CTX_reset(ctx);
1160 if (!HMAC_Init_ex(ctx,
key, key_len, kt, NULL))
1166 ASSERT((ssize_t)HMAC_size(ctx) <= key_len);
1172 HMAC_CTX_reset(ctx);
1175#if defined(__GNUC__) || defined(__clang__)
1176#pragma GCC diagnostic push
1177#pragma GCC diagnostic ignored "-Wconversion"
1183 return HMAC_size(ctx);
1186#if defined(__GNUC__) || defined(__clang__)
1187#pragma GCC diagnostic pop
1193 if (!HMAC_Init_ex(ctx, NULL, 0, NULL, NULL))
1202 HMAC_Update(ctx, src, src_len);
1208 unsigned int in_hmac_len = 0;
1210 HMAC_Final(ctx, dst, &in_hmac_len);
1218 EVP_MAC *hmac = EVP_MAC_fetch(NULL,
"HMAC", NULL);
1219 ctx->ctx = EVP_MAC_CTX_new(hmac);
1230 EVP_MAC_CTX_free(ctx->ctx);
1239 ASSERT(NULL != kt && NULL != ctx && ctx->ctx != NULL);
1243 memcpy(ctx->
key,
key, (
size_t)EVP_MD_size(kt));
1251 ctx->params[0] = OSSL_PARAM_construct_utf8_string(
"digest", (
char *)
EVP_MD_get0_name(kt), 0);
1252 ctx->params[1] = OSSL_PARAM_construct_octet_string(
"key", ctx->
key, (
size_t)EVP_MD_size(kt));
1253 ctx->params[2] = OSSL_PARAM_construct_end();
1255 if (!EVP_MAC_init(ctx->ctx, NULL, 0, ctx->params))
1266 EVP_MAC_init(ctx->ctx, NULL, 0, NULL);
1272 return (
int)EVP_MAC_CTX_get_mac_size(ctx->ctx);
1281 if (!EVP_MAC_init(ctx->ctx, NULL, 0, ctx->params))
1290 EVP_MAC_update(ctx->ctx, src, src_len);
1298 size_t in_hmac_len = EVP_MAC_CTX_get_mac_size(ctx->ctx);
1300 EVP_MAC_final(ctx->ctx, dst, &in_hmac_len, in_hmac_len);
1307 return CRYPTO_memcmp(a, b, size);
1309#if (OPENSSL_VERSION_NUMBER >= 0x30000000L) && !defined(LIBRESSL_VERSION_NUMBER)
1311ssl_tls1_PRF(
const uint8_t *seed,
size_t seed_len,
const uint8_t *secret,
size_t secret_len,
1312 uint8_t *output,
size_t output_len)
1315 EVP_KDF_CTX *kctx = NULL;
1318 EVP_KDF *kdf = EVP_KDF_fetch(NULL,
"TLS1-PRF", NULL);
1324 kctx = EVP_KDF_CTX_new(kdf);
1331 OSSL_PARAM params[4];
1336 OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST, SN_md5_sha1, strlen(SN_md5_sha1));
1337 params[1] = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SECRET, (uint8_t *)secret,
1340 OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SEED, (uint8_t *)seed, seed_len);
1341 params[3] = OSSL_PARAM_construct_end();
1343 if (EVP_KDF_derive(kctx, output, output_len, params) <= 0)
1346 "EVP_KDF_derive failed");
1355 EVP_KDF_CTX_free(kctx);
1360#elif defined(OPENSSL_IS_AWSLC)
1362ssl_tls1_PRF(
const uint8_t *label,
size_t label_len,
const uint8_t *sec,
size_t slen, uint8_t *out1,
1365 return CRYPTO_tls1_prf(EVP_md5_sha1(), out1, olen, sec, slen,
1366 (
const char *)label, label_len, NULL, 0, NULL, 0);
1368#elif !defined(LIBRESSL_VERSION_NUMBER) && !defined(ENABLE_CRYPTO_WOLFSSL)
1369#if defined(__GNUC__) || defined(__clang__)
1370#pragma GCC diagnostic push
1371#pragma GCC diagnostic ignored "-Wconversion"
1375ssl_tls1_PRF(
const uint8_t *seed,
size_t seed_len,
const uint8_t *secret,
size_t secret_len,
1376 uint8_t *output,
size_t output_len)
1378 EVP_PKEY_CTX *pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_TLS1_PRF, NULL);
1385 if (!EVP_PKEY_derive_init(pctx))
1390 if (!EVP_PKEY_CTX_set_tls1_prf_md(pctx, EVP_md5_sha1()))
1395 if (!EVP_PKEY_CTX_set1_tls1_prf_secret(pctx, secret, secret_len))
1400 if (!EVP_PKEY_CTX_add1_tls1_prf_seed(pctx, seed, seed_len))
1405 size_t out_len = output_len;
1406 if (!EVP_PKEY_derive(pctx, output, &out_len))
1410 if (out_len != output_len)
1416 EVP_PKEY_CTX_free(pctx);
1420#if defined(__GNUC__) || defined(__clang__)
1421#pragma GCC diagnostic pop
1429ssl_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)
Allocate a buffer of the given size under garbage collection.
char * string_alloc(const char *str, struct gc_arena *gc)
Duplicate a string, allocating memory under garbage collection.
Buffer management functions and garbage collection.
#define BPTR(buf)
Return a pointer to the start of the buffer content.
static void secure_memzero(void *data, size_t len)
Securely zeroise memory.
static uint8_t * buf_write_alloc(struct buffer *buf, size_t size)
Reserve space at the end of a buffer for writing.
static bool buf_write(struct buffer *dest, const void *src, size_t size)
Append data to a buffer.
#define BLEN(buf)
Return the length of the buffer content in bytes.
#define BCAP(buf)
Return the number of bytes available for appending to the buffer.
static void check_malloc_return(void *p)
Abort if a memory allocation returned NULL.
#define ALLOC_OBJ_CLEAR(dptr, type)
Allocate and zero-initialise memory for a single object of the given 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
#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.
#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.
bool cipher_kt_mode_cbc(const char *ciphername)
Check if the supplied cipher is a supported CBC mode cipher.
void md_ctx_update(EVP_MD_CTX *ctx, const uint8_t *src, size_t src_len)
void show_available_engines(void)
const cipher_name_pair digest_name_translation_table[]
unsigned 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.
void crypto_unload_provider(const char *provname, provider_t *provider)
Unloads the given (OpenSSL) provider.
void crypto_uninit_lib(void)
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.
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)
unsigned int cipher_ctx_block_size(const EVP_CIPHER_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)
unsigned 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)
unsigned int cipher_kt_key_size(const char *ciphername)
Returns the size of keys used by the cipher, in bytes.
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.
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)
int cipher_ctx_final(EVP_CIPHER_CTX *ctx, uint8_t *dst, int *dst_len)
unsigned int cipher_ctx_iv_length(const EVP_CIPHER_CTX *ctx)
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_get_tag(EVP_CIPHER_CTX *ctx, uint8_t *tag_buf, int tag_size)
unsigned int cipher_kt_block_size(const char *ciphername)
Returns the block size of the cipher, in bytes.
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 openssl_err_t ERR_get_error_all(const char **file, int *line, const char **func, const char **data, int *flags)
static void EVP_CIPHER_free(const EVP_CIPHER *cipher)
static const EVP_CIPHER * EVP_CIPHER_fetch(void *ctx, const char *algorithm, const char *properties)
#define EVP_CIPH_FLAG_ENC_THEN_MAC
static void EVP_MD_free(const EVP_MD *md)
static const EVP_MD * EVP_MD_fetch(void *ctx, const char *algorithm, const char *properties)
unsigned long openssl_err_t
#define EVP_CIPHER_get0_name
#define EVP_CIPHER_CTX_get_mode
static bool check_debug_level(msglvl_t 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)