crypto_sizes.h
psa/build_info.h
crypto.h
crypto_driver_common.h
mbedtls/build_info.h
mbedtls/check_config.h
mbedtls/config_adjust_legacy_crypto.h
mbedtls/config_adjust_psa_from_legacy.h
mbedtls/config_adjust_psa_superset_legacy.h
mbedtls/config_adjust_ssl.h
mbedtls/config_adjust_x509.h
mbedtls/config_psa.h
mbedtls/mbedtls_config.h
psa/build_info.h
psa/crypto_adjust_auto_enabled.h
psa/crypto_adjust_config_dependencies.h
psa/crypto_adjust_config_key_pair_types.h
psa/crypto_adjust_config_synonyms.h
psa/crypto_legacy.h
crypto_sizes.h
limits.h
stdint.h
debug.h
net_sockets.h
oid.h
pk.h
pkcs7.h
psa_util.h
ssl.h
ssl_cache.h
ssl_ciphersuites.h
ssl_cookie.h
ssl_ticket.h
x509.h
x509_crl.h
x509_crt.h
x509_csr.h
crypto.h
crypto_builtin_composites.h
crypto_builtin_key_derivation.h
crypto_builtin_primitives.h
crypto_driver_common.h
crypto_driver_contexts_composites.h
crypto_driver_contexts_key_derivation.h
crypto_driver_contexts_primitives.h
crypto_se_driver.h
crypto_sizes.h
crypto_struct.h
PSA_BITS_TO_BYTES
bits
(((bits) + 7u) / 8u)
PSA_BYTES_TO_BITS
bytes
((bytes) * 8u)
PSA_MAX_OF_THREE
a
b
c
((a) <= (b) ? (b) <= (c) ? \ (c) : (b) : (a) <= (c) ? (c) : (a))
PSA_ROUND_UP_TO_MULTIPLE
block_size
length
(((length) + (block_size) - 1) / (block_size) * (block_size))
PSA_HASH_LENGTH
alg
( \ PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_MD5 ? 16u : \ PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_RIPEMD160 ? 20u : \ PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_1 ? 20u : \ PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_224 ? 28u : \ PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_256 ? 32u : \ PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_384 ? 48u : \ PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_512 ? 64u : \ PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_512_224 ? 28u : \ PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_512_256 ? 32u : \ PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA3_224 ? 28u : \ PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA3_256 ? 32u : \ PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA3_384 ? 48u : \ PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA3_512 ? 64u : \ 0u)

The size of the output of psa_hash_finish(), in bytes.

This is also the hash size that psa_hash_verify() expects.

alg

A hash algorithm (`PSA_ALG_XXX` value such that PSA_ALG_IS_HASH(`alg`) is true), or an HMAC algorithm (PSA_ALG_HMAC(`hash_alg`) where `hash_alg` is a hash algorithm).

The hash size for the specified hash algorithm. If the hash algorithm is not recognized, return 0.

PSA_HASH_BLOCK_LENGTH
alg
( \ PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_MD5 ? 64u : \ PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_RIPEMD160 ? 64u : \ PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_1 ? 64u : \ PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_224 ? 64u : \ PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_256 ? 64u : \ PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_384 ? 128u : \ PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_512 ? 128u : \ PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_512_224 ? 128u : \ PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_512_256 ? 128u : \ PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA3_224 ? 144u : \ PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA3_256 ? 136u : \ PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA3_384 ? 104u : \ PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA3_512 ? 72u : \ 0u)

The input block size of a hash algorithm, in bytes.

Hash algorithms process their input data in blocks. Hash operations will retain any partial blocks until they have enough input to fill the block or until the operation is finished. This affects the output from psa_hash_suspend().

alg

A hash algorithm (`PSA_ALG_XXX` value such that PSA_ALG_IS_HASH(`alg`) is true).

The block size in bytes for the specified hash algorithm. If the hash algorithm is not recognized, return 0. An implementation can return either 0 or the correct size for a hash algorithm that it recognizes, but does not support.

PSA_HMAC_MAX_HASH_BLOCK_SIZE
144u
PSA_HASH_MAX_SIZE
64u

Maximum size of a hash.

This macro expands to a compile-time constant integer. This value is the maximum size of a hash in bytes.

PSA_MAC_MAX_SIZE
PSA_HASH_MAX_SIZE

Maximum size of a MAC.

This macro expands to a compile-time constant integer. This value is the maximum size of a MAC in bytes.

PSA_AEAD_TAG_LENGTH
key_type
key_bits
alg
(PSA_AEAD_NONCE_LENGTH(key_type, alg) != 0 ? \ PSA_ALG_AEAD_GET_TAG_LENGTH(alg) : \ ((void) (key_bits), 0u))

The length of a tag for an AEAD algorithm, in bytes.

This macro can be used to allocate a buffer of sufficient size to store the tag output from psa_aead_finish().

See also PSA_AEAD_TAG_MAX_SIZE.

key_type

The type of the AEAD key.

key_bits

The size of the AEAD key in bits.

alg

An AEAD algorithm (`PSA_ALG_XXX` value such that PSA_ALG_IS_AEAD(`alg`) is true).

The tag length for the specified algorithm and key. If the AEAD algorithm does not have an identified tag that can be distinguished from the rest of the ciphertext, return 0. If the key type or AEAD algorithm is not recognized, or the parameters are incompatible, return 0.

PSA_AEAD_TAG_MAX_SIZE
16u

The maximum tag size for all supported AEAD algorithms, in bytes.

See also PSA_AEAD_TAG_LENGTH(`key_type`, `key_bits`, `alg`).

PSA_VENDOR_RSA_MAX_KEY_BITS
4096u
PSA_VENDOR_RSA_GENERATE_MIN_KEY_BITS
1024
PSA_VENDOR_FFDH_MAX_KEY_BITS
8192u
PSA_VENDOR_ECC_MAX_CURVE_BITS
521u
PSA_TLS12_PSK_TO_MS_PSK_MAX_SIZE
128u

This macro returns the maximum supported length of the PSK for the TLS-1.2 PSK-to-MS key derivation (PSA_ALG_TLS12_PSK_TO_MS(`hash_alg`)).

The maximum supported length does not depend on the chosen hash algorithm.

Quoting RFC 4279, Sect 5.3: TLS implementations supporting these ciphersuites MUST support arbitrary PSK identities up to 128 octets in length, and arbitrary PSKs up to 64 octets in length. Supporting longer identities and keys is RECOMMENDED.

Therefore, no implementation should define a value smaller than 64 for PSA_TLS12_PSK_TO_MS_PSK_MAX_SIZE.

PSA_TLS12_ECJPAKE_TO_PMS_INPUT_SIZE
65u
PSA_TLS12_ECJPAKE_TO_PMS_DATA_SIZE
32u
PSA_VENDOR_PBKDF2_MAX_ITERATIONS
0xffffffffU
PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE
16u

The maximum size of a block cipher.

PSA_MAC_LENGTH
key_type
key_bits
alg
((alg) & PSA_ALG_MAC_TRUNCATION_MASK ? PSA_MAC_TRUNCATED_LENGTH(alg) : \ PSA_ALG_IS_HMAC(alg) ? PSA_HASH_LENGTH(PSA_ALG_HMAC_GET_HASH(alg)) : \ PSA_ALG_IS_BLOCK_CIPHER_MAC(alg) ? PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type) : \ ((void) (key_type), (void) (key_bits), 0u))

The size of the output of psa_mac_sign_finish(), in bytes.

This is also the MAC size that psa_mac_verify_finish() expects.

This macro may evaluate its arguments multiple times or zero times, so you should not pass arguments that contain side effects.

key_type

The type of the MAC key.

key_bits

The size of the MAC key in bits.

alg

A MAC algorithm (`PSA_ALG_XXX` value such that PSA_ALG_IS_MAC(`alg`) is true).

The MAC size for the specified algorithm with the specified key parameters.

0 if the MAC algorithm is not recognized.

Either 0 or the correct size for a MAC algorithm that the implementation recognizes, but does not support.

Unspecified if the key parameters are not consistent with the algorithm.

PSA_AEAD_ENCRYPT_OUTPUT_SIZE
key_type
alg
plaintext_length
(PSA_AEAD_NONCE_LENGTH(key_type, alg) != 0 ? \ (plaintext_length) + PSA_ALG_AEAD_GET_TAG_LENGTH(alg) : \ 0u)

The maximum size of the output of psa_aead_encrypt(), in bytes.

If the size of the ciphertext buffer is at least this large, it is guaranteed that psa_aead_encrypt() will not fail due to an insufficient buffer size. Depending on the algorithm, the actual size of the ciphertext may be smaller.

See also PSA_AEAD_ENCRYPT_OUTPUT_MAX_SIZE(`plaintext_length`).

This macro may evaluate its arguments multiple times or zero times, so you should not pass arguments that contain side effects.

key_type

A symmetric key type that is compatible with algorithm `alg`.

alg

An AEAD algorithm (`PSA_ALG_XXX` value such that PSA_ALG_IS_AEAD(`alg`) is true).

plaintext_length

Size of the plaintext in bytes.

The AEAD ciphertext size for the specified algorithm. If the key type or AEAD algorithm is not recognized, or the parameters are incompatible, return 0.

PSA_AEAD_ENCRYPT_OUTPUT_MAX_SIZE
plaintext_length
((plaintext_length) + PSA_AEAD_TAG_MAX_SIZE)

A sufficient output buffer size for psa_aead_encrypt(), for any of the supported key types and AEAD algorithms.

If the size of the ciphertext buffer is at least this large, it is guaranteed that psa_aead_encrypt() will not fail due to an insufficient buffer size.

This macro returns a compile-time constant if its arguments are compile-time constants.

See also PSA_AEAD_ENCRYPT_OUTPUT_SIZE(`key_type`, `alg`, `plaintext_length`).

plaintext_length

Size of the plaintext in bytes.

A sufficient output buffer size for any of the supported key types and AEAD algorithms.

