Skip to content

AES CBC, ECB mode input size are fixed with BLOCK_SIZE #33

Description

@ljmblueday

AES CBC and ECB mode input sizes are fixed as BLOCK_SIZE.
For GCM, CTR mode, use in_size as input->data_length. However, for CBC, ECB mode, in_size is fixed as BLOCK_SIZE. This results in poor performance when encrypting and decrypting.

TA_aes_update function in crypto_aes.c file
keymaster_error_t TA_aes_update(keymaster_operation_t *operation,
				keymaster_blob_t *input,
				keymaster_blob_t *output,
				uint32_t *out_size,
				const uint32_t input_provided,
				size_t *input_consumed,
				const keymaster_key_param_set_t *in_params,
				bool *is_input_ext)
{
	keymaster_error_t res = KM_ERROR_OK;
	uint32_t pos = 0U;
	uint32_t remainder = 0;
	**uint32_t in_size = BLOCK_SIZE;**
.
.
.

Performance test result (AES 256, data size 16MBytes)

CBC 6.7172
ECB 6.703
CTR 0.6988
GCM 0.705

In the case of CBC and ECB modes as follows, if in_size is put in as implemented in code, it shows the same performance as in GCM and CTR modes. Please give me a review opinion on the improved code.

} else {
		if (operation->mode == KM_MODE_CTR)
			/* CTR is a stream mode */
			in_size = input->data_length;
		else
			**/* KM_MODE_CBC, KM_MODE_ECB */
			in_size = input->data_length - ((input->data_length)% BLOCK_SIZE);**

		while (operation->mode == KM_MODE_CTR
			   || remainder / BLOCK_SIZE != 0) {
			/* calculate memory left.
			 * Add BLOCK_SIZE in case adding padding
			 */
	 		if(operation->purpose == KM_PURPOSE_DECRYPT && operation->padding == KM_PAD_PKCS7 && remainder == 16)
				break;
CBC 0.625
ECB 0.647
CTR 0.635
GCM 0.622

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions