Botan  2.4.0
Crypto and TLS for C++11
Public Member Functions | Static Public Member Functions | List of all members
Botan::EC_Group Class Referencefinal

#include <ec_group.h>

Public Member Functions

std::vector< uint8_t > DER_encode (EC_Group_Encoding form) const
 
 EC_Group (const CurveGFp &curve, const PointGFp &base_point, const BigInt &order, const BigInt &cofactor)
 
 EC_Group (const std::vector< uint8_t > &ber_encoding)
 
 EC_Group (const OID &oid)
 
 EC_Group (const std::string &pem_or_oid="")
 
const PointGFpget_base_point () const
 
const BigIntget_cofactor () const
 
const CurveGFpget_curve () const
 
std::string get_oid () const
 
const BigIntget_order () const
 
bool initialized () const
 
bool operator== (const EC_Group &other) const
 
std::string PEM_encode () const
 
bool verify_group (RandomNumberGenerator &rng, bool strong=false) const
 

Static Public Member Functions

static const std::set< std::string > & known_named_groups ()
 
static std::string PEM_for_named_group (const std::string &name)
 

Detailed Description

Class representing an elliptic curve

Definition at line 32 of file ec_group.h.

Constructor & Destructor Documentation

◆ EC_Group() [1/4]

Botan::EC_Group::EC_Group ( const CurveGFp curve,
const PointGFp base_point,
const BigInt order,
const BigInt cofactor 
)
inline

Construct Domain paramers from specified parameters

Parameters
curveelliptic curve
base_pointa base point
orderthe order of the base point
cofactorthe cofactor

Definition at line 43 of file ec_group.h.

Referenced by EC_Group().

46  :
47  m_curve(curve),
48  m_base_point(base_point),
49  m_order(order),
50  m_cofactor(cofactor),
51  m_oid("")
52  {}

◆ EC_Group() [2/4]

Botan::EC_Group::EC_Group ( const std::vector< uint8_t > &  ber_encoding)
explicit

Decode a BER encoded ECC domain parameter set

Parameters
ber_encodingthe bytes of the BER encoding

Definition at line 50 of file ec_group.cpp.

References Botan::BER_Decoder::decode(), Botan::BER_Decoder::decode_and_check(), Botan::BER_Decoder::decode_octet_string_bigint(), EC_Group(), Botan::BER_Decoder::end_cons(), Botan::BER_Decoder::get_next_object(), Botan::NULL_TAG, Botan::OBJECT_ID, Botan::OCTET_STRING, Botan::OS2ECP(), Botan::SEQUENCE, Botan::BER_Decoder::start_cons(), Botan::BER_Object::type_tag, and Botan::BER_Decoder::verify_end().

51  {
52  BER_Decoder ber(ber_data);
53  BER_Object obj = ber.get_next_object();
54 
55  if(obj.type_tag == NULL_TAG)
56  throw Decoding_Error("Cannot handle ImplicitCA ECDSA parameters");
57  else if(obj.type_tag == OBJECT_ID)
58  {
59  OID dom_par_oid;
60  BER_Decoder(ber_data).decode(dom_par_oid);
61  *this = EC_Group(dom_par_oid);
62  }
63  else if(obj.type_tag == SEQUENCE)
64  {
65  BigInt p, a, b;
66  std::vector<uint8_t> sv_base_point;
67 
68  BER_Decoder(ber_data)
69  .start_cons(SEQUENCE)
70  .decode_and_check<size_t>(1, "Unknown ECC param version code")
71  .start_cons(SEQUENCE)
72  .decode_and_check(OID("1.2.840.10045.1.1"),
73  "Only prime ECC fields supported")
74  .decode(p)
75  .end_cons()
76  .start_cons(SEQUENCE)
77  .decode_octet_string_bigint(a)
78  .decode_octet_string_bigint(b)
79  .end_cons()
80  .decode(sv_base_point, OCTET_STRING)
81  .decode(m_order)
82  .decode(m_cofactor)
83  .end_cons()
84  .verify_end();
85 
86  m_curve = CurveGFp(p, a, b);
87  m_base_point = OS2ECP(sv_base_point, m_curve);
88  }
89  else
90  throw Decoding_Error("Unexpected tag while decoding ECC domain params");
91  }
EC_Group(const CurveGFp &curve, const PointGFp &base_point, const BigInt &order, const BigInt &cofactor)
Definition: ec_group.h:43
PointGFp OS2ECP(const uint8_t data[], size_t data_len, const CurveGFp &curve)
Definition: point_gfp.cpp:543

◆ EC_Group() [3/4]

Botan::EC_Group::EC_Group ( const OID oid)
explicit

Create an EC domain by OID (or throw if unknown)

Parameters
oidthe OID of the EC domain to create

Definition at line 19 of file ec_group.cpp.

