Botan  1.10.9
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 * Distributed under the terms of the Botan license
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  curve(curve),
47  base_point(base_point),
48  order(order),
49  cofactor(cofactor),
50  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  EC_Group(const MemoryRegion<byte>& 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  EC_Group(const OID& oid);
64 
65  /**
66  * Create an EC domain from PEM encoding (as from PEM_encode),
67  * or from an OID name (eg "secp160r1", or "1.3.132.0.8")
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  SecureVector<byte> 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 curve; }
90 
91  /**
92  * Return domain parameter curve
93  * @result domain parameter curve
94  */
95  const PointGFp& get_base_point() const { return 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 order; }
102 
103  /**
104  * Return the cofactor
105  * @result the cofactor
106  */
107  const BigInt& get_cofactor() const { return cofactor; }
108 
109  bool initialized() const { return !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 oid; }
116 
117  bool operator==(const EC_Group& other) const
118  {
119  return ((get_curve() == other.get_curve()) &&
120  (get_base_point() == other.get_base_point()) &&
121  (get_order() == other.get_order()) &&
122  (get_cofactor() == other.get_cofactor()));
123  }
124 
125  private:
126  CurveGFp curve;
127  PointGFp base_point;
128  BigInt order, cofactor;
129  std::string oid;
130  };
131 
132 inline bool operator!=(const EC_Group& lhs,
133  const EC_Group& rhs)
134  {
135  return !(lhs == rhs);
136  }
137 
138 // For compatability with 1.8
140 
141 }
142 
143 #endif
std::string get_oid() const
Definition: ec_group.h:115
bool operator!=(const OctetString &s1, const OctetString &s2)
Definition: symkey.cpp:106
const PointGFp & get_base_point() const
Definition: ec_group.h:95
std::string PEM_encode(const Private_Key &key)
Definition: pkcs8.cpp:150
EC_Group EC_Domain_Params
Definition: ec_group.h:139
const CurveGFp & get_curve() const
Definition: ec_group.h:89
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
bool operator==(const EC_Group &other) const
Definition: ec_group.h:117
EC_Group_Encoding
Definition: ec_group.h:22
bool initialized() const
Definition: ec_group.h:109
OID oid
Definition: x509_ext.cpp:446
const BigInt & get_cofactor() const
Definition: ec_group.h:107