|
641 | 641 | (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_KEY_SELECTION)
|
642 | 642 |
|
643 | 643 | #define PSA_ALG_HASH_MASK ((psa_algorithm_t)0x000000ff)
|
| 644 | + |
644 | 645 | #define PSA_ALG_MD2 ((psa_algorithm_t)0x01000001)
|
645 | 646 | #define PSA_ALG_MD4 ((psa_algorithm_t)0x01000002)
|
646 | 647 | #define PSA_ALG_MD5 ((psa_algorithm_t)0x01000003)
|
|
667 | 668 | /** SHA3-512 */
|
668 | 669 | #define PSA_ALG_SHA3_512 ((psa_algorithm_t)0x01000013)
|
669 | 670 |
|
| 671 | +/** In a hash-and-sign algorithm policy, allow any hash algorithm. |
| 672 | + * |
| 673 | + * This value may be used to form the algorithm usage field of a policy |
| 674 | + * for a signature algorithm that is parametrized by a hash. The key |
| 675 | + * may then be used to perform operations using the same signature |
| 676 | + * algorithm parametrized with any supported hash. |
| 677 | + * |
| 678 | + * That is, suppose that `PSA_xxx_SIGNATURE` is one of the following macros: |
| 679 | + * - #PSA_ALG_RSA_PKCS1V15_SIGN, #PSA_ALG_RSA_PSS, |
| 680 | + * - #PSA_ALG_DSA, #PSA_ALG_DETERMINISTIC_DSA, |
| 681 | + * - #PSA_ALG_ECDSA, #PSA_ALG_DETERMINISTIC_ECDSA. |
| 682 | + * Then you may create and use a key as follows: |
| 683 | + * - Set the key usage field using #PSA_ALG_ANY_HASH, for example: |
| 684 | + * ``` |
| 685 | + * psa_key_policy_set_usage(&policy, |
| 686 | + * PSA_KEY_USAGE_SIGN, //or PSA_KEY_USAGE_VERIFY |
| 687 | + * PSA_xxx_SIGNATURE(PSA_ALG_ANY_HASH)); |
| 688 | + * psa_set_key_policy(handle, &policy); |
| 689 | + * ``` |
| 690 | + * - Import or generate key material. |
| 691 | + * - Call psa_asymmetric_sign() or psa_asymmetric_verify(), passing |
| 692 | + * an algorithm built from `PSA_xxx_SIGNATURE` and a specific hash. Each |
| 693 | + * call to sign or verify a message may use a different hash. |
| 694 | + * ``` |
| 695 | + * psa_asymmetric_sign(handle, PSA_xxx_SIGNATURE(PSA_ALG_SHA_256), ...); |
| 696 | + * psa_asymmetric_sign(handle, PSA_xxx_SIGNATURE(PSA_ALG_SHA_512), ...); |
| 697 | + * psa_asymmetric_sign(handle, PSA_xxx_SIGNATURE(PSA_ALG_SHA3_256), ...); |
| 698 | + * ``` |
| 699 | + * |
| 700 | + * This value may not be used to build other algorithms that are |
| 701 | + * parametrized over a hash. For any valid use of this macro to build |
| 702 | + * an algorithm `\p alg`, #PSA_ALG_IS_HASH_AND_SIGN(\p alg) is true. |
| 703 | + * |
| 704 | + * This value may not be used to build an algorithm specification to |
| 705 | + * perform an operation. It is only valid to build policies. |
| 706 | + */ |
| 707 | +#define PSA_ALG_ANY_HASH ((psa_algorithm_t)0x010000ff) |
| 708 | + |
670 | 709 | #define PSA_ALG_MAC_SUBCATEGORY_MASK ((psa_algorithm_t)0x00c00000)
|
671 | 710 | #define PSA_ALG_HMAC_BASE ((psa_algorithm_t)0x02800000)
|
672 | 711 | /** Macro to build an HMAC algorithm.
|
|
914 | 953 | *
|
915 | 954 | * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that
|
916 | 955 | * #PSA_ALG_IS_HASH(\p hash_alg) is true).
|
| 956 | + * This includes #PSA_ALG_ANY_HASH |
| 957 | + * when specifying the algorithm in a usage policy. |
917 | 958 | *
|
918 | 959 | * \return The corresponding RSA PKCS#1 v1.5 signature algorithm.
|
919 | 960 | * \return Unspecified if \p alg is not a supported
|
|
943 | 984 | *
|
944 | 985 | * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that
|
945 | 986 | * #PSA_ALG_IS_HASH(\p hash_alg) is true).
|
| 987 | + * This includes #PSA_ALG_ANY_HASH |
| 988 | + * when specifying the algorithm in a usage policy. |
946 | 989 | *
|
947 | 990 | * \return The corresponding RSA PSS signature algorithm.
|
948 | 991 | * \return Unspecified if \p alg is not a supported
|
|
961 | 1004 | *
|
962 | 1005 | * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that
|
963 | 1006 | * #PSA_ALG_IS_HASH(\p hash_alg) is true).
|
| 1007 | + * This includes #PSA_ALG_ANY_HASH |
| 1008 | + * when specifying the algorithm in a usage policy. |
964 | 1009 | *
|
965 | 1010 | * \return The corresponding DSA signature algorithm.
|
966 | 1011 | * \return Unspecified if \p alg is not a supported
|
|
996 | 1041 | *
|
997 | 1042 | * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that
|
998 | 1043 | * #PSA_ALG_IS_HASH(\p hash_alg) is true).
|
| 1044 | + * This includes #PSA_ALG_ANY_HASH |
| 1045 | + * when specifying the algorithm in a usage policy. |
999 | 1046 | *
|
1000 | 1047 | * \return The corresponding ECDSA signature algorithm.
|
1001 | 1048 | * \return Unspecified if \p alg is not a supported
|
|
1028 | 1075 | *
|
1029 | 1076 | * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that
|
1030 | 1077 | * #PSA_ALG_IS_HASH(\p hash_alg) is true).
|
| 1078 | + * This includes #PSA_ALG_ANY_HASH |
| 1079 | + * when specifying the algorithm in a usage policy. |
1031 | 1080 | *
|
1032 | 1081 | * \return The corresponding deterministic ECDSA signature
|
1033 | 1082 | * algorithm.
|
|
1046 | 1095 | #define PSA_ALG_IS_RANDOMIZED_ECDSA(alg) \
|
1047 | 1096 | (PSA_ALG_IS_ECDSA(alg) && !PSA_ALG_ECDSA_IS_DETERMINISTIC(alg))
|
1048 | 1097 |
|
| 1098 | +/** Whether the specified algorithm is a hash-and-sign algorithm. |
| 1099 | + * |
| 1100 | + * Hash-and-sign algorithms are public-key signature algorithms structured |
| 1101 | + * in two parts: first the calculation of a hash in a way that does not |
| 1102 | + * depend on the key, then the calculation of a signature from the |
| 1103 | + * hash value and the key. |
| 1104 | + * |
| 1105 | + * \param alg An algorithm identifier (value of type #psa_algorithm_t). |
| 1106 | + * |
| 1107 | + * \return 1 if \p alg is a hash-and-sign algorithm, 0 otherwise. |
| 1108 | + * This macro may return either 0 or 1 if \p alg is not a supported |
| 1109 | + * algorithm identifier. |
| 1110 | + */ |
| 1111 | +#define PSA_ALG_IS_HASH_AND_SIGN(alg) \ |
| 1112 | + (PSA_ALG_IS_RSA_PSS(alg) || PSA_ALG_IS_RSA_PKCS1V15_SIGN(alg) || \ |
| 1113 | + PSA_ALG_IS_DSA(alg) || PSA_ALG_IS_ECDSA(alg)) |
| 1114 | + |
1049 | 1115 | /** Get the hash used by a hash-and-sign signature algorithm.
|
1050 | 1116 | *
|
1051 | 1117 | * A hash-and-sign algorithm is a signature algorithm which is
|
|
1065 | 1131 | * if it is not supported by the implementation.
|
1066 | 1132 | */
|
1067 | 1133 | #define PSA_ALG_SIGN_GET_HASH(alg) \
|
1068 |
| - (PSA_ALG_IS_RSA_PSS(alg) || PSA_ALG_IS_RSA_PKCS1V15_SIGN(alg) || \ |
1069 |
| - PSA_ALG_IS_DSA(alg) || PSA_ALG_IS_ECDSA(alg) ? \ |
| 1134 | + (PSA_ALG_IS_HASH_AND_SIGN(alg) ? \ |
1070 | 1135 | ((alg) & PSA_ALG_HASH_MASK) == 0 ? /*"raw" algorithm*/ 0 : \
|
1071 | 1136 | ((alg) & PSA_ALG_HASH_MASK) | PSA_ALG_CATEGORY_HASH : \
|
1072 | 1137 | 0)
|
|
1325 | 1390 | #define PSA_ALG_IS_ECDH(alg) \
|
1326 | 1391 | (PSA_ALG_KEY_AGREEMENT_GET_BASE(alg) == PSA_ALG_ECDH_BASE)
|
1327 | 1392 |
|
| 1393 | +/** Whether the specified algorithm encoding is a wildcard. |
| 1394 | + * |
| 1395 | + * Wildcard values may only be used to set the usage algorithm field in |
| 1396 | + * a policy, not to perform an operation. |
| 1397 | + * |
| 1398 | + * \param alg An algorithm identifier (value of type #psa_algorithm_t). |
| 1399 | + * |
| 1400 | + * \return 1 if \c alg is a wildcard algorithm encoding. |
| 1401 | + * \return 0 if \c alg is a non-wildcard algorithm encoding (suitable for |
| 1402 | + * an operation). |
| 1403 | + * \return This macro may return either 0 or 1 if \c alg is not a supported |
| 1404 | + * algorithm identifier. |
| 1405 | + */ |
| 1406 | +#define PSA_ALG_IS_WILDCARD(alg) \ |
| 1407 | + (PSA_ALG_IS_HASH_AND_SIGN(alg) ? \ |
| 1408 | + PSA_ALG_SIGN_GET_HASH(alg) == PSA_ALG_ANY_HASH : \ |
| 1409 | + (alg) == PSA_ALG_ANY_HASH) |
| 1410 | + |
1328 | 1411 | /**@}*/
|
1329 | 1412 |
|
1330 | 1413 | /** \defgroup key_lifetimes Key lifetimes
|
|
0 commit comments