Loading...
Searching...
No Matches
crypto_sizes.h File Reference

Size definitions for PSA Crypto. More...

Detailed Description

Size definitions for PSA Crypto.

Author
Lena Boeckmann lena..nosp@m.boec.nosp@m.kmann.nosp@m.@haw.nosp@m.-hamb.nosp@m.urg..nosp@m.de
Note
Some of the macros in this file have already been copied here from the PSA API specification, but are not implemented, yet. They are marked by comments that either say "specification-defined" or "implementation-defined". These macros will be implemented successively in the future.

Definition in file crypto_sizes.h.

#include "kernel_defines.h"
#include "crypto_values.h"
+ Include dependency graph for crypto_sizes.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

#define PSA_BITS_TO_BYTES(bits)   (size_t)(((bits) + 7) / 8)
 Functions to convert bits to bytes.
 
#define PSA_BYTES_TO_BITS(bytes)   ((bytes) * 8)
 Functions to convert bytes to bits.
 
#define CONFIG_PSA_MAX_KEY_SIZE   0
 Maximum key size determined by the build system.
 
#define CONFIG_PSA_ASYMMETRIC_KEYPAIR_COUNT   0
 Number of required allocated asymmetric key pair slots.
 
#define CONFIG_PSA_SINGLE_KEY_COUNT   0
 Number of required allocated single key slots.
 
#define CONFIG_PSA_PROTECTED_KEY_COUNT   0
 Number of required allocated protected key slots.
 
#define PSA_AEAD_DECRYPT_OUTPUT_MAX_SIZE(ciphertext_length)   /* implementation-defined value */
 A sufficient plaintext buffer size for psa_aead_decrypt(), for any of the supported key types and AEAD algorithms.
 
#define PSA_AEAD_DECRYPT_OUTPUT_SIZE(key_type, alg, ciphertext_length)   /* implementation-defined value */
 A sufficient plaintext buffer size for psa_aead_decrypt(), in bytes.
 
#define PSA_AEAD_ENCRYPT_OUTPUT_MAX_SIZE(plaintext_length)   /* implementation-defined value */
 A sufficient ciphertext buffer size for psa_aead_encrypt(), for any of the supported key types and AEAD algorithms.
 
#define PSA_AEAD_ENCRYPT_OUTPUT_SIZE(key_type, alg, plaintext_length)   /* implementation-defined value */
 A sufficient ciphertext buffer size for psa_aead_encrypt(), in bytes.
 
#define PSA_AEAD_FINISH_OUTPUT_MAX_SIZE   /* implementation-defined value */
 A sufficient ciphertext buffer size for psa_aead_finish(), for any of the supported key types and AEAD algorithms.
 
#define PSA_AEAD_FINISH_OUTPUT_SIZE(key_type, alg)   /* implementation-defined value */
 A sufficient ciphertext buffer size for psa_aead_finish().
 
#define PSA_AEAD_NONCE_LENGTH(key_type, alg)   /* implementation-defined value */
 The default nonce size for an AEAD algorithm, in bytes.
 
#define PSA_AEAD_NONCE_MAX_SIZE   /* implementation-defined value */
 A sufficient buffer size for storing the nonce generated by psa_aead_generate_nonce(), for any of the supported key types and AEAD algorithms.
 
#define PSA_AEAD_TAG_LENGTH(key_type, key_bits, alg)   /* implementation-defined value */
 The length of a tag for an AEAD algorithm, in bytes.
 
#define PSA_AEAD_TAG_MAX_SIZE   /* implementation-defined value */
 A sufficient buffer size for storing the tag output by psa_aead_finish(), for any of the supported key types and AEAD algorithms.
 
#define PSA_AEAD_UPDATE_OUTPUT_MAX_SIZE(input_length)   /* implementation-defined value */
 A sufficient output buffer size for psa_aead_update(), for any of the supported key types and AEAD algorithms.
 
#define PSA_AEAD_UPDATE_OUTPUT_SIZE(key_type, alg, input_length)   /* implementation-defined value */
 A sufficient output buffer size for psa_aead_update().
 
#define PSA_AEAD_VERIFY_OUTPUT_MAX_SIZE   /* implementation-defined value */
 A sufficient output buffer size for psa_aead_update(), for any of the supported key types and AEAD algorithms.
 
#define PSA_AEAD_VERIFY_OUTPUT_SIZE(key_type, alg)   /* implementation-defined value */
 A sufficient plaintext buffer size for psa_aead_verify(), in bytes.
 
#define PSA_HASH_MAX_SIZE   (64)
 Maximum size of a hash supported by this implementation, in bytes.
 
#define PSA_HASH_BLOCK_LENGTH(alg)   /* implementation-defined value */
 The input block size of a hash algorithm, in bytes.
 
#define PSA_HASH_LENGTH(alg)
 The size of the output of psa_hash_compute() and psa_hash_finish(), in bytes.
 
#define PSA_MAC_LENGTH(key_type, key_bits, alg)
 The size of the output of psa_mac_compute() and psa_mac_sign_finish(), in bytes.
 
#define PSA_MAC_MAX_SIZE   (PSA_HASH_MAX_SIZE)
 A sufficient buffer size for storing the MAC output by psa_mac_verify() and psa_mac_verify_finish(), for any of the supported key types and MAC algorithms.
 
#define PSA_BLOCK_CIPHER_BLOCK_LENGTH(type)    (1u << (((type) >> 8) & 7))
 The block size of a block cipher.
 
#define PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE   /* implementation-defined value */
 The maximum block size of a block cipher supported by the implementation.
 
#define 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.
 
#define PSA_CIPHER_DECRYPT_OUTPUT_SIZE(key_type, alg, input_length)    (input_length - PSA_CIPHER_IV_LENGTH(key_type, alg))
 The maximum size of the output of psa_cipher_decrypt(), in bytes.
 
#define PSA_CIPHER_ENCRYPT_OUTPUT_MAX_SIZE(input_length)    (PSA_CIPHER_ENCRYPT_OUTPUT_SIZE(PSA_KEY_TYPE_AES, PSA_ALG_CBC_NO_PADDING, input_length))
 A sufficient output buffer size for psa_cipher_encrypt(), for any of the supported key types and cipher algorithms.
 
#define PSA_CIPHER_ENCRYPT_OUTPUT_SIZE(key_type, alg, input_length)    (input_length + PSA_CIPHER_IV_LENGTH(key_type, alg))
 The maximum size of the output of psa_cipher_encrypt(), in bytes.
 
#define PSA_CIPHER_FINISH_OUTPUT_MAX_SIZE   /* implementation-defined value */
 A sufficient output buffer size for psa_cipher_finish(), for any of the supported key types and cipher algorithms.
 
