mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-08-01 10:06:53 +03:00
Merge remote-tracking branch 'restricted/development_2.x-restricted' into mbedtls-2.28.0rc0-pr
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
This commit is contained in:
@ -3396,8 +3396,8 @@ psa_status_t psa_cipher_generate_iv( psa_cipher_operation_t *operation,
|
||||
size_t *iv_length )
|
||||
{
|
||||
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||
|
||||
*iv_length = 0;
|
||||
uint8_t local_iv[PSA_CIPHER_IV_MAX_SIZE];
|
||||
size_t default_iv_length;
|
||||
|
||||
if( operation->id == 0 )
|
||||
{
|
||||
@ -3411,28 +3411,38 @@ psa_status_t psa_cipher_generate_iv( psa_cipher_operation_t *operation,
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if( iv_size < operation->default_iv_length )
|
||||
default_iv_length = operation->default_iv_length;
|
||||
if( iv_size < default_iv_length )
|
||||
{
|
||||
status = PSA_ERROR_BUFFER_TOO_SMALL;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
status = psa_generate_random( iv, operation->default_iv_length );
|
||||
if( default_iv_length > PSA_CIPHER_IV_MAX_SIZE )
|
||||
{
|
||||
status = PSA_ERROR_GENERIC_ERROR;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
status = psa_generate_random( local_iv, default_iv_length );
|
||||
if( status != PSA_SUCCESS )
|
||||
goto exit;
|
||||
|
||||
status = psa_driver_wrapper_cipher_set_iv( operation,
|
||||
iv,
|
||||
operation->default_iv_length );
|
||||
local_iv, default_iv_length );
|
||||
|
||||
exit:
|
||||
if( status == PSA_SUCCESS )
|
||||
{
|
||||
memcpy( iv, local_iv, default_iv_length );
|
||||
*iv_length = default_iv_length;
|
||||
operation->iv_set = 1;
|
||||
*iv_length = operation->default_iv_length;
|
||||
}
|
||||
else
|
||||
{
|
||||
*iv_length = 0;
|
||||
psa_cipher_abort( operation );
|
||||
}
|
||||
|
||||
return( status );
|
||||
}
|
||||
@ -3573,50 +3583,67 @@ psa_status_t psa_cipher_encrypt( mbedtls_svc_key_id_t key,
|
||||
{
|
||||
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||
psa_status_t unlock_status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||
psa_key_slot_t *slot;
|
||||
psa_key_type_t key_type;
|
||||
size_t iv_length;
|
||||
|
||||
*output_length = 0;
|
||||
psa_key_slot_t *slot = NULL;
|
||||
uint8_t local_iv[PSA_CIPHER_IV_MAX_SIZE];
|
||||
size_t default_iv_length = 0;
|
||||
|
||||
if( ! PSA_ALG_IS_CIPHER( alg ) )
|
||||
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||
{
|
||||
status = PSA_ERROR_INVALID_ARGUMENT;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
status = psa_get_and_lock_key_slot_with_policy( key, &slot,
|
||||
PSA_KEY_USAGE_ENCRYPT,
|
||||
alg );
|
||||
if( status != PSA_SUCCESS )
|
||||
return( status );
|
||||
goto exit;
|
||||
|
||||
psa_key_attributes_t attributes = {
|
||||
.core = slot->attr
|
||||
};
|
||||
|
||||
key_type = slot->attr.type;
|
||||
iv_length = PSA_CIPHER_IV_LENGTH( key_type, alg );
|
||||
|
||||
if( iv_length > 0 )
|
||||
default_iv_length = PSA_CIPHER_IV_LENGTH( slot->attr.type, alg );
|
||||
if( default_iv_length > PSA_CIPHER_IV_MAX_SIZE )
|
||||
{
|
||||
if( output_size < iv_length )
|
||||
status = PSA_ERROR_GENERIC_ERROR;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if( default_iv_length > 0 )
|
||||
{
|
||||
if( output_size < default_iv_length )
|
||||
{
|
||||
status = PSA_ERROR_BUFFER_TOO_SMALL;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
status = psa_generate_random( output, iv_length );
|
||||
status = psa_generate_random( local_iv, default_iv_length );
|
||||
if( status != PSA_SUCCESS )
|
||||
goto exit;
|
||||
}
|
||||
|
||||
status = psa_driver_wrapper_cipher_encrypt(
|
||||
&attributes, slot->key.data, slot->key.bytes,
|
||||
alg, input, input_length,
|
||||
output, output_size, output_length );
|
||||
alg, local_iv, default_iv_length, input, input_length,
|
||||
output + default_iv_length, output_size - default_iv_length,
|
||||
output_length );
|
||||
|
||||
exit:
|
||||
unlock_status = psa_unlock_key_slot( slot );
|
||||
if( status == PSA_SUCCESS )
|
||||
status = unlock_status;
|
||||
|
||||
return( ( status == PSA_SUCCESS ) ? unlock_status : status );
|
||||
if( status == PSA_SUCCESS )
|
||||
{
|
||||
if( default_iv_length > 0 )
|
||||
memcpy( output, local_iv, default_iv_length );
|
||||
*output_length += default_iv_length;
|
||||
}
|
||||
else
|
||||
*output_length = 0;
|
||||
|
||||
return( status );
|
||||
}
|
||||
|
||||
psa_status_t psa_cipher_decrypt( mbedtls_svc_key_id_t key,
|
||||
@ -3629,18 +3656,19 @@ psa_status_t psa_cipher_decrypt( mbedtls_svc_key_id_t key,
|
||||
{
|
||||
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||
psa_status_t unlock_status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||
psa_key_slot_t *slot;
|
||||
|
||||
*output_length = 0;
|
||||
psa_key_slot_t *slot = NULL;
|
||||
|
||||
if( ! PSA_ALG_IS_CIPHER( alg ) )
|
||||
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||
{
|
||||
status = PSA_ERROR_INVALID_ARGUMENT;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
status = psa_get_and_lock_key_slot_with_policy( key, &slot,
|
||||
PSA_KEY_USAGE_DECRYPT,
|
||||
alg );
|
||||
if( status != PSA_SUCCESS )
|
||||
return( status );
|
||||
goto exit;
|
||||
|
||||
psa_key_attributes_t attributes = {
|
||||
.core = slot->attr
|
||||
@ -3659,8 +3687,13 @@ psa_status_t psa_cipher_decrypt( mbedtls_svc_key_id_t key,
|
||||
|
||||
exit:
|
||||
unlock_status = psa_unlock_key_slot( slot );
|
||||
if( status == PSA_SUCCESS )
|
||||
status = unlock_status;
|
||||
|
||||
return( ( status == PSA_SUCCESS ) ? unlock_status : status );
|
||||
if( status != PSA_SUCCESS )
|
||||
*output_length = 0;
|
||||
|
||||
return( status );
|
||||
}
|
||||
|
||||
|
||||
|
@ -444,20 +444,21 @@ psa_status_t mbedtls_psa_cipher_abort(
|
||||
return( PSA_SUCCESS );
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_psa_cipher_encrypt(
|
||||
const psa_key_attributes_t *attributes,
|
||||
const uint8_t *key_buffer,
|
||||
size_t key_buffer_size,
|
||||
psa_algorithm_t alg,
|
||||
const uint8_t *input,
|
||||
size_t input_length,
|
||||
uint8_t *output,
|
||||
size_t output_size,
|
||||
size_t *output_length )
|
||||
psa_status_t mbedtls_psa_cipher_encrypt( const psa_key_attributes_t *attributes,
|
||||
const uint8_t *key_buffer,
|
||||
size_t key_buffer_size,
|
||||
psa_algorithm_t alg,
|
||||
const uint8_t *iv,
|
||||
size_t iv_length,
|
||||
const uint8_t *input,
|
||||
size_t input_length,
|
||||
uint8_t *output,
|
||||
size_t output_size,
|
||||
size_t *output_length )
|
||||
{
|
||||
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||
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 = mbedtls_psa_cipher_encrypt_setup( &operation, attributes,
|
||||
key_buffer, key_buffer_size,
|
||||
@ -465,33 +466,25 @@ psa_status_t mbedtls_psa_cipher_encrypt(
|
||||
if( status != PSA_SUCCESS )
|
||||
goto exit;
|
||||
|
||||
accumulated_length = 0;
|
||||
if( operation.iv_length > 0 )
|
||||
if( iv_length > 0 )
|
||||
{
|
||||
status = mbedtls_psa_cipher_set_iv( &operation,
|
||||
output, operation.iv_length );
|
||||
status = mbedtls_psa_cipher_set_iv( &operation, iv, iv_length );
|
||||
if( status != PSA_SUCCESS )
|
||||
goto exit;
|
||||
|
||||
accumulated_length = operation.iv_length;
|
||||
}
|
||||
|
||||
status = mbedtls_psa_cipher_update( &operation, input, input_length,
|
||||
output + operation.iv_length,
|
||||
output_size - operation.iv_length,
|
||||
&olength );
|
||||
output, output_size, &update_output_length );
|
||||
if( status != PSA_SUCCESS )
|
||||
goto exit;
|
||||
|
||||
accumulated_length += olength;
|
||||
|
||||
status = mbedtls_psa_cipher_finish( &operation, output + accumulated_length,
|
||||
output_size - accumulated_length,
|
||||
&olength );
|
||||
status = mbedtls_psa_cipher_finish( &operation, output + update_output_length,
|
||||
output_size - update_output_length,
|
||||
&finish_output_length );
|
||||
if( status != PSA_SUCCESS )
|
||||
goto exit;
|
||||
|
||||
*output_length = accumulated_length + olength;
|
||||
*output_length = update_output_length + finish_output_length;
|
||||
|
||||
exit:
|
||||
if( status == PSA_SUCCESS )
|
||||
|
@ -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
|
||||
* (\c PSA_ALG_XXX value such that
|
||||
* #PSA_ALG_IS_CIPHER(\p alg) is true).
|
||||
* \param[in] input Buffer containing the message to encrypt.
|
||||
* \param[in] input_length Size of the \p input buffer in bytes.
|
||||
* \param[in] iv Buffer containing the IV for encryption. The
|
||||
* 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.
|
||||
* 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[out] output_length On success, the number of bytes that make up
|
||||
* 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
|
||||
* The size of the \p output buffer is too small.
|
||||
* \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.
|
||||
* The total input size passed to this operation is not valid for
|
||||
* 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,
|
||||
size_t key_buffer_size,
|
||||
psa_algorithm_t alg,
|
||||
const uint8_t *iv,
|
||||
size_t iv_length,
|
||||
const uint8_t *input,
|
||||
size_t input_length,
|
||||
uint8_t *output,
|
||||
|
@ -778,6 +778,8 @@ psa_status_t psa_driver_wrapper_cipher_encrypt(
|
||||
const uint8_t *key_buffer,
|
||||
size_t key_buffer_size,
|
||||
psa_algorithm_t alg,
|
||||
const uint8_t *iv,
|
||||
size_t iv_length,
|
||||
const uint8_t *input,
|
||||
size_t input_length,
|
||||
uint8_t *output,
|
||||
@ -799,6 +801,8 @@ psa_status_t psa_driver_wrapper_cipher_encrypt(
|
||||
key_buffer,
|
||||
key_buffer_size,
|
||||
alg,
|
||||
iv,
|
||||
iv_length,
|
||||
input,
|
||||
input_length,
|
||||
output,
|
||||
@ -815,6 +819,8 @@ psa_status_t psa_driver_wrapper_cipher_encrypt(
|
||||
key_buffer,
|
||||
key_buffer_size,
|
||||
alg,
|
||||
iv,
|
||||
iv_length,
|
||||
input,
|
||||
input_length,
|
||||
output,
|
||||
@ -832,6 +838,8 @@ psa_status_t psa_driver_wrapper_cipher_encrypt(
|
||||
key_buffer,
|
||||
key_buffer_size,
|
||||
alg,
|
||||
iv,
|
||||
iv_length,
|
||||
input,
|
||||
input_length,
|
||||
output,
|
||||
|
@ -108,6 +108,8 @@ psa_status_t psa_driver_wrapper_cipher_encrypt(
|
||||
const uint8_t *key_buffer,
|
||||
size_t key_buffer_size,
|
||||
psa_algorithm_t alg,
|
||||
const uint8_t *iv,
|
||||
size_t iv_length,
|
||||
const uint8_t *input,
|
||||
size_t input_length,
|
||||
uint8_t *output,
|
||||
|
@ -188,6 +188,10 @@ int mbedtls_ssl_session_copy( mbedtls_ssl_session *dst,
|
||||
mbedtls_ssl_session_free( dst );
|
||||
memcpy( dst, src, sizeof( mbedtls_ssl_session ) );
|
||||
|
||||
#if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_CLI_C)
|
||||
dst->ticket = NULL;
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_X509_CRT_PARSE_C)
|
||||
|
||||
#if defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
|
||||
|
Reference in New Issue
Block a user