PSA_AEAD_DECRYPT_OUTPUT_SIZE
key_type
alg
ciphertext_length
(PSA_AEAD_NONCE_LENGTH(key_type, alg) != 0 && \ (ciphertext_length) > PSA_ALG_AEAD_GET_TAG_LENGTH(alg) ? \ (ciphertext_length) - PSA_ALG_AEAD_GET_TAG_LENGTH(alg) : \ 0u)

The maximum size of the output of psa_aead_decrypt(), in bytes.

If the size of the plaintext buffer is at least this large, it is guaranteed that psa_aead_decrypt() will not fail due to an insufficient buffer size. Depending on the algorithm, the actual size of the plaintext may be smaller.

See also PSA_AEAD_DECRYPT_OUTPUT_MAX_SIZE(`ciphertext_length`).

This macro may evaluate its arguments multiple times or zero times, so you should not pass arguments that contain side effects.

key_type

A symmetric key type that is compatible with algorithm `alg`.

alg

An AEAD algorithm (`PSA_ALG_XXX` value such that PSA_ALG_IS_AEAD(`alg`) is true).

ciphertext_length

Size of the plaintext in bytes.

The AEAD ciphertext size for the specified algorithm. If the key type or AEAD algorithm is not recognized, or the parameters are incompatible, return 0.

PSA_AEAD_DECRYPT_OUTPUT_MAX_SIZE
ciphertext_length
(ciphertext_length)

A sufficient output buffer size for psa_aead_decrypt(), for any of the supported key types and AEAD algorithms.

If the size of the plaintext buffer is at least this large, it is guaranteed that psa_aead_decrypt() will not fail due to an insufficient buffer size.

This macro returns a compile-time constant if its arguments are compile-time constants.

See also PSA_AEAD_DECRYPT_OUTPUT_SIZE(`key_type`, `alg`, `ciphertext_length`).

ciphertext_length

Size of the ciphertext in bytes.

A sufficient output buffer size for any of the supported key types and AEAD algorithms.

PSA_AEAD_NONCE_LENGTH
key_type
alg
(PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type) == 16 ? \ MBEDTLS_PSA_ALG_AEAD_EQUAL(alg, PSA_ALG_CCM) ? 13u : \ MBEDTLS_PSA_ALG_AEAD_EQUAL(alg, PSA_ALG_GCM) ? 12u : \ 0u : \ (key_type) == PSA_KEY_TYPE_CHACHA20 && \ MBEDTLS_PSA_ALG_AEAD_EQUAL(alg, PSA_ALG_CHACHA20_POLY1305) ? 12u : \ 0u)

The default nonce size for an AEAD algorithm, in bytes.

This macro can be used to allocate a buffer of sufficient size to store the nonce output from psa_aead_generate_nonce().

See also PSA_AEAD_NONCE_MAX_SIZE.

This is not the maximum size of nonce supported as input to psa_aead_set_nonce(), psa_aead_encrypt() or psa_aead_decrypt(), just the default size that is generated by psa_aead_generate_nonce().

This macro may evaluate its arguments multiple times or zero times, so you should not pass arguments that contain side effects.

key_type

A symmetric key type that is compatible with algorithm `alg`.

alg

An AEAD algorithm (`PSA_ALG_XXX` value such that PSA_ALG_IS_AEAD(`alg`) is true).

The default nonce size for the specified key type and algorithm. If the key type or AEAD algorithm is not recognized, or the parameters are incompatible, return 0.

PSA_AEAD_NONCE_MAX_SIZE
13u

The maximum default nonce size among all supported pairs of key types and AEAD algorithms, in bytes.

This is equal to or greater than any value that PSA_AEAD_NONCE_LENGTH() may return.

This is not the maximum size of nonce supported as input to psa_aead_set_nonce(), psa_aead_encrypt() or psa_aead_decrypt(), just the largest size that may be generated by psa_aead_generate_nonce().

PSA_AEAD_UPDATE_OUTPUT_SIZE
key_type
alg
input_length
(PSA_AEAD_NONCE_LENGTH(key_type, alg) != 0 ? \ PSA_ALG_IS_AEAD_ON_BLOCK_CIPHER(alg) ? \ PSA_ROUND_UP_TO_MULTIPLE(PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type), (input_length)) : \ (input_length) : \ 0u)

A sufficient output buffer size for psa_aead_update().

If the size of the output buffer is at least this large, it is guaranteed that psa_aead_update() will not fail due to an insufficient buffer size. The actual size of the output may be smaller in any given call.

See also PSA_AEAD_UPDATE_OUTPUT_MAX_SIZE(`input_length`).

This macro may evaluate its arguments multiple times or zero times, so you should not pass arguments that contain side effects.

key_type

A symmetric key type that is compatible with algorithm `alg`.

alg

An AEAD algorithm (`PSA_ALG_XXX` value such that PSA_ALG_IS_AEAD(`alg`) is true).

input_length

Size of the input in bytes.

A sufficient output buffer size for the specified algorithm. If the key type or AEAD algorithm is not recognized, or the parameters are incompatible, return 0.

PSA_AEAD_UPDATE_OUTPUT_MAX_SIZE
input_length
(PSA_ROUND_UP_TO_MULTIPLE(PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE, (input_length)))

A sufficient output buffer size for psa_aead_update(), for any of the supported key types and AEAD algorithms.

If the size of the output buffer is at least this large, it is guaranteed that psa_aead_update() will not fail due to an insufficient buffer size.

See also PSA_AEAD_UPDATE_OUTPUT_SIZE(`key_type`, `alg`, `input_length`).

input_length

Size of the input in bytes.

PSA_AEAD_FINISH_OUTPUT_SIZE
key_type
alg
(PSA_AEAD_NONCE_LENGTH(key_type, alg) != 0 && \ PSA_ALG_IS_AEAD_ON_BLOCK_CIPHER(alg) ? \ PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type) : \ 0u)

A sufficient ciphertext buffer size for psa_aead_finish().

If the size of the ciphertext buffer is at least this large, it is guaranteed that psa_aead_finish() will not fail due to an insufficient ciphertext buffer size. The actual size of the output may be smaller in any given call.

See also PSA_AEAD_FINISH_OUTPUT_MAX_SIZE.

key_type

A symmetric key type that is compatible with algorithm `alg`.

alg

An AEAD algorithm (`PSA_ALG_XXX` value such that PSA_ALG_IS_AEAD(`alg`) is true).

A sufficient ciphertext buffer size for the specified algorithm. If the key type or AEAD algorithm is not recognized, or the parameters are incompatible, return 0.

PSA_AEAD_FINISH_OUTPUT_MAX_SIZE
(PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE)

A sufficient ciphertext buffer size for psa_aead_finish(), for any of the supported key types and AEAD algorithms.

See also PSA_AEAD_FINISH_OUTPUT_SIZE(`key_type`, `alg`).

PSA_AEAD_VERIFY_OUTPUT_SIZE
key_type
alg
(PSA_AEAD_NONCE_LENGTH(key_type, alg) != 0 && \ PSA_ALG_IS_AEAD_ON_BLOCK_CIPHER(alg) ? \ PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type) : \ 0u)

A sufficient plaintext buffer size for psa_aead_verify().

If the size of the plaintext buffer is at least this large, it is guaranteed that psa_aead_verify() will not fail due to an insufficient plaintext buffer size. The actual size of the output may be smaller in any given call.

See also PSA_AEAD_VERIFY_OUTPUT_MAX_SIZE.

key_type

A symmetric key type that is compatible with algorithm `alg`.

alg

An AEAD algorithm (`PSA_ALG_XXX` value such that PSA_ALG_IS_AEAD(`alg`) is true).

A sufficient plaintext buffer size for the specified algorithm. If the key type or AEAD algorithm is not recognized, or the parameters are incompatible, return 0.

PSA_AEAD_VERIFY_OUTPUT_MAX_SIZE
(PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE)

A sufficient plaintext buffer size for psa_aead_verify(), for any of the supported key types and AEAD algorithms.

See also PSA_AEAD_VERIFY_OUTPUT_SIZE(`key_type`, `alg`).

PSA_RSA_MINIMUM_PADDING_SIZE
alg
(PSA_ALG_IS_RSA_OAEP(alg) ? \ 2u * PSA_HASH_LENGTH(PSA_ALG_RSA_OAEP_GET_HASH(alg)) + 1u : \ 11u /*PKCS#1v1.5*/)
PSA_ECDSA_SIGNATURE_SIZE
curve_bits
(PSA_BITS_TO_BYTES(curve_bits) * 2u)

ECDSA signature size for a given curve bit size.

curve_bits

Curve size in bits.

Signature size in bytes.

This macro returns a compile-time constant if its argument is one.

PSA_SIGN_OUTPUT_SIZE
key_type
key_bits
alg
(PSA_KEY_TYPE_IS_RSA(key_type) ? ((void) alg, PSA_BITS_TO_BYTES(key_bits)) : \ PSA_KEY_TYPE_IS_ECC(key_type) ? PSA_ECDSA_SIGNATURE_SIZE(key_bits) : \ ((void) alg, 0u))

Sufficient signature buffer size for psa_sign_hash().

This macro returns a sufficient buffer size for a signature using a key of the specified type and size, with the specified algorithm. Note that the actual size of the signature may be smaller (some algorithms produce a variable-size signature).

This function may call its arguments multiple times or zero times, so you should not pass arguments that contain side effects.

key_type

An asymmetric key type (this may indifferently be a key pair type or a public key type).

key_bits

The size of the key in bits.

alg

The signature algorithm.

If the parameters are valid and supported, return a buffer size in bytes that guarantees that psa_sign_hash() will not fail with PSA_ERROR_BUFFER_TOO_SMALL. If the parameters are a valid combination that is not supported, return either a sensible size or 0. If the parameters are not valid, the return value is unspecified.

PSA_VENDOR_ECDSA_SIGNATURE_MAX_SIZE
PSA_ECDSA_SIGNATURE_SIZE
(PSA_VENDOR_ECC_MAX_CURVE_BITS)
PSA_SIGNATURE_MAX_SIZE
1