References Botan::OID::as_string(), EC_Group(), Botan::OIDS::lookup(), and PEM_for_named_group().

20  {
21  const std::string pem = PEM_for_named_group(OIDS::lookup(domain_oid));
22 
23  if(pem == "")
24  {
25  throw Lookup_Error("No ECC domain data for '" + domain_oid.as_string() + "'");
26  }
27 
28  *this = EC_Group(pem);
29  m_oid = domain_oid.as_string();
30  }
static std::string PEM_for_named_group(const std::string &name)
Definition: ec_named.cpp:13
EC_Group(const CurveGFp &curve, const PointGFp &base_point, const BigInt &order, const BigInt &cofactor)
Definition: ec_group.h:43
std::string lookup(const OID &oid)
Definition: oids.cpp:18

◆ EC_Group() [4/4]

Botan::EC_Group::EC_Group ( const std::string &  pem_or_oid = "")

Create an EC domain from PEM encoding (as from PEM_encode), or from an OID name (eg "secp256r1", or "1.2.840.10045.3.1.7")

Parameters
pem_or_oidPEM-encoded data, or an OID

Definition at line 32 of file ec_group.cpp.

References Botan::PEM_Code::decode_check_label(), EC_Group(), Botan::OIDS::lookup(), and Botan::unlock().

33  {
34  if(str == "")
35  return; // no initialization / uninitialized
36 
37  try
38  {
39  std::vector<uint8_t> ber =
40  unlock(PEM_Code::decode_check_label(str, "EC PARAMETERS"));
41 
42  *this = EC_Group(ber);
43  }
44  catch(Decoding_Error) // hmm, not PEM?
45  {
46  *this = EC_Group(OIDS::lookup(str));
47  }
48  }
secure_vector< uint8_t > decode_check_label(DataSource &source, const std::string &label_want)
Definition: pem.cpp:54
EC_Group(const CurveGFp &curve, const PointGFp &base_point, const BigInt &order, const BigInt &cofactor)
Definition: ec_group.h:43
std::vector< T > unlock(const secure_vector< T > &in)
Definition: secmem.h:95
std::string lookup(const OID &oid)
Definition: oids.cpp:18

Member Function Documentation

◆ DER_encode()

std::vector< uint8_t > Botan::EC_Group::DER_encode ( EC_Group_Encoding  form) const

Create the DER encoding of this domain

Parameters
formof encoding to use
Returns
bytes encododed as DER

Definition at line 94 of file ec_group.cpp.

References Botan::BigInt::bytes(), Botan::EC2OSP(), Botan::EC_DOMPAR_ENC_EXPLICIT, Botan::EC_DOMPAR_ENC_IMPLICITCA, Botan::EC_DOMPAR_ENC_OID, Botan::DER_Encoder::encode(), Botan::BigInt::encode_1363(), Botan::DER_Encoder::encode_null(), Botan::DER_Encoder::end_cons(), Botan::CurveGFp::get_a(), Botan::CurveGFp::get_b(), Botan::DER_Encoder::get_contents_unlocked(), get_oid(), Botan::CurveGFp::get_p(), Botan::OCTET_STRING, Botan::SEQUENCE, Botan::DER_Encoder::start_cons(), and Botan::PointGFp::UNCOMPRESSED.

Referenced by PEM_encode().

95  {
96  if(form == EC_DOMPAR_ENC_EXPLICIT)
97  {
98  const size_t ecpVers1 = 1;
99  OID curve_type("1.2.840.10045.1.1");
100 
101  const size_t p_bytes = m_curve.get_p().bytes();
102 
103  return DER_Encoder()
104  .start_cons(SEQUENCE)
105  .encode(ecpVers1)
106  .start_cons(SEQUENCE)
107  .encode(curve_type)
108  .encode(m_curve.get_p())
109  .end_cons()
110  .start_cons(SEQUENCE)
111  .encode(BigInt::encode_1363(m_curve.get_a(), p_bytes),
112  OCTET_STRING)
113  .encode(BigInt::encode_1363(m_curve.get_b(), p_bytes),
114  OCTET_STRING)
115  .end_cons()
116  .encode(EC2OSP(m_base_point, PointGFp::UNCOMPRESSED), OCTET_STRING)
117  .encode(m_order)
118  .encode(m_cofactor)
119  .end_cons()
120  .get_contents_unlocked();
121  }
122  else if(form == EC_DOMPAR_ENC_OID)
123  {
124  if(get_oid().empty())
125  {
126  throw Encoding_Error("Cannot encode EC_Group as OID because OID not set");
127  }
128  return DER_Encoder().encode(OID(get_oid())).get_contents_unlocked();
129  }
130  else if(form == EC_DOMPAR_ENC_IMPLICITCA)
131  return DER_Encoder().encode_null().get_contents_unlocked();
132  else
133  throw Internal_Error("EC_Group::DER_encode: Unknown encoding");
134  }
secure_vector< uint8_t > EC2OSP(const PointGFp &point, uint8_t format)
Definition: point_gfp.cpp:469
size_t bytes() const
Definition: bigint.cpp:175
const BigInt & get_b() const
Definition: curve_gfp.h:85
const BigInt & get_a() const
Definition: curve_gfp.h:80
static secure_vector< uint8_t > encode_1363(const BigInt &n, size_t bytes)
Definition: big_code.cpp:82
const BigInt & get_p() const
Definition: curve_gfp.h:91
std::string get_oid() const
Definition: ec_group.h:116

