OpenVPN
crypto_mbedtls.h
Go to the documentation of this file.
1/*
2 * OpenVPN -- An application to securely tunnel IP networks
3 * over a single TCP/UDP port, with support for SSL/TLS-based
4 * session authentication and key exchange,
5 * packet encryption, packet authentication, and
6 * packet compression.
7 *
8 * Copyright (C) 2002-2026 OpenVPN Inc <sales@openvpn.net>
9 * Copyright (C) 2010-2026 Sentyron B.V. <openvpn@sentyron.com>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2
13 * as published by the Free Software Foundation.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, see <https://www.gnu.org/licenses/>.
22 */
23
30#ifndef CRYPTO_MBEDTLS4_H_
31#define CRYPTO_MBEDTLS4_H_
32
33#include <psa/crypto.h>
34
35#include "integer.h"
36
38#define OPENVPN_MAX_IV_LENGTH 16
39
41#define OPENVPN_MODE_CBC PSA_ALG_CBC_PKCS7
42
44#define OPENVPN_MODE_OFB PSA_ALG_OFB
45
47#define OPENVPN_MODE_CFB PSA_ALG_CFB
48
50#define OPENVPN_MODE_GCM PSA_ALG_GCM
51
53
55#define OPENVPN_OP_ENCRYPT 0
56
58#define OPENVPN_OP_DECRYPT 1
59
60#define MD4_DIGEST_LENGTH 16
61#define MD5_DIGEST_LENGTH 16
62#define SHA_DIGEST_LENGTH 20
63#define SHA256_DIGEST_LENGTH 32
64
65typedef void provider_t;
66
67typedef struct cipher_info
68{
69 const char *name;
70 psa_key_type_t psa_key_type;
71 psa_algorithm_t psa_alg;
72 unsigned int key_bytes;
73 unsigned int iv_bytes;
74 unsigned int block_size;
76
78{
79 psa_cipher_operation_t cipher;
80 psa_aead_operation_t aead;
82
83typedef struct cipher_ctx
84{
85 mbedtls_svc_key_id_t key;
86 psa_key_attributes_t key_attributes;
90 uint8_t tag[16];
92
93typedef struct md_info
94{
95 const char *name;
96 psa_algorithm_t psa_alg;
98
99typedef struct md_ctx
100{
102 psa_hash_operation_t operation;
104
105typedef struct hmac_ctx
106{
107 mbedtls_svc_key_id_t key;
108 psa_key_attributes_t key_attributes;
110 psa_mac_operation_t operation;
112
122bool mbed_log_err(unsigned int flags, int errval, const char *prefix);
123
134bool mbed_log_func_line(unsigned int flags, int errval, const char *func, int line);
135
137static inline bool
138mbed_log_func_line_lite(unsigned int flags, int errval, const char *func, int line)
139{
140 if (errval)
141 {
142 return mbed_log_func_line(flags, errval, func, line);
143 }
144 return true;
145}
146
160#define mbed_ok(errval) mbed_log_func_line_lite(D_CRYPT_ERRORS, errval, __func__, __LINE__)
161
162#endif /* CRYPTO_MBEDTLS4_H_ */
struct md_info md_info_t
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.
struct hmac_ctx hmac_ctx_t
struct cipher_info cipher_info_t
int crypto_operation_t
bool mbed_log_err(unsigned int flags, int errval, const char *prefix)
Log the supplied mbed TLS error, prefixed by supplied prefix.
struct md_ctx md_ctx_t
struct cipher_ctx cipher_ctx_t
union psa_cipher_or_aead_operation cipher_operation_t
void provider_t
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.
cipher_operation_t operation
uint8_t tag[16]
psa_key_attributes_t key_attributes
mbedtls_svc_key_id_t key
const cipher_info_t * cipher_info
psa_key_type_t psa_key_type
unsigned int iv_bytes
psa_algorithm_t psa_alg
unsigned int key_bytes
const char * name
unsigned int block_size
const md_info_t * md_info
psa_mac_operation_t operation
psa_key_attributes_t key_attributes
mbedtls_svc_key_id_t key
const md_info_t * md_info
psa_hash_operation_t operation
psa_algorithm_t psa_alg
const char * name
psa_aead_operation_t aead
psa_cipher_operation_t cipher