mbed TLS v2.23.0: crypto_sizes.h File Reference

mbed TLS v2.23.0

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_BITS_TO_BYTES(bits) (((bits) + 7) / 8)
#define | PSA_BYTES_TO_BITS(bytes) ((bytes) * 8)
#define | PSA_ROUND_UP_TO_MULTIPLE(block_size, length) (((length) + (block_size) - 1) / (block_size) * (block_size))
#define | PSA_HASH_SIZE(alg)
#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_AEAD_TAG_LENGTH(alg)
#define | PSA_VENDOR_RSA_MAX_KEY_BITS 4096
#define | PSA_VENDOR_ECC_MAX_CURVE_BITS 521
#define | PSA_ALG_TLS12_PSK_TO_MS_MAX_PSK_LEN 128
#define | PSA_MAX_BLOCK_CIPHER_BLOCK_SIZE 16
#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_AEAD_UPDATE_OUTPUT_SIZE(alg, input_length)
#define | PSA_AEAD_FINISH_OUTPUT_SIZE(alg)
#define | PSA_AEAD_VERIFY_OUTPUT_SIZE(alg)
#define | PSA_RSA_MINIMUM_PADDING_SIZE(alg)
#define | PSA_ECDSA_SIGNATURE_SIZE(curve_bits) (PSA_BITS_TO_BYTES(curve_bits) * 2)
| ECDSA signature size for a given curve bit size. More...
#define | PSA_SIGN_OUTPUT_SIZE(key_type, key_bits, alg)
#define | PSA_VENDOR_ECDSA_SIGNATURE_MAX_SIZE PSA_ECDSA_SIGNATURE_SIZE(PSA_VENDOR_ECC_MAX_CURVE_BITS)
#define | PSA_SIGNATURE_MAX_SIZE
#define | PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE(key_type, key_bits, alg)
#define | PSA_ASYMMETRIC_DECRYPT_OUTPUT_SIZE(key_type, key_bits, alg)
#define | PSA_KEY_EXPORT_ASN1_INTEGER_MAX_SIZE(bits) ((bits) / 8 + 5)
#define | PSA_KEY_EXPORT_RSA_PUBLIC_KEY_MAX_SIZE(key_bits) (PSA_KEY_EXPORT_ASN1_INTEGER_MAX_SIZE(key_bits) + 11)
#define | PSA_KEY_EXPORT_RSA_KEY_PAIR_MAX_SIZE(key_bits) (9 * PSA_KEY_EXPORT_ASN1_INTEGER_MAX_SIZE((key_bits) / 2 + 1) + 14)
#define | PSA_KEY_EXPORT_DSA_PUBLIC_KEY_MAX_SIZE(key_bits) (PSA_KEY_EXPORT_ASN1_INTEGER_MAX_SIZE(key_bits) * 3 + 59)
#define | PSA_KEY_EXPORT_DSA_KEY_PAIR_MAX_SIZE(key_bits) (PSA_KEY_EXPORT_ASN1_INTEGER_MAX_SIZE(key_bits) * 3 + 75)
#define | PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(key_bits) (2 * PSA_BITS_TO_BYTES(key_bits) + 1)
#define | PSA_KEY_EXPORT_ECC_KEY_PAIR_MAX_SIZE(key_bits) (PSA_BITS_TO_BYTES(key_bits))
#define | PSA_KEY_EXPORT_MAX_SIZE(key_type, key_bits)

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

Definition in file crypto_sizes.h.

## Macro Definition Documentation

## ◆ PSA_AEAD_DECRYPT_OUTPUT_SIZE

#define PSA_AEAD_DECRYPT_OUTPUT_SIZE | ( |  | alg,
|  |  | ciphertext_length
| ) |  |

Value:
(PSA_AEAD_TAG_LENGTH(alg) != 0 ? \
(ciphertext_length) - PSA_AEAD_TAG_LENGTH(alg) : \
0)

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

  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.

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.

Definition at line 279 of file crypto_sizes.h.

## ◆ PSA_AEAD_ENCRYPT_OUTPUT_SIZE

#define PSA_AEAD_ENCRYPT_OUTPUT_SIZE | ( |  | alg,
|  |  | plaintext_length
| ) |  |

Value:
(PSA_AEAD_TAG_LENGTH(alg) != 0 ? \
(plaintext_length) + PSA_AEAD_TAG_LENGTH(alg) : \
0)

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

  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.

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.

