mirror of
				https://github.com/cuberite/polarssl.git
				synced 2025-11-04 04:32:24 -05:00 
			
		
		
		
	Use bool variable instead of enum values
Signed-off-by: gabor-mezei-arm <gabor.mezei@arm.com>
This commit is contained in:
		
							parent
							
								
									12b4f34fff
								
							
						
					
					
						commit
						8b3e88614c
					
				@ -2460,22 +2460,31 @@ cleanup:
 | 
				
			|||||||
/* Asymmetric cryptography */
 | 
					/* Asymmetric cryptography */
 | 
				
			||||||
/****************************************************************/
 | 
					/****************************************************************/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef enum
 | 
					static psa_status_t psa_sign_verify_check_alg( uint8_t do_hash,
 | 
				
			||||||
 | 
					                                               psa_algorithm_t alg )
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    PSA_SIGN_INVALID = 0,
 | 
					    if( do_hash )
 | 
				
			||||||
    PSA_SIGN_HASH = 1,
 | 
					    {
 | 
				
			||||||
    PSA_SIGN_MESSAGE
 | 
					        if( ! PSA_ALG_IS_SIGN_MESSAGE( alg ) )
 | 
				
			||||||
} psa_sign_operation_t;
 | 
					            return( PSA_ERROR_INVALID_ARGUMENT );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef enum
 | 
					        if ( PSA_ALG_IS_HASH_AND_SIGN( alg ) )
 | 
				
			||||||
{
 | 
					        {
 | 
				
			||||||
    PSA_VERIFY_INVALID = 0,
 | 
					            if( ! PSA_ALG_IS_HASH( PSA_ALG_SIGN_GET_HASH( alg ) ) )
 | 
				
			||||||
    PSA_VERIFY_HASH = 1,
 | 
					                return( PSA_ERROR_INVALID_ARGUMENT );
 | 
				
			||||||
    PSA_VERIFY_MESSAGE
 | 
					        }
 | 
				
			||||||
} psa_verify_operation_t;
 | 
					    }
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        if( ! PSA_ALG_IS_HASH_AND_SIGN( alg ) )
 | 
				
			||||||
 | 
					            return( PSA_ERROR_INVALID_ARGUMENT );
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return( PSA_SUCCESS );
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static psa_status_t psa_sign_internal( mbedtls_svc_key_id_t key,
 | 
					static psa_status_t psa_sign_internal( mbedtls_svc_key_id_t key,
 | 
				
			||||||
                                       psa_sign_operation_t operation,
 | 
					                                       uint8_t do_hash,
 | 
				
			||||||
                                       psa_algorithm_t alg,
 | 
					                                       psa_algorithm_t alg,
 | 
				
			||||||
                                       const uint8_t * input,
 | 
					                                       const uint8_t * input,
 | 
				
			||||||
                                       size_t input_length,
 | 
					                                       size_t input_length,
 | 
				
			||||||
@ -2489,27 +2498,9 @@ static psa_status_t psa_sign_internal( mbedtls_svc_key_id_t key,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    *signature_length = 0;
 | 
					    *signature_length = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    switch( operation )
 | 
					    status = psa_sign_verify_check_alg( do_hash, alg );
 | 
				
			||||||
    {
 | 
					    if( status != PSA_SUCCESS )
 | 
				
			||||||
        case PSA_SIGN_HASH:
 | 
					        return status;
 | 
				
			||||||
            if( ! PSA_ALG_IS_HASH_AND_SIGN( alg ) )
 | 
					 | 
				
			||||||
                return( PSA_ERROR_INVALID_ARGUMENT );
 | 
					 | 
				
			||||||
            break;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        case PSA_SIGN_MESSAGE:
 | 
					 | 
				
			||||||
            if( ! PSA_ALG_IS_SIGN_MESSAGE( alg ) )
 | 
					 | 
				
			||||||
                return( PSA_ERROR_INVALID_ARGUMENT );
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if ( PSA_ALG_IS_HASH_AND_SIGN( alg ) )
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                if( ! PSA_ALG_IS_HASH( PSA_ALG_SIGN_GET_HASH( alg ) ) )
 | 
					 | 
				
			||||||
                    return( PSA_ERROR_INVALID_ARGUMENT );
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            break;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        default:
 | 
					 | 
				
			||||||
            return( PSA_ERROR_INVALID_ARGUMENT );
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Immediately reject a zero-length signature buffer. This guarantees
 | 
					    /* Immediately reject a zero-length signature buffer. This guarantees
 | 
				
			||||||
     * that signature must be a valid pointer. (On the other hand, the input
 | 
					     * that signature must be a valid pointer. (On the other hand, the input
 | 
				
			||||||
@ -2520,8 +2511,8 @@ static psa_status_t psa_sign_internal( mbedtls_svc_key_id_t key,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    status = psa_get_and_lock_key_slot_with_policy(
 | 
					    status = psa_get_and_lock_key_slot_with_policy(
 | 
				
			||||||
                key, &slot,
 | 
					                key, &slot,
 | 
				
			||||||
                operation == PSA_SIGN_HASH ? PSA_KEY_USAGE_SIGN_HASH :
 | 
					                do_hash ? PSA_KEY_USAGE_SIGN_MESSAGE :
 | 
				
			||||||
                                             PSA_KEY_USAGE_SIGN_MESSAGE,
 | 
					                          PSA_KEY_USAGE_SIGN_HASH,
 | 
				
			||||||
                alg );
 | 
					                alg );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if( status != PSA_SUCCESS )
 | 
					    if( status != PSA_SUCCESS )
 | 
				
			||||||
@ -2537,14 +2528,14 @@ static psa_status_t psa_sign_internal( mbedtls_svc_key_id_t key,
 | 
				
			|||||||
      .core = slot->attr
 | 
					      .core = slot->attr
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if( operation == PSA_SIGN_MESSAGE )
 | 
					    if( do_hash )
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        status = psa_driver_wrapper_sign_message(
 | 
					        status = psa_driver_wrapper_sign_message(
 | 
				
			||||||
            &attributes, slot->key.data, slot->key.bytes,
 | 
					            &attributes, slot->key.data, slot->key.bytes,
 | 
				
			||||||
            alg, input, input_length,
 | 
					            alg, input, input_length,
 | 
				
			||||||
            signature, signature_size, signature_length );
 | 
					            signature, signature_size, signature_length );
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else if( operation == PSA_SIGN_HASH )
 | 
					    else
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        status = psa_driver_wrapper_sign_hash(
 | 
					        status = psa_driver_wrapper_sign_hash(
 | 
				
			||||||
@ -2573,7 +2564,7 @@ exit:
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static psa_status_t psa_verify_internal( mbedtls_svc_key_id_t key,
 | 
					static psa_status_t psa_verify_internal( mbedtls_svc_key_id_t key,
 | 
				
			||||||
                                         psa_verify_operation_t operation,
 | 
					                                         uint8_t do_hash,
 | 
				
			||||||
                                         psa_algorithm_t alg,
 | 
					                                         psa_algorithm_t alg,
 | 
				
			||||||
                                         const uint8_t * input,
 | 
					                                         const uint8_t * input,
 | 
				
			||||||
                                         size_t input_length,
 | 
					                                         size_t input_length,
 | 
				
			||||||
@ -2584,32 +2575,14 @@ static psa_status_t psa_verify_internal( mbedtls_svc_key_id_t key,
 | 
				
			|||||||
    psa_status_t unlock_status = PSA_ERROR_CORRUPTION_DETECTED;
 | 
					    psa_status_t unlock_status = PSA_ERROR_CORRUPTION_DETECTED;
 | 
				
			||||||
    psa_key_slot_t *slot;
 | 
					    psa_key_slot_t *slot;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    switch( operation )
 | 
					    status = psa_sign_verify_check_alg( do_hash, alg );
 | 
				
			||||||
    {
 | 
					    if( status != PSA_SUCCESS )
 | 
				
			||||||
        case PSA_VERIFY_HASH:
 | 
					        return status;
 | 
				
			||||||
            if( ! PSA_ALG_IS_HASH_AND_SIGN( alg ) )
 | 
					 | 
				
			||||||
                return( PSA_ERROR_INVALID_ARGUMENT );
 | 
					 | 
				
			||||||
            break;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        case PSA_VERIFY_MESSAGE:
 | 
					 | 
				
			||||||
            if( ! PSA_ALG_IS_SIGN_MESSAGE( alg ) )
 | 
					 | 
				
			||||||
                return( PSA_ERROR_INVALID_ARGUMENT );
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if ( PSA_ALG_IS_HASH_AND_SIGN( alg ) )
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                if( ! PSA_ALG_IS_HASH( PSA_ALG_SIGN_GET_HASH( alg ) ) )
 | 
					 | 
				
			||||||
                    return( PSA_ERROR_INVALID_ARGUMENT );
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            break;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        default:
 | 
					 | 
				
			||||||
            return( PSA_ERROR_INVALID_ARGUMENT );
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    status = psa_get_and_lock_key_slot_with_policy(
 | 
					    status = psa_get_and_lock_key_slot_with_policy(
 | 
				
			||||||
                key, &slot,
 | 
					                key, &slot,
 | 
				
			||||||
                operation == PSA_VERIFY_HASH ? PSA_KEY_USAGE_VERIFY_HASH :
 | 
					                do_hash ? PSA_KEY_USAGE_VERIFY_MESSAGE :
 | 
				
			||||||
                                               PSA_KEY_USAGE_VERIFY_MESSAGE,
 | 
					                          PSA_KEY_USAGE_VERIFY_HASH,
 | 
				
			||||||
                alg );
 | 
					                alg );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if( status != PSA_SUCCESS )
 | 
					    if( status != PSA_SUCCESS )
 | 
				
			||||||
@ -2619,14 +2592,14 @@ static psa_status_t psa_verify_internal( mbedtls_svc_key_id_t key,
 | 
				
			|||||||
      .core = slot->attr
 | 
					      .core = slot->attr
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if( operation == PSA_VERIFY_MESSAGE )
 | 
					    if( do_hash )
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        status = psa_driver_wrapper_verify_message(
 | 
					        status = psa_driver_wrapper_verify_message(
 | 
				
			||||||
            &attributes, slot->key.data, slot->key.bytes,
 | 
					            &attributes, slot->key.data, slot->key.bytes,
 | 
				
			||||||
            alg, input, input_length,
 | 
					            alg, input, input_length,
 | 
				
			||||||
            signature, signature_length );
 | 
					            signature, signature_length );
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else if( operation == PSA_VERIFY_HASH )
 | 
					    else
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        status = psa_driver_wrapper_verify_hash(
 | 
					        status = psa_driver_wrapper_verify_hash(
 | 
				
			||||||
            &attributes, slot->key.data, slot->key.bytes,
 | 
					            &attributes, slot->key.data, slot->key.bytes,
 | 
				
			||||||
@ -2672,10 +2645,7 @@ psa_status_t psa_sign_message_internal(
 | 
				
			|||||||
                    signature, signature_size, signature_length );
 | 
					                    signature, signature_size, signature_length );
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return psa_driver_wrapper_sign_hash(
 | 
					    return( PSA_ERROR_NOT_SUPPORTED );
 | 
				
			||||||
                attributes, key_buffer, key_buffer_size,
 | 
					 | 
				
			||||||
                alg, input, input_length,
 | 
					 | 
				
			||||||
                signature, signature_size, signature_length );
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
psa_status_t psa_sign_message( mbedtls_svc_key_id_t key,
 | 
					psa_status_t psa_sign_message( mbedtls_svc_key_id_t key,
 | 
				
			||||||
@ -2687,7 +2657,7 @@ psa_status_t psa_sign_message( mbedtls_svc_key_id_t key,
 | 
				
			|||||||
                               size_t * signature_length )
 | 
					                               size_t * signature_length )
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    return psa_sign_internal(
 | 
					    return psa_sign_internal(
 | 
				
			||||||
        key, PSA_SIGN_MESSAGE, alg, input, input_length,
 | 
					        key, 1, alg, input, input_length,
 | 
				
			||||||
        signature, signature_size, signature_length );
 | 
					        signature, signature_size, signature_length );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -2736,7 +2706,7 @@ psa_status_t psa_verify_message( mbedtls_svc_key_id_t key,
 | 
				
			|||||||
                                 size_t signature_length )
 | 
					                                 size_t signature_length )
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    return psa_verify_internal(
 | 
					    return psa_verify_internal(
 | 
				
			||||||
        key, PSA_VERIFY_MESSAGE, alg, input, input_length,
 | 
					        key, 1, alg, input, input_length,
 | 
				
			||||||
        signature, signature_length );
 | 
					        signature, signature_length );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -2807,7 +2777,7 @@ psa_status_t psa_sign_hash( mbedtls_svc_key_id_t key,
 | 
				
			|||||||
                            size_t *signature_length )
 | 
					                            size_t *signature_length )
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    return psa_sign_internal(
 | 
					    return psa_sign_internal(
 | 
				
			||||||
        key, PSA_SIGN_HASH, alg, hash, hash_length,
 | 
					        key, 0, alg, hash, hash_length,
 | 
				
			||||||
        signature, signature_size, signature_length );
 | 
					        signature, signature_size, signature_length );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -2876,7 +2846,7 @@ psa_status_t psa_verify_hash( mbedtls_svc_key_id_t key,
 | 
				
			|||||||
                              size_t signature_length )
 | 
					                              size_t signature_length )
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    return psa_verify_internal(
 | 
					    return psa_verify_internal(
 | 
				
			||||||
        key, PSA_VERIFY_HASH, alg, hash, hash_length,
 | 
					        key, 0, alg, hash, hash_length,
 | 
				
			||||||
        signature, signature_length );
 | 
					        signature, signature_length );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user