mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2025-06-01 17:20:15 +00:00
cipher_alg_without_iv: generalized to also do decryption
Test set_iv/generate_iv after decrypt_setup. Test successful decryption. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
parent
5f50420dc8
commit
69d9817a66
|
@ -1541,23 +1541,23 @@ cipher_encrypt_fail:PSA_ALG_CBC_NO_PADDING:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf
|
||||||
|
|
||||||
PSA symmetric encrypt: AES-ECB, 0 bytes, good
|
PSA symmetric encrypt: AES-ECB, 0 bytes, good
|
||||||
depends_on:PSA_WANT_ALG_ECB_NO_PADDING:PSA_WANT_KEY_TYPE_AES
|
depends_on:PSA_WANT_ALG_ECB_NO_PADDING:PSA_WANT_KEY_TYPE_AES
|
||||||
cipher_encrypt_alg_without_iv:PSA_ALG_ECB_NO_PADDING:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"":""
|
cipher_alg_without_iv:PSA_ALG_ECB_NO_PADDING:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"":""
|
||||||
|
|
||||||
PSA symmetric encrypt: AES-ECB, 16 bytes, good
|
PSA symmetric encrypt: AES-ECB, 16 bytes, good
|
||||||
depends_on:PSA_WANT_ALG_ECB_NO_PADDING:PSA_WANT_KEY_TYPE_AES
|
depends_on:PSA_WANT_ALG_ECB_NO_PADDING:PSA_WANT_KEY_TYPE_AES
|
||||||
cipher_encrypt_alg_without_iv:PSA_ALG_ECB_NO_PADDING:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"6bc1bee22e409f96e93d7e117393172a":"3ad77bb40d7a3660a89ecaf32466ef97"
|
cipher_alg_without_iv:PSA_ALG_ECB_NO_PADDING:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"6bc1bee22e409f96e93d7e117393172a":"3ad77bb40d7a3660a89ecaf32466ef97"
|
||||||
|
|
||||||
PSA symmetric encrypt: AES-ECB, 32 bytes, good
|
PSA symmetric encrypt: AES-ECB, 32 bytes, good
|
||||||
depends_on:PSA_WANT_ALG_ECB_NO_PADDING:PSA_WANT_KEY_TYPE_AES
|
depends_on:PSA_WANT_ALG_ECB_NO_PADDING:PSA_WANT_KEY_TYPE_AES
|
||||||
cipher_encrypt_alg_without_iv:PSA_ALG_ECB_NO_PADDING:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"6bc1bee22e409f96e93d7e117393172a3ad77bb40d7a3660a89ecaf32466ef97":"3ad77bb40d7a3660a89ecaf32466ef972249a2638c6f1c755a84f9681a9f08c1"
|
cipher_alg_without_iv:PSA_ALG_ECB_NO_PADDING:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"6bc1bee22e409f96e93d7e117393172a3ad77bb40d7a3660a89ecaf32466ef97":"3ad77bb40d7a3660a89ecaf32466ef972249a2638c6f1c755a84f9681a9f08c1"
|
||||||
|
|
||||||
PSA symmetric encrypt: 2-key 3DES-ECB, 8 bytes, good
|
PSA symmetric encrypt: 2-key 3DES-ECB, 8 bytes, good
|
||||||
depends_on:PSA_WANT_ALG_ECB_NO_PADDING:PSA_WANT_KEY_TYPE_DES
|
depends_on:PSA_WANT_ALG_ECB_NO_PADDING:PSA_WANT_KEY_TYPE_DES
|
||||||
cipher_encrypt_alg_without_iv:PSA_ALG_ECB_NO_PADDING:PSA_KEY_TYPE_DES:"01020407080b0d0ec1c2c4c7c8cbcdce":"c78e2b38139610e3":"5d0652429c5b0ac7"
|
cipher_alg_without_iv:PSA_ALG_ECB_NO_PADDING:PSA_KEY_TYPE_DES:"01020407080b0d0ec1c2c4c7c8cbcdce":"c78e2b38139610e3":"5d0652429c5b0ac7"
|
||||||
|
|
||||||
PSA symmetric encrypt: 3-key 3DES-ECB, 8 bytes, good
|
PSA symmetric encrypt: 3-key 3DES-ECB, 8 bytes, good
|
||||||
depends_on:PSA_WANT_ALG_ECB_NO_PADDING:PSA_WANT_KEY_TYPE_DES
|
depends_on:PSA_WANT_ALG_ECB_NO_PADDING:PSA_WANT_KEY_TYPE_DES
|
||||||
cipher_encrypt_alg_without_iv:PSA_ALG_ECB_NO_PADDING:PSA_KEY_TYPE_DES:"01020407080b0d0ec1c2c4c7c8cbcdce31323437383b3d3e":"c78e2b38139610e3":"817ca7d69b80d86a"
|
cipher_alg_without_iv:PSA_ALG_ECB_NO_PADDING:PSA_KEY_TYPE_DES:"01020407080b0d0ec1c2c4c7c8cbcdce31323437383b3d3e":"c78e2b38139610e3":"817ca7d69b80d86a"
|
||||||
|
|
||||||
PSA symmetric encrypt validation: AES-CBC-nopad, 16 bytes, good
|
PSA symmetric encrypt validation: AES-CBC-nopad, 16 bytes, good
|
||||||
depends_on:PSA_WANT_ALG_CBC_NO_PADDING:PSA_WANT_KEY_TYPE_AES
|
depends_on:PSA_WANT_ALG_CBC_NO_PADDING:PSA_WANT_KEY_TYPE_AES
|
||||||
|
|
|
@ -2592,11 +2592,8 @@ exit:
|
||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
/* BEGIN_CASE */
|
/* BEGIN_CASE */
|
||||||
void cipher_encrypt_alg_without_iv( int alg_arg,
|
void cipher_alg_without_iv( int alg_arg, int key_type_arg, data_t *key_data,
|
||||||
int key_type_arg,
|
data_t *plaintext, data_t *ciphertext )
|
||||||
data_t *key_data,
|
|
||||||
data_t *input,
|
|
||||||
data_t *expected_output )
|
|
||||||
{
|
{
|
||||||
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
|
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
|
||||||
psa_key_type_t key_type = key_type_arg;
|
psa_key_type_t key_type = key_type_arg;
|
||||||
|
@ -2606,46 +2603,65 @@ void cipher_encrypt_alg_without_iv( int alg_arg,
|
||||||
size_t iv_length;
|
size_t iv_length;
|
||||||
unsigned char *output = NULL;
|
unsigned char *output = NULL;
|
||||||
size_t output_buffer_size = 0;
|
size_t output_buffer_size = 0;
|
||||||
size_t output_length = 0;
|
size_t output_length;
|
||||||
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||||
|
|
||||||
PSA_ASSERT( psa_crypto_init( ) );
|
PSA_ASSERT( psa_crypto_init( ) );
|
||||||
|
|
||||||
/* Validate size macros */
|
/* Validate size macros */
|
||||||
TEST_ASSERT( expected_output->len <=
|
TEST_ASSERT( ciphertext->len <=
|
||||||
PSA_CIPHER_ENCRYPT_OUTPUT_SIZE( key_type, alg, input->len ) );
|
PSA_CIPHER_ENCRYPT_OUTPUT_SIZE( key_type, alg, plaintext->len ) );
|
||||||
TEST_ASSERT( PSA_CIPHER_ENCRYPT_OUTPUT_SIZE( key_type, alg, input->len ) <=
|
TEST_ASSERT( PSA_CIPHER_ENCRYPT_OUTPUT_SIZE( key_type, alg, plaintext->len ) <=
|
||||||
PSA_CIPHER_ENCRYPT_OUTPUT_MAX_SIZE( input->len ) );
|
PSA_CIPHER_ENCRYPT_OUTPUT_MAX_SIZE( plaintext->len ) );
|
||||||
|
TEST_ASSERT( plaintext->len <=
|
||||||
|
PSA_CIPHER_DECRYPT_OUTPUT_SIZE( key_type, alg, ciphertext->len ) );
|
||||||
|
TEST_ASSERT( PSA_CIPHER_DECRYPT_OUTPUT_SIZE( key_type, alg, ciphertext->len ) <=
|
||||||
|
PSA_CIPHER_DECRYPT_OUTPUT_MAX_SIZE( ciphertext->len ) );
|
||||||
|
|
||||||
|
|
||||||
/* Set up key and output buffer */
|
/* Set up key and output buffer */
|
||||||
psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_ENCRYPT );
|
psa_set_key_usage_flags( &attributes,
|
||||||
|
PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT );
|
||||||
psa_set_key_algorithm( &attributes, alg );
|
psa_set_key_algorithm( &attributes, alg );
|
||||||
psa_set_key_type( &attributes, key_type );
|
psa_set_key_type( &attributes, key_type );
|
||||||
PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
|
PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
|
||||||
&key ) );
|
&key ) );
|
||||||
output_buffer_size = PSA_CIPHER_ENCRYPT_OUTPUT_SIZE( key_type, alg, input->len );
|
output_buffer_size = PSA_CIPHER_ENCRYPT_OUTPUT_SIZE( key_type, alg,
|
||||||
|
plaintext->len );
|
||||||
ASSERT_ALLOC( output, output_buffer_size );
|
ASSERT_ALLOC( output, output_buffer_size );
|
||||||
|
|
||||||
/* set_iv() is not allowed */
|
/* set_iv() is not allowed */
|
||||||
PSA_ASSERT( psa_cipher_encrypt_setup( &operation, key, alg ) );
|
PSA_ASSERT( psa_cipher_encrypt_setup( &operation, key, alg ) );
|
||||||
|
TEST_EQUAL( psa_cipher_set_iv( &operation, iv, sizeof( iv ) ),
|
||||||
|
PSA_ERROR_BAD_STATE );
|
||||||
|
PSA_ASSERT( psa_cipher_decrypt_setup( &operation, key, alg ) );
|
||||||
TEST_EQUAL( psa_cipher_set_iv( &operation, iv, sizeof( iv ) ),
|
TEST_EQUAL( psa_cipher_set_iv( &operation, iv, sizeof( iv ) ),
|
||||||
PSA_ERROR_BAD_STATE );
|
PSA_ERROR_BAD_STATE );
|
||||||
|
|
||||||
/* generate_iv() is not allowed */
|
/* generate_iv() is not allowed */
|
||||||
PSA_ASSERT( psa_cipher_encrypt_setup( &operation, key, alg ) );
|
PSA_ASSERT( psa_cipher_encrypt_setup( &operation, key, alg ) );
|
||||||
|
TEST_EQUAL( psa_cipher_generate_iv( &operation, iv, sizeof( iv ),
|
||||||
|
&iv_length ),
|
||||||
|
PSA_ERROR_BAD_STATE );
|
||||||
|
PSA_ASSERT( psa_cipher_decrypt_setup( &operation, key, alg ) );
|
||||||
TEST_EQUAL( psa_cipher_generate_iv( &operation, iv, sizeof( iv ),
|
TEST_EQUAL( psa_cipher_generate_iv( &operation, iv, sizeof( iv ),
|
||||||
&iv_length ),
|
&iv_length ),
|
||||||
PSA_ERROR_BAD_STATE );
|
PSA_ERROR_BAD_STATE );
|
||||||
|
|
||||||
/* One-shot encryption */
|
/* One-shot encryption */
|
||||||
PSA_ASSERT( psa_cipher_encrypt( key, alg, input->x, input->len, output,
|
output_length = ~0;
|
||||||
output_buffer_size, &output_length ) );
|
PSA_ASSERT( psa_cipher_encrypt( key, alg, plaintext->x, plaintext->len,
|
||||||
TEST_ASSERT( output_length <=
|
output, output_buffer_size,
|
||||||
PSA_CIPHER_ENCRYPT_OUTPUT_SIZE( key_type, alg, input->len ) );
|
&output_length ) );
|
||||||
TEST_ASSERT( output_length <=
|
ASSERT_COMPARE( ciphertext->x, ciphertext->len,
|
||||||
PSA_CIPHER_ENCRYPT_OUTPUT_MAX_SIZE( input->len ) );
|
output, output_length );
|
||||||
|
|
||||||
ASSERT_COMPARE( expected_output->x, expected_output->len,
|
/* One-shot decryption */
|
||||||
|
output_length = ~0;
|
||||||
|
PSA_ASSERT( psa_cipher_decrypt( key, alg, ciphertext->x, ciphertext->len,
|
||||||
|
output, output_buffer_size,
|
||||||
|
&output_length ) );
|
||||||
|
ASSERT_COMPARE( plaintext->x, plaintext->len,
|
||||||
output, output_length );
|
output, output_length );
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
|
Loading…
Reference in a new issue