#define PSA_CIPHER_FINISH_OUTPUT_SIZE(key_type, alg)   /* implementation-defined value */
 A sufficient output buffer size for psa_cipher_finish().
 
#define PSA_CIPHER_IV_LENGTH(key_type, alg)
 The default IV size for a cipher algorithm, in bytes.
 
#define PSA_CIPHER_IV_MAX_SIZE   /* implementation-defined value */
 A sufficient buffer size for storing the IV generated by psa_cipher_generate_iv(), for any of the supported key types and cipher algorithms.
 
#define PSA_CIPHER_UPDATE_OUTPUT_MAX_SIZE(input_length)   /* implementation-defined value */
 A sufficient output buffer size for psa_cipher_update(), for any of the supported key types and cipher algorithms.
 
#define PSA_CIPHER_UPDATE_OUTPUT_SIZE(key_type, alg, input_length)   /* implementation-defined value */
 A sufficient output buffer size for psa_cipher_update().
 
#define PSA_HASH_SUSPEND_ALGORITHM_FIELD_LENGTH   ((size_t)4)
 The size of the algorithm field that is part of the output of psa_hash_suspend(), in bytes.
 
#define PSA_HASH_SUSPEND_HASH_STATE_FIELD_LENGTH(alg)   /* specification-defined value */
 The size of the hash-state field that is part of the output of psa_hash_suspend(), in bytes.
 
#define PSA_HASH_SUSPEND_INPUT_LENGTH_FIELD_LENGTH(alg)   /* specification-defined value */
 The size of the input-length field that is part of the output of psa_hash_suspend(), in bytes.
 
#define PSA_HASH_SUSPEND_OUTPUT_MAX_SIZE   /* implementation-defined value */
 A sufficient hash suspend state buffer size for psa_hash_suspend(), for any supported hash algorithms.
 
#define PSA_HASH_SUSPEND_OUTPUT_SIZE(alg)   /* specification-defined value */
 A sufficient hash suspend state buffer size for psa_hash_suspend(), in bytes.
 
#define PSA_ASYMMETRIC_DECRYPT_OUTPUT_MAX_SIZE   /* implementation-defined value */
 A sufficient output buffer size for psa_asymmetric_decrypt(), for any of the supported key types and asymmetric encryption algorithms.
 
#define PSA_ASYMMETRIC_DECRYPT_OUTPUT_SIZE(key_type, key_bits, alg)   /* implementation-defined value */
 Sufficient output buffer size for psa_asymmetric_decrypt().
 
#define PSA_ASYMMETRIC_ENCRYPT_OUTPUT_MAX_SIZE   /* implementation-defined value */
 A sufficient output buffer size for psa_asymmetric_encrypt(), for any of the supported key types and asymmetric encryption algorithms.
 
#define PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE(key_type, key_bits, alg)   /* implementation-defined value */
 Sufficient output buffer size for psa_asymmetric_encrypt().
 
#define PSA_KEY_EXPORT_ECC_KEY_MAX_SIZE(key_type, key_bits)
 Maximum size of the export encoding of an ECC keypair.
 
#define PSA_EXPORT_KEY_OUTPUT_SIZE(key_type, key_bits)
 Sufficient output buffer size for psa_export_key().
 
#define PSA_ECC_KEY_SIZE_IS_VALID(type, bits)
 Check whether the key size is a valid ECC size for key type.
 
#define PSA_MAX_PRIV_KEY_SIZE   (PSA_BYTES_TO_BITS(CONFIG_PSA_MAX_KEY_SIZE))
 The maximum size of an asymmetric private key.
 
#define PSA_EXPORT_KEY_PAIR_MAX_SIZE   0
 Sufficient buffer size for exporting any asymmetric key pair.
 
#define PSA_ECC_KEY_GET_CURVE_FROM_PUBLIC_KEY(key_type, key_bits)
 Get curve size from ECC public key.
 
#define PSA_ECC_KEY_GET_CURVE(key_type, key_bits)
 Get curve size from ECC key (public or private)
 
#define PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(key_type, key_bits)
 Maximum size of the export encoding of an ECC public key.
 
#define PSA_EXPORT_PUBLIC_KEY_OUTPUT_SIZE(key_type, key_bits)
 Sufficient output buffer size for psa_export_public_key().
 
#define PSA_EXPORT_PUBLIC_KEY_MAX_SIZE   0
 Sufficient buffer size for exporting any asymmetric public key.
 
#define PSA_MAX_PRIV_KEY_BUFFER_SIZE   (PSA_BITS_TO_BYTES(PSA_MAX_PRIV_KEY_SIZE))
 The maximum size of an asymmetric private key buffer.
 
#define PSA_MAX_ASYMMETRIC_KEYPAIR_SIZE
 The maximum size of an asymmetric private key pair.
 
#define PSA_MAX_KEY_DATA_SIZE   (CONFIG_PSA_MAX_KEY_SIZE)
 The maximum size of the used key data.
 
#define PSA_MAX_UNSTRUCTURED_KEY_SIZE   (CONFIG_PSA_MAX_KEY_SIZE)
 The maximum size of an unstructured key.
 
#define PSA_ECDSA_SIGNATURE_SIZE(curve_bits)    ((size_t)(PSA_BITS_TO_BYTES(curve_bits) * 2))
 ECDSA signature size for a given curve bit size.
 
#define PSA_SIGN_OUTPUT_SIZE(key_type, key_bits, alg)
 Sufficient signature buffer size for psa_sign_message() and psa_sign_hash().
 

Macro Definition Documentation

◆ CONFIG_PSA_ASYMMETRIC_KEYPAIR_COUNT

#define CONFIG_PSA_ASYMMETRIC_KEYPAIR_COUNT   0

Number of required allocated asymmetric key pair slots.

These should be defined by the developer to fit their requirements. The default number is 0.

Definition at line 85 of file crypto_sizes.h.

◆ CONFIG_PSA_MAX_KEY_SIZE

#define CONFIG_PSA_MAX_KEY_SIZE   0

Maximum key size determined by the build system.

The maximum key size is set automatically, depending on the features chosen at compile-time. They should not be changed manually.

Definition at line 74 of file crypto_sizes.h.

◆ CONFIG_PSA_PROTECTED_KEY_COUNT

#define CONFIG_PSA_PROTECTED_KEY_COUNT   0

Number of required allocated protected key slots.

These should be defined by the developer to fit their requirements. The default number is 5.

Definition at line 108 of file crypto_sizes.h.

◆ CONFIG_PSA_SINGLE_KEY_COUNT

#define CONFIG_PSA_SINGLE_KEY_COUNT   0

Number of required allocated single key slots.

