libssh: /build/libssh/src/libssh-0.12.2/src/mbedcrypto-compat.h Source File

libssh 0.12.2 The SSH library

Loading...
Searching...
No Matches
mbedcrypto-compat.h
1#ifndef MBEDCRYPTO_COMPAT_H
2#define MBEDCRYPTO_COMPAT_H
3
4/* mbedtls/version.h should be available for both v2 and v3
5 * v3 defines the version inside build_info.h so if it isn't defined
6 * in version.h we should have v3
7 */
8#include <mbedtls/cipher.h>
9#include <mbedtls/version.h>
10
11#ifndef MBEDTLS_VERSION_MAJOR
12#include <mbedtls/build_info.h>
13#endif /* MBEDTLS_VERSION_MAJOR */
14
15#if MBEDTLS_VERSION_MAJOR < 3
16
17static inline size_t
18mbedtls_cipher_info_get_key_bitlen(const mbedtls_cipher_info_t *info)
19{
20 if (info == NULL) {
21 return 0;
22 }
23 return info->key_bitlen;
24}
25
26static inline size_t
27mbedtls_cipher_info_get_iv_size(const mbedtls_cipher_info_t *info)
28{
29 if (info == NULL) {
30 return 0;
31 }
32 return (size_t)info->iv_size;
33}
34
35#define MBEDTLS_PRIVATE(X) X
36
37#ifdef HAVE_MBEDTLS_CURVE25519
38#include <mbedtls/ecdh.h>
39
40#define MBEDTLS_ECDH_PRIVATE(X) X
41#define MBEDTLS_ECDH_PARAMS(X) X
42typedef mbedtls_ecdh_context mbedtls_ecdh_params;
43#endif /* HAVE_MBEDTLS_CURVE25519 */
44
45#else /* MBEDTLS_VERSION_MAJOR < 3 */
46
47#ifdef HAVE_MBEDTLS_CURVE25519
48#include <mbedtls/ecdh.h>
49
50#define MBEDTLS_ECDH_PRIVATE(X) MBEDTLS_PRIVATE(X)
51#define MBEDTLS_ECDH_PARAMS(X) X.MBEDTLS_PRIVATE(ctx).MBEDTLS_PRIVATE(mbed_ecdh)
52typedef mbedtls_ecdh_context_mbed mbedtls_ecdh_params;
53#endif /* HAVE_MBEDTLS_CURVE25519 */
54
55#endif /* MBEDTLS_VERSION_MAJOR < 3 */
56#endif /* MBEDCRYPTO_COMPAT_H */