26 #ifndef MBEDTLS_PSA_UTIL_H
27 #define MBEDTLS_PSA_UTIL_H
32 #if defined(MBEDTLS_USE_PSA_CRYPTO)
131 #if defined(MBEDTLS_MD5_C)
135 #if defined(MBEDTLS_SHA1_C)
139 #if defined(MBEDTLS_SHA224_C)
143 #if defined(MBEDTLS_SHA256_C)
147 #if defined(MBEDTLS_SHA384_C)
151 #if defined(MBEDTLS_SHA512_C)
155 #if defined(MBEDTLS_RIPEMD160_C)
170 char const **oid,
size_t *oid_len )
177 #if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED)
183 #if defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED)
189 #if defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED)
195 #if defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED)
201 #if defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED)
212 #if defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED)
218 #if defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED)
224 #if defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED)
235 #if defined(MBEDTLS_ECP_DP_BP256R1_ENABLED)
241 #if defined(MBEDTLS_ECP_DP_BP384R1_ENABLED)
247 #if defined(MBEDTLS_ECP_DP_BP512R1_ENABLED)
261 #define MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH 1
263 #if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED)
264 #if MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH < ( 2 * ( ( 192 + 7 ) / 8 ) + 1 )
265 #undef MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH
266 #define MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH ( 2 * ( ( 192 + 7 ) / 8 ) + 1 )
270 #if defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED)
271 #if MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH < ( 2 * ( ( 224 + 7 ) / 8 ) + 1 )
272 #undef MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH
273 #define MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH ( 2 * ( ( 224 + 7 ) / 8 ) + 1 )
277 #if defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED)
278 #if MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH < ( 2 * ( ( 256 + 7 ) / 8 ) + 1 )
279 #undef MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH
280 #define MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH ( 2 * ( ( 256 + 7 ) / 8 ) + 1 )
284 #if defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED)
285 #if MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH < ( 2 * ( ( 384 + 7 ) / 8 ) + 1 )
286 #undef MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH
287 #define MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH ( 2 * ( ( 384 + 7 ) / 8 ) + 1 )
291 #if defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED)
292 #if MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH < ( 2 * ( ( 521 + 7 ) / 8 ) + 1 )
293 #undef MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH
294 #define MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH ( 2 * ( ( 521 + 7 ) / 8 ) + 1 )
298 #if defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED)
299 #if MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH < ( 2 * ( ( 192 + 7 ) / 8 ) + 1 )
300 #undef MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH
301 #define MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH ( 2 * ( ( 192 + 7 ) / 8 ) + 1 )
305 #if defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED)
306 #if MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH < ( 2 * ( ( 224 + 7 ) / 8 ) + 1 )
307 #undef MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH
308 #define MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH ( 2 * ( ( 224 + 7 ) / 8 ) + 1 )
312 #if defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED)
313 #if MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH < ( 2 * ( ( 256 + 7 ) / 8 ) + 1 )
314 #undef MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH
315 #define MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH ( 2 * ( ( 256 + 7 ) / 8 ) + 1 )
319 #if defined(MBEDTLS_ECP_DP_BP256R1_ENABLED)
320 #if MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH < ( 2 * ( ( 256 + 7 ) / 8 ) + 1 )
321 #undef MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH
322 #define MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH ( 2 * ( ( 256 + 7 ) / 8 ) + 1 )
326 #if defined(MBEDTLS_ECP_DP_BP384R1_ENABLED)
327 #if MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH < ( 2 * ( ( 384 + 7 ) / 8 ) + 1 )
328 #undef MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH
329 #define MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH ( 2 * ( ( 384 + 7 ) / 8 ) + 1 )
333 #if defined(MBEDTLS_ECP_DP_BP512R1_ENABLED)
334 #if MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH < ( 2 * ( ( 512 + 7 ) / 8 ) + 1 )
335 #undef MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH
336 #define MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH ( 2 * ( ( 512 + 7 ) / 8 ) + 1 )
374 #if defined(MBEDTLS_ECP_C)
376 uint16_t tls_ecc_grp_reg_id,
size_t *bits )
380 if( curve_info == NULL )
418 if( srclen > dstlen )
421 memcpy( dst, src, srclen );
432 #if defined(MBEDTLS_PSA_CRYPTO_C)
440 typedef int mbedtls_f_rng_t(
void *p_rng,
unsigned char *output,
size_t output_size );
442 #if defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG)
480 unsigned char *output,
481 size_t output_size );
493 #define MBEDTLS_PSA_RANDOM_STATE NULL
497 #if defined(MBEDTLS_CTR_DRBG_C)
501 #elif defined(MBEDTLS_HMAC_DRBG_C)
506 extern mbedtls_psa_drbg_context_t *
const mbedtls_psa_random_state;
508 #define MBEDTLS_PSA_RANDOM_STATE mbedtls_psa_random_state
static psa_ecc_family_t mbedtls_ecc_group_to_psa(mbedtls_ecp_group_id grpid, size_t *bits)
The CTR_DRBG context structure.
#define MBEDTLS_OID_EC_GRP_SECP192K1
#define MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED
#define PSA_ERROR_COMMUNICATION_FAILURE
#define PSA_ALG_ECB_NO_PADDING
static psa_key_type_t mbedtls_psa_translate_cipher_type(mbedtls_cipher_type_t cipher)
This file provides an API for Elliptic Curves over GF(P) (ECP).
Platform Security Architecture cryptography module.
#define MBEDTLS_OID_EC_GRP_SECP192R1
int mbedtls_hmac_drbg_random(void *p_rng, unsigned char *output, size_t out_len)
This function uses HMAC_DRBG to generate random data.
int mbedtls_ctr_drbg_random(void *p_rng, unsigned char *output, size_t output_len)
This function uses CTR_DRBG to generate random data.
#define MBEDTLS_OID_EC_GRP_SECP384R1
int mbedtls_psa_get_random(void *p_rng, unsigned char *output, size_t output_size)
mbedtls_cipher_type_t
Supported {cipher type, cipher mode} pairs.
Object Identifier (OID) database.
Public Key abstraction layer.
#define MBEDTLS_OID_SIZE(x)
#define PSA_ERROR_INSUFFICIENT_MEMORY
Error to string translation.
#define MBEDTLS_OID_EC_GRP_SECP256R1
#define PSA_ALG_RIPEMD160
#define MBEDTLS_OID_EC_GRP_BP256R1
int mbedtls_f_rng_t(void *p_rng, unsigned char *output, size_t output_size)
static psa_key_usage_t mbedtls_psa_translate_cipher_operation(mbedtls_operation_t op)
#define MBEDTLS_OID_EC_GRP_SECP224K1
#define PSA_KEY_USAGE_DECRYPT
static int mbedtls_psa_get_ecc_oid_from_id(psa_ecc_family_t curve, size_t bits, char const **oid, size_t *oid_len)
#define PSA_ALG_AEAD_WITH_SHORTENED_TAG(aead_alg, tag_length)
#define PSA_ALG_CBC_NO_PADDING
#define PSA_ECC_FAMILY_BRAINPOOL_P_R1
static psa_algorithm_t mbedtls_psa_translate_md(mbedtls_md_type_t md_alg)
static int mbedtls_psa_err_translate_pk(psa_status_t status)
#define MBEDTLS_OID_EC_GRP_BP512R1
#define PSA_KEY_TYPE_ECC_KEY_PAIR(curve)
#define MBEDTLS_OID_EC_GRP_SECP521R1
uint32_t psa_algorithm_t
Encoding of a cryptographic algorithm.
#define MBEDTLS_ERR_PK_ALLOC_FAILED
#define PSA_ECC_FAMILY_SECP_R1
Macro wrapper for struct's memebrs.
#define MBEDTLS_ERR_PK_BAD_INPUT_DATA
#define PSA_ERROR_CORRUPTION_DETECTED
uint32_t psa_key_usage_t
Encoding of permitted usage on a key.
uint16_t psa_key_type_t
Encoding of a key type.
Build-time configuration info.
const mbedtls_ecp_curve_info * mbedtls_ecp_curve_info_from_tls_id(uint16_t tls_id)
This function retrieves curve information from a TLS NamedCurve value.
#define MBEDTLS_OID_EC_GRP_SECP224R1
static psa_algorithm_t mbedtls_psa_translate_cipher_mode(mbedtls_cipher_mode_t mode, size_t taglen)
#define PSA_ERROR_HARDWARE_FAILURE
mbedtls_ecp_group_id grp_id
This file contains the generic message-digest wrapper.
#define PSA_ERROR_NOT_SUPPORTED
static int mbedtls_psa_tls_psa_ec_to_ecpoint(unsigned char *src, size_t srclen, unsigned char **dst, size_t *dstlen)
#define PSA_ALG_CCM_STAR_NO_TAG
#define MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE
static int mbedtls_psa_tls_ecpoint_to_psa_ec(unsigned char const *src, size_t srclen, unsigned char *dst, size_t dstlen, size_t *olen)
#define MBEDTLS_OID_EC_GRP_BP384R1
#define PSA_ECC_FAMILY_SECP_K1
#define MBEDTLS_OID_EC_GRP_SECP256K1
#define PSA_ERROR_BAD_STATE
#define MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL
#define MBEDTLS_ERR_ECP_RANDOM_FAILED
mbedtls_md_type_t
Supported message digests.
int32_t psa_status_t
Function return status.
#define PSA_KEY_USAGE_ENCRYPT
static psa_key_type_t mbedtls_psa_parse_tls_ecc_group(uint16_t tls_ecc_grp_reg_id, size_t *bits)
#define PSA_ERROR_INSUFFICIENT_ENTROPY
This file contains definitions and functions for the CTR_DRBG pseudorandom generator.
The HMAC_DRBG pseudorandom generator.