These should be defined by the developer to fit their requirements. The default number is 0.

Definition at line 95 of file crypto_sizes.h.

◆ PSA_AEAD_DECRYPT_OUTPUT_MAX_SIZE

#define PSA_AEAD_DECRYPT_OUTPUT_MAX_SIZE (   ciphertext_length)    /* implementation-defined value */

A sufficient plaintext 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.

See also PSA_AEAD_DECRYPT_OUTPUT_SIZE().

Parameters
ciphertext_lengthSize of the ciphertext in bytes.

Definition at line 124 of file crypto_sizes.h.

◆ PSA_AEAD_DECRYPT_OUTPUT_SIZE

#define PSA_AEAD_DECRYPT_OUTPUT_SIZE (   key_type,
  alg,
  ciphertext_length 
)    /* implementation-defined value */

A sufficient plaintext buffer size for 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 might be smaller.

See also PSA_AEAD_DECRYPT_OUTPUT_MAX_SIZE.

Parameters
key_typeA symmetric key type that is compatible with algorithm alg.
algAn AEAD algorithm: a value of type psa_algorithm_t such that PSA_ALG_IS_AEAD(alg) is true.
ciphertext_lengthSize of the ciphertext in bytes.
Returns
The AEAD plaintext size for the specified key type and algorithm. 0 if the key type or AEAD algorithm is not recognized, not supported or the parameters are incompatible.

Definition at line 145 of file crypto_sizes.h.

◆ PSA_AEAD_ENCRYPT_OUTPUT_MAX_SIZE

#define PSA_AEAD_ENCRYPT_OUTPUT_MAX_SIZE (   plaintext_length)    /* implementation-defined value */

A sufficient ciphertext 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.

See also PSA_AEAD_ENCRYPT_OUTPUT_SIZE().

Parameters
plaintext_lengthSize of the plaintext in bytes.

Definition at line 160 of file crypto_sizes.h.

◆ PSA_AEAD_ENCRYPT_OUTPUT_SIZE

#define PSA_AEAD_ENCRYPT_OUTPUT_SIZE (   key_type,
  alg,
  plaintext_length 
)    /* implementation-defined value */

A sufficient ciphertext buffer size for 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 might be smaller.

See also PSA_AEAD_ENCRYPT_OUTPUT_MAX_SIZE.

Parameters
key_typeA symmetric key type that is compatible with algorithm alg.
algAn AEAD algorithm: a value of type psa_algorithm_t such that PSA_ALG_IS_AEAD(alg) is true.
plaintext_lengthSize of the plaintext in bytes.
Returns
The AEAD ciphertext size for the specified key type and algorithm. 0 if the key type or AEAD algorithm is not recognized, not supported or the parameters are incompatible.

Definition at line 181 of file crypto_sizes.h.

◆ PSA_AEAD_FINISH_OUTPUT_MAX_SIZE

#define PSA_AEAD_FINISH_OUTPUT_MAX_SIZE   /* implementation-defined value */

A sufficient ciphertext buffer size for psa_aead_finish(), 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_finish() will not fail due to an insufficient ciphertext buffer size.

See also PSA_AEAD_FINISH_OUTPUT_SIZE().

Definition at line 193 of file crypto_sizes.h.

◆ PSA_AEAD_FINISH_OUTPUT_SIZE

#define PSA_AEAD_FINISH_OUTPUT_SIZE (   key_type,
  alg 
)    /* implementation-defined value */

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 might be smaller in any given call.

See also PSA_AEAD_FINISH_OUTPUT_MAX_SIZE.

Parameters
key_typeA symmetric key type that is compatible with algorithm alg.
algAn AEAD algorithm: a value of type psa_algorithm_t such that PSA_ALG_IS_AEAD(alg) is true.
Returns
A sufficient ciphertext buffer 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. An implementation can return either 0 or a correct size for a key type and AEAD algorithm that it recognizes, but does not support.

Definition at line 213 of file crypto_sizes.h.

◆ PSA_AEAD_NONCE_LENGTH

#define PSA_AEAD_NONCE_LENGTH (   key_type,
  alg 
)    /* implementation-defined value */

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

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

For most AEAD algorithms, PSA_AEAD_NONCE_LENGTH() evaluates to the exact size of the nonce generated by psa_aead_generate_nonce().

See also PSA_AEAD_NONCE_MAX_SIZE.

Parameters
key_typeA symmetric key type that is compatible with algorithm alg.
algAn AEAD algorithm: a value of type psa_algorithm_t such that PSA_ALG_IS_AEAD(alg) is true.
Returns
The default nonce size for the specified key type and algorithm. 0 if the key type or AEAD algorithm is not recognized, not supported or the parameters are incompatible.

Definition at line 235 of file crypto_sizes.h.

◆ PSA_AEAD_NONCE_MAX_SIZE

#define PSA_AEAD_NONCE_MAX_SIZE   /* implementation-defined value */

A sufficient buffer size for storing the nonce generated by psa_aead_generate_nonce(), for any of the supported key types and AEAD algorithms.

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

See also PSA_AEAD_NONCE_LENGTH().

Definition at line 246 of file crypto_sizes.h.

◆ PSA_AEAD_TAG_LENGTH

#define PSA_AEAD_TAG_LENGTH (   key_type,
  key_bits,
  alg 
)    /* implementation-defined value */

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

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

See also PSA_AEAD_TAG_MAX_SIZE.

Parameters
key_typeThe type of the AEAD key.
key_bitsThe size of the AEAD key in bits.
algAn AEAD algorithm: a value of type psa_algorithm_t such that PSA_ALG_IS_AEAD(alg) is true.
Returns
The tag length for the specified algorithm and key. 0 if the AEAD algorithm does not have an identified tag that can be distinguished from the rest of the ciphertext. 0 if the AEAD algorithm is not recognized or not supported.

Definition at line 267 of file crypto_sizes.h.

◆ PSA_AEAD_TAG_MAX_SIZE

#define PSA_AEAD_TAG_MAX_SIZE   /* implementation-defined value */

A sufficient buffer size for storing the tag output by psa_aead_finish(), for any of the supported key types and AEAD algorithms.

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

See also PSA_AEAD_TAG_LENGTH().

Definition at line 279 of file crypto_sizes.h.

◆ PSA_AEAD_UPDATE_OUTPUT_MAX_SIZE

#define PSA_AEAD_UPDATE_OUTPUT_MAX_SIZE (   input_length)    /* implementation-defined value */

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().

Parameters
input_lengthSize of the input in bytes.

Definition at line 292 of file crypto_sizes.h.

◆ PSA_AEAD_UPDATE_OUTPUT_SIZE

