00001
00002
00003 #define CRYPTOPP_MANUALLY_INSTANTIATE_TEMPLATES
00004 #define CRYPTOPP_DEFAULT_NO_DLL
00005
00006 #include "dll.h"
00007 #include "config.h"
00008
00009
00010 #if CRYPTOPP_MSC_VERSION
00011 # pragma warning(disable: 4589)
00012 #endif
00013
00014 #if CRYPTOPP_MSC_VERSION
00015 # pragma warning(default: 4660)
00016 #endif
00017
00018 #if defined(CRYPTOPP_EXPORTS) && defined(CRYPTOPP_WIN32_AVAILABLE)
00019 #include <windows.h>
00020 #endif
00021
00022 #ifndef CRYPTOPP_IMPORTS
00023
00024 NAMESPACE_BEGIN(CryptoPP)
00025
00026 template<> const byte PKCS_DigestDecoration<SHA1>::decoration[] = {0x30,0x21,0x30,0x09,0x06,0x05,0x2B,0x0E,0x03,0x02,0x1A,0x05,0x00,0x04,0x14};
00027 template<> const unsigned int PKCS_DigestDecoration<SHA1>::length = sizeof(PKCS_DigestDecoration<SHA1>::decoration);
00028
00029 template<> const byte PKCS_DigestDecoration<SHA224>::decoration[] = {0x30,0x2d,0x30,0x0d,0x06,0x09,0x60,0x86,0x48,0x01,0x65,0x03,0x04,0x02,0x04,0x05,0x00,0x04,0x1c};
00030 template<> const unsigned int PKCS_DigestDecoration<SHA224>::length = sizeof(PKCS_DigestDecoration<SHA224>::decoration);
00031
00032 template<> const byte PKCS_DigestDecoration<SHA256>::decoration[] = {0x30,0x31,0x30,0x0d,0x06,0x09,0x60,0x86,0x48,0x01,0x65,0x03,0x04,0x02,0x01,0x05,0x00,0x04,0x20};
00033 template<> const unsigned int PKCS_DigestDecoration<SHA256>::length = sizeof(PKCS_DigestDecoration<SHA256>::decoration);
00034
00035 template<> const byte PKCS_DigestDecoration<SHA384>::decoration[] = {0x30,0x41,0x30,0x0d,0x06,0x09,0x60,0x86,0x48,0x01,0x65,0x03,0x04,0x02,0x02,0x05,0x00,0x04,0x30};
00036 template<> const unsigned int PKCS_DigestDecoration<SHA384>::length = sizeof(PKCS_DigestDecoration<SHA384>::decoration);
00037
00038 template<> const byte PKCS_DigestDecoration<SHA512>::decoration[] = {0x30,0x51,0x30,0x0d,0x06,0x09,0x60,0x86,0x48,0x01,0x65,0x03,0x04,0x02,0x03,0x05,0x00,0x04,0x40};
00039 template<> const unsigned int PKCS_DigestDecoration<SHA512>::length = sizeof(PKCS_DigestDecoration<SHA512>::decoration);
00040
00041 template<> const byte EMSA2HashId<SHA>::id = 0x33;
00042 template<> const byte EMSA2HashId<SHA224>::id = 0x38;
00043 template<> const byte EMSA2HashId<SHA256>::id = 0x34;
00044 template<> const byte EMSA2HashId<SHA384>::id = 0x36;
00045 template<> const byte EMSA2HashId<SHA512>::id = 0x35;
00046
00047 NAMESPACE_END
00048
00049 #endif
00050
00051 #ifdef CRYPTOPP_EXPORTS
00052
00053 USING_NAMESPACE(CryptoPP)
00054
00055 #if !(defined(_MSC_VER) && (_MSC_VER < 1300))
00056 using std::set_new_handler;
00057 #endif
00058
00059 static PNew s_pNew = NULL;
00060 static PDelete s_pDelete = NULL;
00061
00062 static void * New (size_t size)
00063 {
00064 void *p;
00065 while ((p = malloc(size)) == NULL)
00066 CallNewHandler();
00067
00068 return p;
00069 }
00070
00071
00072 #pragma warning(disable: 4191)
00073
00074 static void SetNewAndDeleteFunctionPointers()
00075 {
00076 void *p = NULL;
00077 HMODULE hModule = NULL;
00078 MEMORY_BASIC_INFORMATION mbi;
00079
00080 while (true)
00081 {
00082 VirtualQuery(p, &mbi, sizeof(mbi));
00083
00084 if (p >= (char *)mbi.BaseAddress + mbi.RegionSize)
00085 break;
00086
00087 p = (char *)mbi.BaseAddress + mbi.RegionSize;
00088
00089 if (!mbi.AllocationBase || mbi.AllocationBase == hModule)
00090 continue;
00091
00092 hModule = HMODULE(mbi.AllocationBase);
00093 PGetNewAndDelete pGetNewAndDelete = (PGetNewAndDelete)GetProcAddress(hModule, "GetNewAndDeleteForCryptoPP");
00094 if (pGetNewAndDelete)
00095 {
00096 pGetNewAndDelete(s_pNew, s_pDelete);
00097 return;
00098 }
00099
00100 PSetNewAndDelete pSetNewAndDelete = (PSetNewAndDelete)GetProcAddress(hModule, "SetNewAndDeleteFromCryptoPP");
00101 if (pSetNewAndDelete)
00102 {
00103 s_pNew = &New;
00104 s_pDelete = &free;
00105 pSetNewAndDelete(s_pNew, s_pDelete, &set_new_handler);
00106 return;
00107 }
00108 }
00109
00110
00111
00112 hModule = GetModuleHandle("msvcrtd");
00113 if (!hModule)
00114 hModule = GetModuleHandle("msvcrt");
00115 if (hModule)
00116 {
00117
00118 s_pNew = (PNew)GetProcAddress(hModule, "??2@YAPAXI@Z");
00119 s_pDelete = (PDelete)GetProcAddress(hModule, "??3@YAXPAX@Z");
00120 if (s_pNew && s_pDelete)
00121 return;
00122
00123
00124 s_pNew = (PNew)GetProcAddress(hModule, "??2@YAPEAX_K@Z");
00125 s_pDelete = (PDelete)GetProcAddress(hModule, "??3@YAXPEAX@Z");
00126 if (s_pNew && s_pDelete)
00127 return;
00128 }
00129
00130 OutputDebugString("Crypto++ was not able to obtain new and delete function pointers.\n");
00131 throw 0;
00132 }
00133
00134
00135 #pragma warning(default: 4191)
00136
00137 void * operator new (size_t size)
00138 {
00139 if (!s_pNew)
00140 SetNewAndDeleteFunctionPointers();
00141
00142 return s_pNew(size);
00143 }
00144
00145 void operator delete (void * p)
00146 {
00147 s_pDelete(p);
00148 }
00149
00150 void * operator new [] (size_t size)
00151 {
00152 return operator new (size);
00153 }
00154
00155 void operator delete [] (void * p)
00156 {
00157 operator delete (p);
00158 }
00159
00160 #endif // #ifdef CRYPTOPP_EXPORTS