현재 LibTomCrypt 라이브러리에서는 올바르게 작동하지만 Botan에서는 작동하지 않는 코드가 있습니다 (Botan으로 변환하려고합니다).Botan AES-256, 32 비트 InitialVector
내 (작업) LibTomCrypt 코드 : 당신이 볼 수 있듯이
// 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");
}
, 내 초기 벡터의 내 크기 (IV)가 0x20 (32)입니다. 왜 이것이이 라이브러리에서 작동하는지 모르겠지만,이 메소드로 갔고 LibTomCrypt의 'blocklen'과 관련이있는 것처럼 보입니다. 어쨌든
이 내가 모란 라이브러리와 함께 할 노력하고 무엇 :// 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));
그러나 'get_cipher'의 호출이 던지는 계속 :
terminate called after throwing an instance of 'Botan::Invalid_Key_Length'
what(): Botan: AES-256 cannot accept a key of length 32
내가 할 경우 변경 IV 크기가 16으로 올바르게 작동하지만 IV가 올바르지 않기 때문에 물건을 처리 할 수 없습니다.
또한 내 암호화 코드에서 IV 크기를 변경하는 것은 옵션이 아닙니다.
AES는 128 비트의 블록 크기를 갖고 IV는 하나의 블록입니다. 당신의 망상에도 불구하고 암호화 알고리즘이 소비하는 IV는 16 바이트가됩니다. –
하드 코딩 된 리터럴 대신 실제로 상수를 사용해야하며, 코드를 읽기 어렵고 변경하기 어렵게 만들고 다른 사람들이 실수를 더 쉽게 볼 수있게합니다. 라이브러리가 있으면 라이브러리를 사용하십시오 (예 : LibTomCrypt에서 AES가'ctr_start()'의 첫 번째 인수에 대해 상수 0을 가짐을 가정합니다)? –