summaryrefslogtreecommitdiff
path: root/luc.cpp
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2017-01-29 04:58:56 -0500
committerJeffrey Walton <noloader@gmail.com>2017-01-29 04:58:56 -0500
commitb8adc91ce888b94505f383101ed3a2b06e4a70a2 (patch)
treeb544c3450f2216194ba7b5722c3fd07c7c44cbce /luc.cpp
parent7c7e8aa8046ac6689f4a5468842e4333badebc6c (diff)
downloadcryptopp-git-b8adc91ce888b94505f383101ed3a2b06e4a70a2.tar.gz
Add asserts to validation routines
Diffstat (limited to 'luc.cpp')
-rw-r--r--luc.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/luc.cpp b/luc.cpp
index 6abe2e48..c9faca62 100644
--- a/luc.cpp
+++ b/luc.cpp
@@ -74,7 +74,9 @@ bool LUCFunction::Validate(RandomNumberGenerator &rng, unsigned int level) const
CRYPTOPP_UNUSED(rng), CRYPTOPP_UNUSED(level);
bool pass = true;
pass = pass && m_n > Integer::One() && m_n.IsOdd();
+ CRYPTOPP_ASSERT(pass);
pass = pass && m_e > Integer::One() && m_e.IsOdd() && m_e < m_n;
+ CRYPTOPP_ASSERT(pass);
return pass;
}
@@ -177,20 +179,33 @@ Integer InvertibleLUCFunction::CalculateInverse(RandomNumberGenerator &rng, cons
bool InvertibleLUCFunction::Validate(RandomNumberGenerator &rng, unsigned int level) const
{
bool pass = LUCFunction::Validate(rng, level);
+ CRYPTOPP_ASSERT(pass);
pass = pass && m_p > Integer::One() && m_p.IsOdd() && m_p < m_n;
+ CRYPTOPP_ASSERT(pass);
pass = pass && m_q > Integer::One() && m_q.IsOdd() && m_q < m_n;
+ CRYPTOPP_ASSERT(pass);
pass = pass && m_u.IsPositive() && m_u < m_p;
+ CRYPTOPP_ASSERT(pass);
if (level >= 1)
{
pass = pass && m_p * m_q == m_n;
+ CRYPTOPP_ASSERT(pass);
pass = pass && RelativelyPrime(m_e, m_p+1);
+ CRYPTOPP_ASSERT(pass);
pass = pass && RelativelyPrime(m_e, m_p-1);
+ CRYPTOPP_ASSERT(pass);
pass = pass && RelativelyPrime(m_e, m_q+1);
+ CRYPTOPP_ASSERT(pass);
pass = pass && RelativelyPrime(m_e, m_q-1);
+ CRYPTOPP_ASSERT(pass);
pass = pass && m_u * m_q % m_p == 1;
+ CRYPTOPP_ASSERT(pass);
}
if (level >= 2)
+ {
pass = pass && VerifyPrime(rng, m_p, level-2) && VerifyPrime(rng, m_q, level-2);
+ CRYPTOPP_ASSERT(pass);
+ }
return pass;
}