mbed TLS v2.23.0

crypto_values.h
Go to the documentation of this file.
1
17 /*
18 * Copyright (C) 2018, ARM Limited, All Rights Reserved
19 * SPDX-License-Identifier: Apache-2.0
20 *
21 * Licensed under the Apache License, Version 2.0 (the "License"); you may
22 * not use this file except in compliance with the License.
23 * You may obtain a copy of the License at
24 *
25 * http://www.apache.org/licenses/LICENSE-2.0
26 *
27 * Unless required by applicable law or agreed to in writing, software
28 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
29 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
30 * See the License for the specific language governing permissions and
31 * limitations under the License.
32 *
33 * This file is part of mbed TLS (https://tls.mbed.org)
34 */
35
36 #ifndef PSA_CRYPTO_VALUES_H
37 #define PSA_CRYPTO_VALUES_H
38
43 /* PSA error codes */
44
46 #define PSA_SUCCESS ((psa_status_t)0)
47
53 #define PSA_ERROR_GENERIC_ERROR ((psa_status_t)-132)
54
62 #define PSA_ERROR_NOT_SUPPORTED ((psa_status_t)-134)
63
75 #define PSA_ERROR_NOT_PERMITTED ((psa_status_t)-133)
76
87 #define PSA_ERROR_BUFFER_TOO_SMALL ((psa_status_t)-138)
88
93 #define PSA_ERROR_ALREADY_EXISTS ((psa_status_t)-139)
94
99 #define PSA_ERROR_DOES_NOT_EXIST ((psa_status_t)-140)
100
115 #define PSA_ERROR_BAD_STATE ((psa_status_t)-137)
116
126 #define PSA_ERROR_INVALID_ARGUMENT ((psa_status_t)-135)
127
132 #define PSA_ERROR_INSUFFICIENT_MEMORY ((psa_status_t)-141)
133
141 #define PSA_ERROR_INSUFFICIENT_STORAGE ((psa_status_t)-142)
142
158 #define PSA_ERROR_COMMUNICATION_FAILURE ((psa_status_t)-145)
159
183 #define PSA_ERROR_STORAGE_FAILURE ((psa_status_t)-146)
184
189 #define PSA_ERROR_HARDWARE_FAILURE ((psa_status_t)-147)
190
220 #define PSA_ERROR_CORRUPTION_DETECTED ((psa_status_t)-151)
221
239 #define PSA_ERROR_INSUFFICIENT_ENTROPY ((psa_status_t)-148)
240
249 #define PSA_ERROR_INVALID_SIGNATURE ((psa_status_t)-149)
250
265 #define PSA_ERROR_INVALID_PADDING ((psa_status_t)-150)
266
269 #define PSA_ERROR_INSUFFICIENT_DATA ((psa_status_t)-143)
270
273 #define PSA_ERROR_INVALID_HANDLE ((psa_status_t)-136)
274
285 #define PSA_KEY_TYPE_NONE ((psa_key_type_t)0x0000)
286
294 #define PSA_KEY_TYPE_VENDOR_FLAG ((psa_key_type_t)0x8000)
295
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)
301
302 #define PSA_KEY_TYPE_CATEGORY_FLAG_PAIR ((psa_key_type_t)0x3000)
303
308 #define PSA_KEY_TYPE_IS_VENDOR_DEFINED(type) \
309 (((type) & PSA_KEY_TYPE_VENDOR_FLAG) != 0)
310
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)
318
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)
324
325 #define PSA_KEY_TYPE_IS_PUBLIC_KEY(type) \
326 (((type) & PSA_KEY_TYPE_CATEGORY_MASK) == PSA_KEY_TYPE_CATEGORY_PUBLIC_KEY)
327
329 #define PSA_KEY_TYPE_IS_KEY_PAIR(type) \
330 (((type) & PSA_KEY_TYPE_CATEGORY_MASK) == PSA_KEY_TYPE_CATEGORY_KEY_PAIR)
331
341 #define PSA_KEY_TYPE_KEY_PAIR_OF_PUBLIC_KEY(type) \
342 ((type) | PSA_KEY_TYPE_CATEGORY_FLAG_PAIR)
343
353 #define PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(type) \
354 ((type) & ~PSA_KEY_TYPE_CATEGORY_FLAG_PAIR)
355
360 #define PSA_KEY_TYPE_RAW_DATA ((psa_key_type_t)0x1001)
361
370 #define PSA_KEY_TYPE_HMAC ((psa_key_type_t)0x1100)
371
377 #define PSA_KEY_TYPE_DERIVE ((psa_key_type_t)0x1200)
378
384 #define PSA_KEY_TYPE_AES ((psa_key_type_t)0x2400)
385
395 #define PSA_KEY_TYPE_DES ((psa_key_type_t)0x2301)
396
399 #define PSA_KEY_TYPE_CAMELLIA ((psa_key_type_t)0x2403)
400
405 #define PSA_KEY_TYPE_ARC4 ((psa_key_type_t)0x2002)
406
414 #define PSA_KEY_TYPE_CHACHA20 ((psa_key_type_t)0x2004)
415
417 #define PSA_KEY_TYPE_RSA_PUBLIC_KEY ((psa_key_type_t)0x4001)
418
419 #define PSA_KEY_TYPE_RSA_KEY_PAIR ((psa_key_type_t)0x7001)
420
421 #define PSA_KEY_TYPE_IS_RSA(type) \
422 (PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(type) == PSA_KEY_TYPE_RSA_PUBLIC_KEY)
423
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)
427
432 #define PSA_KEY_TYPE_ECC_KEY_PAIR(curve) \
433 (PSA_KEY_TYPE_ECC_KEY_PAIR_BASE | (curve))
434
439 #define PSA_KEY_TYPE_ECC_PUBLIC_KEY(curve) \
440 (PSA_KEY_TYPE_ECC_PUBLIC_KEY_BASE | (curve))
441
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)
446
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)
450
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)
454
456 #define PSA_KEY_TYPE_GET_CURVE(type) \
457 ((psa_ecc_curve_t) (PSA_KEY_TYPE_IS_ECC(type) ? \
458 ((type) & PSA_KEY_TYPE_ECC_CURVE_MASK) : \
459 0))
460
469 #define PSA_ECC_CURVE_SECP_K1 ((psa_ecc_curve_t) 0x17)
470
479 #define PSA_ECC_CURVE_SECP_R1 ((psa_ecc_curve_t) 0x12)
480 /* SECP160R2 (SEC2 v1, obsolete) */
481 #define PSA_ECC_CURVE_SECP_R2 ((psa_ecc_curve_t) 0x1b)
482
491 #define PSA_ECC_CURVE_SECT_K1 ((psa_ecc_curve_t) 0x27)
492
501 #define PSA_ECC_CURVE_SECT_R1 ((psa_ecc_curve_t) 0x22)
502
511 #define PSA_ECC_CURVE_SECT_R2 ((psa_ecc_curve_t) 0x2b)
512
520 #define PSA_ECC_CURVE_BRAINPOOL_P_R1 ((psa_ecc_curve_t) 0x30)
521
532 #define PSA_ECC_CURVE_MONTGOMERY ((psa_ecc_curve_t) 0x41)
533
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)
537
542 #define PSA_KEY_TYPE_DH_KEY_PAIR(group) \
543 (PSA_KEY_TYPE_DH_KEY_PAIR_BASE | (group))
544
549 #define PSA_KEY_TYPE_DH_PUBLIC_KEY(group) \
550 (PSA_KEY_TYPE_DH_PUBLIC_KEY_BASE | (group))
551
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)
556
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)
560
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)
564
566 #define PSA_KEY_TYPE_GET_GROUP(type) \
567 ((psa_dh_group_t) (PSA_KEY_TYPE_IS_DH(type) ? \
568 ((type) & PSA_KEY_TYPE_DH_GROUP_MASK) : \
569 0))
570
577 #define PSA_DH_GROUP_RFC7919 ((psa_dh_group_t) 0x03)
578
579 #define PSA_GET_KEY_TYPE_BLOCK_SIZE_EXPONENT(type) \
580 (((type) >> 8) & 7)
581
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) : \
602 0u)
603
611 #define PSA_ALG_VENDOR_FLAG ((psa_algorithm_t)0x80000000)
612
613 #define PSA_ALG_CATEGORY_MASK ((psa_algorithm_t)0x7f000000)
614 #define PSA_ALG_CATEGORY_HASH ((psa_algorithm_t)0x01000000)
615 #define PSA_ALG_CATEGORY_MAC ((psa_algorithm_t)0x02000000)
616 #define PSA_ALG_CATEGORY_CIPHER ((psa_algorithm_t)0x04000000)
617 #define PSA_ALG_CATEGORY_AEAD ((psa_algorithm_t)0x06000000)
618 #define PSA_ALG_CATEGORY_SIGN ((psa_algorithm_t)0x10000000)
619 #define PSA_ALG_CATEGORY_ASYMMETRIC_ENCRYPTION ((psa_algorithm_t)0x12000000)
620 #define PSA_ALG_CATEGORY_KEY_DERIVATION ((psa_algorithm_t)0x20000000)
621 #define PSA_ALG_CATEGORY_KEY_AGREEMENT ((psa_algorithm_t)0x30000000)
622
627 #define PSA_ALG_IS_VENDOR_DEFINED(alg) \
628 (((alg) & PSA_ALG_VENDOR_FLAG) != 0)
629
638 #define PSA_ALG_IS_HASH(alg) \
639 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_HASH)
640
649 #define PSA_ALG_IS_MAC(alg) \
650 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_MAC)
651
660 #define PSA_ALG_IS_CIPHER(alg) \
661 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_CIPHER)
662
672 #define PSA_ALG_IS_AEAD(alg) \
673 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_AEAD)
674
684 #define PSA_ALG_IS_SIGN(alg) \
685 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_SIGN)
686
696 #define PSA_ALG_IS_ASYMMETRIC_ENCRYPTION(alg) \
697 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_ASYMMETRIC_ENCRYPTION)
698
707 #define PSA_ALG_IS_KEY_AGREEMENT(alg) \
708 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_KEY_AGREEMENT)
709
718 #define PSA_ALG_IS_KEY_DERIVATION(alg) \
719 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_KEY_DERIVATION)
720
721 #define PSA_ALG_HASH_MASK ((psa_algorithm_t)0x000000ff)
722
723 #define PSA_ALG_MD2 ((psa_algorithm_t)0x01000001)
724
725 #define PSA_ALG_MD4 ((psa_algorithm_t)0x01000002)
726
727 #define PSA_ALG_MD5 ((psa_algorithm_t)0x01000003)
728
729 #define PSA_ALG_RIPEMD160 ((psa_algorithm_t)0x01000004)
730
731 #define PSA_ALG_SHA_1 ((psa_algorithm_t)0x01000005)
732
733 #define PSA_ALG_SHA_224 ((psa_algorithm_t)0x01000008)
734
735 #define PSA_ALG_SHA_256 ((psa_algorithm_t)0x01000009)
736
737 #define PSA_ALG_SHA_384 ((psa_algorithm_t)0x0100000a)
738
739 #define PSA_ALG_SHA_512 ((psa_algorithm_t)0x0100000b)
740
741 #define PSA_ALG_SHA_512_224 ((psa_algorithm_t)0x0100000c)
742
743 #define PSA_ALG_SHA_512_256 ((psa_algorithm_t)0x0100000d)
744
745 #define PSA_ALG_SHA3_224 ((psa_algorithm_t)0x01000010)
746
747 #define PSA_ALG_SHA3_256 ((psa_algorithm_t)0x01000011)
748
749 #define PSA_ALG_SHA3_384 ((psa_algorithm_t)0x01000012)
750
751 #define PSA_ALG_SHA3_512 ((psa_algorithm_t)0x01000013)
752
786 #define PSA_ALG_ANY_HASH ((psa_algorithm_t)0x010000ff)
787
788 #define PSA_ALG_MAC_SUBCATEGORY_MASK ((psa_algorithm_t)0x00c00000)
789 #define PSA_ALG_HMAC_BASE ((psa_algorithm_t)0x02800000)
790
801 #define PSA_ALG_HMAC(hash_alg) \
802 (PSA_ALG_HMAC_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
803
804 #define PSA_ALG_HMAC_GET_HASH(hmac_alg) \
805 (PSA_ALG_CATEGORY_HASH | ((hmac_alg) & PSA_ALG_HASH_MASK))
806
817 #define PSA_ALG_IS_HMAC(alg) \
818 (((alg) & (PSA_ALG_CATEGORY_MASK | PSA_ALG_MAC_SUBCATEGORY_MASK)) == \
819 PSA_ALG_HMAC_BASE)
820
821 /* In the encoding of a MAC algorithm, the bits corresponding to
822 * PSA_ALG_MAC_TRUNCATION_MASK encode the length to which the MAC is
823 * truncated. As an exception, the value 0 means the untruncated algorithm,
824 * whatever its length is. The length is encoded in 6 bits, so it can
825 * reach up to 63; the largest MAC is 64 bytes so its trivial truncation
826 * to full length is correctly encoded as 0 and any non-trivial truncation
827 * is correctly encoded as a value between 1 and 63. */
828 #define PSA_ALG_MAC_TRUNCATION_MASK ((psa_algorithm_t)0x00003f00)
829 #define PSA_MAC_TRUNCATION_OFFSET 8
830
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))
867
880 #define PSA_ALG_FULL_LENGTH_MAC(mac_alg) \
881 ((mac_alg) & ~PSA_ALG_MAC_TRUNCATION_MASK)
882
894 #define PSA_MAC_TRUNCATED_LENGTH(mac_alg) \
895 (((mac_alg) & PSA_ALG_MAC_TRUNCATION_MASK) >> PSA_MAC_TRUNCATION_OFFSET)
896
897 #define PSA_ALG_CIPHER_MAC_BASE ((psa_algorithm_t)0x02c00000)
898
903 #define PSA_ALG_CBC_MAC ((psa_algorithm_t)0x02c00001)
904
905 #define PSA_ALG_CMAC ((psa_algorithm_t)0x02c00002)
906
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)
918
919 #define PSA_ALG_CIPHER_STREAM_FLAG ((psa_algorithm_t)0x00800000)
920 #define PSA_ALG_CIPHER_FROM_BLOCK_FLAG ((psa_algorithm_t)0x00400000)
921
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))
937
940 #define PSA_ALG_ARC4 ((psa_algorithm_t)0x04800001)
941
952 #define PSA_ALG_CHACHA20 ((psa_algorithm_t)0x04800005)
953
961 #define PSA_ALG_CTR ((psa_algorithm_t)0x04c00001)
962
967 #define PSA_ALG_CFB ((psa_algorithm_t)0x04c00002)
968
973 #define PSA_ALG_OFB ((psa_algorithm_t)0x04c00003)
974
981 #define PSA_ALG_XTS ((psa_algorithm_t)0x044000ff)
982
990 #define PSA_ALG_CBC_NO_PADDING ((psa_algorithm_t)0x04600100)
991
998 #define PSA_ALG_CBC_PKCS7 ((psa_algorithm_t)0x04600101)
999
1000 #define PSA_ALG_AEAD_FROM_BLOCK_FLAG ((psa_algorithm_t)0x00400000)
1001
1011 #define PSA_ALG_IS_AEAD_ON_BLOCK_CIPHER(alg) \
1012 (((alg) & (PSA_ALG_CATEGORY_MASK | PSA_ALG_AEAD_FROM_BLOCK_FLAG)) == \
1013 (PSA_ALG_CATEGORY_AEAD | PSA_ALG_AEAD_FROM_BLOCK_FLAG))
1014
1019 #define PSA_ALG_CCM ((psa_algorithm_t)0x06401001)
1020
1025 #define PSA_ALG_GCM ((psa_algorithm_t)0x06401002)
1026
1036 #define PSA_ALG_CHACHA20_POLY1305 ((psa_algorithm_t)0x06001005)
1037
1038 /* In the encoding of a AEAD algorithm, the bits corresponding to
1039 * PSA_ALG_AEAD_TAG_LENGTH_MASK encode the length of the AEAD tag.
1040 * The constants for default lengths follow this encoding.
1041 */
1042 #define PSA_ALG_AEAD_TAG_LENGTH_MASK ((psa_algorithm_t)0x00003f00)
1043 #define PSA_AEAD_TAG_LENGTH_OFFSET 8
1044
1063 #define PSA_ALG_AEAD_WITH_TAG_LENGTH(aead_alg, tag_length) \
1064 (((aead_alg) & ~PSA_ALG_AEAD_TAG_LENGTH_MASK) | \
1065 ((tag_length) << PSA_AEAD_TAG_LENGTH_OFFSET & \
1066 PSA_ALG_AEAD_TAG_LENGTH_MASK))
1067
1076 #define PSA_ALG_AEAD_WITH_DEFAULT_TAG_LENGTH(aead_alg) \
1077 ( \
1078 PSA_ALG_AEAD_WITH_DEFAULT_TAG_LENGTH_CASE(aead_alg, PSA_ALG_CCM) \
1079 PSA_ALG_AEAD_WITH_DEFAULT_TAG_LENGTH_CASE(aead_alg, PSA_ALG_GCM) \
1080 PSA_ALG_AEAD_WITH_DEFAULT_TAG_LENGTH_CASE(aead_alg, PSA_ALG_CHACHA20_POLY1305) \
1081 0)
1082 #define PSA_ALG_AEAD_WITH_DEFAULT_TAG_LENGTH_CASE(aead_alg, ref) \
1083 PSA_ALG_AEAD_WITH_TAG_LENGTH(aead_alg, 0) == \
1084 PSA_ALG_AEAD_WITH_TAG_LENGTH(ref, 0) ? \
1085 ref :
1086
1087 #define PSA_ALG_RSA_PKCS1V15_SIGN_BASE ((psa_algorithm_t)0x10020000)
1088
1103 #define PSA_ALG_RSA_PKCS1V15_SIGN(hash_alg) \
1104 (PSA_ALG_RSA_PKCS1V15_SIGN_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
1105
1111 #define PSA_ALG_RSA_PKCS1V15_SIGN_RAW PSA_ALG_RSA_PKCS1V15_SIGN_BASE
1112 #define PSA_ALG_IS_RSA_PKCS1V15_SIGN(alg) \
1113 (((alg) & ~PSA_ALG_HASH_MASK) == PSA_ALG_RSA_PKCS1V15_SIGN_BASE)
1114
1115 #define PSA_ALG_RSA_PSS_BASE ((psa_algorithm_t)0x10030000)
1116
1134 #define PSA_ALG_RSA_PSS(hash_alg) \
1135 (PSA_ALG_RSA_PSS_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
1136 #define PSA_ALG_IS_RSA_PSS(alg) \
1137 (((alg) & ~PSA_ALG_HASH_MASK) == PSA_ALG_RSA_PSS_BASE)
1138
1139 #define PSA_ALG_ECDSA_BASE ((psa_algorithm_t)0x10060000)
1140
1160 #define PSA_ALG_ECDSA(hash_alg) \
1161 (PSA_ALG_ECDSA_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
1162
1171 #define PSA_ALG_ECDSA_ANY PSA_ALG_ECDSA_BASE
1172 #define PSA_ALG_DETERMINISTIC_ECDSA_BASE ((psa_algorithm_t)0x10070000)
1173
1195 #define PSA_ALG_DETERMINISTIC_ECDSA(hash_alg) \
1196 (PSA_ALG_DETERMINISTIC_ECDSA_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
1197 #define PSA_ALG_ECDSA_DETERMINISTIC_FLAG ((psa_algorithm_t)0x00010000)
1198 #define PSA_ALG_IS_ECDSA(alg) \
1199 (((alg) & ~PSA_ALG_HASH_MASK & ~PSA_ALG_ECDSA_DETERMINISTIC_FLAG) == \
1200 PSA_ALG_ECDSA_BASE)
1201 #define PSA_ALG_ECDSA_IS_DETERMINISTIC(alg) \
1202 (((alg) & PSA_ALG_ECDSA_DETERMINISTIC_FLAG) != 0)
1203 #define PSA_ALG_IS_DETERMINISTIC_ECDSA(alg) \
1204 (PSA_ALG_IS_ECDSA(alg) && PSA_ALG_ECDSA_IS_DETERMINISTIC(alg))
1205 #define PSA_ALG_IS_RANDOMIZED_ECDSA(alg) \
1206 (PSA_ALG_IS_ECDSA(alg) && !PSA_ALG_ECDSA_IS_DETERMINISTIC(alg))
1207
1221 #define PSA_ALG_IS_HASH_AND_SIGN(alg) \
1222 (PSA_ALG_IS_RSA_PSS(alg) || PSA_ALG_IS_RSA_PKCS1V15_SIGN(alg) || \
1223 PSA_ALG_IS_ECDSA(alg))
1224
1243 #define PSA_ALG_SIGN_GET_HASH(alg) \
1244 (PSA_ALG_IS_HASH_AND_SIGN(alg) ? \
1245 ((alg) & PSA_ALG_HASH_MASK) == 0 ? /*"raw" algorithm*/ 0 : \
1246 ((alg) & PSA_ALG_HASH_MASK) | PSA_ALG_CATEGORY_HASH : \
1247 0)
1248
1251 #define PSA_ALG_RSA_PKCS1V15_CRYPT ((psa_algorithm_t)0x12020000)
1252
1253 #define PSA_ALG_RSA_OAEP_BASE ((psa_algorithm_t)0x12030000)
1254
1268 #define PSA_ALG_RSA_OAEP(hash_alg) \
1269 (PSA_ALG_RSA_OAEP_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
1270 #define PSA_ALG_IS_RSA_OAEP(alg) \
1271 (((alg) & ~PSA_ALG_HASH_MASK) == PSA_ALG_RSA_OAEP_BASE)
1272 #define PSA_ALG_RSA_OAEP_GET_HASH(alg) \
1273 (PSA_ALG_IS_RSA_OAEP(alg) ? \
1274 ((alg) & PSA_ALG_HASH_MASK) | PSA_ALG_CATEGORY_HASH : \
1275 0)
1276
1277 #define PSA_ALG_HKDF_BASE ((psa_algorithm_t)0x20000100)
1278
1298 #define PSA_ALG_HKDF(hash_alg) \
1299 (PSA_ALG_HKDF_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
1300
1311 #define PSA_ALG_IS_HKDF(alg) \
1312 (((alg) & ~PSA_ALG_HASH_MASK) == PSA_ALG_HKDF_BASE)
1313 #define PSA_ALG_HKDF_GET_HASH(hkdf_alg) \
1314 (PSA_ALG_CATEGORY_HASH | ((hkdf_alg) & PSA_ALG_HASH_MASK))
1315
1316 #define PSA_ALG_TLS12_PRF_BASE ((psa_algorithm_t)0x20000200)
1317
1343 #define PSA_ALG_TLS12_PRF(hash_alg) \
1344 (PSA_ALG_TLS12_PRF_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
1345
1354 #define PSA_ALG_IS_TLS12_PRF(alg) \
1355 (((alg) & ~PSA_ALG_HASH_MASK) == PSA_ALG_TLS12_PRF_BASE)
1356 #define PSA_ALG_TLS12_PRF_GET_HASH(hkdf_alg) \
1357 (PSA_ALG_CATEGORY_HASH | ((hkdf_alg) & PSA_ALG_HASH_MASK))
1358
1359 #define PSA_ALG_TLS12_PSK_TO_MS_BASE ((psa_algorithm_t)0x20000300)
1360
1389 #define PSA_ALG_TLS12_PSK_TO_MS(hash_alg) \
1390 (PSA_ALG_TLS12_PSK_TO_MS_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
1391
1400 #define PSA_ALG_IS_TLS12_PSK_TO_MS(alg) \
1401 (((alg) & ~PSA_ALG_HASH_MASK) == PSA_ALG_TLS12_PSK_TO_MS_BASE)
1402 #define PSA_ALG_TLS12_PSK_TO_MS_GET_HASH(hkdf_alg) \
1403 (PSA_ALG_CATEGORY_HASH | ((hkdf_alg) & PSA_ALG_HASH_MASK))
1404
1405 #define PSA_ALG_KEY_DERIVATION_MASK ((psa_algorithm_t)0x0803ffff)
1406 #define PSA_ALG_KEY_AGREEMENT_MASK ((psa_algorithm_t)0x10fc0000)
1407
1422 #define PSA_ALG_KEY_AGREEMENT(ka_alg, kdf_alg) \
1423 ((ka_alg) | (kdf_alg))
1424
1425 #define PSA_ALG_KEY_AGREEMENT_GET_KDF(alg) \
1426 (((alg) & PSA_ALG_KEY_DERIVATION_MASK) | PSA_ALG_CATEGORY_KEY_DERIVATION)
1427
1428 #define PSA_ALG_KEY_AGREEMENT_GET_BASE(alg) \
1429 (((alg) & PSA_ALG_KEY_AGREEMENT_MASK) | PSA_ALG_CATEGORY_KEY_AGREEMENT)
1430
1445 #define PSA_ALG_IS_RAW_KEY_AGREEMENT(alg) \
1446 (PSA_ALG_IS_KEY_AGREEMENT(alg) && \
1447 PSA_ALG_KEY_AGREEMENT_GET_KDF(alg) == PSA_ALG_CATEGORY_KEY_DERIVATION)
1448
1449 #define PSA_ALG_IS_KEY_DERIVATION_OR_AGREEMENT(alg) \
1450 ((PSA_ALG_IS_KEY_DERIVATION(alg) || PSA_ALG_IS_KEY_AGREEMENT(alg)))
1451
1459 #define PSA_ALG_FFDH ((psa_algorithm_t)0x30100000)
1460
1473 #define PSA_ALG_IS_FFDH(alg) \
1474 (PSA_ALG_KEY_AGREEMENT_GET_BASE(alg) == PSA_ALG_FFDH)
1475
1501 #define PSA_ALG_ECDH ((psa_algorithm_t)0x30200000)
1502
1517 #define PSA_ALG_IS_ECDH(alg) \
1518 (PSA_ALG_KEY_AGREEMENT_GET_BASE(alg) == PSA_ALG_ECDH)
1519
1533 #define PSA_ALG_IS_WILDCARD(alg) \
1534 (PSA_ALG_IS_HASH_AND_SIGN(alg) ? \
1535 PSA_ALG_SIGN_GET_HASH(alg) == PSA_ALG_ANY_HASH : \
1536 (alg) == PSA_ALG_ANY_HASH)
1537
1555 #define PSA_KEY_LIFETIME_VOLATILE ((psa_key_lifetime_t)0x00000000)
1556
1570 #define PSA_KEY_LIFETIME_PERSISTENT ((psa_key_lifetime_t)0x00000001)
1571
1576 #define PSA_KEY_PERSISTENCE_VOLATILE ((psa_key_persistence_t)0x00)
1577
1582 #define PSA_KEY_PERSISTENCE_DEFAULT ((psa_key_persistence_t)0x01)
1583
1588 #define PSA_KEY_PERSISTENCE_READ_ONLY ((psa_key_persistence_t)0xff)
1589
1590 #define PSA_KEY_LIFETIME_GET_PERSISTENCE(lifetime) \
1591 ((psa_key_persistence_t)((lifetime) & 0x000000ff))
1592
1593 #define PSA_KEY_LIFETIME_GET_LOCATION(lifetime) \
1594 ((psa_key_location_t)((lifetime) >> 8))
1595
1612 #define PSA_KEY_LIFETIME_IS_VOLATILE(lifetime) \
1613 (PSA_KEY_LIFETIME_GET_PERSISTENCE(lifetime) == \
1614 PSA_KEY_LIFETIME_PERSISTENCE_VOLATILE)
1615
1625 #define PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(persistence, location) \
1626 ((location) << 8 | (persistence))
1627
1635 #define PSA_KEY_LOCATION_LOCAL_STORAGE ((psa_key_location_t)0x000000)
1636
1637 #define PSA_KEY_LOCATION_VENDOR_FLAG ((psa_key_location_t)0x800000)
1638
1641 #define PSA_KEY_ID_USER_MIN ((psa_app_key_id_t)0x00000001)
1642
1644 #define PSA_KEY_ID_USER_MAX ((psa_app_key_id_t)0x3fffffff)
1645
1647 #define PSA_KEY_ID_VENDOR_MIN ((psa_app_key_id_t)0x40000000)
1648
1650 #define PSA_KEY_ID_VENDOR_MAX ((psa_app_key_id_t)0x7fffffff)
1651
1669 #define PSA_KEY_USAGE_EXPORT ((psa_key_usage_t)0x00000001)
1670
1685 #define PSA_KEY_USAGE_COPY ((psa_key_usage_t)0x00000002)
1686
1696 #define PSA_KEY_USAGE_ENCRYPT ((psa_key_usage_t)0x00000100)
1697
1707 #define PSA_KEY_USAGE_DECRYPT ((psa_key_usage_t)0x00000200)
1708
1717 #define PSA_KEY_USAGE_SIGN_HASH ((psa_key_usage_t)0x00000400)
1718
1727 #define PSA_KEY_USAGE_VERIFY_HASH ((psa_key_usage_t)0x00000800)
1728
1731 #define PSA_KEY_USAGE_DERIVE ((psa_key_usage_t)0x00001000)
1732
1751 #define PSA_KEY_DERIVATION_INPUT_SECRET ((psa_key_derivation_step_t)0x0101)
1752
1758 #define PSA_KEY_DERIVATION_INPUT_LABEL ((psa_key_derivation_step_t)0x0201)
1759
1765 #define PSA_KEY_DERIVATION_INPUT_SALT ((psa_key_derivation_step_t)0x0202)
1766
1772 #define PSA_KEY_DERIVATION_INPUT_INFO ((psa_key_derivation_step_t)0x0203)
1773
1779 #define PSA_KEY_DERIVATION_INPUT_SEED ((psa_key_derivation_step_t)0x0204)
1780
1783 #endif /* PSA_CRYPTO_VALUES_H */