26#ifndef MBEDTLS_PSA_UTIL_H
27#define MBEDTLS_PSA_UTIL_H
29#if !defined(MBEDTLS_CONFIG_FILE)
32#include MBEDTLS_CONFIG_FILE
35#if defined(MBEDTLS_USE_PSA_CRYPTO)
122#if defined(MBEDTLS_MD2_C)
126#if defined(MBEDTLS_MD4_C)
130#if defined(MBEDTLS_MD5_C)
134#if defined(MBEDTLS_SHA1_C)
138#if defined(MBEDTLS_SHA256_C)
144#if defined(MBEDTLS_SHA512_C)
150#if defined(MBEDTLS_RIPEMD160_C)
162static inline int mbedtls_psa_get_ecc_oid_from_id(
164 char const **oid,
size_t *oid_len )
171#if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED)
173 *oid = MBEDTLS_OID_EC_GRP_SECP192R1;
177#if defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED)
179 *oid = MBEDTLS_OID_EC_GRP_SECP224R1;
183#if defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED)
185 *oid = MBEDTLS_OID_EC_GRP_SECP256R1;
189#if defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED)
191 *oid = MBEDTLS_OID_EC_GRP_SECP384R1;
195#if defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED)
197 *oid = MBEDTLS_OID_EC_GRP_SECP521R1;
206#if defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED)
208 *oid = MBEDTLS_OID_EC_GRP_SECP192K1;
212#if defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED)
214 *oid = MBEDTLS_OID_EC_GRP_SECP224K1;
218#if defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED)
220 *oid = MBEDTLS_OID_EC_GRP_SECP256K1;
229#if defined(MBEDTLS_ECP_DP_BP256R1_ENABLED)
231 *oid = MBEDTLS_OID_EC_GRP_BP256R1;
235#if defined(MBEDTLS_ECP_DP_BP384R1_ENABLED)
237 *oid = MBEDTLS_OID_EC_GRP_BP384R1;
241#if defined(MBEDTLS_ECP_DP_BP512R1_ENABLED)
243 *oid = MBEDTLS_OID_EC_GRP_BP512R1;
255#define MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH 1
257#if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED)
258#if MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH < ( 2 * ( ( 192 + 7 ) / 8 ) + 1 )
259#undef MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH
260#define MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH ( 2 * ( ( 192 + 7 ) / 8 ) + 1 )
264#if defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED)
265#if MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH < ( 2 * ( ( 224 + 7 ) / 8 ) + 1 )
266#undef MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH
267#define MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH ( 2 * ( ( 224 + 7 ) / 8 ) + 1 )
271#if defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED)
272#if MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH < ( 2 * ( ( 256 + 7 ) / 8 ) + 1 )
273#undef MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH
274#define MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH ( 2 * ( ( 256 + 7 ) / 8 ) + 1 )
278#if defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED)
279#if MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH < ( 2 * ( ( 384 + 7 ) / 8 ) + 1 )
280#undef MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH
281#define MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH ( 2 * ( ( 384 + 7 ) / 8 ) + 1 )
285#if defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED)
286#if MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH < ( 2 * ( ( 521 + 7 ) / 8 ) + 1 )
287#undef MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH
288#define MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH ( 2 * ( ( 521 + 7 ) / 8 ) + 1 )
292#if defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED)
293#if MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH < ( 2 * ( ( 192 + 7 ) / 8 ) + 1 )
294#undef MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH
295#define MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH ( 2 * ( ( 192 + 7 ) / 8 ) + 1 )
299#if defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED)
300#if MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH < ( 2 * ( ( 224 + 7 ) / 8 ) + 1 )
301#undef MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH
302#define MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH ( 2 * ( ( 224 + 7 ) / 8 ) + 1 )
306#if defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED)
307#if MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH < ( 2 * ( ( 256 + 7 ) / 8 ) + 1 )
308#undef MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH
309#define MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH ( 2 * ( ( 256 + 7 ) / 8 ) + 1 )
313#if defined(MBEDTLS_ECP_DP_BP256R1_ENABLED)
314#if MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH < ( 2 * ( ( 256 + 7 ) / 8 ) + 1 )
315#undef MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH
316#define MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH ( 2 * ( ( 256 + 7 ) / 8 ) + 1 )
320#if defined(MBEDTLS_ECP_DP_BP384R1_ENABLED)
321#if MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH < ( 2 * ( ( 384 + 7 ) / 8 ) + 1 )
322#undef MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH
323#define MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH ( 2 * ( ( 384 + 7 ) / 8 ) + 1 )
327#if defined(MBEDTLS_ECP_DP_BP512R1_ENABLED)
328#if MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH < ( 2 * ( ( 512 + 7 ) / 8 ) + 1 )
329#undef MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH
330#define MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH ( 2 * ( ( 512 + 7 ) / 8 ) + 1 )
337static inline int mbedtls_psa_err_translate_pk(
psa_status_t status )
368#if defined(MBEDTLS_ECP_C)
370 uint16_t tls_ecc_grp_reg_id,
size_t *bits )
374 if( curve_info == NULL )
377 mbedtls_ecc_group_to_psa( curve_info->
grp_id, bits ) ) );
391static inline int mbedtls_psa_tls_psa_ec_to_ecpoint(
unsigned char *src,
406static inline int mbedtls_psa_tls_ecpoint_to_psa_ec(
unsigned char const *src,
412 if( srclen > dstlen )
415 memcpy( dst, src, srclen );
Configuration options (set of defines)
Platform Security Architecture cryptography module.
#define PSA_KEY_TYPE_ECC_KEY_PAIR(curve)
Elliptic curve key pair.
#define PSA_ALG_GCM
The GCM authenticated encryption algorithm.
#define PSA_ALG_SHA_224
SHA2-224.
#define PSA_ALG_SHA_1
SHA1.
#define PSA_ECC_FAMILY_SECP_R1
SEC random curves over prime fields.
#define PSA_ALG_SHA_384
SHA2-384.
#define PSA_ECC_FAMILY_SECP_K1
SEC Koblitz curves over prime fields.
#define PSA_ALG_AEAD_WITH_TAG_LENGTH(aead_alg, tag_length)
Macro to build a shortened AEAD algorithm.
#define PSA_ALG_SHA_256
SHA2-256.
uint16_t psa_key_type_t
Encoding of a key type.
#define PSA_ALG_RIPEMD160
PSA_ALG_RIPEMD160.
#define PSA_KEY_TYPE_AES
Key for a cipher, AEAD or MAC algorithm based on the AES block cipher.
#define PSA_ALG_ECB_NO_PADDING
The Electronic Code Book (ECB) mode of a block cipher, with no padding.
#define PSA_ECC_FAMILY_BRAINPOOL_P_R1
Brainpool P random curves.
#define PSA_ALG_CCM
The CCM authenticated encryption algorithm.
uint32_t psa_algorithm_t
Encoding of a cryptographic algorithm.
#define PSA_ALG_CBC_NO_PADDING
The CBC block cipher chaining mode, with no padding.
uint8_t psa_ecc_family_t
The type of PSA elliptic curve family identifiers.
#define PSA_ALG_SHA_512
SHA2-512.
int32_t psa_status_t
Function return status.
#define PSA_ERROR_HARDWARE_FAILURE
A hardware failure was detected.
#define PSA_ERROR_CORRUPTION_DETECTED
A tampering attempt was detected.
#define PSA_ERROR_NOT_SUPPORTED
The requested operation or a parameter is not supported by this implementation.
#define PSA_SUCCESS
The action was completed successfully.
#define PSA_ERROR_INSUFFICIENT_ENTROPY
There is not enough entropy to generate random data needed for the requested action.
#define PSA_ERROR_COMMUNICATION_FAILURE
There was a communication failure inside the implementation.
#define PSA_ERROR_INSUFFICIENT_MEMORY
There is not enough runtime memory.
#define PSA_ERROR_BAD_STATE
The requested action cannot be performed in the current state.
#define MBEDTLS_OID_SIZE(x)
Returns the size of the binary string, without the trailing \0.
mbedtls_cipher_type_t
Supported {cipher type, cipher mode} pairs.
mbedtls_operation_t
Type of operation.
mbedtls_cipher_mode_t
Supported cipher modes.
@ MBEDTLS_CIPHER_AES_128_CBC
AES cipher with 128-bit CBC mode.
@ MBEDTLS_CIPHER_AES_192_GCM
AES cipher with 192-bit GCM mode.
@ MBEDTLS_CIPHER_AES_192_CCM
AES cipher with 192-bit CCM mode.
@ MBEDTLS_CIPHER_AES_256_GCM
AES cipher with 256-bit GCM mode.
@ MBEDTLS_CIPHER_AES_256_CCM
AES cipher with 256-bit CCM mode.
@ MBEDTLS_CIPHER_AES_128_GCM
AES cipher with 128-bit GCM mode.
@ MBEDTLS_CIPHER_AES_192_CBC
AES cipher with 192-bit CBC mode.
@ MBEDTLS_CIPHER_AES_128_CCM
AES cipher with 128-bit CCM mode.
@ MBEDTLS_CIPHER_AES_256_CBC
AES cipher with 256-bit CBC mode.
@ MBEDTLS_DECRYPT
Operation type for decryption.
@ MBEDTLS_ENCRYPT
Operation type for encryption.
@ MBEDTLS_MODE_ECB
The ECB cipher mode.
@ MBEDTLS_MODE_CCM
The CCM cipher mode.
@ MBEDTLS_MODE_GCM
The GCM cipher mode.
@ MBEDTLS_MODE_CBC
The CBC cipher mode.
#define MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL
The buffer is too small to write to.
#define MBEDTLS_ERR_ECP_RANDOM_FAILED
Generation of random value, such as ephemeral key, failed.
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.
mbedtls_md_type_t
Supported message digests.
@ MBEDTLS_MD_SHA512
The SHA-512 message digest.
@ MBEDTLS_MD_MD5
The MD5 message digest.
@ MBEDTLS_MD_RIPEMD160
The RIPEMD-160 message digest.
@ MBEDTLS_MD_SHA384
The SHA-384 message digest.
@ MBEDTLS_MD_SHA256
The SHA-256 message digest.
@ MBEDTLS_MD_SHA224
The SHA-224 message digest.
@ MBEDTLS_MD_SHA1
The SHA-1 message digest.
@ MBEDTLS_MD_MD4
The MD4 message digest.
@ MBEDTLS_MD_MD2
The MD2 message digest.
#define PSA_KEY_USAGE_ENCRYPT
Whether the key may be used to encrypt a message.
uint32_t psa_key_usage_t
Encoding of permitted usage on a key.
#define PSA_KEY_USAGE_DECRYPT
Whether the key may be used to decrypt a message.
This file provides an API for Elliptic Curves over GF(P) (ECP).
This file contains the generic message-digest wrapper.
Object Identifier (OID) database.
Public Key abstraction layer.
#define MBEDTLS_ERR_PK_HW_ACCEL_FAILED
PK hardware accelerator failed.
#define MBEDTLS_ERR_PK_BAD_INPUT_DATA
Bad input parameters to function.
#define MBEDTLS_ERR_PK_ALLOC_FAILED
Memory allocation failed.
#define MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE
Unavailable feature, e.g.
Curve information, for use by other modules.
mbedtls_ecp_group_id grp_id