title: Botan AES-256, 32 bit InitialVector
body: <p>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).</p>
  
  <p>My (working) LibTomCrypt code:</p>
  
  <pre><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, &amp;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, &amp;ctr) != 0)
          {
              fclose(inputFile);
              printf("ERROR: ctr_decrypt did not return 0\n");
              return -1;
          }
          if (ctr_done(&amp;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");
      }
  </code></pre>
  
  <p>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.</p>
  
  <p>Anyway, this is what I am trying to do with the Botan libraries:</p>
  
  <pre><code>// get the iv
  t1Stream-&gt;setPosition(0x20);
  BYTE rawIV[0x20];
  t1Stream-&gt;readBytes(rawIV, 0x20);
  
  // get the encrypted data
  t1Stream-&gt;setPosition(0x40);
  BYTE cipheredText[0x3A8];
  t1Stream-&gt;readBytes(cipheredText, 0x3A8);
  
  // setup the keys &amp; 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));
  </code></pre>
  
  <p>But it keeps throwing this on the call of 'get_cipher':</p>
  
  <pre><code>terminate called after throwing an instance of 'Botan::Invalid_Key_Length'
    what():  Botan: AES-256 cannot accept a key of length 32
  </code></pre>
  
  <p>If I do change the IV size to 16, than it does work correctly, but cannot process stuff since the IV is incorrect.</p>
  
  <p>Also, <strong>change the IV size in my encrypting code is not an option.</strong></p>