mirror of
				https://github.com/cuberite/polarssl.git
				synced 2025-11-04 04:32:24 -05:00 
			
		
		
		
	Refactor is_encrypt into aead setup arguments
Avoid touching the operation until later. Signed-off-by: Paul Elliott <paul.elliott@arm.com>
This commit is contained in:
		
							parent
							
								
									36869706e2
								
							
						
					
					
						commit
						d9343f2f0f
					
				@ -3403,6 +3403,7 @@ static psa_algorithm_t psa_aead_get_base_algorithm( psa_algorithm_t alg )
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
/* Set the key for a multipart authenticated operation. */
 | 
					/* Set the key for a multipart authenticated operation. */
 | 
				
			||||||
static psa_status_t psa_aead_setup( psa_aead_operation_t *operation,
 | 
					static psa_status_t psa_aead_setup( psa_aead_operation_t *operation,
 | 
				
			||||||
 | 
					                                    int is_encrypt,
 | 
				
			||||||
                                    mbedtls_svc_key_id_t key,
 | 
					                                    mbedtls_svc_key_id_t key,
 | 
				
			||||||
                                    psa_algorithm_t alg )
 | 
					                                    psa_algorithm_t alg )
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@ -3430,7 +3431,7 @@ static psa_status_t psa_aead_setup( psa_aead_operation_t *operation,
 | 
				
			|||||||
        goto exit;
 | 
					        goto exit;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if( operation->is_encrypt )
 | 
					    if( is_encrypt )
 | 
				
			||||||
        key_usage = PSA_KEY_USAGE_ENCRYPT;
 | 
					        key_usage = PSA_KEY_USAGE_ENCRYPT;
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
        key_usage = PSA_KEY_USAGE_DECRYPT;
 | 
					        key_usage = PSA_KEY_USAGE_DECRYPT;
 | 
				
			||||||
@ -3445,7 +3446,7 @@ static psa_status_t psa_aead_setup( psa_aead_operation_t *operation,
 | 
				
			|||||||
        .core = slot->attr
 | 
					        .core = slot->attr
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if( operation->is_encrypt )
 | 
					    if( is_encrypt )
 | 
				
			||||||
        status = psa_driver_wrapper_aead_encrypt_setup( operation,
 | 
					        status = psa_driver_wrapper_aead_encrypt_setup( operation,
 | 
				
			||||||
                                                        &attributes,
 | 
					                                                        &attributes,
 | 
				
			||||||
                                                        slot->key.data,
 | 
					                                                        slot->key.data,
 | 
				
			||||||
@ -3472,6 +3473,7 @@ exit:
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        status = unlock_status;
 | 
					        status = unlock_status;
 | 
				
			||||||
        operation->alg = psa_aead_get_base_algorithm( alg );
 | 
					        operation->alg = psa_aead_get_base_algorithm( alg );
 | 
				
			||||||
 | 
					        operation->is_encrypt = is_encrypt;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
        psa_aead_abort( operation );
 | 
					        psa_aead_abort( operation );
 | 
				
			||||||
@ -3484,9 +3486,7 @@ psa_status_t psa_aead_encrypt_setup( psa_aead_operation_t *operation,
 | 
				
			|||||||
                                     mbedtls_svc_key_id_t key,
 | 
					                                     mbedtls_svc_key_id_t key,
 | 
				
			||||||
                                     psa_algorithm_t alg )
 | 
					                                     psa_algorithm_t alg )
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    operation->is_encrypt = 1;
 | 
					    return( psa_aead_setup( operation, 1, key, alg ) );
 | 
				
			||||||
 | 
					 | 
				
			||||||
    return( psa_aead_setup( operation, key, alg ) );
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Set the key for a multipart authenticated decryption operation. */
 | 
					/* Set the key for a multipart authenticated decryption operation. */
 | 
				
			||||||
@ -3494,9 +3494,7 @@ psa_status_t psa_aead_decrypt_setup( psa_aead_operation_t *operation,
 | 
				
			|||||||
                                     mbedtls_svc_key_id_t key,
 | 
					                                     mbedtls_svc_key_id_t key,
 | 
				
			||||||
                                     psa_algorithm_t alg )
 | 
					                                     psa_algorithm_t alg )
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    operation->is_encrypt = 0;
 | 
					    return( psa_aead_setup( operation, 0, key, alg ) );
 | 
				
			||||||
 | 
					 | 
				
			||||||
    return( psa_aead_setup( operation, key, alg ) );
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Generate a random nonce / IV for multipart AEAD operation */
 | 
					/* Generate a random nonce / IV for multipart AEAD operation */
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user