From 08c0e260200b3441c43bb529b5dbe7cdff6e37f7 Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Fri, 20 Jan 2017 06:10:14 -0500 Subject: 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 --- eccrypto.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'eccrypto.cpp') diff --git a/eccrypto.cpp b/eccrypto.cpp index c1a9c7e0..133194ea 100644 --- a/eccrypto.cpp +++ b/eccrypto.cpp @@ -586,17 +586,23 @@ template bool DL_GroupParameters_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::ValidateGroup(RandomNumberGenerator &rng, unsign template bool DL_GroupParameters_EC::ValidateElement(unsigned int level, const Element &g, const DL_FixedBasePrecomputation *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; } -- cgit v1.2.1