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