Definition at line 255 of file crypto_sizes.h.

## ◆ PSA_AEAD_FINISH_OUTPUT_SIZE

#define PSA_AEAD_FINISH_OUTPUT_SIZE | ( |  | alg | ) |

Value:
(PSA_ALG_IS_AEAD_ON_BLOCK_CIPHER(alg) ? \
PSA_MAX_BLOCK_CIPHER_BLOCK_SIZE : \
0)

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.

Parameters

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

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

Definition at line 330 of file crypto_sizes.h.

## ◆ PSA_AEAD_TAG_LENGTH

#define PSA_AEAD_TAG_LENGTH | ( |  | alg | ) |

Value:
(PSA_ALG_IS_AEAD(alg) ? \
(((alg) & PSA_ALG_AEAD_TAG_LENGTH_MASK) >> PSA_AEAD_TAG_LENGTH_OFFSET) : \
0)

The tag size for an AEAD algorithm, in bytes.

Parameters

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

Returns
  The tag size for the specified algorithm. If the AEAD algorithm does not have an identified tag that can be distinguished from the rest of the ciphertext, return 0. 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.

Definition at line 142 of file crypto_sizes.h.

## ◆ PSA_AEAD_UPDATE_OUTPUT_SIZE

#define PSA_AEAD_UPDATE_OUTPUT_SIZE | ( |  | alg,
|  |  | input_length
| ) |  |

Value:
(PSA_ALG_IS_AEAD_ON_BLOCK_CIPHER(alg) ? \
PSA_ROUND_UP_TO_MULTIPLE(PSA_MAX_BLOCK_CIPHER_BLOCK_SIZE, (input_length)) : \
(input_length))

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.

Parameters

  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.

Returns
  A sufficient output buffer 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.

Definition at line 307 of file crypto_sizes.h.

## ◆ PSA_AEAD_VERIFY_OUTPUT_SIZE

#define PSA_AEAD_VERIFY_OUTPUT_SIZE | ( |  | alg | ) |

Value:
(PSA_ALG_IS_AEAD_ON_BLOCK_CIPHER(alg) ? \
PSA_MAX_BLOCK_CIPHER_BLOCK_SIZE : \
0)

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.

Parameters

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

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

Definition at line 353 of file crypto_sizes.h.

## ◆ PSA_ALG_TLS12_PSK_TO_MS_MAX_PSK_LEN

#define PSA_ALG_TLS12_PSK_TO_MS_MAX_PSK_LEN 128

This macro returns the maximum length of the PSK supported by the TLS-1.2 PSK-to-MS key derivation.

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

Definition at line 208 of file crypto_sizes.h.

## ◆ 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)

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.

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

Parameters

  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.

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 shall return either a sensible size or 0. If the parameters are not valid, the return value is unspecified.

Definition at line 478 of file crypto_sizes.h.

## ◆ 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)

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.

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

Parameters

  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.

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 shall return either a sensible size or 0. If the parameters are not valid, the return value is unspecified.

Definition at line 447 of file crypto_sizes.h.

## ◆ PSA_BITS_TO_BYTES

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

Definition at line 54 of file crypto_sizes.h.

## ◆ PSA_BYTES_TO_BITS

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

Definition at line 55 of file crypto_sizes.h.

## ◆ PSA_ECDSA_SIGNATURE_SIZE

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

ECDSA signature size for a given curve bit size.

Parameters

  curve_bits | Curve size in bits.

Returns
  Signature size in bytes.

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

Definition at line 371 of file crypto_sizes.h.

## ◆ 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.

Definition at line 105 of file crypto_sizes.h.

## ◆ PSA_HASH_SIZE

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

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

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

Parameters

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

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

Definition at line 74 of file crypto_sizes.h.

## ◆ PSA_HMAC_MAX_HASH_BLOCK_SIZE

#define PSA_HMAC_MAX_HASH_BLOCK_SIZE 128

Definition at line 106 of file crypto_sizes.h.

## ◆ PSA_KEY_EXPORT_ASN1_INTEGER_MAX_SIZE

#define PSA_KEY_EXPORT_ASN1_INTEGER_MAX_SIZE | ( |  | bits | ) | ((bits) / 8 + 5)

Definition at line 493 of file crypto_sizes.h.

