I'm applying the Arduino Crypto Library for the code fragments.
In the above library, example of encryption and decryption using GCM given as follows:
For encryption:
GCM<AES256> gcm;
gcm.setKey(key, sizeof(key));
gcm.setIV(iv, sizeof(iv));
gcm.addAuthData(adata, sizeof(adata));
gcm.encrypt(ciphertext, plaintext, sizeof(plaintext));
gcm.computeTag(tag, sizeof(tag));
For decryption:
GCM<AES256> gcm;
gcm.setKey(key, sizeof(key));
gcm.setIV(iv, sizeof(iv));
gcm.addAuthData(adata, sizeof(adata));
gcm.decrypt(ciphertext, plaintext, sizeof(plaintext));
if (!gcm.checkTag(tag, sizeof(tag))) {
// The data was invalid - do not use it.
...
}
These are my questions:
- Should the IV be unique for each 128 bit text or for each message? How should the next IV be generated? Should we increment the IV by one for each message or for each block of 128 bit?
- Does adding the IV in authentication data makes it less secure?
- Does sending the computed tag by prepending / appending to the ciphertext, create any vulnerability?
- What is the standard way to share the IV & computed tag?
incrementing for each message is insecure. must be randomly generated
. I think generating the iv randomly, is insecure as there is still a chance that iv become repetitive. So incrementing the iv by message_length_in_bit/128 would be the best way to go. What do you think? It is hard for me to read the specification as I have very little knowledge about cryptography mathematically. $\endgroup$