Go to the documentation of this file.
29 #ifndef CRYPTO_BACKEND_H_
30 #define CRYPTO_BACKEND_H_
32 #ifdef ENABLE_CRYPTO_OPENSSL
35 #ifdef ENABLE_CRYPTO_MBEDTLS
42 #define OPENVPN_AEAD_TAG_LENGTH 16
45 #define OPENVPN_MAX_CIPHER_BLOCK_SIZE 32
48 #define OPENVPN_MAX_HMAC_SIZE 64
102 void crypto_init_dmalloc(
void);
138 const struct buffer *src);
177 #define MAX_CIPHER_KEY_LENGTH 64
221 return strcmp(ciphername,
"none") != 0;
451 uint8_t *src,
int src_len);
479 uint8_t *tag,
size_t tag_len);
495 #define MAX_HMAC_KEY_LENGTH 64
506 return strcmp(mdname,
"none") != 0;
555 int md_full(
const char *mdname,
const uint8_t *src,
int src_len, uint8_t *dst);
719 bool ssl_tls1_PRF(
const uint8_t *seed,
int seed_len,
const uint8_t *secret,
720 int secret_len, uint8_t *output,
int output_len);
int md_full(const char *mdname, const uint8_t *src, int src_len, uint8_t *dst)
Calculates the message digest for the given buffer.
cipher_ctx_t * cipher_ctx_new(void)
Generic cipher functions.
void crypto_uninit_lib(void)
static bool cipher_valid(const char *ciphername)
Returns if the cipher is valid, based on the given cipher name.
void hmac_ctx_cleanup(hmac_ctx_t *ctx)
int cipher_ctx_iv_length(const cipher_ctx_t *ctx)
Returns the size of the IV used by the cipher, in bytes, or 0 if no IV is used.
mbedtls_md_context_t hmac_ctx_t
Generic HMAC context.
static bool cipher_defined(const char *ciphername)
Checks if the cipher is defined and is not the null (none) cipher.
mbedtls_md_context_t md_ctx_t
Generic message digest context.
int cipher_ctx_final_check_tag(cipher_ctx_t *ctx, uint8_t *dst, int *dst_len, uint8_t *tag, size_t tag_len)
Like cipher_ctx_final, but check the computed authentication tag against the supplied (expected) tag.
const char * translate_cipher_name_to_openvpn(const char *cipher_name)
Translate a crypto library cipher name to an OpenVPN cipher name.
void show_available_ciphers(void)
int md_ctx_size(const md_ctx_t *ctx)
bool cipher_ctx_mode_cbc(const cipher_ctx_t *ctx)
Check if the supplied cipher is a supported CBC mode cipher.
void hmac_ctx_update(hmac_ctx_t *ctx, const uint8_t *src, int src_len)
const char * cipher_kt_name(const char *ciphername)
Retrieve a normalised string describing the cipher (e.g.
md_ctx_t * md_ctx_new(void)
bool cipher_ctx_mode_ofb_cfb(const cipher_ctx_t *ctx)
Check if the supplied cipher is a supported OFB or CFB mode cipher.
int cipher_ctx_final(cipher_ctx_t *ctx, uint8_t *dst, int *dst_len)
Pads the final cipher block using PKCS padding, and output to the destination buffer.
Container for unidirectional cipher and HMAC key material.
void cipher_ctx_free(cipher_ctx_t *ctx)
Cleanup and free a cipher context.
int cipher_kt_block_size(const char *ciphername)
Returns the block size of the cipher, in bytes.
const cipher_name_pair cipher_name_translation_table[]
Cipher name translation table.
void md_ctx_final(md_ctx_t *ctx, uint8_t *dst)
const char * md_kt_name(const char *mdname)
Retrieve a string describing the digest digest (e.g.
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.
const char * openvpn_name
Cipher name used by OpenVPN.
mbedtls_cipher_context_t cipher_ctx_t
Generic cipher context.
void md_ctx_cleanup(md_ctx_t *ctx)
int cipher_ctx_update(cipher_ctx_t *ctx, uint8_t *dst, int *dst_len, uint8_t *src, int src_len)
Updates the given cipher context, encrypting data in the source buffer, and placing any complete bloc...
void cipher_ctx_init(cipher_ctx_t *ctx, const uint8_t *key, const char *cipername, crypto_operation_t enc)
Initialise a cipher context, based on the given key and key type.
void crypto_init_lib(void)
void crypto_clear_error(void)
hash_algo_type
Types referencing specific message digest hashing algorithms.
int cipher_ctx_mode(const cipher_ctx_t *ctx)
Returns the mode that the cipher runs in.
unsigned char md_kt_size(const char *mdname)
Returns the size of the message digest, in bytes.
int cipher_ctx_update_ad(cipher_ctx_t *ctx, const uint8_t *src, int src_len)
Updates the given cipher context, providing additional data (AD) for authenticated encryption with ad...
void hmac_ctx_final(hmac_ctx_t *ctx, uint8_t *dst)
void crypto_unload_provider(const char *provname, provider_t *provider)
Unloads the given (OpenSSL) provider.
bool cipher_kt_mode_aead(const char *ciphername)
Check if the supplied cipher is a supported AEAD mode cipher.
bool cipher_ctx_mode_aead(const cipher_ctx_t *ctx)
Check if the supplied cipher is a supported AEAD mode cipher.
const size_t cipher_name_translation_table_count
Wrapper structure for dynamically allocated memory.
void md_ctx_update(md_ctx_t *ctx, const uint8_t *src, int src_len)
void md_ctx_init(md_ctx_t *ctx, const char *mdname)
Initialises the given message digest context.
void hmac_ctx_reset(hmac_ctx_t *ctx)
int rand_bytes(uint8_t *output, int len)
Wrapper for secure random number generator.
void hmac_ctx_free(hmac_ctx_t *ctx)
Struct used in cipher name translation table.
void show_available_engines(void)
int cipher_ctx_block_size(const cipher_ctx_t *ctx)
Returns the block size of the cipher, in bytes.
void show_available_digests(void)
bool cipher_kt_mode_ofb_cfb(const char *ciphername)
Check if the supplied cipher is a supported OFB or CFB mode cipher.
bool cipher_kt_insecure(const char *ciphername)
Returns true if we consider this cipher to be insecure.
Garbage collection arena used to keep track of dynamically allocated memory.
bool crypto_pem_encode(const char *name, struct buffer *dst, const struct buffer *src, struct gc_arena *gc)
Encode binary data as PEM.
int cipher_ctx_get_tag(cipher_ctx_t *ctx, uint8_t *tag, int tag_len)
Gets the computed message authenticated code (MAC) tag for this cipher.
int cipher_kt_key_size(const char *ciphername)
Returns the size of keys used by the cipher, in bytes.
int cipher_kt_tag_size(const char *ciphername)
Returns the MAC tag size of the cipher, in bytes.
void md_ctx_free(md_ctx_t *ctx)
bool crypto_pem_decode(const char *name, struct buffer *dst, const struct buffer *src)
Decode a PEM buffer to binary data.
static bool md_defined(const char *mdname)
Checks if the cipher is defined and is not the null (none) cipher.
provider_t * crypto_load_provider(const char *provider)
Load the given (OpenSSL) providers.
bool cipher_kt_mode_cbc(const char *ciphername)
Check if the supplied cipher is a supported CBC mode cipher.
int cipher_ctx_reset(cipher_ctx_t *ctx, const uint8_t *iv_buf)
Resets the given cipher context, setting the IV to the specified value.
hmac_ctx_t * hmac_ctx_new(void)
const char * translate_cipher_name_from_openvpn(const char *cipher_name)
Translate an OpenVPN cipher name to a crypto library cipher name.
void hmac_ctx_init(hmac_ctx_t *ctx, const uint8_t *key, const char *mdname)
bool md_valid(const char *digest)
Return if a message digest parameters is valid given the name of the digest.
void crypto_init_lib_engine(const char *engine_name)
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.
const char * lib_name
Cipher name used by crypto library.
bool ssl_tls1_PRF(const uint8_t *seed, int seed_len, const uint8_t *secret, int secret_len, uint8_t *output, int output_len)
Calculates the TLS 1.0-1.1 PRF function.
mbedtls_operation_t crypto_operation_t
int hmac_ctx_size(hmac_ctx_t *ctx)