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-2024 OpenVPN Inc <sales@openvpn.net>
9  * Copyright (C) 2010-2021 Fox Crypto B.V. <openvpn@foxcrypto.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, write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  */
24 
29 #ifndef CRYPTO_MBEDTLS_H_
30 #define CRYPTO_MBEDTLS_H_
31 
32 #include <mbedtls/cipher.h>
33 #include <mbedtls/md.h>
34 #include <mbedtls/ctr_drbg.h>
35 
37 typedef mbedtls_md_info_t md_kt_t;
38 
40 typedef mbedtls_cipher_context_t cipher_ctx_t;
41 
43 typedef mbedtls_md_context_t md_ctx_t;
44 
46 typedef mbedtls_md_context_t hmac_ctx_t;
47 
48 /* Use a dummy type for the provider */
49 typedef void provider_t;
50 
52 #define OPENVPN_MAX_IV_LENGTH MBEDTLS_MAX_IV_LENGTH
53 
55 #define OPENVPN_MODE_CBC MBEDTLS_MODE_CBC
56 
58 #define OPENVPN_MODE_OFB MBEDTLS_MODE_OFB
59 
61 #define OPENVPN_MODE_CFB MBEDTLS_MODE_CFB
62 
64 #define OPENVPN_MODE_GCM MBEDTLS_MODE_GCM
65 
66 typedef mbedtls_operation_t crypto_operation_t;
67 
69 #define OPENVPN_OP_ENCRYPT MBEDTLS_ENCRYPT
70 
72 #define OPENVPN_OP_DECRYPT MBEDTLS_DECRYPT
73 
74 #define MD4_DIGEST_LENGTH 16
75 #define MD5_DIGEST_LENGTH 16
76 #define SHA_DIGEST_LENGTH 20
77 #define SHA256_DIGEST_LENGTH 32
78 #define DES_KEY_LENGTH 8
79 
90 mbedtls_ctr_drbg_context *rand_ctx_get(void);
91 
92 #ifdef ENABLE_PREDICTION_RESISTANCE
93 
96 void rand_ctx_enable_prediction_resistance(void);
97 
98 #endif
99 
109 bool mbed_log_err(unsigned int flags, int errval, const char *prefix);
110 
121 bool mbed_log_func_line(unsigned int flags, int errval, const char *func,
122  int line);
123 
125 static inline bool
126 mbed_log_func_line_lite(unsigned int flags, int errval,
127  const char *func, int line)
128 {
129  if (errval)
130  {
131  return mbed_log_func_line(flags, errval, func, line);
132  }
133  return true;
134 }
135 
148 #define mbed_ok(errval) \
149  mbed_log_func_line_lite(D_CRYPT_ERRORS, errval, __func__, __LINE__)
150 
151 #endif /* CRYPTO_MBEDTLS_H_ */
mbed_log_func_line_lite
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.
Definition: crypto_mbedtls.h:126
hmac_ctx_t
mbedtls_md_context_t hmac_ctx_t
Generic HMAC context.
Definition: crypto_mbedtls.h:46
rand_ctx_get
mbedtls_ctr_drbg_context * rand_ctx_get(void)
Returns a singleton instance of the mbed TLS random number generator.
md_ctx_t
mbedtls_md_context_t md_ctx_t
Generic message digest context.
Definition: crypto_mbedtls.h:43
cipher_ctx_t
mbedtls_cipher_context_t cipher_ctx_t
Generic cipher context.
Definition: crypto_mbedtls.h:40
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.
provider_t
void provider_t
Definition: crypto_mbedtls.h:49
md_kt_t
mbedtls_md_info_t md_kt_t
Generic message digest key type context.
Definition: crypto_mbedtls.h:37
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.
crypto_operation_t
mbedtls_operation_t crypto_operation_t
Definition: crypto_mbedtls.h:66