34#ifndef PSA_CRYPTO_VALUES_H
35#define PSA_CRYPTO_VALUES_H
45#define PSA_SUCCESS ((psa_status_t)0)
52#define PSA_ERROR_GENERIC_ERROR ((psa_status_t)-132)
61#define PSA_ERROR_NOT_SUPPORTED ((psa_status_t)-134)
74#define PSA_ERROR_NOT_PERMITTED ((psa_status_t)-133)
86#define PSA_ERROR_BUFFER_TOO_SMALL ((psa_status_t)-138)
92#define PSA_ERROR_ALREADY_EXISTS ((psa_status_t)-139)
98#define PSA_ERROR_DOES_NOT_EXIST ((psa_status_t)-140)
114#define PSA_ERROR_BAD_STATE ((psa_status_t)-137)
125#define PSA_ERROR_INVALID_ARGUMENT ((psa_status_t)-135)
131#define PSA_ERROR_INSUFFICIENT_MEMORY ((psa_status_t)-141)
140#define PSA_ERROR_INSUFFICIENT_STORAGE ((psa_status_t)-142)
157#define PSA_ERROR_COMMUNICATION_FAILURE ((psa_status_t)-145)
182#define PSA_ERROR_STORAGE_FAILURE ((psa_status_t)-146)
188#define PSA_ERROR_HARDWARE_FAILURE ((psa_status_t)-147)
219#define PSA_ERROR_CORRUPTION_DETECTED ((psa_status_t)-151)
238#define PSA_ERROR_INSUFFICIENT_ENTROPY ((psa_status_t)-148)
248#define PSA_ERROR_INVALID_SIGNATURE ((psa_status_t)-149)
264#define PSA_ERROR_INVALID_PADDING ((psa_status_t)-150)
268#define PSA_ERROR_INSUFFICIENT_DATA ((psa_status_t)-143)
272#define PSA_ERROR_INVALID_HANDLE ((psa_status_t)-136)
285#define PSA_KEY_TYPE_NONE ((psa_key_type_t)0x0000)
294#define PSA_KEY_TYPE_VENDOR_FLAG ((psa_key_type_t)0x8000)
296#define PSA_KEY_TYPE_CATEGORY_MASK ((psa_key_type_t)0x7000)
297#define PSA_KEY_TYPE_CATEGORY_RAW ((psa_key_type_t)0x1000)
298#define PSA_KEY_TYPE_CATEGORY_SYMMETRIC ((psa_key_type_t)0x2000)
299#define PSA_KEY_TYPE_CATEGORY_PUBLIC_KEY ((psa_key_type_t)0x4000)
300#define PSA_KEY_TYPE_CATEGORY_KEY_PAIR ((psa_key_type_t)0x7000)
302#define PSA_KEY_TYPE_CATEGORY_FLAG_PAIR ((psa_key_type_t)0x3000)
308#define PSA_KEY_TYPE_IS_VENDOR_DEFINED(type) \
309 (((type) & PSA_KEY_TYPE_VENDOR_FLAG) != 0)
315#define PSA_KEY_TYPE_IS_UNSTRUCTURED(type) \
316 (((type) & PSA_KEY_TYPE_CATEGORY_MASK) == PSA_KEY_TYPE_CATEGORY_RAW || \
317 ((type) & PSA_KEY_TYPE_CATEGORY_MASK) == PSA_KEY_TYPE_CATEGORY_SYMMETRIC)
320#define PSA_KEY_TYPE_IS_ASYMMETRIC(type) \
321 (((type) & PSA_KEY_TYPE_CATEGORY_MASK \
322 & ~PSA_KEY_TYPE_CATEGORY_FLAG_PAIR) == \
323 PSA_KEY_TYPE_CATEGORY_PUBLIC_KEY)
325#define PSA_KEY_TYPE_IS_PUBLIC_KEY(type) \
326 (((type) & PSA_KEY_TYPE_CATEGORY_MASK) == PSA_KEY_TYPE_CATEGORY_PUBLIC_KEY)
329#define PSA_KEY_TYPE_IS_KEY_PAIR(type) \
330 (((type) & PSA_KEY_TYPE_CATEGORY_MASK) == PSA_KEY_TYPE_CATEGORY_KEY_PAIR)
341#define PSA_KEY_TYPE_KEY_PAIR_OF_PUBLIC_KEY(type) \
342 ((type) | PSA_KEY_TYPE_CATEGORY_FLAG_PAIR)
353#define PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(type) \
354 ((type) & ~PSA_KEY_TYPE_CATEGORY_FLAG_PAIR)
360#define PSA_KEY_TYPE_RAW_DATA ((psa_key_type_t)0x1001)
370#define PSA_KEY_TYPE_HMAC ((psa_key_type_t)0x1100)
377#define PSA_KEY_TYPE_DERIVE ((psa_key_type_t)0x1200)
384#define PSA_KEY_TYPE_AES ((psa_key_type_t)0x2400)
395#define PSA_KEY_TYPE_DES ((psa_key_type_t)0x2301)
399#define PSA_KEY_TYPE_CAMELLIA ((psa_key_type_t)0x2403)
405#define PSA_KEY_TYPE_ARC4 ((psa_key_type_t)0x2002)
414#define PSA_KEY_TYPE_CHACHA20 ((psa_key_type_t)0x2004)
417#define PSA_KEY_TYPE_RSA_PUBLIC_KEY ((psa_key_type_t)0x4001)
419#define PSA_KEY_TYPE_RSA_KEY_PAIR ((psa_key_type_t)0x7001)
421#define PSA_KEY_TYPE_IS_RSA(type) \
422 (PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(type) == PSA_KEY_TYPE_RSA_PUBLIC_KEY)
424#define PSA_KEY_TYPE_ECC_PUBLIC_KEY_BASE ((psa_key_type_t)0x4100)
425#define PSA_KEY_TYPE_ECC_KEY_PAIR_BASE ((psa_key_type_t)0x7100)
426#define PSA_KEY_TYPE_ECC_CURVE_MASK ((psa_key_type_t)0x00ff)
432#define PSA_KEY_TYPE_ECC_KEY_PAIR(curve) \
433 (PSA_KEY_TYPE_ECC_KEY_PAIR_BASE | (curve))
439#define PSA_KEY_TYPE_ECC_PUBLIC_KEY(curve) \
440 (PSA_KEY_TYPE_ECC_PUBLIC_KEY_BASE | (curve))
443#define PSA_KEY_TYPE_IS_ECC(type) \
444 ((PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(type) & \
445 ~PSA_KEY_TYPE_ECC_CURVE_MASK) == PSA_KEY_TYPE_ECC_PUBLIC_KEY_BASE)
447#define PSA_KEY_TYPE_IS_ECC_KEY_PAIR(type) \
448 (((type) & ~PSA_KEY_TYPE_ECC_CURVE_MASK) == \
449 PSA_KEY_TYPE_ECC_KEY_PAIR_BASE)
451#define PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY(type) \
452 (((type) & ~PSA_KEY_TYPE_ECC_CURVE_MASK) == \
453 PSA_KEY_TYPE_ECC_PUBLIC_KEY_BASE)
456#define PSA_KEY_TYPE_ECC_GET_FAMILY(type) \
457 ((psa_ecc_family_t) (PSA_KEY_TYPE_IS_ECC(type) ? \
458 ((type) & PSA_KEY_TYPE_ECC_CURVE_MASK) : \
469#define PSA_ECC_FAMILY_SECP_K1 ((psa_ecc_family_t) 0x17)
479#define PSA_ECC_FAMILY_SECP_R1 ((psa_ecc_family_t) 0x12)
481#define PSA_ECC_FAMILY_SECP_R2 ((psa_ecc_family_t) 0x1b)
491#define PSA_ECC_FAMILY_SECT_K1 ((psa_ecc_family_t) 0x27)
501#define PSA_ECC_FAMILY_SECT_R1 ((psa_ecc_family_t) 0x22)
511#define PSA_ECC_FAMILY_SECT_R2 ((psa_ecc_family_t) 0x2b)
520#define PSA_ECC_FAMILY_BRAINPOOL_P_R1 ((psa_ecc_family_t) 0x30)
532#define PSA_ECC_FAMILY_MONTGOMERY ((psa_ecc_family_t) 0x41)
534#define PSA_KEY_TYPE_DH_PUBLIC_KEY_BASE ((psa_key_type_t)0x4200)
535#define PSA_KEY_TYPE_DH_KEY_PAIR_BASE ((psa_key_type_t)0x7200)
536#define PSA_KEY_TYPE_DH_GROUP_MASK ((psa_key_type_t)0x00ff)
542#define PSA_KEY_TYPE_DH_KEY_PAIR(group) \
543 (PSA_KEY_TYPE_DH_KEY_PAIR_BASE | (group))
549#define PSA_KEY_TYPE_DH_PUBLIC_KEY(group) \
550 (PSA_KEY_TYPE_DH_PUBLIC_KEY_BASE | (group))
553#define PSA_KEY_TYPE_IS_DH(type) \
554 ((PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(type) & \
555 ~PSA_KEY_TYPE_DH_GROUP_MASK) == PSA_KEY_TYPE_DH_PUBLIC_KEY_BASE)
557#define PSA_KEY_TYPE_IS_DH_KEY_PAIR(type) \
558 (((type) & ~PSA_KEY_TYPE_DH_GROUP_MASK) == \
559 PSA_KEY_TYPE_DH_KEY_PAIR_BASE)
561#define PSA_KEY_TYPE_IS_DH_PUBLIC_KEY(type) \
562 (((type) & ~PSA_KEY_TYPE_DH_GROUP_MASK) == \
563 PSA_KEY_TYPE_DH_PUBLIC_KEY_BASE)
566#define PSA_KEY_TYPE_DH_GET_FAMILY(type) \
567 ((psa_dh_family_t) (PSA_KEY_TYPE_IS_DH(type) ? \
568 ((type) & PSA_KEY_TYPE_DH_GROUP_MASK) : \
577#define PSA_DH_FAMILY_RFC7919 ((psa_dh_family_t) 0x03)
579#define PSA_GET_KEY_TYPE_BLOCK_SIZE_EXPONENT(type) \
599#define PSA_BLOCK_CIPHER_BLOCK_SIZE(type) \
600 (((type) & PSA_KEY_TYPE_CATEGORY_MASK) == PSA_KEY_TYPE_CATEGORY_SYMMETRIC ? \
601 1u << PSA_GET_KEY_TYPE_BLOCK_SIZE_EXPONENT(type) : \
611#define PSA_ALG_VENDOR_FLAG ((psa_algorithm_t)0x80000000)
613#define PSA_ALG_CATEGORY_MASK ((psa_algorithm_t)0x7f000000)
614#define PSA_ALG_CATEGORY_HASH ((psa_algorithm_t)0x02000000)
615#define PSA_ALG_CATEGORY_MAC ((psa_algorithm_t)0x03000000)
616#define PSA_ALG_CATEGORY_CIPHER ((psa_algorithm_t)0x04000000)
617#define PSA_ALG_CATEGORY_AEAD ((psa_algorithm_t)0x05000000)
618#define PSA_ALG_CATEGORY_SIGN ((psa_algorithm_t)0x06000000)
619#define PSA_ALG_CATEGORY_ASYMMETRIC_ENCRYPTION ((psa_algorithm_t)0x07000000)
620#define PSA_ALG_CATEGORY_KEY_DERIVATION ((psa_algorithm_t)0x08000000)
621#define PSA_ALG_CATEGORY_KEY_AGREEMENT ((psa_algorithm_t)0x09000000)
627#define PSA_ALG_IS_VENDOR_DEFINED(alg) \
628 (((alg) & PSA_ALG_VENDOR_FLAG) != 0)
638#define PSA_ALG_IS_HASH(alg) \
639 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_HASH)
649#define PSA_ALG_IS_MAC(alg) \
650 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_MAC)
660#define PSA_ALG_IS_CIPHER(alg) \
661 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_CIPHER)
672#define PSA_ALG_IS_AEAD(alg) \
673 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_AEAD)
684#define PSA_ALG_IS_SIGN(alg) \
685 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_SIGN)
696#define PSA_ALG_IS_ASYMMETRIC_ENCRYPTION(alg) \
697 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_ASYMMETRIC_ENCRYPTION)
707#define PSA_ALG_IS_KEY_AGREEMENT(alg) \
708 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_KEY_AGREEMENT)
718#define PSA_ALG_IS_KEY_DERIVATION(alg) \
719 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_KEY_DERIVATION)
721#define PSA_ALG_HASH_MASK ((psa_algorithm_t)0x000000ff)
723#define PSA_ALG_MD2 ((psa_algorithm_t)0x02000001)
725#define PSA_ALG_MD4 ((psa_algorithm_t)0x02000002)
727#define PSA_ALG_MD5 ((psa_algorithm_t)0x02000003)
729#define PSA_ALG_RIPEMD160 ((psa_algorithm_t)0x02000004)
731#define PSA_ALG_SHA_1 ((psa_algorithm_t)0x02000005)
733#define PSA_ALG_SHA_224 ((psa_algorithm_t)0x02000008)
735#define PSA_ALG_SHA_256 ((psa_algorithm_t)0x02000009)
737#define PSA_ALG_SHA_384 ((psa_algorithm_t)0x0200000a)
739#define PSA_ALG_SHA_512 ((psa_algorithm_t)0x0200000b)
741#define PSA_ALG_SHA_512_224 ((psa_algorithm_t)0x0200000c)
743#define PSA_ALG_SHA_512_256 ((psa_algorithm_t)0x0200000d)
745#define PSA_ALG_SHA3_224 ((psa_algorithm_t)0x02000010)
747#define PSA_ALG_SHA3_256 ((psa_algorithm_t)0x02000011)
749#define PSA_ALG_SHA3_384 ((psa_algorithm_t)0x02000012)
751#define PSA_ALG_SHA3_512 ((psa_algorithm_t)0x02000013)
786#define PSA_ALG_ANY_HASH ((psa_algorithm_t)0x020000ff)
788#define PSA_ALG_MAC_SUBCATEGORY_MASK ((psa_algorithm_t)0x00c00000)
789#define PSA_ALG_HMAC_BASE ((psa_algorithm_t)0x03800000)
801#define PSA_ALG_HMAC(hash_alg) \
802 (PSA_ALG_HMAC_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
804#define PSA_ALG_HMAC_GET_HASH(hmac_alg) \
805 (PSA_ALG_CATEGORY_HASH | ((hmac_alg) & PSA_ALG_HASH_MASK))
817#define PSA_ALG_IS_HMAC(alg) \
818 (((alg) & (PSA_ALG_CATEGORY_MASK | PSA_ALG_MAC_SUBCATEGORY_MASK)) == \
828#define PSA_ALG_MAC_TRUNCATION_MASK ((psa_algorithm_t)0x003f0000)
829#define PSA_MAC_TRUNCATION_OFFSET 16
864#define PSA_ALG_TRUNCATED_MAC(mac_alg, mac_length) \
865 (((mac_alg) & ~PSA_ALG_MAC_TRUNCATION_MASK) | \
866 ((mac_length) << PSA_MAC_TRUNCATION_OFFSET & PSA_ALG_MAC_TRUNCATION_MASK))
880#define PSA_ALG_FULL_LENGTH_MAC(mac_alg) \
881 ((mac_alg) & ~PSA_ALG_MAC_TRUNCATION_MASK)
894#define PSA_MAC_TRUNCATED_LENGTH(mac_alg) \
895 (((mac_alg) & PSA_ALG_MAC_TRUNCATION_MASK) >> PSA_MAC_TRUNCATION_OFFSET)
897#define PSA_ALG_CIPHER_MAC_BASE ((psa_algorithm_t)0x03c00000)
903#define PSA_ALG_CBC_MAC ((psa_algorithm_t)0x03c00100)
905#define PSA_ALG_CMAC ((psa_algorithm_t)0x03c00200)
915#define PSA_ALG_IS_BLOCK_CIPHER_MAC(alg) \
916 (((alg) & (PSA_ALG_CATEGORY_MASK | PSA_ALG_MAC_SUBCATEGORY_MASK)) == \
917 PSA_ALG_CIPHER_MAC_BASE)
919#define PSA_ALG_CIPHER_STREAM_FLAG ((psa_algorithm_t)0x00800000)
920#define PSA_ALG_CIPHER_FROM_BLOCK_FLAG ((psa_algorithm_t)0x00400000)
934#define PSA_ALG_IS_STREAM_CIPHER(alg) \
935 (((alg) & (PSA_ALG_CATEGORY_MASK | PSA_ALG_CIPHER_STREAM_FLAG)) == \
936 (PSA_ALG_CATEGORY_CIPHER | PSA_ALG_CIPHER_STREAM_FLAG))
944#define PSA_ALG_STREAM_CIPHER ((psa_algorithm_t)0x04800100)
953#define PSA_ALG_CTR ((psa_algorithm_t)0x04c01000)
959#define PSA_ALG_CFB ((psa_algorithm_t)0x04c01100)
965#define PSA_ALG_OFB ((psa_algorithm_t)0x04c01200)
973#define PSA_ALG_XTS ((psa_algorithm_t)0x0440ff00)
993#define PSA_ALG_ECB_NO_PADDING ((psa_algorithm_t)0x04404400)
1002#define PSA_ALG_CBC_NO_PADDING ((psa_algorithm_t)0x04404000)
1010#define PSA_ALG_CBC_PKCS7 ((psa_algorithm_t)0x04404100)
1012#define PSA_ALG_AEAD_FROM_BLOCK_FLAG ((psa_algorithm_t)0x00400000)
1023#define PSA_ALG_IS_AEAD_ON_BLOCK_CIPHER(alg) \
1024 (((alg) & (PSA_ALG_CATEGORY_MASK | PSA_ALG_AEAD_FROM_BLOCK_FLAG)) == \
1025 (PSA_ALG_CATEGORY_AEAD | PSA_ALG_AEAD_FROM_BLOCK_FLAG))
1031#define PSA_ALG_CCM ((psa_algorithm_t)0x05500100)
1037#define PSA_ALG_GCM ((psa_algorithm_t)0x05500200)
1048#define PSA_ALG_CHACHA20_POLY1305 ((psa_algorithm_t)0x05100500)
1054#define PSA_ALG_AEAD_TAG_LENGTH_MASK ((psa_algorithm_t)0x003f0000)
1055#define PSA_AEAD_TAG_LENGTH_OFFSET 16
1075#define PSA_ALG_AEAD_WITH_TAG_LENGTH(aead_alg, tag_length) \
1076 (((aead_alg) & ~PSA_ALG_AEAD_TAG_LENGTH_MASK) | \
1077 ((tag_length) << PSA_AEAD_TAG_LENGTH_OFFSET & \
1078 PSA_ALG_AEAD_TAG_LENGTH_MASK))
1088#define PSA_ALG_AEAD_WITH_DEFAULT_TAG_LENGTH(aead_alg) \
1090 PSA_ALG_AEAD_WITH_DEFAULT_TAG_LENGTH_CASE(aead_alg, PSA_ALG_CCM) \
1091 PSA_ALG_AEAD_WITH_DEFAULT_TAG_LENGTH_CASE(aead_alg, PSA_ALG_GCM) \
1092 PSA_ALG_AEAD_WITH_DEFAULT_TAG_LENGTH_CASE(aead_alg, PSA_ALG_CHACHA20_POLY1305) \
1094#define PSA_ALG_AEAD_WITH_DEFAULT_TAG_LENGTH_CASE(aead_alg, ref) \
1095 PSA_ALG_AEAD_WITH_TAG_LENGTH(aead_alg, 0) == \
1096 PSA_ALG_AEAD_WITH_TAG_LENGTH(ref, 0) ? \
1099#define PSA_ALG_RSA_PKCS1V15_SIGN_BASE ((psa_algorithm_t)0x06000200)
1115#define PSA_ALG_RSA_PKCS1V15_SIGN(hash_alg) \
1116 (PSA_ALG_RSA_PKCS1V15_SIGN_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
1123#define PSA_ALG_RSA_PKCS1V15_SIGN_RAW PSA_ALG_RSA_PKCS1V15_SIGN_BASE
1124#define PSA_ALG_IS_RSA_PKCS1V15_SIGN(alg) \
1125 (((alg) & ~PSA_ALG_HASH_MASK) == PSA_ALG_RSA_PKCS1V15_SIGN_BASE)
1127#define PSA_ALG_RSA_PSS_BASE ((psa_algorithm_t)0x06000300)
1146#define PSA_ALG_RSA_PSS(hash_alg) \
1147 (PSA_ALG_RSA_PSS_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
1148#define PSA_ALG_IS_RSA_PSS(alg) \
1149 (((alg) & ~PSA_ALG_HASH_MASK) == PSA_ALG_RSA_PSS_BASE)
1151#define PSA_ALG_ECDSA_BASE ((psa_algorithm_t)0x06000600)
1172#define PSA_ALG_ECDSA(hash_alg) \
1173 (PSA_ALG_ECDSA_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
1183#define PSA_ALG_ECDSA_ANY PSA_ALG_ECDSA_BASE
1184#define PSA_ALG_DETERMINISTIC_ECDSA_BASE ((psa_algorithm_t)0x06000700)
1207#define PSA_ALG_DETERMINISTIC_ECDSA(hash_alg) \
1208 (PSA_ALG_DETERMINISTIC_ECDSA_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
1209#define PSA_ALG_ECDSA_DETERMINISTIC_FLAG ((psa_algorithm_t)0x00000100)
1210#define PSA_ALG_IS_ECDSA(alg) \
1211 (((alg) & ~PSA_ALG_HASH_MASK & ~PSA_ALG_ECDSA_DETERMINISTIC_FLAG) == \
1213#define PSA_ALG_ECDSA_IS_DETERMINISTIC(alg) \
1214 (((alg) & PSA_ALG_ECDSA_DETERMINISTIC_FLAG) != 0)
1215#define PSA_ALG_IS_DETERMINISTIC_ECDSA(alg) \
1216 (PSA_ALG_IS_ECDSA(alg) && PSA_ALG_ECDSA_IS_DETERMINISTIC(alg))
1217#define PSA_ALG_IS_RANDOMIZED_ECDSA(alg) \
1218 (PSA_ALG_IS_ECDSA(alg) && !PSA_ALG_ECDSA_IS_DETERMINISTIC(alg))
1233#define PSA_ALG_IS_HASH_AND_SIGN(alg) \
1234 (PSA_ALG_IS_RSA_PSS(alg) || PSA_ALG_IS_RSA_PKCS1V15_SIGN(alg) || \
1235 PSA_ALG_IS_ECDSA(alg))
1255#define PSA_ALG_SIGN_GET_HASH(alg) \
1256 (PSA_ALG_IS_HASH_AND_SIGN(alg) ? \
1257 ((alg) & PSA_ALG_HASH_MASK) == 0 ? 0 : \
1258 ((alg) & PSA_ALG_HASH_MASK) | PSA_ALG_CATEGORY_HASH : \
1263#define PSA_ALG_RSA_PKCS1V15_CRYPT ((psa_algorithm_t)0x07000200)
1265#define PSA_ALG_RSA_OAEP_BASE ((psa_algorithm_t)0x07000300)
1280#define PSA_ALG_RSA_OAEP(hash_alg) \
1281 (PSA_ALG_RSA_OAEP_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
1282#define PSA_ALG_IS_RSA_OAEP(alg) \
1283 (((alg) & ~PSA_ALG_HASH_MASK) == PSA_ALG_RSA_OAEP_BASE)
1284#define PSA_ALG_RSA_OAEP_GET_HASH(alg) \
1285 (PSA_ALG_IS_RSA_OAEP(alg) ? \
1286 ((alg) & PSA_ALG_HASH_MASK) | PSA_ALG_CATEGORY_HASH : \
1289#define PSA_ALG_HKDF_BASE ((psa_algorithm_t)0x08000100)
1310#define PSA_ALG_HKDF(hash_alg) \
1311 (PSA_ALG_HKDF_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
1323#define PSA_ALG_IS_HKDF(alg) \
1324 (((alg) & ~PSA_ALG_HASH_MASK) == PSA_ALG_HKDF_BASE)
1325#define PSA_ALG_HKDF_GET_HASH(hkdf_alg) \
1326 (PSA_ALG_CATEGORY_HASH | ((hkdf_alg) & PSA_ALG_HASH_MASK))
1328#define PSA_ALG_TLS12_PRF_BASE ((psa_algorithm_t)0x08000200)
1355#define PSA_ALG_TLS12_PRF(hash_alg) \
1356 (PSA_ALG_TLS12_PRF_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
1366#define PSA_ALG_IS_TLS12_PRF(alg) \
1367 (((alg) & ~PSA_ALG_HASH_MASK) == PSA_ALG_TLS12_PRF_BASE)
1368#define PSA_ALG_TLS12_PRF_GET_HASH(hkdf_alg) \
1369 (PSA_ALG_CATEGORY_HASH | ((hkdf_alg) & PSA_ALG_HASH_MASK))
1371#define PSA_ALG_TLS12_PSK_TO_MS_BASE ((psa_algorithm_t)0x08000300)
1401#define PSA_ALG_TLS12_PSK_TO_MS(hash_alg) \
1402 (PSA_ALG_TLS12_PSK_TO_MS_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
1412#define PSA_ALG_IS_TLS12_PSK_TO_MS(alg) \
1413 (((alg) & ~PSA_ALG_HASH_MASK) == PSA_ALG_TLS12_PSK_TO_MS_BASE)
1414#define PSA_ALG_TLS12_PSK_TO_MS_GET_HASH(hkdf_alg) \
1415 (PSA_ALG_CATEGORY_HASH | ((hkdf_alg) & PSA_ALG_HASH_MASK))
1417#define PSA_ALG_KEY_DERIVATION_MASK ((psa_algorithm_t)0xfe00ffff)
1418#define PSA_ALG_KEY_AGREEMENT_MASK ((psa_algorithm_t)0xffff0000)
1434#define PSA_ALG_KEY_AGREEMENT(ka_alg, kdf_alg) \
1435 ((ka_alg) | (kdf_alg))
1437#define PSA_ALG_KEY_AGREEMENT_GET_KDF(alg) \
1438 (((alg) & PSA_ALG_KEY_DERIVATION_MASK) | PSA_ALG_CATEGORY_KEY_DERIVATION)
1440#define PSA_ALG_KEY_AGREEMENT_GET_BASE(alg) \
1441 (((alg) & PSA_ALG_KEY_AGREEMENT_MASK) | PSA_ALG_CATEGORY_KEY_AGREEMENT)
1457#define PSA_ALG_IS_RAW_KEY_AGREEMENT(alg) \
1458 (PSA_ALG_IS_KEY_AGREEMENT(alg) && \
1459 PSA_ALG_KEY_AGREEMENT_GET_KDF(alg) == PSA_ALG_CATEGORY_KEY_DERIVATION)
1461#define PSA_ALG_IS_KEY_DERIVATION_OR_AGREEMENT(alg) \
1462 ((PSA_ALG_IS_KEY_DERIVATION(alg) || PSA_ALG_IS_KEY_AGREEMENT(alg)))
1471#define PSA_ALG_FFDH ((psa_algorithm_t)0x09010000)
1485#define PSA_ALG_IS_FFDH(alg) \
1486 (PSA_ALG_KEY_AGREEMENT_GET_BASE(alg) == PSA_ALG_FFDH)
1513#define PSA_ALG_ECDH ((psa_algorithm_t)0x09020000)
1529#define PSA_ALG_IS_ECDH(alg) \
1530 (PSA_ALG_KEY_AGREEMENT_GET_BASE(alg) == PSA_ALG_ECDH)
1545#define PSA_ALG_IS_WILDCARD(alg) \
1546 (PSA_ALG_IS_HASH_AND_SIGN(alg) ? \
1547 PSA_ALG_SIGN_GET_HASH(alg) == PSA_ALG_ANY_HASH : \
1548 (alg) == PSA_ALG_ANY_HASH)
1568#define PSA_KEY_LIFETIME_VOLATILE ((psa_key_lifetime_t)0x00000000)
1583#define PSA_KEY_LIFETIME_PERSISTENT ((psa_key_lifetime_t)0x00000001)
1589#define PSA_KEY_PERSISTENCE_VOLATILE ((psa_key_persistence_t)0x00)
1595#define PSA_KEY_PERSISTENCE_DEFAULT ((psa_key_persistence_t)0x01)
1601#define PSA_KEY_PERSISTENCE_READ_ONLY ((psa_key_persistence_t)0xff)
1606#define PSA_KEY_LIFETIME_GET_PERSISTENCE(lifetime) \
1607 ((psa_key_persistence_t)((lifetime) & 0x000000ff))
1612#define PSA_KEY_LIFETIME_GET_LOCATION(lifetime) \
1613 ((psa_key_location_t)((lifetime) >> 8))
1631#define PSA_KEY_LIFETIME_IS_VOLATILE(lifetime) \
1632 (PSA_KEY_LIFETIME_GET_PERSISTENCE(lifetime) == \
1633 PSA_KEY_PERSISTENCE_VOLATILE)
1644#define PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(persistence, location) \
1645 ((location) << 8 | (persistence))
1654#define PSA_KEY_LOCATION_LOCAL_STORAGE ((psa_key_location_t)0x000000)
1656#define PSA_KEY_LOCATION_VENDOR_FLAG ((psa_key_location_t)0x800000)
1660#define PSA_KEY_ID_USER_MIN ((psa_key_id_t)0x00000001)
1663#define PSA_KEY_ID_USER_MAX ((psa_key_id_t)0x3fffffff)
1666#define PSA_KEY_ID_VENDOR_MIN ((psa_key_id_t)0x40000000)
1669#define PSA_KEY_ID_VENDOR_MAX ((psa_key_id_t)0x7fffffff)
1672#if !defined(MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER)
1674#define MBEDTLS_SVC_KEY_ID_INIT ( (psa_key_id_t)0 )
1675#define MBEDTLS_SVC_KEY_ID_GET_KEY_ID( id ) ( id )
1676#define MBEDTLS_SVC_KEY_ID_GET_OWNER_ID( id ) ( 0 )
1701 return( id1 == id2 );
1717#define MBEDTLS_SVC_KEY_ID_INIT ( (mbedtls_svc_key_id_t){ 0, 0 } )
1718#define MBEDTLS_SVC_KEY_ID_GET_KEY_ID( id ) ( ( id ).key_id )
1719#define MBEDTLS_SVC_KEY_ID_GET_OWNER_ID( id ) ( ( id ).owner )
1730 .owner = owner_id } );
1743 return( ( id1.key_id == id2.key_id ) &&
1744 mbedtls_key_owner_id_equal( id1.owner, id2.owner ) );
1755 return( ( key.key_id == 0 ) && ( key.owner == 0 ) );
1778#define PSA_KEY_USAGE_EXPORT ((psa_key_usage_t)0x00000001)
1794#define PSA_KEY_USAGE_COPY ((psa_key_usage_t)0x00000002)
1805#define PSA_KEY_USAGE_ENCRYPT ((psa_key_usage_t)0x00000100)
1816#define PSA_KEY_USAGE_DECRYPT ((psa_key_usage_t)0x00000200)
1826#define PSA_KEY_USAGE_SIGN_HASH ((psa_key_usage_t)0x00001000)
1836#define PSA_KEY_USAGE_VERIFY_HASH ((psa_key_usage_t)0x00002000)
1840#define PSA_KEY_USAGE_DERIVE ((psa_key_usage_t)0x00004000)
1861#define PSA_KEY_DERIVATION_INPUT_SECRET ((psa_key_derivation_step_t)0x0101)
1868#define PSA_KEY_DERIVATION_INPUT_LABEL ((psa_key_derivation_step_t)0x0201)
1875#define PSA_KEY_DERIVATION_INPUT_SALT ((psa_key_derivation_step_t)0x0202)
1882#define PSA_KEY_DERIVATION_INPUT_INFO ((psa_key_derivation_step_t)0x0203)
1889#define PSA_KEY_DERIVATION_INPUT_SEED ((psa_key_derivation_step_t)0x0204)
uint32_t psa_key_id_t
Encoding of identifiers of persistent keys.
psa_key_id_t mbedtls_svc_key_id_t
Identifier for persistent keys.