Skip to content

Commit

Permalink
changes done for FIPS-140 lab code drop
Browse files Browse the repository at this point in the history
  • Loading branch information
weidai11 committed Jan 20, 2005
1 parent 79e29d0 commit b3924f2
Show file tree
Hide file tree
Showing 57 changed files with 997 additions and 617 deletions.
5 changes: 4 additions & 1 deletion Readme.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Crypto++: a C++ Class Library of Cryptographic Schemes
Version 5.2.2 (in development)
Version 5.2.3 (in development)

This library includes:

Expand Down Expand Up @@ -346,5 +346,8 @@ the mailing list.

5.2.2 - added SHA-224
- put SHA-256, SHA-384, SHA-512, RSASSA-PSS into DLL

5.2.3 - fixed issues with FIPS algorithm test vectors
- put RSASSA-ISO into DLL

Written by Wei Dai
2 changes: 1 addition & 1 deletion algparam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

NAMESPACE_BEGIN(CryptoPP)

bool (*AssignIntToInteger)(const std::type_info &valueType, void *pInteger, const void *pInt) = NULL;
PAssignIntToInteger g_pAssignIntToInteger = NULL;

bool CombinedNameValuePairs::GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const
{
Expand Down
9 changes: 5 additions & 4 deletions algparam.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,11 @@ AssignFromHelperClass<T, T> AssignFromHelper(T *pObject, const NameValuePairs &s

// ********************************************************

// This should allow the linker to discard Integer code if not needed.
CRYPTOPP_DLL extern bool (*AssignIntToInteger)(const std::type_info &valueType, void *pInteger, const void *pInt);
// to allow the linker to discard Integer code if not needed.
typedef bool (CRYPTOPP_API * PAssignIntToInteger)(const std::type_info &valueType, void *pInteger, const void *pInt);
CRYPTOPP_DLL extern PAssignIntToInteger g_pAssignIntToInteger;

CRYPTOPP_DLL const std::type_info & IntegerTypeId();
CRYPTOPP_DLL const std::type_info & CRYPTOPP_API IntegerTypeId();

class CRYPTOPP_DLL AlgorithmParametersBase : public NameValuePairs
{
Expand Down Expand Up @@ -292,7 +293,7 @@ class AlgorithmParametersBase2 : public AlgorithmParametersBase
void AssignValue(const char *name, const std::type_info &valueType, void *pValue) const
{
// special case for retrieving an Integer parameter when an int was passed in
if (!(AssignIntToInteger != NULL && typeid(T) == typeid(int) && AssignIntToInteger(valueType, pValue, &m_value)))
if (!(g_pAssignIntToInteger != NULL && typeid(T) == typeid(int) && g_pAssignIntToInteger(valueType, pValue, &m_value)))
{
ThrowIfTypeMismatch(name, typeid(T), valueType);
*reinterpret_cast<T *>(pValue) = m_value;
Expand Down
1 change: 1 addition & 0 deletions argnames.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ CRYPTOPP_DEFINE_NAME_STRING(MultiplicativeInverseOfPrime2ModPrime1) //!< Integer
CRYPTOPP_DEFINE_NAME_STRING(QuadraticResidueModPrime1) //!< Integer
CRYPTOPP_DEFINE_NAME_STRING(QuadraticResidueModPrime2) //!< Integer
CRYPTOPP_DEFINE_NAME_STRING(PutMessage) //!< bool
CRYPTOPP_DEFINE_NAME_STRING(TruncatedDigestSize) //!< int
CRYPTOPP_DEFINE_NAME_STRING(HashVerificationFilterFlags) //!< word32
CRYPTOPP_DEFINE_NAME_STRING(SignatureVerificationFilterFlags) //!< word32
CRYPTOPP_DEFINE_NAME_STRING(InputBuffer) //!< ConstByteArrayParameter
Expand Down
26 changes: 13 additions & 13 deletions asn.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,27 +56,27 @@ class CRYPTOPP_DLL UnknownOID : public BERDecodeErr
};

// unsigned int DERLengthEncode(unsigned int length, byte *output=0);
CRYPTOPP_DLL unsigned int DERLengthEncode(BufferedTransformation &out, unsigned int length);
CRYPTOPP_DLL unsigned int CRYPTOPP_API DERLengthEncode(BufferedTransformation &out, unsigned int length);
// returns false if indefinite length
CRYPTOPP_DLL bool BERLengthDecode(BufferedTransformation &in, unsigned int &length);
CRYPTOPP_DLL bool CRYPTOPP_API BERLengthDecode(BufferedTransformation &in, unsigned int &length);

CRYPTOPP_DLL void DEREncodeNull(BufferedTransformation &out);
CRYPTOPP_DLL void BERDecodeNull(BufferedTransformation &in);
CRYPTOPP_DLL void CRYPTOPP_API DEREncodeNull(BufferedTransformation &out);
CRYPTOPP_DLL void CRYPTOPP_API BERDecodeNull(BufferedTransformation &in);

CRYPTOPP_DLL unsigned int DEREncodeOctetString(BufferedTransformation &out, const byte *str, unsigned int strLen);
CRYPTOPP_DLL unsigned int DEREncodeOctetString(BufferedTransformation &out, const SecByteBlock &str);
CRYPTOPP_DLL unsigned int BERDecodeOctetString(BufferedTransformation &in, SecByteBlock &str);
CRYPTOPP_DLL unsigned int BERDecodeOctetString(BufferedTransformation &in, BufferedTransformation &str);
CRYPTOPP_DLL unsigned int CRYPTOPP_API DEREncodeOctetString(BufferedTransformation &out, const byte *str, unsigned int strLen);
CRYPTOPP_DLL unsigned int CRYPTOPP_API DEREncodeOctetString(BufferedTransformation &out, const SecByteBlock &str);
CRYPTOPP_DLL unsigned int CRYPTOPP_API BERDecodeOctetString(BufferedTransformation &in, SecByteBlock &str);
CRYPTOPP_DLL unsigned int CRYPTOPP_API BERDecodeOctetString(BufferedTransformation &in, BufferedTransformation &str);

// for UTF8_STRING, PRINTABLE_STRING, and IA5_STRING
CRYPTOPP_DLL unsigned int DEREncodeTextString(BufferedTransformation &out, const std::string &str, byte asnTag);
CRYPTOPP_DLL unsigned int BERDecodeTextString(BufferedTransformation &in, std::string &str, byte asnTag);
CRYPTOPP_DLL unsigned int CRYPTOPP_API DEREncodeTextString(BufferedTransformation &out, const std::string &str, byte asnTag);
CRYPTOPP_DLL unsigned int CRYPTOPP_API BERDecodeTextString(BufferedTransformation &in, std::string &str, byte asnTag);

CRYPTOPP_DLL unsigned int DEREncodeBitString(BufferedTransformation &out, const byte *str, unsigned int strLen, unsigned int unusedBits=0);
CRYPTOPP_DLL unsigned int BERDecodeBitString(BufferedTransformation &in, SecByteBlock &str, unsigned int &unusedBits);
CRYPTOPP_DLL unsigned int CRYPTOPP_API DEREncodeBitString(BufferedTransformation &out, const byte *str, unsigned int strLen, unsigned int unusedBits=0);
CRYPTOPP_DLL unsigned int CRYPTOPP_API BERDecodeBitString(BufferedTransformation &in, SecByteBlock &str, unsigned int &unusedBits);

// BER decode from source and DER reencode into dest
CRYPTOPP_DLL void DERReencode(BufferedTransformation &source, BufferedTransformation &dest);
CRYPTOPP_DLL void CRYPTOPP_API DERReencode(BufferedTransformation &source, BufferedTransformation &dest);

//! Object Identifier
class CRYPTOPP_DLL OID
Expand Down
4 changes: 1 addition & 3 deletions config.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,14 +273,12 @@ NAMESPACE_END
#define CRYPTOPP_DLL
#endif

#define CRYPTOPP_API __stdcall
#define CRYPTOPP_CDECL __cdecl
#define CRYPTOPP_API __cdecl

#else // CRYPTOPP_WIN32_AVAILABLE

#define CRYPTOPP_DLL
#define CRYPTOPP_API
#define CRYPTOPP_CDECL

#endif // CRYPTOPP_WIN32_AVAILABLE

Expand Down
4 changes: 2 additions & 2 deletions cryptlib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ unsigned int BufferedTransformation::PutWord32(word32 value, ByteOrder order, bo
return ChannelPutWord32(NULL_CHANNEL, value, order, blocking);
}

unsigned int BufferedTransformation::PeekWord16(word16 &value, ByteOrder order)
unsigned int BufferedTransformation::PeekWord16(word16 &value, ByteOrder order) const
{
byte buf[2] = {0, 0};
unsigned int len = Peek(buf, 2);
Expand All @@ -487,7 +487,7 @@ unsigned int BufferedTransformation::PeekWord16(word16 &value, ByteOrder order)
return len;
}

unsigned int BufferedTransformation::PeekWord32(word32 &value, ByteOrder order)
unsigned int BufferedTransformation::PeekWord32(word32 &value, ByteOrder order) const
{
byte buf[4] = {0, 0, 0, 0};
unsigned int len = Peek(buf, 4);
Expand Down
10 changes: 5 additions & 5 deletions cryptlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
classes that provide a uniform interface to this library.
*/

/*! \mainpage <a href="http://www.cryptopp.com">Crypto++</a><sup><small>&reg;</small></sup> Library 5.2.2 Reference Manual
/*! \mainpage <a href="http://www.cryptopp.com">Crypto++</a><sup><small>&reg;</small></sup> Library 5.2.3 Reference Manual
<dl>
<dt>Abstract Base Classes<dd>
cryptlib.h
Expand Down Expand Up @@ -283,7 +283,7 @@ class CRYPTOPP_NO_VTABLE NameValuePairs
{return GetValueWithDefault(name, defaultValue);}

//! used by derived classes to check for type mismatch
CRYPTOPP_DLL static void ThrowIfTypeMismatch(const char *name, const std::type_info &stored, const std::type_info &retrieving)
CRYPTOPP_DLL static void CRYPTOPP_API ThrowIfTypeMismatch(const char *name, const std::type_info &stored, const std::type_info &retrieving)
{if (stored != retrieving) throw ValueTypeMismatch(name, stored, retrieving);}

template <class T>
Expand Down Expand Up @@ -653,7 +653,7 @@ class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE RandomNumberGenerator : public Algorithm
};

//! returns a reference that can be passed to functions that ask for a RNG but doesn't actually use it
CRYPTOPP_DLL RandomNumberGenerator & NullRNG();
CRYPTOPP_DLL RandomNumberGenerator & CRYPTOPP_API NullRNG();

class WaitObjectContainer;

Expand Down Expand Up @@ -823,9 +823,9 @@ class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE BufferedTransformation : public Algorithm,
unsigned int GetWord32(word32 &value, ByteOrder order=BIG_ENDIAN_ORDER);

//! try to peek at a 16-bit word
unsigned int PeekWord16(word16 &value, ByteOrder order=BIG_ENDIAN_ORDER);
unsigned int PeekWord16(word16 &value, ByteOrder order=BIG_ENDIAN_ORDER) const;
//! try to peek at a 32-bit word
unsigned int PeekWord32(word32 &value, ByteOrder order=BIG_ENDIAN_ORDER);
unsigned int PeekWord32(word32 &value, ByteOrder order=BIG_ENDIAN_ORDER) const;

//! move transferMax bytes of the buffered output to target as input
unsigned long TransferTo(BufferedTransformation &target, unsigned long transferMax=ULONG_MAX, const std::string &channel=NULL_CHANNEL)
Expand Down
37 changes: 16 additions & 21 deletions cryptopp.rc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//Microsoft Developer Studio generated resource script.
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"

Expand All @@ -21,15 +21,14 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32

#ifndef _MAC
/////////////////////////////////////////////////////////////////////////////
//
// Version
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 5,2,0,0
PRODUCTVERSION 5,2,0,0
FILEVERSION 5,2,3,0
PRODUCTVERSION 5,2,3,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
Expand All @@ -44,18 +43,16 @@ BEGIN
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "Comments", "free crypto library, more information available at www.cryptopp.com\0"
VALUE "CompanyName", "Wei Dai\0"
VALUE "FileDescription", "Crypto++� Library DLL\0"
VALUE "FileVersion", "5, 2, 0, 0\0"
VALUE "InternalName", "cryptopp\0"
VALUE "LegalCopyright", "Copyright � 1995-2003 by Wei Dai\0"
VALUE "LegalTrademarks", "Crypto++�\0"
VALUE "OriginalFilename", "cryptopp.dll\0"
VALUE "PrivateBuild", "\0"
VALUE "ProductName", "Crypto++� Library\0"
VALUE "ProductVersion", "5, 2, 0, 0\0"
VALUE "SpecialBuild", "\0"
VALUE "Comments", "free crypto library, more information available at www.cryptopp.com"
VALUE "CompanyName", "Wei Dai"
VALUE "FileDescription", "Crypto++� Library DLL"
VALUE "FileVersion", "5, 2, 3, 0"
VALUE "InternalName", "cryptopp"
VALUE "LegalCopyright", "Copyright � 1995-2004 by Wei Dai"
VALUE "LegalTrademarks", "Crypto++�"
VALUE "OriginalFilename", "cryptopp.dll"
VALUE "ProductName", "Crypto++� Library"
VALUE "ProductVersion", "5, 2, 3, 0"
END
END
BLOCK "VarFileInfo"
Expand All @@ -64,27 +61,25 @@ BEGIN
END
END

#endif // !_MAC


#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//

1 TEXTINCLUDE DISCARDABLE
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END

2 TEXTINCLUDE DISCARDABLE
2 TEXTINCLUDE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END

3 TEXTINCLUDE DISCARDABLE
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
Expand Down
4 changes: 2 additions & 2 deletions default.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static void Mash(const byte *in, word16 inLen, byte *out, word16 outLen, int ite
unsigned int i;
for(i=0; i<outLen; i+=DefaultHashModule::DIGESTSIZE)
{
b[0] = (byte) i >> 8;
b[0] = (byte) (i >> 8);
b[1] = (byte) i;
hash.Update(b, 2);
hash.Update(in, inLen);
Expand All @@ -45,7 +45,7 @@ static void Mash(const byte *in, word16 inLen, byte *out, word16 outLen, int ite
memcpy(buf, outBuf, bufSize);
for (i=0; i<bufSize; i+=DefaultHashModule::DIGESTSIZE)
{
b[0] = (byte) i >> 8;
b[0] = (byte) (i >> 8);
b[1] = (byte) i;
hash.Update(b, 2);
hash.Update(buf, bufSize);
Expand Down
4 changes: 2 additions & 2 deletions des.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class DES : public DES_Info, public BlockCipherDocumentation
//! _
struct DES_EDE2_Info : public FixedBlockSize<8>, public FixedKeyLength<16>
{
CRYPTOPP_DLL static const char * StaticAlgorithmName() {return "DES-EDE2";}
CRYPTOPP_DLL static const char * CRYPTOPP_API StaticAlgorithmName() {return "DES-EDE2";}
};

/// <a href="http://www.weidai.com/scan-mirror/cs.html#DESede">DES-EDE2</a>
Expand All @@ -78,7 +78,7 @@ class DES_EDE2 : public DES_EDE2_Info, public BlockCipherDocumentation
//! _
struct DES_EDE3_Info : public FixedBlockSize<8>, public FixedKeyLength<24>
{
CRYPTOPP_DLL static const char * StaticAlgorithmName() {return "DES-EDE3";}
CRYPTOPP_DLL static const char * CRYPTOPP_API StaticAlgorithmName() {return "DES-EDE3";}
};

/// <a href="http://www.weidai.com/scan-mirror/cs.html#DESede">DES-EDE3</a>
Expand Down
18 changes: 11 additions & 7 deletions dll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ CRYPTOPP_DLL_TEMPLATE_CLASS AdditiveCipherTemplate<AbstractPolicyHolder<Additive
CRYPTOPP_DLL_TEMPLATE_CLASS AbstractEuclideanDomain<Integer>;
#endif

template<> const byte PKCS_DigestDecoration<SHA>::decoration[] = {0x30,0x21,0x30,0x09,0x06,0x05,0x2B,0x0E,0x03,0x02,0x1A,0x05,0x00,0x04,0x14};
template<> const unsigned int PKCS_DigestDecoration<SHA>::length = sizeof(PKCS_DigestDecoration<SHA>::decoration);
template<> const byte PKCS_DigestDecoration<SHA1>::decoration[] = {0x30,0x21,0x30,0x09,0x06,0x05,0x2B,0x0E,0x03,0x02,0x1A,0x05,0x00,0x04,0x14};
template<> const unsigned int PKCS_DigestDecoration<SHA1>::length = sizeof(PKCS_DigestDecoration<SHA1>::decoration);

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};
template<> const unsigned int PKCS_DigestDecoration<SHA224>::length = sizeof(PKCS_DigestDecoration<SHA224>::decoration);

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};
template<> const unsigned int PKCS_DigestDecoration<SHA256>::length = sizeof(PKCS_DigestDecoration<SHA256>::decoration);
Expand All @@ -50,6 +53,7 @@ template<> const byte PKCS_DigestDecoration<SHA512>::decoration[] = {0x30,0x51,0
template<> const unsigned int PKCS_DigestDecoration<SHA512>::length = sizeof(PKCS_DigestDecoration<SHA512>::decoration);

template<> const byte EMSA2HashId<SHA>::id = 0x33;
template<> const byte EMSA2HashId<SHA224>::id = 0x38;
template<> const byte EMSA2HashId<SHA256>::id = 0x34;
template<> const byte EMSA2HashId<SHA384>::id = 0x36;
template<> const byte EMSA2HashId<SHA512>::id = 0x35;
Expand All @@ -69,7 +73,7 @@ using std::set_new_handler;
static PNew s_pNew = NULL;
static PDelete s_pDelete = NULL;

static void * CRYPTOPP_CDECL New (size_t size)
static void * New (size_t size)
{
void *p;
while (!(p = malloc(size)))
Expand Down Expand Up @@ -129,25 +133,25 @@ static void SetNewAndDeleteFunctionPointers()
throw 0;
}

void * CRYPTOPP_CDECL operator new (size_t size)
void * operator new (size_t size)
{
if (!s_pNew)
SetNewAndDeleteFunctionPointers();

return s_pNew(size);
}

void CRYPTOPP_CDECL operator delete (void * p)
void operator delete (void * p)
{
s_pDelete(p);
}

void * CRYPTOPP_CDECL operator new [] (size_t size)
void * operator new [] (size_t size)
{
return operator new (size);
}

void CRYPTOPP_CDECL operator delete [] (void * p)
void operator delete [] (void * p)
{
operator delete (p);
}
Expand Down
11 changes: 6 additions & 5 deletions dll.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "pssr.h"
#include "randpool.h"
#include "rsa.h"
#include "rw.h"
#include "sha.h"
#include "skipjack.h"
#include "trdlocal.h"
Expand Down Expand Up @@ -56,11 +57,11 @@ NAMESPACE_BEGIN(CryptoPP)
using std::new_handler;
#endif

typedef void * (CRYPTOPP_CDECL * PNew)(size_t);
typedef void (CRYPTOPP_CDECL * PDelete)(void *);
typedef void (CRYPTOPP_CDECL * PGetNewAndDelete)(PNew &, PDelete &);
typedef new_handler (CRYPTOPP_CDECL * PSetNewHandler)(new_handler);
typedef void (CRYPTOPP_CDECL * PSetNewAndDelete)(PNew, PDelete, PSetNewHandler);
typedef void * (CRYPTOPP_API * PNew)(size_t);
typedef void (CRYPTOPP_API * PDelete)(void *);
typedef void (CRYPTOPP_API * PGetNewAndDelete)(PNew &, PDelete &);
typedef new_handler (CRYPTOPP_API * PSetNewHandler)(new_handler);
typedef void (CRYPTOPP_API * PSetNewAndDelete)(PNew, PDelete, PSetNewHandler);

NAMESPACE_END

Expand Down
Loading

0 comments on commit b3924f2

Please sign in to comment.