◆ get_base_point()

const PointGFp& Botan::EC_Group::get_base_point ( ) const
inline

Return group base point

Returns
base point

Definition at line 96 of file ec_group.h.

Referenced by Botan::EC_PrivateKey::EC_PrivateKey(), operator==(), and Botan::sm2_compute_za().

96 { return m_base_point; }

◆ get_cofactor()

const BigInt& Botan::EC_Group::get_cofactor ( ) const
inline

Return the cofactor

Returns
the cofactor

Definition at line 108 of file ec_group.h.

Referenced by Botan::EC_PublicKey::check_key(), Botan::ECIES_KA_Operation::derive_secret(), Botan::ECIES_Decryptor::ECIES_Decryptor(), and operator==().

108 { return m_cofactor; }

◆ get_curve()

const CurveGFp& Botan::EC_Group::get_curve ( ) const
inline

◆ get_oid()

std::string Botan::EC_Group::get_oid ( ) const
inline

Return the OID of these domain parameters

Returns
the OID

Definition at line 116 of file ec_group.h.

Referenced by DER_encode(), Botan::EC_PrivateKey::EC_PrivateKey(), Botan::EC_PublicKey::EC_PublicKey(), and Botan::EC_PublicKey::set_parameter_encoding().

116 { return m_oid; }

◆ get_order()

const BigInt& Botan::EC_Group::get_order ( ) const
inline

◆ initialized()

bool Botan::EC_Group::initialized ( ) const
inline

Definition at line 110 of file ec_group.h.

110 { return !m_base_point.is_zero(); }
bool is_zero() const
Definition: point_gfp.h:179

◆ known_named_groups()

const std::set< std::string > & Botan::EC_Group::known_named_groups ( )
static

Return a set of known named EC groups

Definition at line 287 of file ec_named.cpp.

288  {
289  static const std::set<std::string> named_groups = {
290  "secp160k1",
291  "secp160r1",
292  "secp160r2",
293  "secp192k1",
294  "secp192r1",
295  "secp224k1",
296  "secp224r1",
297  "secp256k1",
298  "secp256r1",
299  "secp384r1",
300  "secp521r1",
301  "brainpool160r1",
302  "brainpool192r1",
303  "brainpool224r1",
304  "brainpool256r1",
305  "brainpool320r1",
306  "brainpool384r1",
307  "brainpool512r1",
308  "x962_p192v2",
309  "x962_p192v3",
310  "x962_p239v1",
311  "x962_p239v2",
312  "x962_p239v3",
313  "gost_256A",
314  "frp256v1",
315  "sm2p256v1"
316 #if defined(BOTAN_HOUSE_ECC_CURVE_NAME)
317  ,BOTAN_HOUSE_ECC_CURVE_NAME
318 #endif
319  };
320  return named_groups;
321  }

◆ operator==()

bool Botan::EC_Group::operator== ( const EC_Group other) const
inline

Definition at line 125 of file ec_group.h.

References get_base_point(), get_cofactor(), get_curve(), and get_order().

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  }
const PointGFp & get_base_point() const
Definition: ec_group.h:96
const BigInt & get_cofactor() const
Definition: ec_group.h:108
const BigInt & get_order() const
Definition: ec_group.h:102
const CurveGFp & get_curve() const
Definition: ec_group.h:90

◆ PEM_encode()

std::string Botan::EC_Group::PEM_encode ( ) const

Return the PEM encoding (always in explicit form)

Returns
string containing PEM data

Definition at line 136 of file ec_group.cpp.

References DER_encode(), Botan::EC_DOMPAR_ENC_EXPLICIT, and Botan::PEM_Code::encode().

137  {
138  const std::vector<uint8_t> der = DER_encode(EC_DOMPAR_ENC_EXPLICIT);
139  return PEM_Code::encode(der, "EC PARAMETERS");
140  }
std::string encode(const uint8_t der[], size_t length, const std::string &label, size_t width)
Definition: pem.cpp:43
std::vector< uint8_t > DER_encode(EC_Group_Encoding form) const
Definition: ec_group.cpp:94

◆ PEM_for_named_group()

std::string Botan::EC_Group::PEM_for_named_group ( const std::string &  name)
static

Return PEM representation of named EC group

