Botan  2.1.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 
17 namespace Botan {
18 
19 /**
20 * This class represents elliptic curce domain parameters
21 */
26 };
27 
28 /**
29 * Class representing an elliptic curve
30 */
31 class BOTAN_DLL EC_Group
32  {
33  public:
34 
35  /**
36  * Construct Domain paramers from specified parameters
37  * @param curve elliptic curve
38  * @param base_point a base point
39  * @param order the order of the base point
40  * @param cofactor the cofactor
41  */
42  EC_Group(const CurveGFp& curve,
43  const PointGFp& base_point,
44  const BigInt& order,
45  const BigInt& cofactor) :
46  m_curve(curve),
47  m_base_point(base_point),
48  m_order(order),
49  m_cofactor(cofactor),
50  m_oid("")
51  {}
52 
53  /**
54  * Decode a BER encoded ECC domain parameter set
55  * @param ber_encoding the bytes of the BER encoding
56  */
57  explicit EC_Group(const std::vector<uint8_t>& ber_encoding);
58 
59  /**
60  * Create an EC domain by OID (or throw if unknown)
61  * @param oid the OID of the EC domain to create
62  */
63  explicit EC_Group(const OID& oid);
64 
65  /**
66  * Create an EC domain from PEM encoding (as from PEM_encode), or
67  * from an OID name (eg "secp256r1", or "1.2.840.10045.3.1.7")
68  * @param pem_or_oid PEM-encoded data, or an OID
69  */
70  EC_Group(const std::string& pem_or_oid = "");
71 
72  /**
73  * Create the DER encoding of this domain
74  * @param form of encoding to use
75  * @returns bytes encododed as DER
76  */
77  std::vector<uint8_t> DER_encode(EC_Group_Encoding form) const;
78 
79  /**
80  * Return the PEM encoding (always in explicit form)
81  * @return string containing PEM data
82  */
83  std::string PEM_encode() const;
84 
85  /**
86  * Return domain parameter curve
87  * @result domain parameter curve
88  */
89  const CurveGFp& get_curve() const { return m_curve; }
90 
91  /**
92  * Return group base point
93  * @result base point
94  */
95  const PointGFp& get_base_point() const { return m_base_point; }
96 
97  /**
98  * Return the order of the base point
99  * @result order of the base point
100  */
101  const BigInt& get_order() const { return m_order; }
102 
103  /**
104  * Return the cofactor
105  * @result the cofactor
106  */
107  const BigInt& get_cofactor() const { return m_cofactor; }
108 
109  bool initialized() const { return !m_base_point.is_zero(); }
110 
111  /**
112  * Return the OID of these domain parameters
113  * @result the OID
114  */
115  std::string get_oid() const { return m_oid; }
116 
117  /**
118  * Verify EC_Group domain
119  * @returns true if group is valid. false otherwise
120  */
121  bool verify_group(RandomNumberGenerator& rng,
122  bool strong = false) const;
123 
124  bool operator==(const EC_Group& other) const
125  {
126  return ((get_curve() == other.get_curve()) &&
127  (get_base_point() == other.get_base_point()) &&
128  (get_order() == other.get_order()) &&
129  (get_cofactor() == other.get_cofactor()));
130  }
131 
132  /**
133  * Return PEM representation of named EC group
134  */
135  static std::string PEM_for_named_group(const std::string& name);
136 
137  private:
141  std::string m_oid;
142  };
143 
144 inline bool operator!=(const EC_Group& lhs,
145  const EC_Group& rhs)
146  {
147  return !(lhs == rhs);
148  }
149 
150 // For compatibility with 1.8
152 
153 }
154 
155 #endif
const BigInt & m_cofactor
Definition: ecdh.cpp:49
std::string get_oid() const
Definition: ec_group.h:115
bool operator!=(const AlgorithmIdentifier &a1, const AlgorithmIdentifier &a2)
Definition: alg_id.cpp:82
const PointGFp & get_base_point() const
Definition: ec_group.h:95
const CurveGFp & m_curve
Definition: ecdh.cpp:48
OID m_oid
Definition: x509_ext.cpp:682
std::string PEM_encode(const Private_Key &key)
Definition: pkcs8.cpp:139
EC_Group EC_Domain_Params
Definition: ec_group.h:151
const CurveGFp & get_curve() const
Definition: ec_group.h:89
Blinded_Point_Multiply m_base_point
Definition: ecdsa.cpp:66
const BigInt & get_order() const
Definition: ec_group.h:101
EC_Group(const CurveGFp &curve, const PointGFp &base_point, const BigInt &order, const BigInt &cofactor)
Definition: ec_group.h:42
Definition: alg_id.cpp:13
const BigInt & m_order
Definition: ecdh.cpp:50
bool operator==(const EC_Group &other) const
Definition: ec_group.h:124
EC_Group_Encoding
Definition: ec_group.h:22
bool initialized() const
Definition: ec_group.h:109
const BigInt & get_cofactor() const
Definition: ec_group.h:107