I have to encrypt some data using a 4 byte IV. However, the encryption algorithm that I am using (AES128)needs a 16 byte (128 bit) key. Say, my code is as follows:
#include<gcrypt.h>
void encrypt(){
int IV = 6174;
gcry_cipher_hd_t hd;
errStatus = gcry_cipher_open(&hd, GCRY_CIPHER_AES128, GCRY_CIPHER_MODE_CBC, 0);
errStatus = gcry_cipher_setkey(hd, keyBuffer, 16);
gcry_cipher_setiv(hd, &IV, 16);
gcry_cipher_encrypt(hd, output, 16, bytesToEncrypt, 16);
}
Say keyBuffer
contains a 16 byte key and bytes,
output` are my input and output respectively. How do I go about properly giving the IV?
Can you try this code just for avoiding buffer overflow? I haven't tested this myself, though