summaryrefslogtreecommitdiff
path: root/eccrypto.cpp
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2017-01-20 06:10:14 -0500
committerJeffrey Walton <noloader@gmail.com>2017-01-20 06:10:14 -0500
commit08c0e260200b3441c43bb529b5dbe7cdff6e37f7 (patch)
treec84f6549629cb7a69425a7de4af85f02a5563435 /eccrypto.cpp
parent5522e9313369960bc9db1d1a0e0502ba42e7da7e (diff)
downloadcryptopp-git-08c0e260200b3441c43bb529b5dbe7cdff6e37f7.tar.gz
Add CRYPTOPP_ASSERT to Validate routines
Since we switched to CRYPTOPP_ASSERT we don't have to worry about an accidental assert in production. We can now assert ValidateElement and ValidateGroup and let the code warn of potential problems during development. This came about because ECGDSA inadvertently used GetGroupOrder() rather than GetSubgroupOrder(). The assert alerted to the problem area without the need for debugging
Diffstat (limited to 'eccrypto.cpp')
-rw-r--r--eccrypto.cpp16
1 files changed, 15 insertions, 1 deletions
diff --git a/eccrypto.cpp b/eccrypto.cpp
index c1a9c7e0..133194ea 100644
--- a/eccrypto.cpp
+++ b/eccrypto.cpp
@@ -586,17 +586,23 @@ template <class EC>
bool DL_GroupParameters_EC<EC>::ValidateGroup(RandomNumberGenerator &rng, unsigned int level) const
{
bool pass = GetCurve().ValidateParameters(rng, level);
+ CRYPTOPP_ASSERT(pass);
Integer q = GetCurve().FieldSize();
pass = pass && m_n!=q;
+ CRYPTOPP_ASSERT(pass);
if (level >= 2)
{
Integer qSqrt = q.SquareRoot();
pass = pass && m_n>4*qSqrt;
+ CRYPTOPP_ASSERT(pass);
pass = pass && VerifyPrime(rng, m_n, level-2);
+ CRYPTOPP_ASSERT(pass);
pass = pass && (m_k.IsZero() || m_k == (q+2*qSqrt+1)/m_n);
+ CRYPTOPP_ASSERT(pass);
pass = pass && CheckMOVCondition(q, m_n);
+ CRYPTOPP_ASSERT(pass);
}
return pass;
@@ -605,17 +611,25 @@ bool DL_GroupParameters_EC<EC>::ValidateGroup(RandomNumberGenerator &rng, unsign
template <class EC>
bool DL_GroupParameters_EC<EC>::ValidateElement(unsigned int level, const Element &g, const DL_FixedBasePrecomputation<Element> *gpc) const
{
- bool pass = !IsIdentity(g) && GetCurve().VerifyPoint(g);
+ bool pass = !IsIdentity(g);
+ CRYPTOPP_ASSERT(pass);
+ pass = pass && GetCurve().VerifyPoint(g);
+ CRYPTOPP_ASSERT(pass);
+
if (level >= 1)
{
if (gpc)
+ {
pass = pass && gpc->Exponentiate(this->GetGroupPrecomputation(), Integer::One()) == g;
+ CRYPTOPP_ASSERT(pass);
+ }
}
if (level >= 2 && pass)
{
const Integer &q = GetSubgroupOrder();
Element gq = gpc ? gpc->Exponentiate(this->GetGroupPrecomputation(), q) : this->ExponentiateElement(g, q);
pass = pass && IsIdentity(gq);
+ CRYPTOPP_ASSERT(pass);
}
return pass;
}