Maximum size of an asymmetric signature.

This macro expands to a compile-time constant integer. This value is the maximum size of a signature in bytes.

PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE
key_type
key_bits
alg
(PSA_KEY_TYPE_IS_RSA(key_type) ? \ ((void) alg, PSA_BITS_TO_BYTES(key_bits)) : \ 0u)

Sufficient output buffer size for psa_asymmetric_encrypt().

This macro returns a sufficient buffer size for a ciphertext produced using a key of the specified type and size, with the specified algorithm. Note that the actual size of the ciphertext may be smaller, depending on the algorithm.

This function may call its arguments multiple times or zero times, so you should not pass arguments that contain side effects.

key_type

An asymmetric key type (this may indifferently be a key pair type or a public key type).

key_bits

The size of the key in bits.

alg

The asymmetric encryption algorithm.

If the parameters are valid and supported, return a buffer size in bytes that guarantees that psa_asymmetric_encrypt() will not fail with PSA_ERROR_BUFFER_TOO_SMALL. If the parameters are a valid combination that is not supported, return either a sensible size or 0. If the parameters are not valid, the return value is unspecified.

PSA_ASYMMETRIC_ENCRYPT_OUTPUT_MAX_SIZE
(PSA_BITS_TO_BYTES(PSA_VENDOR_RSA_MAX_KEY_BITS))

A sufficient output buffer size for psa_asymmetric_encrypt(), for any supported asymmetric encryption.

See also PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE(`key_type`, `key_bits`, `alg`).

PSA_ASYMMETRIC_DECRYPT_OUTPUT_SIZE
key_type
key_bits
alg
(PSA_KEY_TYPE_IS_RSA(key_type) ? \ PSA_BITS_TO_BYTES(key_bits) - PSA_RSA_MINIMUM_PADDING_SIZE(alg) : \ 0u)

Sufficient output buffer size for psa_asymmetric_decrypt().

This macro returns a sufficient buffer size for a plaintext produced using a key of the specified type and size, with the specified algorithm. Note that the actual size of the plaintext may be smaller, depending on the algorithm.

This function may call its arguments multiple times or zero times, so you should not pass arguments that contain side effects.

key_type

An asymmetric key type (this may indifferently be a key pair type or a public key type).

key_bits

The size of the key in bits.

alg

The asymmetric encryption algorithm.

If the parameters are valid and supported, return a buffer size in bytes that guarantees that psa_asymmetric_decrypt() will not fail with PSA_ERROR_BUFFER_TOO_SMALL. If the parameters are a valid combination that is not supported, return either a sensible size or 0. If the parameters are not valid, the return value is unspecified.

PSA_ASYMMETRIC_DECRYPT_OUTPUT_MAX_SIZE
(PSA_BITS_TO_BYTES(PSA_VENDOR_RSA_MAX_KEY_BITS))

A sufficient output buffer size for psa_asymmetric_decrypt(), for any supported asymmetric decryption.

This macro assumes that RSA is the only supported asymmetric encryption.

See also PSA_ASYMMETRIC_DECRYPT_OUTPUT_SIZE(`key_type`, `key_bits`, `alg`).

PSA_KEY_EXPORT_ASN1_INTEGER_MAX_SIZE
bits
((bits) / 8u + 5u)
PSA_KEY_EXPORT_RSA_PUBLIC_KEY_MAX_SIZE
key_bits
(PSA_KEY_EXPORT_ASN1_INTEGER_MAX_SIZE(key_bits) + 11u)
PSA_KEY_EXPORT_RSA_KEY_PAIR_MAX_SIZE
key_bits
(9u * PSA_KEY_EXPORT_ASN1_INTEGER_MAX_SIZE((key_bits) / 2u + 1u) + 14u)
PSA_KEY_EXPORT_DSA_PUBLIC_KEY_MAX_SIZE
key_bits
(PSA_KEY_EXPORT_ASN1_INTEGER_MAX_SIZE(key_bits) * 3u + 59u)
PSA_KEY_EXPORT_DSA_KEY_PAIR_MAX_SIZE
key_bits
(PSA_KEY_EXPORT_ASN1_INTEGER_MAX_SIZE(key_bits) * 3u + 75u)
PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE
key_bits
(2u * PSA_BITS_TO_BYTES(key_bits) + 1u)
PSA_KEY_EXPORT_ECC_KEY_PAIR_MAX_SIZE
key_bits
(PSA_BITS_TO_BYTES(key_bits))
PSA_KEY_EXPORT_FFDH_KEY_PAIR_MAX_SIZE
key_bits
(PSA_BITS_TO_BYTES(key_bits))
PSA_KEY_EXPORT_FFDH_PUBLIC_KEY_MAX_SIZE
key_bits
(PSA_BITS_TO_BYTES(key_bits))
PSA_EXPORT_KEY_OUTPUT_SIZE
key_type
key_bits
(PSA_KEY_TYPE_IS_UNSTRUCTURED(key_type) ? PSA_BITS_TO_BYTES(key_bits) : \ PSA_KEY_TYPE_IS_DH(key_type) ? PSA_BITS_TO_BYTES(key_bits) : \ (key_type) == PSA_KEY_TYPE_RSA_KEY_PAIR ? PSA_KEY_EXPORT_RSA_KEY_PAIR_MAX_SIZE(key_bits) : \ (key_type) == PSA_KEY_TYPE_RSA_PUBLIC_KEY ? PSA_KEY_EXPORT_RSA_PUBLIC_KEY_MAX_SIZE(key_bits) : \ (key_type) == PSA_KEY_TYPE_DSA_KEY_PAIR ? PSA_KEY_EXPORT_DSA_KEY_PAIR_MAX_SIZE(key_bits) : \ (key_type) == PSA_KEY_TYPE_DSA_PUBLIC_KEY ? PSA_KEY_EXPORT_DSA_PUBLIC_KEY_MAX_SIZE(key_bits) : \ PSA_KEY_TYPE_IS_ECC_KEY_PAIR(key_type) ? PSA_KEY_EXPORT_ECC_KEY_PAIR_MAX_SIZE(key_bits) : \ PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY(key_type) ? PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(key_bits) : \ 0u)

Sufficient output buffer size for psa_export_key() or psa_export_public_key().

This macro returns a compile-time constant if its arguments are compile-time constants.

This macro may evaluate its arguments multiple times or zero times, so you should not pass arguments that contain side effects.

The following code illustrates how to allocate enough memory to export a key by querying the key type and size at runtime.

    psa_key_attributes_tattributes=PSA_KEY_ATTRIBUTES_INIT;
    psa_status_tstatus;
    status=psa_get_key_attributes(key,&attributes);
    if(status!=PSA_SUCCESS)handle_error(...);
    psa_key_type_tkey_type=psa_get_key_type(&attributes);
    size_tkey_bits=psa_get_key_bits(&attributes);
    size_tbuffer_size=PSA_EXPORT_KEY_OUTPUT_SIZE(key_type,key_bits);
    psa_reset_key_attributes(&attributes);
    uint8_t*buffer=malloc(buffer_size);
    if(buffer==NULL)handle_error(...);
    size_tbuffer_length;
    status=psa_export_key(key,buffer,buffer_size,&buffer_length);
    if(status!=PSA_SUCCESS)handle_error(...);

key_type

A supported key type.

key_bits

The size of the key in bits.

If the parameters are valid and supported, return a buffer size in bytes that guarantees that psa_export_key() or psa_export_public_key() will not fail with PSA_ERROR_BUFFER_TOO_SMALL. If the parameters are a valid combination that is not supported, return either a sensible size or 0. If the parameters are not valid, the return value is unspecified.

PSA_EXPORT_PUBLIC_KEY_OUTPUT_SIZE
key_type
key_bits
(PSA_KEY_TYPE_IS_RSA(key_type) ? PSA_KEY_EXPORT_RSA_PUBLIC_KEY_MAX_SIZE(key_bits) : \ PSA_KEY_TYPE_IS_ECC(key_type) ? PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(key_bits) : \ PSA_KEY_TYPE_IS_DH(key_type) ? PSA_BITS_TO_BYTES(key_bits) : \ 0u)

Sufficient output buffer size for psa_export_public_key().

This macro returns a compile-time constant if its arguments are compile-time constants.

This macro may evaluate its arguments multiple times or zero times, so you should not pass arguments that contain side effects.

The following code illustrates how to allocate enough memory to export a public key by querying the key type and size at runtime.

    psa_key_attributes_tattributes=PSA_KEY_ATTRIBUTES_INIT;
    psa_status_tstatus;
    status=psa_get_key_attributes(key,&attributes);
    if(status!=PSA_SUCCESS)handle_error(...);
    psa_key_type_tkey_type=psa_get_key_type(&attributes);
    size_tkey_bits=psa_get_key_bits(&attributes);
    size_tbuffer_size=PSA_EXPORT_PUBLIC_KEY_OUTPUT_SIZE(key_type,key_bits);
    psa_reset_key_attributes(&attributes);
    uint8_t*buffer=malloc(buffer_size);
    if(buffer==NULL)handle_error(...);
    size_tbuffer_length;
    status=psa_export_public_key(key,buffer,buffer_size,&buffer_length);
    if(status!=PSA_SUCCESS)handle_error(...);

key_type

A public key or key pair key type.

key_bits

The size of the key in bits.

If the parameters are valid and supported, return a buffer size in bytes that guarantees that psa_export_public_key() will not fail with PSA_ERROR_BUFFER_TOO_SMALL. If the parameters are a valid combination that is not supported, return either a sensible size or 0. If the parameters are not valid, the return value is unspecified.

If the parameters are valid and supported, return the same result as PSA_EXPORT_KEY_OUTPUT_SIZE( `PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR`(`key_type`), `key_bits`).
PSA_EXPORT_KEY_PAIR_MAX_SIZE
1

Sufficient buffer size for exporting any asymmetric key pair.

