aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/pubkey/ec_group/ec_group.h
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2018-01-31 14:03:05 -0500
committerJack Lloyd <[email protected]>2018-01-31 14:03:05 -0500
commite5b9ee2345affb56307070298ded9c2d5e1914be (patch)
tree7311fb0a10a99ccaf8cb82eecdea26d9fbe3d458 /src/lib/pubkey/ec_group/ec_group.h
parent439d2ead033142365f092c7882bad31e4257ed09 (diff)
Use shared representation of EC_Group
Hide CurveGFp with an eye for eventual removal
Diffstat (limited to 'src/lib/pubkey/ec_group/ec_group.h')
-rw-r--r--src/lib/pubkey/ec_group/ec_group.h92
1 files changed, 69 insertions, 23 deletions
diff --git a/src/lib/pubkey/ec_group/ec_group.h b/src/lib/pubkey/ec_group/ec_group.h
index 18ffed12c..3da38a7da 100644
--- a/src/lib/pubkey/ec_group/ec_group.h
+++ b/src/lib/pubkey/ec_group/ec_group.h
@@ -13,6 +13,7 @@
#include <botan/point_gfp.h>
#include <botan/curve_gfp.h>
#include <botan/asn1_oid.h>
+#include <memory>
#include <set>
namespace Botan {
@@ -26,6 +27,8 @@ enum EC_Group_Encoding {
EC_DOMPAR_ENC_OID = 2
};
+struct EC_Group_Data;
+
/**
* Class representing an elliptic curve
*/
@@ -43,13 +46,7 @@ class BOTAN_PUBLIC_API(2,0) EC_Group final
EC_Group(const CurveGFp& curve,
const PointGFp& base_point,
const BigInt& order,
- const BigInt& cofactor) :
- m_curve(curve),
- m_base_point(base_point),
- m_order(order),
- m_cofactor(cofactor),
- m_oid("")
- {}
+ const BigInt& cofactor);
/**
* Decode a BER encoded ECC domain parameter set
@@ -68,7 +65,7 @@ class BOTAN_PUBLIC_API(2,0) EC_Group final
* from an OID name (eg "secp256r1", or "1.2.840.10045.3.1.7")
* @param pem_or_oid PEM-encoded data, or an OID
*/
- EC_Group(const std::string& pem_or_oid = "");
+ explicit EC_Group(const std::string& pem_or_oid = "");
/**
* Create the DER encoding of this domain
@@ -87,41 +84,90 @@ class BOTAN_PUBLIC_API(2,0) EC_Group final
* Return domain parameter curve
* @result domain parameter curve
*/
- const CurveGFp& get_curve() const { return m_curve; }
+ const CurveGFp& BOTAN_DEPRECATED("Avoid CurveGFp") get_curve() const;
+
+ /**
+ * Return the size of p in bits (same as get_p().bits())
+ */
+ size_t get_p_bits() const;
+
+ /**
+ * Return the size of p in bits (same as get_p().bytes())
+ */
+ size_t get_p_bytes() const;
+
+ /**
+ * Return the prime modulus of the field
+ */
+ const BigInt& get_p() const;
+
+ /**
+ * Return the a parameter of the elliptic curve equation
+ */
+ const BigInt& get_a() const;
+
+ /**
+ * Return the b parameter of the elliptic curve equation
+ */
+ const BigInt& get_b() const;
/**
* Return group base point
* @result base point
*/
- const PointGFp& get_base_point() const { return m_base_point; }
+ const PointGFp& get_base_point() const;
/**
* Return the order of the base point
* @result order of the base point
*/
- const BigInt& get_order() const { return m_order; }
+ const BigInt& get_order() const;
+
+ /**
+ * Return the OID of these domain parameters
+ * @result the OID as a string
+ */
+ std::string BOTAN_DEPRECATED("Use get_curve_oid") get_oid() const { return get_curve_oid().as_string(); }
+
+ /**
+ * Return the OID of these domain parameters
+ * @result the OID
+ */
+ const OID& get_curve_oid() const;
/**
* Return the cofactor
* @result the cofactor
*/
- const BigInt& get_cofactor() const { return m_cofactor; }
+ const BigInt& get_cofactor() const;
- bool initialized() const { return !m_base_point.is_zero(); }
+ /**
+ * Return a point on this curve with the affine values x, y
+ */
+ PointGFp point(const BigInt& x, const BigInt& y) const;
/**
- * Return the OID of these domain parameters
- * @result the OID
+ * Return the zero (or infinite) point on this curve
*/
- std::string get_oid() const { return m_oid; }
-
+ PointGFp zero_point() const;
+
+ PointGFp OS2ECP(const uint8_t bits[], size_t len) const;
+
+ template<typename Alloc>
+ PointGFp OS2ECP(const std::vector<uint8_t, Alloc>& vec) const
+ {
+ return this->OS2ECP(vec.data(), vec.size());
+ }
+
+ bool initialized() const { return (m_data != nullptr); }
+
/**
* Verify EC_Group domain
* @returns true if group is valid. false otherwise
*/
bool verify_group(RandomNumberGenerator& rng,
- bool strong = false) const;
-
+ bool strong = false) const;
+
bool operator==(const EC_Group& other) const
{
return ((get_curve() == other.get_curve()) &&
@@ -140,11 +186,11 @@ class BOTAN_PUBLIC_API(2,0) EC_Group final
*/
static const std::set<std::string>& known_named_groups();
+ static void add_named_group(const std::string& name, const OID& oid, const EC_Group& group);
+
private:
- CurveGFp m_curve;
- PointGFp m_base_point;
- BigInt m_order, m_cofactor;
- std::string m_oid;
+ const EC_Group_Data& data() const;
+ std::shared_ptr<EC_Group_Data> m_data;
};
inline bool operator!=(const EC_Group& lhs,