mirror of
				https://github.com/cuberite/polarssl.git
				synced 2025-11-04 04:32:24 -05:00 
			
		
		
		
	add iv_required field to psa_cipher_operation_s and fix relevant functions
This commit is contained in:
		
							parent
							
								
									71f19ae6f8
								
							
						
					
					
						commit
						ad9d82cc0e
					
				@ -101,6 +101,7 @@ struct psa_cipher_operation_s
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    psa_algorithm_t alg;
 | 
					    psa_algorithm_t alg;
 | 
				
			||||||
    int key_set : 1;
 | 
					    int key_set : 1;
 | 
				
			||||||
 | 
					    int iv_required : 1;
 | 
				
			||||||
    int iv_set : 1;
 | 
					    int iv_set : 1;
 | 
				
			||||||
    uint8_t iv_size;
 | 
					    uint8_t iv_size;
 | 
				
			||||||
    uint8_t block_size;
 | 
					    uint8_t block_size;
 | 
				
			||||||
 | 
				
			|||||||
@ -1311,6 +1311,7 @@ static psa_status_t psa_cipher_setup(psa_cipher_operation_t *operation,
 | 
				
			|||||||
    operation->alg = alg;
 | 
					    operation->alg = alg;
 | 
				
			||||||
    operation->key_set = 0;
 | 
					    operation->key_set = 0;
 | 
				
			||||||
    operation->iv_set = 0;
 | 
					    operation->iv_set = 0;
 | 
				
			||||||
 | 
					    operation->iv_required = 1;
 | 
				
			||||||
    operation->iv_size = 0;
 | 
					    operation->iv_size = 0;
 | 
				
			||||||
    operation->block_size = 0;
 | 
					    operation->block_size = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -1397,7 +1398,7 @@ psa_status_t psa_encrypt_generate_iv(psa_cipher_operation_t *operation,
 | 
				
			|||||||
                                     size_t *iv_length)
 | 
					                                     size_t *iv_length)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    int ret = PSA_SUCCESS;
 | 
					    int ret = PSA_SUCCESS;
 | 
				
			||||||
    if( operation->iv_set )
 | 
					    if( operation->iv_set || !( operation->iv_required ) )
 | 
				
			||||||
        return( PSA_ERROR_BAD_STATE );
 | 
					        return( PSA_ERROR_BAD_STATE );
 | 
				
			||||||
    if( iv_size < operation->iv_size )
 | 
					    if( iv_size < operation->iv_size )
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
@ -1425,7 +1426,7 @@ psa_status_t psa_encrypt_set_iv(psa_cipher_operation_t *operation,
 | 
				
			|||||||
                                size_t iv_length)
 | 
					                                size_t iv_length)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    int ret = PSA_SUCCESS;
 | 
					    int ret = PSA_SUCCESS;
 | 
				
			||||||
    if( operation->iv_set )
 | 
					    if( operation->iv_set || !( operation->iv_required ) )
 | 
				
			||||||
        return( PSA_ERROR_BAD_STATE );
 | 
					        return( PSA_ERROR_BAD_STATE );
 | 
				
			||||||
    if (iv_length != operation->iv_size)
 | 
					    if (iv_length != operation->iv_size)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
@ -1442,6 +1443,7 @@ psa_status_t psa_encrypt_set_iv(psa_cipher_operation_t *operation,
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    operation->iv_set = 1;
 | 
					    operation->iv_set = 1;
 | 
				
			||||||
 | 
					    operation->iv_required = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return ( PSA_SUCCESS );
 | 
					    return ( PSA_SUCCESS );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -1480,7 +1482,7 @@ psa_status_t psa_cipher_finish(psa_cipher_operation_t *operation,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    if( ! operation->key_set )
 | 
					    if( ! operation->key_set )
 | 
				
			||||||
        return( PSA_ERROR_BAD_STATE );
 | 
					        return( PSA_ERROR_BAD_STATE );
 | 
				
			||||||
    if( ! operation->iv_set )
 | 
					    if ( operation->iv_required && ! operation->iv_set )
 | 
				
			||||||
        return( PSA_ERROR_BAD_STATE );
 | 
					        return( PSA_ERROR_BAD_STATE );
 | 
				
			||||||
    if( operation->ctx.cipher.operation == MBEDTLS_ENCRYPT )
 | 
					    if( operation->ctx.cipher.operation == MBEDTLS_ENCRYPT )
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
@ -1519,6 +1521,7 @@ psa_status_t psa_cipher_abort(psa_cipher_operation_t *operation)
 | 
				
			|||||||
    operation->iv_set = 0;
 | 
					    operation->iv_set = 0;
 | 
				
			||||||
    operation->iv_size = 0;
 | 
					    operation->iv_size = 0;
 | 
				
			||||||
    operation->block_size = 0;
 | 
					    operation->block_size = 0;
 | 
				
			||||||
 | 
					    operation->iv_required = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return ( PSA_SUCCESS );
 | 
					    return ( PSA_SUCCESS );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user