This macro expands to a compile-time constant integer. This value is a sufficient buffer size when calling psa_export_key() to export any asymmetric key pair, regardless of the exact key type and key size.

See also PSA_EXPORT_KEY_OUTPUT_SIZE(`key_type`, `key_bits`).

PSA_EXPORT_PUBLIC_KEY_MAX_SIZE
1

Sufficient buffer size for exporting any asymmetric public key.

This macro expands to a compile-time constant integer. This value is a sufficient buffer size when calling psa_export_key() or psa_export_public_key() to export any asymmetric public key, regardless of the exact key type and key size.

See also PSA_EXPORT_PUBLIC_KEY_OUTPUT_SIZE(`key_type`, `key_bits`).

PSA_EXPORT_KEY_PAIR_OR_PUBLIC_MAX_SIZE
((PSA_EXPORT_KEY_PAIR_MAX_SIZE > PSA_EXPORT_PUBLIC_KEY_MAX_SIZE) ? \ PSA_EXPORT_KEY_PAIR_MAX_SIZE : PSA_EXPORT_PUBLIC_KEY_MAX_SIZE)
PSA_RAW_KEY_AGREEMENT_OUTPUT_SIZE
key_type
key_bits
((PSA_KEY_TYPE_IS_ECC_KEY_PAIR(key_type) || \ PSA_KEY_TYPE_IS_DH_KEY_PAIR(key_type)) ? PSA_BITS_TO_BYTES(key_bits) : 0u)

Sufficient output buffer size for psa_raw_key_agreement().

This macro returns a compile-time constant if its arguments are compile-time constants.

This macro may evaluate its arguments multiple times or zero times, so you should not pass arguments that contain side effects.

See also PSA_RAW_KEY_AGREEMENT_OUTPUT_MAX_SIZE.

key_type

A supported key type.

key_bits

The size of the key in bits.

If the parameters are valid and supported, return a buffer size in bytes that guarantees that psa_raw_key_agreement() will not fail with PSA_ERROR_BUFFER_TOO_SMALL. If the parameters are a valid combination that is not supported, return either a sensible size or 0. If the parameters are not valid, the return value is unspecified.

PSA_RAW_KEY_AGREEMENT_OUTPUT_MAX_SIZE
1

Maximum size of the output from psa_raw_key_agreement().

This macro expands to a compile-time constant integer. This value is the maximum size of the output any raw key agreement algorithm, in bytes.

See also PSA_RAW_KEY_AGREEMENT_OUTPUT_SIZE(`key_type`, `key_bits`).

PSA_CIPHER_MAX_KEY_LENGTH
32u

Maximum key length for ciphers.

Since there is no additional PSA_WANT_xxx symbol to specifiy the size of the key once a cipher is enabled (as it happens for asymmetric keys for example), the maximum key length is taken into account for each cipher. The resulting value will be the maximum cipher's key length given depending on which ciphers are enabled.

Note: max value for AES used below would be doubled if XTS were enabled, but this mode is currently not supported in Mbed TLS implementation of PSA APIs.

PSA_CIPHER_IV_LENGTH
key_type
alg
(PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type) > 1 && \ ((alg) == PSA_ALG_CTR || \ (alg) == PSA_ALG_CFB || \ (alg) == PSA_ALG_OFB || \ (alg) == PSA_ALG_XTS || \ (alg) == PSA_ALG_CBC_NO_PADDING || \ (alg) == PSA_ALG_CBC_PKCS7) ? PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type) : \ (key_type) == PSA_KEY_TYPE_CHACHA20 && \ (alg) == PSA_ALG_STREAM_CIPHER ? 12u : \ (alg) == PSA_ALG_CCM_STAR_NO_TAG ? 13u : \ 0u)

The default IV size for a cipher algorithm, in bytes.

The IV that is generated as part of a call to psa_cipher_encrypt() is always the default IV length for the algorithm.

This macro can be used to allocate a buffer of sufficient size to store the IV output from psa_cipher_generate_iv() when using a multi-part cipher operation.

See also PSA_CIPHER_IV_MAX_SIZE.

This macro may evaluate its arguments multiple times or zero times, so you should not pass arguments that contain side effects.

key_type

A symmetric key type that is compatible with algorithm `alg`.

alg

A cipher algorithm (`PSA_ALG_XXX` value such that PSA_ALG_IS_CIPHER(`alg`) is true).

The default IV size for the specified key type and algorithm. If the algorithm does not use an IV, return 0. If the key type or cipher algorithm is not recognized, or the parameters are incompatible, return 0.

PSA_CIPHER_IV_MAX_SIZE
16u

The maximum IV size for all supported cipher algorithms, in bytes.

See also PSA_CIPHER_IV_LENGTH().

PSA_CIPHER_ENCRYPT_OUTPUT_SIZE
key_type
alg
input_length
(alg == PSA_ALG_CBC_PKCS7 ? \ (PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type) != 0 ? \ PSA_ROUND_UP_TO_MULTIPLE(PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type), \ (input_length) + 1u) + \ PSA_CIPHER_IV_LENGTH((key_type), (alg)) : 0u) : \ (PSA_ALG_IS_CIPHER(alg) ? \ (input_length) + PSA_CIPHER_IV_LENGTH((key_type), (alg)) : \ 0u))

The maximum size of the output of psa_cipher_encrypt(), in bytes.

If the size of the output buffer is at least this large, it is guaranteed that psa_cipher_encrypt() will not fail due to an insufficient buffer size. Depending on the algorithm, the actual size of the output might be smaller.

See also PSA_CIPHER_ENCRYPT_OUTPUT_MAX_SIZE(`input_length`).

This macro may evaluate its arguments multiple times or zero times, so you should not pass arguments that contain side effects.

key_type

A symmetric key type that is compatible with algorithm alg.

alg

A cipher algorithm (`PSA_ALG_XXX` value such that PSA_ALG_IS_CIPHER(`alg`) is true).

input_length

Size of the input in bytes.

A sufficient output size for the specified key type and algorithm. If the key type or cipher algorithm is not recognized, or the parameters are incompatible, return 0.

PSA_CIPHER_ENCRYPT_OUTPUT_MAX_SIZE
input_length
(PSA_ROUND_UP_TO_MULTIPLE(PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE, \ (input_length) + 1u) + \ PSA_CIPHER_IV_MAX_SIZE)

A sufficient output buffer size for psa_cipher_encrypt(), for any of the supported key types and cipher algorithms.

If the size of the output buffer is at least this large, it is guaranteed that psa_cipher_encrypt() will not fail due to an insufficient buffer size.

See also PSA_CIPHER_ENCRYPT_OUTPUT_SIZE(`key_type`, `alg`, `input_length`).

input_length

Size of the input in bytes.

PSA_CIPHER_DECRYPT_OUTPUT_SIZE
key_type
alg
input_length
(PSA_ALG_IS_CIPHER(alg) && \ ((key_type) & PSA_KEY_TYPE_CATEGORY_MASK) == PSA_KEY_TYPE_CATEGORY_SYMMETRIC ? \ (input_length) : \ 0u)

The maximum size of the output of psa_cipher_decrypt(), in bytes.

If the size of the output buffer is at least this large, it is guaranteed that psa_cipher_decrypt() will not fail due to an insufficient buffer size. Depending on the algorithm, the actual size of the output might be smaller.

See also PSA_CIPHER_DECRYPT_OUTPUT_MAX_SIZE(`input_length`).

key_type

A symmetric key type that is compatible with algorithm alg.

alg

A cipher algorithm (`PSA_ALG_XXX` value such that PSA_ALG_IS_CIPHER(`alg`) is true).

input_length

Size of the input in bytes.

A sufficient output size for the specified key type and algorithm. If the key type or cipher algorithm is not recognized, or the parameters are incompatible, return 0.

PSA_CIPHER_DECRYPT_OUTPUT_MAX_SIZE
input_length
(input_length)

A sufficient output buffer size for psa_cipher_decrypt(), for any of the supported key types and cipher algorithms.

If the size of the output buffer is at least this large, it is guaranteed that psa_cipher_decrypt() will not fail due to an insufficient buffer size.

See also PSA_CIPHER_DECRYPT_OUTPUT_SIZE(`key_type`, `alg`, `input_length`).

input_length

Size of the input in bytes.

PSA_CIPHER_UPDATE_OUTPUT_SIZE
key_type
alg
input_length
(PSA_ALG_IS_CIPHER(alg) ? \ (PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type) != 0 ? \ (((alg) == PSA_ALG_CBC_PKCS7 || \ (alg) == PSA_ALG_CBC_NO_PADDING || \ (alg) == PSA_ALG_ECB_NO_PADDING) ? \ PSA_ROUND_UP_TO_MULTIPLE(PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type), \ input_length) : \ (input_length)) : 0u) : \ 0u)

A sufficient output buffer size for psa_cipher_update().

If the size of the output buffer is at least this large, it is guaranteed that psa_cipher_update() will not fail due to an insufficient buffer size. The actual size of the output might be smaller in any given call.

See also PSA_CIPHER_UPDATE_OUTPUT_MAX_SIZE(`input_length`).

key_type

A symmetric key type that is compatible with algorithm alg.

alg

A cipher algorithm (PSA_ALG_XXX value such that PSA_ALG_IS_CIPHER(`alg`) is true).

input_length

Size of the input in bytes.

A sufficient output size for the specified key type and algorithm. If the key type or cipher algorithm is not recognized, or the parameters are incompatible, return 0.

PSA_CIPHER_UPDATE_OUTPUT_MAX_SIZE
input_length
(PSA_ROUND_UP_TO_MULTIPLE(PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE, input_length))

A sufficient output buffer size for psa_cipher_update(), for any of the supported key types and cipher algorithms.

If the size of the output buffer is at least this large, it is guaranteed that psa_cipher_update() will not fail due to an insufficient buffer size.

See also PSA_CIPHER_UPDATE_OUTPUT_SIZE(`key_type`, `alg`, `input_length`).

input_length

Size of the input in bytes.

