|
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 | +/** Allow any hash algorithm. |
| 672 | + * |
| 673 | + * This value may only be used to form the algorithm usage field of a policy |
| 674 | + * for a signature algorithm that is parametrized by a hash. That is, |
| 675 | + * suppose that `PSA_xxx_SIGNATURE` is one of the following macros: |
| 676 | + * - #PSA_ALG_RSA_PKCS1V15_SIGN, #PSA_ALG_RSA_PSS, |
| 677 | + * - #PSA_ALG_DSA, #PSA_ALG_DETERMINISTIC_DSA, |
| 678 | + * - #PSA_ALG_ECDSA, #PSA_ALG_DETERMINISTIC_ECDSA. |
| 679 | + * Then you may create a key as follows: |
| 680 | + * - Set the key usage field using #PSA_ALG_ANY_HASH, for example: |
| 681 | + * ``` |
| 682 | + * psa_key_policy_set_usage(&policy, |
| 683 | + * PSA_KEY_USAGE_SIGN, //or PSA_KEY_USAGE_VERIFY |
| 684 | + * PSA_xxx_SIGNATURE(PSA_ALG_ANY_HASH)); |
| 685 | + * psa_set_key_policy(handle, &policy); |
| 686 | + * ``` |
| 687 | + * - Import or generate key material. |
| 688 | + * - Call psa_asymmetric_sign() or psa_asymmetric_verify(), passing |
| 689 | + * an algorithm built from `PSA_xxx_SIGNATURE` and a specific hash. Each |
| 690 | + * call to sign or verify a message may use a different hash. |
| 691 | + * ``` |
| 692 | + * psa_asymmetric_sign(handle, PSA_xxx_SIGNATURE(PSA_ALG_SHA_256), ...); |
| 693 | + * psa_asymmetric_sign(handle, PSA_xxx_SIGNATURE(PSA_ALG_SHA_512), ...); |
| 694 | + * psa_asymmetric_sign(handle, PSA_xxx_SIGNATURE(PSA_ALG_SHA3_256), ...); |
| 695 | + * ``` |
| 696 | + * |
| 697 | + * This value may not be used to build other algorithms that are |
| 698 | + * parametrized over a hash. For any valid use of this macro to build |
| 699 | + * an algorithm `\p alg`, #PSA_ALG_IS_HASH_AND_SIGN(\p alg) is true. |
| 700 | + * |
| 701 | + * This value may not be used to build an algorithm specification to |
| 702 | + * perform an operation. It is only valid to build policies. |
| 703 | + */ |
| 704 | +#define PSA_ALG_ANY_HASH ((psa_algorithm_t)0x010000ff) |
| 705 | + |
670 | 706 | #define PSA_ALG_MAC_SUBCATEGORY_MASK ((psa_algorithm_t)0x00c00000)
|
671 | 707 | #define PSA_ALG_HMAC_BASE ((psa_algorithm_t)0x02800000)
|
672 | 708 | /** Macro to build an HMAC algorithm.
|
|
914 | 950 | *
|
915 | 951 | * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that
|
916 | 952 | * #PSA_ALG_IS_HASH(\p hash_alg) is true).
|
| 953 | + * This includes #PSA_ALG_ANY_HASH |
| 954 | + * when specifying the algorithm in a usage policy. |
917 | 955 | *
|
918 | 956 | * \return The corresponding RSA PKCS#1 v1.5 signature algorithm.
|
919 | 957 | * \return Unspecified if \p alg is not a supported
|
|
943 | 981 | *
|
944 | 982 | * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that
|
945 | 983 | * #PSA_ALG_IS_HASH(\p hash_alg) is true).
|
| 984 | + * This includes #PSA_ALG_ANY_HASH |
| 985 | + * when specifying the algorithm in a usage policy. |
946 | 986 | *
|
947 | 987 | * \return The corresponding RSA PSS signature algorithm.
|
948 | 988 | * \return Unspecified if \p alg is not a supported
|
|
961 | 1001 | *
|
962 | 1002 | * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that
|
963 | 1003 | * #PSA_ALG_IS_HASH(\p hash_alg) is true).
|
| 1004 | + * This includes #PSA_ALG_ANY_HASH |
| 1005 | + * when specifying the algorithm in a usage policy. |
964 | 1006 | *
|
965 | 1007 | * \return The corresponding DSA signature algorithm.
|
966 | 1008 | * \return Unspecified if \p alg is not a supported
|
|
996 | 1038 | *
|
997 | 1039 | * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that
|
998 | 1040 | * #PSA_ALG_IS_HASH(\p hash_alg) is true).
|
| 1041 | + * This includes #PSA_ALG_ANY_HASH |
| 1042 | + * when specifying the algorithm in a usage policy. |
999 | 1043 | *
|
1000 | 1044 | * \return The corresponding ECDSA signature algorithm.
|
1001 | 1045 | * \return Unspecified if \p alg is not a supported
|
|
1028 | 1072 | *
|
1029 | 1073 | * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that
|
1030 | 1074 | * #PSA_ALG_IS_HASH(\p hash_alg) is true).
|
| 1075 | + * This includes #PSA_ALG_ANY_HASH |
| 1076 | + * when specifying the algorithm in a usage policy. |
1031 | 1077 | *
|
1032 | 1078 | * \return The corresponding deterministic ECDSA signature
|
1033 | 1079 | * algorithm.
|
|
1341 | 1387 | #define PSA_ALG_IS_ECDH(alg) \
|
1342 | 1388 | (PSA_ALG_KEY_AGREEMENT_GET_BASE(alg) == PSA_ALG_ECDH_BASE)
|
1343 | 1389 |
|
| 1390 | +/** Whether the specified algorithm encoding is a wildcard. |
| 1391 | + * |
| 1392 | + * Wildcard values may only be used to set the usage algorithm field in |
| 1393 | + * a policy, not to perform an operation. |
| 1394 | + * |
| 1395 | + * \param alg An algorithm identifier (value of type #psa_algorithm_t). |
| 1396 | + * |
| 1397 | + * \return 1 if \c alg is a wildcard algorithm encoding. |
| 1398 | + * \return 0 if \c alg is a non-wildcard algorithm encoding (suitable for |
| 1399 | + * an operation). |
| 1400 | + * \return This macro may return either 0 or 1 if \c alg is not a supported |
| 1401 | + * algorithm identifier. |
| 1402 | + */ |
| 1403 | +#define PSA_ALG_IS_WILDCARD(alg) \ |
| 1404 | + (PSA_ALG_IS_HASH_AND_SIGN(alg) ? \ |
| 1405 | + PSA_ALG_SIGN_GET_HASH(alg) == PSA_ALG_ANY_HASH : \ |
| 1406 | + (alg) == PSA_ALG_ANY_HASH) |
| 1407 | + |
1344 | 1408 | /**@}*/
|
1345 | 1409 |
|
1346 | 1410 | /** \defgroup key_lifetimes Key lifetimes
|
|
0 commit comments