mirror of
https://github.com/shadps4-emu/ext-cryptopp.git
synced 2024-11-26 19:30:21 +00:00
Add asserts to validation routines
This commit is contained in:
parent
7c7e8aa804
commit
b8adc91ce8
12
esign.cpp
12
esign.cpp
@ -61,7 +61,9 @@ bool ESIGNFunction::Validate(RandomNumberGenerator& rng, unsigned int level) con
|
|||||||
CRYPTOPP_UNUSED(rng), CRYPTOPP_UNUSED(level);
|
CRYPTOPP_UNUSED(rng), CRYPTOPP_UNUSED(level);
|
||||||
bool pass = true;
|
bool pass = true;
|
||||||
pass = pass && m_n > Integer::One() && m_n.IsOdd();
|
pass = pass && m_n > Integer::One() && m_n.IsOdd();
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
pass = pass && m_e >= 8 && m_e < m_n;
|
pass = pass && m_e >= 8 && m_e < m_n;
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
return pass;
|
return pass;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,13 +194,23 @@ Integer InvertibleESIGNFunction::CalculateRandomizedInverse(RandomNumberGenerato
|
|||||||
bool InvertibleESIGNFunction::Validate(RandomNumberGenerator &rng, unsigned int level) const
|
bool InvertibleESIGNFunction::Validate(RandomNumberGenerator &rng, unsigned int level) const
|
||||||
{
|
{
|
||||||
bool pass = ESIGNFunction::Validate(rng, level);
|
bool pass = ESIGNFunction::Validate(rng, level);
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
pass = pass && m_p > Integer::One() && m_p.IsOdd() && m_p < m_n;
|
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;
|
pass = pass && m_q > Integer::One() && m_q.IsOdd() && m_q < m_n;
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
pass = pass && m_p.BitCount() == m_q.BitCount();
|
pass = pass && m_p.BitCount() == m_q.BitCount();
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
if (level >= 1)
|
if (level >= 1)
|
||||||
|
{
|
||||||
pass = pass && m_p * m_p * m_q == m_n;
|
pass = pass && m_p * m_p * m_q == m_n;
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
|
}
|
||||||
if (level >= 2)
|
if (level >= 2)
|
||||||
|
{
|
||||||
pass = pass && VerifyPrime(rng, m_p, level-2) && VerifyPrime(rng, m_q, level-2);
|
pass = pass && VerifyPrime(rng, m_p, level-2) && VerifyPrime(rng, m_q, level-2);
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
|
}
|
||||||
return pass;
|
return pass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
15
luc.cpp
15
luc.cpp
@ -74,7 +74,9 @@ bool LUCFunction::Validate(RandomNumberGenerator &rng, unsigned int level) const
|
|||||||
CRYPTOPP_UNUSED(rng), CRYPTOPP_UNUSED(level);
|
CRYPTOPP_UNUSED(rng), CRYPTOPP_UNUSED(level);
|
||||||
bool pass = true;
|
bool pass = true;
|
||||||
pass = pass && m_n > Integer::One() && m_n.IsOdd();
|
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;
|
pass = pass && m_e > Integer::One() && m_e.IsOdd() && m_e < m_n;
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
return pass;
|
return pass;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,20 +179,33 @@ Integer InvertibleLUCFunction::CalculateInverse(RandomNumberGenerator &rng, cons
|
|||||||
bool InvertibleLUCFunction::Validate(RandomNumberGenerator &rng, unsigned int level) const
|
bool InvertibleLUCFunction::Validate(RandomNumberGenerator &rng, unsigned int level) const
|
||||||
{
|
{
|
||||||
bool pass = LUCFunction::Validate(rng, level);
|
bool pass = LUCFunction::Validate(rng, level);
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
pass = pass && m_p > Integer::One() && m_p.IsOdd() && m_p < m_n;
|
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;
|
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;
|
pass = pass && m_u.IsPositive() && m_u < m_p;
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
if (level >= 1)
|
if (level >= 1)
|
||||||
{
|
{
|
||||||
pass = pass && m_p * m_q == m_n;
|
pass = pass && m_p * m_q == m_n;
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
pass = pass && RelativelyPrime(m_e, m_p+1);
|
pass = pass && RelativelyPrime(m_e, m_p+1);
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
pass = pass && RelativelyPrime(m_e, m_p-1);
|
pass = pass && RelativelyPrime(m_e, m_p-1);
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
pass = pass && RelativelyPrime(m_e, m_q+1);
|
pass = pass && RelativelyPrime(m_e, m_q+1);
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
pass = pass && RelativelyPrime(m_e, m_q-1);
|
pass = pass && RelativelyPrime(m_e, m_q-1);
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
pass = pass && m_u * m_q % m_p == 1;
|
pass = pass && m_u * m_q % m_p == 1;
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
}
|
}
|
||||||
if (level >= 2)
|
if (level >= 2)
|
||||||
|
{
|
||||||
pass = pass && VerifyPrime(rng, m_p, level-2) && VerifyPrime(rng, m_q, level-2);
|
pass = pass && VerifyPrime(rng, m_p, level-2) && VerifyPrime(rng, m_q, level-2);
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
|
}
|
||||||
return pass;
|
return pass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
19
rabin.cpp
19
rabin.cpp
@ -44,10 +44,16 @@ bool RabinFunction::Validate(RandomNumberGenerator& /*rng*/, unsigned int level)
|
|||||||
{
|
{
|
||||||
bool pass = true;
|
bool pass = true;
|
||||||
pass = pass && m_n > Integer::One() && m_n%4 == 1;
|
pass = pass && m_n > Integer::One() && m_n%4 == 1;
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
pass = pass && m_r > Integer::One() && m_r < m_n;
|
pass = pass && m_r > Integer::One() && m_r < m_n;
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
pass = pass && m_s > Integer::One() && m_s < m_n;
|
pass = pass && m_s > Integer::One() && m_s < m_n;
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
if (level >= 1)
|
if (level >= 1)
|
||||||
|
{
|
||||||
pass = pass && Jacobi(m_r, m_n) == -1 && Jacobi(m_s, m_n) == -1;
|
pass = pass && Jacobi(m_r, m_n) == -1 && Jacobi(m_s, m_n) == -1;
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
|
}
|
||||||
return pass;
|
return pass;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,20 +190,33 @@ Integer InvertibleRabinFunction::CalculateInverse(RandomNumberGenerator &rng, co
|
|||||||
bool InvertibleRabinFunction::Validate(RandomNumberGenerator &rng, unsigned int level) const
|
bool InvertibleRabinFunction::Validate(RandomNumberGenerator &rng, unsigned int level) const
|
||||||
{
|
{
|
||||||
bool pass = RabinFunction::Validate(rng, level);
|
bool pass = RabinFunction::Validate(rng, level);
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
pass = pass && m_p > Integer::One() && m_p%4 == 3 && m_p < m_n;
|
pass = pass && m_p > Integer::One() && m_p%4 == 3 && m_p < m_n;
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
pass = pass && m_q > Integer::One() && m_q%4 == 3 && m_q < m_n;
|
pass = pass && m_q > Integer::One() && m_q%4 == 3 && m_q < m_n;
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
pass = pass && m_u.IsPositive() && m_u < m_p;
|
pass = pass && m_u.IsPositive() && m_u < m_p;
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
if (level >= 1)
|
if (level >= 1)
|
||||||
{
|
{
|
||||||
pass = pass && m_p * m_q == m_n;
|
pass = pass && m_p * m_q == m_n;
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
pass = pass && m_u * m_q % m_p == 1;
|
pass = pass && m_u * m_q % m_p == 1;
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
pass = pass && Jacobi(m_r, m_p) == 1;
|
pass = pass && Jacobi(m_r, m_p) == 1;
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
pass = pass && Jacobi(m_r, m_q) == -1;
|
pass = pass && Jacobi(m_r, m_q) == -1;
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
pass = pass && Jacobi(m_s, m_p) == -1;
|
pass = pass && Jacobi(m_s, m_p) == -1;
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
pass = pass && Jacobi(m_s, m_q) == 1;
|
pass = pass && Jacobi(m_s, m_q) == 1;
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
}
|
}
|
||||||
if (level >= 2)
|
if (level >= 2)
|
||||||
|
{
|
||||||
pass = pass && VerifyPrime(rng, m_p, level-2) && VerifyPrime(rng, m_q, level-2);
|
pass = pass && VerifyPrime(rng, m_p, level-2) && VerifyPrime(rng, m_q, level-2);
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
|
}
|
||||||
return pass;
|
return pass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
16
rsa.cpp
16
rsa.cpp
@ -73,7 +73,9 @@ bool RSAFunction::Validate(RandomNumberGenerator& rng, unsigned int level) const
|
|||||||
|
|
||||||
bool pass = true;
|
bool pass = true;
|
||||||
pass = pass && m_n > Integer::One() && m_n.IsOdd();
|
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;
|
pass = pass && m_e > Integer::One() && m_e.IsOdd() && m_e < m_n;
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
return pass;
|
return pass;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -247,21 +249,35 @@ Integer InvertibleRSAFunction::CalculateInverse(RandomNumberGenerator &rng, cons
|
|||||||
bool InvertibleRSAFunction::Validate(RandomNumberGenerator &rng, unsigned int level) const
|
bool InvertibleRSAFunction::Validate(RandomNumberGenerator &rng, unsigned int level) const
|
||||||
{
|
{
|
||||||
bool pass = RSAFunction::Validate(rng, level);
|
bool pass = RSAFunction::Validate(rng, level);
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
pass = pass && m_p > Integer::One() && m_p.IsOdd() && m_p < m_n;
|
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;
|
pass = pass && m_q > Integer::One() && m_q.IsOdd() && m_q < m_n;
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
pass = pass && m_d > Integer::One() && m_d.IsOdd() && m_d < m_n;
|
pass = pass && m_d > Integer::One() && m_d.IsOdd() && m_d < m_n;
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
pass = pass && m_dp > Integer::One() && m_dp.IsOdd() && m_dp < m_p;
|
pass = pass && m_dp > Integer::One() && m_dp.IsOdd() && m_dp < m_p;
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
pass = pass && m_dq > Integer::One() && m_dq.IsOdd() && m_dq < m_q;
|
pass = pass && m_dq > Integer::One() && m_dq.IsOdd() && m_dq < m_q;
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
pass = pass && m_u.IsPositive() && m_u < m_p;
|
pass = pass && m_u.IsPositive() && m_u < m_p;
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
if (level >= 1)
|
if (level >= 1)
|
||||||
{
|
{
|
||||||
pass = pass && m_p * m_q == m_n;
|
pass = pass && m_p * m_q == m_n;
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
pass = pass && m_e*m_d % LCM(m_p-1, m_q-1) == 1;
|
pass = pass && m_e*m_d % LCM(m_p-1, m_q-1) == 1;
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
pass = pass && m_dp == m_d%(m_p-1) && m_dq == m_d%(m_q-1);
|
pass = pass && m_dp == m_d%(m_p-1) && m_dq == m_d%(m_q-1);
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
pass = pass && m_u * m_q % m_p == 1;
|
pass = pass && m_u * m_q % m_p == 1;
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
}
|
}
|
||||||
if (level >= 2)
|
if (level >= 2)
|
||||||
|
{
|
||||||
pass = pass && VerifyPrime(rng, m_p, level-2) && VerifyPrime(rng, m_q, level-2);
|
pass = pass && VerifyPrime(rng, m_p, level-2) && VerifyPrime(rng, m_q, level-2);
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
|
}
|
||||||
return pass;
|
return pass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
rsa.h
2
rsa.h
@ -115,7 +115,7 @@ public:
|
|||||||
|
|
||||||
// GeneratableCryptoMaterial
|
// GeneratableCryptoMaterial
|
||||||
bool Validate(RandomNumberGenerator &rng, unsigned int level) const;
|
bool Validate(RandomNumberGenerator &rng, unsigned int level) const;
|
||||||
/*! parameters: (ModulusSize, PublicExponent (default 17)) */
|
// parameters: (ModulusSize, PublicExponent (default 17))
|
||||||
void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg);
|
void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg);
|
||||||
bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const;
|
bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const;
|
||||||
void AssignFrom(const NameValuePairs &source);
|
void AssignFrom(const NameValuePairs &source);
|
||||||
|
10
rw.cpp
10
rw.cpp
@ -75,6 +75,7 @@ bool RWFunction::Validate(RandomNumberGenerator &rng, unsigned int level) const
|
|||||||
CRYPTOPP_UNUSED(rng), CRYPTOPP_UNUSED(level);
|
CRYPTOPP_UNUSED(rng), CRYPTOPP_UNUSED(level);
|
||||||
bool pass = true;
|
bool pass = true;
|
||||||
pass = pass && m_n > Integer::One() && m_n%8 == 5;
|
pass = pass && m_n > Integer::One() && m_n%8 == 5;
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
return pass;
|
return pass;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -252,16 +253,25 @@ Integer InvertibleRWFunction::CalculateInverse(RandomNumberGenerator &rng, const
|
|||||||
bool InvertibleRWFunction::Validate(RandomNumberGenerator &rng, unsigned int level) const
|
bool InvertibleRWFunction::Validate(RandomNumberGenerator &rng, unsigned int level) const
|
||||||
{
|
{
|
||||||
bool pass = RWFunction::Validate(rng, level);
|
bool pass = RWFunction::Validate(rng, level);
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
pass = pass && m_p > Integer::One() && m_p%8 == 3 && m_p < m_n;
|
pass = pass && m_p > Integer::One() && m_p%8 == 3 && m_p < m_n;
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
pass = pass && m_q > Integer::One() && m_q%8 == 7 && m_q < m_n;
|
pass = pass && m_q > Integer::One() && m_q%8 == 7 && m_q < m_n;
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
pass = pass && m_u.IsPositive() && m_u < m_p;
|
pass = pass && m_u.IsPositive() && m_u < m_p;
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
if (level >= 1)
|
if (level >= 1)
|
||||||
{
|
{
|
||||||
pass = pass && m_p * m_q == m_n;
|
pass = pass && m_p * m_q == m_n;
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
pass = pass && m_u * m_q % m_p == 1;
|
pass = pass && m_u * m_q % m_p == 1;
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
}
|
}
|
||||||
if (level >= 2)
|
if (level >= 2)
|
||||||
|
{
|
||||||
pass = pass && VerifyPrime(rng, m_p, level-2) && VerifyPrime(rng, m_q, level-2);
|
pass = pass && VerifyPrime(rng, m_p, level-2) && VerifyPrime(rng, m_q, level-2);
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
|
}
|
||||||
return pass;
|
return pass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
10
xtrcrypt.cpp
10
xtrcrypt.cpp
@ -45,16 +45,26 @@ bool XTR_DH::Validate(RandomNumberGenerator &rng, unsigned int level) const
|
|||||||
{
|
{
|
||||||
bool pass = true;
|
bool pass = true;
|
||||||
pass = pass && m_p > Integer::One() && m_p.IsOdd();
|
pass = pass && m_p > Integer::One() && m_p.IsOdd();
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
pass = pass && m_q > Integer::One() && m_q.IsOdd();
|
pass = pass && m_q > Integer::One() && m_q.IsOdd();
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
GFP2Element three = GFP2_ONB<ModularArithmetic>(m_p).ConvertIn(3);
|
GFP2Element three = GFP2_ONB<ModularArithmetic>(m_p).ConvertIn(3);
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
pass = pass && !(m_g.c1.IsNegative() || m_g.c2.IsNegative() || m_g.c1 >= m_p || m_g.c2 >= m_p || m_g == three);
|
pass = pass && !(m_g.c1.IsNegative() || m_g.c2.IsNegative() || m_g.c1 >= m_p || m_g.c2 >= m_p || m_g == three);
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
if (level >= 1)
|
if (level >= 1)
|
||||||
|
{
|
||||||
pass = pass && ((m_p.Squared()-m_p+1)%m_q).IsZero();
|
pass = pass && ((m_p.Squared()-m_p+1)%m_q).IsZero();
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
|
}
|
||||||
if (level >= 2)
|
if (level >= 2)
|
||||||
{
|
{
|
||||||
pass = pass && VerifyPrime(rng, m_p, level-2) && VerifyPrime(rng, m_q, level-2);
|
pass = pass && VerifyPrime(rng, m_p, level-2) && VerifyPrime(rng, m_q, level-2);
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
pass = pass && XTR_Exponentiate(m_g, (m_p.Squared()-m_p+1)/m_q, m_p) != three;
|
pass = pass && XTR_Exponentiate(m_g, (m_p.Squared()-m_p+1)/m_q, m_p) != three;
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
pass = pass && XTR_Exponentiate(m_g, m_q, m_p) == three;
|
pass = pass && XTR_Exponentiate(m_g, m_q, m_p) == three;
|
||||||
|
CRYPTOPP_ASSERT(pass);
|
||||||
}
|
}
|
||||||
return pass;
|
return pass;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user