Platform Security Architecture — cryptography and keystore interface  Working draft
Macros
crypto_sizes.h File Reference

PSA cryptography module: Mbed TLS buffer size macros. More...

#include "../mbedtls/config.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.

Macros

#define PSA_HASH_MAX_SIZE   64
 
#define PSA_HMAC_MAX_HASH_BLOCK_SIZE   128
 
#define PSA_MAC_MAX_SIZE   PSA_HASH_MAX_SIZE
 
#define PSA_VENDOR_RSA_MAX_KEY_BITS   4096
 
#define PSA_VENDOR_ECC_MAX_CURVE_BITS   521
 
#define PSA_ASYMMETRIC_SIGNATURE_MAX_SIZE
 
#define PSA_MAC_FINAL_SIZE(key_type, key_bits, alg)
 
#define PSA_AEAD_ENCRYPT_OUTPUT_SIZE(alg, plaintext_length)
 
#define PSA_AEAD_DECRYPT_OUTPUT_SIZE(alg, ciphertext_length)
 
#define PSA_ASYMMETRIC_SIGN_OUTPUT_SIZE(key_type, key_bits, alg)
 
#define PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE(key_type, key_bits, alg)
 
#define PSA_ASYMMETRIC_DECRYPT_OUTPUT_SIZE(key_type, key_bits, alg)
 

Detailed Description

PSA cryptography module: Mbed TLS buffer size macros.

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

Macro Definition Documentation

◆ PSA_AEAD_DECRYPT_OUTPUT_SIZE

#define PSA_AEAD_DECRYPT_OUTPUT_SIZE (   alg,
  ciphertext_length 
)
Value:
(PSA_AEAD_TAG_SIZE(alg) != 0 ? \
(plaintext_length) - PSA_AEAD_TAG_SIZE(alg) : \
0)
#define PSA_AEAD_TAG_SIZE(alg)
Definition: crypto.h:2197

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.

Parameters
algAn AEAD algorithm (PSA_ALG_XXX value such that PSA_ALG_IS_AEAD(alg) is true).
ciphertext_lengthSize of the plaintext in bytes.
Returns
The AEAD ciphertext size for the specified algorithm. If the AEAD algorithm is not recognized, return 0. An implementation may return either 0 or a correct size for an AEAD algorithm that it recognizes, but does not support.

◆ PSA_AEAD_ENCRYPT_OUTPUT_SIZE

#define PSA_AEAD_ENCRYPT_OUTPUT_SIZE (   alg,
  plaintext_length 
)
Value:
(PSA_AEAD_TAG_SIZE(alg) != 0 ? \
(plaintext_length) + PSA_AEAD_TAG_SIZE(alg) : \
0)
#define PSA_AEAD_TAG_SIZE(alg)
Definition: crypto.h:2197

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.

Parameters
algAn AEAD algorithm (PSA_ALG_XXX value such that PSA_ALG_IS_AEAD(alg) is true).
plaintext_lengthSize of the plaintext in bytes.
Returns
The AEAD ciphertext size for the specified algorithm. If the AEAD algorithm is not recognized, return 0. An implementation may return either 0 or a correct size for an AEAD algorithm that it recognizes, but does not support.

◆ PSA_ASYMMETRIC_DECRYPT_OUTPUT_SIZE

#define PSA_ASYMMETRIC_DECRYPT_OUTPUT_SIZE (   key_type,
  key_bits,
  alg 
)
Value:
(PSA_KEY_TYPE_IS_RSA(key_type) ? \
PSA_BITS_TO_BYTES(key_bits) - PSA_RSA_MINIMUM_PADDING_SIZE(alg) : \
0)
#define PSA_KEY_TYPE_IS_RSA(type)
Definition: crypto.h:463

Safe output buffer size for psa_asymmetric_decrypt().

This macro returns a safe 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.

Warning
This function may call its arguments multiple times or zero times, so you should not pass arguments that contain side effects.
Parameters
key_typeAn asymmetric key type (this may indifferently be a key pair type or a public key type).
key_bitsThe size of the key in bits.
algThe signature algorithm.
Returns
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 by the implementation, this macro either shall return either a sensible size or 0. If the parameters are not valid, the return value is unspecified.

◆ PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE

