Search code examples
aesbotan

Invalid argument: AES-128/XTS cannot accept a key of length 16


I'm trying to use AES-128/XTS in Botan, but the following exception is thrown:

terminate called after throwing an instance of 'Botan::Invalid_Key_Length'    
what():  Invalid argument AES-128/XTS cannot accept a key of length 16

My program is like this (header files are omitted):

using namespace Botan;
int main()
{
    SymmetricKey key_t(hex_decode("13232453fa2343432453de2adfedf2fa"));
    InitializationVector iv_t(hex_decode("0b0c7fc670656e36a7637b4e209885a9"));
    Pipe encryptor(get_cipher("AES-128/XTS", key_t, iv_t, Botan::ENCRYPTION));
    encryptor.process_msg((uint8_t *)s.data(), s.size());
    return 0;
}

I really wonder what goes wrong here.


Solution

  • AES-XTS has a quirk where the key length supplied must be double. 256 bit for 128 and 512 for 256. Check the XTS section of https://en.m.wikipedia.org/wiki/Disk_encryption_theory if you're curious why.