OpenVPN
crypto_mbedtls.h File Reference

Data Channel Cryptography backend interface using the TF-PSA-Crypto library part of Mbed TLS 4. More...

#include <psa/crypto.h>
#include "integer.h"
Include dependency graph for crypto_mbedtls.h:

Go to the source code of this file.

Data Structures

struct  cipher_info
union  psa_cipher_or_aead_operation
struct  cipher_ctx
struct  md_info
struct  md_ctx
struct  hmac_ctx

Macros

#define OPENVPN_MAX_IV_LENGTH   16
 Maximum length of an IV.
#define OPENVPN_MODE_CBC   PSA_ALG_CBC_PKCS7
 Cipher is in CBC mode.
#define OPENVPN_MODE_OFB   PSA_ALG_OFB
 Cipher is in OFB mode.
#define OPENVPN_MODE_CFB   PSA_ALG_CFB
 Cipher is in CFB mode.
#define OPENVPN_MODE_GCM   PSA_ALG_GCM
 Cipher is in GCM mode.
#define OPENVPN_OP_ENCRYPT   0
 Cipher should encrypt.
#define OPENVPN_OP_DECRYPT   1
 Cipher should decrypt.
#define MD4_DIGEST_LENGTH   16
#define MD5_DIGEST_LENGTH   16
#define SHA_DIGEST_LENGTH   20
#define SHA256_DIGEST_LENGTH   32
#define mbed_ok(errval)
 Check errval and log on error.

Typedefs

typedef int crypto_operation_t
typedef void provider_t
typedef struct cipher_info cipher_info_t
typedef union psa_cipher_or_aead_operation cipher_operation_t
typedef struct cipher_ctx cipher_ctx_t
typedef struct md_info md_info_t
typedef struct md_ctx md_ctx_t
typedef struct hmac_ctx hmac_ctx_t

Functions

bool mbed_log_err (unsigned int flags, int errval, const char *prefix)
 Log the supplied mbed TLS error, prefixed by supplied prefix.
bool mbed_log_func_line (unsigned int flags, int errval, const char *func, int line)
 Log the supplied mbed TLS error, prefixed by function name and line number.
static bool mbed_log_func_line_lite (unsigned int flags, int errval, const char *func, int line)
 Wraps mbed_log_func_line() to prevent function calls for non-errors.

Detailed Description

Data Channel Cryptography backend interface using the TF-PSA-Crypto library part of Mbed TLS 4.

Definition in file crypto_mbedtls.h.

Macro Definition Documentation

◆ mbed_ok

#define mbed_ok ( errval)
Value:
mbed_log_func_line_lite(D_CRYPT_ERRORS, errval, __func__, __LINE__)
static bool mbed_log_func_line_lite(unsigned int flags, int errval, const char *func, int line)
Wraps mbed_log_func_line() to prevent function calls for non-errors.
#define D_CRYPT_ERRORS
Definition errlevel.h:57

Check errval and log on error.

Convenience wrapper to put around mbed TLS library calls, e.g. if (!mbed_ok (mbedtls_ssl_func())) return 0; or ASSERT (mbed_ok (mbedtls_ssl_func()));

Parameters
errvalmbed TLS error code to convert to error message.
Returns
true if no errors are detected, false otherwise. TODO: The log function has been removed, do something about it?

Definition at line 160 of file crypto_mbedtls.h.

Referenced by mbedtls_compat_pk_check_pair().

◆ MD4_DIGEST_LENGTH

#define MD4_DIGEST_LENGTH   16

Definition at line 60 of file crypto_mbedtls.h.

◆ MD5_DIGEST_LENGTH

#define MD5_DIGEST_LENGTH   16

Definition at line 61 of file crypto_mbedtls.h.

◆ OPENVPN_MAX_IV_LENGTH

#define OPENVPN_MAX_IV_LENGTH   16

◆ OPENVPN_MODE_CBC

#define OPENVPN_MODE_CBC   PSA_ALG_CBC_PKCS7

Cipher is in CBC mode.

Definition at line 41 of file crypto_mbedtls.h.

Referenced by cipher_kt_mode_cbc(), and openvpn_encrypt_v1().

◆ OPENVPN_MODE_CFB

#define OPENVPN_MODE_CFB   PSA_ALG_CFB

Cipher is in CFB mode.

Definition at line 47 of file crypto_mbedtls.h.

Referenced by cipher_kt_mode_ofb_cfb().

◆ OPENVPN_MODE_GCM

#define OPENVPN_MODE_GCM   PSA_ALG_GCM

Cipher is in GCM mode.

Definition at line 50 of file crypto_mbedtls.h.

Referenced by cipher_kt_mode_aead().

◆ OPENVPN_MODE_OFB

#define OPENVPN_MODE_OFB   PSA_ALG_OFB

Cipher is in OFB mode.

Definition at line 44 of file crypto_mbedtls.h.

Referenced by cipher_kt_mode_ofb_cfb().

◆ OPENVPN_OP_DECRYPT

#define OPENVPN_OP_DECRYPT   1

Cipher should decrypt.

Definition at line 58 of file crypto_mbedtls.h.

Referenced by init_key_bi_ctx_recv().

◆ OPENVPN_OP_ENCRYPT

#define OPENVPN_OP_ENCRYPT   0

Cipher should encrypt.

Definition at line 55 of file crypto_mbedtls.h.

Referenced by init_key_bi_ctx_send().

◆ SHA256_DIGEST_LENGTH

#define SHA256_DIGEST_LENGTH   32

Definition at line 63 of file crypto_mbedtls.h.

Referenced by add_option(), epoch_key::epoch_key, ovpn_hkdf_expand(), and show_settings().

◆ SHA_DIGEST_LENGTH

#define SHA_DIGEST_LENGTH   20

Definition at line 62 of file crypto_mbedtls.h.

Referenced by add_option(), and show_settings().

Typedef Documentation

◆ cipher_ctx_t

typedef struct cipher_ctx cipher_ctx_t

◆ cipher_info_t

typedef struct cipher_info cipher_info_t

◆ cipher_operation_t

◆ crypto_operation_t

typedef int crypto_operation_t

Definition at line 52 of file crypto_mbedtls.h.

◆ hmac_ctx_t

typedef struct hmac_ctx hmac_ctx_t

◆ md_ctx_t

typedef struct md_ctx md_ctx_t

◆ md_info_t

typedef struct md_info md_info_t

◆ provider_t

typedef void provider_t

Definition at line 65 of file crypto_mbedtls.h.

Function Documentation

◆ mbed_log_err()

bool mbed_log_err ( unsigned int flags,
int errval,
const char * prefix )

Log the supplied mbed TLS error, prefixed by supplied prefix.

Parameters
flagsFlags to indicate error type and priority.
errvalmbed TLS error code.
prefixPrefix to mbed TLS error message.
Returns
true if no errors are detected, false otherwise.

◆ mbed_log_func_line()

bool mbed_log_func_line ( unsigned int flags,
int errval,
const char * func,
int line )

Log the supplied mbed TLS error, prefixed by function name and line number.

Parameters
flagsFlags to indicate error type and priority.
errvalmbed TLS error code.
funcFunction name where error was reported.
lineLine number where error was reported.
Returns
true if no errors are detected, false otherwise.

Referenced by mbed_log_func_line_lite().

◆ mbed_log_func_line_lite()

bool mbed_log_func_line_lite ( unsigned int flags,
int errval,
const char * func,
int line )
inlinestatic

Wraps mbed_log_func_line() to prevent function calls for non-errors.

Definition at line 138 of file crypto_mbedtls.h.

References mbed_log_func_line().