Updated CRYPTOPP_ASSERT based on comments

Also see 399a1546de (commitcomment-19448453)
pull/326/head
Jeffrey Walton 2016-10-17 22:00:31 -04:00
parent b7423a3bf7
commit 54d17c7361
No known key found for this signature in database
GPG Key ID: B36AB348921B1838
29 changed files with 76 additions and 82 deletions

View File

@ -7,7 +7,7 @@
NAMESPACE_BEGIN(CryptoPP)
#if CRYPTOPP_DEBUG && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
#if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
void ThreeWay_TestInstantiations()
{
ThreeWay::Encryption x1;

View File

@ -13,7 +13,7 @@
NAMESPACE_BEGIN(CryptoPP)
namespace Weak1 {
#if CRYPTOPP_DEBUG && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
#if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
void ARC4_TestInstantiations()
{
ARC4 x;

View File

@ -18,7 +18,7 @@ NAMESPACE_BEGIN(CryptoPP)
a += b; d ^= a; d = rotlFixed<word32>(d, 8); \
c += d; b ^= c; b = rotlFixed<word32>(b, 7);
#if CRYPTOPP_DEBUG && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
#if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
void ChaCha_TestInstantiations()
{
ChaCha8::Encryption x1;

2
dh.cpp
View File

@ -8,7 +8,7 @@
NAMESPACE_BEGIN(CryptoPP)
#if CRYPTOPP_DEBUG && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
#if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
void DH_TestInstantiations()
{
DH dh1;

View File

@ -5,7 +5,7 @@
NAMESPACE_BEGIN(CryptoPP)
#if CRYPTOPP_DEBUG && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
#if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
void DH2_TestInstantiations()
{
DH2 dh(*(SimpleKeyAgreementDomain*)NULL);

28
ec2n.h
View File

@ -21,21 +21,21 @@ NAMESPACE_BEGIN(CryptoPP)
//! Elliptic Curve Point
struct CRYPTOPP_DLL EC2NPoint
{
#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
virtual ~EC2NPoint() {}
#endif
EC2NPoint() : identity(true) {}
EC2NPoint(const PolynomialMod2 &x, const PolynomialMod2 &y)
: identity(false), x(x), y(y) {}
: x(x), y(y), identity(false) {}
bool operator==(const EC2NPoint &t) const
{return (identity && t.identity) || (!identity && !t.identity && x==t.x && y==t.y);}
bool operator< (const EC2NPoint &t) const
{return identity ? !t.identity : (!t.identity && (x<t.x || (x==t.x && y<t.y)));}
#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
virtual ~EC2NPoint() {}
#endif
bool identity;
PolynomialMod2 x, y;
bool identity;
};
CRYPTOPP_DLL_TEMPLATE_CLASS AbstractGroup<EC2NPoint>;
@ -48,6 +48,10 @@ public:
typedef Field::Element FieldElement;
typedef EC2NPoint Point;
#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
virtual ~EC2N() {}
#endif
EC2N() {}
EC2N(const Field &field, const Field::Element &a, const Field::Element &b)
: m_field(field), m_a(a), m_b(b) {}
@ -92,10 +96,6 @@ public:
bool operator==(const EC2N &rhs) const
{return GetField() == rhs.GetField() && m_a == rhs.m_a && m_b == rhs.m_b;}
#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
virtual ~EC2N() {}
#endif
private:
clonable_ptr<Field> m_field;
FieldElement m_a, m_b;
@ -113,6 +113,10 @@ template<> class EcPrecomputation<EC2N> : public DL_GroupPrecomputation<EC2N::Po
public:
typedef EC2N EllipticCurve;
#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
virtual ~EcPrecomputation() {}
#endif
// DL_GroupPrecomputation
const AbstractGroup<Element> & GetGroup() const {return m_ec;}
Element BERDecodeElement(BufferedTransformation &bt) const {return m_ec.BERDecodePoint(bt);}
@ -122,10 +126,6 @@ public:
void SetCurve(const EC2N &ec) {m_ec = ec;}
const EC2N & GetCurve() const {return m_ec;}
#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
virtual ~EcPrecomputation() {}
#endif
private:
EC2N m_ec;
};

View File

@ -31,7 +31,7 @@
NAMESPACE_BEGIN(CryptoPP)
#if 0
#if CRYPTOPP_DEBUG && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
#if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
static void ECDSA_TestInstantiations()
{
ECDSA<EC2N>::Signer t1;

View File

@ -38,6 +38,10 @@ public:
typedef Point Element;
typedef IncompatibleCofactorMultiplication DefaultCofactorOption;
#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
virtual ~DL_GroupParameters_EC() {}
#endif
DL_GroupParameters_EC() : m_compress(false), m_encodeAsOID(true) {}
DL_GroupParameters_EC(const OID &oid)
: m_compress(false), m_encodeAsOID(true) {Initialize(oid);}
@ -133,10 +137,6 @@ public:
void LoadRecommendedParameters(const OID &oid) {Initialize(oid);}
#endif
#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
virtual ~DL_GroupParameters_EC() {}
#endif
protected:
unsigned int FieldElementLength() const {return GetCurve().GetField().MaxElementByteLength();}
unsigned int ExponentLength() const {return m_n.ByteCount();}
@ -154,6 +154,10 @@ class DL_PublicKey_EC : public DL_PublicKeyImpl<DL_GroupParameters_EC<EC> >
public:
typedef typename EC::Point Element;
#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
virtual ~DL_PublicKey_EC() {}
#endif
void Initialize(const DL_GroupParameters_EC<EC> &params, const Element &Q)
{this->AccessGroupParameters() = params; this->SetPublicElement(Q);}
void Initialize(const EC &ec, const Element &G, const Integer &n, const Element &Q)
@ -162,10 +166,6 @@ public:
// X509PublicKey
void BERDecodePublicKey(BufferedTransformation &bt, bool parametersPresent, size_t size);
void DEREncodePublicKey(BufferedTransformation &bt) const;
#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
virtual ~DL_PublicKey_EC() {}
#endif
};
//! EC private key
@ -175,6 +175,10 @@ class DL_PrivateKey_EC : public DL_PrivateKeyImpl<DL_GroupParameters_EC<EC> >
public:
typedef typename EC::Point Element;
#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
virtual ~DL_PrivateKey_EC() {}
#endif
void Initialize(const DL_GroupParameters_EC<EC> &params, const Integer &x)
{this->AccessGroupParameters() = params; this->SetPrivateExponent(x);}
void Initialize(const EC &ec, const Element &G, const Integer &n, const Integer &x)
@ -187,10 +191,6 @@ public:
// PKCS8PrivateKey
void BERDecodePrivateKey(BufferedTransformation &bt, bool parametersPresent, size_t size);
void DEREncodePrivateKey(BufferedTransformation &bt) const;
#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
virtual ~DL_PrivateKey_EC() {}
#endif
};
//! Elliptic Curve Diffie-Hellman, AKA <a href="http://www.weidai.com/scan-mirror/ka.html#ECDH">ECDH</a>
@ -340,13 +340,7 @@ struct ECIES
virtual ~ECIES() {}
#endif
#if (CRYPTOPP_GCC_VERSION >= 40500) || (CRYPTOPP_LLVM_CLANG_VERSION >= 20800)
} __attribute__((deprecated ("ECIES will be changing in the near future due to (1) an implementation bug and (2) an interop issue")));
#elif (CRYPTOPP_GCC_VERSION)
} __attribute__((deprecated));
#else
};
#endif
} CRYPTOPP_DEPRECATED ("ECIES will be changing in the near future due to an interop issue");
NAMESPACE_END