#define PSA_AEAD_UPDATE_OUTPUT_SIZE (   key_type,
  alg,
  input_length 
)    /* implementation-defined value */

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 might be smaller in any given call.

See also PSA_AEAD_UPDATE_OUTPUT_MAX_SIZE.

Parameters
key_typeA symmetric key type that is compatible with algorithm alg.
algAn AEAD algorithm: a value of type psa_algorithm_t such that PSA_ALG_IS_AEAD(alg) is true.
input_lengthSize of the input in bytes.
Returns
A sufficient output buffer size for the specified key type and algorithm. 0 if the key type or AEAD algorithm is not recognized, not supported or the parameters are incompatible.

Definition at line 313 of file crypto_sizes.h.

◆ PSA_AEAD_VERIFY_OUTPUT_MAX_SIZE

#define PSA_AEAD_VERIFY_OUTPUT_MAX_SIZE   /* implementation-defined value */

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().

Parameters
input_lengthSize of the input in bytes.

Definition at line 327 of file crypto_sizes.h.

◆ PSA_AEAD_VERIFY_OUTPUT_SIZE

#define PSA_AEAD_VERIFY_OUTPUT_SIZE (   key_type,
  alg 
)    /* implementation-defined value */

A sufficient plaintext buffer size for psa_aead_verify(), in bytes.

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 might be smaller in any given call.

See also PSA_AEAD_VERIFY_OUTPUT_MAX_SIZE.

Parameters
key_typeA symmetric key type that is compatible with algorithm alg.
algAn AEAD algorithm: a value of type psa_algorithm_t such that PSA_ALG_IS_AEAD(alg) is true.
Returns
A sufficient plaintext buffer size for the specified key type and algorithm. 0 if the key type or AEAD algorithm is not recognized, not supported or the parameters are incompatible.

Definition at line 346 of file crypto_sizes.h.

◆ PSA_ASYMMETRIC_DECRYPT_OUTPUT_MAX_SIZE

#define PSA_ASYMMETRIC_DECRYPT_OUTPUT_MAX_SIZE   /* implementation-defined value */

A sufficient output buffer size for psa_asymmetric_decrypt(), for any of the supported key types and asymmetric encryption algorithms.

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

See also PSA_ASYMMETRIC_DECRYPT_OUTPUT_SIZE().

Definition at line 736 of file crypto_sizes.h.

◆ PSA_ASYMMETRIC_DECRYPT_OUTPUT_SIZE

#define PSA_ASYMMETRIC_DECRYPT_OUTPUT_SIZE (   key_type,
  key_bits,
  alg 
)    /* implementation-defined value */

Sufficient output buffer size for psa_asymmetric_decrypt().

If the size of the output buffer is at least this large, it is guaranteed that psa_asymmetric_decrypt() 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_ASYMMETRIC_DECRYPT_OUTPUT_MAX_SIZE.

Parameters
key_typeAn asymmetric key type, either a key pair or a public key.
key_bitsThe size of the key in bits.
algAn asymmetric encryption algorithm: a value of type psa_algorithm_t such that PSA_ALG_IS_ASYMMETRIC_ENCRYPTION(alg) is true.
Returns
A sufficient output buffer size for the specified asymmetric encryption algorithm and key parameters. 0 if the asymmetric encryption algorithm and key parameters are not supported. Unspecified if the parameters are not valid.

Definition at line 758 of file crypto_sizes.h.

◆ PSA_ASYMMETRIC_ENCRYPT_OUTPUT_MAX_SIZE

#define PSA_ASYMMETRIC_ENCRYPT_OUTPUT_MAX_SIZE   /* implementation-defined value */

A sufficient output buffer size for psa_asymmetric_encrypt(), for any of the supported key types and asymmetric encryption algorithms.

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

See also PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE().

Definition at line 770 of file crypto_sizes.h.

◆ PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE

#define PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE (   key_type,
  key_bits,
  alg 
)    /* implementation-defined value */

Sufficient output buffer size for psa_asymmetric_encrypt().

If the size of the output buffer is at least this large, it is guaranteed that psa_asymmetric_encrypt() 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_ASYMMETRIC_ENCRYPT_OUTPUT_MAX_SIZE.

Parameters
key_typeAn asymmetric key type, either a key pair or a public key.
key_bitsThe size of the key in bits.
algAn asymmetric encryption algorithm: a value of type psa_algorithm_t such that PSA_ALG_IS_ASYMMETRIC_ENCRYPTION(alg) is true.
Returns
A sufficient output buffer size for the specified asymmetric encryption algorithm and key parameters. 0 if the asymmetric encryption algorithm and key parameters are not supported. Unspecified if the parameters are not valid.

Definition at line 791 of file crypto_sizes.h.

◆ PSA_BITS_TO_BYTES

#define PSA_BITS_TO_BYTES (   bits)    (size_t)(((bits) + 7) / 8)

Functions to convert bits to bytes.

Parameters
bits
Returns
Number of bytes contained in bits

Definition at line 42 of file crypto_sizes.h.

◆ PSA_BLOCK_CIPHER_BLOCK_LENGTH

#define PSA_BLOCK_CIPHER_BLOCK_LENGTH (   type)     (1u << (((type) >> 8) & 7))

The block size of a block cipher.

Note
It is possible to build stream cipher algorithms on top of a block cipher, for example CTR mode (PSA_ALG_CTR). This macro only takes the key type into account, so it cannot be used to determine the size of the data that psa_cipher_update() might buffer for future processing in general.
Parameters
typeA cipher key type (value of type psa_key_type_t).
Returns
The block size for a block cipher, or 1 for a stream cipher.

Definition at line 458 of file crypto_sizes.h.

◆ PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE

#define PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE   /* implementation-defined value */

The maximum block size of a block cipher supported by the implementation.

See also PSA_BLOCK_CIPHER_BLOCK_LENGTH().

Definition at line 466 of file crypto_sizes.h.

◆ PSA_BYTES_TO_BITS

#define PSA_BYTES_TO_BITS (   bytes)    ((bytes) * 8)

Functions to convert bytes to bits.

Parameters
bytes
Returns
Number of bits contained in bytes

Definition at line 51 of file crypto_sizes.h.

◆ PSA_CIPHER_DECRYPT_OUTPUT_MAX_SIZE

#define 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().

Parameters
input_lengthSize of the input in bytes.

Definition at line 479 of file crypto_sizes.h.

◆ PSA_CIPHER_DECRYPT_OUTPUT_SIZE

#define PSA_CIPHER_DECRYPT_OUTPUT_SIZE (   key_type,
  alg,
  input_length 
)     (input_length - PSA_CIPHER_IV_LENGTH(key_type, alg))

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.

