Hi All,
I am confused by CBC_CTS_Mode.
Here is my program.
----------------------------------------------------------------------------------------------------------
#include <iostream>
#include <cryptopp/aes.h>
#include <cryptopp/modes.h>
#include <cryptopp/filters.h>
#include <cryptopp/hex.h>
#include <cryptopp/files.h>
using namespace std;
using namespace CryptoPP;
int main()
{
string message = "this is a message for testing";
string ciphertext;
string messageRecovered;
cout << "Plaintext (" << message.size() << " bytes):\n\t" <<
message << '\n';
byte key[AES::DEFAULT_KEYLENGTH], iv[AES::BLOCKSIZE];
::memset(key, 0x01, sizeof(key));
::memset(iv, 0x11, sizeof(iv));
CBC_CTS_Mode<AES>::Encryption encryptor(key,
AES::DEFAULT_KEYLENGTH, iv);
StringSource(message, true, new StreamTransformationFilter(
encryptor, new StringSink(ciphertext)));
cout << "Ciphertext (" << ciphertext.size() << " bytes):\n\t";
StringSource(ciphertext, true, new HexEncoder(new
FileSink(cout)));
cout << '\n';
CBC_CTS_Mode<AES>::Decryption decryptor(key,
AES::DEFAULT_KEYLENGTH, iv);
StringSource(ciphertext, true, new StreamTransformationFilter(
decryptor, new StringSink(messageRecovered)));
cout << "Plaintext recovered (" << messageRecovered.size() << "
bytes):\n\t";
cout << messageRecovered << endl;
return 0;
}
--------------------------------------------------------------------------------------------------------------------
The running result:
-------------------------------------------------------------------------------------------------------------------
Plaintext (29 bytes):
this is a message for testing
Ciphertext (29 bytes):
8383CA42A94C7781D0ACA5BECB663F7CFA8DE5CB20080DCB329C96825B
Plaintext recovered (29 bytes):
this is a message for testing
-------------------------------------------------------------------------------------------------------------------
I thought CBC_CTS_Mode was block-oriented, right?
And I thought length of the outputed cipher should be 32 bytes, but
the result was not.
If I use CBC_CTS_Mode to process data directly (not by
StreamTransformationFilter),
I can only process data with length of multiple block size.
They seems to be conflicting with each other? What's wrong with this?
Regards,
Yongce
--~--~---------~--~----~------------~-------~--~----~
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.
-~----------~----~----~----~------~----~------~--~---