28
ecp.h
View File

@ -19,21 +19,21 @@ NAMESPACE_BEGIN(CryptoPP)
//! Elliptical Curve Point
struct CRYPTOPP_DLL ECPPoint
{
#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
virtual ~ECPPoint() {}
#endif
ECPPoint() : identity(true) {}
ECPPoint(const Integer &x, const Integer &y)
: identity(false), x(x), y(y) {}
: x(x), y(y), identity(false) {}
bool operator==(const ECPPoint &t) const
{return (identity && t.identity) || (!identity && !t.identity && x==t.x && y==t.y);}
bool operator< (const ECPPoint &t) const
{return identity ? !t.identity : (!t.identity && (x<t.x || (x==t.x && y<t.y)));}
#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
virtual ~ECPPoint() {}
#endif
bool identity;
Integer x, y;
bool identity;
};
CRYPTOPP_DLL_TEMPLATE_CLASS AbstractGroup<ECPPoint>;
@ -46,6 +46,10 @@ public:
typedef Integer FieldElement;
typedef ECPPoint Point;
#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
virtual ~ECP() {}
#endif
ECP() {}
ECP(const ECP &ecp, bool convertToMontgomeryRepresentation = false);
ECP(const Integer &modulus, const FieldElement &a, const FieldElement &b)
@ -94,10 +98,6 @@ public:
bool operator==(const ECP &rhs) const
{return GetField() == rhs.GetField() && m_a == rhs.m_a && m_b == rhs.m_b;}
#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
virtual ~ECP() {}
#endif
private:
clonable_ptr<Field> m_fieldPtr;
FieldElement m_a, m_b;
@ -115,6 +115,10 @@ template<> class EcPrecomputation<ECP> : public DL_GroupPrecomputation<ECP::Poin
public:
typedef ECP EllipticCurve;
#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
virtual ~EcPrecomputation() {}
#endif
// DL_GroupPrecomputation
bool NeedConversions() const {return true;}
Element ConvertIn(const Element &P) const
@ -133,10 +137,6 @@ public:
}
const ECP & GetCurve() const {return *m_ecOriginal;}
#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
virtual ~EcPrecomputation() {}
#endif
private:
value_ptr<ECP> m_ec, m_ecOriginal;
};

