I currently have some code that works correctly with the LibTomCrypt libraries, but not with Botan (I am trying to convert it over to Botan).
My (working) LibTomCrypt code:
// read the initial vector
unsigned char iv[0x20];
fseek(inputFile, 0x20, SEEK_SET);
fread(iv, 0x20, 1, inputFile);
// call ctr_start
res = ctr_start(0, iv, key, 0x20, 0, 0, &ctr);
if (res == 0)
{
printf("decrypting data...\n");
// read the encrypyted data
unsigned char cipheredText[0x3A8];
fread(cipheredText, 0x3A8, 1, inputFile);
// decrypt the data
unsigned char uncipheredText[0x3A8];
if (ctr_decrypt(cipheredText, uncipheredText, 0x3A8, &ctr) != 0)
{
fclose(inputFile);
printf("ERROR: ctr_decrypt did not return 0\n");
return -1;
}
if (ctr_done(&ctr) != 0)
{
fclose(inputFile);
printf("ERROR: ctr_done did not return 0\n");
return -1;
}
printf("writing decrypted data...\n");
// get the decrypted path
char *decPath = concat(fileName, ".dec", 4);
// write the decrypted data to disk
FILE *outFile = fopen(decPath, "w");
fwrite(uncipheredText, 0x3A8, 1, outFile);
fclose(outFile);
}
else
{
printf("ERROR: ctr_start did not return 0\n");
}
As you can see, my the size of my initial vector (IV), is 0x20 (32). I don't know why this would work with this library, but I went to the method and it seems like it has something to do with the 'blocklen' in LibTomCrypt.
Anyway, this is what I am trying to do with the Botan libraries:
// get the iv
t1Stream->setPosition(0x20);
BYTE rawIV[0x20];
t1Stream->readBytes(rawIV, 0x20);
// get the encrypted data
t1Stream->setPosition(0x40);
BYTE cipheredText[0x3A8];
t1Stream->readBytes(cipheredText, 0x3A8);
// setup the keys & IV
Botan::SymmetricKey symKey(key, 0x20);
Botan::InitializationVector IV(rawIV, 0x20);
// setup the 'pipe' ?
Botan::Pipe pipe(Botan::get_cipher("AES-256/CBC/NoPadding", symKey, IV, Botan::DECRYPTION));
But it keeps throwing this on the call of 'get_cipher':
terminate called after throwing an instance of 'Botan::Invalid_Key_Length'
what(): Botan: AES-256 cannot accept a key of length 32
If I do change the IV size to 16, than it does work correctly, but cannot process stuff since the IV is incorrect.
Also, change the IV size in my encrypting code is not an option.