, public ChannelSwitchTypedefs
{
public:
ChannelSwitch() : m_it(*this), m_blocked(false) {}
diff --git a/config.h b/config.h
index d82d9f5e..3b864cac 100644
--- a/config.h
+++ b/config.h
@@ -100,11 +100,7 @@ typedef unsigned char byte; // moved outside namespace for Borland C++Builde
NAMESPACE_BEGIN(CryptoPP)
typedef unsigned short word16;
-#if defined(__alpha) && !defined(_MSC_VER)
typedef unsigned int word32;
-#else
- typedef unsigned long word32;
-#endif
#if defined(__GNUC__) || defined(__MWERKS__)
# define WORD64_AVAILABLE
@@ -184,14 +180,46 @@ NAMESPACE_END
#endif
#ifdef _MSC_VER
+ // 4231: nonstandard extension used : 'extern' before template explicit instantiation
// 4250: dominance
+ // 4251: member needs to have dll-interface
+ // 4275: base needs to have dll-interface
// 4660: explicitly instantiating a class that's already implicitly instantiated
// 4661: no suitable definition provided for explicit template instantiation request
// 4786: identifer was truncated in debug information
// 4355: 'this' : used in base member initializer list
-# pragma warning(disable: 4250 4660 4661 4786 4355)
+# pragma warning(disable: 4231 4250 4251 4275 4660 4661 4786 4355)
#endif
+#ifdef _MSC_VER
+
+#ifdef CRYPTOPP_EXPORTS
+#define CRYPTOPP_IS_DLL
+#define CRYPTOPP_DLL __declspec(dllexport)
+#elif defined(CRYPTOPP_IMPORTS)
+#define CRYPTOPP_IS_DLL
+#define CRYPTOPP_DLL __declspec(dllimport)
+#else
+#define CRYPTOPP_DLL
+#endif
+
+#define CRYPTOPP_API __stdcall
+
+#else // _MSC_VER
+
+#define CRYPTOPP_DLL
+#define CRYPTOPP_API
+
+#endif // _MSC_VER
+
+#ifdef CRYPTOPP_MANUALLY_INSTANTIATE_TEMPLATES
+#define CRYPTOPP_MANUAL_EXTERN
+#else
+#define CRYPTOPP_MANUAL_EXTERN extern
+#endif
+
+#define CRYPTOPP_DLL_TEMPLATE_CLASS CRYPTOPP_MANUAL_EXTERN template class CRYPTOPP_DLL
+
// ***************** determine availability of OS features ********************
#ifndef NO_OS_DEPENDENCE
diff --git a/cryptdll.dsp b/cryptdll.dsp
new file mode 100644
index 00000000..d7d68f12
--- /dev/null
+++ b/cryptdll.dsp
@@ -0,0 +1,545 @@
+# Microsoft Developer Studio Project File - Name="cryptdll" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
+
+CFG=cryptdll - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "cryptdll.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "cryptdll.mak" CFG="cryptdll - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "cryptdll - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "cryptdll - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName "Perforce Project"
+# PROP Scc_LocalPath "."
+CPP=cl.exe
+MTL=midl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "cryptdll - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "cryptdll___Win32_Release"
+# PROP BASE Intermediate_Dir "cryptdll___Win32_Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "DLL_Release"
+# PROP Intermediate_Dir "DLL_Release"
+# 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 BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# 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:"0x69000000" /dll /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
+TargetPath=.\DLL_Release\cryptopp.dll
+InputPath=.\DLL_Release\cryptopp.dll
+SOURCE="$(InputPath)"
+
+"$(OutDir)\cryptopp.mac.done" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ CTRelease\cryptest mac_dll $(TargetPath)
+ echo mac done > $(OutDir)\cryptopp.mac.done
+
+# End Custom Build
+
+!ELSEIF "$(CFG)" == "cryptdll - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "cryptdll___Win32_Debug"
+# PROP BASE Intermediate_Dir "cryptdll___Win32_Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "DLL_Debug"
+# PROP Intermediate_Dir "DLL_Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "CRYPTDLL_EXPORTS" /YX /FD /GZ /c
+# ADD CPP /nologo /G5 /Gz /MDd /W3 /Gm /GX /Zi /Od /D "_DEBUG" /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 /GZ /Zm200 /c
+# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# 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 /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 advapi32.lib /nologo /base:"0x69000000" /dll /incremental:no /debug /machine:I386 /out:"DLL_Debug/cryptopp.dll" /opt:ref
+# SUBTRACT LINK32 /pdb:none
+# Begin Custom Build
+OutDir=.\DLL_Debug
+TargetPath=.\DLL_Debug\cryptopp.dll
+InputPath=.\DLL_Debug\cryptopp.dll
+SOURCE="$(InputPath)"
+
+"$(OutDir)\cryptopp.mac.done" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ CTDebug\cryptest mac_dll $(TargetPath)
+ echo mac done > $(OutDir)\cryptopp.mac.done
+
+# End Custom Build
+
+!ENDIF
+
+# Begin Target
+
+# Name "cryptdll - Win32 Release"
+# Name "cryptdll - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\algebra.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\algparam.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\asn.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\basecode.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\cbcmac.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\channels.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\cryptlib.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\des.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\dessp.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\dh.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\dll.cpp
+# SUBTRACT CPP /YX /Yc /Yu
+# End Source File
+# Begin Source File
+
+SOURCE=.\dsa.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\ec2n.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\eccrypto.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\ecp.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\eprecomp.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\files.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\filters.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\fips140.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\fipstest.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\gf2n.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\gfpcrypt.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\hex.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\hmac.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\integer.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\iterhash.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\misc.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\modes.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\modexppc.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\mqueue.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\nbtheory.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\oaep.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\osrng.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\pch.cpp
+# ADD CPP /Yc"pch.h"
+# End Source File
+# Begin Source File
+
+SOURCE=.\pkcspad.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\pubkey.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\queue.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\randpool.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\rdtables.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\rijndael.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\rng.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\rsa.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\sha.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\simple.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\skipjack.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\strciphr.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\trdlocal.cpp
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter ".h"
+# Begin Source File
+
+SOURCE=.\aes.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\algebra.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\algparam.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\argnames.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\asn.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\basecode.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\cbcmac.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\channels.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\config.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\cryptlib.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\des.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\dh.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\dll.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\dsa.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\ec2n.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\eccrypto.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\ecp.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\eprecomp.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\files.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\filters.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\fips140.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\fltrimpl.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\gf2n.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\gfpcrypt.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\hex.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\hmac.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\integer.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\iterhash.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\mdc.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\misc.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\modarith.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\modes.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\modexppc.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\mqueue.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\mqv.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\nbtheory.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\oaep.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\oids.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\osrng.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\pch.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\pkcspad.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\pubkey.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\queue.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\randpool.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\rijndael.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\rng.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\rsa.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\secblock.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\seckey.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\sha.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\simple.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\skipjack.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\smartptr.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\stdcpp.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\strciphr.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\trdlocal.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\words.h
+# End Source File
+# End Group
+# Begin Source File
+
+SOURCE=.\cryptopp.rc
+# End Source File
+# End Target
+# End Project
diff --git a/cryptest.dsp b/cryptest.dsp
index 33bbe2a5..a6f3ae1e 100644
--- a/cryptest.dsp
+++ b/cryptest.dsp
@@ -25,8 +25,8 @@ CFG=cryptest - Win32 Debug
# Begin Project
# PROP AllowPerConfigDependencies 0
-# PROP Scc_ProjName ""
-# PROP Scc_LocalPath ""
+# PROP Scc_ProjName "Perforce Project"
+# PROP Scc_LocalPath "."
CPP=cl.exe
RSC=rc.exe
@@ -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 /MT /W3 /GX /Zi /O2 /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /D "WIN32" /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 BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
@@ -53,11 +53,11 @@ 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 Ws2_32.lib /nologo /subsystem:console /debug /machine:I386 /OPT:NOWIN98
-# 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
-# SUBTRACT LINK32 /pdb:none
+# ADD LINK32 Ws2_32.lib /nologo /subsystem:console /debug /machine:I386 /out:"DLL_Release/cryptest.exe" /libpath:"DLL_Release" /OPT:NOWIN98 /OPT:REF /OPT:ICF
+# SUBTRACT LINK32 /pdb:none /incremental:yes
# Begin Special Build Tool
SOURCE="$(InputPath)"
-PostBuild_Cmds=echo This configuration is used to build a static binary for FIPS 140 evaluation by a testing laboratory. echo Crypto++ users should not build this configuration directly.
+PreLink_Cmds=echo This configuration requires cryptopp.dll. echo You can build it yourself using the cryptdll project, or echo obtain a pre-built, FIPS 140-2 validated DLL. If you build it yourself echo the resulting DLL will not be considered FIPS validated echo unless it undergoes FIPS validation.
# End Special Build Tool
!ELSEIF "$(CFG)" == "cryptest - Win32 FIPS 140 Debug"
@@ -75,7 +75,7 @@ PostBuild_Cmds=echo This configuration is used to build a static binary for FIPS
# 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 /MTd /W3 /GX /ZI /Od /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "WIN32" /YX /FD /Zm300 /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 BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
@@ -83,10 +83,10 @@ 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 Ws2_32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /OPT:NOWIN98
-# 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 /pdbtype:sept /OPT:NOWIN98
+# ADD LINK32 Ws2_32.lib /nologo /subsystem:console /debug /machine:I386 /out:"DLL_Debug/cryptest.exe" /pdbtype:sept /libpath:"DLL_Debug" /OPT:NOWIN98
# Begin Special Build Tool
SOURCE="$(InputPath)"
-PostBuild_Cmds=echo This configuration is used to build a static binary for FIPS 140 evaluation by a testing laboratory. echo Crypto++ users should not build this configuration directly.
+PreLink_Cmds=echo This configuration requires cryptopp.dll. echo You can build it yourself using the cryptdll project, or echo obtain a pre-built, FIPS 140-2 validated DLL. If you build it yourself echo the resulting DLL will not be considered FIPS validated echo unless it undergoes FIPS validation.
# End Special Build Tool
!ELSEIF "$(CFG)" == "cryptest - Win32 Release"
@@ -103,7 +103,7 @@ PostBuild_Cmds=echo This configuration is used to build a static binary for FIPS
# 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 "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /Zm200 /c
+# ADD CPP /nologo /MT /W3 /GX /Zi /O2 /D "NDEBUG" /D "CRYPTOPP_NO_DLL" /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
@@ -128,7 +128,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 /c
-# ADD CPP /nologo /MTd /W3 /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /Zm300 /c
+# ADD CPP /nologo /MTd /W3 /GX /ZI /Od /D "_DEBUG" /D "CRYPTOPP_NO_DLL" /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
@@ -392,6 +392,10 @@ SOURCE=.\datatest.cpp
# End Source File
# Begin Source File
+SOURCE=.\dlltest.cpp
+# End Source File
+# Begin Source File
+
SOURCE=.\factory.h
# End Source File
# Begin Source File
diff --git a/cryptest.dsw b/cryptest.dsw
index bce8473e..2260dbf9 100644
--- a/cryptest.dsw
+++ b/cryptest.dsw
@@ -3,10 +3,33 @@ Microsoft Developer Studio Workspace File, Format Version 6.00
###############################################################################
+Project: "cryptdll"=.\cryptdll.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+ begin source code control
+ Perforce Project
+ .
+ end source code control
+}}}
+
+Package=<4>
+{{{
+ Begin Project Dependency
+ Project_Dep_Name cryptest
+ End Project Dependency
+}}}
+
+###############################################################################
+
Project: "cryptest"=.\cryptest.dsp - Package Owner=<4>
Package=<5>
{{{
+ begin source code control
+ Perforce Project
+ .
+ end source code control
}}}
Package=<4>
@@ -22,6 +45,10 @@ Project: "cryptlib"=.\cryptlib.dsp - Package Owner=<4>
Package=<5>
{{{
+ begin source code control
+ Perforce Project
+ .
+ end source code control
}}}
Package=<4>
@@ -30,6 +57,25 @@ Package=<4>
###############################################################################
+Project: "dlltest"=.\dlltest.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+ begin source code control
+ Perforce Project
+ .
+ end source code control
+}}}
+
+Package=<4>
+{{{
+ Begin Project Dependency
+ Project_Dep_Name cryptdll
+ End Project Dependency
+}}}
+
+###############################################################################
+
Global:
Package=<5>
diff --git a/cryptlib.cpp b/cryptlib.cpp
index 5254c85d..1412ab9b 100644
--- a/cryptlib.cpp
+++ b/cryptlib.cpp
@@ -1,6 +1,9 @@
// cryptlib.cpp - written and placed in the public domain by Wei Dai
#include "pch.h"
+
+#ifndef CRYPTOPP_IMPORTS
+
#include "cryptlib.h"
#include "misc.h"
#include "filters.h"
@@ -37,7 +40,7 @@ Algorithm::Algorithm(bool checkSelfTestStatus)
throw SelfTestFailure("Cryptographic algorithms are disabled before the power-up self tests are performed.");
if (GetPowerUpSelfTestStatus() == POWER_UP_SELF_TEST_FAILED)
- throw SelfTestFailure("Cryptographic algorithms are disabled after power-up a self test failed.");
+ throw SelfTestFailure("Cryptographic algorithms are disabled after a power-up self test failed.");
}
}
@@ -691,3 +694,5 @@ void AuthenticatedKeyAgreementDomain::GenerateEphemeralKeyPair(RandomNumberGener
}
NAMESPACE_END
+
+#endif
diff --git a/cryptlib.dsp b/cryptlib.dsp
index 1c32dd01..e91ea269 100644
--- a/cryptlib.dsp
+++ b/cryptlib.dsp
@@ -25,8 +25,8 @@ CFG=cryptlib - Win32 Debug
# Begin Project
# PROP AllowPerConfigDependencies 0
-# PROP Scc_ProjName ""
-# PROP Scc_LocalPath ""
+# PROP Scc_ProjName "Perforce Project"
+# PROP Scc_LocalPath "."
CPP=cl.exe
RSC=rc.exe
@@ -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 /MT /W3 /GX /Zi /O2 /D "NDEBUG" /D "_WINDOWS" /D "USE_PRECOMPILED_HEADERS" /D "WIN32" /D CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2=1 /Yu"pch.h" /Fd"FIPS_140_Release/cryptopp" /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 BASE RSC /l 0x409
# ADD RSC /l 0x409
BSC32=bscmake.exe
@@ -51,7 +51,7 @@ BSC32=bscmake.exe
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
-# ADD LIB32 /nologo /out:"FIPS_140_Release\cryptopp.lib"
+# ADD LIB32 /nologo
!ELSEIF "$(CFG)" == "cryptlib - Win32 FIPS 140 Debug"
@@ -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 /MTd /W3 /GX /ZI /Od /D "_DEBUG" /D "_WINDOWS" /D "USE_PRECOMPILED_HEADERS" /D "WIN32" /D CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2=1 /Yu"pch.h" /Fd"FIPS_140_Debug/cryptopp" /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 BASE RSC /l 0x409
# ADD RSC /l 0x409
BSC32=bscmake.exe
@@ -74,7 +74,7 @@ BSC32=bscmake.exe
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
-# ADD LIB32 /nologo /out:"FIPS_140_Debug\cryptopp.lib"
+# ADD LIB32 /nologo
!ELSEIF "$(CFG)" == "cryptlib - Win32 Release"
@@ -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 "WIN32" /D "_WINDOWS" /D "USE_PRECOMPILED_HEADERS" /Yu"pch.h" /FD /c
+# ADD CPP /nologo /MT /W3 /GX /Zi /O2 /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "USE_PRECOMPILED_HEADERS" /D "CRYPTOPP_NO_DLL" /Yu"pch.h" /FD /c
# ADD BASE RSC /l 0x409
# ADD RSC /l 0x409
BSC32=bscmake.exe
@@ -112,7 +112,7 @@ LIB32=link.exe -lib
# PROP Intermediate_Dir "Debug"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /Z7 /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
-# ADD 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 /MTd /W3 /GX /ZI /Od /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "USE_PRECOMPILED_HEADERS" /D "CRYPTOPP_NO_DLL" /Yu"pch.h" /FD /c
# ADD BASE RSC /l 0x409
# ADD RSC /l 0x409
BSC32=bscmake.exe
@@ -242,6 +242,10 @@ SOURCE=.\casts.cpp
# End Source File
# Begin Source File
+SOURCE=.\cbcmac.cpp
+# End Source File
+# Begin Source File
+
SOURCE=.\channels.cpp
# End Source File
# Begin Source File
@@ -282,6 +286,11 @@ SOURCE=.\diamondt.cpp
# End Source File
# Begin Source File
+SOURCE=.\dll.cpp
+# SUBTRACT CPP /YX /Yc /Yu
+# End Source File
+# Begin Source File
+
SOURCE=.\dsa.cpp
# End Source File
# Begin Source File
@@ -358,6 +367,10 @@ SOURCE=.\hex.cpp
# End Source File
# Begin Source File
+SOURCE=.\hmac.cpp
+# End Source File
+# Begin Source File
+
SOURCE=.\hrtimer.cpp
# End Source File
# Begin Source File
diff --git a/cryptlib.h b/cryptlib.h
index 08201b3f..a1a2f1c4 100644
--- a/cryptlib.h
+++ b/cryptlib.h
@@ -4,7 +4,7 @@
classes that provide a uniform interface to this library.
*/
-/*! \mainpage Crypto++TM Library 5.1 Reference Manual
+/*! \mainpage Crypto++TM Library 5.2 Reference Manual
- Abstract Base Classes
-
cryptlib.h
@@ -46,6 +46,26 @@
fips140.h
+In the FIPS 140-2 validated DLL version of Crypto++, only the following implementation class are available.
+
+- Block Ciphers
-
+ AES, DES, DES_EDE2, DES_EDE3, SKIPJACK
+
- Cipher Modes (replace template parameter BC with one of the block ciphers above)
-
+ ECB_Mode , CTR_Mode , CBC_Mode , CFB_Mode , OFB_Mode
+
- Hash Functions
-
+ SHA, SHA256, SHA384, SHA512
+
- Public Key Signature Schemes
-
+ RSASSA , DSA, ECDSA , ECDSA
+
- Message Authentication Codes
-
+ HMAC , HMAC , HMAC , HMAC , CBC_MAC , CBC_MAC , CBC_MAC
+
- Random Number Generators
-
+ AutoSeededX917RNG
+
- Key Agreement
-
+ #DH
+
- Public Key Cryptosystems
-
+ RSAES >
+
+
This reference manual is a work in progress. Some classes are still lacking detailed descriptions.
Click here to download a zip archive containing this manual.
Thanks to Ryan Phillips for providing the Doxygen configuration file
@@ -56,11 +76,7 @@ and getting me started with this manual.
#define CRYPTOPP_CRYPTLIB_H
#include "config.h"
-#include
-#include
-#include
-#include
-#include
+#include "stdcpp.h"
NAMESPACE_BEGIN(CryptoPP)
@@ -85,7 +101,7 @@ typedef EnumToType LittleEndian;
typedef EnumToType BigEndian;
//! base class for all exceptions thrown by Crypto++
-class Exception : public std::exception
+class CRYPTOPP_DLL Exception : public std::exception
{
public:
//! error types
@@ -120,42 +136,42 @@ private:
};
//! exception thrown when an invalid argument is detected
-class InvalidArgument : public Exception
+class CRYPTOPP_DLL InvalidArgument : public Exception
{
public:
explicit InvalidArgument(const std::string &s) : Exception(INVALID_ARGUMENT, s) {}
};
//! exception thrown by decryption filters when trying to decrypt an invalid ciphertext
-class InvalidDataFormat : public Exception
+class CRYPTOPP_DLL InvalidDataFormat : public Exception
{
public:
explicit InvalidDataFormat(const std::string &s) : Exception(INVALID_DATA_FORMAT, s) {}
};
//! exception thrown by decryption filters when trying to decrypt an invalid ciphertext
-class InvalidCiphertext : public InvalidDataFormat
+class CRYPTOPP_DLL InvalidCiphertext : public InvalidDataFormat
{
public:
explicit InvalidCiphertext(const std::string &s) : InvalidDataFormat(s) {}
};
//! exception thrown by a class if a non-implemented method is called
-class NotImplemented : public Exception
+class CRYPTOPP_DLL NotImplemented : public Exception
{
public:
explicit NotImplemented(const std::string &s) : Exception(NOT_IMPLEMENTED, s) {}
};
//! exception thrown by a class when Flush(true) is called but it can't completely flush its buffers
-class CannotFlush : public Exception
+class CRYPTOPP_DLL CannotFlush : public Exception
{
public:
explicit CannotFlush(const std::string &s) : Exception(CANNOT_FLUSH, s) {}
};
//! error reported by the operating system
-class OS_Error : public Exception
+class CRYPTOPP_DLL OS_Error : public Exception
{
public:
OS_Error(ErrorType errorType, const std::string s, const std::string& operation, int errorCode)
@@ -173,7 +189,7 @@ protected:
};
//! used to return decoding results
-struct DecodingResult
+struct CRYPTOPP_DLL DecodingResult
{
explicit DecodingResult() : isValidCoding(false), messageLength(0) {}
explicit DecodingResult(unsigned int len) : isValidCoding(true), messageLength(len) {}
@@ -249,21 +265,21 @@ public:
}
//! get a list of value names that can be retrieved
- std::string GetValueNames() const
+ CRYPTOPP_DLL std::string GetValueNames() const
{std::string result; GetValue("ValueNames", result); return result;}
//! get a named value with type int
/*! used to ensure we don't accidentally try to get an unsigned int
or some other type when we mean int (which is the most common case) */
- bool GetIntValue(const char *name, int &value) const
+ CRYPTOPP_DLL bool GetIntValue(const char *name, int &value) const
{return GetValue(name, value);}
//! get a named value with type int, with default
- int GetIntValueWithDefault(const char *name, int defaultValue) const
+ CRYPTOPP_DLL int GetIntValueWithDefault(const char *name, int defaultValue) const
{return GetValueWithDefault(name, defaultValue);}
//! used by derived classes to check for type mismatch
- static void ThrowIfTypeMismatch(const char *name, const std::type_info &stored, const std::type_info &retrieving)
+ CRYPTOPP_DLL static void ThrowIfTypeMismatch(const char *name, const std::type_info &stored, const std::type_info &retrieving)
{if (stored != retrieving) throw ValueTypeMismatch(name, stored, retrieving);}
template
@@ -273,14 +289,14 @@ public:
throw InvalidArgument(std::string(className) + ": missing required parameter '" + name + "'");
}
- void GetRequiredIntParameter(const char *className, const char *name, int &value) const
+ CRYPTOPP_DLL void GetRequiredIntParameter(const char *className, const char *name, int &value) const
{
if (!GetIntValue(name, value))
throw InvalidArgument(std::string(className) + ": missing required parameter '" + name + "'");
}
//! to be implemented by derived classes, users should use one of the above functions instead
- virtual bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const =0;
+ CRYPTOPP_DLL virtual bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const =0;
};
//! namespace containing value name definitions
@@ -294,19 +310,19 @@ DOCUMENTED_NAMESPACE_BEGIN(Name)
DOCUMENTED_NAMESPACE_END
//! .
-class NullNameValuePairs : public NameValuePairs
+class CRYPTOPP_DLL NullNameValuePairs : public NameValuePairs
{
public:
bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const {return false;}
};
//! .
-extern const NullNameValuePairs g_nullNameValuePairs;
+extern CRYPTOPP_DLL const NullNameValuePairs g_nullNameValuePairs;
// ********************************************************
//! interface for cloning objects, this is not implemented by most classes yet
-class CRYPTOPP_NO_VTABLE Clonable
+class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Clonable
{
public:
virtual ~Clonable() {}
@@ -316,7 +332,7 @@ public:
//! interface for all crypto algorithms
-class CRYPTOPP_NO_VTABLE Algorithm : public Clonable
+class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Algorithm : public Clonable
{
public:
/*! When FIPS 140-2 compliance is enabled and checkSelfTestStatus == true,
@@ -328,7 +344,7 @@ public:
//! keying interface for crypto algorithms that take byte strings as keys
-class CRYPTOPP_NO_VTABLE SimpleKeyingInterface
+class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE SimpleKeyingInterface
{
public:
//! returns smallest valid key length in bytes */
@@ -399,7 +415,7 @@ protected:
These classes should not be used directly, but only in combination with
a mode class (see CipherModeDocumentation in modes.h).
*/
-class CRYPTOPP_NO_VTABLE BlockTransformation : public Algorithm
+class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE BlockTransformation : public Algorithm
{
public:
//! encrypt or decrypt inBlock, xor with xorBlock, and write to outBlock
@@ -435,7 +451,7 @@ public:
//! interface for the data processing part of stream ciphers
-class CRYPTOPP_NO_VTABLE StreamTransformation : public Algorithm
+class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE StreamTransformation : public Algorithm
{
public:
//! return a reference to this object,
@@ -498,7 +514,7 @@ public:
be hashed in pieces by calling Update() on each piece followed by
calling Final().
*/
-class CRYPTOPP_NO_VTABLE HashTransformation : public Algorithm
+class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE HashTransformation : public Algorithm
{
public:
//! process more input
@@ -519,6 +535,9 @@ public:
//! size of the hash returned by Final()
virtual unsigned int DigestSize() const =0;
+ //! block size of underlying compression function, or 0 if not block based
+ virtual unsigned int BlockSize() const {return 0;}
+
//! input to Update() should have length a multiple of this for optimal speed
virtual unsigned int OptimalBlockSize() const {return 1;}
@@ -559,7 +578,7 @@ protected:
//! .
template
-class CRYPTOPP_NO_VTABLE SimpleKeyedTransformation : public T, public SimpleKeyingInterface
+class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE SimpleKeyedTransformation : public T, public SimpleKeyingInterface
{
public:
void ThrowIfInvalidKeyLength(unsigned int length)
@@ -579,6 +598,10 @@ class MessageAuthenticationCode : public HashTransformation, public SimpleKeying
typedef SimpleKeyedTransformation BlockCipher;
typedef SimpleKeyedTransformation SymmetricCipher;
typedef SimpleKeyedTransformation MessageAuthenticationCode;
+
+CRYPTOPP_DLL_TEMPLATE_CLASS SimpleKeyedTransformation;
+CRYPTOPP_DLL_TEMPLATE_CLASS SimpleKeyedTransformation;
+CRYPTOPP_DLL_TEMPLATE_CLASS SimpleKeyedTransformation;
#endif
#ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY
@@ -588,7 +611,7 @@ typedef SymmetricCipher StreamCipher;
//! interface for random number generators
/*! All return values are uniformly distributed over the range specified.
*/
-class CRYPTOPP_NO_VTABLE RandomNumberGenerator : public Algorithm
+class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE RandomNumberGenerator : public Algorithm
{
public:
//! generate new random byte and return it
@@ -626,7 +649,7 @@ public:
};
//! returns a reference that can be passed to functions that ask for a RNG but doesn't actually use it
-RandomNumberGenerator & NullRNG();
+CRYPTOPP_DLL RandomNumberGenerator & NullRNG();
class WaitObjectContainer;
@@ -670,7 +693,7 @@ public:
\nosubgrouping
*/
-class CRYPTOPP_NO_VTABLE BufferedTransformation : public Algorithm, public Waitable
+class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE BufferedTransformation : public Algorithm, public Waitable
{
public:
// placed up here for CW8
@@ -929,11 +952,11 @@ BufferedTransformation & TheBitBucket();
//! interface for crypto material, such as public and private keys, and crypto parameters
-class CRYPTOPP_NO_VTABLE CryptoMaterial : public NameValuePairs
+class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CryptoMaterial : public NameValuePairs
{
public:
//! exception thrown when invalid crypto material is detected
- class InvalidMaterial : public InvalidDataFormat
+ class CRYPTOPP_DLL InvalidMaterial : public InvalidDataFormat
{
public:
explicit InvalidMaterial(const std::string &s) : InvalidDataFormat(s) {}
@@ -990,7 +1013,7 @@ public:
//! interface for generatable crypto material, such as private keys and crypto parameters
-class CRYPTOPP_NO_VTABLE GeneratableCryptoMaterial : virtual public CryptoMaterial
+class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE GeneratableCryptoMaterial : virtual public CryptoMaterial
{
public:
//! generate a random key or crypto parameters
@@ -1005,25 +1028,25 @@ public:
//! interface for public keys
-class CRYPTOPP_NO_VTABLE PublicKey : virtual public CryptoMaterial
+class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE PublicKey : virtual public CryptoMaterial
{
};
//! interface for private keys
-class CRYPTOPP_NO_VTABLE PrivateKey : public GeneratableCryptoMaterial
+class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE PrivateKey : public GeneratableCryptoMaterial
{
};
//! interface for crypto prameters
-class CRYPTOPP_NO_VTABLE CryptoParameters : public GeneratableCryptoMaterial
+class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CryptoParameters : public GeneratableCryptoMaterial
{
};
//! interface for asymmetric algorithms
-class CRYPTOPP_NO_VTABLE AsymmetricAlgorithm : public Algorithm
+class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE AsymmetricAlgorithm : public Algorithm
{
public:
//! returns a reference to the crypto material used by this object
@@ -1041,7 +1064,7 @@ public:
//! interface for asymmetric algorithms using public keys
-class CRYPTOPP_NO_VTABLE PublicKeyAlgorithm : public AsymmetricAlgorithm
+class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE PublicKeyAlgorithm : public AsymmetricAlgorithm
{
public:
// VC60 workaround: no co-variant return type
@@ -1054,7 +1077,7 @@ public:
//! interface for asymmetric algorithms using private keys
-class CRYPTOPP_NO_VTABLE PrivateKeyAlgorithm : public AsymmetricAlgorithm
+class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE PrivateKeyAlgorithm : public AsymmetricAlgorithm
{
public:
CryptoMaterial & AccessMaterial() {return AccessPrivateKey();}
@@ -1066,7 +1089,7 @@ public:
//! interface for key agreement algorithms
-class CRYPTOPP_NO_VTABLE KeyAgreementAlgorithm : public AsymmetricAlgorithm
+class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE KeyAgreementAlgorithm : public AsymmetricAlgorithm
{
public:
CryptoMaterial & AccessMaterial() {return AccessCryptoParameters();}
@@ -1081,7 +1104,7 @@ public:
/*! This class provides an interface common to encryptors and decryptors
for querying their plaintext and ciphertext lengths.
*/
-class CRYPTOPP_NO_VTABLE PK_CryptoSystem
+class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE PK_CryptoSystem
{
public:
virtual ~PK_CryptoSystem() {}
@@ -1102,11 +1125,11 @@ public:
//! interface for public-key encryptors
-class CRYPTOPP_NO_VTABLE PK_Encryptor : public PK_CryptoSystem, public PublicKeyAlgorithm
+class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE PK_Encryptor : virtual public PK_CryptoSystem, public PublicKeyAlgorithm
{
public:
//! .
- class InvalidPlaintextLength : public Exception
+ class CRYPTOPP_DLL InvalidPlaintextLength : public Exception
{
public:
InvalidPlaintextLength() : Exception(OTHER_ERROR, "PK_Encryptor: invalid plaintext length") {}
@@ -1126,7 +1149,7 @@ public:
//! interface for public-key decryptors
-class CRYPTOPP_NO_VTABLE PK_Decryptor : public PK_CryptoSystem, public PrivateKeyAlgorithm
+class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE PK_Decryptor : virtual public PK_CryptoSystem, public PrivateKeyAlgorithm
{
public:
//! decrypt a byte string, and return the length of plaintext
@@ -1147,7 +1170,7 @@ public:
as RSA) whose ciphertext length and maximum plaintext length
depend only on the key.
*/
-class CRYPTOPP_NO_VTABLE PK_FixedLengthCryptoSystem
+class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE PK_FixedLengthCryptoSystem
{
public:
//!
@@ -1174,13 +1197,13 @@ class CRYPTOPP_NO_VTABLE PK_FixedLengthCryptoSystemImpl : public BASE, public PK
//! interface for encryptors with fixed length ciphertext
-class CRYPTOPP_NO_VTABLE PK_FixedLengthEncryptor : public PK_FixedLengthCryptoSystemImpl
+class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE PK_FixedLengthEncryptor : public PK_FixedLengthCryptoSystemImpl
{
};
//! interface for decryptors with fixed length ciphertext
-class CRYPTOPP_NO_VTABLE PK_FixedLengthDecryptor : public PK_FixedLengthCryptoSystemImpl
+class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE PK_FixedLengthDecryptor : public PK_FixedLengthCryptoSystemImpl
{
public:
//! decrypt a byte string, and return the length of plaintext
@@ -1198,18 +1221,18 @@ public:
/*! This class provides an interface common to signers and verifiers
for querying scheme properties.
*/
-class CRYPTOPP_NO_VTABLE PK_SignatureScheme
+class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE PK_SignatureScheme
{
public:
//! invalid key exception, may be thrown by any function in this class if the private or public key has a length that can't be used
- class InvalidKeyLength : public Exception
+ class CRYPTOPP_DLL InvalidKeyLength : public Exception
{
public:
InvalidKeyLength(const std::string &message) : Exception(OTHER_ERROR, message) {}
};
//! key too short exception, may be thrown by any function in this class if the private or public key is too short to sign or verify anything
- class KeyTooShort : public InvalidKeyLength
+ class CRYPTOPP_DLL KeyTooShort : public InvalidKeyLength
{
public:
KeyTooShort() : InvalidKeyLength("PK_Signer: key too short for this signature scheme") {}
@@ -1247,7 +1270,7 @@ public:
/*! Only Update() should be called
on this class. No other functions inherited from HashTransformation should be called.
*/
-class CRYPTOPP_NO_VTABLE PK_MessageAccumulator : public HashTransformation
+class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE PK_MessageAccumulator : public HashTransformation
{
public:
//! should not be called on PK_MessageAccumulator
@@ -1260,7 +1283,7 @@ public:
//! interface for public-key signers
-class CRYPTOPP_NO_VTABLE PK_Signer : public PK_SignatureScheme, public PrivateKeyAlgorithm
+class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE PK_Signer : public PK_SignatureScheme, public PrivateKeyAlgorithm
{
public:
//! create a new HashTransformation to accumulate the message to be signed
@@ -1301,7 +1324,7 @@ public:
recovery and the signature contains a non-empty recoverable message part. The
Recovery* functions should be used in that case.
*/
-class CRYPTOPP_NO_VTABLE PK_Verifier : public PK_SignatureScheme, public PublicKeyAlgorithm
+class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE PK_Verifier : public PK_SignatureScheme, public PublicKeyAlgorithm
{
public:
//! create a new HashTransformation to accumulate the message to be verified
@@ -1344,7 +1367,7 @@ public:
by two parties in a key agreement protocol, along with the algorithms
for generating key pairs and deriving agreed values.
*/
-class CRYPTOPP_NO_VTABLE SimpleKeyAgreementDomain : public KeyAgreementAlgorithm
+class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE SimpleKeyAgreementDomain : public KeyAgreementAlgorithm
{
public:
//! return length of agreed value produced
@@ -1382,7 +1405,7 @@ public:
key pairs. The long-lived key pair is called the static key pair,
and the short-lived key pair is called the ephemeral key pair.
*/
-class CRYPTOPP_NO_VTABLE AuthenticatedKeyAgreementDomain : public KeyAgreementAlgorithm
+class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE AuthenticatedKeyAgreementDomain : public KeyAgreementAlgorithm
{
public:
//! return length of agreed value produced
@@ -1539,7 +1562,7 @@ public:
#endif
//! BER Decode Exception Class, may be thrown during an ASN1 BER decode operation
-class BERDecodeErr : public InvalidArgument
+class CRYPTOPP_DLL BERDecodeErr : public InvalidArgument
{
public:
BERDecodeErr() : InvalidArgument("BER decode error") {}
@@ -1547,7 +1570,7 @@ public:
};
//! interface for encoding and decoding ASN1 objects
-class CRYPTOPP_NO_VTABLE ASN1Object
+class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE ASN1Object
{
public:
virtual ~ASN1Object() {}
diff --git a/cryptopp.rc b/cryptopp.rc
new file mode 100644
index 00000000..7f9913b2
--- /dev/null
+++ b/cryptopp.rc
@@ -0,0 +1,109 @@
+//Microsoft Developer Studio generated resource script.
+//
+#include "resource.h"
+
+#define APSTUDIO_READONLY_SYMBOLS
+/////////////////////////////////////////////////////////////////////////////
+//
+// Generated from the TEXTINCLUDE 2 resource.
+//
+#include "afxres.h"
+
+/////////////////////////////////////////////////////////////////////////////
+#undef APSTUDIO_READONLY_SYMBOLS
+
+/////////////////////////////////////////////////////////////////////////////
+// English (U.S.) resources
+
+#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
+#ifdef _WIN32
+LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
+#pragma code_page(1252)
+#endif //_WIN32
+
+#ifndef _MAC
+/////////////////////////////////////////////////////////////////////////////
+//
+// Version
+//
+
+VS_VERSION_INFO VERSIONINFO
+ FILEVERSION 5,0,3,0
+ PRODUCTVERSION 5,0,3,0
+ FILEFLAGSMASK 0x3fL
+#ifdef _DEBUG
+ FILEFLAGS 0x1L
+#else
+ FILEFLAGS 0x0L
+#endif
+ FILEOS 0x40004L
+ FILETYPE 0x2L
+ FILESUBTYPE 0x0L
+BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK "040904b0"
+ BEGIN
+ VALUE "Comments", "\0"
+ VALUE "CompanyName", "Wei Dai\0"
+ VALUE "FileDescription", "Crypto++® Library DLL\0"
+ VALUE "FileVersion", "5, 0, 3, 0\0"
+ VALUE "InternalName", "cryptopp\0"
+ VALUE "LegalCopyright", "Copyright © 1995-2003\0"
+ VALUE "LegalTrademarks", "Crypto++®\0"
+ VALUE "OriginalFilename", "cryptopp.dll\0"
+ VALUE "PrivateBuild", "\0"
+ VALUE "ProductName", "Crypto++® Library\0"
+ VALUE "ProductVersion", "5, 0, 3, 0\0"
+ VALUE "SpecialBuild", "\0"
+ END
+ END
+ BLOCK "VarFileInfo"
+ BEGIN
+ VALUE "Translation", 0x409, 1200
+ END
+END
+
+#endif // !_MAC
+
+
+#ifdef APSTUDIO_INVOKED
+/////////////////////////////////////////////////////////////////////////////
+//
+// TEXTINCLUDE
+//
+
+1 TEXTINCLUDE DISCARDABLE
+BEGIN
+ "resource.h\0"
+END
+
+2 TEXTINCLUDE DISCARDABLE
+BEGIN
+ "#include ""afxres.h""\r\n"
+ "\0"
+END
+
+3 TEXTINCLUDE DISCARDABLE
+BEGIN
+ "\r\n"
+ "\0"
+END
+
+#endif // APSTUDIO_INVOKED
+
+#endif // English (U.S.) resources
+/////////////////////////////////////////////////////////////////////////////
+
+
+
+#ifndef APSTUDIO_INVOKED
+/////////////////////////////////////////////////////////////////////////////
+//
+// Generated from the TEXTINCLUDE 3 resource.
+//
+
+
+/////////////////////////////////////////////////////////////////////////////
+#endif // not APSTUDIO_INVOKED
+
diff --git a/des.cpp b/des.cpp
index b3a58e50..c9f4a384 100644
--- a/des.cpp
+++ b/des.cpp
@@ -20,6 +20,8 @@
NAMESPACE_BEGIN(CryptoPP)
+#ifndef CRYPTOPP_IMPORTS
+
static inline bool CheckParity(byte b)
{
unsigned int a = b ^ (b >> 4);
@@ -445,6 +447,8 @@ void DES_EDE3::Base::ProcessAndXorBlock(const byte *inBlock, const byte *xorBloc
Block::Put(xorBlock, outBlock)(r)(l);
}
+#endif // #ifndef CRYPTOPP_IMPORTS
+
void DES_XEX3::Base::UncheckedSetKey(CipherDir dir, const byte *key, unsigned int length)
{
AssertValidKeyLength(length);
diff --git a/des.h b/des.h
index 5a7f2dfe..a6c56727 100644
--- a/des.h
+++ b/des.h
@@ -11,7 +11,7 @@ NAMESPACE_BEGIN(CryptoPP)
struct DES_Info : public FixedBlockSize<8>, public FixedKeyLength<8>
{
- static const char *StaticAlgorithmName() {return "DES";}
+ CRYPTOPP_DLL static const char * StaticAlgorithmName() {return "DES";}
};
/// DES
@@ -21,7 +21,7 @@ struct DES_Info : public FixedBlockSize<8>, public FixedKeyLength<8>
check or correct the parity bits if you wish. */
class DES : public DES_Info, public BlockCipherDocumentation
{
- class CRYPTOPP_NO_VTABLE Base : public BlockCipherBaseTemplate
+ class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl
{
public:
void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length = 8);
@@ -42,19 +42,19 @@ public:
//! correct DES key parity bits
static void CorrectKeyParityBits(byte *key);
- typedef BlockCipherTemplate Encryption;
- typedef BlockCipherTemplate Decryption;
+ typedef BlockCipherFinal Encryption;
+ typedef BlockCipherFinal Decryption;
};
struct DES_EDE2_Info : public FixedBlockSize<8>, public FixedKeyLength<16>
{
- static const char *StaticAlgorithmName() {return "DES-EDE2";}
+ CRYPTOPP_DLL static const char * StaticAlgorithmName() {return "DES-EDE2";}
};
/// DES-EDE2
class DES_EDE2 : public DES_EDE2_Info, public BlockCipherDocumentation
{
- class CRYPTOPP_NO_VTABLE Base : public BlockCipherBaseTemplate
+ class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl
{
public:
void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length);
@@ -65,19 +65,19 @@ class DES_EDE2 : public DES_EDE2_Info, public BlockCipherDocumentation
};
public:
- typedef BlockCipherTemplate Encryption;
- typedef BlockCipherTemplate Decryption;
+ typedef BlockCipherFinal Encryption;
+ typedef BlockCipherFinal Decryption;
};
struct DES_EDE3_Info : public FixedBlockSize<8>, public FixedKeyLength<24>
{
- static const char *StaticAlgorithmName() {return "DES-EDE3";}
+ CRYPTOPP_DLL static const char * StaticAlgorithmName() {return "DES-EDE3";}
};
/// DES-EDE3
class DES_EDE3 : public DES_EDE3_Info, public BlockCipherDocumentation
{
- class CRYPTOPP_NO_VTABLE Base : public BlockCipherBaseTemplate
+ class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl
{
public:
void UncheckedSetKey(CipherDir dir, const byte *key, unsigned int length);
@@ -88,8 +88,8 @@ class DES_EDE3 : public DES_EDE3_Info, public BlockCipherDocumentation
};
public:
- typedef BlockCipherTemplate Encryption;
- typedef BlockCipherTemplate Decryption;
+ typedef BlockCipherFinal Encryption;
+ typedef BlockCipherFinal Decryption;
};
struct DES_XEX3_Info : public FixedBlockSize<8>, public FixedKeyLength<24>
@@ -100,7 +100,7 @@ struct DES_XEX3_Info : public FixedBlockSize<8>, public FixedKeyLength<24>
/// DES-XEX3, AKA DESX
class DES_XEX3 : public DES_XEX3_Info, public BlockCipherDocumentation
{
- class CRYPTOPP_NO_VTABLE Base : public BlockCipherBaseTemplate
+ class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl
{
public:
void UncheckedSetKey(CipherDir dir, const byte *key, unsigned int length);
@@ -112,8 +112,8 @@ class DES_XEX3 : public DES_XEX3_Info, public BlockCipherDocumentation
};
public:
- typedef BlockCipherTemplate Encryption;
- typedef BlockCipherTemplate Decryption;
+ typedef BlockCipherFinal Encryption;
+ typedef BlockCipherFinal Decryption;
};
typedef DES::Encryption DESEncryption;
diff --git a/dessp.cpp b/dessp.cpp
index 1f7a9510..4ef9d18b 100644
--- a/dessp.cpp
+++ b/dessp.cpp
@@ -1,6 +1,9 @@
// This file is mostly generated by Phil Karn's gensp.c
#include "pch.h"
+
+#ifndef CRYPTOPP_IMPORTS
+
#include "des.h"
NAMESPACE_BEGIN(CryptoPP)
@@ -88,3 +91,5 @@ const word32 DES::Base::Spbox[8][64] = {
};
NAMESPACE_END
+
+#endif
diff --git a/dh.cpp b/dh.cpp
index fc818b72..22097a05 100644
--- a/dh.cpp
+++ b/dh.cpp
@@ -1,6 +1,9 @@
// dh.cpp - written and placed in the public domain by Wei Dai
#include "pch.h"
+
+#ifndef CRYPTOPP_IMPORTS
+
#include "dh.h"
NAMESPACE_BEGIN(CryptoPP)
@@ -12,3 +15,5 @@ void DH_TestInstantiations()
}
NAMESPACE_END
+
+#endif
diff --git a/dh.h b/dh.h
index 2514333b..31fa7985 100644
--- a/dh.h
+++ b/dh.h
@@ -85,6 +85,8 @@ private:
GroupParameters m_groupParameters;
};
+CRYPTOPP_DLL_TEMPLATE_CLASS DH_Domain;
+
//! Diffie-Hellman in GF(p) with key validation
typedef DH_Domain DH;
diff --git a/diamond.h b/diamond.h
index 4646b460..e5ac3e71 100644
--- a/diamond.h
+++ b/diamond.h
@@ -17,7 +17,7 @@ struct Diamond2_Info : public FixedBlockSize<16>, public VariableKeyLength<16, 1
/// Diamond2
class Diamond2 : public Diamond2_Info, public BlockCipherDocumentation
{
- class CRYPTOPP_NO_VTABLE Base : public BlockCipherBaseTemplate
+ class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl
{
public:
void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length, unsigned int rounds);
@@ -50,8 +50,8 @@ class Diamond2 : public Diamond2_Info, public BlockCipherDocumentation
};
public:
- typedef BlockCipherTemplate Encryption;
- typedef BlockCipherTemplate Decryption;
+ typedef BlockCipherFinal Encryption;
+ typedef BlockCipherFinal Decryption;
};
typedef Diamond2::Encryption Diamond2Encryption;
@@ -65,7 +65,7 @@ struct Diamond2Lite_Info : public FixedBlockSize<8>, public VariableKeyLength<16
/// Diamond2Lite
class Diamond2Lite : public Diamond2Lite_Info, public BlockCipherDocumentation
{
- class CRYPTOPP_NO_VTABLE Base : public BlockCipherBaseTemplate
+ class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl
{
public:
void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length, unsigned int rounds);
@@ -97,8 +97,8 @@ class Diamond2Lite : public Diamond2Lite_Info, public BlockCipherDocumentation
};
public:
- typedef BlockCipherTemplate Encryption;
- typedef BlockCipherTemplate Decryption;
+ typedef BlockCipherFinal Encryption;
+ typedef BlockCipherFinal Decryption;
};
typedef Diamond2Lite::Encryption Diamond2LiteEncryption;
diff --git a/dll.cpp b/dll.cpp
new file mode 100644
index 00000000..29f4aa57
--- /dev/null
+++ b/dll.cpp
@@ -0,0 +1,100 @@
+// dll.cpp - written and placed in the public domain by Wei Dai
+
+#ifndef CRYPTOPP_IMPORTS
+
+#define CRYPTOPP_MANUALLY_INSTANTIATE_TEMPLATES
+
+#include "dll.h"
+#pragma warning(default: 4660)
+
+#include
+#include
+
+#include "strciphr.cpp"
+#include "algebra.cpp"
+#include "eprecomp.cpp"
+#include "eccrypto.cpp"
+#include "iterhash.cpp"
+#include "oaep.cpp"
+
+static const byte s_moduleMac[CryptoPP::HMAC::DIGESTSIZE] = "reserved for mac";
+static HMODULE s_hModule = NULL;
+
+NAMESPACE_BEGIN(CryptoPP)
+
+template<> const byte PKCS_DigestDecoration::decoration[] = {0x30,0x21,0x30,0x09,0x06,0x05,0x2B,0x0E,0x03,0x02,0x1A,0x05,0x00,0x04,0x14};
+template<> const unsigned int PKCS_DigestDecoration::length = sizeof(PKCS_DigestDecoration::decoration);
+
+void DoDllPowerUpSelfTest()
+{
+ char moduleFileName[_MAX_PATH];
+ GetModuleFileNameA(s_hModule, moduleFileName, sizeof(moduleFileName));
+ CryptoPP::DoPowerUpSelfTest(moduleFileName, s_moduleMac);
+}
+
+NAMESPACE_END
+
+#endif
+
+#ifdef CRYPTOPP_EXPORTS
+
+USING_NAMESPACE(CryptoPP)
+
+static PNew s_pNew = NULL;
+static PDelete s_pDelete = NULL;
+
+void * _cdecl operator new (size_t size)
+{
+ if (!s_pNew)
+ {
+ HMODULE hExe = GetModuleHandle(NULL);
+ PGetNewAndDelete pGetNewAndDelete = (PGetNewAndDelete)GetProcAddress(hExe, "GetNewAndDeleteForCryptoPP");
+ if (pGetNewAndDelete)
+ pGetNewAndDelete(s_pNew, s_pDelete);
+ else
+ {
+ PSetNewAndDelete pSetNewAndDelete = (PSetNewAndDelete)GetProcAddress(hExe, "SetNewAndDeleteFromCryptoPP");
+ if (pSetNewAndDelete)
+ {
+ _set_new_mode(1);
+ s_pNew = &malloc;
+ s_pDelete = &free;
+ pSetNewAndDelete(s_pNew, s_pDelete, &_set_new_handler);
+ }
+ else
+ {
+ HMODULE hCrt = GetModuleHandle("msvcrtd");
+ if (!hCrt)
+ hCrt = GetModuleHandle("msvcrt");
+ if (hCrt)
+ {
+ s_pNew = (PNew)GetProcAddress(hCrt, "??2@YAPAXI@Z"); // operator new
+ s_pDelete = (PDelete)GetProcAddress(hCrt, "??3@YAXPAX@Z"); // operator delete
+ }
+ }
+ }
+
+ if (!s_pNew || !s_pDelete)
+ OutputDebugString("Crypto++ was not able to obtain new and delete function pointers.");
+ }
+ return s_pNew(size);
+}
+
+void _cdecl operator delete (void * p)
+{
+ s_pDelete(p);
+}
+
+BOOL APIENTRY DllMain(HANDLE hModule,
+ DWORD ul_reason_for_call,
+ LPVOID lpReserved)
+{
+ if (ul_reason_for_call == DLL_PROCESS_ATTACH)
+ {
+ s_hModule = (HMODULE)hModule;
+ DoDllPowerUpSelfTest();
+ }
+ return TRUE;
+}
+
+#endif
diff --git a/dll.h b/dll.h
new file mode 100644
index 00000000..a8b07d69
--- /dev/null
+++ b/dll.h
@@ -0,0 +1,64 @@
+#ifndef CRYPTOPP_DLL_H
+#define CRYPTOPP_DLL_H
+
+#if !defined(CRYPTOPP_EXPORTS) && !defined(CRYPTOPP_IMPORTS) && !defined(CRYPTOPP_NO_DLL)
+#ifdef CRYPTOPP_CONFIG_H
+#error To use the DLL version of Crypto++, this file must be included before any other Crypto++ header files.
+#endif
+#define CRYPTOPP_IMPORTS
+#endif
+
+#include "aes.h"
+#include "cbcmac.h"
+#include "channels.h"
+#include "des.h"
+#include "dh.h"
+#include "dsa.h"
+#include "ec2n.h"
+#include "eccrypto.h"
+#include "ecp.h"
+#include "files.h"
+#include "fips140.h"
+#include "hex.h"
+#include "hmac.h"
+#include "modes.h"
+#include "mqueue.h"
+#include "nbtheory.h"
+#include "osrng.h"
+#include "pkcspad.h"
+#include "randpool.h"
+#include "rsa.h"
+#include "sha.h"
+#include "skipjack.h"
+#include "trdlocal.h"
+
+#ifdef CRYPTOPP_IMPORTS
+
+#ifdef _DLL
+// cause CRT DLL to be initialized before Crypto++ so that we can use malloc and free during DllMain()
+#ifdef NDEBUG
+#pragma comment(lib, "msvcrt")
+#else
+#pragma comment(lib, "msvcrtd")
+#endif
+#endif
+
+#pragma comment(lib, "cryptopp")
+
+#endif // #ifdef CRYPTOPP_IMPORTS
+
+#include // for _PNH
+
+NAMESPACE_BEGIN(CryptoPP)
+
+typedef void * (_cdecl * PNew)(size_t);
+typedef void (_cdecl * PDelete)(void *);
+typedef void (_cdecl * PGetNewAndDelete)(PNew &, PDelete &);
+typedef _PNH (_cdecl * PSetNewHandler)(_PNH);
+typedef void (_cdecl * PSetNewAndDelete)(PNew, PDelete, PSetNewHandler);
+
+CRYPTOPP_DLL void DoDllPowerUpSelfTest();
+
+NAMESPACE_END
+
+#endif
diff --git a/dlltest.cpp b/dlltest.cpp
new file mode 100644
index 00000000..eb11feb4
--- /dev/null
+++ b/dlltest.cpp
@@ -0,0 +1,178 @@
+#include "dll.h"
+#include
+
+USING_NAMESPACE(CryptoPP)
+USING_NAMESPACE(std)
+
+void FIPS140_SampleApplication()
+{
+ if (!FIPS_140_2_ComplianceEnabled())
+ {
+ cerr << "FIPS-140-2 compliance was turned off at compile time.\n";
+ abort();
+ }
+
+ // check self test status
+ if (GetPowerUpSelfTestStatus() != POWER_UP_SELF_TEST_PASSED)
+ {
+ cerr << "Automatic power-up self test failed.\n";
+ abort();
+ }
+ cout << "0. Automatic power-up self test passed.\n";
+
+ // simulate a power-up self test error
+ SimulatePowerUpSelfTestFailure();
+ try
+ {
+ // trying to use a crypto algorithm after power-up self test error will result in an exception
+ DES::Encryption des;
+
+ // should not be here
+ cerr << "Use of DES failed to cause an exception after power-up self test error.\n";
+ abort();
+ }
+ catch (SelfTestFailure &e)
+ {
+ cout << "1. Caught expected exception when simulating self test failure. Exception message follows: ";
+ cout << e.what() << endl;
+ }
+
+ // clear the self test error state and redo power-up self test
+ DoDllPowerUpSelfTest();
+ if (GetPowerUpSelfTestStatus() != POWER_UP_SELF_TEST_PASSED)
+ {
+ cerr << "Re-do power-up self test failed.\n";
+ abort();
+ }
+ cout << "2. Re-do power-up self test passed.\n";
+
+ // encrypt and decrypt
+ const byte key[] = {0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};
+ const byte iv[] = {0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef};
+ const byte plaintext[] = { // "Now is the time for all " without tailing 0
+ 0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
+ 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
+ 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20};
+ byte ciphertext[24];
+ byte decrypted[24];
+
+ CFB_Mode::Encryption encryption_DES_CBC;
+ encryption_DES_CBC.SetKeyWithIV(key, 8, iv);
+ encryption_DES_CBC.ProcessString(ciphertext, plaintext, 24);
+
+ CFB_Mode::Decryption decryption_DES_CBC;
+ decryption_DES_CBC.SetKeyWithIV(key, 8, iv);
+ decryption_DES_CBC.ProcessString(decrypted, ciphertext, 24);
+
+ if (memcmp(plaintext, decrypted, 24) != 0)
+ {
+ cerr << "DES-CBC Encryption/decryption failed.\n";
+ abort();
+ }
+ cout << "3. DES-CBC Encryption/decryption succeeded.\n";
+
+ // hash
+ const byte message[] = {'a', 'b', 'c'};
+ const byte expectedDigest[] = {0xA9,0x99,0x3E,0x36,0x47,0x06,0x81,0x6A,0xBA,0x3E,0x25,0x71,0x78,0x50,0xC2,0x6C,0x9C,0xD0,0xD8,0x9D};
+ byte digest[20];
+
+ SHA1 sha;
+ sha.Update(message, 3);
+ sha.Final(digest);
+
+ if (memcmp(digest, expectedDigest, 20) != 0)
+ {
+ cerr << "SHA-1 hash failed.\n";
+ abort();
+ }
+ cout << "4. SHA-1 hash succeeded.\n";
+
+ // create auto-seeded X9.17 RNG object, if available
+#ifdef OS_RNG_AVAILABLE
+ AutoSeededX917RNG rng;
+#else
+ // this is used to allow this function to compile on platforms that don't have auto-seeded RNGs
+ RandomNumberGenerator &rng(NullRNG());
+#endif
+
+ // generate DSA key
+ DSA::PrivateKey dsaPrivateKey;
+ dsaPrivateKey.GenerateRandomWithKeySize(rng, 1024);
+ DSA::PublicKey dsaPublicKey;
+ dsaPublicKey.AssignFrom(dsaPrivateKey);
+ if (!dsaPrivateKey.Validate(rng, 3) || !dsaPublicKey.Validate(rng, 3))
+ {
+ cerr << "DSA key generation failed.\n";
+ abort();
+ }
+ cout << "5. DSA key generation succeeded.\n";
+
+ // encode DSA key
+ std::string encodedDsaPublicKey, encodedDsaPrivateKey;
+ dsaPublicKey.DEREncode(StringSink(encodedDsaPublicKey).Ref());
+ dsaPrivateKey.DEREncode(StringSink(encodedDsaPrivateKey).Ref());
+
+ // decode DSA key
+ DSA::PrivateKey decodedDsaPrivateKey;
+ decodedDsaPrivateKey.BERDecode(StringStore(encodedDsaPrivateKey).Ref());
+ DSA::PublicKey decodedDsaPublicKey;
+ decodedDsaPublicKey.BERDecode(StringStore(encodedDsaPublicKey).Ref());
+
+ if (!decodedDsaPrivateKey.Validate(rng, 3) || !decodedDsaPublicKey.Validate(rng, 3))
+ {
+ cerr << "DSA key encode/decode failed.\n";
+ abort();
+ }
+ cout << "6. DSA key encode/decode succeeded.\n";
+
+ // sign and verify
+ byte signature[40];
+ DSA::Signer signer(dsaPrivateKey);
+ assert(signer.SignatureLength() == 40);
+ signer.SignMessage(rng, message, 3, signature);
+
+ DSA::Verifier verifier(dsaPublicKey);
+ if (!verifier.VerifyMessage(message, 3, signature, sizeof(signature)))
+ {
+ cerr << "DSA signature and verification failed.\n";
+ abort();
+ }
+ cout << "7. DSA signature and verification succeeded.\n";
+
+
+ // try to verify an invalid signature
+ signature[0] ^= 1;
+ if (verifier.VerifyMessage(message, 3, signature, sizeof(signature)))
+ {
+ cerr << "DSA signature verification failed to detect bad signature.\n";
+ abort();
+ }
+ cout << "8. DSA signature verification successfully detected bad signature.\n";
+
+ // try to use an invalid key length
+ try
+ {
+ encryption_DES_CBC.SetKey(key, 5);
+
+ // should not be here
+ cerr << "DES implementation did not detect use of invalid key length.\n";
+ abort();
+ }
+ catch (InvalidArgument &e)
+ {
+ cout << "9. Caught expected exception when using invalid key length. Exception message follows: ";
+ cout << e.what() << endl;
+ }
+
+ cout << "\nFIPS 140-2 Sample Application completed normally.\n";
+}
+
+#ifdef CRYPTOPP_DLL_ONLY
+
+int __cdecl main()
+{
+ FIPS140_SampleApplication();
+ return 0;
+}
+
+#endif
diff --git a/dlltest.dsp b/dlltest.dsp
new file mode 100644
index 00000000..7a71a598
--- /dev/null
+++ b/dlltest.dsp
@@ -0,0 +1,90 @@
+# Microsoft Developer Studio Project File - Name="dlltest" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=dlltest - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "dlltest.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "dlltest.mak" CFG="dlltest - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "dlltest - Win32 Release" (based on "Win32 (x86) Console Application")
+!MESSAGE "dlltest - Win32 Debug" (based on "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName "Perforce Project"
+# PROP Scc_LocalPath "."
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "dlltest - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "dlltest___Win32_Release"
+# PROP BASE Intermediate_Dir "dlltest___Win32_Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "dlltest___Win32_Release"
+# PROP Intermediate_Dir "dlltest___Win32_Release"
+# 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 BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# 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"
+
+!ELSEIF "$(CFG)" == "dlltest - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "dlltest___Win32_Debug"
+# PROP BASE Intermediate_Dir "dlltest___Win32_Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "dlltest___Win32_Debug"
+# PROP Intermediate_Dir "dlltest___Win32_Debug"
+# 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 BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# 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 /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 /nologo /subsystem:console /debug /machine:I386 /out:"DLL_Debug/dlltest.exe" /pdbtype:sept /libpath:"DLL_Debug"
+
+!ENDIF
+
+# Begin Target
+
+# Name "dlltest - Win32 Release"
+# Name "dlltest - Win32 Debug"
+# Begin Source File
+
+SOURCE=.\dlltest.cpp
+# End Source File
+# End Target
+# End Project
diff --git a/dmac.h b/dmac.h
index e431c447..521ba448 100644
--- a/dmac.h
+++ b/dmac.h
@@ -35,7 +35,7 @@ private:
and Charles Rackoff. T should be BlockTransformation class.
*/
template
-class DMAC : public MessageAuthenticationCodeTemplate >
+class DMAC : public MessageAuthenticationCodeFinal >
{
public:
DMAC() {}
diff --git a/dsa.cpp b/dsa.cpp
index 4bdbae61..c7e3da18 100644
--- a/dsa.cpp
+++ b/dsa.cpp
@@ -1,6 +1,9 @@
// dsa.cpp - written and placed in the public domain by Wei Dai
#include "pch.h"
+
+#ifndef CRYPTOPP_IMPORTS
+
#include "dsa.h"
#include "nbtheory.h"
@@ -112,3 +115,5 @@ bool DSA::GeneratePrimes(const byte *seedIn, unsigned int g, int &counter,
}
NAMESPACE_END
+
+#endif
diff --git a/ec2n.cpp b/ec2n.cpp
index c6494efd..d668c4f0 100644
--- a/ec2n.cpp
+++ b/ec2n.cpp
@@ -1,6 +1,9 @@
// ec2n.cpp - written and placed in the public domain by Wei Dai
#include "pch.h"
+
+#ifndef CRYPTOPP_IMPORTS
+
#include "ec2n.h"
#include "asn.h"
@@ -281,7 +284,6 @@ EC2N::Point EcPrecomputation::CascadeExponentiate(const Integer &exponent,
}
*/
-template class AbstractGroup;
-template class DL_FixedBasePrecomputationImpl;
-
NAMESPACE_END
+
+#endif
diff --git a/ec2n.h b/ec2n.h
index c2177e76..3cb42460 100644
--- a/ec2n.h
+++ b/ec2n.h
@@ -9,7 +9,7 @@
NAMESPACE_BEGIN(CryptoPP)
//! Elliptic Curve Point
-struct EC2NPoint
+struct CRYPTOPP_DLL EC2NPoint
{
EC2NPoint() : identity(true) {}
EC2NPoint(const PolynomialMod2 &x, const PolynomialMod2 &y)
@@ -24,8 +24,10 @@ struct EC2NPoint
PolynomialMod2 x, y;
};
+CRYPTOPP_DLL_TEMPLATE_CLASS AbstractGroup;
+
//! Elliptic Curve over GF(2^n)
-class EC2N : public AbstractGroup
+class CRYPTOPP_DLL EC2N : public AbstractGroup
{
public:
typedef GF2NP Field;
@@ -73,12 +75,18 @@ public:
const FieldElement & GetA() const {return m_a;}
const FieldElement & GetB() const {return m_b;}
+ bool operator==(const EC2N &rhs) const
+ {return GetField() == rhs.GetField() && m_a == rhs.m_a && m_b == rhs.m_b;}
+
private:
clonable_ptr m_field;
FieldElement m_a, m_b;
mutable Point m_R;
};
+CRYPTOPP_DLL_TEMPLATE_CLASS DL_FixedBasePrecomputationImpl;
+CRYPTOPP_DLL_TEMPLATE_CLASS DL_GroupPrecomputation;
+
template class EcPrecomputation;
//! .
diff --git a/eccrypto.cpp b/eccrypto.cpp
index b0042e89..a9345349 100644
--- a/eccrypto.cpp
+++ b/eccrypto.cpp
@@ -1,14 +1,19 @@
+// eccrypto.cpp - written and placed in the public domain by Wei Dai
+
#include "pch.h"
+
+#ifndef CRYPTOPP_IMPORTS
+
#include "eccrypto.h"
-#include "ec2n.h"
-#include "ecp.h"
#include "nbtheory.h"
#include "oids.h"
#include "hex.h"
#include "argnames.h"
+#include "ec2n.h"
NAMESPACE_BEGIN(CryptoPP)
+#ifndef NDEBUG
static void ECDSA_TestInstantiations()
{
ECDSA::Signer t1;
@@ -20,6 +25,7 @@ static void ECDSA_TestInstantiations()
ECDH::Domain t7;
ECMQV::Domain t8;
}
+#endif
// VC60 workaround: complains when these functions are put into an anonymous namespace
static Integer ConvertToInteger(const PolynomialMod2 &x)
@@ -627,13 +633,6 @@ void DL_PrivateKey_EC::DEREncodeKey(BufferedTransformation &bt) const
privateKey.MessageEnd();
}
-// ******************************************************************
-
-template class DL_GroupParameters_EC;
-template class DL_GroupParameters_EC;
-template class DL_PublicKey_EC;
-template class DL_PublicKey_EC;
-template class DL_PrivateKey_EC;
-template class DL_PrivateKey_EC;
-
NAMESPACE_END
+
+#endif
diff --git a/eccrypto.h b/eccrypto.h
index dafa1c70..cb295a6a 100644
--- a/eccrypto.h
+++ b/eccrypto.h
@@ -1,5 +1,5 @@
#ifndef CRYPTOPP_ECCRYPTO_H
-#define CRYPTOPP_ECCRTPTO_H
+#define CRYPTOPP_ECCRYPTO_H
/*! \file
*/
@@ -12,11 +12,11 @@
#include "gfpcrypt.h"
#include "dh.h"
#include "mqv.h"
+#include "ecp.h"
+#include "ec2n.h"
NAMESPACE_BEGIN(CryptoPP)
-template class EcPrecomputation;
-
//! Elliptic Curve Parameters
/*! This class corresponds to the ASN.1 sequence of the same name
in ANSI X9.62 (also SEC 1).
@@ -117,6 +117,9 @@ public:
const EllipticCurve& GetCurve() const {return m_groupPrecomputation.GetCurve();}
+ bool operator==(const ThisClass &rhs) const
+ {return DL_GroupParametersImpl >::operator==(rhs);}
+
#ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY
const Point& GetBasePoint() const {return GetSubgroupGenerator();}
const Integer& GetBasePointOrder() const {return GetSubgroupOrder();}
@@ -133,6 +136,11 @@ protected:
mutable Integer m_k; // cofactor
};
+CRYPTOPP_DLL_TEMPLATE_CLASS DL_GroupParameters_EC;
+CRYPTOPP_DLL_TEMPLATE_CLASS DL_GroupParameters_EC;
+CRYPTOPP_DLL_TEMPLATE_CLASS DL_PublicKeyImpl >;
+CRYPTOPP_DLL_TEMPLATE_CLASS DL_PublicKeyImpl >;
+
//! .
template
class DL_PublicKey_EC : public DL_PublicKeyImpl >
@@ -150,6 +158,11 @@ public:
void DEREncodeKey(BufferedTransformation &bt) const;
};
+CRYPTOPP_DLL_TEMPLATE_CLASS DL_PublicKey_EC;
+CRYPTOPP_DLL_TEMPLATE_CLASS DL_PublicKey_EC;
+CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKeyImpl >;
+CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKeyImpl >;
+
//! .
template
class DL_PrivateKey_EC : public DL_PrivateKeyImpl >
@@ -171,6 +184,9 @@ public:
void DEREncodeKey(BufferedTransformation &bt) const;
};
+CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKey_EC;
+CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKey_EC;
+
//! Elliptic Curve Diffie-Hellman, AKA ECDH
template ::DefaultCofactorOption>
struct ECDH
@@ -196,6 +212,9 @@ struct DL_Keys_EC
template
struct ECDSA;
+CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKey_WithSignaturePairwiseConsistencyTest, ECDSA >;
+CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKey_WithSignaturePairwiseConsistencyTest, ECDSA >;
+
//! .
template
struct DL_Keys_ECDSA
@@ -204,6 +223,9 @@ struct DL_Keys_ECDSA
typedef DL_PrivateKey_WithSignaturePairwiseConsistencyTest, ECDSA > PrivateKey;
};
+CRYPTOPP_DLL_TEMPLATE_CLASS DL_Algorithm_GDSA;
+CRYPTOPP_DLL_TEMPLATE_CLASS DL_Algorithm_GDSA;
+
//! .
template
class DL_Algorithm_ECDSA : public DL_Algorithm_GDSA
diff --git a/ecp.cpp b/ecp.cpp
index cfbad96a..f13ee287 100644
--- a/ecp.cpp
+++ b/ecp.cpp
@@ -1,12 +1,14 @@
// ecp.cpp - written and placed in the public domain by Wei Dai
#include "pch.h"
+
+#ifndef CRYPTOPP_IMPORTS
+
#include "ecp.h"
#include "asn.h"
#include "nbtheory.h"
#include "algebra.cpp"
-#include "eprecomp.cpp"
NAMESPACE_BEGIN(CryptoPP)
@@ -463,15 +465,6 @@ ECP::Point ECP::CascadeScalarMultiply(const Point &P, const Integer &k1, const P
return AbstractGroup::CascadeScalarMultiply(P, k1, Q, k2);
}
-// ********************************************************
-
-void EcPrecomputation::SetCurve(const ECP &ec)
-{
- m_ec.reset(new ECP(ec, true));
- m_ecOriginal = ec;
-}
-
-template class AbstractGroup;
-template class DL_FixedBasePrecomputationImpl;
-
NAMESPACE_END
+
+#endif
diff --git a/ecp.h b/ecp.h
index 28822ee9..bc7303d1 100644
--- a/ecp.h
+++ b/ecp.h
@@ -9,7 +9,7 @@
NAMESPACE_BEGIN(CryptoPP)
//! Elliptical Curve Point
-struct ECPPoint
+struct CRYPTOPP_DLL ECPPoint
{
ECPPoint() : identity(true) {}
ECPPoint(const Integer &x, const Integer &y)
@@ -24,8 +24,10 @@ struct ECPPoint
Integer x, y;
};
+CRYPTOPP_DLL_TEMPLATE_CLASS AbstractGroup;
+
//! Elliptic Curve over GF(p), where p is prime
-class ECP : public AbstractGroup
+class CRYPTOPP_DLL ECP : public AbstractGroup
{
public:
typedef ModularArithmetic Field;
@@ -77,12 +79,18 @@ public:
const FieldElement & GetA() const {return m_a;}
const FieldElement & GetB() const {return m_b;}
+ bool operator==(const ECP &rhs) const
+ {return GetField() == rhs.GetField() && m_a == rhs.m_a && m_b == rhs.m_b;}
+
private:
clonable_ptr m_fieldPtr;
FieldElement m_a, m_b;
mutable Point m_R;
};
+CRYPTOPP_DLL_TEMPLATE_CLASS DL_FixedBasePrecomputationImpl;
+CRYPTOPP_DLL_TEMPLATE_CLASS DL_GroupPrecomputation;
+
template class EcPrecomputation;
//! .
@@ -102,7 +110,11 @@ public:
void DEREncodeElement(BufferedTransformation &bt, const Element &v) const {m_ec->DEREncodePoint(bt, v, false);}
// non-inherited
- void SetCurve(const ECP &ec);
+ void SetCurve(const ECP &ec)
+ {
+ m_ec.reset(new ECP(ec, true));
+ m_ecOriginal = ec;
+ }
const ECP & GetCurve() const {return *m_ecOriginal;}
private:
diff --git a/eprecomp.cpp b/eprecomp.cpp
index f9878b90..a061cf6c 100644
--- a/eprecomp.cpp
+++ b/eprecomp.cpp
@@ -1,6 +1,9 @@
// eprecomp.cpp - written and placed in the public domain by Wei Dai
#include "pch.h"
+
+#ifndef CRYPTOPP_IMPORTS
+
#include "eprecomp.h"
#include "asn.h"
@@ -105,3 +108,5 @@ template T
}
NAMESPACE_END
+
+#endif
diff --git a/files.cpp b/files.cpp
index fc32b4b4..25300a1b 100644
--- a/files.cpp
+++ b/files.cpp
@@ -1,6 +1,9 @@
// files.cpp - written and placed in the public domain by Wei Dai
#include "pch.h"
+
+#ifndef CRYPTOPP_IMPORTS
+
#include "files.h"
NAMESPACE_BEGIN(CryptoPP)
@@ -16,16 +19,15 @@ void Files_TestInstantiations()
void FileStore::StoreInitialize(const NameValuePairs ¶meters)
{
- m_file.close();
- m_file.clear();
+ m_file.reset(new std::ifstream);
const char *fileName;
if (parameters.GetValue(Name::InputFileName(), fileName))
{
ios::openmode binary = parameters.GetValueWithDefault(Name::InputBinaryMode(), true) ? ios::binary : ios::openmode(0);
- m_file.open(fileName, ios::in | binary);
- if (!m_file)
+ m_file->open(fileName, ios::in | binary);
+ if (!*m_file)
throw OpenErr(fileName);
- m_stream = &m_file;
+ m_stream = m_file.get();
}
else
{
@@ -148,14 +150,15 @@ unsigned long FileStore::Skip(unsigned long skipMax)
void FileSink::IsolatedInitialize(const NameValuePairs ¶meters)
{
+ m_file.reset(new std::ofstream);
const char *fileName;
if (parameters.GetValue(Name::OutputFileName(), fileName))
{
ios::openmode binary = parameters.GetValueWithDefault(Name::OutputBinaryMode(), true) ? ios::binary : ios::openmode(0);
- m_file.open(fileName, ios::out | ios::trunc | binary);
- if (!m_file)
+ m_file->open(fileName, ios::out | ios::trunc | binary);
+ if (!*m_file)
throw OpenErr(fileName);
- m_stream = &m_file;
+ m_stream = m_file.get();
}
else
{
@@ -193,3 +196,5 @@ unsigned int FileSink::Put2(const byte *inString, unsigned int length, int messa
}
NAMESPACE_END
+
+#endif
diff --git a/files.h b/files.h
index fc3d650b..e54d8902 100644
--- a/files.h
+++ b/files.h
@@ -11,7 +11,7 @@
NAMESPACE_BEGIN(CryptoPP)
//! .
-class FileStore : public Store, private FilterPutSpaceHelper
+class CRYPTOPP_DLL FileStore : public Store, private FilterPutSpaceHelper, public NotCopyable
{
public:
class Err : public Exception
@@ -38,7 +38,7 @@ public:
private:
void StoreInitialize(const NameValuePairs ¶meters);
- std::ifstream m_file;
+ member_ptr m_file;
std::istream *m_stream;
byte *m_space;
unsigned int m_len;
@@ -46,7 +46,7 @@ private:
};
//! .
-class FileSource : public SourceTemplate
+class CRYPTOPP_DLL FileSource : public SourceTemplate
{
public:
typedef FileStore::Err Err;
@@ -64,7 +64,7 @@ public:
};
//! .
-class FileSink : public Sink
+class CRYPTOPP_DLL FileSink : public Sink, public NotCopyable
{
public:
class Err : public Exception
@@ -88,7 +88,7 @@ public:
bool IsolatedFlush(bool hardFlush, bool blocking);
private:
- std::ofstream m_file;
+ member_ptr m_file;
std::ostream *m_stream;
};
diff --git a/filters.cpp b/filters.cpp
index 576022e3..3596e26f 100644
--- a/filters.cpp
+++ b/filters.cpp
@@ -1,6 +1,9 @@
// filters.cpp - written and placed in the public domain by Wei Dai
#include "pch.h"
+
+#ifndef CRYPTOPP_IMPORTS
+
#include "filters.h"
#include "mqueue.h"
#include "fltrimpl.h"
@@ -154,7 +157,7 @@ unsigned int MeterFilter::Put2(const byte *begin, unsigned int length, int messa
m_currentSeriesMessages++;
m_totalMessages++;
}
-
+
FILTER_OUTPUT(1, begin, length, messageEnd);
FILTER_END_NO_MESSAGE_END;
}
@@ -773,7 +776,7 @@ void SignatureVerificationFilter::InitializeDerivedAndReturnNewSizes(const NameV
{
m_flags = parameters.GetValueWithDefault(Name::SignatureVerificationFilterFlags(), (word32)DEFAULT_FLAGS);
m_messageAccumulator.reset(m_verifier.NewVerificationAccumulator());
- unsigned int size = m_verifier.SignatureLength();
+ unsigned int size = m_verifier.SignatureLength();
assert(size != 0); // TODO: handle recoverable signature scheme
m_verified = false;
firstSize = m_flags & SIGNATURE_AT_BEGIN ? size : 0;
@@ -931,3 +934,5 @@ unsigned int NullStore::TransferTo2(BufferedTransformation &target, unsigned lon
}
NAMESPACE_END
+
+#endif
diff --git a/filters.h b/filters.h
index afd33572..74b2b3d3 100644
--- a/filters.h
+++ b/filters.h
@@ -11,7 +11,7 @@
NAMESPACE_BEGIN(CryptoPP)
/// provides an implementation of BufferedTransformation's attachment interface
-class CRYPTOPP_NO_VTABLE Filter : public BufferedTransformation, public NotCopyable
+class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Filter : public BufferedTransformation, public NotCopyable
{
public:
Filter(BufferedTransformation *attachment);
@@ -52,7 +52,7 @@ protected:
int m_continueAt;
};
-struct FilterPutSpaceHelper
+struct CRYPTOPP_DLL FilterPutSpaceHelper
{
// desiredSize is how much to ask target, bufferSize is how much to allocate in m_tempSpace
byte *HelpCreatePutSpace(BufferedTransformation &target, const std::string &channel, unsigned int minSize, unsigned int desiredSize, unsigned int &bufferSize)
@@ -80,7 +80,7 @@ struct FilterPutSpaceHelper
};
//! measure how many byte and messages pass through, also serves as valve
-class MeterFilter : public Bufferless
+class CRYPTOPP_DLL MeterFilter : public Bufferless
{
public:
MeterFilter(BufferedTransformation *attachment=NULL, bool transparent=true)
@@ -111,14 +111,14 @@ private:
};
//! .
-class TransparentFilter : public MeterFilter
+class CRYPTOPP_DLL TransparentFilter : public MeterFilter
{
public:
TransparentFilter(BufferedTransformation *attachment=NULL) : MeterFilter(attachment, true) {}
};
//! .
-class OpaqueFilter : public MeterFilter
+class CRYPTOPP_DLL OpaqueFilter : public MeterFilter
{
public:
OpaqueFilter(BufferedTransformation *attachment=NULL) : MeterFilter(attachment, false) {}
@@ -129,7 +129,7 @@ public:
First and last blocks are optional, and middle blocks may
be a stream instead (i.e. blockSize == 1).
*/
-class FilterWithBufferedInput : public Filter
+class CRYPTOPP_DLL FilterWithBufferedInput : public Filter
{
public:
FilterWithBufferedInput(BufferedTransformation *attachment);
@@ -212,7 +212,7 @@ private:
};
//! .
-class FilterWithInputQueue : public Filter
+class CRYPTOPP_DLL FilterWithInputQueue : public Filter
{
public:
FilterWithInputQueue(BufferedTransformation *attachment) : Filter(attachment) {}
@@ -238,7 +238,7 @@ protected:
};
//! Filter Wrapper for StreamTransformation
-class StreamTransformationFilter : public FilterWithBufferedInput, private FilterPutSpaceHelper
+class CRYPTOPP_DLL StreamTransformationFilter : public FilterWithBufferedInput, private FilterPutSpaceHelper
{
public:
enum BlockPaddingScheme {NO_PADDING, ZEROS_PADDING, PKCS_PADDING, ONE_AND_ZEROS_PADDING, DEFAULT_PADDING};
@@ -265,7 +265,7 @@ typedef StreamTransformationFilter StreamCipherFilter;
#endif
//! Filter Wrapper for HashTransformation
-class HashFilter : public Bufferless, private FilterPutSpaceHelper
+class CRYPTOPP_DLL HashFilter : public Bufferless, private FilterPutSpaceHelper
{
public:
HashFilter(HashTransformation &hm, BufferedTransformation *attachment = NULL, bool putMessage=false)
@@ -283,7 +283,7 @@ private:
};
//! Filter Wrapper for HashTransformation
-class HashVerificationFilter : public FilterWithBufferedInput
+class CRYPTOPP_DLL HashVerificationFilter : public FilterWithBufferedInput
{
public:
class HashVerificationFailed : public Exception
@@ -317,7 +317,7 @@ private:
typedef HashVerificationFilter HashVerifier; // for backwards compatibility
//! Filter Wrapper for PK_Signer
-class SignerFilter : public Unflushable
+class CRYPTOPP_DLL SignerFilter : public Unflushable
{
public:
SignerFilter(RandomNumberGenerator &rng, const PK_Signer &signer, BufferedTransformation *attachment = NULL, bool putMessage=false)
@@ -328,14 +328,14 @@ public:
private:
RandomNumberGenerator &m_rng;
- const PK_Signer &m_signer;
+ const PK_Signer &m_signer;
member_ptr m_messageAccumulator;
bool m_putMessage;
SecByteBlock m_buf;
};
//! Filter Wrapper for PK_Verifier
-class SignatureVerificationFilter : public FilterWithBufferedInput
+class CRYPTOPP_DLL SignatureVerificationFilter : public FilterWithBufferedInput
{
public:
class SignatureVerificationFailed : public Exception
@@ -364,10 +364,10 @@ private:
bool m_verified;
};
-typedef SignatureVerificationFilter VerifierFilter; // for backwards compatibility
+typedef SignatureVerificationFilter VerifierFilter; // for backwards compatibility
//! Redirect input to another BufferedTransformation without owning it
-class Redirector : public CustomSignalPropagation
+class CRYPTOPP_DLL Redirector : public CustomSignalPropagation
{
public:
enum Behavior
@@ -429,7 +429,7 @@ private:
};
// Used By ProxyFilter
-class OutputProxy : public CustomSignalPropagation
+class CRYPTOPP_DLL OutputProxy : public CustomSignalPropagation
{
public:
OutputProxy(BufferedTransformation &owner, bool passSignal) : m_owner(owner), m_passSignal(passSignal) {}
@@ -467,7 +467,7 @@ private:
};
//! Base class for Filter classes that are proxies for a chain of other filters.
-class ProxyFilter : public FilterWithBufferedInput
+class CRYPTOPP_DLL ProxyFilter : public FilterWithBufferedInput
{
public:
ProxyFilter(BufferedTransformation *filter, unsigned int firstSize, unsigned int lastSize, BufferedTransformation *attachment);
@@ -483,7 +483,7 @@ protected:
};
//! simple proxy filter that doesn't modify the underlying filter's input or output
-class SimpleProxyFilter : public ProxyFilter
+class CRYPTOPP_DLL SimpleProxyFilter : public ProxyFilter
{
public:
SimpleProxyFilter(BufferedTransformation *filter, BufferedTransformation *attachment)
@@ -495,7 +495,7 @@ public:
//! proxy for the filter created by PK_Encryptor::CreateEncryptionFilter
/*! This class is here just to provide symmetry with VerifierFilter. */
-class PK_EncryptorFilter : public SimpleProxyFilter
+class CRYPTOPP_DLL PK_EncryptorFilter : public SimpleProxyFilter
{
public:
PK_EncryptorFilter(RandomNumberGenerator &rng, const PK_Encryptor &encryptor, BufferedTransformation *attachment = NULL)
@@ -504,7 +504,7 @@ public:
//! proxy for the filter created by PK_Decryptor::CreateDecryptionFilter
/*! This class is here just to provide symmetry with SignerFilter. */
-class PK_DecryptorFilter : public SimpleProxyFilter
+class CRYPTOPP_DLL PK_DecryptorFilter : public SimpleProxyFilter
{
public:
PK_DecryptorFilter(RandomNumberGenerator &rng, const PK_Decryptor &decryptor, BufferedTransformation *attachment = NULL)
@@ -532,7 +532,7 @@ public:
typename T::size_type size = m_output->size();
if (length < size && size + length > m_output->capacity())
m_output->reserve(2*size);
- m_output->append((const char_type *)begin, (const char_type *)begin+length);
+ m_output->append((const char_type *)begin, (const char_type *)begin+length);
}
return 0;
}
@@ -542,10 +542,11 @@ private:
};
//! Append input to an std::string
+CRYPTOPP_DLL_TEMPLATE_CLASS StringSinkTemplate;
typedef StringSinkTemplate StringSink;
//! Copy input to a memory buffer
-class ArraySink : public Bufferless
+class CRYPTOPP_DLL ArraySink : public Bufferless
{
public:
ArraySink(const NameValuePairs ¶meters = g_nullNameValuePairs) {IsolatedInitialize(parameters);}
@@ -565,7 +566,7 @@ protected:
};
//! Xor input to a memory buffer
-class ArrayXorSink : public ArraySink
+class CRYPTOPP_DLL ArrayXorSink : public ArraySink
{
public:
ArrayXorSink(byte *buf, unsigned int size)
@@ -586,18 +587,18 @@ public:
template StringStore(const T &string)
{StoreInitialize(MakeParameters("InputBuffer", ConstByteArrayParameter(string)));}
- unsigned int TransferTo2(BufferedTransformation &target, unsigned long &transferBytes, const std::string &channel=NULL_CHANNEL, bool blocking=true);
- unsigned int CopyRangeTo2(BufferedTransformation &target, unsigned long &begin, unsigned long end=ULONG_MAX, const std::string &channel=NULL_CHANNEL, bool blocking=true) const;
+ CRYPTOPP_DLL unsigned int TransferTo2(BufferedTransformation &target, unsigned long &transferBytes, const std::string &channel=NULL_CHANNEL, bool blocking=true);
+ CRYPTOPP_DLL unsigned int CopyRangeTo2(BufferedTransformation &target, unsigned long &begin, unsigned long end=ULONG_MAX, const std::string &channel=NULL_CHANNEL, bool blocking=true) const;
private:
- void StoreInitialize(const NameValuePairs ¶meters);
+ CRYPTOPP_DLL void StoreInitialize(const NameValuePairs ¶meters);
const byte *m_store;
unsigned int m_length, m_count;
};
//! .
-class RandomNumberStore : public Store
+class CRYPTOPP_DLL RandomNumberStore : public Store
{
public:
RandomNumberStore(RandomNumberGenerator &rng, unsigned long length)
@@ -621,7 +622,7 @@ private:
};
//! .
-class NullStore : public Store
+class CRYPTOPP_DLL NullStore : public Store
{
public:
NullStore(unsigned long size = ULONG_MAX) : m_size(size) {}
@@ -635,7 +636,7 @@ private:
};
//! A Filter that pumps data into its attachment as input
-class CRYPTOPP_NO_VTABLE Source : public InputRejecting
+class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Source : public InputRejecting
{
public:
Source(BufferedTransformation *attachment)
@@ -690,7 +691,7 @@ protected:
};
//! .
-class StringSource : public SourceTemplate
+class CRYPTOPP_DLL StringSource : public SourceTemplate
{
public:
StringSource(BufferedTransformation *attachment = NULL)
@@ -699,17 +700,12 @@ public:
: SourceTemplate(attachment) {SourceInitialize(pumpAll, MakeParameters("InputBuffer", ConstByteArrayParameter(string)));}
StringSource(const byte *string, unsigned int length, bool pumpAll, BufferedTransformation *attachment = NULL)
: SourceTemplate(attachment) {SourceInitialize(pumpAll, MakeParameters("InputBuffer", ConstByteArrayParameter(string, length)));}
-
-#ifdef __MWERKS__ // CW60 workaround
StringSource(const std::string &string, bool pumpAll, BufferedTransformation *attachment = NULL)
-#else
- template StringSource(const T &string, bool pumpAll, BufferedTransformation *attachment = NULL)
-#endif
: SourceTemplate(attachment) {SourceInitialize(pumpAll, MakeParameters("InputBuffer", ConstByteArrayParameter(string)));}
};
//! .
-class RandomNumberSource : public SourceTemplate
+class CRYPTOPP_DLL RandomNumberSource : public SourceTemplate
{
public:
RandomNumberSource(RandomNumberGenerator &rng, unsigned int length, bool pumpAll, BufferedTransformation *attachment = NULL)
diff --git a/fips140.cpp b/fips140.cpp
index 7781956a..1fcf5901 100644
--- a/fips140.cpp
+++ b/fips140.cpp
@@ -1,6 +1,9 @@
// fips140.cpp - written and placed in the public domain by Wei Dai
#include "pch.h"
+
+#ifndef CRYPTOPP_IMPORTS
+
#include "fips140.h"
#include "trdlocal.h" // needs to be included last for cygwin
@@ -32,7 +35,7 @@ void SimulatePowerUpSelfTestFailure()
g_powerUpSelfTestStatus = POWER_UP_SELF_TEST_FAILED;
}
-PowerUpSelfTestStatus GetPowerUpSelfTestStatus()
+PowerUpSelfTestStatus CRYPTOPP_API GetPowerUpSelfTestStatus()
{
return g_powerUpSelfTestStatus;
}
@@ -77,3 +80,5 @@ void SignaturePairwiseConsistencyTest_FIPS_140_Only(const PK_Signer &signer, con
}
NAMESPACE_END
+
+#endif
diff --git a/fips140.h b/fips140.h
index 76353ed5..f46eff69 100644
--- a/fips140.h
+++ b/fips140.h
@@ -10,26 +10,36 @@
NAMESPACE_BEGIN(CryptoPP)
//! exception thrown when a crypto algorithm is used after a self test fails
-class SelfTestFailure : public Exception
+class CRYPTOPP_DLL SelfTestFailure : public Exception
{
public:
explicit SelfTestFailure(const std::string &s) : Exception(OTHER_ERROR, s) {}
};
//! returns whether FIPS 140-2 compliance features were enabled at compile time
-bool FIPS_140_2_ComplianceEnabled();
+CRYPTOPP_DLL bool FIPS_140_2_ComplianceEnabled();
//! enum values representing status of the power-up self test
enum PowerUpSelfTestStatus {POWER_UP_SELF_TEST_NOT_DONE, POWER_UP_SELF_TEST_FAILED, POWER_UP_SELF_TEST_PASSED};
//! perform the power-up self test, and set the self test status
-void DoPowerUpSelfTest(const char *moduleFilename, const byte *expectedModuleSha1Digest);
+CRYPTOPP_DLL void DoPowerUpSelfTest(const char *moduleFilename, const byte *expectedModuleMac);
//! set the power-up self test status to POWER_UP_SELF_TEST_FAILED
-void SimulatePowerUpSelfTestFailure();
+CRYPTOPP_DLL void SimulatePowerUpSelfTestFailure();
//! return the current power-up self test status
-PowerUpSelfTestStatus GetPowerUpSelfTestStatus();
+CRYPTOPP_DLL PowerUpSelfTestStatus CRYPTOPP_API GetPowerUpSelfTestStatus();
+
+typedef PowerUpSelfTestStatus (CRYPTOPP_API * PGetPowerUpSelfTestStatus)();
+
+CRYPTOPP_DLL const byte * CRYPTOPP_API GetActualMacAndLocation(unsigned int &macSize, unsigned int &fileLocation);
+
+typedef const byte * (CRYPTOPP_API * PGetActualMacAndLocation)(unsigned int &macSize, unsigned int &fileLocation);
+
+CRYPTOPP_DLL MessageAuthenticationCode * NewIntegrityCheckingMAC();
+
+CRYPTOPP_DLL bool IntegrityCheckModule(const char *moduleFilename, const byte *expectedModuleMac, SecByteBlock *pActualMac = NULL, unsigned long *pMacFileLocation = NULL);
// this is used by Algorithm constructor to allow Algorithm objects to be constructed for the self test
bool PowerUpSelfTestInProgressOnThisThread();
diff --git a/fipstest.cpp b/fipstest.cpp
index c2256193..70fbb87e 100644
--- a/fipstest.cpp
+++ b/fipstest.cpp
@@ -1,27 +1,24 @@
// fipstest.cpp - written and placed in the public domain by Wei Dai
#include "pch.h"
-#include "fips140.h"
-#include "sha.h"
-#include "files.h"
-#include "hex.h"
-#include "rsa.h"
-#include "dsa.h"
-#include "mqueue.h"
-#include "channels.h"
-#include "osrng.h"
-#include "des.h"
-#include "eccrypto.h"
-#include "ec2n.h"
-#include "ecp.h"
-#include "modes.h"
-#include "aes.h"
-#include "skipjack.h"
-#include "trdlocal.h" // needs to be included last for cygwin
+
+#ifndef CRYPTOPP_IMPORTS
+
+#include "dll.h"
+#include
NAMESPACE_BEGIN(CryptoPP)
extern PowerUpSelfTestStatus g_powerUpSelfTestStatus;
+SecByteBlock g_actualMac;
+unsigned long g_macFileLocation = 0;
+
+const byte * CRYPTOPP_API GetActualMacAndLocation(unsigned int &macSize, unsigned int &fileLocation)
+{
+ macSize = g_actualMac.size();
+ fileLocation = g_macFileLocation;
+ return g_actualMac;
+}
void KnownAnswerTest(RandomNumberGenerator &rng, const char *output)
{
@@ -105,22 +102,22 @@ void SymmetricEncryptionKnownAnswerTest(
void KnownAnswerTest(HashTransformation &hash, const char *message, const char *digest)
{
EqualityComparisonFilter comparison;
- StringSource(message, true, new HashFilter(hash, new ChannelSwitch(comparison, "0")));
StringSource(digest, true, new HexDecoder(new ChannelSwitch(comparison, "1")));
+ StringSource(message, true, new HashFilter(hash, new ChannelSwitch(comparison, "0")));
comparison.ChannelMessageSeriesEnd("0");
comparison.ChannelMessageSeriesEnd("1");
}
template
-void SecureHashKnownAnswerTest(const char *message, const char *digest)
+void SecureHashKnownAnswerTest(const char *message, const char *digest, HASH *dummy = NULL)
{
HASH hash;
KnownAnswerTest(hash, message, digest);
}
template
-void MAC_KnownAnswerTest(const char *key, const char *message, const char *digest)
+void MAC_KnownAnswerTest(const char *key, const char *message, const char *digest, MAC *dummy = NULL)
{
std::string decodedKey;
StringSource(key, true, new HexDecoder(new StringSink(decodedKey)));
@@ -219,7 +216,104 @@ void SignaturePairwiseConsistencyTest(const char *key, SCHEME *dummy = NULL)
SignaturePairwiseConsistencyTest(signer, verifier);
}
-void DoPowerUpSelfTest(const char *moduleFilename, const byte *expectedModuleSha1Digest)
+MessageAuthenticationCode * NewIntegrityCheckingMAC()
+{
+ byte key[] = {0x47, 0x1E, 0x33, 0x96, 0x65, 0xB1, 0x6A, 0xED, 0x0B, 0xF8, 0x6B, 0xFD, 0x01, 0x65, 0x05, 0xCC};
+ return new HMAC(key, sizeof(key));
+}
+
+bool IntegrityCheckModule(const char *moduleFilename, const byte *expectedModuleMac, SecByteBlock *pActualMac, unsigned long *pMacFileLocation)
+{
+ std::auto_ptr mac(NewIntegrityCheckingMAC());
+ unsigned int macSize = mac->DigestSize();
+
+ SecByteBlock tempMac;
+ SecByteBlock &actualMac = pActualMac ? *pActualMac : tempMac;
+ actualMac.resize(macSize);
+
+ unsigned long tempLocation;
+ unsigned long &macFileLocation = pMacFileLocation ? *pMacFileLocation : tempLocation;
+ macFileLocation = 0;
+
+ HashFilter verifier(*mac, new ArraySink(actualMac, actualMac.size()));
+ FileStore file(moduleFilename);
+
+#ifdef CRYPTOPP_WIN32_AVAILABLE
+ // try to hash from memory first
+ HMODULE h = GetModuleHandle(moduleFilename);
+ IMAGE_DOS_HEADER *ph = (IMAGE_DOS_HEADER *)h;
+ IMAGE_NT_HEADERS *phnt = (IMAGE_NT_HEADERS *)((byte *)h + ph->e_lfanew);
+ IMAGE_SECTION_HEADER *phs = IMAGE_FIRST_SECTION(phnt);
+ DWORD nSections = phnt->FileHeader.NumberOfSections;
+ DWORD currentFilePos = 0;
+
+ while (nSections--)
+ {
+ switch (phs->Characteristics)
+ {
+ default:
+ break;
+ case IMAGE_SCN_CNT_CODE | IMAGE_SCN_MEM_EXECUTE | IMAGE_SCN_MEM_READ:
+ case IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ:
+ DWORD sectionSize = STDMIN(phs->SizeOfRawData, phs->Misc.VirtualSize);
+ const byte *memStart = (const byte *)h + phs->VirtualAddress;
+ DWORD fileStart = phs->PointerToRawData;
+ if (phs->VirtualAddress == phnt->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IAT].VirtualAddress)
+ {
+ // read IAT, which is changed during DLL loading, from disk
+ DWORD iatSize = phnt->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IAT].Size;
+ fileStart += iatSize;
+ memStart += iatSize;
+ sectionSize -= iatSize;
+ }
+ file.TransferTo(verifier, fileStart - currentFilePos);
+ if (memStart <= expectedModuleMac && expectedModuleMac < memStart + sectionSize)
+ {
+ // skip over the MAC
+ verifier.Put(memStart, expectedModuleMac - memStart);
+ verifier.Put(expectedModuleMac + macSize, sectionSize - macSize - (expectedModuleMac - memStart));
+ macFileLocation = fileStart + (expectedModuleMac - memStart);
+ }
+ else
+ verifier.Put(memStart, sectionSize);
+ ::VirtualUnlock((LPVOID)memStart, sectionSize); // release the memory from working set
+ file.Skip(sectionSize);
+ currentFilePos = fileStart + sectionSize;
+ }
+ phs++;
+ }
+#endif
+ file.TransferAllTo(verifier);
+
+#ifdef CRYPTOPP_WIN32_AVAILABLE
+ // if that fails (could be caused by debug breakpoints or DLL base relocation modifying image in memory),
+ // hash from disk instead
+ if (memcmp(expectedModuleMac, actualMac, macSize) != 0)
+ {
+ OutputDebugString("In memory integrity check failed. This may be caused by debug breakpoints or DLL relocation.\n");
+ file.Initialize(MakeParameters("InputFileName", moduleFilename));
+ verifier.Detach(new ArraySink(actualMac, actualMac.size()));
+ if (macFileLocation)
+ {
+ file.TransferTo(verifier, macFileLocation);
+ file.Skip(macSize);
+ }
+ file.TransferAllTo(verifier);
+ }
+#endif
+
+ if (memcmp(expectedModuleMac, actualMac, macSize) == 0)
+ return true;
+
+#ifdef CRYPTOPP_WIN32_AVAILABLE
+ std::string hexMac;
+ HexEncoder(new StringSink(hexMac)).PutMessageEnd(actualMac, actualMac.size());
+ OutputDebugString((moduleFilename + (" integrity check failed. Actual MAC is: " + hexMac) + "\n").c_str());
+#endif
+ return false;
+}
+
+void DoPowerUpSelfTest(const char *moduleFilename, const byte *expectedModuleMac)
{
g_powerUpSelfTestStatus = POWER_UP_SELF_TEST_NOT_DONE;
SetPowerUpSelfTestInProgressOnThisThread(true);
@@ -228,72 +322,8 @@ void DoPowerUpSelfTest(const char *moduleFilename, const byte *expectedModuleSha
{
if (FIPS_140_2_ComplianceEnabled() || moduleFilename != NULL)
{
- // integrity test
- SHA1 sha;
- HashVerifier verifier(sha);
- verifier.Put(expectedModuleSha1Digest, sha.DigestSize());
- FileStore file(moduleFilename);
-
-#ifdef CRYPTOPP_WIN32_AVAILABLE
- // try to hash from memory first
- HMODULE h = GetModuleHandle(moduleFilename);
- IMAGE_DOS_HEADER *ph = (IMAGE_DOS_HEADER *)h;
- IMAGE_NT_HEADERS *phnt = (IMAGE_NT_HEADERS *)((byte *)h + ph->e_lfanew);
- IMAGE_SECTION_HEADER *phs = IMAGE_FIRST_SECTION(phnt);
- DWORD nSections = phnt->FileHeader.NumberOfSections;
- DWORD currentFilePos = 0;
-
- while (nSections--)
- {
- DWORD sectionSize = STDMIN(phs->SizeOfRawData, phs->Misc.VirtualSize);
- switch (phs->Characteristics)
- {
- default:
- break;
- case IMAGE_SCN_CNT_CODE | IMAGE_SCN_MEM_EXECUTE | IMAGE_SCN_MEM_READ:
- case IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ:
- const byte *memStart = (const byte *)h + phs->VirtualAddress;
- DWORD fileStart = phs->PointerToRawData;
- if (phs->VirtualAddress == phnt->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IAT].VirtualAddress)
- {
- // read IAT, which is changed during DLL loading, from disk
- DWORD iatSize = phnt->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IAT].Size;
- fileStart += iatSize;
- memStart += iatSize;
- sectionSize -= iatSize;
- }
- file.TransferTo(verifier, fileStart - currentFilePos);
- verifier.Put(memStart, sectionSize);
- ::VirtualUnlock((LPVOID)memStart, sectionSize); // release the memory from working set
- file.Skip(sectionSize);
- currentFilePos = fileStart + sectionSize;
- }
- phs++;
- }
-#endif
- file.TransferAllTo(verifier);
-
-#ifdef CRYPTOPP_WIN32_AVAILABLE
- // if that fails (could be caused by debug breakpoints or DLL base relocation modifying image in memory),
- // hash from disk instead
- if (!verifier.GetLastResult())
- {
- OutputDebugString("In memory EDC test failed. This may be caused by debug breakpoints or DLL relocation.\n");
- verifier.Put(expectedModuleSha1Digest, sha.DigestSize());
- file.Initialize(MakeParameters(Name::InputFileName(), moduleFilename));
- file.TransferAllTo(verifier);
- }
-#endif
-
- if (!verifier.GetLastResult())
- {
-#ifdef CRYPTOPP_WIN32_AVAILABLE
- std::string actualDigest;
- FileSource(moduleFilename, true, new HashFilter(sha, new HexEncoder(new StringSink(actualDigest))));
- OutputDebugString(("Crypto++ EDC test failed. Actual digest is: " + actualDigest + "\n").c_str());
-#endif
+ if (!IntegrityCheckModule(moduleFilename, expectedModuleMac, &g_actualMac, &g_macFileLocation))
throw 0; // throw here so we break in the debugger, this will be caught right away
- }
}
// algorithm tests
@@ -359,11 +389,38 @@ void DoPowerUpSelfTest(const char *moduleFilename, const byte *expectedModuleSha
"abc",
"A9993E364706816ABA3E25717850C26C9CD0D89D");
+ SecureHashKnownAnswerTest(
+ "abc",
+ "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad");
+
+ SecureHashKnownAnswerTest(
+ "abc",
+ "cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7");
+
+ SecureHashKnownAnswerTest(
+ "abc",
+ "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f");
+
MAC_KnownAnswerTest >(
"303132333435363738393a3b3c3d3e3f40414243",
"Sample #2",
"0922d3405faa3d194f82a45830737d5cc6c75d24");
+ MAC_KnownAnswerTest >(
+ "303132333435363738393a3b3c3d3e3f40414243",
+ "abc",
+ "D28363F335B2DAE468793A38680DEA9F7FB8BE1DCEDA197CDB3B1CB59A9F6422");
+
+ MAC_KnownAnswerTest >(
+ "303132333435363738393a3b3c3d3e3f40414243",
+ "abc",
+ "E7740C592F1414C969190EFACF51FC8BE1CB52F5DC5E686200D2CA1773D151DB19C59112371CE374165A6BF72AEF69D0");
+
+ MAC_KnownAnswerTest >(
+ "303132333435363738393a3b3c3d3e3f40414243",
+ "abc",
+ "BF07864E733B995862F3C2D432C7FF2F5EB073FFFC4F880CD94D5D21086476B7428F27BE694A9D9CB3BB500FE1255852BAFCBAF4042390B3706CDF02421B51AC");
+
SignatureKnownAnswerTest >(
"30820150020100300d06092a864886f70d01010105000482013a3082013602010002400a66791dc6988168de7ab77419bb7fb0"
"c001c62710270075142942e19a8d8c51d053b3e3782a1de5dc5af4ebe99468170114a1dfe67cdc9a9af55d655620bbab0203010001"
@@ -398,3 +455,5 @@ done:
}
NAMESPACE_END
+
+#endif
diff --git a/gf2n.cpp b/gf2n.cpp
index 30430750..b7b4bf9c 100644
--- a/gf2n.cpp
+++ b/gf2n.cpp
@@ -1,17 +1,18 @@
// gf2n.cpp - written and placed in the public domain by Wei Dai
#include "pch.h"
+
+#ifndef CRYPTOPP_IMPORTS
+
#include "gf2n.h"
#include "algebra.h"
#include "words.h"
-#include "rng.h"
+#include "randpool.h"
#include "asn.h"
#include "oids.h"
#include
-#include "algebra.cpp"
-
NAMESPACE_BEGIN(CryptoPP)
PolynomialMod2::PolynomialMod2()
@@ -551,10 +552,10 @@ GF2NP::Element GF2NP::SolveQuadraticEquation(const Element &a) const
if (m%2 == 0)
{
Element z, w;
+ RandomPool rng;
do
{
- LC_RNG rng(11111);
- Element p(rng, m);
+ Element p((RandomNumberGenerator &)rng, m);
z = PolynomialMod2::Zero();
w = p;
for (unsigned int i=1; i<=m-1; i++)
@@ -868,3 +869,5 @@ GF2NP * BERDecodeGF2NP(BufferedTransformation &bt)
}
NAMESPACE_END
+
+#endif
diff --git a/gf2n.h b/gf2n.h
index 69a149b7..f5a4468c 100644
--- a/gf2n.h
+++ b/gf2n.h
@@ -14,7 +14,7 @@ NAMESPACE_BEGIN(CryptoPP)
//! Polynomial with Coefficients in GF(2)
/*! \nosubgrouping */
-class PolynomialMod2
+class CRYPTOPP_DLL PolynomialMod2
{
public:
//! \name ENUMS, EXCEPTIONS, and TYPEDEFS
@@ -236,8 +236,13 @@ private:
SecWordBlock reg;
};
+CRYPTOPP_DLL_TEMPLATE_CLASS AbstractGroup;
+CRYPTOPP_DLL_TEMPLATE_CLASS AbstractRing;
+CRYPTOPP_DLL_TEMPLATE_CLASS EuclideanDomainOf;
+CRYPTOPP_DLL_TEMPLATE_CLASS QuotientRing >;
+
//! GF(2^n) with Polynomial Basis
-class GF2NP : public QuotientRing >
+class CRYPTOPP_DLL GF2NP : public QuotientRing