mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2025-01-24 21:21:07 +00:00
Language & readability touchups
Signed-off-by: Steven Cooreman <steven.cooreman@silabs.com>
This commit is contained in:
parent
d788fab4ff
commit
328f11c50e
|
@ -868,7 +868,8 @@
|
|||
|
||||
/* In the encoding of a MAC algorithm, the bit corresponding to
|
||||
* #PSA_ALG_MAC_AT_LEAST_THIS_LENGTH_FLAG encodes the fact that the algorithm
|
||||
* is a wildcard algorithm, which allows any algorithm corresponding to the
|
||||
* is a wildcard algorithm. A key with such wildcard algorithm as permitted
|
||||
* algorithm policy can be used with any algorithm corresponding to the
|
||||
* same base class and having a (potentially truncated) MAC length greater or
|
||||
* equal than the one encoded in #PSA_ALG_MAC_TRUNCATION_MASK. */
|
||||
#define PSA_ALG_MAC_AT_LEAST_THIS_LENGTH_FLAG ((psa_algorithm_t)0x00008000)
|
||||
|
@ -906,8 +907,9 @@
|
|||
* MAC algorithm or if \p mac_length is too small or
|
||||
* too large for the specified MAC algorithm.
|
||||
*/
|
||||
#define PSA_ALG_TRUNCATED_MAC(mac_alg, mac_length) \
|
||||
(((mac_alg) & ~(PSA_ALG_MAC_TRUNCATION_MASK | PSA_ALG_MAC_AT_LEAST_THIS_LENGTH_FLAG)) | \
|
||||
#define PSA_ALG_TRUNCATED_MAC(mac_alg, mac_length) \
|
||||
(((mac_alg) & ~(PSA_ALG_MAC_TRUNCATION_MASK | \
|
||||
PSA_ALG_MAC_AT_LEAST_THIS_LENGTH_FLAG)) | \
|
||||
((mac_length) << PSA_MAC_TRUNCATION_OFFSET & PSA_ALG_MAC_TRUNCATION_MASK))
|
||||
|
||||
/** Macro to build the base MAC algorithm corresponding to a truncated
|
||||
|
@ -922,8 +924,9 @@
|
|||
* \return Unspecified if \p alg is not a supported
|
||||
* MAC algorithm.
|
||||
*/
|
||||
#define PSA_ALG_FULL_LENGTH_MAC(mac_alg) \
|
||||
((mac_alg) & ~(PSA_ALG_MAC_TRUNCATION_MASK | PSA_ALG_MAC_AT_LEAST_THIS_LENGTH_FLAG))
|
||||
#define PSA_ALG_FULL_LENGTH_MAC(mac_alg) \
|
||||
((mac_alg) & ~(PSA_ALG_MAC_TRUNCATION_MASK | \
|
||||
PSA_ALG_MAC_AT_LEAST_THIS_LENGTH_FLAG))
|
||||
|
||||
/** Length to which a MAC algorithm is truncated.
|
||||
*
|
||||
|
@ -963,8 +966,9 @@
|
|||
* algorithm or if \p min_mac_length is less than 1 or
|
||||
* too large for the specified MAC algorithm.
|
||||
*/
|
||||
#define PSA_ALG_AT_LEAST_THIS_LENGTH_MAC(mac_alg, min_mac_length) \
|
||||
( PSA_ALG_TRUNCATED_MAC(mac_alg, min_mac_length) | PSA_ALG_MAC_AT_LEAST_THIS_LENGTH_FLAG )
|
||||
#define PSA_ALG_AT_LEAST_THIS_LENGTH_MAC(mac_alg, min_mac_length) \
|
||||
( PSA_ALG_TRUNCATED_MAC(mac_alg, min_mac_length) | \
|
||||
PSA_ALG_MAC_AT_LEAST_THIS_LENGTH_FLAG )
|
||||
|
||||
#define PSA_ALG_CIPHER_MAC_BASE ((psa_algorithm_t)0x03c00000)
|
||||
/** The CBC-MAC construction over a block cipher
|
||||
|
@ -1128,7 +1132,8 @@
|
|||
|
||||
/* In the encoding of an AEAD algorithm, the bit corresponding to
|
||||
* #PSA_ALG_AEAD_AT_LEAST_THIS_LENGTH_FLAG encodes the fact that the algorithm
|
||||
* is a wildcard algorithm, which allows any algorithm corresponding to the
|
||||
* is a wildcard algorithm. A key with such wildcard algorithm as permitted
|
||||
* algorithm policy can be used with any algorithm corresponding to the
|
||||
* same base class and having a tag length greater than or equal to the one
|
||||
* encoded in #PSA_ALG_AEAD_TAG_LENGTH_MASK. */
|
||||
#define PSA_ALG_AEAD_AT_LEAST_THIS_LENGTH_FLAG ((psa_algorithm_t)0x00008000)
|
||||
|
@ -1152,7 +1157,8 @@
|
|||
* for the specified AEAD algorithm.
|
||||
*/
|
||||
#define PSA_ALG_AEAD_WITH_SHORTENED_TAG(aead_alg, tag_length) \
|
||||
(((aead_alg) & ~(PSA_ALG_AEAD_TAG_LENGTH_MASK | PSA_ALG_AEAD_AT_LEAST_THIS_LENGTH_FLAG)) | \
|
||||
(((aead_alg) & ~(PSA_ALG_AEAD_TAG_LENGTH_MASK | \
|
||||
PSA_ALG_AEAD_AT_LEAST_THIS_LENGTH_FLAG)) | \
|
||||
((tag_length) << PSA_AEAD_TAG_LENGTH_OFFSET & \
|
||||
PSA_ALG_AEAD_TAG_LENGTH_MASK))
|
||||
|
||||
|
@ -1215,7 +1221,8 @@
|
|||
* or too large for the specified AEAD algorithm.
|
||||
*/
|
||||
#define PSA_ALG_AEAD_WITH_AT_LEAST_THIS_LENGTH_TAG(aead_alg, min_tag_length) \
|
||||
( PSA_ALG_AEAD_WITH_SHORTENED_TAG(aead_alg, min_tag_length) | PSA_ALG_AEAD_AT_LEAST_THIS_LENGTH_FLAG )
|
||||
( PSA_ALG_AEAD_WITH_SHORTENED_TAG(aead_alg, min_tag_length) | \
|
||||
PSA_ALG_AEAD_AT_LEAST_THIS_LENGTH_FLAG )
|
||||
|
||||
#define PSA_ALG_RSA_PKCS1V15_SIGN_BASE ((psa_algorithm_t)0x06000200)
|
||||
/** RSA PKCS#1 v1.5 signature with hashing.
|
||||
|
|
|
@ -890,9 +890,11 @@ static psa_status_t psa_get_and_lock_key_slot_with_policy(
|
|||
if( PSA_KEY_TYPE_IS_PUBLIC_KEY( slot->attr.type ) )
|
||||
usage &= ~PSA_KEY_USAGE_EXPORT;
|
||||
|
||||
status = PSA_ERROR_NOT_PERMITTED;
|
||||
if( ( slot->attr.policy.usage & usage ) != usage )
|
||||
{
|
||||
status = PSA_ERROR_NOT_PERMITTED;
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* Enforce that the usage policy permits the requested algortihm. */
|
||||
if( alg != 0 )
|
||||
|
@ -2938,21 +2940,29 @@ static psa_status_t psa_mac_setup( psa_mac_operation_t *operation,
|
|||
* a corner case due to the default MAC length being unknown
|
||||
* at key loading time. */
|
||||
if( PSA_ALG_IS_MAC( slot->attr.policy.alg ) &&
|
||||
( PSA_ALG_FULL_LENGTH_MAC( slot->attr.policy.alg ) == full_length_alg ) &&
|
||||
( PSA_ALG_FULL_LENGTH_MAC( slot->attr.policy.alg ) ==
|
||||
full_length_alg ) &&
|
||||
( slot->attr.policy.alg & PSA_ALG_MAC_AT_LEAST_THIS_LENGTH_FLAG ) )
|
||||
{
|
||||
/* validate policy length */
|
||||
if( PSA_MAC_TRUNCATED_LENGTH( slot->attr.policy.alg ) > operation->mac_size )
|
||||
if( PSA_MAC_TRUNCATED_LENGTH( slot->attr.policy.alg ) >
|
||||
operation->mac_size )
|
||||
{
|
||||
status = PSA_ERROR_NOT_PERMITTED;
|
||||
}
|
||||
}
|
||||
|
||||
if( PSA_ALG_IS_MAC( slot->attr.policy.alg2 ) &&
|
||||
( PSA_ALG_FULL_LENGTH_MAC( slot->attr.policy.alg2 ) == full_length_alg ) &&
|
||||
( PSA_ALG_FULL_LENGTH_MAC( slot->attr.policy.alg2 ) ==
|
||||
full_length_alg ) &&
|
||||
( slot->attr.policy.alg2 & PSA_ALG_MAC_AT_LEAST_THIS_LENGTH_FLAG ) )
|
||||
{
|
||||
/* validate policy length */
|
||||
if( PSA_MAC_TRUNCATED_LENGTH( slot->attr.policy.alg2 ) > operation->mac_size )
|
||||
if( PSA_MAC_TRUNCATED_LENGTH( slot->attr.policy.alg2 ) >
|
||||
operation->mac_size )
|
||||
{
|
||||
status = PSA_ERROR_NOT_PERMITTED;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if( truncated < 4 )
|
||||
|
|
|
@ -428,43 +428,43 @@ PSA key policy: CMAC, sign-verify, tag length < min-length policy
|
|||
depends_on:MBEDTLS_AES_C:MBEDTLS_CMAC_C
|
||||
mac_key_policy:PSA_KEY_USAGE_SIGN_HASH | PSA_KEY_USAGE_VERIFY_HASH:PSA_ALG_AT_LEAST_THIS_LENGTH_MAC(PSA_ALG_CMAC, 10):PSA_KEY_TYPE_AES:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa":PSA_ALG_TRUNCATED_MAC(PSA_ALG_CMAC, 8):PSA_ERROR_NOT_PERMITTED
|
||||
|
||||
PSA key policy: MAC, sign-verify, default tag length > min-length policy
|
||||
PSA key policy: HMAC, sign-verify, default tag length > min-length policy
|
||||
depends_on:PSA_WANT_ALG_HMAC:PSA_WANT_ALG_SHA_256:PSA_WANT_KEY_TYPE_HMAC
|
||||
mac_key_policy:PSA_KEY_USAGE_SIGN_HASH | PSA_KEY_USAGE_VERIFY_HASH:PSA_ALG_AT_LEAST_THIS_LENGTH_MAC(PSA_ALG_HMAC(PSA_ALG_SHA_256), 31):PSA_KEY_TYPE_HMAC:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa":PSA_ALG_HMAC(PSA_ALG_SHA_256):PSA_SUCCESS
|
||||
|
||||
PSA key policy: MAC, sign-verify, default tag length = min-length policy
|
||||
PSA key policy: HMAC, sign-verify, default tag length = min-length policy
|
||||
depends_on:PSA_WANT_ALG_HMAC:PSA_WANT_ALG_SHA_256:PSA_WANT_KEY_TYPE_HMAC
|
||||
mac_key_policy:PSA_KEY_USAGE_SIGN_HASH | PSA_KEY_USAGE_VERIFY_HASH:PSA_ALG_AT_LEAST_THIS_LENGTH_MAC(PSA_ALG_HMAC(PSA_ALG_SHA_256), 32):PSA_KEY_TYPE_HMAC:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa":PSA_ALG_HMAC(PSA_ALG_SHA_256):PSA_SUCCESS
|
||||
|
||||
PSA key policy: MAC, sign-verify, default tag length < min-length policy
|
||||
PSA key policy: HMAC, sign-verify, default tag length < min-length policy
|
||||
depends_on:PSA_WANT_ALG_HMAC:PSA_WANT_ALG_SHA_256:PSA_WANT_KEY_TYPE_HMAC
|
||||
mac_key_policy:PSA_KEY_USAGE_SIGN_HASH | PSA_KEY_USAGE_VERIFY_HASH:PSA_ALG_AT_LEAST_THIS_LENGTH_MAC(PSA_ALG_HMAC(PSA_ALG_SHA_256), 33):PSA_KEY_TYPE_HMAC:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa":PSA_ALG_HMAC(PSA_ALG_SHA_256):PSA_ERROR_NOT_PERMITTED
|
||||
|
||||
PSA key policy: MAC, sign-verify, min-length policy, unmatched base alg
|
||||
PSA key policy: HMAC, sign-verify, min-length policy, unmatched base alg
|
||||
depends_on:PSA_WANT_ALG_HMAC:PSA_WANT_ALG_SHA_256:PSA_WANT_KEY_TYPE_HMAC:MBEDTLS_CMAC_C
|
||||
mac_key_policy:PSA_KEY_USAGE_SIGN_HASH | PSA_KEY_USAGE_VERIFY_HASH:PSA_ALG_AT_LEAST_THIS_LENGTH_MAC(PSA_ALG_HMAC(PSA_ALG_SHA_256), 20):PSA_KEY_TYPE_HMAC:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa":PSA_ALG_TRUNCATED_MAC(PSA_ALG_CMAC, 20):PSA_ERROR_NOT_PERMITTED
|
||||
|
||||
PSA key policy: MAC, sign-verify, min-length policy, unmatched base alg (different hash base)
|
||||
PSA key policy: HMAC, sign-verify, min-length policy, unmatched base alg (different hash base)
|
||||
depends_on:PSA_WANT_ALG_HMAC:PSA_WANT_ALG_SHA_256:PSA_WANT_ALG_SHA_224:PSA_WANT_KEY_TYPE_HMAC
|
||||
mac_key_policy:PSA_KEY_USAGE_SIGN_HASH | PSA_KEY_USAGE_VERIFY_HASH:PSA_ALG_AT_LEAST_THIS_LENGTH_MAC(PSA_ALG_HMAC(PSA_ALG_SHA_256), 20):PSA_KEY_TYPE_HMAC:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa":PSA_ALG_TRUNCATED_MAC(PSA_ALG_HMAC(PSA_ALG_SHA_224), 20):PSA_ERROR_NOT_PERMITTED
|
||||
|
||||
PSA key policy: MAC, sign-verify, min-length policy, unmatched base alg (different algorithm)
|
||||
PSA key policy: HMAC, sign-verify, min-length policy, unmatched base alg (different algorithm)
|
||||
depends_on:PSA_WANT_ALG_HMAC:PSA_WANT_ALG_SHA_256:PSA_WANT_KEY_TYPE_HMAC:MBEDTLS_CMAC_C
|
||||
mac_key_policy:PSA_KEY_USAGE_SIGN_HASH | PSA_KEY_USAGE_VERIFY_HASH:PSA_ALG_AT_LEAST_THIS_LENGTH_MAC(PSA_ALG_HMAC(PSA_ALG_SHA_256), 10):PSA_KEY_TYPE_HMAC:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa":PSA_ALG_CMAC:PSA_ERROR_NOT_PERMITTED
|
||||
|
||||
PSA key policy: MAC, sign-verify, min-length policy used as algorithm
|
||||
PSA key policy: HMAC, sign-verify, min-length policy used as algorithm
|
||||
depends_on:PSA_WANT_ALG_HMAC:PSA_WANT_ALG_SHA_256:PSA_WANT_KEY_TYPE_HMAC
|
||||
mac_key_policy:PSA_KEY_USAGE_SIGN_HASH | PSA_KEY_USAGE_VERIFY_HASH:PSA_ALG_AT_LEAST_THIS_LENGTH_MAC(PSA_ALG_HMAC(PSA_ALG_SHA_256), 20):PSA_KEY_TYPE_HMAC:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa":PSA_ALG_AT_LEAST_THIS_LENGTH_MAC(PSA_ALG_HMAC(PSA_ALG_SHA_256), 20):PSA_ERROR_INVALID_ARGUMENT
|
||||
|
||||
PSA key policy: MAC, sign-verify, tag length > exact-length policy
|
||||
PSA key policy: HMAC, sign-verify, tag length > exact-length policy
|
||||
depends_on:PSA_WANT_ALG_HMAC:PSA_WANT_ALG_SHA_256:PSA_WANT_KEY_TYPE_HMAC
|
||||
mac_key_policy:PSA_KEY_USAGE_SIGN_HASH | PSA_KEY_USAGE_VERIFY_HASH:PSA_ALG_TRUNCATED_MAC(PSA_ALG_HMAC(PSA_ALG_SHA_256), 10):PSA_KEY_TYPE_HMAC:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa":PSA_ALG_TRUNCATED_MAC(PSA_ALG_HMAC(PSA_ALG_SHA_256), 20):PSA_ERROR_NOT_PERMITTED
|
||||
|
||||
PSA key policy: MAC, sign-verify, tag length = exact-length policy
|
||||
PSA key policy: HMAC, sign-verify, tag length = exact-length policy
|
||||
depends_on:PSA_WANT_ALG_HMAC:PSA_WANT_ALG_SHA_256:PSA_WANT_KEY_TYPE_HMAC
|
||||
mac_key_policy:PSA_KEY_USAGE_SIGN_HASH | PSA_KEY_USAGE_VERIFY_HASH:PSA_ALG_TRUNCATED_MAC(PSA_ALG_HMAC(PSA_ALG_SHA_256), 20):PSA_KEY_TYPE_HMAC:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa":PSA_ALG_TRUNCATED_MAC(PSA_ALG_HMAC(PSA_ALG_SHA_256), 20):PSA_SUCCESS
|
||||
|
||||
PSA key policy: MAC, sign-verify, tag length < exact-length policy
|
||||
PSA key policy: HMAC, sign-verify, tag length < exact-length policy
|
||||
depends_on:PSA_WANT_ALG_HMAC:PSA_WANT_ALG_SHA_256:PSA_WANT_KEY_TYPE_HMAC
|
||||
mac_key_policy:PSA_KEY_USAGE_SIGN_HASH | PSA_KEY_USAGE_VERIFY_HASH:PSA_ALG_TRUNCATED_MAC(PSA_ALG_HMAC(PSA_ALG_SHA_256), 20):PSA_KEY_TYPE_HMAC:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa":PSA_ALG_TRUNCATED_MAC(PSA_ALG_HMAC(PSA_ALG_SHA_256), 10):PSA_ERROR_NOT_PERMITTED
|
||||
|
||||
|
|
Loading…
Reference in a new issue