## ◆ PSA_KEY_EXPORT_DSA_KEY_PAIR_MAX_SIZE

#define PSA_KEY_EXPORT_DSA_KEY_PAIR_MAX_SIZE | ( |  | key_bits | ) | (PSA_KEY_EXPORT_ASN1_INTEGER_MAX_SIZE(key_bits) * 3 + 75)

Definition at line 570 of file crypto_sizes.h.

## ◆ PSA_KEY_EXPORT_DSA_PUBLIC_KEY_MAX_SIZE

#define PSA_KEY_EXPORT_DSA_PUBLIC_KEY_MAX_SIZE | ( |  | key_bits | ) | (PSA_KEY_EXPORT_ASN1_INTEGER_MAX_SIZE(key_bits) * 3 + 59)

Definition at line 551 of file crypto_sizes.h.

## ◆ PSA_KEY_EXPORT_ECC_KEY_PAIR_MAX_SIZE

#define PSA_KEY_EXPORT_ECC_KEY_PAIR_MAX_SIZE | ( |  | key_bits | ) | (PSA_BITS_TO_BYTES(key_bits))

Definition at line 590 of file crypto_sizes.h.

## ◆ PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE

#define PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE | ( |  | key_bits | ) | (2 * PSA_BITS_TO_BYTES(key_bits) + 1)

Definition at line 583 of file crypto_sizes.h.

## ◆ PSA_KEY_EXPORT_MAX_SIZE

#define PSA_KEY_EXPORT_MAX_SIZE | ( |  | key_type,
|  |  | key_bits
| ) |  |

Value:
(PSA_KEY_TYPE_IS_UNSTRUCTURED(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) : \
0)

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.

Warning
  This function may call 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_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_status_t status;
status = psa_get_key_attributes(key, &attributes);
if (status != PSA_SUCCESS) handle_error(...);
psa_key_type_t key_type = psa_get_key_type(&attributes);
size_t key_bits = psa_get_key_bits(&attributes);
size_t buffer_size = PSA_KEY_EXPORT_MAX_SIZE(key_type, key_bits);
psa_reset_key_attributes(&attributes);
uint8_t *buffer = malloc(buffer_size);
if (buffer == NULL) handle_error(...);
size_t buffer_length;
status = psa_export_key(key, buffer, buffer_size, &buffer_length);
if (status != PSA_SUCCESS) handle_error(...);

For psa_export_public_key(), calculate the buffer size from the public key type. You can use the macro PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR to convert a key pair type to the corresponding public key type.

psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_status_t status;
status = psa_get_key_attributes(key, &attributes);
if (status != PSA_SUCCESS) handle_error(...);
psa_key_type_t key_type = psa_get_key_type(&attributes);
psa_key_type_t public_key_type = PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(key_type);
size_t key_bits = psa_get_key_bits(&attributes);
size_t buffer_size = PSA_KEY_EXPORT_MAX_SIZE(public_key_type, key_bits);
psa_reset_key_attributes(&attributes);
uint8_t *buffer = malloc(buffer_size);
if (buffer == NULL) handle_error(...);
size_t buffer_length;
status = psa_export_public_key(key, buffer, buffer_size, &buffer_length);
if (status != PSA_SUCCESS) handle_error(...);

Parameters

  key_type | A supported key type.
  key_bits | The size of the key in bits.

Returns
  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 by the implementation, this macro shall return either a sensible size or 0. If the parameters are not valid, the return value is unspecified.

Definition at line 653 of file crypto_sizes.h.

## ◆ PSA_KEY_EXPORT_RSA_KEY_PAIR_MAX_SIZE

#define PSA_KEY_EXPORT_RSA_KEY_PAIR_MAX_SIZE | ( |  | key_bits | ) | (9 * PSA_KEY_EXPORT_ASN1_INTEGER_MAX_SIZE((key_bits) / 2 + 1) + 14)

Definition at line 532 of file crypto_sizes.h.

## ◆ PSA_KEY_EXPORT_RSA_PUBLIC_KEY_MAX_SIZE

#define PSA_KEY_EXPORT_RSA_PUBLIC_KEY_MAX_SIZE | ( |  | key_bits | ) | (PSA_KEY_EXPORT_ASN1_INTEGER_MAX_SIZE(key_bits) + 11)

Definition at line 507 of file crypto_sizes.h.

