33 #ifndef MBEDTLS_COMPAT_H_
34 #define MBEDTLS_COMPAT_H_
40 #include <mbedtls/cipher.h>
41 #include <mbedtls/ctr_drbg.h>
42 #include <mbedtls/dhm.h>
43 #include <mbedtls/ecp.h>
44 #include <mbedtls/md.h>
45 #include <mbedtls/pem.h>
46 #include <mbedtls/pk.h>
47 #include <mbedtls/ssl.h>
48 #include <mbedtls/version.h>
49 #include <mbedtls/x509_crt.h>
51 #if HAVE_MBEDTLS_PSA_CRYPTO_H
52 #include <psa/crypto.h>
55 #if MBEDTLS_VERSION_NUMBER >= 0x03000000
64 #if HAVE_MBEDTLS_PSA_CRYPTO_H && defined(MBEDTLS_PSA_CRYPTO_C)
65 if (psa_crypto_init() != PSA_SUCCESS)
67 msg(
M_FATAL,
"mbedtls: psa_crypto_init() failed");
77 #if MBEDTLS_VERSION_NUMBER >= 0x03000000
78 return curve_info->tls_id;
80 return curve_info->grp_id;
94 const unsigned char *additional,
97 #if MBEDTLS_VERSION_NUMBER > 0x03000000
98 return mbedtls_ctr_drbg_update(ctx, additional, add_len);
99 #elif HAVE_MBEDTLS_CTR_DRBG_UPDATE_RET
100 return mbedtls_ctr_drbg_update_ret(ctx, additional, add_len);
102 mbedtls_ctr_drbg_update(ctx, additional, add_len);
109 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng)
111 #if MBEDTLS_VERSION_NUMBER < 0x03020100
112 return mbedtls_pk_check_pair(pub, prv);
114 return mbedtls_pk_check_pair(pub, prv, f_rng, p_rng);
120 const unsigned char *
key,
size_t keylen,
121 const unsigned char *pwd,
size_t pwdlen,
122 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng)
124 #if MBEDTLS_VERSION_NUMBER < 0x03020100
125 return mbedtls_pk_parse_key(ctx,
key, keylen, pwd, pwdlen);
127 return mbedtls_pk_parse_key(ctx,
key, keylen, pwd, pwdlen, f_rng, p_rng);
133 const char *path,
const char *password,
134 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng)
136 #if MBEDTLS_VERSION_NUMBER < 0x03020100
137 return mbedtls_pk_parse_keyfile(ctx, path, password);
139 return mbedtls_pk_parse_keyfile(ctx, path, password, f_rng, p_rng);
143 #if MBEDTLS_VERSION_NUMBER < 0x03020100
153 int major = (tls_version >> 8) & 0xff;
154 int minor = tls_version & 0xff;
155 mbedtls_ssl_conf_min_version(conf, major, minor);
161 int major = (tls_version >> 8) & 0xff;
162 int minor = tls_version & 0xff;
163 mbedtls_ssl_conf_max_version(conf, major, minor);
169 mbedtls_ssl_conf_curves(conf, groups);
175 return (
size_t)cipher->block_size;
181 return (
size_t)cipher->iv_size;
187 return (
size_t)cipher->key_bitlen;
190 static inline mbedtls_cipher_mode_t
196 static inline const char *
202 static inline mbedtls_cipher_type_t
214 static inline const mbedtls_md_info_t *
220 static inline const unsigned char *
223 *buf_size = ctx->buflen;
230 return ctx->ext_types & ext_type;