mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-12-23 11:05:29 +00:00
Implement support for multipart ECB and add tests
Signed-off-by: Steven Cooreman <steven.cooreman@silabs.com>
This commit is contained in:
parent
a6033e92af
commit
ffecb7b982
|
@ -3945,9 +3945,9 @@ psa_status_t psa_cipher_update( psa_cipher_operation_t *operation,
|
|||
size_t output_size,
|
||||
size_t *output_length )
|
||||
{
|
||||
psa_status_t status;
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||
size_t expected_output_size;
|
||||
size_t internal_output_length;
|
||||
|
||||
if( operation->alg == 0 )
|
||||
{
|
||||
|
@ -3975,9 +3975,83 @@ psa_status_t psa_cipher_update( psa_cipher_operation_t *operation,
|
|||
goto exit;
|
||||
}
|
||||
|
||||
ret = mbedtls_cipher_update( &operation->ctx.cipher, input,
|
||||
input_length, output, output_length );
|
||||
status = mbedtls_to_psa_error( ret );
|
||||
if( operation->alg == PSA_ALG_ECB_NO_PADDING )
|
||||
{
|
||||
/* mbedtls_cipher_update has an API inconsistency: it will only
|
||||
* process a single block at a time in ECB mode. Abstract away that
|
||||
* inconsistency here to match the PSA API behaviour. */
|
||||
*output_length = 0;
|
||||
|
||||
if( input_length == 0 )
|
||||
{
|
||||
status = PSA_SUCCESS;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if( expected_output_size > 0 )
|
||||
{
|
||||
size_t ctx_bytes = operation->ctx.cipher.unprocessed_len;
|
||||
if( ctx_bytes > 0 )
|
||||
{
|
||||
/* Fill up to block size and run the block */
|
||||
size_t bytes_to_copy = operation->block_size - ctx_bytes;
|
||||
memcpy( &( operation->ctx.cipher.unprocessed_data[ctx_bytes] ),
|
||||
input, bytes_to_copy );
|
||||
input_length -= bytes_to_copy;
|
||||
input += bytes_to_copy;
|
||||
operation->ctx.cipher.unprocessed_len = 0;
|
||||
|
||||
status = mbedtls_to_psa_error(
|
||||
mbedtls_cipher_update( &operation->ctx.cipher,
|
||||
operation->ctx.cipher.unprocessed_data,
|
||||
operation->block_size,
|
||||
output, &internal_output_length ) );
|
||||
|
||||
if( status != PSA_SUCCESS )
|
||||
goto exit;
|
||||
|
||||
output += internal_output_length;
|
||||
output_size -= internal_output_length;
|
||||
*output_length += internal_output_length;
|
||||
}
|
||||
|
||||
size_t blocks = input_length / operation->block_size;
|
||||
for( ; blocks > 0; blocks-- )
|
||||
{
|
||||
/* Run all full blocks we have, one by one */
|
||||
status = mbedtls_to_psa_error(
|
||||
mbedtls_cipher_update( &operation->ctx.cipher, input,
|
||||
operation->block_size,
|
||||
output, &internal_output_length ) );
|
||||
|
||||
if( status != PSA_SUCCESS )
|
||||
goto exit;
|
||||
|
||||
input_length -= operation->block_size;
|
||||
input += operation->block_size;
|
||||
|
||||
output += internal_output_length;
|
||||
output_size -= internal_output_length;
|
||||
*output_length += internal_output_length;
|
||||
}
|
||||
}
|
||||
|
||||
if( input_length > 0 )
|
||||
{
|
||||
/* Save unprocessed bytes for later processing */
|
||||
memcpy( &( operation->ctx.cipher.unprocessed_data[operation->ctx.cipher.unprocessed_len] ),
|
||||
input, input_length );
|
||||
operation->ctx.cipher.unprocessed_len += input_length;
|
||||
}
|
||||
|
||||
status = PSA_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
status = mbedtls_to_psa_error(
|
||||
mbedtls_cipher_update( &operation->ctx.cipher, input,
|
||||
input_length, output, output_length ) );
|
||||
}
|
||||
exit:
|
||||
if( status != PSA_SUCCESS )
|
||||
psa_cipher_abort( operation );
|
||||
|
|
|
@ -1126,10 +1126,18 @@ PSA cipher: bad order function calls
|
|||
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CBC
|
||||
cipher_bad_order:
|
||||
|
||||
PSA symmetric encrypt: AES-ECB, 0 bytes, good
|
||||
depends_on:MBEDTLS_AES_C
|
||||
cipher_encrypt:PSA_ALG_ECB_NO_PADDING:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"":"":"":PSA_SUCCESS
|
||||
|
||||
PSA symmetric encrypt: AES-ECB, 16 bytes, good
|
||||
depends_on:MBEDTLS_AES_C
|
||||
cipher_encrypt:PSA_ALG_ECB_NO_PADDING:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"":"6bc1bee22e409f96e93d7e117393172a":"3ad77bb40d7a3660a89ecaf32466ef97":PSA_SUCCESS
|
||||
|
||||
PSA symmetric encrypt: AES-ECB, 32 bytes, good
|
||||
depends_on:MBEDTLS_AES_C
|
||||
cipher_encrypt:PSA_ALG_ECB_NO_PADDING:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"":"6bc1bee22e409f96e93d7e117393172a3ad77bb40d7a3660a89ecaf32466ef97":"3ad77bb40d7a3660a89ecaf32466ef972249a2638c6f1c755a84f9681a9f08c1":PSA_SUCCESS
|
||||
|
||||
PSA symmetric encrypt: AES-CBC-nopad, 16 bytes, good
|
||||
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CBC
|
||||
cipher_encrypt:PSA_ALG_CBC_NO_PADDING:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a":"6bc1bee22e409f96e93d7e117393172a":"a076ec9dfbe47d52afc357336f20743b":PSA_SUCCESS
|
||||
|
@ -1142,6 +1150,10 @@ PSA symmetric encrypt: AES-CBC-PKCS#7, 15 bytes, good
|
|||
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CBC
|
||||
cipher_encrypt:PSA_ALG_CBC_PKCS7:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a":"6bc1bee22e409f96e93d7e11739317":"6279b49d7f7a8dd87b685175d4276e24":PSA_SUCCESS
|
||||
|
||||
PSA symmetric encrypt: AES-ECB, input too short (15 bytes)
|
||||
depends_on:MBEDTLS_AES_C
|
||||
cipher_encrypt:PSA_ALG_ECB_NO_PADDING:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"":"6bc1bee22e409f96e93d7e11739317":"3ad77bb40d7a3660a89ecaf32466ef":PSA_ERROR_INVALID_ARGUMENT
|
||||
|
||||
PSA symmetric encrypt: AES-CBC-nopad, input too short
|
||||
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CBC
|
||||
cipher_encrypt:PSA_ALG_CBC_NO_PADDING:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a":"6bc1bee223":"6bc1bee223":PSA_ERROR_INVALID_ARGUMENT
|
||||
|
@ -1166,10 +1178,26 @@ PSA symmetric encrypt: 3-key 3DES-CBC-nopad, 8 bytes, good
|
|||
depends_on:MBEDTLS_DES_C:MBEDTLS_CIPHER_MODE_CBC
|
||||
cipher_encrypt:PSA_ALG_CBC_NO_PADDING:PSA_KEY_TYPE_DES:"01020407080b0d0ec1c2c4c7c8cbcdce31323437383b3d3e":"2a2a2a2a2a2a2a2a":"eda4011239bc3ac9":"817ca7d69b80d86a":PSA_SUCCESS
|
||||
|
||||
PSA symmetric encrypt: 2-key 3DES-ECB, 8 bytes, good
|
||||
depends_on:MBEDTLS_DES_C:MBEDTLS_CIPHER_MODE_CBC
|
||||
cipher_encrypt:PSA_ALG_ECB_NO_PADDING:PSA_KEY_TYPE_DES:"01020407080b0d0ec1c2c4c7c8cbcdce":"":"c78e2b38139610e3":"5d0652429c5b0ac7":PSA_SUCCESS
|
||||
|
||||
PSA symmetric encrypt: 3-key 3DES-ECB, 8 bytes, good
|
||||
depends_on:MBEDTLS_DES_C:MBEDTLS_CIPHER_MODE_CBC
|
||||
cipher_encrypt:PSA_ALG_ECB_NO_PADDING:PSA_KEY_TYPE_DES:"01020407080b0d0ec1c2c4c7c8cbcdce31323437383b3d3e":"":"c78e2b38139610e3":"817ca7d69b80d86a":PSA_SUCCESS
|
||||
|
||||
PSA symmetric decrypt: AES-ECB, 0 bytes, good
|
||||
depends_on:MBEDTLS_AES_C
|
||||
cipher_decrypt:PSA_ALG_ECB_NO_PADDING:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"":"":"":PSA_SUCCESS
|
||||
|
||||
PSA symmetric decrypt: AES-ECB, 16 bytes, good
|
||||
depends_on:MBEDTLS_AES_C
|
||||
cipher_decrypt:PSA_ALG_ECB_NO_PADDING:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"":"396ee84fb75fdbb5c2b13c7fe5a654aa":"63cecc46a382414d5fa7d2b79387437f":PSA_SUCCESS
|
||||
|
||||
PSA symmetric decrypt: AES-ECB, 32 bytes, good
|
||||
depends_on:MBEDTLS_AES_C
|
||||
cipher_decrypt:PSA_ALG_ECB_NO_PADDING:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"":"3ad77bb40d7a3660a89ecaf32466ef972249a2638c6f1c755a84f9681a9f08c1":"6bc1bee22e409f96e93d7e117393172a3ad77bb40d7a3660a89ecaf32466ef97":PSA_SUCCESS
|
||||
|
||||
PSA symmetric decrypt: AES-CBC-nopad, 16 bytes, good
|
||||
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CBC
|
||||
cipher_decrypt:PSA_ALG_CBC_NO_PADDING:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a":"396ee84fb75fdbb5c2b13c7fe5a654aa":"49e4e66c89a86b67758df89db9ad6955":PSA_SUCCESS
|
||||
|
@ -1190,6 +1218,10 @@ PSA symmetric decrypt: AES-CTR, 16 bytes, good
|
|||
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CBC:MBEDTLS_CIPHER_MODE_CTR
|
||||
cipher_decrypt:PSA_ALG_CTR:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a":"396ee84fb75fdbb5c2b13c7fe5a654aa":"dd3b5e5319b7591daab1e1a92687feb2":PSA_SUCCESS
|
||||
|
||||
PSA symmetric decrypt: AES-ECB, input too short (15 bytes)
|
||||
depends_on:MBEDTLS_AES_C
|
||||
cipher_decrypt:PSA_ALG_ECB_NO_PADDING:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"":"396ee84fb75fdbb5c2b13c7fe5a654":"63cecc46a382414d5fa7d2b7938743":PSA_ERROR_INVALID_ARGUMENT
|
||||
|
||||
PSA symmetric decrypt: AES-CBC-nopad, input too short (5 bytes)
|
||||
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CBC
|
||||
cipher_decrypt:PSA_ALG_CBC_NO_PADDING:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a":"6bc1bee223":"6bc1bee223":PSA_ERROR_BAD_STATE
|
||||
|
@ -1206,6 +1238,14 @@ PSA symmetric decrypt: 3-key 3DES-CBC-nopad, 8 bytes, good
|
|||
depends_on:MBEDTLS_DES_C:MBEDTLS_CIPHER_MODE_CBC
|
||||
cipher_decrypt:PSA_ALG_CBC_NO_PADDING:PSA_KEY_TYPE_DES:"01020407080b0d0ec1c2c4c7c8cbcdce31323437383b3d3e":"2a2a2a2a2a2a2a2a":"817ca7d69b80d86a":"eda4011239bc3ac9":PSA_SUCCESS
|
||||
|
||||
PSA symmetric decrypt: 2-key 3DES-ECB, 8 bytes, good
|
||||
depends_on:MBEDTLS_DES_C:MBEDTLS_CIPHER_MODE_CBC
|
||||
cipher_decrypt:PSA_ALG_ECB_NO_PADDING:PSA_KEY_TYPE_DES:"01020407080b0d0ec1c2c4c7c8cbcdce":"":"5d0652429c5b0ac7":"c78e2b38139610e3":PSA_SUCCESS
|
||||
|
||||
PSA symmetric decrypt: 3-key 3DES-ECB, 8 bytes, good
|
||||
depends_on:MBEDTLS_DES_C:MBEDTLS_CIPHER_MODE_CBC
|
||||
cipher_decrypt:PSA_ALG_ECB_NO_PADDING:PSA_KEY_TYPE_DES:"01020407080b0d0ec1c2c4c7c8cbcdce31323437383b3d3e":"":"817ca7d69b80d86a":"c78e2b38139610e3":PSA_SUCCESS
|
||||
|
||||
PSA symmetric encrypt/decrypt: AES-ECB, 16 bytes, good
|
||||
depends_on:MBEDTLS_AES_C
|
||||
cipher_verify_output:PSA_ALG_ECB_NO_PADDING:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"6bc1bee22e409f96e93d7e117393172a"
|
||||
|
@ -1230,6 +1270,14 @@ PSA symmetric encryption multipart: AES-ECB, 16+16 bytes
|
|||
depends_on:MBEDTLS_AES_C
|
||||
cipher_encrypt_multipart:PSA_ALG_ECB_NO_PADDING:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"":"6bc1bee22e409f96e93d7e117393172a5434f378a597bcef1389318c7fc865ef":16:16:16:"3ad77bb40d7a3660a89ecaf32466ef9755ed5e9e066820fa52c729886d18854c"
|
||||
|
||||
PSA symmetric encryption multipart: AES-ECB, 13+19 bytes
|
||||
depends_on:MBEDTLS_AES_C
|
||||
cipher_encrypt_multipart:PSA_ALG_ECB_NO_PADDING:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"":"6bc1bee22e409f96e93d7e117393172a5434f378a597bcef1389318c7fc865ef":13:0:32:"3ad77bb40d7a3660a89ecaf32466ef9755ed5e9e066820fa52c729886d18854c"
|
||||
|
||||
PSA symmetric encryption multipart: AES-ECB, 24+12 bytes
|
||||
depends_on:MBEDTLS_AES_C
|
||||
cipher_encrypt_multipart:PSA_ALG_ECB_NO_PADDING:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"":"6bc1bee22e409f96e93d7e117393172a5434f378a597bcef1389318c7fc865ef":24:16:16:"3ad77bb40d7a3660a89ecaf32466ef9755ed5e9e066820fa52c729886d18854c"
|
||||
|
||||
PSA symmetric encryption multipart: AES-CBC-nopad, 7+9 bytes
|
||||
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CBC
|
||||
cipher_encrypt_multipart:PSA_ALG_CBC_NO_PADDING:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a":"6bc1bee22e409f96e93d7e117393172a":7:0:16:"a076ec9dfbe47d52afc357336f20743b"
|
||||
|
@ -1298,6 +1346,14 @@ PSA symmetric decryption multipart: AES-ECB, 16+16 bytes
|
|||
depends_on:MBEDTLS_AES_C
|
||||
cipher_decrypt_multipart:PSA_ALG_ECB_NO_PADDING:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"":"3ad77bb40d7a3660a89ecaf32466ef9755ed5e9e066820fa52c729886d18854c":16:16:16:"6bc1bee22e409f96e93d7e117393172a5434f378a597bcef1389318c7fc865ef"
|
||||
|
||||
PSA symmetric decryption multipart: AES-ECB, 11+21 bytes
|
||||
depends_on:MBEDTLS_AES_C
|
||||
cipher_decrypt_multipart:PSA_ALG_ECB_NO_PADDING:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"":"3ad77bb40d7a3660a89ecaf32466ef9755ed5e9e066820fa52c729886d18854c":11:0:32:"6bc1bee22e409f96e93d7e117393172a5434f378a597bcef1389318c7fc865ef"
|
||||
|
||||
PSA symmetric decryption multipart: AES-ECB, 28+4 bytes
|
||||
depends_on:MBEDTLS_AES_C
|
||||
cipher_decrypt_multipart:PSA_ALG_ECB_NO_PADDING:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"":"3ad77bb40d7a3660a89ecaf32466ef9755ed5e9e066820fa52c729886d18854c":28:16:16:"6bc1bee22e409f96e93d7e117393172a5434f378a597bcef1389318c7fc865ef"
|
||||
|
||||
PSA symmetric decryption multipart: AES-CBC-nopad, 7+9 bytes
|
||||
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CBC
|
||||
cipher_decrypt_multipart:PSA_ALG_CBC_NO_PADDING:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a":"a076ec9dfbe47d52afc357336f20743b":7:0:16:"6bc1bee22e409f96e93d7e117393172a"
|
||||
|
@ -1326,19 +1382,19 @@ PSA symmetric encryption multipart: AES-CTR, 11+5 bytes [#2]
|
|||
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CTR
|
||||
cipher_decrypt_multipart:PSA_ALG_CTR:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a":"6bc1bee22e409f96e93d7e117393172a":11:11:5:"8f9408fe80a81d3e813da3c7b0b2bd32"
|
||||
|
||||
PSA symmetric encryption multipart: AES-CTR, 16+16 bytes [#2]
|
||||
PSA symmetric decryption multipart: AES-CTR, 16+16 bytes [#2]
|
||||
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CTR
|
||||
cipher_decrypt_multipart:PSA_ALG_CTR:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a":"6bc1bee22e409f96e93d7e117393172a5434f378a597bcef1389318c7fc865ef":16:16:16:"8f9408fe80a81d3e813da3c7b0b2bd321c965bb1de7baf71025f6ef6393ca587"
|
||||
|
||||
PSA symmetric encryption multipart: AES-CTR, 12+20 bytes [#2]
|
||||
PSA symmetric decryption multipart: AES-CTR, 12+20 bytes [#2]
|
||||
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CTR
|
||||
cipher_decrypt_multipart:PSA_ALG_CTR:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a":"6bc1bee22e409f96e93d7e117393172a5434f378a597bcef1389318c7fc865ef":12:12:20:"8f9408fe80a81d3e813da3c7b0b2bd321c965bb1de7baf71025f6ef6393ca587"
|
||||
|
||||
PSA symmetric encryption multipart: AES-CTR, 20+12 bytes [#2]
|
||||
PSA symmetric decryption multipart: AES-CTR, 20+12 bytes [#2]
|
||||
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CTR
|
||||
cipher_decrypt_multipart:PSA_ALG_CTR:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a":"6bc1bee22e409f96e93d7e117393172a5434f378a597bcef1389318c7fc865ef":20:20:12:"8f9408fe80a81d3e813da3c7b0b2bd321c965bb1de7baf71025f6ef6393ca587"
|
||||
|
||||
PSA symmetric encryption multipart: AES-CTR, 12+10 bytes [#2]
|
||||
PSA symmetric decryption multipart: AES-CTR, 12+10 bytes [#2]
|
||||
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CTR
|
||||
cipher_decrypt_multipart:PSA_ALG_CTR:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":"2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a":"6bc1bee22e409f96e93d7e117393172a5434f378a597":12:12:10:"8f9408fe80a81d3e813da3c7b0b2bd321c965bb1de7b"
|
||||
|
||||
|
|
Loading…
Reference in a new issue