## ◆ PSA_MAC_FINAL_SIZE

#define PSA_MAC_FINAL_SIZE | ( |  | key_type,
|  |  | key_bits,
|  |  | alg
| ) |  |

Value:
((alg) & PSA_ALG_MAC_TRUNCATION_MASK ? PSA_MAC_TRUNCATED_LENGTH(alg) : \
PSA_ALG_IS_HMAC(alg) ? PSA_HASH_SIZE(PSA_ALG_HMAC_GET_HASH(alg)) : \
PSA_ALG_IS_BLOCK_CIPHER_MAC(alg) ? PSA_BLOCK_CIPHER_BLOCK_SIZE(key_type) : \
((void)(key_type), (void)(key_bits), 0))

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

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.

Definition at line 230 of file crypto_sizes.h.

## ◆ 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.

Definition at line 125 of file crypto_sizes.h.

## ◆ PSA_MAX_BLOCK_CIPHER_BLOCK_SIZE

#define PSA_MAX_BLOCK_CIPHER_BLOCK_SIZE 16

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

Definition at line 211 of file crypto_sizes.h.

## ◆ PSA_ROUND_UP_TO_MULTIPLE

#define PSA_ROUND_UP_TO_MULTIPLE | ( |  | block_size,
|  |  | length
| ) |  | (((length) + (block_size) - 1) / (block_size) * (block_size))

Definition at line 57 of file crypto_sizes.h.

## ◆ PSA_RSA_MINIMUM_PADDING_SIZE

#define PSA_RSA_MINIMUM_PADDING_SIZE | ( |  | alg | ) |

Value:
(PSA_ALG_IS_RSA_OAEP(alg) ? \
2 * PSA_HASH_SIZE(PSA_ALG_RSA_OAEP_GET_HASH(alg)) + 1 : \
11 /*PKCS#1v1.5*/)

Definition at line 358 of file crypto_sizes.h.

## ◆ PSA_SIGN_OUTPUT_SIZE

#define PSA_SIGN_OUTPUT_SIZE | ( |  | key_type,
|  |  | key_bits,
|  |  | alg
| ) |  |

Value:
(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, 0))

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

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

Parameters

  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.

Returns
  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 by the implementation, this macro shall return either a sensible size or 0. If the parameters are not valid, the return value is unspecified.

Definition at line 400 of file crypto_sizes.h.

## ◆ PSA_SIGNATURE_MAX_SIZE

#define PSA_SIGNATURE_MAX_SIZE

Value:
(PSA_BITS_TO_BYTES(PSA_VENDOR_RSA_MAX_KEY_BITS) > PSA_VENDOR_ECDSA_SIGNATURE_MAX_SIZE ? \
PSA_BITS_TO_BYTES(PSA_VENDOR_RSA_MAX_KEY_BITS) : \
PSA_VENDOR_ECDSA_SIGNATURE_MAX_SIZE)

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 signature supported by the implementation, in bytes, and must be no smaller than this maximum.

Definition at line 416 of file crypto_sizes.h.

## ◆ PSA_VENDOR_ECC_MAX_CURVE_BITS

#define PSA_VENDOR_ECC_MAX_CURVE_BITS 521

Definition at line 165 of file crypto_sizes.h.

## ◆ PSA_VENDOR_ECDSA_SIGNATURE_MAX_SIZE

#define PSA_VENDOR_ECDSA_SIGNATURE_MAX_SIZE PSA_ECDSA_SIGNATURE_SIZE(PSA_VENDOR_ECC_MAX_CURVE_BITS)

Definition at line 405 of file crypto_sizes.h.

## ◆ PSA_VENDOR_RSA_MAX_KEY_BITS

#define PSA_VENDOR_RSA_MAX_KEY_BITS 4096

Definition at line 160 of file crypto_sizes.h.

