New macro PSA_ALG_FULL_LENGTH_MAC

Provide a documented way of constructing the full-length MAC algorithm
from a truncated version.
This commit is contained in:
Gilles Peskine 2018-10-17 18:28:05 +02:00
parent 57fbdb1939
commit e0e9c7c417
3 changed files with 18 additions and 1 deletions

View file

@ -803,6 +803,21 @@ typedef uint32_t psa_algorithm_t;
(((alg) & ~PSA_ALG_MAC_TRUNCATION_MASK) | \
((mac_length) << PSA_MAC_TRUNCATION_OFFSET & PSA_ALG_MAC_TRUNCATION_MASK))
/** Macro to build the base MAC algorithm corresponding to a truncated
* MAC algorithm.
*
* \param alg A MAC algorithm identifier (value of type
* #psa_algorithm_t such that #PSA_ALG_IS_MAC(\p alg)
* is true). This may be a truncated or untruncated
* MAC algorithm.
*
* \return The corresponding base MAC algorithm.
* \return Unspecified if \p alg is not a supported
* MAC algorithm.
*/
#define PSA_ALG_FULL_LENGTH_MAC(alg) \
((alg) & ~PSA_ALG_MAC_TRUNCATION_MASK)
/** Length to which a MAC algorithm is truncated.
*
* \param alg A MAC algorithm identifier (value of type

View file

@ -1527,7 +1527,7 @@ static psa_status_t psa_mac_setup( psa_mac_operation_t *operation,
psa_key_usage_t usage =
is_sign ? PSA_KEY_USAGE_SIGN : PSA_KEY_USAGE_VERIFY;
unsigned char truncated = PSA_MAC_TRUNCATED_LENGTH( alg );
psa_algorithm_t full_length_alg = alg & ~PSA_ALG_MAC_TRUNCATION_MASK;
psa_algorithm_t full_length_alg = PSA_ALG_FULL_LENGTH_MAC( alg );
status = psa_mac_init( operation, full_length_alg );
if( status != PSA_SUCCESS )

View file

@ -198,6 +198,7 @@ void mac_algorithm( int alg_arg, int classification_flags,
mac_algorithm_core( alg, classification_flags,
key_type, key_bits, length );
TEST_ASSERT( PSA_ALG_FULL_LENGTH_MAC( alg ) == alg );
TEST_ASSERT( length <= PSA_MAC_MAX_SIZE );
/* Truncated versions */
@ -206,6 +207,7 @@ void mac_algorithm( int alg_arg, int classification_flags,
psa_algorithm_t truncated_alg = PSA_ALG_TRUNCATED_MAC( alg, n );
mac_algorithm_core( truncated_alg, classification_flags,
key_type, key_bits, n );
TEST_ASSERT( PSA_ALG_FULL_LENGTH_MAC( truncated_alg ) == alg );
/* Check that calling PSA_ALG_TRUNCATED_MAC twice gives the length
* of the outer truncation (even if the outer length is smaller than
* the inner length). */