Parameters
key_typeA symmetric key type that is compatible with algorithm alg.
algA cipher algorithm (PSA_ALG_XXX value such that PSA_ALG_IS_CIPHER(alg) is true).
input_lengthSize of the input in bytes.
Returns
A sufficient output size for the specified key type and algorithm. 0 if the key type or cipher algorithm is not recognized, or the parameters are incompatible.

Definition at line 500 of file crypto_sizes.h.

◆ PSA_CIPHER_ENCRYPT_OUTPUT_MAX_SIZE

#define PSA_CIPHER_ENCRYPT_OUTPUT_MAX_SIZE (   input_length)     (PSA_CIPHER_ENCRYPT_OUTPUT_SIZE(PSA_KEY_TYPE_AES, PSA_ALG_CBC_NO_PADDING, input_length))

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().

Parameters
input_lengthSize of the input in bytes.

Definition at line 514 of file crypto_sizes.h.

◆ PSA_CIPHER_ENCRYPT_OUTPUT_SIZE

#define PSA_CIPHER_ENCRYPT_OUTPUT_SIZE (   key_type,
  alg,
  input_length 
)     (input_length + PSA_CIPHER_IV_LENGTH(key_type, alg))

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.

Parameters
key_typeA symmetric key type that is compatible with algorithm alg.
algA cipher algorithm (PSA_ALG_XXX value such that PSA_ALG_IS_CIPHER(alg) is true).
input_lengthSize of the input in bytes.
Returns
A sufficient output size for the specified key type and algorithm. 0 if the key type or cipher algorithm is not recognized, not supported or the parameters are incompatible.

Definition at line 535 of file crypto_sizes.h.

◆ PSA_CIPHER_FINISH_OUTPUT_MAX_SIZE

#define PSA_CIPHER_FINISH_OUTPUT_MAX_SIZE   /* implementation-defined value */

A sufficient output buffer size for psa_cipher_finish(), 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_finish() will not fail due to an insufficient buffer size.

See also PSA_CIPHER_FINISH_OUTPUT_SIZE().

Definition at line 547 of file crypto_sizes.h.

◆ PSA_CIPHER_FINISH_OUTPUT_SIZE

#define PSA_CIPHER_FINISH_OUTPUT_SIZE (   key_type,
  alg 
)    /* implementation-defined value */

A sufficient output buffer size for psa_cipher_finish().

If the size of the output buffer is at least this large, it is guaranteed that psa_cipher_finish() 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_FINISH_OUTPUT_MAX_SIZE.

Parameters
key_typeA symmetric key type that is compatible with algorithm alg.
algA cipher algorithm: a value of type psa_algorithm_t such that PSA_ALG_IS_CIPHER(alg) is true.
Returns
A sufficient output size for the specified key type and algorithm. 0 if the key type or cipher algorithm is not recognized, not supported or the parameters are incompatible.

Definition at line 566 of file crypto_sizes.h.

◆ PSA_CIPHER_IV_LENGTH

#define PSA_CIPHER_IV_LENGTH (   key_type,
  alg 
)
Value:
(PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type) > 1 && \
((alg) == PSA_ALG_CBC_NO_PADDING) ? 16 : 0)
#define PSA_BLOCK_CIPHER_BLOCK_LENGTH(type)
The block size of a block cipher.
#define PSA_ALG_CBC_NO_PADDING
The Cipher Block Chaining (CBC) mode of a block cipher, with no padding.

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.

Warning
This macro may evaluate its arguments multiple times or zero times, so you should not pass arguments that contain side effects.
Parameters
key_typeA symmetric key type that is compatible with algorithm alg.
algA cipher algorithm (PSA_ALG_XXX value such that PSA_ALG_IS_CIPHER(alg) is true)
Returns
The default IV size for the specified key type and algorithm. 0, if the algorithm does not use an IV, if key type or cipher algorithm are not recognized or if the parameters are not compatible.

Definition at line 595 of file crypto_sizes.h.

◆ PSA_CIPHER_IV_MAX_SIZE

#define PSA_CIPHER_IV_MAX_SIZE   /* implementation-defined value */

A sufficient buffer size for storing the IV generated by psa_cipher_generate_iv(), for any of the supported key types and cipher algorithms.

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

See also PSA_CIPHER_IV_LENGTH().

Definition at line 608 of file crypto_sizes.h.

◆ PSA_CIPHER_UPDATE_OUTPUT_MAX_SIZE

#define PSA_CIPHER_UPDATE_OUTPUT_MAX_SIZE (   input_length)    /* implementation-defined value */

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().

Parameters
input_lengthSize of the input in bytes.

Definition at line 622 of file crypto_sizes.h.

◆ PSA_CIPHER_UPDATE_OUTPUT_SIZE

#define PSA_CIPHER_UPDATE_OUTPUT_SIZE (   key_type,
  alg,
  input_length 
)    /* implementation-defined value */

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.

Parameters
key_typeA symmetric key type that is compatible with algorithm alg.
algA cipher algorithm (PSA_ALG_XXX value such that PSA_ALG_IS_CIPHER(alg) is true).
input_lengthSize of the input in bytes.
Returns
A sufficient output size for the specified key type and algorithm. 0 if the key type or cipher algorithm is not recognized, not supported or the parameters are incompatible.

Definition at line 644 of file crypto_sizes.h.

◆ PSA_ECC_KEY_GET_CURVE

#define PSA_ECC_KEY_GET_CURVE (   key_type,
  key_bits 
)
Value:
PSA_ECC_KEY_GET_CURVE_FROM_PUBLIC_KEY(key_type, key_bits) : \
(size_t)key_bits)
#define PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY(type)
Whether a key type is an elliptic curve public key.

Get curve size from ECC key (public or private)

Definition at line 915 of file crypto_sizes.h.

◆ PSA_ECC_KEY_GET_CURVE_FROM_PUBLIC_KEY

#define PSA_ECC_KEY_GET_CURVE_FROM_PUBLIC_KEY (   key_type,
  key_bits 
)
Value:
((size_t)((key_bits - 8) / 2)))
#define PSA_KEY_TYPE_ECC_GET_FAMILY(type)
Extract the curve family from an elliptic curve key type.
#define PSA_ECC_FAMILY_TWISTED_EDWARDS
Twisted Edwards curves.

Get curve size from ECC public key.

The representation of an ECC public key is dependent on the family:

  • for twisted Edwards curves: 32B
  • for Weierstrass curves:
    • The byte 0x04;
    • x_P as a ceiling(m/8)-byte string, big-endian;
    • y_P as a ceiling(m/8)-byte string, big-endian;
    • where m is the bit size associated with the curve.
    • 1 byte + 2 * point size.

