25#ifndef PSA_CRYPTO_PSA_CRYPTO_SIZES_H
26#define PSA_CRYPTO_PSA_CRYPTO_SIZES_H
42#define PSA_BITS_TO_BYTES(bits) (size_t)(((bits) + 7) / 8)
51#define PSA_BYTES_TO_BITS(bytes) ((bytes) * 8)
60#if (IS_USED(MODULE_PSA_MAC_HMAC_SHA_256))
61#define CONFIG_PSA_MAX_KEY_SIZE 64
62#elif (IS_USED(MODULE_PSA_ASYMMETRIC_ECC_P256R1) || \
63 IS_USED(MODULE_PSA_ASYMMETRIC_ECC_ED25519) || \
64 IS_USED(MODULE_PSA_CIPHER_AES_256_CBC) || \
65 IS_USED(MODULE_PSA_SECURE_ELEMENT_ATECCX08A_ECC_P256) || \
66 IS_USED(MODULE_PSA_CIPHER_CHACHA20))
67#define CONFIG_PSA_MAX_KEY_SIZE 32
68#elif (IS_USED(MODULE_PSA_CIPHER_AES_192_CBC) || \
69 IS_USED(MODULE_PSA_ASYMMETRIC_ECC_P192R1))
70#define CONFIG_PSA_MAX_KEY_SIZE 24
71#elif (IS_USED(MODULE_PSA_CIPHER_AES_128_CBC)) || \
72 (IS_USED(MODULE_PSA_CIPHER_AES_128_ECB))
73#define CONFIG_PSA_MAX_KEY_SIZE 16
75#define CONFIG_PSA_MAX_KEY_SIZE 0
84#ifndef CONFIG_PSA_ASYMMETRIC_KEYPAIR_COUNT
85#define CONFIG_PSA_ASYMMETRIC_KEYPAIR_COUNT 0
94#ifndef CONFIG_PSA_SINGLE_KEY_COUNT
95#define CONFIG_PSA_SINGLE_KEY_COUNT 0
104#ifndef CONFIG_PSA_PROTECTED_KEY_COUNT
105#if (IS_USED(MODULE_PSA_SECURE_ELEMENT))
106#define CONFIG_PSA_PROTECTED_KEY_COUNT 5
108#define CONFIG_PSA_PROTECTED_KEY_COUNT 0
124#define PSA_AEAD_DECRYPT_OUTPUT_MAX_SIZE(ciphertext_length) \
124#define PSA_AEAD_DECRYPT_OUTPUT_MAX_SIZE(ciphertext_length) \ …
145#define PSA_AEAD_DECRYPT_OUTPUT_SIZE(key_type, alg, ciphertext_length) \
145#define PSA_AEAD_DECRYPT_OUTPUT_SIZE(key_type, alg, ciphertext_length) \ …
160#define PSA_AEAD_ENCRYPT_OUTPUT_MAX_SIZE(plaintext_length) \
160#define PSA_AEAD_ENCRYPT_OUTPUT_MAX_SIZE(plaintext_length) \ …
181#define PSA_AEAD_ENCRYPT_OUTPUT_SIZE(key_type, alg, plaintext_length) \
181#define PSA_AEAD_ENCRYPT_OUTPUT_SIZE(key_type, alg, plaintext_length) \ …
193#define PSA_AEAD_FINISH_OUTPUT_MAX_SIZE
213#define PSA_AEAD_FINISH_OUTPUT_SIZE(key_type, alg) \
213#define PSA_AEAD_FINISH_OUTPUT_SIZE(key_type, alg) \ …
235#define PSA_AEAD_NONCE_LENGTH(key_type, alg)
246#define PSA_AEAD_NONCE_MAX_SIZE
267#define PSA_AEAD_TAG_LENGTH(key_type, key_bits, alg) \
267#define PSA_AEAD_TAG_LENGTH(key_type, key_bits, alg) \ …
279#define PSA_AEAD_TAG_MAX_SIZE
292#define PSA_AEAD_UPDATE_OUTPUT_MAX_SIZE(input_length) \
292#define PSA_AEAD_UPDATE_OUTPUT_MAX_SIZE(input_length) \ …
313#define PSA_AEAD_UPDATE_OUTPUT_SIZE(key_type, alg, input_length) \
313#define PSA_AEAD_UPDATE_OUTPUT_SIZE(key_type, alg, input_length) \ …
327#define PSA_AEAD_VERIFY_OUTPUT_MAX_SIZE
346#define PSA_AEAD_VERIFY_OUTPUT_SIZE(key_type, alg) \
346#define PSA_AEAD_VERIFY_OUTPUT_SIZE(key_type, alg) \ …
354#define PSA_HASH_MAX_SIZE (64)
361#if (IS_USED(MODULE_PSA_HASH_SHA3_256))
362#define PSA_HASH_MAX_BLOCK_SIZE 136
363#elif (IS_USED(MODULE_PSA_HASH_SHA_512) || \
364 IS_USED(MODULE_PSA_HASH_SHA_384) || \
365 IS_USED(MODULE_PSA_HASH_SHA_512_224) || \
366 IS_USED(MODULE_PSA_HASH_SHA_512_256))
367#define PSA_HASH_MAX_BLOCK_SIZE 128
368#elif (IS_USED(MODULE_PSA_HASH_SHA3_384))
369#define PSA_HASH_MAX_BLOCK_SIZE 104
370#elif (IS_USED(MODULE_PSA_HASH_SHA3_512))
371#define PSA_HASH_MAX_BLOCK_SIZE 72
372#elif (IS_USED(MODULE_PSA_HASH_MD5) || \
373 IS_USED(MODULE_PSA_HASH_SHA_1) || \
374 IS_USED(MODULE_PSA_HASH_SHA_224) || \
375 IS_USED(MODULE_PSA_HASH_SHA_256))
376#define PSA_HASH_MAX_BLOCK_SIZE 64
378#define PSA_HASH_MAX_BLOCK_SIZE 0
397#define PSA_HASH_BLOCK_LENGTH(alg) \
399 PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_MD2 ? 16 : \
400 PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_MD4 ? 64 : \
401 PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_MD5 ? 64 : \
402 PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_RIPEMD160 ? 64 : \
403 PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_1 ? 64 : \
404 PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_224 ? 64 : \
405 PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_256 ? 64 : \
406 PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_384 ? 128 : \
407 PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_512 ? 128 : \
408 PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_512_224 ? 128 : \
409 PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_512_256 ? 128 : \
410 PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA3_224 ? 144 : \
411 PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA3_256 ? 136 : \
412 PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA3_384 ? 104 : \
413 PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA3_512 ? 72 : \
397#define PSA_HASH_BLOCK_LENGTH(alg) \ …
430#define PSA_HASH_LENGTH(alg) \
432 PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_MD2 ? 16 : \
433 PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_MD4 ? 16 : \
434 PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_MD5 ? 16 : \
435 PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_RIPEMD160 ? 20 : \
436 PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_1 ? 20 : \
437 PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_224 ? 28 : \
438 PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_256 ? 32 : \
439 PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_384 ? 48 : \
440 PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_512 ? 64 : \
441 PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_512_224 ? 28 : \
442 PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_512_256 ? 32 : \
443 PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA3_224 ? 28 : \
444 PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA3_256 ? 32 : \
445 PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA3_384 ? 48 : \
446 PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA3_512 ? 64 : \
430#define PSA_HASH_LENGTH(alg) \ …
471#define PSA_MAC_LENGTH(key_type, key_bits, alg) \
472 ((PSA_ALG_IS_HMAC(alg)) ? PSA_HASH_LENGTH(PSA_ALG_HMAC_GET_HASH(alg)) : \
473 PSA_ALG_IS_BLOCK_CIPHER_MAC(alg) ? PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type) : \
474 ((void)(key_type), (void)(key_bits), 0))
471#define PSA_MAC_LENGTH(key_type, key_bits, alg) \ …
486#if (IS_USED(MODULE_PSA_MAC_HMAC_SHA_512) || \
487 IS_USED(MODULE_PSA_MAC_HMAC_SHA3_512))
488#define PSA_MAC_MAX_SIZE (PSA_HASH_LENGTH(PSA_ALG_SHA3_512))
489#elif (IS_USED(MODULE_PSA_MAC_HMAC_SHA_384) || \
490 IS_USED(MODULE_PSA_MAC_HMAC_SHA3_384))
491#define PSA_MAC_MAX_SIZE (PSA_HASH_LENGTH(PSA_ALG_SHA3_384))
492#elif (IS_USED(MODULE_PSA_MAC_HMAC_SHA_256) || \
493 IS_USED(MODULE_PSA_MAC_HMAC_SHA_512_256) || \
494 IS_USED(MODULE_PSA_MAC_HMAC_SHA3_256))
495#define PSA_MAC_MAX_SIZE (PSA_HASH_LENGTH(PSA_ALG_SHA3_256))
496#elif (IS_USED(MODULE_PSA_MAC_HMAC_SHA_224) || \
497 IS_USED(MODULE_PSA_MAC_HMAC_SHA_512_224) || \
498 IS_USED(MODULE_PSA_MAC_HMAC_SHA3_224))
499#define PSA_MAC_MAX_SIZE (PSA_HASH_LENGTH(PSA_ALG_SHA3_224))
500#elif (IS_USED(MODULE_PSA_MAC_HMAC_RIPEMD160) || \
501 IS_USED(MODULE_PSA_MAC_HMAC_SHA_1))
502#define PSA_MAC_MAX_SIZE (PSA_HASH_LENGTH(PSA_ALG_SHA_1))
503#elif (IS_USED(MODULE_PSA_MAC_HMAC_MD2) || \
504 IS_USED(MODULE_PSA_MAC_HMAC_MD4) || \
505 IS_USED(MODULE_PSA_MAC_HMAC_MD5))
506#define PSA_MAC_MAX_SIZE (PSA_HASH_LENGTH(PSA_ALG_MD5))
508#define PSA_MAC_MAX_SIZE 0
523#define PSA_BLOCK_CIPHER_BLOCK_LENGTH(type) \
524 (1u << (((type) >> 8) & 7))
523#define PSA_BLOCK_CIPHER_BLOCK_LENGTH(type) \ …
531#define PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE
544#define PSA_CIPHER_DECRYPT_OUTPUT_MAX_SIZE(input_length) \
544#define PSA_CIPHER_DECRYPT_OUTPUT_MAX_SIZE(input_length) \ …
565#define PSA_CIPHER_DECRYPT_OUTPUT_SIZE(key_type, alg, input_length) \
566 (input_length - PSA_CIPHER_IV_LENGTH(key_type, alg))
565#define PSA_CIPHER_DECRYPT_OUTPUT_SIZE(key_type, alg, input_length) \ …
579#define PSA_CIPHER_ENCRYPT_OUTPUT_MAX_SIZE(input_length) \
580 (PSA_CIPHER_ENCRYPT_OUTPUT_SIZE(PSA_KEY_TYPE_AES, PSA_ALG_CBC_NO_PADDING, input_length))
579#define PSA_CIPHER_ENCRYPT_OUTPUT_MAX_SIZE(input_length) \ …
600#define PSA_CIPHER_ENCRYPT_OUTPUT_SIZE(key_type, alg, input_length) \
601 (input_length + PSA_CIPHER_IV_LENGTH(key_type, alg))
600#define PSA_CIPHER_ENCRYPT_OUTPUT_SIZE(key_type, alg, input_length) \ …
612#define PSA_CIPHER_FINISH_OUTPUT_MAX_SIZE
631#define PSA_CIPHER_FINISH_OUTPUT_SIZE(key_type, alg) \
631#define PSA_CIPHER_FINISH_OUTPUT_SIZE(key_type, alg) \ …
660#define PSA_CIPHER_IV_LENGTH(key_type, alg) \
661 ((PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type) > 1 && \
662 ((alg) == PSA_ALG_CBC_NO_PADDING)) ? 16 : \
663 (key_type == PSA_KEY_TYPE_CHACHA20) ? 12 : 0)
660#define PSA_CIPHER_IV_LENGTH(key_type, alg) \ …
674#define PSA_CIPHER_IV_MAX_SIZE
688#define PSA_CIPHER_UPDATE_OUTPUT_MAX_SIZE(input_length) \
688#define PSA_CIPHER_UPDATE_OUTPUT_MAX_SIZE(input_length) \ …
710#define PSA_CIPHER_UPDATE_OUTPUT_SIZE(key_type, alg, input_length) \
710#define PSA_CIPHER_UPDATE_OUTPUT_SIZE(key_type, alg, input_length) \ …
720#define PSA_HASH_SUSPEND_ALGORITHM_FIELD_LENGTH ((size_t)4)
736#define PSA_HASH_SUSPEND_HASH_STATE_FIELD_LENGTH(alg) \
736#define PSA_HASH_SUSPEND_HASH_STATE_FIELD_LENGTH(alg) \ …
753#define PSA_HASH_SUSPEND_INPUT_LENGTH_FIELD_LENGTH(alg) \
753#define PSA_HASH_SUSPEND_INPUT_LENGTH_FIELD_LENGTH(alg) \ …
765#define PSA_HASH_SUSPEND_OUTPUT_MAX_SIZE
791#define PSA_HASH_SUSPEND_OUTPUT_SIZE(alg)
802#define PSA_ASYMMETRIC_DECRYPT_OUTPUT_MAX_SIZE \
802#define PSA_ASYMMETRIC_DECRYPT_OUTPUT_MAX_SIZE \ …
824#define PSA_ASYMMETRIC_DECRYPT_OUTPUT_SIZE(key_type, key_bits, alg) \
824#define PSA_ASYMMETRIC_DECRYPT_OUTPUT_SIZE(key_type, key_bits, alg) \ …
836#define PSA_ASYMMETRIC_ENCRYPT_OUTPUT_MAX_SIZE
857#define PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE(key_type, key_bits, alg) \
857#define PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE(key_type, key_bits, alg) \ …
870#define PSA_KEY_EXPORT_ECC_KEY_MAX_SIZE(key_type, key_bits) \
872 (PSA_KEY_TYPE_ECC_GET_FAMILY(key_type) == PSA_ECC_FAMILY_TWISTED_EDWARDS ? 32 : \
873 (PSA_KEY_TYPE_ECC_GET_FAMILY(key_type) == PSA_ECC_FAMILY_SECP_R1 ? \
874 PSA_BITS_TO_BYTES(key_bits) : \
870#define PSA_KEY_EXPORT_ECC_KEY_MAX_SIZE(key_type, key_bits) \ …
913#define PSA_EXPORT_KEY_OUTPUT_SIZE(key_type, key_bits) \
914 (PSA_KEY_TYPE_IS_PUBLIC_KEY(key_type) ? \
915 PSA_EXPORT_PUBLIC_KEY_OUTPUT_SIZE(key_type, key_bits) : \
916 (PSA_KEY_TYPE_IS_ECC(key_type) ? \
917 PSA_KEY_EXPORT_ECC_KEY_MAX_SIZE(key_type, key_bits) : \
913#define PSA_EXPORT_KEY_OUTPUT_SIZE(key_type, key_bits) \ …
926#define PSA_ECC_KEY_SIZE_IS_VALID(type, bits) \
927 (PSA_KEY_TYPE_ECC_GET_FAMILY(type) == PSA_ECC_FAMILY_TWISTED_EDWARDS ? \
929 (PSA_KEY_TYPE_ECC_GET_FAMILY(type) == PSA_ECC_FAMILY_SECP_R1 ? \
926#define PSA_ECC_KEY_SIZE_IS_VALID(type, bits) \ …
940#define PSA_MAX_PRIV_KEY_SIZE (PSA_BYTES_TO_BITS(CONFIG_PSA_MAX_KEY_SIZE))
951#if (IS_USED(MODULE_PSA_ASYMMETRIC_ECC_P256R1) || \
952 IS_USED(MODULE_PSA_SECURE_ELEMENT_ATECCX08A_ECC_P256))
953#define PSA_EXPORT_KEY_PAIR_MAX_SIZE \
954 (PSA_EXPORT_KEY_OUTPUT_SIZE(PSA_ECC_FAMILY_SECT_R1, 256))
955#elif (IS_USED(MODULE_PSA_ASYMMETRIC_ECC_ED25519))
956#define PSA_EXPORT_KEY_PAIR_MAX_SIZE \
957 (PSA_EXPORT_KEY_OUTPUT_SIZE(PSA_ECC_FAMILY_TWISTED_EDWARDS, 255))
958#elif (IS_USED(MODULE_PSA_ASYMMETRIC_ECC_P192R1))
959#define PSA_EXPORT_KEY_PAIR_MAX_SIZE \
960 (PSA_EXPORT_KEY_OUTPUT_SIZE(PSA_ECC_FAMILY_SECT_R1, 192))
962#define PSA_EXPORT_KEY_PAIR_MAX_SIZE 0
977#define PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(key_type, key_bits) \
978 (PSA_KEY_TYPE_ECC_GET_FAMILY(key_type) == PSA_ECC_FAMILY_TWISTED_EDWARDS ? 32 : \
979 ((size_t)(2 * PSA_BITS_TO_BYTES(key_bits) + 1)))
977#define PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(key_type, key_bits) \ …
1021#define PSA_EXPORT_PUBLIC_KEY_OUTPUT_SIZE(key_type, key_bits) \
1022 (PSA_KEY_TYPE_IS_ECC(key_type) ? PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(key_type, key_bits) : \
1021#define PSA_EXPORT_PUBLIC_KEY_OUTPUT_SIZE(key_type, key_bits) \ …
1035#if (IS_USED(MODULE_PSA_ASYMMETRIC_ECC_P256R1) || \
1036 IS_USED(MODULE_PSA_SECURE_ELEMENT_ATECCX08A_ECC_P256))
1037#define PSA_EXPORT_PUBLIC_KEY_MAX_SIZE \
1038 (PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(PSA_ECC_FAMILY_SECT_R1, 256))
1039#elif (IS_USED(MODULE_PSA_ASYMMETRIC_ECC_P192R1))
1040#define PSA_EXPORT_PUBLIC_KEY_MAX_SIZE \
1041 (PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(PSA_ECC_FAMILY_SECT_R1, 192))
1042#elif (IS_USED(MODULE_PSA_ASYMMETRIC_ECC_ED25519))
1043#define PSA_EXPORT_PUBLIC_KEY_MAX_SIZE \
1044 (PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(PSA_ECC_FAMILY_TWISTED_EDWARDS, 255))
1046#define PSA_EXPORT_PUBLIC_KEY_MAX_SIZE 0
1054#define PSA_MAX_PRIV_KEY_BUFFER_SIZE (PSA_BITS_TO_BYTES(PSA_MAX_PRIV_KEY_SIZE))
1059#define PSA_MAX_ASYMMETRIC_KEYPAIR_SIZE (PSA_BITS_TO_BYTES(PSA_MAX_PRIV_KEY_SIZE) + \
1060 PSA_EXPORT_PUBLIC_KEY_MAX_SIZE)
1059#define PSA_MAX_ASYMMETRIC_KEYPAIR_SIZE (PSA_BITS_TO_BYTES(PSA_MAX_PRIV_KEY_SIZE) + \ …
1065#if IS_USED(MODULE_PSA_ASYMMETRIC)
1066#define PSA_MAX_KEY_DATA_SIZE (PSA_EXPORT_PUBLIC_KEY_MAX_SIZE)
1068#define PSA_MAX_KEY_DATA_SIZE (CONFIG_PSA_MAX_KEY_SIZE)
1074#define PSA_MAX_UNSTRUCTURED_KEY_SIZE (CONFIG_PSA_MAX_KEY_SIZE)
1085#define PSA_ECDSA_SIGNATURE_SIZE(curve_bits) \
1086 ((size_t)(PSA_BITS_TO_BYTES(curve_bits) * 2))
1085#define PSA_ECDSA_SIGNATURE_SIZE(curve_bits) \ …
1106#define PSA_SIGN_OUTPUT_SIZE(key_type, key_bits, alg) \
1107 (PSA_KEY_TYPE_IS_ECC(key_type) ? PSA_ECDSA_SIGNATURE_SIZE(key_bits) : \
1106#define PSA_SIGN_OUTPUT_SIZE(key_type, key_bits, alg) \ …
Value definitions for PSA Crypto.
Common macros and compiler attributes/pragmas configuration.