Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ljmblueday opened this issue Feb 7, 2023 · 0 comments
Open

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

ljmblueday opened this issue Feb 7, 2023 · 0 comments

Comments

@ljmblueday
Copy link

ljmblueday commented Feb 7, 2023

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant