aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib
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
parent2142cf8de355a2c442922e02696ee8e26449f5e6 (diff)
Add ec_group verify function
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/pubkey/ec_group/ec_group.cpp41
-rw-r--r--src/lib/pubkey/ec_group/ec_group.h9
2 files changed, 49 insertions, 1 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;
+ }
+
}
diff --git a/src/lib/pubkey/ec_group/ec_group.h b/src/lib/pubkey/ec_group/ec_group.h
index 15c09a54d..a2cd4d719 100644
--- a/src/lib/pubkey/ec_group/ec_group.h
+++ b/src/lib/pubkey/ec_group/ec_group.h
@@ -113,7 +113,14 @@ class BOTAN_DLL EC_Group
* @result the OID
*/
std::string get_oid() const { return m_oid; }
-
+
+ /**
+ * Verify EC_Group domain
+ * @returns true if group is valid. false otherwise
+ */
+ bool verify_group(RandomNumberGenerator& rng,
+ bool strong = false) const;
+
bool operator==(const EC_Group& other) const
{
return ((get_curve() == other.get_curve()) &&