aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/pubkey/ec_group/ec_group.cpp
diff options
context:
space:
mode:
authorNever <[email protected]>2017-02-24 17:52:13 +0100
committerNever <[email protected]>2017-02-24 17:55:29 +0100
commit09d213dead4d3519bbd9aa8083e8c784a4eb9c4f (patch)
treec3776ae9291635a39088ec1a22e136aa34e76a2f /src/lib/pubkey/ec_group/ec_group.cpp
parent2142cf8de355a2c442922e02696ee8e26449f5e6 (diff)
Add ec_group verify function
Diffstat (limited to 'src/lib/pubkey/ec_group/ec_group.cpp')
-rw-r--r--src/lib/pubkey/ec_group/ec_group.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/lib/pubkey/ec_group/ec_group.cpp b/src/lib/pubkey/ec_group/ec_group.cpp
index cbc628195..e8a9672ab 100644
--- a/src/lib/pubkey/ec_group/ec_group.cpp
+++ b/src/lib/pubkey/ec_group/ec_group.cpp
@@ -12,6 +12,7 @@
#include <botan/der_enc.h>
#include <botan/oids.h>
#include <botan/pem.h>
+#include <botan/reducer.h>
namespace Botan {
@@ -130,4 +131,44 @@ std::string EC_Group::PEM_encode() const
return PEM_Code::encode(der, "EC PARAMETERS");
}
+bool EC_Group::verify_group(RandomNumberGenerator& rng,
+ bool) const
+ {
+ //compute the discriminant
+ Modular_Reducer p(m_curve.get_p());
+ BigInt discriminant = p.multiply(4, m_curve.get_a());
+ discriminant += p.multiply(27, m_curve.get_b());
+ discriminant = p.reduce(discriminant);
+ //check the discriminant
+ if(discriminant == 0)
+ {
+ return false;
+ }
+ //check for valid cofactor
+ if(m_cofactor < 1)
+ {
+ return false;
+ }
+ //check if the base point is on the curve
+ if(!m_base_point.on_the_curve())
+ {
+ return false;
+ }
+ if((m_base_point * m_cofactor).is_zero())
+ {
+ return false;
+ }
+ //check if order is prime
+ if(!is_prime(m_order, rng, 128))
+ {
+ return false;
+ }
+ //check if order of the base point is correct
+ if(!(m_base_point * m_order).is_zero())
+ {
+ return false;
+ }
+ return true;
+ }
+
}