Definition at line 908 of file crypto_sizes.h.

◆ PSA_ECC_KEY_SIZE_IS_VALID

#define PSA_ECC_KEY_SIZE_IS_VALID (   type,
  bits 
)
Value:
(bits == 255) : \
(bits == 128 || \
bits == 192 || \
bits == 224 || \
bits == 256 || \
bits == 384) : \
0))
#define PSA_ECC_FAMILY_SECP_R1
SEC random curves over prime fields.

Check whether the key size is a valid ECC size for key type.

Parameters
typekey type of of type psa_key_type_t
bitsKey size of type psa_key_bits_t

Definition at line 857 of file crypto_sizes.h.

◆ PSA_ECDSA_SIGNATURE_SIZE

#define PSA_ECDSA_SIGNATURE_SIZE (   curve_bits)     ((size_t)(PSA_BITS_TO_BYTES(curve_bits) * 2))

ECDSA signature size for a given curve bit size.

Note
This macro returns a compile-time constant if its argument is one.
Parameters
curve_bitsCurve size in bits.
Returns
Signature size in bytes.

Definition at line 1040 of file crypto_sizes.h.

◆ PSA_EXPORT_KEY_OUTPUT_SIZE

#define PSA_EXPORT_KEY_OUTPUT_SIZE (   key_type,
  key_bits 
)
Value:
(PSA_KEY_TYPE_IS_ECC(key_type) ? PSA_KEY_EXPORT_ECC_KEY_MAX_SIZE(key_type, key_bits) : \
0))
#define PSA_EXPORT_PUBLIC_KEY_OUTPUT_SIZE(key_type, key_bits)
Sufficient output buffer size for psa_export_public_key().
#define PSA_KEY_EXPORT_ECC_KEY_MAX_SIZE(key_type, key_bits)
Maximum size of the export encoding of an ECC keypair.
#define PSA_KEY_TYPE_IS_ECC(type)
Whether a key type is an elliptic curve key, either a key pair or a public key.
#define PSA_KEY_TYPE_IS_PUBLIC_KEY(type)
Whether a key type is the public part of a key pair.

Sufficient output buffer size for psa_export_key().

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

@ref psa_status_t status;
status = @ref psa_get_key_attributes(key, &attributes);
if (status != @ref PSA_SUCCESS)
handle_error(...);
@ref psa_key_type_t key_type = @ref psa_get_key_type(&attributes);
size_t key_bits = @ref psa_get_key_bits(&attributes);
size_t buffer_size = @ref PSA_EXPORT_KEY_OUTPUT_SIZE(key_type, key_bits);
@ref psa_reset_key_attributes(&attributes);
uint8_t *buffer = malloc(buffer_size);
if (buffer == NULL)
handle_error(...);
size_t buffer_length;
status = @ref psa_export_key(key, buffer, buffer_size, &buffer_length);
if (status != @ref PSA_SUCCESS)
handle_error(...);
static size_t psa_get_key_bits(const psa_key_attributes_t *attributes)
Retrieve the key size from key attributes.
Definition crypto.h:1908
psa_status_t psa_export_key(psa_key_id_t key, uint8_t *data, size_t data_size, size_t *data_length)
Export a key in binary format.
psa_status_t psa_get_key_attributes(psa_key_id_t key, psa_key_attributes_t *attributes)
Retrieve the attributes of a key.
static psa_key_type_t psa_get_key_type(const psa_key_attributes_t *attributes)
Retrieve the key type from key attributes.
Definition crypto.h:2006
static void psa_reset_key_attributes(psa_key_attributes_t *attributes)
Reset a key attribute object to a freshly initialized state.
Definition crypto.h:2051
#define PSA_EXPORT_KEY_OUTPUT_SIZE(key_type, key_bits)
Sufficient output buffer size for psa_export_key().
#define PSA_KEY_ATTRIBUTES_INIT
This macro returns a suitable initializer for a key attribute object of type psa_key_attributes_t.
int32_t psa_status_t
Function return status.
uint16_t psa_key_type_t
Encoding of a key type.
#define PSA_SUCCESS
The action was completed successfully.
void * malloc(size_t size)
Allocation a block of memory.
Structure storing key attributes.

See also PSA_EXPORT_KEY_PAIR_MAX_SIZE and PSA_EXPORT_PUBLIC_KEY_MAX_SIZE.

Parameters
key_typeA supported key type.
key_bitsThe size of the key in bits.
Returns
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. 0 if the parameters are a valid combination that is not supported by the implementation. Unspecified if the parameters are not valid.

Definition at line 846 of file crypto_sizes.h.

◆ PSA_EXPORT_KEY_PAIR_MAX_SIZE

#define PSA_EXPORT_KEY_PAIR_MAX_SIZE   0

Sufficient buffer size for exporting any asymmetric key pair.

This value must be a sufficient buffer size when calling psa_export_key() to export any asymmetric key pair that is supported by the implementation, regardless of the exact key type and key size.

See also PSA_EXPORT_KEY_OUTPUT_SIZE().

Definition at line 893 of file crypto_sizes.h.

◆ PSA_EXPORT_PUBLIC_KEY_MAX_SIZE

#define PSA_EXPORT_PUBLIC_KEY_MAX_SIZE   0

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).

Definition at line 1001 of file crypto_sizes.h.

◆ PSA_EXPORT_PUBLIC_KEY_OUTPUT_SIZE

#define PSA_EXPORT_PUBLIC_KEY_OUTPUT_SIZE (   key_type,
  key_bits 
)
Value:
(PSA_KEY_TYPE_IS_ECC(key_type) ? PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(key_type, key_bits) : \
0)
#define PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(key_type, key_bits)
Maximum size of the export encoding of an ECC public key.

Sufficient output buffer size for psa_export_public_key().

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

Warning
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.

@ref psa_status_t status;
status = @ref psa_get_key_attributes(key, &attributes);
if (status != @ref PSA_SUCCESS) handle_error(...);
@ref psa_key_type_t key_type = @ref psa_get_key_type(&attributes);
size_t key_bits = @ref psa_get_key_bits(&attributes);
size_t buffer_size = @ref PSA_EXPORT_PUBLIC_KEY_OUTPUT_SIZE(key_type, key_bits);
@ref psa_reset_key_attributes(&attributes);
uint8_t *buffer = malloc(buffer_size);
if (buffer == NULL) handle_error(...);
size_t buffer_length;
status = @ref psa_export_public_key(key, buffer, buffer_size, &buffer_length);
if (status != @ref PSA_SUCCESS) handle_error(...);
psa_status_t psa_export_public_key(psa_key_id_t key, uint8_t *data, size_t data_size, size_t *data_length)
Export a public key or the public part of a key pair in binary format.
Parameters
key_typeA public key or key pair key type.
key_bitsThe size of the key in bits.
Returns
A buffer size in bytes that guarantees that psa_export_public_key() will not fail with PSA_ERROR_BUFFER_TOO_SMALL. 0 if the parameters are a valid combination that is not supported. Unspecified 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).