Definition at line 13 of file ec_named.cpp.

Referenced by EC_Group().

14  {
15  if(name == "secp160k1")
16  return
17  "-----BEGIN EC PARAMETERS-----"
18  "MIGYAgEBMCAGByqGSM49AQECFQD////////////////////+//+sczAsBBQAAAAA"
19  "AAAAAAAAAAAAAAAAAAAAAAQUAAAAAAAAAAAAAAAAAAAAAAAAAAcEKQQ7TDgs43qh"
20  "kqQBnnYwNvT13U1+u5OM+TUxj9zta8KChlMXM8PwPE/uAhUBAAAAAAAAAAAAAbj6"
21  "Ft+rmsoWtrMCAQE="
22  "-----END EC PARAMETERS-----";
23 
24  if(name == "secp160r1")
25  return
26  "-----BEGIN EC PARAMETERS-----"
27  "MIGYAgEBMCAGByqGSM49AQECFQD/////////////////////f////zAsBBT/////"
28  "////////////////f////AQUHJe+/FS9eotlrPifgdTUrcVl+kUEKQRKlrVojvVz"
29  "KEZkaYlow4u5E8v8giOmKFUxaJR9WdzJEgQjUTd6xfsyAhUBAAAAAAAAAAAAAfTI"
30  "+Seu08p1IlcCAQE="
31  "-----END EC PARAMETERS-----";
32 
33  if(name == "secp160r2")
34  return
35  "-----BEGIN EC PARAMETERS-----"
36  "MIGYAgEBMCAGByqGSM49AQECFQD////////////////////+//+sczAsBBT/////"
37  "///////////////+//+scAQUtOE00/tZ64urVydJBGZNWvUDiLoEKQRS3LA0KToR"
38  "fh9P8Rsw9xmdMUTObf6v/vLjMfKW4HH6DfmYLP6n1D8uAhUBAAAAAAAAAAAAADUe"
39  "54aoGPOhoWsCAQE="
40  "-----END EC PARAMETERS-----";
41 
42  if(name == "secp192k1")
43  return
44  "-----BEGIN EC PARAMETERS-----"
45  "MIGwAgEBMCQGByqGSM49AQECGQD//////////////////////////v//7jcwNAQY"
46  "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBgAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
47  "AAMEMQTbT/EOwFfpriawfQKAt/Q0HaXRsergbH2bLy9tnFYop4RBY9AVvoY0QIKq"
48  "iNleL50CGQD///////////////4m8vwXD2lGanTe/Y0CAQE="
49  "-----END EC PARAMETERS-----";
50 
51  if(name == "secp192r1")
52  return
53  "-----BEGIN EC PARAMETERS-----"
54  "MIGwAgEBMCQGByqGSM49AQECGQD////////////////////+//////////8wNAQY"
55  "/////////////////////v/////////8BBhkIQUZ5ZyA5w+n6atyJDBJ/rje7MFG"
56  "ubEEMQQYjagOsDCQ9ny/IOtDoYgA9P8K/YL/EBIHGSuV/8jaeGMQEe1rJM3Vc/l3"
57  "oR55SBECGQD///////////////+Z3vg2FGvJsbTSKDECAQE="
58  "-----END EC PARAMETERS-----";
59 
60  if(name == "secp224k1")
61  return
62  "-----BEGIN EC PARAMETERS-----"
63  "MIHIAgEBMCgGByqGSM49AQECHQD///////////////////////////////7//+Vt"
64  "MDwEHAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEHAAAAAAAAAAAAAAAAAAA"
65  "AAAAAAAAAAAAAAAAAAUEOQShRVszTfCZ3zD8KKFppGfp5HB1qQ9+ZQ62t6Rcfgif"
66  "7X+6NEKCyvvW9+MZ98CwvVniykvbVW1hpQIdAQAAAAAAAAAAAAAAAAAB3OjS7GGE"
67  "yvCpcXafsfcCAQE="
68  "-----END EC PARAMETERS-----";
69 
70  if(name == "secp224r1")
71  return
72  "-----BEGIN EC PARAMETERS-----"
73  "MIHIAgEBMCgGByqGSM49AQECHQD/////////////////////AAAAAAAAAAAAAAAB"
74  "MDwEHP////////////////////7///////////////4EHLQFCoUMBLOr9UEyVlBE"
75  "sLfXv9i6Jws5QyNV/7QEOQS3Dgy9a7S/fzITkLlKA8HTVsIRIjQygNYRXB0hvTdj"
76  "iLX3I/tMIt/mzUN1oFoHR2RE1YGZhQB+NAIdAP//////////////////FqLguPA+"
77  "E90pRVxcKj0CAQE="
78  "-----END EC PARAMETERS-----";
79 
80  if(name == "secp256k1")
81  return
82  "-----BEGIN EC PARAMETERS-----"
83  "MIHgAgEBMCwGByqGSM49AQECIQD////////////////////////////////////+"
84  "///8LzBEBCAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQgAAAAAAAA"
85  "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAcEQQR5vmZ++dy7rFWgYpXOhwsHApv8"
86  "2y3OKNlZ8oFbFvgXmEg62ncmo8RlXaT7/A4RCKj9F7RIpoVUGZxH0I/7ENS4AiEA"
87  "/////////////////////rqu3OavSKA7v9JejNA2QUECAQE="
88  "-----END EC PARAMETERS-----";
89 
90  if(name == "secp256r1")
91  return
92  "-----BEGIN EC PARAMETERS-----"
93  "MIHgAgEBMCwGByqGSM49AQECIQD/////AAAAAQAAAAAAAAAAAAAAAP//////////"
94  "/////zBEBCD/////AAAAAQAAAAAAAAAAAAAAAP///////////////AQgWsY12Ko6"
95  "k+ez671VdpiGvGUdBrDMU7D2O848PifSYEsEQQRrF9Hy4SxCR/i85uVjpEDydwN9"
96  "gS3rM6D0oTlF2JjClk/jQuL+Gn+bjufrSnwPnhYrzjNXazFezsu2QGg3v1H1AiEA"
97  "/////wAAAAD//////////7zm+q2nF56E87nKwvxjJVECAQE="
98  "-----END EC PARAMETERS-----";
99 
100  if(name == "secp384r1")
101  return
102  "-----BEGIN EC PARAMETERS-----"
103  "MIIBQAIBATA8BgcqhkjOPQEBAjEA////////////////////////////////////"
104  "//////7/////AAAAAAAAAAD/////MGQEMP//////////////////////////////"
105  "///////////+/////wAAAAAAAAAA/////AQwszEvp+I+5+SYjgVr4/gtGRgdnG7+"
106  "gUESAxQIj1ATh1rGVjmNii7RnSqFyO3T7CrvBGEEqofKIr6LBTeOscce8yCtdG4d"
107  "O2KLp5uYWfdB4IJUKjhVAvJdv1UpbDpUXjhydgq3NhfeSpYmLG9dnpi/kpLcKfj0"
108  "Hb0omhR86doxE7XwuMAKYLHOHX6BnXpDHXyQ6g5fAjEA////////////////////"
109  "////////////x2NNgfQ3Ld9YGg2ySLCneuzsGWrMxSlzAgEB"
110  "-----END EC PARAMETERS-----";
111 
112  if(name == "secp521r1")
113  return
114  "-----BEGIN EC PARAMETERS-----"
115  "MIIBrAIBATBNBgcqhkjOPQEBAkIB////////////////////////////////////"
116  "//////////////////////////////////////////////////8wgYgEQgH/////"
117  "////////////////////////////////////////////////////////////////"
118  "/////////////////ARCAFGVPrlhjhyaH5KaIaC2hUDuotpyW5mzFfO4tImRjvEJ"
119  "4VYZOVHsfpN7FlLAvTuxvwc1c9+IPSw08e9FH9RrUD8ABIGFBADGhY4GtwQE6c2e"
120  "PstmI5W0QpxkgTkFP7Uh+CivYGtNPbqhS1537+dZKP4dwSei/6jeM0izwYVqQpv5"
121  "fn4xwuW9ZgEYOSlqeJo7wARcil+0LH0b2Zj1RElXm0RoF6+9Fyc+ZiyX7nKZXvQm"
122  "QMVQuQE/rQdhNTxwhqJywkCIvpR2n9FmUAJCAf//////////////////////////"
123  "////////////////+lGGh4O/L5Zrf8wBSPcJpdA7tcm4iZxHrrtvtx6ROGQJAgEB"
124  "-----END EC PARAMETERS-----";
125 
126  if(name == "brainpool160r1")
127  return
128  "-----BEGIN EC PARAMETERS-----"
129  "MIGYAgEBMCAGByqGSM49AQECFQDpXkpfc3BZ3GDfx62Vs9gTlRViDzAsBBQ0Dnvi"
130  "ooDrdOK+YbradF2X6PfDAAQUHliahZVCNBITT6otveyVyNhnXlgEKQS+1a8W6j9q"
131  "T2KTjEYx61r3vbzbwxZny0d6Go7DOPlHQWacl2MW2mMhAhUA6V5KX3NwWdxg31mR"
132  "1FApQJ5g/AkCAQE="
133  "-----END EC PARAMETERS-----";
134 
135  if(name == "brainpool192r1")
136  return
137  "-----BEGIN EC PARAMETERS-----"
138  "MIGwAgEBMCQGByqGSM49AQECGQDDAvQdkyo2zaejRjCT0Y23j85HbeGoYpcwNAQY"
139  "apEXQHax4OGcOcAx/oaFwcrgQOXGmijvBBhGmijvfCjMo9xyHQRPRJa8yn70FG+/"
140  "JckEMQTAoGR+qrakh1OwM8VssPCQCi9cSFM3X9YUtpCGar1buItfSCjBSQAC5nc/"
141  "ovopm48CGQDDAvQdkyo2zaejRi+enpFrW+jxAprErMECAQE="
142  "-----END EC PARAMETERS-----";
143 
144  if(name == "brainpool224r1")
145  return
146  "-----BEGIN EC PARAMETERS-----"
147  "MIHIAgEBMCgGByqGSM49AQECHQDXwTSqJkNmhioYMCV10deHsJ8HV5faifV+yMD/"
148  "MDwEHGil5iypzmwcKZgDpsFTC1FOGCrYsAQqWcrSn0MEHCWA9jzP5EE4hwcTsakj"
149  "aeM+ITXSZtuzcjhsQAsEOQQNkCmtLH5c9DQII7KofcaMnkzjF0webv3uEsB9WKpW"
150  "93LAcm8kxrieTs2sJDVLnpnKo/bTdhQCzQIdANfBNKomQ2aGKhgwJXXQ+5jRFrxL"
151  "bd68o6Wnk58CAQE="
152  "-----END EC PARAMETERS-----";
153 
154  if(name == "brainpool256r1")
155  return
156  "-----BEGIN EC PARAMETERS-----"
157  "MIHgAgEBMCwGByqGSM49AQECIQCp+1fboe6pvD5mCpCdg41ybjv2I9UmICggE0gd"
158  "H25TdzBEBCB9Wgl1/CwwV+72dTBBev/n+4BVwSbcXGzpSktE8zC12QQgJtxcbOlK"
159  "S0TzMLXZu9d8v5WEFilc9+HOa8zcGP+MB7YEQQSL0q65y35XyyxLSC/8gbevud4n"
160  "4eO9I8I6RFO9ms4yYlR++DXD2sT9l/hGGhRhHcnCd0UTLe2OVFwdVMcvBGmXAiEA"
161  "qftX26Huqbw+ZgqQnYONcYw5eqO1Yab3kB4OgpdIVqcCAQE="
162  "-----END EC PARAMETERS-----";
163 
164  if(name == "brainpool320r1")
165  return
166  "-----BEGIN EC PARAMETERS-----"
167  "MIIBEAIBATA0BgcqhkjOPQEBAikA015HIDa8T7fhPHhe0gHgZfmPz6b29A3vT5K5"
168  "7HiT7Cj81BKx8bMuJzBUBCg+4wtWj7qw+IPM69RtPzu4oqc1E/XredpmGQ6whf+p"
169  "9JLzdal9hg60BChSCIOUnf28QtOtGYZAaIpv4T9BNJVUtJrMMdzNiEU5gW9etKyP"
170  "sfGmBFEEQ71+mvtT2LhSibzEjuW/5vIBN9EKCH6254ceKhClmccQr40NOeIGERT9"
171  "0FVF7BzIq0CTJH93J14HQ//tEXGC6qnHeHeqrGrH01JF0WkujuECKQDTXkcgNrxP"
172  "t+E8eF7SAeBl+Y/PpbaPEqMtSC7H7oZY6YaRVVtExZMRAgEB"
173  "-----END EC PARAMETERS-----";
174 
175  if(name == "brainpool384r1")
176  return
177  "-----BEGIN EC PARAMETERS-----"
178  "MIIBQAIBATA8BgcqhkjOPQEBAjEAjLkegqM4bSgPXW9+UOZB3xUvcQntVFa0ErHa"
179  "GX+3ESOs06cpkB0acYdHABMxB+xTMGQEMHvDgsY9jBUMPHIICs4Fr6DCvqKOT7In"
180  "hxORZe+6kfkPiqWBSlA61OsEqMfdIs4oJgQwBKjH3SLOKCaLObVUFvBEfC+3feEH"
181  "3NKmLogOpT7rYtV8tDkCldvJlDq3hpb6UEwRBGEEHRxk8GjPRf+ipjqBt8E/a4hH"
182  "o+d+8U/j23/K/gy9EOjoJuA0NtZGqu+HsuJH1K8eir4ddSD5wqRcseuOlc/VUmK3"
183  "Cyn+7Fhk4ZwFT/mRKSgORkYhd5GBEUKCA0EmPFMVAjEAjLkegqM4bSgPXW9+UOZB"
184  "3xUvcQntVFazHxZubKwEJafPOrava3/DEDuIMgLpBGVlAgEB"
185  "-----END EC PARAMETERS-----";
186 
187  if(name == "brainpool512r1")
188  return
189  "-----BEGIN EC PARAMETERS-----"
190  "MIIBogIBATBMBgcqhkjOPQEBAkEAqt2duNvpxIs/1OauM8n8B8swjbOzydIO1mOc"
191  "ynAzCHF9TZsAm8ZoQq7NoSrmo4DmKIH/Ly2CxoUoqmBWWDpI8zCBhARAeDCjMYtg"
192  "O4niMnFFrCNMxZTL3Y09+RYQqDRByuqYY7wt7V1aqCU6oQou8cmLmsi1fxEXpyvy"
193  "x7nnwaxNd/yUygRAPfkWEKg0QcrqmGO8Le1dWqglOqEKLvHJi5rItX8RF6cr8se5"
194  "58GsTXf8lMrcCD5nmEBQt1665d0oCb1jgBb3IwSBgQSBruS92C7ZZFohMi6cTGqT"
195  "he2fcLXZFsG0O2Lu9NAJjv87H3ji0NSNUNFoe5O5fV98bVBHQGpeaIs1Igm8ufgi"
196  "fd44XVZjMuzA6r+pz3gi/fIJ9wAkpXsaoADFW4gfgRGy3N5JSl9IXlvKS9iKJ2Ou"
197  "0corL6jwVAZ4zR4POtgIkgJBAKrdnbjb6cSLP9TmrjPJ/AfLMI2zs8nSDtZjnMpw"
198  "MwhwVT5cQUypJhlBhmEZf6wQRx2x04EIXdrdtYeWgpypAGkCAQE="
199  "-----END EC PARAMETERS-----";
200 
201  if(name == "x962_p192v2")
202  return
203  "-----BEGIN EC PARAMETERS-----"
204  "MIGwAgEBMCQGByqGSM49AQECGQD////////////////////+//////////8wNAQY"
205  "/////////////////////v/////////8BBjMItbfuVxrJeScDWNkpOWYDDk6ohZo"
206  "2VMEMQTuorrn4Ul4QvLed2nP6cmJwHKtaW9IA0pldNEdabbsemcruCoIPfLysIR9"
207  "6XCy3hUCGQD///////////////5fsack3IBBhkjY3TECAQE="
208  "-----END EC PARAMETERS-----";
209 
210  if(name == "x962_p192v3")
211  return
212  "-----BEGIN EC PARAMETERS-----"
213  "MIGwAgEBMCQGByqGSM49AQECGQD////////////////////+//////////8wNAQY"
214  "/////////////////////v/////////8BBgiEj3COVoFyqdCPa7MyUdgp9RiJWvV"
215  "aRYEMQR9KXeBAMZaHaF4NxZYjc4ri0rujiKPGJY4qQ8iY3M3M0tJ3LZqbcj5l4rK"
216  "dkipQ7ACGQD///////////////96YtAxyD9ClPZA7BMCAQE="
217  "-----END EC PARAMETERS-----";
218 
219  if(name == "x962_p239v1")
220  return
221  "-----BEGIN EC PARAMETERS-----"
222  "MIHSAgEBMCkGByqGSM49AQECHn///////////////3///////4AAAAAAAH//////"
223  "/zBABB5///////////////9///////+AAAAAAAB///////wEHmsBbDvc8YlB0NZU"
224  "khR1ynGp2y+yfR03eWGFwpQsCgQ9BA/6ljzcqIFszDO4ZCvt+QXD01hXPT8n+707"
225  "PLmqr33r6OTpCl2ubkBUylMLoEZUs2gYziJrOfzLewLxrgIef///////////////"
226  "f///nl6an12QcfvRUiaIkJ0LAgEB"
227  "-----END EC PARAMETERS-----";
228 
229  if(name == "x962_p239v2")
230  return
231  "-----BEGIN EC PARAMETERS-----"
232  "MIHSAgEBMCkGByqGSM49AQECHn///////////////3///////4AAAAAAAH//////"
233  "/zBABB5///////////////9///////+AAAAAAAB///////wEHmF/q2gyV2y7/tUN"
234  "mfAknD/uWLlLoAOMeuhMjIMvLAQ9BDivCdmHJ3BRIMkhu16eJilqPNzy81dXoOr9"
235  "h7gw51sBJeTb6g7HIG2g/AHZsIEyn7VV3m70YCN9/4vkugIef///////////////"
236  "gAAAz6foWUN31BTAOCG8WCBjAgEB"
237  "-----END EC PARAMETERS-----";
238 
239  if(name == "x962_p239v3")
240  return
241  "-----BEGIN EC PARAMETERS-----"
242  "MIHSAgEBMCkGByqGSM49AQECHn///////////////3///////4AAAAAAAH//////"
243  "/zBABB5///////////////9///////+AAAAAAAB///////wEHiVXBfoqMGZUsfTL"
244  "A9anUKMMJQEC1JiHF9m6FattPgQ9BGdoro4Yu5LPzwBclJqixtlIU9DmYLv4VLHJ"
245  "UF/pWhYH5omPOQwGvB1VK60ibztvz+SLboGEma8Y4+1s8wIef///////////////"
246  "f///l13rQbOmBXw8QyFGUmVRAgEB"
247  "-----END EC PARAMETERS-----";
248 
249  if(name == "gost_256A")
250  return
251  "-----BEGIN EC PARAMETERS-----"
252  "MIHgAgEBMCwGByqGSM49AQECIQD/////////////////////////////////////"
253  "///9lzBEBCD////////////////////////////////////////9lAQgAAAAAAAA"
254  "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAKYEQQQAAAAAAAAAAAAAAAAAAAAAAAAA"
255  "AAAAAAAAAAAAAAAAAY2R5HHgmJzaJ99QWkU/K3Y1KU8t3yPjsSKsyZyenx4UAiEA"
256  "/////////////////////2xhEHCZWtEARYQbCbdhuJMCAQE="
257  "-----END EC PARAMETERS-----";
258 
259  if(name == "frp256v1")
260  return
261  "-----BEGIN EC PARAMETERS-----"
262  "MIHgAgEBMCwGByqGSM49AQECIQDx/ReMCzrVjxASbejOQkNbOWGtvKvIym3o/PNT"
263  "2G6cAzBEBCDx/ReMCzrVjxASbejOQkNbOWGtvKvIym3o/PNT2G6cAAQg7jU/ylQo"
264  "qTANSrp1SkTAD9/sDJrksaGAMHXtlnt7tz8EQQS2s9TDVsE56zEYPUdJ1COVjCfS"
265  "3K+YtwFkyXot2Y9c/2FC4PfIsgSRH5Jx8PPs74wnAcMH6OTJ4YMRWhVUBiz7AiEA"
266  "8f0XjAs61Y8QEm3ozkJDW1PcZ+FA0r+UH/3UWcbWVeECAQE="
267  "-----END EC PARAMETERS-----";
268 
269  if(name == "sm2p256v1")
270  return
271  "-----BEGIN EC PARAMETERS-----"
272  "MIHgAgEBMCwGByqGSM49AQECIQD////+/////////////////////wAAAAD/////"
273  "/////zBEBCD////+/////////////////////wAAAAD//////////AQgKOn6np2f"
274  "XjRNWp5Lz2UJp/OXifUVq4+S3by9QU2UDpMEQQQyxK4sHxmBGV+ZBEZqOcmUj+ML"
275  "v/JmC+FxWkWJM0x0x7w3NqL09necWb3O42tpIVPQqYd8xipHQALfMuUhOfCgAiEA"
276  "/////v///////////////3ID32shxgUrU7v0CTnVQSMCAQE="
277  "-----END EC PARAMETERS-----";
278 
279 #if defined(BOTAN_HOUSE_ECC_CURVE_NAME)
280  if(name == BOTAN_HOUSE_ECC_CURVE_NAME)
281  return BOTAN_HOUSE_ECC_CURVE_PEM;
282 #endif
283 
284  return "";
285  }

