I've just updated my working 4.2 code to use 5.0 (downloaded from the
website, not from CVS).  Under 4.2, Seek()'ing worked correctly for me, but
it no longer seems to work under 5.

Here's some test code that demonstrates the failure:

 AutoSeededRandomPool rnd;

 SecByteBlock pass;
 const char* passphrase  = "test passphrase-";
 pass.Assign((unsigned char*)passphrase, strlen(passphrase));

 unsigned char plain[100], buffer[100];
 rnd.GenerateBlock(plain, 100);
 memcpy(buffer, plain, 100);

 SecByteBlock IV;
 IV .New(IV_SIZE);
 rnd.GenerateBlock(IV, IV_SIZE);

 CTR_Mode<Blowfish>::Encryption Enc(pass, pass.size(), IV);
 CTR_Mode<Blowfish>::Decryption Dec(pass, pass.size(), IV);

 // encode, then decode the buffer
 Enc.ProcessString(buffer, 100);
 _ASSERT(memcmp(plain, buffer, 100) != 0); // passes
 Dec.ProcessString(buffer, 100);
 // does it match the plaintext?
 _ASSERT(memcmp(plain, buffer, 100) == 0); // passes

 // encrypt the buffer again
 Enc.Seek(0);
 Enc.ProcessString(buffer, 100);
 // copy the first plain byte into the first encrypted byte,
 //  seek the streamcipher and process it.
 buffer[0] = plain[0];
 Enc.Seek(0);
 Enc.ProcessString(buffer, 1);
 // now try to decode the buffer again
 Dec.Seek(0);
 Dec.ProcessString(buffer, 100);
 // do they still match?
 _ASSERTE(memcmp(plain, buffer, 100) == 0); // FAILS!

Does anyone see anything wrong with this?  If no, Wei, any idea what's
happening here?
--
gl

Reply via email to