PSA_KEY_ATTRIBUTES_INIT
#define PSA_KEY_ATTRIBUTES_INIT
Definition: crypto_struct.h:355
psa_status_t
int32_t psa_status_t
Function return status.
Definition: crypto_types.h:55
PSA_KEY_EXPORT_ECC_KEY_PAIR_MAX_SIZE
#define PSA_KEY_EXPORT_ECC_KEY_PAIR_MAX_SIZE(key_bits)
Definition: crypto_sizes.h:589
PSA_ALG_SHA3_384
#define PSA_ALG_SHA3_384
Definition: crypto_values.h:749
PSA_ALG_SHA3_224
#define PSA_ALG_SHA3_224
Definition: crypto_values.h:745
PSA_HASH_SIZE
#define PSA_HASH_SIZE(alg)
Definition: crypto_sizes.h:73
psa_key_attributes_s
Definition: crypto_struct.h:343
psa_export_public_key
psa_status_t psa_export_public_key(psa_key_handle_t handle, 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.
PSA_VENDOR_RSA_MAX_KEY_BITS
#define PSA_VENDOR_RSA_MAX_KEY_BITS
Definition: crypto_sizes.h:159
PSA_SUCCESS
#define PSA_SUCCESS
Definition: crypto_values.h:46
PSA_ALG_IS_BLOCK_CIPHER_MAC
#define PSA_ALG_IS_BLOCK_CIPHER_MAC(alg)
Definition: crypto_values.h:915
PSA_ALG_SHA_224
#define PSA_ALG_SHA_224
Definition: crypto_values.h:733
PSA_ALG_AEAD_TAG_LENGTH_MASK
#define PSA_ALG_AEAD_TAG_LENGTH_MASK
Definition: crypto_values.h:1042
PSA_MAX_BLOCK_CIPHER_BLOCK_SIZE
#define PSA_MAX_BLOCK_CIPHER_BLOCK_SIZE
Definition: crypto_sizes.h:210
PSA_KEY_TYPE_DSA_KEY_PAIR
#define PSA_KEY_TYPE_DSA_KEY_PAIR
Definition: crypto_extra.h:350
PSA_ALG_SHA_384
#define PSA_ALG_SHA_384
Definition: crypto_values.h:737
PSA_KEY_EXPORT_MAX_SIZE
#define PSA_KEY_EXPORT_MAX_SIZE(key_type, key_bits)
Definition: crypto_sizes.h:652
PSA_ALG_RIPEMD160
#define PSA_ALG_RIPEMD160
Definition: crypto_values.h:729
PSA_VENDOR_ECDSA_SIGNATURE_MAX_SIZE
#define PSA_VENDOR_ECDSA_SIGNATURE_MAX_SIZE
Definition: crypto_sizes.h:404
psa_get_key_attributes
psa_status_t psa_get_key_attributes(psa_key_handle_t handle, psa_key_attributes_t *attributes)
PSA_KEY_EXPORT_RSA_KEY_PAIR_MAX_SIZE
#define PSA_KEY_EXPORT_RSA_KEY_PAIR_MAX_SIZE(key_bits)
Definition: crypto_sizes.h:531
PSA_KEY_TYPE_IS_UNSTRUCTURED
#define PSA_KEY_TYPE_IS_UNSTRUCTURED(type)
Definition: crypto_values.h:315
PSA_KEY_TYPE_IS_RSA
#define PSA_KEY_TYPE_IS_RSA(type)
Definition: crypto_values.h:421
PSA_ALG_SHA3_512
#define PSA_ALG_SHA3_512
Definition: crypto_values.h:751
PSA_AEAD_TAG_LENGTH
#define PSA_AEAD_TAG_LENGTH(alg)
Definition: crypto_sizes.h:141
PSA_KEY_TYPE_RSA_KEY_PAIR
#define PSA_KEY_TYPE_RSA_KEY_PAIR
Definition: crypto_values.h:419
PSA_RSA_MINIMUM_PADDING_SIZE
#define PSA_RSA_MINIMUM_PADDING_SIZE(alg)
Definition: crypto_sizes.h:357
PSA_AEAD_TAG_LENGTH_OFFSET
#define PSA_AEAD_TAG_LENGTH_OFFSET
Definition: crypto_values.h:1043
PSA_ALG_SHA_512
#define PSA_ALG_SHA_512
Definition: crypto_values.h:739
PSA_KEY_TYPE_IS_ECC_KEY_PAIR
#define PSA_KEY_TYPE_IS_ECC_KEY_PAIR(type)
Definition: crypto_values.h:447
PSA_ALG_MD4
#define PSA_ALG_MD4
Definition: crypto_values.h:725
PSA_ALG_MAC_TRUNCATION_MASK
#define PSA_ALG_MAC_TRUNCATION_MASK
Definition: crypto_values.h:828
PSA_ALG_SHA_256
#define PSA_ALG_SHA_256
Definition: crypto_values.h:735
PSA_KEY_EXPORT_DSA_KEY_PAIR_MAX_SIZE
#define PSA_KEY_EXPORT_DSA_KEY_PAIR_MAX_SIZE(key_bits)
Definition: crypto_sizes.h:569
PSA_ALG_SHA_512_224
#define PSA_ALG_SHA_512_224
Definition: crypto_values.h:741
PSA_ALG_HMAC_GET_HASH
#define PSA_ALG_HMAC_GET_HASH(hmac_alg)
Definition: crypto_values.h:804
PSA_ALG_RSA_OAEP_GET_HASH
#define PSA_ALG_RSA_OAEP_GET_HASH(alg)
Definition: crypto_values.h:1272
PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE
#define PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(key_bits)
Definition: crypto_sizes.h:582
PSA_MAC_TRUNCATED_LENGTH
#define PSA_MAC_TRUNCATED_LENGTH(mac_alg)
Definition: crypto_values.h:894
PSA_ALG_IS_AEAD_ON_BLOCK_CIPHER
#define PSA_ALG_IS_AEAD_ON_BLOCK_CIPHER(alg)
Definition: crypto_values.h:1011
PSA_KEY_TYPE_RSA_PUBLIC_KEY
#define PSA_KEY_TYPE_RSA_PUBLIC_KEY
Definition: crypto_values.h:417
psa_key_type_t
uint16_t psa_key_type_t
Encoding of a key type.
Definition: crypto_types.h:66
psa_get_key_bits
static size_t psa_get_key_bits(const psa_key_attributes_t *attributes)
PSA_ECDSA_SIGNATURE_SIZE
#define PSA_ECDSA_SIGNATURE_SIZE(curve_bits)
ECDSA signature size for a given curve bit size.
Definition: crypto_sizes.h:370
PSA_BITS_TO_BYTES
#define PSA_BITS_TO_BYTES(bits)
Definition: crypto_sizes.h:53
PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY
#define PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY(type)
Definition: crypto_values.h:451
PSA_ALG_IS_AEAD
#define PSA_ALG_IS_AEAD(alg)
Definition: crypto_values.h:672
psa_get_key_type
static psa_key_type_t psa_get_key_type(const psa_key_attributes_t *attributes)
PSA_KEY_EXPORT_RSA_PUBLIC_KEY_MAX_SIZE
#define PSA_KEY_EXPORT_RSA_PUBLIC_KEY_MAX_SIZE(key_bits)
Definition: crypto_sizes.h:506
PSA_ALG_SHA_512_256
#define PSA_ALG_SHA_512_256
Definition: crypto_values.h:743
PSA_BLOCK_CIPHER_BLOCK_SIZE
#define PSA_BLOCK_CIPHER_BLOCK_SIZE(type)
Definition: crypto_values.h:599
PSA_ALG_MD2
#define PSA_ALG_MD2
Definition: crypto_values.h:723
PSA_ALG_IS_RSA_OAEP
#define PSA_ALG_IS_RSA_OAEP(alg)
Definition: crypto_values.h:1270
PSA_KEY_TYPE_IS_ECC
#define PSA_KEY_TYPE_IS_ECC(type)
Definition: crypto_values.h:443
PSA_KEY_EXPORT_DSA_PUBLIC_KEY_MAX_SIZE
#define PSA_KEY_EXPORT_DSA_PUBLIC_KEY_MAX_SIZE(key_bits)
Definition: crypto_sizes.h:550
PSA_KEY_TYPE_DSA_PUBLIC_KEY
#define PSA_KEY_TYPE_DSA_PUBLIC_KEY
Definition: crypto_extra.h:332
PSA_ALG_SHA_1
#define PSA_ALG_SHA_1
Definition: crypto_values.h:731
PSA_ALG_MD5
#define PSA_ALG_MD5
Definition: crypto_values.h:727
PSA_ALG_SHA3_256
#define PSA_ALG_SHA3_256
Definition: crypto_values.h:747
psa_reset_key_attributes
void psa_reset_key_attributes(psa_key_attributes_t *attributes)
PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR
#define PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(type)
Definition: crypto_values.h:353
psa_export_key
psa_status_t psa_export_key(psa_key_handle_t handle, uint8_t *data, size_t data_size, size_t *data_length)
Export a key in binary format.