mirror of
				https://github.com/cuberite/polarssl.git
				synced 2025-11-03 12:11:27 -05:00 
			
		
		
		
	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:
		
							parent
							
								
									57fbdb1939
								
							
						
					
					
						commit
						e0e9c7c417
					
				@ -803,6 +803,21 @@ typedef uint32_t psa_algorithm_t;
 | 
				
			|||||||
    (((alg) & ~PSA_ALG_MAC_TRUNCATION_MASK) |                           \
 | 
					    (((alg) & ~PSA_ALG_MAC_TRUNCATION_MASK) |                           \
 | 
				
			||||||
     ((mac_length) << PSA_MAC_TRUNCATION_OFFSET & 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.
 | 
					/** Length to which a MAC algorithm is truncated.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * \param alg           A MAC algorithm identifier (value of type
 | 
					 * \param alg           A MAC algorithm identifier (value of type
 | 
				
			||||||
 | 
				
			|||||||
@ -1527,7 +1527,7 @@ static psa_status_t psa_mac_setup( psa_mac_operation_t *operation,
 | 
				
			|||||||
    psa_key_usage_t usage =
 | 
					    psa_key_usage_t usage =
 | 
				
			||||||
        is_sign ? PSA_KEY_USAGE_SIGN : PSA_KEY_USAGE_VERIFY;
 | 
					        is_sign ? PSA_KEY_USAGE_SIGN : PSA_KEY_USAGE_VERIFY;
 | 
				
			||||||
    unsigned char truncated = PSA_MAC_TRUNCATED_LENGTH( alg );
 | 
					    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 );
 | 
					    status = psa_mac_init( operation, full_length_alg );
 | 
				
			||||||
    if( status != PSA_SUCCESS )
 | 
					    if( status != PSA_SUCCESS )
 | 
				
			||||||
 | 
				
			|||||||
@ -198,6 +198,7 @@ void mac_algorithm( int alg_arg, int classification_flags,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    mac_algorithm_core( alg, classification_flags,
 | 
					    mac_algorithm_core( alg, classification_flags,
 | 
				
			||||||
                        key_type, key_bits, length );
 | 
					                        key_type, key_bits, length );
 | 
				
			||||||
 | 
					    TEST_ASSERT( PSA_ALG_FULL_LENGTH_MAC( alg ) == alg );
 | 
				
			||||||
    TEST_ASSERT( length <= PSA_MAC_MAX_SIZE );
 | 
					    TEST_ASSERT( length <= PSA_MAC_MAX_SIZE );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Truncated versions */
 | 
					    /* 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 );
 | 
					        psa_algorithm_t truncated_alg = PSA_ALG_TRUNCATED_MAC( alg, n );
 | 
				
			||||||
        mac_algorithm_core( truncated_alg, classification_flags,
 | 
					        mac_algorithm_core( truncated_alg, classification_flags,
 | 
				
			||||||
                            key_type, key_bits, n );
 | 
					                            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
 | 
					        /* Check that calling PSA_ALG_TRUNCATED_MAC twice gives the length
 | 
				
			||||||
         * of the outer truncation (even if the outer length is smaller than
 | 
					         * of the outer truncation (even if the outer length is smaller than
 | 
				
			||||||
         * the inner length). */
 | 
					         * the inner length). */
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user