AnsweredAssumed Answered

K82: mbedtls mbedtls_gcm_crypt_and_tag/mbedtls_gcm_auth_decrypt

Question asked by Eugene Hiihtaja on Aug 12, 2019
Latest reply on Aug 20, 2019 by Estephania Martinez

Hello !

 

NXP implement own pair of APIs mbedtls_gcm_crypt_and_tag/mbedtls_gcm_auth_decrypt what is LTC accelerated.

 

But it is not so clear if context of decrypt operation supports decryption by using smaller blocks.

 

For example mbedtls_gcm_crypt_and_tag() is used and taged for 4KB block of data at one.

 

And after that can I decrypt it by using 1KB chunks, e.g call mbedtls_gcm_auth_decrypt() 4 times and pass some context from stage to stage ?

 

Looks like already second 1KB block give invalid data . Does those API is even disagned for incremental operation

or they always expect complete data for input and output ?

 

// decrypt by using 2 chunks
mbedtls_gcm_init(&gcm);
keysize = 256;
memset(buf, 0, sizeof(buf)); // output buffer
memset(key, 0x55, sizeof(key));
memset(iv, 0xAA, sizeof(iv));
mbedtls_gcm_setkey(&gcm, MBEDTLS_CIPHER_ID_AES, key, keysize);

int res = mbedtls_gcm_auth_decrypt(&gcm, /*MBEDTLS_GCM_DECRYPT,*/
BUFSIZE/4,
iv, // iv
12, // iv len
NULL, 0, // add
//tag, 16, // tag
NULL, 16, // ignore tag
buf_out, // in
buf); // out

PRINTF("1 decrypt %d bytes, res - %d\r\n", BUFSIZE/4, res);

 

Data OK !


res = mbedtls_gcm_auth_decrypt(&gcm, 
BUFSIZE/4,
iv, // iv
12, // iv len
NULL, 0, // add
//tag, 16, // tag
NULL, 16, // ignore tag
buf_out + 256, // in
buf + 256); // out

PRINTF("2 decrypt %d bytes, res - %d\r\n", BUFSIZE/4, res);

 

Data broken

 

 

Regards,

Eugene

Outcomes