Botan
1.11.15
|
00001 /* 00002 * ECC Domain Parameters 00003 * 00004 * (C) 2007 Falko Strenzke, FlexSecure GmbH 00005 * 2008-2010 Jack Lloyd 00006 * 00007 * Botan is released under the Simplified BSD License (see license.txt) 00008 */ 00009 00010 #ifndef BOTAN_ECC_DOMAIN_PARAMETERS_H__ 00011 #define BOTAN_ECC_DOMAIN_PARAMETERS_H__ 00012 00013 #include <botan/point_gfp.h> 00014 #include <botan/curve_gfp.h> 00015 #include <botan/asn1_oid.h> 00016 00017 namespace Botan { 00018 00019 /** 00020 * This class represents elliptic curce domain parameters 00021 */ 00022 enum EC_Group_Encoding { 00023 EC_DOMPAR_ENC_EXPLICIT = 0, 00024 EC_DOMPAR_ENC_IMPLICITCA = 1, 00025 EC_DOMPAR_ENC_OID = 2 00026 }; 00027 00028 /** 00029 * Class representing an elliptic curve 00030 */ 00031 class BOTAN_DLL EC_Group 00032 { 00033 public: 00034 00035 /** 00036 * Construct Domain paramers from specified parameters 00037 * @param curve elliptic curve 00038 * @param base_point a base point 00039 * @param order the order of the base point 00040 * @param cofactor the cofactor 00041 */ 00042 EC_Group(const CurveGFp& curve, 00043 const PointGFp& base_point, 00044 const BigInt& order, 00045 const BigInt& cofactor) : 00046 curve(curve), 00047 base_point(base_point), 00048 order(order), 00049 cofactor(cofactor), 00050 oid("") 00051 {} 00052 00053 /** 00054 * Decode a BER encoded ECC domain parameter set 00055 * @param ber_encoding the bytes of the BER encoding 00056 */ 00057 EC_Group(const std::vector<byte>& ber_encoding); 00058 00059 /** 00060 * Create an EC domain by OID (or throw if unknown) 00061 * @param oid the OID of the EC domain to create 00062 */ 00063 EC_Group(const OID& oid); 00064 00065 /** 00066 * Create an EC domain from PEM encoding (as from PEM_encode), or 00067 * from an OID name (eg "secp256r1", or "1.2.840.10045.3.1.7") 00068 * @param pem_or_oid PEM-encoded data, or an OID 00069 */ 00070 EC_Group(const std::string& pem_or_oid = ""); 00071 00072 /** 00073 * Create the DER encoding of this domain 00074 * @param form of encoding to use 00075 * @returns bytes encododed as DER 00076 */ 00077 std::vector<byte> DER_encode(EC_Group_Encoding form) const; 00078 00079 /** 00080 * Return the PEM encoding (always in explicit form) 00081 * @return string containing PEM data 00082 */ 00083 std::string PEM_encode() const; 00084 00085 /** 00086 * Return domain parameter curve 00087 * @result domain parameter curve 00088 */ 00089 const CurveGFp& get_curve() const { return curve; } 00090 00091 /** 00092 * Return group base point 00093 * @result base point 00094 */ 00095 const PointGFp& get_base_point() const { return base_point; } 00096 00097 /** 00098 * Return the order of the base point 00099 * @result order of the base point 00100 */ 00101 const BigInt& get_order() const { return order; } 00102 00103 /** 00104 * Return the cofactor 00105 * @result the cofactor 00106 */ 00107 const BigInt& get_cofactor() const { return cofactor; } 00108 00109 bool initialized() const { return !base_point.is_zero(); } 00110 00111 /** 00112 * Return the OID of these domain parameters 00113 * @result the OID 00114 */ 00115 std::string get_oid() const { return oid; } 00116 00117 bool operator==(const EC_Group& other) const 00118 { 00119 return ((get_curve() == other.get_curve()) && 00120 (get_base_point() == other.get_base_point()) && 00121 (get_order() == other.get_order()) && 00122 (get_cofactor() == other.get_cofactor())); 00123 } 00124 00125 /** 00126 * Return PEM representation of named EC group 00127 */ 00128 static const char* PEM_for_named_group(const std::string& name); 00129 00130 private: 00131 CurveGFp curve; 00132 PointGFp base_point; 00133 BigInt order, cofactor; 00134 std::string oid; 00135 }; 00136 00137 inline bool operator!=(const EC_Group& lhs, 00138 const EC_Group& rhs) 00139 { 00140 return !(lhs == rhs); 00141 } 00142 00143 // For compatability with 1.8 00144 typedef EC_Group EC_Domain_Params; 00145 00146 } 00147 00148 #endif