Forgive us if the following behavior isn't a bug and is expected (we only
started using cryptopp).

When using AES CBC key (CryptoPP release V.5.5.2) to decode the SAME
ciphertext twice, we got garbage result on the second try. In the following
very simple example, the first 16 bytes would be decoded into garbage when
the same cipher text was decoded for the second time.

============ start example ==============
{
    // Key and IV setup
    byte key[CryptoPP::AES::DEFAULT_KEYLENGTH ], 
          iv[CryptoPP::AES::BLOCKSIZE ];

    memset(key, 0x01, CryptoPP::AES::DEFAULT_KEYLENGTH);
    memset(iv, 0x01, CryptoPP::AES::BLOCKSIZE);

    // Plain text
    std::string PlainText = "-First 16 bytes- Hello World";

    // Cipher Text Sink
    std::string CipherText;

    // Encryption
    CryptoPP::CBC_Mode<CryptoPP::AES>::Encryption
        Encryptor(key, sizeof(key), iv);

    CryptoPP::StringSource(PlainText, true,
        new CryptoPP::StreamTransformationFilter(Encryptor,
            new CryptoPP::StringSink(CipherText)
        )
    );
    
    // Copy the cipher text
    std::string CipherText2 = CipherText;

    // Recovered Text Sinks
    std::string RecoveredText;
    std::string RecoveredText2;

    // Decryption
    CryptoPP::CBC_Mode<CryptoPP::AES>::Decryption
        Decryptor( key, sizeof(key), iv );

    // First decoding
    CryptoPP::StringSource(CipherText, true,
        new CryptoPP::StreamTransformationFilter(Decryptor,
            new CryptoPP::StringSink(RecoveredText)
        )
    );
    // Second decoding
    CryptoPP::StringSource(CipherText, true,
        new CryptoPP::StreamTransformationFilter(Decryptor,
            new CryptoPP::StringSink(RecoveredText2)
        )
    );

    std::cout << "First Recovered Text:" << std::endl;
    std::cout << "  '" << RecoveredText << "'" << std::endl;
    std::cout << std::endl;

    std::cout << "Second (garbage) Recovered Text:" << std::endl;
    std::cout << "  '" << RecoveredText2 << "'" << std::endl;
    std::cout << std::endl;
}

-- 
View this message in context: 
http://www.nabble.com/CryptoPP-Bug-%28-%29%3A-cannot-decode-the-SAME-ciphertext-twice-tp15912506p15912506.html
Sent from the Crypto++ Users mailing list archive at Nabble.com.


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