PSA_CIPHER_FINISH_OUTPUT_SIZE
key_type
alg
(PSA_ALG_IS_CIPHER(alg) ? \ (alg == PSA_ALG_CBC_PKCS7 ? \ PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type) : \ 0u) : \ 0u)

A sufficient ciphertext buffer size for psa_cipher_finish().

If the size of the ciphertext buffer is at least this large, it is guaranteed that psa_cipher_finish() will not fail due to an insufficient ciphertext buffer size. The actual size of the output might be smaller in any given call.

See also PSA_CIPHER_FINISH_OUTPUT_MAX_SIZE().

key_type

A symmetric key type that is compatible with algorithm alg.

alg

A cipher algorithm (PSA_ALG_XXX value such that PSA_ALG_IS_CIPHER(`alg`) is true).

A sufficient output size for the specified key type and algorithm. If the key type or cipher algorithm is not recognized, or the parameters are incompatible, return 0.

PSA_CIPHER_FINISH_OUTPUT_MAX_SIZE
(PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE)

A sufficient ciphertext buffer size for psa_cipher_finish(), for any of the supported key types and cipher algorithms.

See also PSA_CIPHER_FINISH_OUTPUT_SIZE(`key_type`, `alg`).

PSA cryptography module: Mbed TLS buffer size macros.

This file may not be included directly. Applications must include psa/crypto.h.

This file contains the definitions of macros that are useful to compute buffer sizes. The signatures and semantics of these macros are standardized, but the definitions are not, because they depend on the available algorithms and, in some cases, on permitted tolerances on buffer sizes.

In implementations with isolation between the application and the cryptography module, implementers should take care to ensure that the definitions that are exposed to applications match what the module implements.

