summaryrefslogtreecommitdiff
path: root/gfpcrypt.cpp
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2019-08-24 15:48:14 -0400
committerJeffrey Walton <noloader@gmail.com>2019-08-24 15:48:14 -0400
commita7e83e6bf4c31c1b5d6c7168692b689a3e02ed86 (patch)
tree91f953020e3724b24137e18ef207a208d043ce85 /gfpcrypt.cpp
parent3d96234038b5e2476766a41ef89ed6c2296a1b74 (diff)
downloadcryptopp-git-a7e83e6bf4c31c1b5d6c7168692b689a3e02ed86.tar.gz
Update asserts in gfpcrypt.cpp
Diffstat (limited to 'gfpcrypt.cpp')
-rw-r--r--gfpcrypt.cpp29
1 files changed, 17 insertions, 12 deletions
diff --git a/gfpcrypt.cpp b/gfpcrypt.cpp
index c54c4ee1..4c257cbd 100644
--- a/gfpcrypt.cpp
+++ b/gfpcrypt.cpp
@@ -133,22 +133,27 @@ void DL_SignatureMessageEncodingMethod_NR::ComputeMessageRepresentative(RandomNu
bool DL_GroupParameters_IntegerBased::ValidateGroup(RandomNumberGenerator &rng, unsigned int level) const
{
const Integer &p = GetModulus(), &q = GetSubgroupOrder();
-
bool pass = true;
+
+ CRYPTOPP_ASSERT(p > Integer::One() && p.IsOdd());
pass = pass && p > Integer::One() && p.IsOdd();
- CRYPTOPP_ASSERT(pass);
+
+ CRYPTOPP_ASSERT(q > Integer::One() && q.IsOdd());
pass = pass && q > Integer::One() && q.IsOdd();
- CRYPTOPP_ASSERT(pass);
if (level >= 1)
{
+ CRYPTOPP_ASSERT(GetCofactor() > Integer::One());
+ CRYPTOPP_ASSERT(GetGroupOrder() % q == Integer::Zero());
+
pass = pass && GetCofactor() > Integer::One() && GetGroupOrder() % q == Integer::Zero();
- CRYPTOPP_ASSERT(pass);
}
if (level >= 2)
{
+ CRYPTOPP_ASSERT(VerifyPrime(rng, q, level-2));
+ CRYPTOPP_ASSERT(VerifyPrime(rng, p, level-2));
+
pass = pass && VerifyPrime(rng, q, level-2) && VerifyPrime(rng, p, level-2);
- CRYPTOPP_ASSERT(pass);
}
return pass;
@@ -157,28 +162,28 @@ bool DL_GroupParameters_IntegerBased::ValidateGroup(RandomNumberGenerator &rng,
bool DL_GroupParameters_IntegerBased::ValidateElement(unsigned int level, const Integer &g, const DL_FixedBasePrecomputation<Integer> *gpc) const
{
const Integer &p = GetModulus(), &q = GetSubgroupOrder();
-
bool pass = true;
+
+ CRYPTOPP_ASSERT(GetFieldType() == 1 ? g.IsPositive() : g.NotNegative());
pass = pass && GetFieldType() == 1 ? g.IsPositive() : g.NotNegative();
- CRYPTOPP_ASSERT(pass);
+ CRYPTOPP_ASSERT(g < p && !IsIdentity(g));
pass = pass && g < p && !IsIdentity(g);
- CRYPTOPP_ASSERT(pass);
if (level >= 1)
{
if (gpc)
{
+ CRYPTOPP_ASSERT(gpc->Exponentiate(GetGroupPrecomputation(), Integer::One()) == g);
pass = pass && gpc->Exponentiate(GetGroupPrecomputation(), Integer::One()) == g;
- CRYPTOPP_ASSERT(pass);
}
}
if (level >= 2)
{
if (GetFieldType() == 2)
{
+ CRYPTOPP_ASSERT(Jacobi(g*g-4, p)==-1);
pass = pass && Jacobi(g*g-4, p)==-1;
- CRYPTOPP_ASSERT(pass);
}
// verifying that Lucas((p+1)/2, w, p)==2 is omitted because it's too costly
@@ -188,13 +193,13 @@ bool DL_GroupParameters_IntegerBased::ValidateElement(unsigned int level, const
if (fullValidate && pass)
{
Integer gp = gpc ? gpc->Exponentiate(GetGroupPrecomputation(), q) : ExponentiateElement(g, q);
+ CRYPTOPP_ASSERT(IsIdentity(gp));
pass = pass && IsIdentity(gp);
- CRYPTOPP_ASSERT(pass);
}
else if (GetFieldType() == 1)
{
+ CRYPTOPP_ASSERT(Jacobi(g, p) == 1);
pass = pass && Jacobi(g, p) == 1;
- CRYPTOPP_ASSERT(pass);
}
}