Hi All,

I'm using AES in CTR mode. After I encrypt a block of data (happens to
be of size AES::BLOCKSIZE), I get a random IV back on a call to
GetNextIV(). Is there a way to get the next counter back?

I'm trying to verify my management of the counter value is consistent
with Crypto++'s management of the counter.

Jeff

   ///////////////////////////////////////
   // Key and Counter
   ///////////////////////////////////////

   byte key[ CryptoPP::AES::DEFAULT_KEYLENGTH ];
   byte counter[ CryptoPP::AES::BLOCKSIZE ];
   byte next[ CryptoPP::AES::BLOCKSIZE ];  // next counter

   ::memset( key, 0xAA, CryptoPP::AES::DEFAULT_KEYLENGTH );
   ::memset( counter, 0x00, CryptoPP::AES::BLOCKSIZE );

   ///////////////////////////////////////
   // Sources and Sinks
   ///////////////////////////////////////

   // Message M
   std::string PlainText;

   // Cipher Text Sink
   std::string CipherText;

   // Recovered Text Sink
   std::string RecoveredText;

   ///////////////////////////////////////
   // Random Data
   ///////////////////////////////////////
   CryptoPP::AutoSeededRandomPool rng;
   CryptoPP::RandomNumberSource( rng,
       CryptoPP::AES::BLOCKSIZE,
       true, new CryptoPP::StringSink( PlainText )
   );

   ///////////////////////////////////////
   // Encryption
   ///////////////////////////////////////

   CryptoPP::CTR_Mode< CryptoPP::AES >::Encryption Encryptor;
   Encryptor.SetKeyWithIV( key, sizeof(key), counter );

   CryptoPP::StringSource( PlainText, true,
       new CryptoPP::StreamTransformationFilter(
         Encryptor,
         new CryptoPP::StringSink( CipherText )
       ) // StreamTransformationFilter
   ); // StringSource

   ///////////////////////////////////////
   // Next Counter Value
   ///////////////////////////////////////
   Encryptor.GetNextIV( NullRng, next );

  ...

   std::string scratch;
   CryptoPP::ArraySource(
       (const byte*)next, CryptoPP::AES::BLOCKSIZE, true,
       new CryptoPP::HexEncoder(
           new CryptoPP::StringSink( scratch ), true, 2
       )
   );

   cout << "Next Counter: " << endl;
   cout << scratch << endl;

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the "Crypto++ Users" 
Google Group.
To unsubscribe, send an email to [EMAIL PROTECTED]
More information about Crypto++ and this group is available at 
http://www.cryptopp.com.
-~----------~----~----~----~------~----~------~--~---

Reply via email to