Definition at line 976 of file crypto_sizes.h.

◆ PSA_HASH_BLOCK_LENGTH

#define PSA_HASH_BLOCK_LENGTH (   alg)    /* implementation-defined value */

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().

Parameters
algA hash algorithm: a value of type psa_algorithm_t such that PSA_ALG_IS_HASH(alg) is true.
Returns
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.

Definition at line 372 of file crypto_sizes.h.

◆ PSA_HASH_LENGTH

#define PSA_HASH_LENGTH (   alg)
Value:
( \
PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_MD2 ? 16 : \
PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_MD4 ? 16 : \
PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_MD5 ? 16 : \
PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_RIPEMD160 ? 20 : \
PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_1 ? 20 : \
PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_224 ? 28 : \
PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_256 ? 32 : \
PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_384 ? 48 : \
PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_512 ? 64 : \
PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_512_224 ? 28 : \
PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_512_256 ? 32 : \
PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA3_224 ? 28 : \
PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA3_256 ? 32 : \
PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA3_384 ? 48 : \
PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA3_512 ? 64 : \
0)
#define PSA_ALG_SHA3_224
The SHA3-224 message-digest algorithm.
#define PSA_ALG_SHA_224
The SHA-224 message-digest algorithm.
#define PSA_ALG_SHA3_512
The SHA3-512 message-digest algorithm.
#define PSA_ALG_SHA_1
The SHA-1 message-digest algorithm.
#define PSA_ALG_SHA_512_224
The SHA-512/224 message-digest algorithm.
#define PSA_ALG_SHA_384
The SHA-384 message-digest algorithm.
#define PSA_ALG_SHA_512_256
The SHA-512/256 message-digest algorithm.
#define PSA_ALG_SHA_256
The SHA-256 message-digest algorithm.
#define PSA_ALG_RIPEMD160
The RIPEMD-160 message-digest algorithm.
#define PSA_ALG_MD4
The MD4 message-digest algorithm.
#define PSA_ALG_SHA3_256
The SHA3-256 message-digest algorithm.
#define PSA_ALG_MD2
The MD2 message-digest algorithm.
#define PSA_ALG_SHA3_384
The SHA3-384 message-digest algorithm.
#define PSA_ALG_MD5
The MD5 message-digest algorithm.
#define PSA_ALG_SHA_512
The SHA-512 message-digest algorithm.

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

This is also the hash length that psa_hash_compare() and psa_hash_verify() expect.

See also PSA_HASH_MAX_SIZE.

Parameters
algA hash algorithm or an HMAC algorithm: a value of type psa_algorithm_t such that (PSA_ALG_IS_HASH(alg) || PSA_ALG_IS_HMAC(alg)) is true.
Returns
The hash length for the specified hash algorithm. 0 if the hash algorithm is not recognized or not supported.

Definition at line 388 of file crypto_sizes.h.

◆ PSA_HASH_MAX_SIZE

#define PSA_HASH_MAX_SIZE   (64)

Maximum size of a hash supported by this implementation, in bytes.

     See also @ref PSA_HASH_LENGTH().

Definition at line 354 of file crypto_sizes.h.

◆ PSA_HASH_SUSPEND_ALGORITHM_FIELD_LENGTH

#define PSA_HASH_SUSPEND_ALGORITHM_FIELD_LENGTH   ((size_t)4)

The size of the algorithm field that is part of the output of psa_hash_suspend(), in bytes.

Applications can use this value to unpack the hash suspend state that is output by psa_hash_suspend().

Definition at line 654 of file crypto_sizes.h.

◆ PSA_HASH_SUSPEND_HASH_STATE_FIELD_LENGTH

#define PSA_HASH_SUSPEND_HASH_STATE_FIELD_LENGTH (   alg)    /* specification-defined value */

The size of the hash-state field that is part of the output of psa_hash_suspend(), in bytes.

Applications can use this value to unpack the hash suspend state that is output by psa_hash_suspend().

Parameters
algA hash algorithm: a value of type psa_algorithm_t such that PSA_ALG_IS_HASH(alg) is true.
Returns
The size, in bytes, of the hash-state field of the hash suspend state for the specified hash algorithm. 0 if the hash algorithm is not recognized or not supported.

Definition at line 670 of file crypto_sizes.h.

◆ PSA_HASH_SUSPEND_INPUT_LENGTH_FIELD_LENGTH

#define PSA_HASH_SUSPEND_INPUT_LENGTH_FIELD_LENGTH (   alg)    /* specification-defined value */

The size of the input-length field that is part of the output of psa_hash_suspend(), in bytes.

Applications can use this value to unpack the hash suspend state that is output by psa_hash_suspend().

Parameters
algA hash algorithm: a value of type psa_algorithm_t such that PSA_ALG_IS_HASH(alg) is true.
Returns
The size, in bytes, of the input-length field of the hash suspend state for the specified hash algorithm. 0 i f the hash algorithm is not recognized or not supported.

Definition at line 687 of file crypto_sizes.h.

◆ PSA_HASH_SUSPEND_OUTPUT_MAX_SIZE

#define PSA_HASH_SUSPEND_OUTPUT_MAX_SIZE   /* implementation-defined value */

A sufficient hash suspend state buffer size for psa_hash_suspend(), for any supported hash algorithms.

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

See also PSA_HASH_SUSPEND_OUTPUT_SIZE().

Definition at line 699 of file crypto_sizes.h.

◆ PSA_HASH_SUSPEND_OUTPUT_SIZE

#define PSA_HASH_SUSPEND_OUTPUT_SIZE (   alg)    /* specification-defined value */

A sufficient hash suspend state buffer size for psa_hash_suspend(), in bytes.

If the size of the hash state buffer is at least this large, it is guaranteed that psa_hash_suspend() 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_HASH_SUSPEND_OUTPUT_MAX_SIZE.

Parameters
algA hash algorithm: a value of type psa_algorithm_t such that PSA_ALG_IS_HASH(alg) is true.
Returns
A sufficient output size for the algorithm. 0 if the hash algorithm is not recognized, or is not supported by psa_hash_suspend().

For a supported hash algorithm alg, the following expression is true:

