Go to the documentation of this file.
25 #ifndef SOPC_CRYPTO_MBEDTLS_COMMON_H_
26 #define SOPC_CRYPTO_MBEDTLS_COMMON_H_
28 #include "mbedtls/version.h"
30 #if MBEDTLS_VERSION_MAJOR == 2
31 #if MBEDTLS_VERSION_MINOR >= 28
32 #define MBEDTLS_CAN_RESOLVE_HOSTNAME 1
34 #define MBEDTLS_CAN_RESOLVE_HOSTNAME 0
36 #define MBEDTLS_X509_SAN_DNS_NAME 2
37 #define MBEDTLS_X509_SAN_UNIFORM_RESOURCE_IDENTIFIER 6
38 #endif // MBEDTLS_VERSION_MINOR >= 28
41 #define MBEDTLS_RSA_RSAES_OAEP_ENCRYPT(ctx, f_rng, p_rng, label, label_len, ilen, input, output) \
42 mbedtls_rsa_rsaes_oaep_encrypt(ctx, f_rng, p_rng, MBEDTLS_RSA_PUBLIC, label, label_len, ilen, input, output)
43 #define MBEDTLS_RSA_RSAES_OAEP_DECRYPT(ctx, f_rng, p_rng, label, label_len, olen, input, output, output_max_len) \
44 mbedtls_rsa_rsaes_oaep_decrypt(ctx, f_rng, p_rng, MBEDTLS_RSA_PRIVATE, label, label_len, olen, input, output, \
46 #define MBEDTLS_RSA_RSASSA_PKCS1_V15_SIGN(ctx, f_rng, p_rng, md_alg, hashlen, hash, sig) \
47 mbedtls_rsa_rsassa_pkcs1_v15_sign(ctx, f_rng, p_rng, MBEDTLS_RSA_PRIVATE, md_alg, hashlen, hash, sig)
48 #define MBEDTLS_RSA_RSASSA_PKCS1_V15_VERIFY(ctx, md_alg, hashlen, hash, sig) \
49 mbedtls_rsa_rsassa_pkcs1_v15_verify(ctx, NULL, NULL, MBEDTLS_RSA_PUBLIC, md_alg, hashlen, hash, sig)
50 #define MBEDTLS_RSA_RSASSA_PSS_SIGN(ctx, f_rng, p_rng, md_alg, hashlen, hash, sig) \
51 mbedtls_rsa_rsassa_pss_sign(ctx, f_rng, p_rng, MBEDTLS_RSA_PRIVATE, md_alg, hashlen, hash, sig)
52 #define MBEDTLS_RSA_RSASSA_PSS_VERIFY(ctx, md_alg, hashlen, hash, sig) \
53 mbedtls_rsa_rsassa_pss_verify(ctx, NULL, NULL, MBEDTLS_RSA_PUBLIC, md_alg, hashlen, hash, sig)
54 #define MBEDTLS_PK_PARSE_KEY mbedtls_pk_parse_key
55 #define MBEDTLS_RSA_SET_PADDING(prsa, padding, hash_id) mbedtls_rsa_set_padding(prsa, padding, (int) hash_id)
56 #define MBEDTLS_X509WRITE_CSR_SET_EXTENSION(ctx, oid, oid_len, val, val_len) \
57 mbedtls_x509write_csr_set_extension(ctx, oid, oid_len, val, val_len)
59 #elif MBEDTLS_VERSION_MAJOR == 3
61 #define MBEDTLS_CAN_RESOLVE_HOSTNAME 1
62 #define MBEDTLS_RSA_RSAES_OAEP_ENCRYPT mbedtls_rsa_rsaes_oaep_encrypt
63 #define MBEDTLS_RSA_RSAES_OAEP_DECRYPT mbedtls_rsa_rsaes_oaep_decrypt
64 #define MBEDTLS_RSA_RSASSA_PKCS1_V15_SIGN mbedtls_rsa_rsassa_pkcs1_v15_sign
65 #define MBEDTLS_RSA_RSASSA_PKCS1_V15_VERIFY mbedtls_rsa_rsassa_pkcs1_v15_verify
66 #define MBEDTLS_RSA_RSASSA_PSS_SIGN mbedtls_rsa_rsassa_pss_sign
67 #define MBEDTLS_RSA_RSASSA_PSS_VERIFY mbedtls_rsa_rsassa_pss_verify
68 #define MBEDTLS_RSA_SET_PADDING(prsa, padding, hash_id) mbedtls_rsa_set_padding(prsa, padding, hash_id)
69 #define MBEDTLS_X509WRITE_CSR_SET_EXTENSION(ctx, oid, oid_len, val, val_len) \
70 mbedtls_x509write_csr_set_extension(ctx, oid, oid_len, 0, val, val_len)
74 #define MBEDTLS_PK_PARSE_KEY(ctx, key, keylen, pwd, pwdlen) \
75 mbedtls_pk_parse_key(ctx, key, keylen, pwd, pwdlen, NULL, NULL)
78 #error "Cannot use elliptic curves with MBEDTLS V3. MBEDTLS_PK_PARSE_KEY must be modified to receive f_rng"
82 #ifndef MBEDTLS_ALLOW_PRIVATE_ACCESS
83 #define MBEDTLS_ALLOW_PRIVATE_ACCESS
87 #error "Unsupported MBEDTLS VERSION (see MBEDTLS_VERSION_MAJOR)"