Macros that compute sizes whose values do not depend on the implementation are in crypto.h.

    /*
    *CopyrightTheMbedTLSContributors
    *SPDX-License-Identifier:Apache-2.0ORGPL-2.0-or-later
    */

    #ifndefPSA_CRYPTO_SIZES_H
    #definePSA_CRYPTO_SIZES_H

    /*
    *Includethebuild-timeconfigurationinformationheader.Here,wedonot
    *include`"mbedtls/build_info.h"`directlybut`"psa/build_info.h"`,which
    *isbasicallyjustanaliastoit.Thisistoeasethemaintenanceofthe
    *TF-PSA-Cryptorepositorywhichhasadifferentbuildsystemand
    *configuration.
    */
    #include"psa/build_info.h"

    #definePSA_BITS_TO_BYTES(bits)(((bits)+7u)/8u)
    #definePSA_BYTES_TO_BITS(bytes)((bytes)*8u)
    #definePSA_MAX_OF_THREE(a,b,c)((a)<=(b)?(b)<=(c)?\
    (c):(b):(a)<=(c)?(c):(a))

    #definePSA_ROUND_UP_TO_MULTIPLE(block_size,length)\
    (((length)+(block_size)-1)/(block_size)*(block_size))

    #definePSA_HASH_LENGTH(alg)\
    (\
    PSA_ALG_HMAC_GET_HASH(alg)==PSA_ALG_MD5?16u:\
    PSA_ALG_HMAC_GET_HASH(alg)==PSA_ALG_RIPEMD160?20u:\
    PSA_ALG_HMAC_GET_HASH(alg)==PSA_ALG_SHA_1?20u:\
    PSA_ALG_HMAC_GET_HASH(alg)==PSA_ALG_SHA_224?28u:\
    PSA_ALG_HMAC_GET_HASH(alg)==PSA_ALG_SHA_256?32u:\
    PSA_ALG_HMAC_GET_HASH(alg)==PSA_ALG_SHA_384?48u:\
    PSA_ALG_HMAC_GET_HASH(alg)==PSA_ALG_SHA_512?64u:\
    PSA_ALG_HMAC_GET_HASH(alg)==PSA_ALG_SHA_512_224?28u:\
    PSA_ALG_HMAC_GET_HASH(alg)==PSA_ALG_SHA_512_256?32u:\
    PSA_ALG_HMAC_GET_HASH(alg)==PSA_ALG_SHA3_224?28u:\
    PSA_ALG_HMAC_GET_HASH(alg)==PSA_ALG_SHA3_256?32u:\
    PSA_ALG_HMAC_GET_HASH(alg)==PSA_ALG_SHA3_384?48u:\
    PSA_ALG_HMAC_GET_HASH(alg)==PSA_ALG_SHA3_512?64u:\
    0u)

    #definePSA_HASH_BLOCK_LENGTH(alg)\
    (\
    PSA_ALG_HMAC_GET_HASH(alg)==PSA_ALG_MD5?64u:\
    PSA_ALG_HMAC_GET_HASH(alg)==PSA_ALG_RIPEMD160?64u:\
    PSA_ALG_HMAC_GET_HASH(alg)==PSA_ALG_SHA_1?64u:\
    PSA_ALG_HMAC_GET_HASH(alg)==PSA_ALG_SHA_224?64u:\
    PSA_ALG_HMAC_GET_HASH(alg)==PSA_ALG_SHA_256?64u:\
    PSA_ALG_HMAC_GET_HASH(alg)==PSA_ALG_SHA_384?128u:\
    PSA_ALG_HMAC_GET_HASH(alg)==PSA_ALG_SHA_512?128u:\
    PSA_ALG_HMAC_GET_HASH(alg)==PSA_ALG_SHA_512_224?128u:\
    PSA_ALG_HMAC_GET_HASH(alg)==PSA_ALG_SHA_512_256?128u:\
    PSA_ALG_HMAC_GET_HASH(alg)==PSA_ALG_SHA3_224?144u:\
    PSA_ALG_HMAC_GET_HASH(alg)==PSA_ALG_SHA3_256?136u:\
    PSA_ALG_HMAC_GET_HASH(alg)==PSA_ALG_SHA3_384?104u:\
    PSA_ALG_HMAC_GET_HASH(alg)==PSA_ALG_SHA3_512?72u:\
    0u)

    /*Note:forHMAC-SHA-3,theblocksizeis144bytesforHMAC-SHA3-224,
    *136bytesforHMAC-SHA3-256,104bytesforSHA3-384,72bytesfor
    *HMAC-SHA3-512.*/
    /*Note:PSA_HASH_MAX_SIZEshouldbekeptinsyncwithMBEDTLS_MD_MAX_SIZE,
    *seethenoteonMBEDTLS_MD_MAX_SIZEfordetails.*/
    #ifdefined(PSA_WANT_ALG_SHA3_224)
    #definePSA_HMAC_MAX_HASH_BLOCK_SIZE144u
    #elifdefined(PSA_WANT_ALG_SHA3_256)
    #definePSA_HMAC_MAX_HASH_BLOCK_SIZE136u
    #elifdefined(PSA_WANT_ALG_SHA_512)
    #definePSA_HMAC_MAX_HASH_BLOCK_SIZE128u
    #elifdefined(PSA_WANT_ALG_SHA_384)
    #definePSA_HMAC_MAX_HASH_BLOCK_SIZE128u
    #elifdefined(PSA_WANT_ALG_SHA3_384)
    #definePSA_HMAC_MAX_HASH_BLOCK_SIZE104u
    #elifdefined(PSA_WANT_ALG_SHA3_512)
    #definePSA_HMAC_MAX_HASH_BLOCK_SIZE72u
    #elifdefined(PSA_WANT_ALG_SHA_256)
    #definePSA_HMAC_MAX_HASH_BLOCK_SIZE64u
    #elifdefined(PSA_WANT_ALG_SHA_224)
    #definePSA_HMAC_MAX_HASH_BLOCK_SIZE64u
    #else/*SHA-1orsmaller*/
    #definePSA_HMAC_MAX_HASH_BLOCK_SIZE64u
    #endif

    #ifdefined(PSA_WANT_ALG_SHA_512)||defined(PSA_WANT_ALG_SHA3_512)
    #definePSA_HASH_MAX_SIZE64u
    #elifdefined(PSA_WANT_ALG_SHA_384)||defined(PSA_WANT_ALG_SHA3_384)
    #definePSA_HASH_MAX_SIZE48u
    #elifdefined(PSA_WANT_ALG_SHA_256)||defined(PSA_WANT_ALG_SHA3_256)
    #definePSA_HASH_MAX_SIZE32u
    #elifdefined(PSA_WANT_ALG_SHA_224)||defined(PSA_WANT_ALG_SHA3_224)
    #definePSA_HASH_MAX_SIZE28u
    #else/*SHA-1orsmaller*/
    #definePSA_HASH_MAX_SIZE20u
    #endif

    /*Allnon-HMACMACshaveamaximumsizethat'ssmallerthanthe
    *minimumpossiblevalueofPSA_HASH_MAX_SIZEinthisimplementation.*/
    /*NotethattheencodingoftruncatedMACalgorithmslimitsthisvalue
    *to64bytes.
    */
    #definePSA_MAC_MAX_SIZEPSA_HASH_MAX_SIZE

    #definePSA_AEAD_TAG_LENGTH(key_type,key_bits,alg)\
    (PSA_AEAD_NONCE_LENGTH(key_type,alg)!=0?\
    PSA_ALG_AEAD_GET_TAG_LENGTH(alg):\
    ((void)(key_bits),0u))

    #definePSA_AEAD_TAG_MAX_SIZE16u

    /*ThemaximumsizeofanRSAkeyonthisimplementation,inbits.
    *Thisisavendor-specificmacro.
    *
    *MbedTLSdoesnotsetahardlimitonthesizeofRSAkeys:anykey
    *whoseparametersfitinabignumisaccepted.Howeverlargekeyscan
    *inducealargememoryusageandlongcomputationtimes.Unlikeother
    *auxiliarymacrosinthisfileandincrypto.h,whichreflecthowthe
    *libraryisconfigured,thismacrodefineshowthelibraryis
    *configured.Thisimplementationrefusestoimportorgeneratean
    *RSAkeywhosesizeislargerthanthevaluedefinedhere.
    *
    *Notethatanimplementationmaysetdifferentsizelimitsfordifferent
    *operations,anddoesnotneedtoacceptallkeysizesuptothelimit.*/
    #definePSA_VENDOR_RSA_MAX_KEY_BITS4096u

    /*TheminimumsizeofanRSAkeyonthisimplementation,inbits.
    *Thisisavendor-specificmacro.
    *
    *LimitsRSAkeygenerationtoaminimumduetoavoidaccidentalmisuse.
    *Thisvaluecannotbelessthan128bits.
    */
    #ifdefined(MBEDTLS_RSA_GEN_KEY_MIN_BITS)
    #definePSA_VENDOR_RSA_GENERATE_MIN_KEY_BITSMBEDTLS_RSA_GEN_KEY_MIN_BITS
    #else
    #definePSA_VENDOR_RSA_GENERATE_MIN_KEY_BITS1024
    #endif

    /*ThemaximumsizeofanDHkeyonthisimplementation,inbits.
    *Thisisavendor-specificmacro.*/
    #ifdefined(PSA_WANT_DH_RFC7919_8192)
    #definePSA_VENDOR_FFDH_MAX_KEY_BITS8192u
    #elifdefined(PSA_WANT_DH_RFC7919_6144)
    #definePSA_VENDOR_FFDH_MAX_KEY_BITS6144u
    #elifdefined(PSA_WANT_DH_RFC7919_4096)
    #definePSA_VENDOR_FFDH_MAX_KEY_BITS4096u
    #elifdefined(PSA_WANT_DH_RFC7919_3072)
    #definePSA_VENDOR_FFDH_MAX_KEY_BITS3072u
    #elifdefined(PSA_WANT_DH_RFC7919_2048)
    #definePSA_VENDOR_FFDH_MAX_KEY_BITS2048u
    #else
    #definePSA_VENDOR_FFDH_MAX_KEY_BITS0u
    #endif

    /*ThemaximumsizeofanECCkeyonthisimplementation,inbits.
    *Thisisavendor-specificmacro.*/
    #ifdefined(PSA_WANT_ECC_SECP_R1_521)
    #definePSA_VENDOR_ECC_MAX_CURVE_BITS521u
    #elifdefined(PSA_WANT_ECC_BRAINPOOL_P_R1_512)
    #definePSA_VENDOR_ECC_MAX_CURVE_BITS512u
    #elifdefined(PSA_WANT_ECC_MONTGOMERY_448)
    #definePSA_VENDOR_ECC_MAX_CURVE_BITS448u
    #elifdefined(PSA_WANT_ECC_SECP_R1_384)
    #definePSA_VENDOR_ECC_MAX_CURVE_BITS384u
    #elifdefined(PSA_WANT_ECC_BRAINPOOL_P_R1_384)
    #definePSA_VENDOR_ECC_MAX_CURVE_BITS384u
    #elifdefined(PSA_WANT_ECC_SECP_R1_256)
    #definePSA_VENDOR_ECC_MAX_CURVE_BITS256u
    #elifdefined(PSA_WANT_ECC_SECP_K1_256)
    #definePSA_VENDOR_ECC_MAX_CURVE_BITS256u
    #elifdefined(PSA_WANT_ECC_BRAINPOOL_P_R1_256)
    #definePSA_VENDOR_ECC_MAX_CURVE_BITS256u
    #elifdefined(PSA_WANT_ECC_MONTGOMERY_255)
    #definePSA_VENDOR_ECC_MAX_CURVE_BITS255u
    #elifdefined(PSA_WANT_ECC_SECP_R1_224)
    #definePSA_VENDOR_ECC_MAX_CURVE_BITS224u
    #elifdefined(PSA_WANT_ECC_SECP_K1_224)
    #definePSA_VENDOR_ECC_MAX_CURVE_BITS224u
    #elifdefined(PSA_WANT_ECC_SECP_R1_192)
    #definePSA_VENDOR_ECC_MAX_CURVE_BITS192u
    #elifdefined(PSA_WANT_ECC_SECP_K1_192)
    #definePSA_VENDOR_ECC_MAX_CURVE_BITS192u
    #else
    #definePSA_VENDOR_ECC_MAX_CURVE_BITS0u
    #endif

    #definePSA_TLS12_PSK_TO_MS_PSK_MAX_SIZE128u

    /*Theexpectedsizeofinputpassedtopsa_tls12_ecjpake_to_pms_input,
    *whichisexpectedtoworkwithP-256curveonly.*/
    #definePSA_TLS12_ECJPAKE_TO_PMS_INPUT_SIZE65u

    /*ThesizeofaserializedK.Xcoordinatetobeusedin
    *psa_tls12_ecjpake_to_pms_input.ThisfunctiononlyacceptstheP-256
    *curve.*/
    #definePSA_TLS12_ECJPAKE_TO_PMS_DATA_SIZE32u

    /*ThemaximumnumberofiterationsforPBKDF2onthisimplementation,inbits.
    *Thisisavendor-specificmacro.Thiscanbeconfiguredifnecessary*/
    #definePSA_VENDOR_PBKDF2_MAX_ITERATIONS0xffffffffU

    #definePSA_BLOCK_CIPHER_BLOCK_MAX_SIZE16u

    #definePSA_MAC_LENGTH(key_type,key_bits,alg)\
    ((alg)&PSA_ALG_MAC_TRUNCATION_MASK?PSA_MAC_TRUNCATED_LENGTH(alg):\
    PSA_ALG_IS_HMAC(alg)?PSA_HASH_LENGTH(PSA_ALG_HMAC_GET_HASH(alg)):\
    PSA_ALG_IS_BLOCK_CIPHER_MAC(alg)?PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type):\
    ((void)(key_type),(void)(key_bits),0u))

    #definePSA_AEAD_ENCRYPT_OUTPUT_SIZE(key_type,alg,plaintext_length)\
    (PSA_AEAD_NONCE_LENGTH(key_type,alg)!=0?\
    (plaintext_length)+PSA_ALG_AEAD_GET_TAG_LENGTH(alg):\
    0u)

    #definePSA_AEAD_ENCRYPT_OUTPUT_MAX_SIZE(plaintext_length)\
    ((plaintext_length)+PSA_AEAD_TAG_MAX_SIZE)

    #definePSA_AEAD_DECRYPT_OUTPUT_SIZE(key_type,alg,ciphertext_length)\
    (PSA_AEAD_NONCE_LENGTH(key_type,alg)!=0&&\
    (ciphertext_length)>PSA_ALG_AEAD_GET_TAG_LENGTH(alg)?\
    (ciphertext_length)-PSA_ALG_AEAD_GET_TAG_LENGTH(alg):\
    0u)

    #definePSA_AEAD_DECRYPT_OUTPUT_MAX_SIZE(ciphertext_length)\
    (ciphertext_length)

    #definePSA_AEAD_NONCE_LENGTH(key_type,alg)\
    (PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type)==16?\
    MBEDTLS_PSA_ALG_AEAD_EQUAL(alg,PSA_ALG_CCM)?13u:\
    MBEDTLS_PSA_ALG_AEAD_EQUAL(alg,PSA_ALG_GCM)?12u:\
    0u:\
    (key_type)==PSA_KEY_TYPE_CHACHA20&&\
    MBEDTLS_PSA_ALG_AEAD_EQUAL(alg,PSA_ALG_CHACHA20_POLY1305)?12u:\
    0u)

    #definePSA_AEAD_NONCE_MAX_SIZE13u

    /*ForalltheAEADmodesdefinedinthisspecification,itispossible
    *toemitoutputwithoutdelay.However,hardwaremaynotalwaysbe
    *capableofthis.Soformodesbasedonablockcipher,allowthe
    *implementationtodelaytheoutputuntilithasafullblock.*/
    #definePSA_AEAD_UPDATE_OUTPUT_SIZE(key_type,alg,input_length)\
    (PSA_AEAD_NONCE_LENGTH(key_type,alg)!=0?\
    PSA_ALG_IS_AEAD_ON_BLOCK_CIPHER(alg)?\
    PSA_ROUND_UP_TO_MULTIPLE(PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type),(input_length)):\
    (input_length):\
    0u)

    #definePSA_AEAD_UPDATE_OUTPUT_MAX_SIZE(input_length)\
    (PSA_ROUND_UP_TO_MULTIPLE(PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE,(input_length)))

    #definePSA_AEAD_FINISH_OUTPUT_SIZE(key_type,alg)\
    (PSA_AEAD_NONCE_LENGTH(key_type,alg)!=0&&\
    PSA_ALG_IS_AEAD_ON_BLOCK_CIPHER(alg)?\
    PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type):\
    0u)

    #definePSA_AEAD_FINISH_OUTPUT_MAX_SIZE(PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE)

    #definePSA_AEAD_VERIFY_OUTPUT_SIZE(key_type,alg)\
    (PSA_AEAD_NONCE_LENGTH(key_type,alg)!=0&&\
    PSA_ALG_IS_AEAD_ON_BLOCK_CIPHER(alg)?\
    PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type):\
    0u)

    #definePSA_AEAD_VERIFY_OUTPUT_MAX_SIZE(PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE)

    #definePSA_RSA_MINIMUM_PADDING_SIZE(alg)\
    (PSA_ALG_IS_RSA_OAEP(alg)?\
    2u*PSA_HASH_LENGTH(PSA_ALG_RSA_OAEP_GET_HASH(alg))+1u:\
    11u/*PKCS#1v1.5*/)

    #definePSA_ECDSA_SIGNATURE_SIZE(curve_bits)\
    (PSA_BITS_TO_BYTES(curve_bits)*2u)

    #definePSA_SIGN_OUTPUT_SIZE(key_type,key_bits,alg)\
    (PSA_KEY_TYPE_IS_RSA(key_type)?((void)alg,PSA_BITS_TO_BYTES(key_bits)):\
    PSA_KEY_TYPE_IS_ECC(key_type)?PSA_ECDSA_SIGNATURE_SIZE(key_bits):\
    ((void)alg,0u))

    #definePSA_VENDOR_ECDSA_SIGNATURE_MAX_SIZE\
    PSA_ECDSA_SIGNATURE_SIZE(PSA_VENDOR_ECC_MAX_CURVE_BITS)

    #definePSA_SIGNATURE_MAX_SIZE1

    #if(defined(PSA_WANT_ALG_ECDSA)||defined(PSA_WANT_ALG_DETERMINISTIC_ECDSA))&&\
    (PSA_VENDOR_ECDSA_SIGNATURE_MAX_SIZE>PSA_SIGNATURE_MAX_SIZE)
    #undefPSA_SIGNATURE_MAX_SIZE
    #definePSA_SIGNATURE_MAX_SIZEPSA_VENDOR_ECDSA_SIGNATURE_MAX_SIZE
    #endif
    #if(defined(PSA_WANT_ALG_RSA_PKCS1V15_SIGN)||defined(PSA_WANT_ALG_RSA_PSS))&&\
    (PSA_BITS_TO_BYTES(PSA_VENDOR_RSA_MAX_KEY_BITS)>PSA_SIGNATURE_MAX_SIZE)
    #undefPSA_SIGNATURE_MAX_SIZE
    #definePSA_SIGNATURE_MAX_SIZEPSA_BITS_TO_BYTES(PSA_VENDOR_RSA_MAX_KEY_BITS)
    #endif

    #definePSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE(key_type,key_bits,alg)\
    (PSA_KEY_TYPE_IS_RSA(key_type)?\
    ((void)alg,PSA_BITS_TO_BYTES(key_bits)):\
    0u)

    /*ThismacroassumesthatRSAistheonlysupportedasymmetricencryption.*/
    #definePSA_ASYMMETRIC_ENCRYPT_OUTPUT_MAX_SIZE\
    (PSA_BITS_TO_BYTES(PSA_VENDOR_RSA_MAX_KEY_BITS))

    #definePSA_ASYMMETRIC_DECRYPT_OUTPUT_SIZE(key_type,key_bits,alg)\
    (PSA_KEY_TYPE_IS_RSA(key_type)?\
    PSA_BITS_TO_BYTES(key_bits)-PSA_RSA_MINIMUM_PADDING_SIZE(alg):\
    0u)

    #definePSA_ASYMMETRIC_DECRYPT_OUTPUT_MAX_SIZE\
    (PSA_BITS_TO_BYTES(PSA_VENDOR_RSA_MAX_KEY_BITS))

    /*MaximumsizeoftheASN.1encodingofanINTEGERwiththespecified
    *numberofbits.
    *
    *Thisdefinitionassumesthatbits<=2^19-9sothatthelengthfield
    *isatmost3bytes.Thelengthoftheencodingisthelengthofthe
    *bitstringpaddedtoawholenumberofbytesplus:
    *-1typebyte;
    *-1to3lengthbytes;
    *-0to1bytesofleading0duetothesignbit.
    */
    #definePSA_KEY_EXPORT_ASN1_INTEGER_MAX_SIZE(bits)\
    ((bits)/8u+5u)

    /*MaximumsizeoftheexportencodingofanRSApublickey.
    *Assumesthatthepublicexponentislessthan2^32.
    *
    *RSAPublicKey::=SEQUENCE{
    *modulusINTEGER,--n
    *publicExponentINTEGER}--e
    *
    *-4bytesofSEQUENCEoverhead;
    *-n:INTEGER;
    *-7bytesforthepublicexponent.
    */
    #definePSA_KEY_EXPORT_RSA_PUBLIC_KEY_MAX_SIZE(key_bits)\
    (PSA_KEY_EXPORT_ASN1_INTEGER_MAX_SIZE(key_bits)+11u)

    /*MaximumsizeoftheexportencodingofanRSAkeypair.
    *Assumesthatthepublicexponentislessthan2^32andthatthesize
    *differencebetweenthetwoprimesisatmost1bit.
    *
    *RSAPrivateKey::=SEQUENCE{
    *versionVersion,--0
    *modulusINTEGER,--N-bit
    *publicExponentINTEGER,--32-bit
    *privateExponentINTEGER,--N-bit
    *prime1INTEGER,--N/2-bit
    *prime2INTEGER,--N/2-bit
    *exponent1INTEGER,--N/2-bit
    *exponent2INTEGER,--N/2-bit
    *coefficientINTEGER,--N/2-bit
    *}
    *
    *-4bytesofSEQUENCEoverhead;
    *-3bytesofversion;
    *-7half-sizeINTEGERsplus2full-sizeINTEGERs,
    *overapproximatedas9half-sizeINTEGERS;
    *-7bytesforthepublicexponent.
    */
    #definePSA_KEY_EXPORT_RSA_KEY_PAIR_MAX_SIZE(key_bits)\
    (9u*PSA_KEY_EXPORT_ASN1_INTEGER_MAX_SIZE((key_bits)/2u+1u)+14u)

    /*MaximumsizeoftheexportencodingofaDSApublickey.
    *
    *SubjectPublicKeyInfo::=SEQUENCE{
    *algorithmAlgorithmIdentifier,
    *subjectPublicKeyBITSTRING}--containsDSAPublicKey
    *AlgorithmIdentifier::=SEQUENCE{
    *algorithmOBJECTIDENTIFIER,
    *parametersDss-Params}--SEQUENCEof3INTEGERs
    *DSAPublicKey::=INTEGER--publickey,Y
    *
    *-3*4bytesofSEQUENCEoverhead;
    *-1+1+7bytesofalgorithm(DSAOID);
    *-4bytesofBITSTRINGoverhead;
    *-3full-sizeINTEGERs(p,g,y);
    *-1+1+32bytesfor1sub-sizeINTEGER(q<=256bits).
    */
    #definePSA_KEY_EXPORT_DSA_PUBLIC_KEY_MAX_SIZE(key_bits)\
    (PSA_KEY_EXPORT_ASN1_INTEGER_MAX_SIZE(key_bits)*3u+59u)

    /*MaximumsizeoftheexportencodingofaDSAkeypair.
    *
    *DSAPrivateKey::=SEQUENCE{
    *versionVersion,--0
    *primeINTEGER,--p
    *subprimeINTEGER,--q
    *generatorINTEGER,--g
    *publicINTEGER,--y
    *privateINTEGER,--x
    *}
    *
    *-4bytesofSEQUENCEoverhead;
    *-3bytesofversion;
    *-3full-sizeINTEGERs(p,g,y);
    *-2*(1+1+32)bytesfor2sub-sizeINTEGERs(q,x<=256bits).
    */
    #definePSA_KEY_EXPORT_DSA_KEY_PAIR_MAX_SIZE(key_bits)\
    (PSA_KEY_EXPORT_ASN1_INTEGER_MAX_SIZE(key_bits)*3u+75u)

    /*MaximumsizeoftheexportencodingofanECCpublickey.
    *
    *TherepresentationofanECCpublickeyis:
    *-Thebyte0x04;
    *-`x_P`asa`ceiling(m/8)`-bytestring,big-endian;
    *-`y_P`asa`ceiling(m/8)`-bytestring,big-endian;
    *-wheremisthebitsizeassociatedwiththecurve.
    *
    *-1byte+2*pointsize.
    */
    #definePSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(key_bits)\
    (2u*PSA_BITS_TO_BYTES(key_bits)+1u)

    /*MaximumsizeoftheexportencodingofanECCkeypair.
    *
    *AnECCkeypairisrepresentedbythesecretvalue.
    */
    #definePSA_KEY_EXPORT_ECC_KEY_PAIR_MAX_SIZE(key_bits)\
    (PSA_BITS_TO_BYTES(key_bits))

    /*MaximumsizeoftheexportencodingofanDHkeypair.
    *
    *AnDHkeypairisrepresentedbythesecretvalue.
    */
    #definePSA_KEY_EXPORT_FFDH_KEY_PAIR_MAX_SIZE(key_bits)\
    (PSA_BITS_TO_BYTES(key_bits))

    /*MaximumsizeoftheexportencodingofanDHpublickey.
    */
    #definePSA_KEY_EXPORT_FFDH_PUBLIC_KEY_MAX_SIZE(key_bits)\
    (PSA_BITS_TO_BYTES(key_bits))

    #definePSA_EXPORT_KEY_OUTPUT_SIZE(key_type,key_bits)\
    (PSA_KEY_TYPE_IS_UNSTRUCTURED(key_type)?PSA_BITS_TO_BYTES(key_bits):\
    PSA_KEY_TYPE_IS_DH(key_type)?PSA_BITS_TO_BYTES(key_bits):\
    (key_type)==PSA_KEY_TYPE_RSA_KEY_PAIR?PSA_KEY_EXPORT_RSA_KEY_PAIR_MAX_SIZE(key_bits):\
    (key_type)==PSA_KEY_TYPE_RSA_PUBLIC_KEY?PSA_KEY_EXPORT_RSA_PUBLIC_KEY_MAX_SIZE(key_bits):\
    (key_type)==PSA_KEY_TYPE_DSA_KEY_PAIR?PSA_KEY_EXPORT_DSA_KEY_PAIR_MAX_SIZE(key_bits):\
    (key_type)==PSA_KEY_TYPE_DSA_PUBLIC_KEY?PSA_KEY_EXPORT_DSA_PUBLIC_KEY_MAX_SIZE(key_bits):\
    PSA_KEY_TYPE_IS_ECC_KEY_PAIR(key_type)?PSA_KEY_EXPORT_ECC_KEY_PAIR_MAX_SIZE(key_bits):\
    PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY(key_type)?PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(key_bits):\
    0u)

    #definePSA_EXPORT_PUBLIC_KEY_OUTPUT_SIZE(key_type,key_bits)\
    (PSA_KEY_TYPE_IS_RSA(key_type)?PSA_KEY_EXPORT_RSA_PUBLIC_KEY_MAX_SIZE(key_bits):\
    PSA_KEY_TYPE_IS_ECC(key_type)?PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(key_bits):\
    PSA_KEY_TYPE_IS_DH(key_type)?PSA_BITS_TO_BYTES(key_bits):\
    0u)

    #definePSA_EXPORT_KEY_PAIR_MAX_SIZE1

    #ifdefined(PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_BASIC)&&\
    (PSA_KEY_EXPORT_ECC_KEY_PAIR_MAX_SIZE(PSA_VENDOR_ECC_MAX_CURVE_BITS)>\
    PSA_EXPORT_KEY_PAIR_MAX_SIZE)
    #undefPSA_EXPORT_KEY_PAIR_MAX_SIZE
    #definePSA_EXPORT_KEY_PAIR_MAX_SIZE\
    PSA_KEY_EXPORT_ECC_KEY_PAIR_MAX_SIZE(PSA_VENDOR_ECC_MAX_CURVE_BITS)
    #endif
    #ifdefined(PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC)&&\
    (PSA_KEY_EXPORT_RSA_KEY_PAIR_MAX_SIZE(PSA_VENDOR_RSA_MAX_KEY_BITS)>\
    PSA_EXPORT_KEY_PAIR_MAX_SIZE)
    #undefPSA_EXPORT_KEY_PAIR_MAX_SIZE
    #definePSA_EXPORT_KEY_PAIR_MAX_SIZE\
    PSA_KEY_EXPORT_RSA_KEY_PAIR_MAX_SIZE(PSA_VENDOR_RSA_MAX_KEY_BITS)
    #endif
    #ifdefined(PSA_WANT_KEY_TYPE_DH_KEY_PAIR_BASIC)&&\
    (PSA_KEY_EXPORT_FFDH_KEY_PAIR_MAX_SIZE(PSA_VENDOR_FFDH_MAX_KEY_BITS)>\
    PSA_EXPORT_KEY_PAIR_MAX_SIZE)
    #undefPSA_EXPORT_KEY_PAIR_MAX_SIZE
    #definePSA_EXPORT_KEY_PAIR_MAX_SIZE\
    PSA_KEY_EXPORT_FFDH_KEY_PAIR_MAX_SIZE(PSA_VENDOR_FFDH_MAX_KEY_BITS)
    #endif

    #definePSA_EXPORT_PUBLIC_KEY_MAX_SIZE1

    #ifdefined(PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY)&&\
    (PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(PSA_VENDOR_ECC_MAX_CURVE_BITS)>\
    PSA_EXPORT_PUBLIC_KEY_MAX_SIZE)
    #undefPSA_EXPORT_PUBLIC_KEY_MAX_SIZE
    #definePSA_EXPORT_PUBLIC_KEY_MAX_SIZE\
    PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(PSA_VENDOR_ECC_MAX_CURVE_BITS)
    #endif
    #ifdefined(PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY)&&\
    (PSA_KEY_EXPORT_RSA_PUBLIC_KEY_MAX_SIZE(PSA_VENDOR_RSA_MAX_KEY_BITS)>\
    PSA_EXPORT_PUBLIC_KEY_MAX_SIZE)
    #undefPSA_EXPORT_PUBLIC_KEY_MAX_SIZE
    #definePSA_EXPORT_PUBLIC_KEY_MAX_SIZE\
    PSA_KEY_EXPORT_RSA_PUBLIC_KEY_MAX_SIZE(PSA_VENDOR_RSA_MAX_KEY_BITS)
    #endif
    #ifdefined(PSA_WANT_KEY_TYPE_DH_PUBLIC_KEY)&&\
    (PSA_KEY_EXPORT_FFDH_PUBLIC_KEY_MAX_SIZE(PSA_VENDOR_FFDH_MAX_KEY_BITS)>\
    PSA_EXPORT_PUBLIC_KEY_MAX_SIZE)
    #undefPSA_EXPORT_PUBLIC_KEY_MAX_SIZE
    #definePSA_EXPORT_PUBLIC_KEY_MAX_SIZE\
    PSA_KEY_EXPORT_FFDH_PUBLIC_KEY_MAX_SIZE(PSA_VENDOR_FFDH_MAX_KEY_BITS)
    #endif

    #definePSA_EXPORT_KEY_PAIR_OR_PUBLIC_MAX_SIZE\
    ((PSA_EXPORT_KEY_PAIR_MAX_SIZE>PSA_EXPORT_PUBLIC_KEY_MAX_SIZE)?\
    PSA_EXPORT_KEY_PAIR_MAX_SIZE:PSA_EXPORT_PUBLIC_KEY_MAX_SIZE)

    #definePSA_RAW_KEY_AGREEMENT_OUTPUT_SIZE(key_type,key_bits)\
    ((PSA_KEY_TYPE_IS_ECC_KEY_PAIR(key_type)||\
    PSA_KEY_TYPE_IS_DH_KEY_PAIR(key_type))?PSA_BITS_TO_BYTES(key_bits):0u)

    #definePSA_RAW_KEY_AGREEMENT_OUTPUT_MAX_SIZE1

    #ifdefined(PSA_WANT_ALG_ECDH)&&\
    (PSA_BITS_TO_BYTES(PSA_VENDOR_ECC_MAX_CURVE_BITS)>PSA_RAW_KEY_AGREEMENT_OUTPUT_MAX_SIZE)
    #undefPSA_RAW_KEY_AGREEMENT_OUTPUT_MAX_SIZE
    #definePSA_RAW_KEY_AGREEMENT_OUTPUT_MAX_SIZEPSA_BITS_TO_BYTES(PSA_VENDOR_ECC_MAX_CURVE_BITS)
    #endif
    #ifdefined(PSA_WANT_ALG_FFDH)&&\
    (PSA_BITS_TO_BYTES(PSA_VENDOR_FFDH_MAX_KEY_BITS)>PSA_RAW_KEY_AGREEMENT_OUTPUT_MAX_SIZE)
    #undefPSA_RAW_KEY_AGREEMENT_OUTPUT_MAX_SIZE
    #definePSA_RAW_KEY_AGREEMENT_OUTPUT_MAX_SIZEPSA_BITS_TO_BYTES(PSA_VENDOR_FFDH_MAX_KEY_BITS)
    #endif

    #if(defined(PSA_WANT_KEY_TYPE_AES)||defined(PSA_WANT_KEY_TYPE_ARIA)||\
    defined(PSA_WANT_KEY_TYPE_CAMELLIA)||defined(PSA_WANT_KEY_TYPE_CHACHA20))
    #definePSA_CIPHER_MAX_KEY_LENGTH32u
    #elifdefined(PSA_WANT_KEY_TYPE_DES)
    #definePSA_CIPHER_MAX_KEY_LENGTH24u
    #else
    #definePSA_CIPHER_MAX_KEY_LENGTH0u
    #endif

    #definePSA_CIPHER_IV_LENGTH(key_type,alg)\
    (PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type)>1&&\
    ((alg)==PSA_ALG_CTR||\
    (alg)==PSA_ALG_CFB||\
    (alg)==PSA_ALG_OFB||\
    (alg)==PSA_ALG_XTS||\
    (alg)==PSA_ALG_CBC_NO_PADDING||\
    (alg)==PSA_ALG_CBC_PKCS7)?PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type):\
    (key_type)==PSA_KEY_TYPE_CHACHA20&&\
    (alg)==PSA_ALG_STREAM_CIPHER?12u:\
    (alg)==PSA_ALG_CCM_STAR_NO_TAG?13u:\
    0u)

    #definePSA_CIPHER_IV_MAX_SIZE16u

    #definePSA_CIPHER_ENCRYPT_OUTPUT_SIZE(key_type,alg,input_length)\
    (alg==PSA_ALG_CBC_PKCS7?\
    (PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type)!=0?\
    PSA_ROUND_UP_TO_MULTIPLE(PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type),\
    (input_length)+1u)+\
    PSA_CIPHER_IV_LENGTH((key_type),(alg)):0u):\
    (PSA_ALG_IS_CIPHER(alg)?\
    (input_length)+PSA_CIPHER_IV_LENGTH((key_type),(alg)):\
    0u))

    #definePSA_CIPHER_ENCRYPT_OUTPUT_MAX_SIZE(input_length)\
    (PSA_ROUND_UP_TO_MULTIPLE(PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE,\
    (input_length)+1u)+\
    PSA_CIPHER_IV_MAX_SIZE)

    #definePSA_CIPHER_DECRYPT_OUTPUT_SIZE(key_type,alg,input_length)\
    (PSA_ALG_IS_CIPHER(alg)&&\
    ((key_type)&PSA_KEY_TYPE_CATEGORY_MASK)==PSA_KEY_TYPE_CATEGORY_SYMMETRIC?\
    (input_length):\
    0u)

    #definePSA_CIPHER_DECRYPT_OUTPUT_MAX_SIZE(input_length)\
    (input_length)

    #definePSA_CIPHER_UPDATE_OUTPUT_SIZE(key_type,alg,input_length)\
    (PSA_ALG_IS_CIPHER(alg)?\
    (PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type)!=0?\
    (((alg)==PSA_ALG_CBC_PKCS7||\
    (alg)==PSA_ALG_CBC_NO_PADDING||\
    (alg)==PSA_ALG_ECB_NO_PADDING)?\
    PSA_ROUND_UP_TO_MULTIPLE(PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type),\
    input_length):\
    (input_length)):0u):\
    0u)

    #definePSA_CIPHER_UPDATE_OUTPUT_MAX_SIZE(input_length)\
    (PSA_ROUND_UP_TO_MULTIPLE(PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE,input_length))

    #definePSA_CIPHER_FINISH_OUTPUT_SIZE(key_type,alg)\
    (PSA_ALG_IS_CIPHER(alg)?\
    (alg==PSA_ALG_CBC_PKCS7?\
    PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type):\
    0u):\
    0u)

    #definePSA_CIPHER_FINISH_OUTPUT_MAX_SIZE\
    (PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE)

    #endif/*PSA_CRYPTO_SIZES_H*/