#define PSA_HASH_SUSPEND_HASH_STATE_FIELD_LENGTH(alg)
The size of the hash-state field that is part of the output of psa_hash_suspend(),...
#define PSA_HASH_SUSPEND_OUTPUT_SIZE(alg)
A sufficient hash suspend state buffer size for psa_hash_suspend(), in bytes.
#define PSA_HASH_SUSPEND_ALGORITHM_FIELD_LENGTH
The size of the algorithm field that is part of the output of psa_hash_suspend(), in bytes.
#define PSA_HASH_BLOCK_LENGTH(alg)
The input block size of a hash algorithm, in bytes.
#define PSA_HASH_SUSPEND_INPUT_LENGTH_FIELD_LENGTH(alg)
The size of the input-length field that is part of the output of psa_hash_suspend(),...

Definition at line 725 of file crypto_sizes.h.

◆ PSA_KEY_EXPORT_ECC_KEY_MAX_SIZE

#define PSA_KEY_EXPORT_ECC_KEY_MAX_SIZE (   key_type,
  key_bits 
)
Value:
(size_t)\
0))
#define PSA_BITS_TO_BYTES(bits)
Functions to convert bits to bytes.

Maximum size of the export encoding of an ECC keypair.

The representation of an ECC keypair follows https://arm-software.github.io/psa-api/crypto/1.1/api/keys/management.html#key-formats and is dependent on the family:

  • for twisted Edwards curves: 32B
  • for Weierstrass curves: ceiling(m/8)-byte string, big-endian where m is the bit size associated with the curve.

Definition at line 804 of file crypto_sizes.h.

◆ PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE

#define PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE (   key_type,
  key_bits 
)
Value:
((size_t)(2 * PSA_BITS_TO_BYTES(key_bits) + 1)))

Maximum size of the export encoding of an ECC public key.

The representation of an ECC public key is dependent on the family:

  • for twisted Edwards curves: 32B
  • for Weierstrass curves:
    • The byte 0x04;
    • x_P as a ceiling(m/8)-byte string, big-endian;
    • y_P as a ceiling(m/8)-byte string, big-endian;
    • where m is the bit size associated with the curve.
    • 1 byte + 2 * point size.

Definition at line 932 of file crypto_sizes.h.

◆ PSA_MAC_LENGTH

#define PSA_MAC_LENGTH (   key_type,
  key_bits,
  alg 
)
Value:
((void)(key_type), (void)(key_bits), 0))
#define PSA_HASH_LENGTH(alg)
The size of the output of psa_hash_compute() and psa_hash_finish(), in bytes.
#define PSA_ALG_IS_HMAC(alg)
Whether the specified algorithm is an HMAC algorithm.
#define PSA_ALG_IS_BLOCK_CIPHER_MAC(alg)
Whether the specified algorithm is a MAC algorithm based on a block cipher.
#define PSA_ALG_HMAC_GET_HASH(hmac_alg)
Get the hash operation of a hmac algorithm.

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

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

This is also the MAC length that psa_mac_verify() and psa_mac_verify_finish() expect.

See also PSA_MAC_MAX_SIZE.

Parameters
key_typeThe type of the MAC key.
key_bitsThe size of the MAC key in bits.
algA MAC algorithm: a value of type psa_algorithm_t such that PSA_ALG_IS_MAC(alg) is true.
Returns
The MAC length for the specified algorithm with the specified key parameters. 0 if the MAC algorithm is not recognized or not supported. Unspecified if the key parameters are not consistent with the algorithm.

Definition at line 429 of file crypto_sizes.h.

◆ PSA_MAC_MAX_SIZE

#define PSA_MAC_MAX_SIZE   (PSA_HASH_MAX_SIZE)

A sufficient buffer size for storing the MAC output by psa_mac_verify() and psa_mac_verify_finish(), for any of the supported key types and MAC algorithms.

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

See also PSA_MAC_LENGTH().

Definition at line 444 of file crypto_sizes.h.

◆ PSA_MAX_ASYMMETRIC_KEYPAIR_SIZE

#define PSA_MAX_ASYMMETRIC_KEYPAIR_SIZE
Value:
#define PSA_MAX_PRIV_KEY_SIZE
The maximum size of an asymmetric private key.
#define PSA_EXPORT_PUBLIC_KEY_MAX_SIZE
Sufficient buffer size for exporting any asymmetric public key.

The maximum size of an asymmetric private key pair.

Definition at line 1014 of file crypto_sizes.h.

◆ PSA_MAX_KEY_DATA_SIZE

#define PSA_MAX_KEY_DATA_SIZE   (CONFIG_PSA_MAX_KEY_SIZE)

The maximum size of the used key data.

Definition at line 1023 of file crypto_sizes.h.

◆ PSA_MAX_PRIV_KEY_BUFFER_SIZE

#define PSA_MAX_PRIV_KEY_BUFFER_SIZE   (PSA_BITS_TO_BYTES(PSA_MAX_PRIV_KEY_SIZE))

The maximum size of an asymmetric private key buffer.

If only a secure element driver is present, the private key will always be stored in a key slot and PSA Crypto will only allocate memory for an 8 Byte key slot number.

Definition at line 1009 of file crypto_sizes.h.

◆ PSA_MAX_PRIV_KEY_SIZE

#define PSA_MAX_PRIV_KEY_SIZE   (PSA_BYTES_TO_BITS(CONFIG_PSA_MAX_KEY_SIZE))

The maximum size of an asymmetric private key.

Definition at line 871 of file crypto_sizes.h.

◆ PSA_MAX_UNSTRUCTURED_KEY_SIZE

#define PSA_MAX_UNSTRUCTURED_KEY_SIZE   (CONFIG_PSA_MAX_KEY_SIZE)

The maximum size of an unstructured key.

Definition at line 1029 of file crypto_sizes.h.

◆ PSA_SIGN_OUTPUT_SIZE

#define PSA_SIGN_OUTPUT_SIZE (   key_type,
  key_bits,
  alg 
)
Value:
((void)alg, 0))
#define PSA_ECDSA_SIGNATURE_SIZE(curve_bits)
ECDSA signature size for a given curve bit size.
#define PSA_ECC_KEY_GET_CURVE(key_type, key_bits)
Get curve size from ECC key (public or private)

Sufficient signature buffer size for psa_sign_message() and psa_sign_hash().

If the size of the signature buffer is at least this large, it is guaranteed that psa_sign_message() and psa_sign_hash() 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_SIGNATURE_MAX_SIZE.

Parameters
key_typeAn asymmetric key type. This can be a key pair type or a public key type.
key_bitsThe size of the key in bits.
algThe signature algorithm.
Returns
A sufficient signature buffer size for the specified asymmetric signature algorithm and key parameters. 0 if algorithm and key parameters are not supported. If the parameters are not valid, the return value is unspecified.

Definition at line 1061 of file crypto_sizes.h.