Skip to content

Commit

Permalink
Updated CRYPTOPP_ASSERT based on comments
Browse files Browse the repository at this point in the history
  • Loading branch information
noloader committed Oct 18, 2016
1 parent b7423a3 commit 54d17c7
Show file tree
Hide file tree
Showing 29 changed files with 76 additions and 82 deletions.
2 changes: 1 addition & 1 deletion 3way.cpp
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion arc4.cpp
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion chacha.cpp
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion dh.cpp
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion dh2.cpp
Expand Up @@ -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);
Expand Down
28 changes: 14 additions & 14 deletions ec2n.h
Expand Up @@ -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>;
Expand All @@ -48,6 +48,10 @@ class CRYPTOPP_DLL EC2N : public AbstractGroup<EC2NPoint>
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) {}
Expand Down Expand Up @@ -92,10 +96,6 @@ class CRYPTOPP_DLL EC2N : public AbstractGroup<EC2NPoint>
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;
Expand All @@ -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);}
Expand All @@ -122,10 +126,6 @@ template<> class EcPrecomputation<EC2N> : public DL_GroupPrecomputation<EC2N::Po
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;
};
Expand Down
2 changes: 1 addition & 1 deletion eccrypto.cpp
Expand Up @@ -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;
Expand Down
32 changes: 13 additions & 19 deletions eccrypto.h
Expand Up @@ -38,6 +38,10 @@ class DL_GroupParameters_EC : public DL_GroupParametersImpl<EcPrecomputation<EC>
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);}
Expand Down Expand Up @@ -133,10 +137,6 @@ class DL_GroupParameters_EC : public DL_GroupParametersImpl<EcPrecomputation<EC>
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();}
Expand All @@ -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)
Expand All @@ -162,10 +166,6 @@ class DL_PublicKey_EC : public DL_PublicKeyImpl<DL_GroupParameters_EC<EC> >
// 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
Expand All @@ -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)
Expand All @@ -187,10 +191,6 @@ class DL_PrivateKey_EC : public DL_PrivateKeyImpl<DL_GroupParameters_EC<EC> >
// 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>
Expand Down Expand Up @@ -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

Expand Down
28 changes: 14 additions & 14 deletions ecp.h
Expand Up @@ -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>;
Expand All @@ -46,6 +46,10 @@ class CRYPTOPP_DLL ECP : public AbstractGroup<ECPPoint>
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)
Expand Down Expand Up @@ -94,10 +98,6 @@ class CRYPTOPP_DLL ECP : public AbstractGroup<ECPPoint>
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;
Expand All @@ -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
Expand All @@ -133,10 +137,6 @@ template<> class EcPrecomputation<ECP> : public DL_GroupPrecomputation<ECP::Poin
}
const ECP & GetCurve() const {return *m_ecOriginal;}

#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
virtual ~EcPrecomputation() {}
#endif

private:
value_ptr<ECP> m_ec, m_ecOriginal;
};
Expand Down
2 changes: 1 addition & 1 deletion elgamal.cpp
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion esign.cpp
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion files.cpp
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion gf2n.cpp
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion gfpcrypt.cpp
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions integer.cpp
Expand Up @@ -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];
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion luc.cpp
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion md5.cpp
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions modes.cpp
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion mqv.cpp
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion rsa.cpp
Expand Up @@ -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()
Expand Down

1 comment on commit 54d17c7

@noloader
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also see comments on Commit 399a1546de71.

Please sign in to comment.