Hopefully someone can help me with some understanding.  I'm going
through the samples in RFC-3602 (http://www.faqs.org/rfcs/
rfc3602.html) (the AES/CBC RFC).  I hit the first example, which looks
like this:

Case #1: Encrypting 16 bytes (1 block) using AES-CBC with 128-bit key
Key       : 0x06a9214036b8a15b512e03d534120006
IV        : 0x3dafba429d9eb430b422da802c9fac41
Plaintext : "Single block msg"
Ciphertext: 0xe353779c1079aeb82708942dbe77181a

CryptoPP's ciphertext looks like this:

0xe353779c1079aeb82708942dbe77181a b97c825e1c785146542d396941bce55d

The cipher is correct, but it is giving me two blocks instead of a
single block.  Here is the code I'm using:


        cout << "Blocksize:  " << CryptoPP::AES::BLOCKSIZE << endl;
        cout << "Def Keylen: " << CryptoPP::AES::DEFAULT_KEYLENGTH <<
endl;

        string plainStr =  "Single block msg";
        byte key[16] = { 0x06, 0xa9, 0x21, 0x40, 0x36, 0xb8, 0xa1,
0x5b,
                         0x51, 0x2e, 0x03, 0xd5, 0x34, 0x12, 0x00,
0x06 };
        byte iv[16] = { 0x3d, 0xaf, 0xba, 0x42, 0x9d, 0x9e, 0xb4,
0x30,
                        0xb4, 0x22, 0xda, 0x80, 0x2c, 0x9f, 0xac,
0x41 };
        byte * plain = (byte *) plainStr.c_str();
        byte cipher[16] = { 0xe3, 0x53, 0x77, 0x9c, 0x10, 0x79, 0xae,
0xb8,
                            0x27, 0x08, 0x94, 0x2d, 0xbe, 0x77, 0x18,
0x1a };
        string outStr;
        AES::Encryption tEncryptor(key, sizeof(key));
        CBC_Mode_ExternalCipher::Encryption encryptor(tEncryptor, iv,
sizeof(iv));
        cout << "Trying the string..." << endl;
        CryptoPP::StringSource( plainStr, true,
                                new
CryptoPP::StreamTransformationFilter(
                                    encryptor,
                                    new CryptoPP::StringSink( outStr )
                                    ) // StreamTransformationFilter
            ); // StringSource
        const unsigned char * theOutPtr = (unsigned char *)
outStr.c_str();
        cout << "Output size: " << outStr.size() << endl;

For my project, I want to make sure I'm not screwing things up by
setting CryptoPP up incorrectly, so I want to make sure I get back
what I expect to.  Is there some other way I should be setting up
things like padding to get the expected results?

Thanks.

tj

-- 
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