mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-04-09 21:44:28 +00:00
psa: cipher: Add IV parameters to cipher_encrypt entry point
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
This commit is contained in:
parent
e9a45fcecb
commit
9b67428e22
@ -3539,15 +3539,17 @@ psa_status_t psa_cipher_encrypt( mbedtls_svc_key_id_t key,
|
|||||||
|
|
||||||
status = psa_driver_wrapper_cipher_encrypt(
|
status = psa_driver_wrapper_cipher_encrypt(
|
||||||
&attributes, slot->key.data, slot->key.bytes,
|
&attributes, slot->key.data, slot->key.bytes,
|
||||||
alg, input, input_length,
|
alg, output, iv_length, input, input_length,
|
||||||
output, output_size, output_length );
|
output + iv_length, output_size - iv_length, output_length );
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
unlock_status = psa_unlock_key_slot( slot );
|
unlock_status = psa_unlock_key_slot( slot );
|
||||||
if( status == PSA_SUCCESS )
|
if( status == PSA_SUCCESS )
|
||||||
status = unlock_status;
|
status = unlock_status;
|
||||||
|
|
||||||
if( status != PSA_SUCCESS )
|
if( status == PSA_SUCCESS )
|
||||||
|
*output_length += iv_length;
|
||||||
|
else
|
||||||
*output_length = 0;
|
*output_length = 0;
|
||||||
|
|
||||||
return( status );
|
return( status );
|
||||||
|
@ -451,6 +451,8 @@ static psa_status_t cipher_encrypt( const psa_key_attributes_t *attributes,
|
|||||||
const uint8_t *key_buffer,
|
const uint8_t *key_buffer,
|
||||||
size_t key_buffer_size,
|
size_t key_buffer_size,
|
||||||
psa_algorithm_t alg,
|
psa_algorithm_t alg,
|
||||||
|
const uint8_t *iv,
|
||||||
|
size_t iv_length,
|
||||||
const uint8_t *input,
|
const uint8_t *input,
|
||||||
size_t input_length,
|
size_t input_length,
|
||||||
uint8_t *output,
|
uint8_t *output,
|
||||||
@ -459,38 +461,32 @@ static psa_status_t cipher_encrypt( const psa_key_attributes_t *attributes,
|
|||||||
{
|
{
|
||||||
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||||
mbedtls_psa_cipher_operation_t operation = MBEDTLS_PSA_CIPHER_OPERATION_INIT;
|
mbedtls_psa_cipher_operation_t operation = MBEDTLS_PSA_CIPHER_OPERATION_INIT;
|
||||||
size_t olength, accumulated_length;
|
size_t update_output_length, finish_output_length;
|
||||||
|
|
||||||
status = cipher_encrypt_setup( &operation, attributes,
|
status = cipher_encrypt_setup( &operation, attributes,
|
||||||
key_buffer, key_buffer_size, alg );
|
key_buffer, key_buffer_size, alg );
|
||||||
if( status != PSA_SUCCESS )
|
if( status != PSA_SUCCESS )
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
||||||
accumulated_length = 0;
|
if( iv_length > 0 )
|
||||||
if( operation.iv_length > 0 )
|
|
||||||
{
|
{
|
||||||
status = cipher_set_iv( &operation, output, operation.iv_length );
|
status = cipher_set_iv( &operation, iv, iv_length );
|
||||||
if( status != PSA_SUCCESS )
|
if( status != PSA_SUCCESS )
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
||||||
accumulated_length = operation.iv_length;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
status = cipher_update( &operation, input, input_length,
|
status = cipher_update( &operation, input, input_length,
|
||||||
output + operation.iv_length,
|
output, output_size, &update_output_length );
|
||||||
output_size - operation.iv_length,
|
|
||||||
&olength );
|
|
||||||
if( status != PSA_SUCCESS )
|
if( status != PSA_SUCCESS )
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
||||||
accumulated_length += olength;
|
status = cipher_finish( &operation, output + update_output_length,
|
||||||
|
output_size - update_output_length,
|
||||||
status = cipher_finish( &operation, output + accumulated_length,
|
&finish_output_length );
|
||||||
output_size - accumulated_length, &olength );
|
|
||||||
if( status != PSA_SUCCESS )
|
if( status != PSA_SUCCESS )
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
||||||
*output_length = accumulated_length + olength;
|
*output_length = update_output_length + finish_output_length;
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
if( status == PSA_SUCCESS )
|
if( status == PSA_SUCCESS )
|
||||||
@ -606,6 +602,8 @@ psa_status_t mbedtls_psa_cipher_encrypt( const psa_key_attributes_t *attributes,
|
|||||||
const uint8_t *key_buffer,
|
const uint8_t *key_buffer,
|
||||||
size_t key_buffer_size,
|
size_t key_buffer_size,
|
||||||
psa_algorithm_t alg,
|
psa_algorithm_t alg,
|
||||||
|
const uint8_t *iv,
|
||||||
|
size_t iv_length,
|
||||||
const uint8_t *input,
|
const uint8_t *input,
|
||||||
size_t input_length,
|
size_t input_length,
|
||||||
uint8_t *output,
|
uint8_t *output,
|
||||||
@ -613,7 +611,7 @@ psa_status_t mbedtls_psa_cipher_encrypt( const psa_key_attributes_t *attributes,
|
|||||||
size_t *output_length )
|
size_t *output_length )
|
||||||
{
|
{
|
||||||
return( cipher_encrypt( attributes, key_buffer, key_buffer_size,
|
return( cipher_encrypt( attributes, key_buffer, key_buffer_size,
|
||||||
alg, input, input_length,
|
alg, iv, iv_length, input, input_length,
|
||||||
output, output_size, output_length ) );
|
output, output_size, output_length ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -692,6 +690,8 @@ psa_status_t mbedtls_transparent_test_driver_cipher_encrypt(
|
|||||||
const uint8_t *key_buffer,
|
const uint8_t *key_buffer,
|
||||||
size_t key_buffer_size,
|
size_t key_buffer_size,
|
||||||
psa_algorithm_t alg,
|
psa_algorithm_t alg,
|
||||||
|
const uint8_t *iv,
|
||||||
|
size_t iv_length,
|
||||||
const uint8_t *input,
|
const uint8_t *input,
|
||||||
size_t input_length,
|
size_t input_length,
|
||||||
uint8_t *output,
|
uint8_t *output,
|
||||||
@ -699,7 +699,7 @@ psa_status_t mbedtls_transparent_test_driver_cipher_encrypt(
|
|||||||
size_t *output_length )
|
size_t *output_length )
|
||||||
{
|
{
|
||||||
return( cipher_encrypt( attributes, key_buffer, key_buffer_size,
|
return( cipher_encrypt( attributes, key_buffer, key_buffer_size,
|
||||||
alg, input, input_length,
|
alg, iv, iv_length, input, input_length,
|
||||||
output, output_size, output_length ) );
|
output, output_size, output_length ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -213,16 +213,12 @@ psa_status_t mbedtls_psa_cipher_abort( mbedtls_psa_cipher_operation_t *operation
|
|||||||
* \param[in] alg The cipher algorithm to compute
|
* \param[in] alg The cipher algorithm to compute
|
||||||
* (\c PSA_ALG_XXX value such that
|
* (\c PSA_ALG_XXX value such that
|
||||||
* #PSA_ALG_IS_CIPHER(\p alg) is true).
|
* #PSA_ALG_IS_CIPHER(\p alg) is true).
|
||||||
* \param[in] input Buffer containing the message to encrypt.
|
* \param[in] iv Buffer containing the IV for encryption. The
|
||||||
* \param[in] input_length Size of the \p input buffer in bytes.
|
* IV has been generated by the core.
|
||||||
|
* \param[in] iv_length Size of the \p iv in bytes.
|
||||||
|
* \param[in] input Buffer containing the message to encrypt.
|
||||||
|
* \param[in] input_length Size of the \p input buffer in bytes.
|
||||||
* \param[in,out] output Buffer where the output is to be written.
|
* \param[in,out] output Buffer where the output is to be written.
|
||||||
* The core has generated and written the IV
|
|
||||||
* at the beginning of this buffer before
|
|
||||||
* this function is called. The size of the IV
|
|
||||||
* is PSA_CIPHER_IV_LENGTH( key_type, alg ) where
|
|
||||||
* \c key_type is the type of the key identified
|
|
||||||
* by \p key and \p alg is the cipher algorithm
|
|
||||||
* to compute.
|
|
||||||
* \param[in] output_size Size of the \p output buffer in bytes.
|
* \param[in] output_size Size of the \p output buffer in bytes.
|
||||||
* \param[out] output_length On success, the number of bytes that make up
|
* \param[out] output_length On success, the number of bytes that make up
|
||||||
* the returned output. Initialized to zero
|
* the returned output. Initialized to zero
|
||||||
@ -235,7 +231,7 @@ psa_status_t mbedtls_psa_cipher_abort( mbedtls_psa_cipher_operation_t *operation
|
|||||||
* \retval #PSA_ERROR_BUFFER_TOO_SMALL
|
* \retval #PSA_ERROR_BUFFER_TOO_SMALL
|
||||||
* The size of the \p output buffer is too small.
|
* The size of the \p output buffer is too small.
|
||||||
* \retval #PSA_ERROR_INVALID_ARGUMENT
|
* \retval #PSA_ERROR_INVALID_ARGUMENT
|
||||||
* The size of \p iv is not acceptable for the chosen algorithm,
|
* The size \p iv_length is not acceptable for the chosen algorithm,
|
||||||
* or the chosen algorithm does not use an IV.
|
* or the chosen algorithm does not use an IV.
|
||||||
* The total input size passed to this operation is not valid for
|
* The total input size passed to this operation is not valid for
|
||||||
* this particular algorithm. For example, the algorithm is a based
|
* this particular algorithm. For example, the algorithm is a based
|
||||||
@ -249,6 +245,8 @@ psa_status_t mbedtls_psa_cipher_encrypt( const psa_key_attributes_t *attributes,
|
|||||||
const uint8_t *key_buffer,
|
const uint8_t *key_buffer,
|
||||||
size_t key_buffer_size,
|
size_t key_buffer_size,
|
||||||
psa_algorithm_t alg,
|
psa_algorithm_t alg,
|
||||||
|
const uint8_t *iv,
|
||||||
|
size_t iv_length,
|
||||||
const uint8_t *input,
|
const uint8_t *input,
|
||||||
size_t input_length,
|
size_t input_length,
|
||||||
uint8_t *output,
|
uint8_t *output,
|
||||||
@ -342,6 +340,8 @@ psa_status_t mbedtls_transparent_test_driver_cipher_encrypt(
|
|||||||
const uint8_t *key_buffer,
|
const uint8_t *key_buffer,
|
||||||
size_t key_buffer_size,
|
size_t key_buffer_size,
|
||||||
psa_algorithm_t alg,
|
psa_algorithm_t alg,
|
||||||
|
const uint8_t *iv,
|
||||||
|
size_t iv_length,
|
||||||
const uint8_t *input,
|
const uint8_t *input,
|
||||||
size_t input_length,
|
size_t input_length,
|
||||||
uint8_t *output,
|
uint8_t *output,
|
||||||
|
@ -741,6 +741,8 @@ psa_status_t psa_driver_wrapper_cipher_encrypt(
|
|||||||
const uint8_t *key_buffer,
|
const uint8_t *key_buffer,
|
||||||
size_t key_buffer_size,
|
size_t key_buffer_size,
|
||||||
psa_algorithm_t alg,
|
psa_algorithm_t alg,
|
||||||
|
const uint8_t *iv,
|
||||||
|
size_t iv_length,
|
||||||
const uint8_t *input,
|
const uint8_t *input,
|
||||||
size_t input_length,
|
size_t input_length,
|
||||||
uint8_t *output,
|
uint8_t *output,
|
||||||
@ -762,6 +764,8 @@ psa_status_t psa_driver_wrapper_cipher_encrypt(
|
|||||||
key_buffer,
|
key_buffer,
|
||||||
key_buffer_size,
|
key_buffer_size,
|
||||||
alg,
|
alg,
|
||||||
|
iv,
|
||||||
|
iv_length,
|
||||||
input,
|
input,
|
||||||
input_length,
|
input_length,
|
||||||
output,
|
output,
|
||||||
@ -778,6 +782,8 @@ psa_status_t psa_driver_wrapper_cipher_encrypt(
|
|||||||
key_buffer,
|
key_buffer,
|
||||||
key_buffer_size,
|
key_buffer_size,
|
||||||
alg,
|
alg,
|
||||||
|
iv,
|
||||||
|
iv_length,
|
||||||
input,
|
input,
|
||||||
input_length,
|
input_length,
|
||||||
output,
|
output,
|
||||||
@ -795,6 +801,8 @@ psa_status_t psa_driver_wrapper_cipher_encrypt(
|
|||||||
key_buffer,
|
key_buffer,
|
||||||
key_buffer_size,
|
key_buffer_size,
|
||||||
alg,
|
alg,
|
||||||
|
iv,
|
||||||
|
iv_length,
|
||||||
input,
|
input,
|
||||||
input_length,
|
input_length,
|
||||||
output,
|
output,
|
||||||
|
@ -102,6 +102,8 @@ psa_status_t psa_driver_wrapper_cipher_encrypt(
|
|||||||
const uint8_t *key_buffer,
|
const uint8_t *key_buffer,
|
||||||
size_t key_buffer_size,
|
size_t key_buffer_size,
|
||||||
psa_algorithm_t alg,
|
psa_algorithm_t alg,
|
||||||
|
const uint8_t *iv,
|
||||||
|
size_t iv_length,
|
||||||
const uint8_t *input,
|
const uint8_t *input,
|
||||||
size_t input_length,
|
size_t input_length,
|
||||||
uint8_t *output,
|
uint8_t *output,
|
||||||
|
@ -53,6 +53,7 @@ psa_status_t mbedtls_test_transparent_cipher_encrypt(
|
|||||||
const psa_key_attributes_t *attributes,
|
const psa_key_attributes_t *attributes,
|
||||||
const uint8_t *key, size_t key_length,
|
const uint8_t *key, size_t key_length,
|
||||||
psa_algorithm_t alg,
|
psa_algorithm_t alg,
|
||||||
|
const uint8_t *iv, size_t iv_length,
|
||||||
const uint8_t *input, size_t input_length,
|
const uint8_t *input, size_t input_length,
|
||||||
uint8_t *output, size_t output_size, size_t *output_length);
|
uint8_t *output, size_t output_size, size_t *output_length);
|
||||||
|
|
||||||
@ -98,6 +99,7 @@ psa_status_t mbedtls_test_opaque_cipher_encrypt(
|
|||||||
const psa_key_attributes_t *attributes,
|
const psa_key_attributes_t *attributes,
|
||||||
const uint8_t *key, size_t key_length,
|
const uint8_t *key, size_t key_length,
|
||||||
psa_algorithm_t alg,
|
psa_algorithm_t alg,
|
||||||
|
const uint8_t *iv, size_t iv_length,
|
||||||
const uint8_t *input, size_t input_length,
|
const uint8_t *input, size_t input_length,
|
||||||
uint8_t *output, size_t output_size, size_t *output_length);
|
uint8_t *output, size_t output_size, size_t *output_length);
|
||||||
|
|
||||||
|
@ -40,6 +40,8 @@ psa_status_t mbedtls_test_transparent_cipher_encrypt(
|
|||||||
const uint8_t *key_buffer,
|
const uint8_t *key_buffer,
|
||||||
size_t key_buffer_size,
|
size_t key_buffer_size,
|
||||||
psa_algorithm_t alg,
|
psa_algorithm_t alg,
|
||||||
|
const uint8_t *iv,
|
||||||
|
size_t iv_length,
|
||||||
const uint8_t *input,
|
const uint8_t *input,
|
||||||
size_t input_length,
|
size_t input_length,
|
||||||
uint8_t *output,
|
uint8_t *output,
|
||||||
@ -66,7 +68,7 @@ psa_status_t mbedtls_test_transparent_cipher_encrypt(
|
|||||||
|
|
||||||
return( mbedtls_transparent_test_driver_cipher_encrypt(
|
return( mbedtls_transparent_test_driver_cipher_encrypt(
|
||||||
attributes, key_buffer, key_buffer_size,
|
attributes, key_buffer, key_buffer_size,
|
||||||
alg, input, input_length,
|
alg, iv, iv_length, input, input_length,
|
||||||
output, output_size, output_length ) );
|
output, output_size, output_length ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -240,6 +242,7 @@ psa_status_t mbedtls_test_opaque_cipher_encrypt(
|
|||||||
const psa_key_attributes_t *attributes,
|
const psa_key_attributes_t *attributes,
|
||||||
const uint8_t *key, size_t key_length,
|
const uint8_t *key, size_t key_length,
|
||||||
psa_algorithm_t alg,
|
psa_algorithm_t alg,
|
||||||
|
const uint8_t *iv, size_t iv_length,
|
||||||
const uint8_t *input, size_t input_length,
|
const uint8_t *input, size_t input_length,
|
||||||
uint8_t *output, size_t output_size, size_t *output_length)
|
uint8_t *output, size_t output_size, size_t *output_length)
|
||||||
{
|
{
|
||||||
@ -247,6 +250,8 @@ psa_status_t mbedtls_test_opaque_cipher_encrypt(
|
|||||||
(void) key;
|
(void) key;
|
||||||
(void) key_length;
|
(void) key_length;
|
||||||
(void) alg;
|
(void) alg;
|
||||||
|
(void) iv;
|
||||||
|
(void) iv_length;
|
||||||
(void) input;
|
(void) input;
|
||||||
(void) input_length;
|
(void) input_length;
|
||||||
(void) output;
|
(void) output;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user