View File

@ -7,7 +7,7 @@
NAMESPACE_BEGIN(CryptoPP)
#if CRYPTOPP_DEBUG && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
#if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
void ElGamal_TestInstantiations()
{
ElGamalEncryptor test1(1, 1, 1);

View File

@ -18,7 +18,7 @@
NAMESPACE_BEGIN(CryptoPP)
#if CRYPTOPP_DEBUG && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
#if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
void ESIGN_TestInstantiations()
{
ESIGN<SHA>::Verifier x1(1, 1);

View File

@ -10,7 +10,7 @@
NAMESPACE_BEGIN(CryptoPP)
#if CRYPTOPP_DEBUG && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
#if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
void Files_TestInstantiations()
{
FileStore f0;

View File

@ -325,7 +325,7 @@ PolynomialMod2 PolynomialMod2::Modulo(const PolynomialMod2 &b) const
PolynomialMod2& PolynomialMod2::operator<<=(unsigned int n)
{
#if CRYPTOPP_DEBUG
#if defined(CRYPTOPP_DEBUG)
int x; CRYPTOPP_UNUSED(x);
CRYPTOPP_ASSERT(SafeConvert(n,x));
#endif

View File

@ -20,7 +20,7 @@
NAMESPACE_BEGIN(CryptoPP)
#if CRYPTOPP_DEBUG && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
#if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
void TestInstantiations_gfpcrypt()
{
GDSA<SHA>::Signer test;

View File

@ -2637,7 +2637,7 @@ static inline void AtomicDivide(word *Q, const word *A, const word *B)
Q[1] = SubatomicDivide(T+1, B[0], B[1]);
Q[0] = SubatomicDivide(T, B[0], B[1]);
#if CRYPTOPP_DEBUG
#if defined(CRYPTOPP_DEBUG)
// multiply quotient and divisor and add remainder, make sure it equals dividend
CRYPTOPP_ASSERT(!T[2] && !T[3] && (T[1] < B[1] || (T[1]==B[1] && T[0]<B[0])));
word P[4];
@ -2656,7 +2656,7 @@ static inline void AtomicDivide(word *Q, const word *A, const word *B)
Q[0] = q.GetLowHalf();
Q[1] = q.GetHighHalf();
#if CRYPTOPP_DEBUG
#if defined(CRYPTOPP_DEBUG)
if (B[0] || B[1])
{
// multiply quotient and divisor and add remainder, make sure it equals dividend

View File

@ -10,7 +10,7 @@
NAMESPACE_BEGIN(CryptoPP)
#if CRYPTOPP_DEBUG && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
#if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
void LUC_TestInstantiations()
{
LUC_HMP<SHA>::Signer t1;

View File

@ -9,7 +9,7 @@
NAMESPACE_BEGIN(CryptoPP)
namespace Weak1 {
#if CRYPTOPP_DEBUG && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
#if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
void MD5_TestInstantiations()
{
MD5 x;

View File

@ -7,13 +7,13 @@
#include "modes.h"
#include "misc.h"
//#if CRYPTOPP_DEBUG
#if defined(CRYPTOPP_DEBUG)
#include "des.h"
//#endif
#endif
NAMESPACE_BEGIN(CryptoPP)
#if CRYPTOPP_DEBUG && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
#if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
void Modes_TestInstantiations()
{
CFB_Mode<DES>::Encryption m0;

View File

@ -9,7 +9,7 @@
NAMESPACE_BEGIN(CryptoPP)
#if CRYPTOPP_DEBUG && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
#if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
void TestInstantiations_MQV()
{
MQV mqv;

View File

@ -10,7 +10,7 @@
#include "algparam.h"
#include "fips140.h"
#if CRYPTOPP_DEBUG && !defined(CRYPTOPP_DOXYGEN_PROCESSING) && !defined(CRYPTOPP_IS_DLL)
#if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING) && !defined(CRYPTOPP_IS_DLL)
#include "pssr.h"
NAMESPACE_BEGIN(CryptoPP)
void RSA_TestInstantiations()

View File

@ -32,7 +32,7 @@
NAMESPACE_BEGIN(CryptoPP)
#if CRYPTOPP_DEBUG && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
#if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
void Salsa20_TestInstantiations()
{
Salsa20::Encryption x1;

View File

@ -10,7 +10,7 @@
NAMESPACE_BEGIN(CryptoPP)
#if CRYPTOPP_DEBUG && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
#if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
void SEAL_TestInstantiations()
{
SEAL<>::Encryption x;

View File

@ -126,7 +126,7 @@ RandomNumberGenerator & GlobalRNG()
}
// See misc.h and trap.h for comments and usage
#if CRYPTOPP_DEBUG && defined(UNIX_SIGNALS_AVAILABLE)
#if defined(CRYPTOPP_DEBUG) && defined(UNIX_SIGNALS_AVAILABLE)
static const SignalHandler<SIGTRAP, false> s_dummyHandler;
// static const DebugTrapHandler s_dummyHandler;
#endif

10
trap.h
View File

@ -18,7 +18,7 @@
#include "config.h"
#if CRYPTOPP_DEBUG
#if defined(CRYPTOPP_DEBUG)
# include <iostream>
# include <sstream>
# if defined(UNIX_SIGNALS_AVAILABLE)
@ -46,7 +46,7 @@
//! \details An example of using \ref CRYPTOPP_ASSERT "CRYPTOPP_ASSERT" and DebugTrapHandler is shown below. The library's
//! test program, <tt>cryptest.exe</tt> (from test.cpp), exercises the structure:
//! <pre>
//! #if CRYPTOPP_DEBUG && (defined(CRYPTOPP_BSD_AVAILABLE) || defined(CRYPTOPP_UNIX_AVAILABLE))
//! #if defined(CRYPTOPP_DEBUG) && defined(UNIX_SIGNALS_AVAILABLE)
//! static const DebugTrapHandler g_dummyHandler;
//! #endif
//!
@ -62,7 +62,7 @@
# define CRYPTOPP_ASSERT(exp) { ... }
#endif
#if CRYPTOPP_DEBUG && defined(UNIX_SIGNALS_AVAILABLE)
#if defined(CRYPTOPP_DEBUG) && defined(UNIX_SIGNALS_AVAILABLE)
# define CRYPTOPP_ASSERT(exp) { \
if (!(exp)) { \
std::ostringstream oss; \
@ -89,7 +89,7 @@
// Remove CRYPTOPP_ASSERT in non-debug builds.
// Can't use CRYPTOPP_UNUSED due to circular dependency
#ifndef CRYPTOPP_ASSERT
# define CRYPTOPP_ASSERT(exp) ((void)(exp))
# define CRYPTOPP_ASSERT(exp) ((void)0)
#endif
NAMESPACE_BEGIN(CryptoPP)
@ -119,7 +119,7 @@ NAMESPACE_BEGIN(CryptoPP)
//! \details An example of using \ref CRYPTOPP_ASSERT "CRYPTOPP_ASSERT" and DebugTrapHandler is shown below. The library's
//! test program, <tt>cryptest.exe</tt> (from test.cpp), exercises the structure:
//! <pre>
//! #if CRYPTOPP_DEBUG && (defined(CRYPTOPP_BSD_AVAILABLE) || defined(CRYPTOPP_UNIX_AVAILABLE))
//! #if defined(CRYPTOPP_DEBUG) && defined(UNIX_SIGNALS_AVAILABLE)
//! static const DebugTrapHandler g_dummyHandler;
//! #endif
//!

View File

@ -78,7 +78,7 @@ bool ValidateAll(bool thorough)
pass=TestRDSEED() && pass;
#endif
#if CRYPTOPP_DEBUG && !defined(CRYPTOPP_IMPORTS)
#if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_IMPORTS)
// http://github.com/weidai11/cryptopp/issues/92
pass=TestSecBlock() && pass;
// http://github.com/weidai11/cryptopp/issues/64
@ -330,7 +330,7 @@ bool TestSettings()
return pass;
}
#if CRYPTOPP_DEBUG && !defined(CRYPTOPP_IMPORTS)
#if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_IMPORTS)
bool TestSecBlock()
{
cout << "\nTesting SecBlock...\n\n";
@ -1264,7 +1264,7 @@ bool TestSecBlock()
}
#endif
#if CRYPTOPP_DEBUG && !defined(CRYPTOPP_IMPORTS)
#if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_IMPORTS)
bool TestHuffmanCodes()
{
cout << "\nTesting Huffman codes...\n\n";

View File

@ -794,7 +794,7 @@ bool ValidateBlumGoldwasser()
}
*/
#if CRYPTOPP_DEBUG && !defined(CRYPTOPP_IMPORTS)
#if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_IMPORTS)
// Issue 64: "PolynomialMod2::operator<<=", http://github.com/weidai11/cryptopp/issues/64
bool TestPolynomialMod2()
{

View File

@ -90,7 +90,7 @@ bool ValidateEC2N();
bool ValidateECDSA();
bool ValidateESIGN();
#if CRYPTOPP_DEBUG
#if defined(CRYPTOPP_DEBUG)
bool TestSecBlock();
bool TestPolynomialMod2();
bool TestHuffmanCodes();

View File

@ -7,7 +7,7 @@
NAMESPACE_BEGIN(CryptoPP)
#if CRYPTOPP_DEBUG && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
#if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
void WAKE_TestInstantiations()
{
WAKE_OFB<>::Encryption x2;

View File

@ -85,7 +85,7 @@
NAMESPACE_BEGIN(CryptoPP)
#if CRYPTOPP_DEBUG && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
#if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
void Whirlpool_TestInstantiations()
{
Whirlpool x;