◆ verify_group()

bool Botan::EC_Group::verify_group ( RandomNumberGenerator rng,
bool  strong = false 
) const

Verify EC_Group domain

Returns
true if group is valid. false otherwise

Definition at line 142 of file ec_group.cpp.

References Botan::CurveGFp::get_a(), Botan::CurveGFp::get_b(), Botan::CurveGFp::get_p(), Botan::is_prime(), and Botan::PointGFp::on_the_curve().

Referenced by Botan::EC_PublicKey::check_key().

144  {
145  //compute the discriminant
146  Modular_Reducer p(m_curve.get_p());
147  BigInt discriminant = p.multiply(4, m_curve.get_a());
148  discriminant += p.multiply(27, m_curve.get_b());
149  discriminant = p.reduce(discriminant);
150  //check the discriminant
151  if(discriminant == 0)
152  {
153  return false;
154  }
155  //check for valid cofactor
156  if(m_cofactor < 1)
157  {
158  return false;
159  }
160  //check if the base point is on the curve
161  if(!m_base_point.on_the_curve())
162  {
163  return false;
164  }
165  if((m_base_point * m_cofactor).is_zero())
166  {
167  return false;
168  }
169  //check if order is prime
170  if(!is_prime(m_order, rng, 128))
171  {
172  return false;
173  }
174  //check if order of the base point is correct
175  if(!(m_base_point * m_order).is_zero())
176  {
177  return false;
178  }
179  return true;
180  }
bool is_prime(const BigInt &n, RandomNumberGenerator &rng, size_t prob, bool is_random)
Definition: numthry.cpp:455
const BigInt & get_b() const
Definition: curve_gfp.h:85
bool on_the_curve() const
Definition: point_gfp.cpp:413
const BigInt & get_a() const
Definition: curve_gfp.h:80
const BigInt & get_p() const
Definition: curve_gfp.h:91

The documentation for this class was generated from the following files: