Closed erikbs closed 8 years ago
Good idea! We will use that...
Thanks!
Mike
On Tue, Aug 2, 2016 at 10:42 PM, erikbs notifications@github.com wrote:
Hi
I have a suggestion concerning in-place encryption and decryption using the AES-GCM algorithm (mrgcm.c).
The implementation currently supports in-place encryption by passing the same pointer to both the char plain and char cipher parameters of gcm_add_cipher, like this: gcm_add_cipher(&g, GCM_ENCRYPTING, BUFFER_NAME, len, BUFFER_NAME);
In-place decryption, however, works only partially. If GCM_DECRYPTING is passed instead of GCM_ENCRYPTING, the message is decrypted correctly, but the tag is computed in the same way as during encryption. This is of course because the if statements on lines 197 and 198 become identical. Consider the following lines in mrgcm.c:
- if (mode==GCM_ENCRYPTING) cipher[j]=plain[j]^B[i];
- if (mode==GCM_DECRYPTING) plain[j]=cipher[j]^B[i];
- g->stateX[i]^=cipher[j++];
If the incrementation is placed on a separate line and the if statements are reordered like this …:
- if (mode==GCM_ENCRYPTING) cipher[j]=plain[j]^B[i];
- g->stateX[i]^=cipher[j];
- if (mode==GCM_DECRYPTING) plain[j]=cipher[j]^B[i];
- j++;
… then the tag is computed correctly for in-place decryption as well. As far as I can see, it should not cause any problems. Any thought on this idea?
TL;DR: swapping lines 198 and 199 in mrgcm.c, then placing j++ on a separate line, will make in-place decryption work.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/miracl/MIRACL/issues/27, or mute the thread https://github.com/notifications/unsubscribe-auth/ACm8jpcfj7Mx6i1NzYDXO78xRJNX4w4jks5qb7mvgaJpZM4JbFI0 .
Hi
I have a suggestion concerning in-place encryption and decryption using the AES-GCM algorithm (mrgcm.c).
The implementation currently supports in-place encryption by passing the same pointer to both the
char *plain
andchar *cipher
parameters ofgcm_add_cipher
, like this:gcm_add_cipher(&g, GCM_ENCRYPTING, BUFFER_NAME, len, BUFFER_NAME);
In-place decryption, however, works only partially. If
GCM_DECRYPTING
is passed instead ofGCM_ENCRYPTING
, the message is decrypted correctly, but the tag is computed in the same way as during encryption. This is of course because theif
statements on lines 197 and 198 become identical. Consider the following lines in mrgcm.c:If the incrementation is placed on a separate line and the
if
statements are reordered like this …:… then the tag is computed correctly for in-place decryption as well. As far as I can see, it should not cause any problems. Any thought on this idea?
TL;DR: swapping lines 198 and 199 in mrgcm.c, then placing j++ on a separate line, will make in-place decryption work.