diff --git a/Readme.txt b/Readme.txt index e449bb50..44b32d77 100644 --- a/Readme.txt +++ b/Readme.txt @@ -264,4 +264,6 @@ History 5.2 - Merged in changes for 5.01 - 5.0.4 - added support for using encoding parameters and key derivation parameters - with public key encryption (implemented by OAEP and DLIES) + with public key encryption (implemented by OAEP and DL/ECIES) + - added Camellia, SHACAL-2, Two-Track-MAC, Whirlpool, RIPEMD-320, + RIPEMD-128, RIPEMD-256, Base 32 coding diff --git a/algparam.h b/algparam.h index 95a90772..b6f21028 100644 --- a/algparam.h +++ b/algparam.h @@ -67,7 +67,7 @@ private: unsigned int m_size; }; -class CombinedNameValuePairs : public NameValuePairs +class CRYPTOPP_DLL CombinedNameValuePairs : public NameValuePairs { public: CombinedNameValuePairs(const NameValuePairs &pairs1, const NameValuePairs &pairs2) @@ -323,6 +323,12 @@ public: return AlgorithmParameters, R>(*this, name, value, m_throwIfNotUsed); } + template + AlgorithmParameters, R> operator()(const char *name, const R &value, bool throwIfNotUsed) const + { + return AlgorithmParameters, R>(*this, name, value, throwIfNotUsed); + } + private: const NameValuePairs & GetParent() const {return m_parent;} PARENT m_parent; @@ -331,7 +337,11 @@ private: //! Create an object that implements NameValuePairs for passing parameters /*! \param throwIfNotUsed if true, the object will throw an exception if the value is not accessed \note throwIfNotUsed is ignored if using a compiler that does not support std::uncaught_exception(), - such as MSVC 7.0 and earlier. */ + such as MSVC 7.0 and earlier. + \note A NameValuePairs object containing an arbitrary number of name value pairs may be constructed by + repeatedly using operator() on the object returned by MakeParameters, for example: + const NameValuePairs ¶meters = MakeParameters(name1, value1)(name2, value2)(name3, value3); +*/ template AlgorithmParameters MakeParameters(const char *name, const T &value, bool throwIfNotUsed = true) { diff --git a/argnames.h b/argnames.h index d5ac7058..eb35b68c 100644 --- a/argnames.h +++ b/argnames.h @@ -55,6 +55,17 @@ CRYPTOPP_DEFINE_NAME_STRING(OutputStreamPointer) //!< std::ostream * CRYPTOPP_DEFINE_NAME_STRING(OutputBinaryMode) //!< bool CRYPTOPP_DEFINE_NAME_STRING(EncodingParameters) //!< ConstByteArrayParameter CRYPTOPP_DEFINE_NAME_STRING(KeyDerivationParameters) //!< ConstByteArrayParameter +CRYPTOPP_DEFINE_NAME_STRING(Separator) //< ConstByteArrayParameter +CRYPTOPP_DEFINE_NAME_STRING(Terminator) //< ConstByteArrayParameter +CRYPTOPP_DEFINE_NAME_STRING(Uppercase) //< bool +CRYPTOPP_DEFINE_NAME_STRING(GroupSize) //< int +CRYPTOPP_DEFINE_NAME_STRING(Pad) //< bool +CRYPTOPP_DEFINE_NAME_STRING(PaddingByte) //< byte +CRYPTOPP_DEFINE_NAME_STRING(Log2Base) //< int +CRYPTOPP_DEFINE_NAME_STRING(EncodingLookupArray) //< const byte * +CRYPTOPP_DEFINE_NAME_STRING(DecodingLookupArray) //< const byte * +CRYPTOPP_DEFINE_NAME_STRING(InsertLineBreaks) //< bool +CRYPTOPP_DEFINE_NAME_STRING(MaxLineLength) //< int DOCUMENTED_NAMESPACE_END diff --git a/base64.cpp b/base64.cpp index 2670155e..f86dc6e5 100644 --- a/base64.cpp +++ b/base64.cpp @@ -11,19 +11,19 @@ static const byte s_padding = '='; void Base64Encoder::IsolatedInitialize(const NameValuePairs ¶meters) { - bool insertLineBreaks = parameters.GetValueWithDefault("InsertLineBreaks", true); - int maxLineLength = parameters.GetIntValueWithDefault("MaxLineLength", 72); + bool insertLineBreaks = parameters.GetValueWithDefault(Name::InsertLineBreaks(), true); + int maxLineLength = parameters.GetIntValueWithDefault(Name::MaxLineLength(), 72); const char *lineBreak = insertLineBreaks ? "\n" : ""; m_filter->Initialize(CombinedNameValuePairs( parameters, - MakeParameters("EncodingLookupArray", (const byte *)s_vec) - ("PaddingByte", s_padding) - ("Log2Base", 6) - ("GroupSize", insertLineBreaks ? maxLineLength : 0) - ("Separator", ConstByteArrayParameter(lineBreak)) - ("Terminator", ConstByteArrayParameter(lineBreak)))); + MakeParameters(Name::EncodingLookupArray(), &s_vec[0], false) + (Name::PaddingByte(), s_padding) + (Name::GroupSize(), insertLineBreaks ? maxLineLength : 0) + (Name::Separator(), ConstByteArrayParameter(lineBreak)) + (Name::Terminator(), ConstByteArrayParameter(lineBreak)) + (Name::Log2Base(), 6, true))); } const int *Base64Decoder::GetDecodingLookupArray() diff --git a/base64.h b/base64.h index 33072a0d..b9ba801e 100644 --- a/base64.h +++ b/base64.h @@ -12,7 +12,7 @@ public: Base64Encoder(BufferedTransformation *attachment = NULL, bool insertLineBreaks = true, int maxLineLength = 72) : SimpleProxyFilter(new BaseN_Encoder(new Grouper), attachment) { - IsolatedInitialize(MakeParameters("InsertLineBreaks", insertLineBreaks)("MaxLineLength", maxLineLength)); + IsolatedInitialize(MakeParameters(Name::InsertLineBreaks(), insertLineBreaks)(Name::MaxLineLength(), maxLineLength)); } void IsolatedInitialize(const NameValuePairs ¶meters); diff --git a/basecode.cpp b/basecode.cpp index 8b420730..e439e108 100644 --- a/basecode.cpp +++ b/basecode.cpp @@ -12,16 +12,16 @@ NAMESPACE_BEGIN(CryptoPP) void BaseN_Encoder::IsolatedInitialize(const NameValuePairs ¶meters) { - parameters.GetRequiredParameter("BaseN_Encoder", "EncodingLookupArray", m_alphabet); + parameters.GetRequiredParameter("BaseN_Encoder", Name::EncodingLookupArray(), m_alphabet); - parameters.GetRequiredIntParameter("BaseN_Encoder", "Log2Base", m_bitsPerChar); + parameters.GetRequiredIntParameter("BaseN_Encoder", Name::Log2Base(), m_bitsPerChar); if (m_bitsPerChar <= 0 || m_bitsPerChar >= 8) throw InvalidArgument("BaseN_Encoder: Log2Base must be between 1 and 7 inclusive"); byte padding; bool pad; - if (parameters.GetValue("PaddingByte", padding)) - pad = parameters.GetValueWithDefault("Pad", true); + if (parameters.GetValue(Name::PaddingByte(), padding)) + pad = parameters.GetValueWithDefault(Name::Pad(), true); else pad = false; m_padding = pad ? padding : -1; @@ -105,9 +105,9 @@ unsigned int BaseN_Encoder::Put2(const byte *begin, unsigned int length, int mes void BaseN_Decoder::IsolatedInitialize(const NameValuePairs ¶meters) { - parameters.GetRequiredParameter("BaseN_Decoder", "DecodingLookupArray", m_lookup); + parameters.GetRequiredParameter("BaseN_Decoder", Name::DecodingLookupArray(), m_lookup); - parameters.GetRequiredIntParameter("BaseN_Decoder", "Log2Base", m_bitsPerChar); + parameters.GetRequiredIntParameter("BaseN_Decoder", Name::Log2Base(), m_bitsPerChar); if (m_bitsPerChar <= 0 || m_bitsPerChar >= 8) throw InvalidArgument("BaseN_Decoder: Log2Base must be between 1 and 7 inclusive"); @@ -189,13 +189,13 @@ void BaseN_Decoder::InitializeDecodingLookupArray(int *lookup, const byte *alpha void Grouper::IsolatedInitialize(const NameValuePairs ¶meters) { - m_groupSize = parameters.GetIntValueWithDefault("GroupSize", 0); + m_groupSize = parameters.GetIntValueWithDefault(Name::GroupSize(), 0); ConstByteArrayParameter separator, terminator; if (m_groupSize) - parameters.GetRequiredParameter("Grouper", "Separator", separator); + parameters.GetRequiredParameter("Grouper", Name::Separator(), separator); else - parameters.GetValue("Separator", separator); - parameters.GetValue("Terminator", terminator); + parameters.GetValue(Name::Separator(), separator); + parameters.GetValue(Name::Terminator(), terminator); m_separator.Assign(separator.begin(), separator.size()); m_terminator.Assign(terminator.begin(), terminator.size()); diff --git a/basecode.h b/basecode.h index b2e53b6a..d1fa3b5d 100644 --- a/basecode.h +++ b/basecode.h @@ -3,6 +3,7 @@ #include "filters.h" #include "algparam.h" +#include "argnames.h" NAMESPACE_BEGIN(CryptoPP) @@ -15,10 +16,10 @@ public: BaseN_Encoder(const byte *alphabet, int log2base, BufferedTransformation *attachment=NULL, int padding=-1) : Unflushable(attachment) { - IsolatedInitialize(MakeParameters("EncodingLookupArray", alphabet) - ("Log2Base", log2base) - ("Pad", padding != -1) - ("PaddingByte", byte(padding))); + IsolatedInitialize(MakeParameters(Name::EncodingLookupArray(), alphabet) + (Name::Log2Base(), log2base) + (Name::Pad(), padding != -1) + (Name::PaddingByte(), byte(padding))); } void IsolatedInitialize(const NameValuePairs ¶meters); @@ -40,13 +41,13 @@ public: BaseN_Decoder(const int *lookup, int log2base, BufferedTransformation *attachment=NULL) : Unflushable(attachment) { - IsolatedInitialize(MakeParameters("DecodingLookupArray", lookup)("Log2Base", log2base)); + IsolatedInitialize(MakeParameters(Name::DecodingLookupArray(), lookup)(Name::Log2Base(), log2base)); } void IsolatedInitialize(const NameValuePairs ¶meters); unsigned int Put2(const byte *begin, unsigned int length, int messageEnd, bool blocking); - static void InitializeDecodingLookupArray(int *lookup, const byte *alphabet, unsigned int log2base, bool caseInsensitive); + static void InitializeDecodingLookupArray(int *lookup, const byte *alphabet, unsigned int base, bool caseInsensitive); private: const int *m_lookup; @@ -64,9 +65,9 @@ public: Grouper(int groupSize, const std::string &separator, const std::string &terminator, BufferedTransformation *attachment=NULL) : Bufferless(attachment) { - IsolatedInitialize(MakeParameters("GroupSize", groupSize) - ("Separator", ConstByteArrayParameter(separator)) - ("Terminator", ConstByteArrayParameter(terminator))); + IsolatedInitialize(MakeParameters(Name::GroupSize(), groupSize) + (Name::Separator(), ConstByteArrayParameter(separator)) + (Name::Terminator(), ConstByteArrayParameter(terminator))); } void IsolatedInitialize(const NameValuePairs ¶meters); diff --git a/bench.cpp b/bench.cpp index 8670d37a..82f84463 100644 --- a/bench.cpp +++ b/bench.cpp @@ -87,11 +87,11 @@ static const byte *const key=(byte *)"0123456789abcdefghijklmnopqrstuvwxyzABCDEF static double logtotal = 0; static unsigned int logcount = 0; -void OutputResultBytes(const char *name, unsigned long length, double timeTaken) +void OutputResultBytes(const char *name, double length, double timeTaken) { double mbs = length / timeTaken / (1024*1024); cout << "" << name; - cout << "" << length; + cout << "" << setprecision(3) << length / (1024*1024); cout << setiosflags(ios::fixed); cout << "" << setprecision(3) << timeTaken; cout << "" << setprecision(3) << mbs << endl; @@ -120,18 +120,18 @@ void BenchMark(const char *name, BlockTransformation &cipher, double timeTotal) const int nBlocks = BUF_SIZE / cipher.BlockSize(); clock_t start = clock(); - unsigned long i=0, length=BUF_SIZE; + unsigned long i=0, blocks=1; double timeTaken; do { - length *= 2; - for (; i" << endl; - cout << "AlgorithmBytes ProcessedTime TakenMegabytes(2^20 bytes)/Second\n" << endl; + cout << "AlgorithmMegabytes(2^20 bytes) ProcessedTime TakenMB/Second\n" << endl; BenchMarkKeyless("CRC-32", t); BenchMarkKeyless("Adler-32", t); diff --git a/cryptdll.dsp b/cryptdll.dsp index 21bb06b6..abdb9066 100644 --- a/cryptdll.dsp +++ b/cryptdll.dsp @@ -43,7 +43,7 @@ RSC=rc.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "CRYPTDLL_EXPORTS" /YX /FD /c -# ADD CPP /nologo /G5 /Gz /MT /W3 /GX /Zi /O1 /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "CRYPTOPP_EXPORTS" /D CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2=1 /D "USE_PRECOMPILED_HEADERS" /Yu"pch.h" /FD /Zm200 /c +# ADD CPP /nologo /G5 /Gz /MT /W3 /GX /Zi /O1 /Ob2 /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "CRYPTOPP_EXPORTS" /D CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2=1 /D "USE_PRECOMPILED_HEADERS" /Yu"pch.h" /FD /Zm200 /c # ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 # ADD BASE RSC /l 0x409 /d "NDEBUG" @@ -53,7 +53,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 -# ADD LINK32 advapi32.lib /nologo /base:"0x42900000" /dll /debug /machine:I386 /out:"DLL_Release/cryptopp.dll" /opt:ref /export:CryptoPP_Malloc=malloc /export:CryptoPP_Free=free +# ADD LINK32 advapi32.lib /nologo /base:"0x42900000" /dll /map /debug /machine:I386 /out:"DLL_Release/cryptopp.dll" /opt:ref /export:CryptoPP_Malloc=malloc /export:CryptoPP_Free=free # SUBTRACT LINK32 /pdb:none # Begin Custom Build OutDir=.\DLL_Release diff --git a/cryptest.dsp b/cryptest.dsp index 86e75e3f..3a07817f 100644 --- a/cryptest.dsp +++ b/cryptest.dsp @@ -45,7 +45,7 @@ RSC=rc.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /G5 /Gz /MT /W3 /GX /Zi /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /Zm200 /c -# ADD CPP /nologo /G5 /Gz /MD /W3 /GX /Zi /O2 /D "NDEBUG" /D "CRYPTOPP_IMPORTS" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /YX /FD /Zm400 /c +# ADD CPP /nologo /G5 /Gz /MT /W3 /GX /Zi /O2 /D "NDEBUG" /D "CRYPTOPP_IMPORTS" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /YX /FD /Zm400 /c # ADD BASE RSC /l 0x409 /d "NDEBUG" # ADD RSC /l 0x409 /d "NDEBUG" BSC32=bscmake.exe @@ -75,7 +75,7 @@ PreLink_Cmds=echo This configuration requires cryptopp.dll. echo You can build i # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /MTd /W3 /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /Zm200 /c -# ADD CPP /nologo /G5 /Gz /MDd /W3 /GX /ZI /Od /D "_DEBUG" /D "CRYPTOPP_IMPORTS" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /YX /FD /Zm400 /c +# ADD CPP /nologo /G5 /Gz /MTd /W3 /GX /ZI /Od /D "_DEBUG" /D "CRYPTOPP_IMPORTS" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /YX /FD /Zm400 /c # ADD BASE RSC /l 0x409 /d "_DEBUG" # ADD RSC /l 0x409 /d "_DEBUG" BSC32=bscmake.exe @@ -103,7 +103,7 @@ PreLink_Cmds=echo This configuration requires cryptopp.dll. echo You can build i # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD CPP /nologo /MT /W3 /GX /Zi /O2 /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /D "WIN32" /YX /FD /Zm400 /c +# ADD CPP /nologo /MT /W3 /GX /Zi /O1 /Ob2 /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /D "WIN32" /YX /FD /Zm400 /c # ADD BASE RSC /l 0x409 /d "NDEBUG" # ADD RSC /l 0x409 /d "NDEBUG" BSC32=bscmake.exe @@ -111,7 +111,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 -# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib Ws2_32.lib /nologo /subsystem:console /debug /machine:I386 /OPT:NOWIN98 /OPT:REF /OPT:ICF +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib Ws2_32.lib /nologo /subsystem:console /map /debug /machine:I386 /OPT:NOWIN98 /OPT:REF /OPT:ICF # SUBTRACT LINK32 /pdb:none !ELSEIF "$(CFG)" == "cryptest - Win32 Debug" diff --git a/cryptlib.cpp b/cryptlib.cpp index f3b3fde2..cc1e3ce6 100644 --- a/cryptlib.cpp +++ b/cryptlib.cpp @@ -359,12 +359,12 @@ unsigned int BufferedTransformation::TransferMessagesTo2(BufferedTransformation for (messageCount=0; messageCount < maxMessages && AnyMessages(); messageCount++) { unsigned int blockedBytes; - unsigned long transferedBytes; + unsigned long transferredBytes; while (AnyRetrievable()) { - transferedBytes = ULONG_MAX; - blockedBytes = TransferTo2(target, transferedBytes, channel, blocking); + transferredBytes = ULONG_MAX; + blockedBytes = TransferTo2(target, transferredBytes, channel, blocking); if (blockedBytes > 0) return blockedBytes; } diff --git a/cryptlib.dsp b/cryptlib.dsp index 30f703ed..c5a5dead 100644 --- a/cryptlib.dsp +++ b/cryptlib.dsp @@ -43,7 +43,7 @@ RSC=rc.exe # PROP Intermediate_Dir "FIPS_140_Release" # PROP Target_Dir "" # ADD BASE CPP /nologo /G5 /Gz /MT /W3 /GX /Zi /O2 /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "USE_PRECOMPILED_HEADERS" /Yu"pch.h" /FD /c -# ADD CPP /nologo /G5 /Gz /MD /W3 /GX /Zi /O2 /D "NDEBUG" /D "_WINDOWS" /D "USE_PRECOMPILED_HEADERS" /D "WIN32" /D "CRYPTOPP_IMPORTS" /Yu"pch.h" /Fd"FIPS_140_Release/cryptopp" /FD /c +# ADD CPP /nologo /G5 /Gz /MT /W3 /GX /Zi /O2 /D "NDEBUG" /D "_WINDOWS" /D "USE_PRECOMPILED_HEADERS" /D "WIN32" /D "CRYPTOPP_IMPORTS" /Yu"pch.h" /Fd"FIPS_140_Release/cryptopp" /FD /c # ADD BASE RSC /l 0x409 # ADD RSC /l 0x409 BSC32=bscmake.exe @@ -66,7 +66,7 @@ LIB32=link.exe -lib # PROP Intermediate_Dir "FIPS_140_Debug" # PROP Target_Dir "" # ADD BASE CPP /nologo /MTd /W3 /GX /ZI /Od /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "USE_PRECOMPILED_HEADERS" /Yu"pch.h" /FD /c -# ADD CPP /nologo /G5 /Gz /MDd /W3 /GX /ZI /Od /D "_DEBUG" /D "_WINDOWS" /D "USE_PRECOMPILED_HEADERS" /D "WIN32" /D "CRYPTOPP_IMPORTS" /Yu"pch.h" /Fd"FIPS_140_Debug/cryptopp" /FD /c +# ADD CPP /nologo /G5 /Gz /MTd /W3 /GX /ZI /Od /D "_DEBUG" /D "_WINDOWS" /D "USE_PRECOMPILED_HEADERS" /D "WIN32" /D "CRYPTOPP_IMPORTS" /Yu"pch.h" /Fd"FIPS_140_Debug/cryptopp" /FD /c # ADD BASE RSC /l 0x409 # ADD RSC /l 0x409 BSC32=bscmake.exe @@ -89,7 +89,7 @@ LIB32=link.exe -lib # PROP Intermediate_Dir "Release" # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c -# ADD CPP /nologo /MT /W3 /GX /Zi /O2 /D "NDEBUG" /D "_WINDOWS" /D "USE_PRECOMPILED_HEADERS" /D "WIN32" /Yu"pch.h" /FD /c +# ADD CPP /nologo /MT /W3 /GX /Zi /O1 /Ob2 /D "NDEBUG" /D "_WINDOWS" /D "USE_PRECOMPILED_HEADERS" /D "WIN32" /Yu"pch.h" /FD /c # ADD BASE RSC /l 0x409 # ADD RSC /l 0x409 BSC32=bscmake.exe @@ -210,6 +210,10 @@ SOURCE=.\asn.cpp # End Source File # Begin Source File +SOURCE=.\base32.cpp +# End Source File +# Begin Source File + SOURCE=.\base64.cpp # End Source File # Begin Source File @@ -680,6 +684,10 @@ SOURCE=.\asn.h # End Source File # Begin Source File +SOURCE=.\base32.h +# End Source File +# Begin Source File + SOURCE=.\base64.h # End Source File # Begin Source File diff --git a/cryptlib.h b/cryptlib.h index 69526a4c..f2479e88 100644 --- a/cryptlib.h +++ b/cryptlib.h @@ -206,9 +206,11 @@ struct CRYPTOPP_DLL DecodingResult }; //! interface for retrieving values given their names -/*! This class is used to safely pass a variable number of arbitrarily typed arguments to functions +/*! \note This class is used to safely pass a variable number of arbitrarily typed arguments to functions and to read values from keys and crypto parameters. - To get a value, you need to know the name and the type of the value. + \note To obtain an object that implements NameValuePairs for the purpose of parameter + passing, use the MakeParameters() function. + \note To get a value from NameValuePairs, you need to know the name and the type of the value. Call GetValueNames() on a NameValuePairs object to obtain a list of value names that it supports. Then look at the Name namespace documentation to see what the type of each value is, or alternatively, call GetIntValue() with the value name, and if the type is not int, a @@ -779,7 +781,7 @@ public: /*! There should be a MessageEnd immediately before MessageSeriesEnd. */ virtual bool MessageSeriesEnd(int propagation=-1, bool blocking=true); - //! set propagation of automatically generated and transfered signals + //! set propagation of automatically generated and transferred signals /*! propagation == 0 means do not automaticly generate signals */ virtual void SetAutoSignalPropagation(int propagation) {} diff --git a/datatest.cpp b/datatest.cpp index 13077602..a104ae5e 100644 --- a/datatest.cpp +++ b/datatest.cpp @@ -24,7 +24,7 @@ public: static const TestData *s_currentTestData = NULL; -void OutputTestData(const TestData &v) +static void OutputTestData(const TestData &v) { for (TestData::const_iterator i = v.begin(); i != v.end(); ++i) { @@ -32,13 +32,13 @@ void OutputTestData(const TestData &v) } } -void SignalTestFailure() +static void SignalTestFailure() { OutputTestData(*s_currentTestData); throw TestFailure(); } -void SignalTestError() +static void SignalTestError() { OutputTestData(*s_currentTestData); throw Exception(Exception::OTHER_ERROR, "Unexpected error during validation test"); diff --git a/dlltest.dsp b/dlltest.dsp index 7a71a598..0d82a114 100644 --- a/dlltest.dsp +++ b/dlltest.dsp @@ -42,7 +42,7 @@ RSC=rc.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD CPP /nologo /Gz /MD /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /D "CRYPTOPP_DLL_ONLY" /YX /FD /c +# ADD CPP /nologo /Gz /MT /W3 /GX /O1 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /D "CRYPTOPP_DLL_ONLY" /YX /FD /c # ADD BASE RSC /l 0x409 /d "NDEBUG" # ADD RSC /l 0x409 /d "NDEBUG" BSC32=bscmake.exe @@ -50,7 +50,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 -# ADD LINK32 /nologo /subsystem:console /debug /machine:I386 /out:"DLL_Release/dlltest.exe" /libpath:"DLL_Release" +# ADD LINK32 /nologo /subsystem:console /map /debug /machine:I386 /out:"DLL_Release/dlltest.exe" /libpath:"DLL_Release" !ELSEIF "$(CFG)" == "dlltest - Win32 Debug" @@ -66,7 +66,7 @@ LINK32=link.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c -# ADD CPP /nologo /Gz /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "CRYPTOPP_DLL_ONLY" /YX /FD /GZ /c +# ADD CPP /nologo /Gz /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "CRYPTOPP_DLL_ONLY" /YX /FD /GZ /c # ADD BASE RSC /l 0x409 /d "_DEBUG" # ADD RSC /l 0x409 /d "_DEBUG" BSC32=bscmake.exe diff --git a/hex.cpp b/hex.cpp index 5ac6e8cf..31561676 100644 --- a/hex.cpp +++ b/hex.cpp @@ -13,13 +13,20 @@ static const byte s_vecLower[] = "0123456789abcdef"; void HexEncoder::IsolatedInitialize(const NameValuePairs ¶meters) { - bool uppercase = parameters.GetValueWithDefault("Uppercase", true); + bool uppercase = parameters.GetValueWithDefault(Name::Uppercase(), true); m_filter->Initialize(CombinedNameValuePairs( parameters, - MakeParameters("EncodingLookupArray", uppercase ? &s_vecUpper[0] : &s_vecLower[0])("Log2Base", 4))); + MakeParameters(Name::EncodingLookupArray(), uppercase ? &s_vecUpper[0] : &s_vecLower[0], false)(Name::Log2Base(), 4, true))); } -const int *HexDecoder::GetDecodingLookupArray() +void HexDecoder::IsolatedInitialize(const NameValuePairs ¶meters) +{ + BaseN_Decoder::Initialize(CombinedNameValuePairs( + parameters, + MakeParameters(Name::DecodingLookupArray(), GetDefaultDecodingLookupArray(), false)(Name::Log2Base(), 4, true))); +} + +const int *HexDecoder::GetDefaultDecodingLookupArray() { static bool s_initialized = false; static int s_array[256]; diff --git a/hex.h b/hex.h index ec8c91c0..74302f28 100644 --- a/hex.h +++ b/hex.h @@ -12,7 +12,7 @@ public: HexEncoder(BufferedTransformation *attachment = NULL, bool uppercase = true, int outputGroupSize = 0, const std::string &separator = ":", const std::string &terminator = "") : SimpleProxyFilter(new BaseN_Encoder(new Grouper), attachment) { - IsolatedInitialize(MakeParameters("Uppercase", uppercase)("GroupSize", outputGroupSize)("Separator", ConstByteArrayParameter(separator))); + IsolatedInitialize(MakeParameters(Name::Uppercase(), uppercase)(Name::GroupSize(), outputGroupSize)(Name::Separator(), ConstByteArrayParameter(separator))); } void IsolatedInitialize(const NameValuePairs ¶meters); @@ -23,12 +23,12 @@ class CRYPTOPP_DLL HexDecoder : public BaseN_Decoder { public: HexDecoder(BufferedTransformation *attachment = NULL) - : BaseN_Decoder(GetDecodingLookupArray(), 4, attachment) {} + : BaseN_Decoder(GetDefaultDecodingLookupArray(), 4, attachment) {} - void IsolatedInitialize(const NameValuePairs ¶meters) {} + void IsolatedInitialize(const NameValuePairs ¶meters); private: - static const int *GetDecodingLookupArray(); + static const int *GetDefaultDecodingLookupArray(); }; NAMESPACE_END diff --git a/modes.h b/modes.h index e6b30e09..34dd21ab 100644 --- a/modes.h +++ b/modes.h @@ -275,19 +275,26 @@ template class CipherModeFinalTemplate_ExternalCipher : public BASE { public: - CipherModeFinalTemplate_ExternalCipher(BlockCipher &cipher); + CipherModeFinalTemplate_ExternalCipher() {} + CipherModeFinalTemplate_ExternalCipher(BlockCipher &cipher) + {SetCipher(cipher);} + CipherModeFinalTemplate_ExternalCipher(BlockCipher &cipher, const byte *iv, int feedbackSize = 0) + {SetCipherWithIV(cipher, iv, feedbackSize);} - CipherModeFinalTemplate_ExternalCipher(BlockCipher &cipher, const byte *iv, int feedbackSize = 0); + void SetCipher(BlockCipher &cipher); + void SetCipherWithIV(BlockCipher &cipher, const byte *iv, int feedbackSize = 0); }; -template CipherModeFinalTemplate_ExternalCipher::CipherModeFinalTemplate_ExternalCipher(BlockCipher &cipher) +template +void CipherModeFinalTemplate_ExternalCipher::SetCipher(BlockCipher &cipher) { ThrowIfResynchronizable(); m_cipher = &cipher; ResizeBuffers(); } -template CipherModeFinalTemplate_ExternalCipher::CipherModeFinalTemplate_ExternalCipher(BlockCipher &cipher, const byte *iv, int feedbackSize) +template +void CipherModeFinalTemplate_ExternalCipher::SetCipherWithIV(BlockCipher &cipher, const byte *iv, int feedbackSize) { ThrowIfInvalidIV(iv); m_cipher = &cipher; diff --git a/network.h b/network.h index a02e9ed7..b4c79ac2 100644 --- a/network.h +++ b/network.h @@ -137,12 +137,14 @@ public: unsigned int TimedFlush(unsigned long maxTime, unsigned int targetSize = 0); - void SetMaxBufferSize(unsigned int maxBufferSize) {m_maxBufferSize = maxBufferSize;} + void SetMaxBufferSize(unsigned int maxBufferSize) {m_maxBufferSize = maxBufferSize; m_buffer.SetNodeSize(STDMIN(16U*1024U+256, maxBufferSize));} void SetAutoFlushBound(unsigned int bound) {m_autoFlushBound = bound;} unsigned int GetMaxBufferSize() const {return m_maxBufferSize;} unsigned int GetCurrentBufferSize() const {return m_buffer.CurrentSize();} + void ClearBuffer() {m_buffer.Clear();} + //! compute the current speed of this sink in bytes per second float ComputeCurrentSpeed(); //! get the maximum observed speed of this sink in bytes per second diff --git a/oaep.cpp b/oaep.cpp index ddd846de..fd2d97a6 100644 --- a/oaep.cpp +++ b/oaep.cpp @@ -1,8 +1,10 @@ // oaep.cpp - written and placed in the public domain by Wei Dai #include "pch.h" -#include "oaep.h" +#ifndef CRYPTOPP_IMPORTS + +#include "oaep.h" #include NAMESPACE_BEGIN(CryptoPP) @@ -91,3 +93,5 @@ DecodingResult OAEP_Base::Unpad(const byte *oaepBlock, unsigned int oaepBlockLen } NAMESPACE_END + +#endif diff --git a/rsa.cpp b/rsa.cpp index 1e00a6cf..eb68a67f 100644 --- a/rsa.cpp +++ b/rsa.cpp @@ -12,11 +12,7 @@ #if !defined(NDEBUG) && !defined(CRYPTOPP_IS_DLL) #include "pssr.h" -#endif - NAMESPACE_BEGIN(CryptoPP) - -#if !defined(NDEBUG) && !defined(CRYPTOPP_IS_DLL) void RSA_TestInstantiations() { RSASS::Verifier x1(1, 1); @@ -37,10 +33,13 @@ void RSA_TestInstantiations() x4 = x2.GetKey(); } +NAMESPACE_END #endif #ifndef CRYPTOPP_IMPORTS +NAMESPACE_BEGIN(CryptoPP) + OID RSAFunction::GetAlgorithmID() const { return ASN1::rsaEncryption(); @@ -276,6 +275,6 @@ void InvertibleRSAFunction::AssignFrom(const NameValuePairs &source) ; } -#endif - NAMESPACE_END + +#endif diff --git a/stdcpp.h b/stdcpp.h index de1ea9e4..30fa9a90 100644 --- a/stdcpp.h +++ b/stdcpp.h @@ -15,8 +15,6 @@ #include #include #include -#include -#include #include // re-disable this diff --git a/test.cpp b/test.cpp index 063e6dd6..e3716527 100644 --- a/test.cpp +++ b/test.cpp @@ -51,6 +51,8 @@ bool RSAVerifyFile(const char *pubFilename, const char *messageFilename, const c void DigestFile(const char *file); void HmacFile(const char *hexKey, const char *file); +void AES_CTR_Encrypt(const char *hexKey, const char *hexIV, const char *infile, const char *outfile); + string EncryptString(const char *plaintext, const char *passPhrase); string DecryptString(const char *ciphertext, const char *passPhrase); @@ -66,10 +68,10 @@ void InformationRecoverFile(int threshold, const char *outFilename, char *const void GzipFile(const char *in, const char *out, int deflate_level); void GunzipFile(const char *in, const char *out); -void Base64Encode(const char *in, const char *out); -void Base64Decode(const char *in, const char *out); -void HexEncode(const char *in, const char *out); -void HexDecode(const char *in, const char *out); +void Base64Encode(const char *infile, const char *outfile); +void Base64Decode(const char *infile, const char *outfile); +void HexEncode(const char *infile, const char *outfile); +void HexDecode(const char *infile, const char *outfile); void ForwardTcpPort(const char *sourcePort, const char *destinationHost, const char *destinationPort); @@ -291,6 +293,8 @@ int CRYPTOPP_CDECL main(int argc, char *argv[]) } else if (command == "hmac") HmacFile(argv[2], argv[3]); + else if (command == "ae") + AES_CTR_Encrypt(argv[2], argv[3], argv[4], argv[5]); else if (command == "h") { FileSource usage("usage.dat", true, new FileSink(cout)); @@ -298,7 +302,7 @@ int CRYPTOPP_CDECL main(int argc, char *argv[]) } else { - cerr << "Unrecognized command.\n"; + cerr << "Unrecognized command. Run \"cryptest h\" to obtain usage information.\n"; return 1; } return 0; @@ -329,6 +333,14 @@ void FIPS140_GenerateRandomFiles() #endif } +SecByteBlock HexDecodeString(const char *hex) +{ + StringSource ss(hex, true, new HexDecoder); + SecByteBlock result(ss.MaxRetrievable()); + ss.Get(result, result.size()); + return result; +} + RandomPool & GlobalRNG() { static RandomPool randomPool; @@ -442,6 +454,14 @@ void HmacFile(const char *hexKey, const char *file) FileSource(file, true, new HashFilter(*mac, new HexEncoder(new FileSink(cout)))); } +void AES_CTR_Encrypt(const char *hexKey, const char *hexIV, const char *infile, const char *outfile) +{ + SecByteBlock key = HexDecodeString(hexKey); + SecByteBlock iv = HexDecodeString(hexIV); + CTR_Mode::Encryption aes(key, key.size(), iv); + FileSource(infile, true, new StreamTransformationFilter(aes, new FileSink(outfile))); +} + string EncryptString(const char *instr, const char *passPhrase) { string outstr; diff --git a/usage.dat b/usage.dat index eb92a438..0761529a 100644 --- a/usage.dat +++ b/usage.dat @@ -41,6 +41,9 @@ Test Driver for Crypto++(TM) Library, a C++ Class Library of Cryptographic Schem - To gunzip a file cryptest u input output +- To encrypt a file with AES in CTR mode + cryptest ae input output + - To base64 encode a file cryptest e64 input output diff --git a/validat1.cpp b/validat1.cpp index ed3f26a6..4edaada9 100644 --- a/validat1.cpp +++ b/validat1.cpp @@ -4,6 +4,7 @@ #include "files.h" #include "hex.h" +#include "base32.h" #include "base64.h" #include "modes.h" #include "cbcmac.h" @@ -1279,6 +1280,13 @@ bool ValidateBaseCode() "A0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7" "C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEF" "F0F1F2F3F4F5F6F7F8F9FAFBFCFDFE"; + const char *base32Encoded = +"AAASEA2EAWDAQCAJBIFS2DIQB6IBCESVCSKTNF22DEPBYHA7D2RUAIJCENUCKJTHFAWUWK3NFWZC8NBT" +"GI3VIPJYG66DUQT5HS8V6R4AIFBEGTCFI3DWSUKKJPGE4VURKBIXEW4WKXMFQYC3MJPX2ZK8M7SGC2VD" +"NTUYN35IPFXGY5DPP3ZZA6MUQP4HK7VZRB6ZW856RX9H9AEBSKB2JBNGS8EIVCWMTUG27D6SUGJJHFEX" +"U4M3TGN4VQQJ5HW9WCS4FI7EWYVKRKFJXKX43MPQX82MDNXVYU45PP72ZG7MZRF7Z496BSQC2RCNMTYH" +"3DE6XU8N3ZHN9WGT4MJ7JXQY49NPVYY55VQ77Z9A6HTQH3HF65V8T4RK7RYQ55ZR8D29F69W8Z5RR8H3" +"9M7939R8"; const char *base64AndHexEncoded = "41414543417751464267634943516F4C4441304F4478415245684D554652595847426B6147787764" "486838674953496A4A43556D4A7967704B6973734C5334764D4445794D7A51310A4E6A63344F546F" @@ -1290,7 +1298,7 @@ bool ValidateBaseCode() "39445230745055316462580A324E6E6132397A6433742F6734654C6A354F586D352B6A7036757673" "3765377638504879382F5431397666342B6672372F50332B0A"; - cout << "\nBase64 and hex coding validation suite running...\n\n"; + cout << "\nBase64, base32 and hex coding validation suite running...\n\n"; fail = !TestFilter(HexEncoder().Ref(), data, 255, (const byte *)hexEncoded, strlen(hexEncoded)); cout << (fail ? "FAILED " : "passed "); @@ -1302,6 +1310,16 @@ bool ValidateBaseCode() cout << "Hex Decoding\n"; pass = pass && !fail; + fail = !TestFilter(Base32Encoder().Ref(), data, 255, (const byte *)base32Encoded, strlen(base32Encoded)); + cout << (fail ? "FAILED " : "passed "); + cout << "Base32 Encoding\n"; + pass = pass && !fail; + + fail = !TestFilter(Base32Decoder().Ref(), (const byte *)base32Encoded, strlen(base32Encoded), data, 255); + cout << (fail ? "FAILED " : "passed "); + cout << "Base32 Decoding\n"; + pass = pass && !fail; + fail = !TestFilter(Base64Encoder(new HexEncoder).Ref(), data, 255, (const byte *)base64AndHexEncoded, strlen(base64AndHexEncoded)); cout << (fail ? "FAILED " : "passed "); cout << "Base64 Encoding\n";