#define PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE (   key_type,
  key_bits,
  alg 
)
Value:
(PSA_KEY_TYPE_IS_RSA(key_type) ? \
((void)alg, PSA_BITS_TO_BYTES(key_bits)) : \
0)
#define PSA_KEY_TYPE_IS_RSA(type)
Definition: crypto.h:463

Safe output buffer size for psa_asymmetric_encrypt().

This macro returns a safe 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.

Warning
This function may call its arguments multiple times or zero times, so you should not pass arguments that contain side effects.
Parameters
key_typeAn asymmetric key type (this may indifferently be a key pair type or a public key type).
key_bitsThe size of the key in bits.
algThe signature algorithm.
Returns
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 by the implementation, this macro either shall return either a sensible size or 0. If the parameters are not valid, the return value is unspecified.

◆ PSA_ASYMMETRIC_SIGN_OUTPUT_SIZE

#define PSA_ASYMMETRIC_SIGN_OUTPUT_SIZE (   key_type,
  key_bits,
  alg 
)
Value:
(PSA_KEY_TYPE_IS_RSA(key_type) ? ((void)alg, PSA_BITS_TO_BYTES(key_bits)) : \
((void)alg, 0))
#define PSA_KEY_TYPE_IS_RSA(type)
Definition: crypto.h:463
#define PSA_ECDSA_SIGNATURE_SIZE(curve_bits)
ECDSA signature size for a given curve bit size.
Definition: crypto.h:2322
#define PSA_KEY_TYPE_IS_ECC(type)
Definition: crypto.h:467

Safe signature buffer size for psa_asymmetric_sign().

This macro returns a safe 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).

Warning
This function may call its arguments multiple times or zero times, so you should not pass arguments that contain side effects.
Parameters
key_typeAn asymmetric key type (this may indifferently be a key pair type or a public key type).
key_bitsThe size of the key in bits.
algThe signature algorithm.
Returns
If the parameters are valid and supported, return a buffer size in bytes that guarantees that psa_asymmetric_sign() will not fail with PSA_ERROR_BUFFER_TOO_SMALL. If the parameters are a valid combination that is not supported by the implementation, this macro either shall return either a sensible size or 0. If the parameters are not valid, the return value is unspecified.

◆ PSA_ASYMMETRIC_SIGNATURE_MAX_SIZE

#define PSA_ASYMMETRIC_SIGNATURE_MAX_SIZE
Value:
PSA_BITS_TO_BYTES( \
PSA_VENDOR_RSA_MAX_KEY_BITS > PSA_VENDOR_ECC_MAX_CURVE_BITS ? \
PSA_VENDOR_RSA_MAX_KEY_BITS : \
PSA_VENDOR_ECC_MAX_CURVE_BITS \
)

Maximum size of an asymmetric signature.

This macro must expand to a compile-time constant integer. This value should be the maximum size of a MAC supported by the implementation, in bytes, and must be no smaller than this maximum.

◆ PSA_HASH_MAX_SIZE

#define PSA_HASH_MAX_SIZE   64

Maximum size of a hash.

This macro must expand to a compile-time constant integer. This value should be the maximum size of a hash supported by the implementation, in bytes, and must be no smaller than this maximum.

◆ PSA_MAC_FINAL_SIZE

#define PSA_MAC_FINAL_SIZE (   key_type,
  key_bits,
  alg 
)
Value:
(PSA_ALG_IS_HMAC(alg) ? PSA_HASH_SIZE(PSA_ALG_HMAC_HASH(alg)) : \
PSA_ALG_IS_BLOCK_CIPHER_MAC(alg) ? PSA_BLOCK_CIPHER_BLOCK_SIZE(key_type) : \
0)
#define PSA_BLOCK_CIPHER_BLOCK_SIZE(type)
Definition: crypto.h:544
#define PSA_HASH_SIZE(alg)
Definition: crypto.h:1463
#define PSA_ALG_IS_HMAC(alg)
Definition: crypto.h:721

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

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

Parameters
key_typeThe type of the MAC key.
key_bitsThe size of the MAC key in bits.
algA MAC algorithm (PSA_ALG_XXX value such that PSA_ALG_IS_MAC(alg) is true).
Returns
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_MAC_MAX_SIZE

#define PSA_MAC_MAX_SIZE   PSA_HASH_MAX_SIZE

Maximum size of a MAC.

This macro must expand to a compile-time constant integer. This value should be the maximum size of a MAC supported by the implementation, in bytes, and must be no smaller than this maximum.