Botan  2.4.0
Crypto and TLS for C++11
ec_group.h
Go to the documentation of this file.
1 /*
2 * ECC Domain Parameters
3 *
4 * (C) 2007 Falko Strenzke, FlexSecure GmbH
5 * 2008-2010 Jack Lloyd
6 *
7 * Botan is released under the Simplified BSD License (see license.txt)
8 */
9 
10 #ifndef BOTAN_ECC_DOMAIN_PARAMETERS_H_
11 #define BOTAN_ECC_DOMAIN_PARAMETERS_H_
12 
13 #include <botan/point_gfp.h>
14 #include <botan/curve_gfp.h>
15 #include <botan/asn1_oid.h>
16 #include <set>
17 
18 namespace Botan {
19 
20 /**
21 * This class represents elliptic curce domain parameters
22 */
27 };
28 
29 /**
30 * Class representing an elliptic curve
31 */
32 class BOTAN_PUBLIC_API(2,0) EC_Group final
33  {
34  public:
35 
36  /**
37  * Construct Domain paramers from specified parameters
38  * @param curve elliptic curve
39  * @param base_point a base point
40  * @param order the order of the base point
41  * @param cofactor the cofactor
42  */
43  EC_Group(const CurveGFp& curve,
44  const PointGFp& base_point,
45  const BigInt& order,
46  const BigInt& cofactor) :
47  m_curve(curve),
48  m_base_point(base_point),
49  m_order(order),
50  m_cofactor(cofactor),
51  m_oid("")
52  {}
53 
54  /**
55  * Decode a BER encoded ECC domain parameter set
56  * @param ber_encoding the bytes of the BER encoding
57  */
58  explicit EC_Group(const std::vector<uint8_t>& ber_encoding);
59 
60  /**
61  * Create an EC domain by OID (or throw if unknown)
62  * @param oid the OID of the EC domain to create
63  */
64  explicit EC_Group(const OID& oid);
65 
66  /**
67  * Create an EC domain from PEM encoding (as from PEM_encode), or
68  * from an OID name (eg "secp256r1", or "1.2.840.10045.3.1.7")
69  * @param pem_or_oid PEM-encoded data, or an OID
70  */
71  EC_Group(const std::string& pem_or_oid = "");
72 
73  /**
74  * Create the DER encoding of this domain
75  * @param form of encoding to use
76  * @returns bytes encododed as DER
77  */
78  std::vector<uint8_t> DER_encode(EC_Group_Encoding form) const;
79 
80  /**
81  * Return the PEM encoding (always in explicit form)
82  * @return string containing PEM data
83  */
84  std::string PEM_encode() const;
85 
86  /**
87  * Return domain parameter curve
88  * @result domain parameter curve
89  */
90  const CurveGFp& get_curve() const { return m_curve; }
91 
92  /**
93  * Return group base point
94  * @result base point
95  */
96  const PointGFp& get_base_point() const { return m_base_point; }
97 
98  /**
99  * Return the order of the base point
100  * @result order of the base point
101  */
102  const BigInt& get_order() const { return m_order; }
103 
104  /**
105  * Return the cofactor
106  * @result the cofactor
107  */
108  const BigInt& get_cofactor() const { return m_cofactor; }
109 
110  bool initialized() const { return !m_base_point.is_zero(); }
111 
112  /**
113  * Return the OID of these domain parameters
114  * @result the OID
115  */
116  std::string get_oid() const { return m_oid; }
117 
118  /**
119  * Verify EC_Group domain
120  * @returns true if group is valid. false otherwise
121  */
122  bool verify_group(RandomNumberGenerator& rng,
123  bool strong = false) const;
124 
125  bool operator==(const EC_Group& other) const
126  {
127  return ((get_curve() == other.get_curve()) &&
128  (get_base_point() == other.get_base_point()) &&
129  (get_order() == other.get_order()) &&
130  (get_cofactor() == other.get_cofactor()));
131  }
132 
133  /**
134  * Return PEM representation of named EC group
135  */
136  static std::string PEM_for_named_group(const std::string& name);
137 
138  /**
139  * Return a set of known named EC groups
140  */
141  static const std::set<std::string>& known_named_groups();
142 
143  private:
144  CurveGFp m_curve;
145  PointGFp m_base_point;
146  BigInt m_order, m_cofactor;
147  std::string m_oid;
148  };
149 
150 inline bool operator!=(const EC_Group& lhs,
151  const EC_Group& rhs)
152  {
153  return !(lhs == rhs);
154  }
155 
156 // For compatibility with 1.8
158 
159 }
160 
161 #endif
bool operator!=(const AlgorithmIdentifier &a1, const AlgorithmIdentifier &a2)
Definition: alg_id.cpp:90
const PointGFp & get_base_point() const
Definition: ec_group.h:96
const BigInt & get_cofactor() const
Definition: ec_group.h:108
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:27
bool initialized() const
Definition: ec_group.h:110
EC_Group EC_Domain_Params
Definition: ec_group.h:157
std::string PEM_encode(const Private_Key &key)
Definition: pkcs8.cpp:140
EC_Group(const CurveGFp &curve, const PointGFp &base_point, const BigInt &order, const BigInt &cofactor)
Definition: ec_group.h:43
Definition: alg_id.cpp:13
const BigInt & get_order() const
Definition: ec_group.h:102
EC_Group_Encoding
Definition: ec_group.h:23
const CurveGFp & get_curve() const
Definition: ec_group.h:90
bool operator==(const EC_Group &other) const
Definition: ec_group.h:125
std::string get_oid() const
Definition: ec_group.h:116