As in the title, I am looking for the difference in the cryptopp library between this declaration:
CBC_Mode<AES>::Decryption
cbcDecryption.SetKeyWithIV(key, AES::DEFAULT_KEYLENGTH, iv);
and this one:
AES::Decryption aesDecryption(key, AES::DEFAULT_KEYLENGTH);
CBC_Mode_ExternalCipher::Decryption cbcDecryption( aesDecryption, iv );
Moreover, I can't understand why with this:
AES::Decryption aesDecryption(key, AES::DEFAULT_KEYLENGTH);
CBC_Mode_ExternalCipher::Decryption cbcDecryption( aesDecryption, iv );
StreamTransformationFilter stfDecryptor(
cbcDecryption,
new StringSink( recoveredtext )
);
stfDecryptor.Put( reinterpret_cast<const unsigned char*>( ciphertext.c_str() ), ciphertext.size() );
stfDecryptor.MessageEnd();
all works fine while using the templated mode I have this error during run time:
AES128CBC: /usr/local/include/cryptopp/misc.h:304: void CryptoPP::memcpy_s(void*, size_t, const void*, size_t): Assertion `dest != __null' failed.
Aborted (core dumped)
Shouldn't be the same?
I have looked at this but I didn't understand well the difference and searching over the net I couldn't find an answer to my problem.
The explanation for the
*_ExternalCiphers
is given inmodes.h
, and it shows up on the web inCipherModeDocumentation Class Reference
. Its not easy to find, and I only know about it because I work closely with the sources.Here's the text:
So the difference is how the mode of operation associates with the cipher - literally external versus internal.
External - below are two distinct objects. The first is the symmetric cipher, the second is the mode of operation:
Internal - below is a single object. The mode of operation "has a" symmetric cipher that's instantiated through the template:
OK, this is a different problem. Let's see how to use it:
You can find validat1.cpp online, starting around line 1366:
So the wild card is
DESEncryption
andDESDecryption
. Let's see about it:So AES should cut-in cleanly. Now, the test program:
Compile and run:
So everything appears to be working as expected.
Now, for this issue:
In AES128 in CBC mode implementation using cryptopp library, you were told to use the latest Crypto++ library because we cleaned up a few of them. See this comment:
You also accepted Zaph's answer, so that should be the end of things with respect to you troubles with decryption and the assert. That signaled to me and the Stack Overflow community you did not need additional help or answers.
The problem you are likely running into is mixing your version of Crypto++ located at
/usr/local
with the one you installed via your distro withsudo apt-get install libcrypto++-dev libcrypto++-doc libcrypto++-utils
. The assert is a classic sign of mixing and matching them because the distro provides an old version of the library.If you take note of the command line I used, you will see:
-DNDEBUG -g2 -O2
to ensure I'm using the same options as used to build the library-I
to ensure I'm using the Crypto++ headers in PWD./libcryptopp.a
to ensure I link to the static version of the library in PWD and avoid runtime linking/loading with the wrong libraryYou are probably runtime linking with the wrong Crypto++ library. I avoid them by controlling exactly what is linked, and not depending on the runtime link/loader.
You are free to use the runtime link/loader to do these things, but care must be taken to ensure you get the right library at runtime. For that, see GNUmakefile | Compiling and Linking. I think you are in the second case called out as BAD:
If its not solved, then you need to post a Minimal, Complete, and Verifiable example (MCVE). It could well be that an assert fires under your data set. We had one recently at Trying to do CMAC on VS2013 and found this error. "Assertion failed: (input && length) || !(input || length)". We checked-in the fix within hours of the report, which is less than 30 days ago.
I also need to see your compile and link command, and the output of
ldd
to see what you are linking against.Sometimes, there's nothing we can do when you don't provide the plain text or cipher text data (
input0.txt
andoutput0.txt
), or you don't provide details like the compile and link command.