6 #ifndef CRYPTOPP_ECCRYPTO_H
7 #define CRYPTOPP_ECCRYPTO_H
36 typedef EC EllipticCurve;
37 typedef typename EllipticCurve::Point Point;
38 typedef Point Element;
43 : m_compress(
false), m_encodeAsOID(
false) {Initialize(oid);}
45 : m_compress(
false), m_encodeAsOID(
false) {Initialize(ec, G, n, k);}
47 : m_compress(
false), m_encodeAsOID(
false) {BERDecode(bt);}
51 this->m_groupPrecomputation.SetCurve(ec);
56 void Initialize(
const OID &oid);
59 bool GetVoidValue(
const char *name,
const std::type_info &valueType,
void *pValue)
const;
70 const Integer & GetSubgroupOrder()
const {
return m_n;}
74 bool FastSubgroupCheckAvailable()
const {
return false;}
75 void EncodeElement(
bool reversible,
const Element &element,
byte *encoded)
const
78 GetCurve().EncodePoint(encoded, element, m_compress);
85 return GetCurve().EncodedPointSize(m_compress);
87 return GetCurve().GetField().MaxElementByteLength();
89 Element
DecodeElement(
const byte *encoded,
bool checkForGroupMembership)
const
94 if (checkForGroupMembership && !ValidateElement(1, result, NULL))
98 Integer ConvertElementToInteger(
const Element &element)
const;
99 Integer GetMaxExponent()
const {
return GetSubgroupOrder()-1;}
100 bool IsIdentity(
const Element &element)
const {
return element.identity;}
101 void SimultaneousExponentiate(Element *results,
const Element &base,
const Integer *exponents,
unsigned int exponentsCount)
const;
102 static std::string CRYPTOPP_API StaticAlgorithmNamePrefix() {
return "EC";}
105 OID GetAlgorithmID()
const;
108 Element MultiplyElements(
const Element &a,
const Element &b)
const;
109 Element CascadeExponentiate(
const Element &element1,
const Integer &exponent1,
const Element &element2,
const Integer &exponent2)
const;
114 static OID CRYPTOPP_API GetNextRecommendedParametersOID(
const OID &oid);
119 void SetPointCompression(
bool compress) {m_compress = compress;}
120 bool GetPointCompression()
const {
return m_compress;}
122 void SetEncodeAsOID(
bool encodeAsOID) {m_encodeAsOID = encodeAsOID;}
123 bool GetEncodeAsOID()
const {
return m_encodeAsOID;}
125 const EllipticCurve& GetCurve()
const {
return this->m_groupPrecomputation.GetCurve();}
127 bool operator==(
const ThisClass &rhs)
const
128 {
return this->m_groupPrecomputation.GetCurve() == rhs.m_groupPrecomputation.GetCurve() && this->m_gpc.GetBase(this->m_groupPrecomputation) == rhs.m_gpc.GetBase(rhs.m_groupPrecomputation);}
130 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY
132 const Integer& GetBasePointOrder()
const {
return this->GetSubgroupOrder();}
133 void LoadRecommendedParameters(
const OID &oid) {Initialize(oid);}
136 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
141 unsigned int FieldElementLength()
const {
return GetCurve().GetField().MaxElementByteLength();}
142 unsigned int ExponentLength()
const {
return m_n.
ByteCount();}
147 mutable bool m_compress, m_encodeAsOID;
155 typedef typename EC::Point Element;
158 {this->AccessGroupParameters() = params; this->SetPublicElement(Q);}
159 void Initialize(
const EC &ec,
const Element &G,
const Integer &n,
const Element &Q)
160 {this->AccessGroupParameters().Initialize(ec, G, n); this->SetPublicElement(Q);}
166 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
176 typedef typename EC::Point Element;
179 {this->AccessGroupParameters() = params; this->SetPrivateExponent(x);}
180 void Initialize(
const EC &ec,
const Element &G,
const Integer &n,
const Integer &x)
181 {this->AccessGroupParameters().Initialize(ec, G, n); this->SetPrivateExponent(x);}
191 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
197 template <class EC, class COFACTOR_OPTION = CPP_TYPENAME DL_GroupParameters_EC<EC>::DefaultCofactorOption>
202 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
208 template <class EC, class COFACTOR_OPTION = CPP_TYPENAME DL_GroupParameters_EC<EC>::DefaultCofactorOption>
213 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
221 template <class EC, class COFACTOR_OPTION = CPP_TYPENAME DL_GroupParameters_EC<EC>::DefaultCofactorOption,
class HASH =
SHA256>
226 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
240 template <class EC, class COFACTOR_OPTION = CPP_TYPENAME DL_GroupParameters_EC<EC>::DefaultCofactorOption,
class HASH =
SHA256>
245 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
262 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
267 template <
class EC,
class H>
277 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
287 CRYPTOPP_CONSTEXPR
static const char * CRYPTOPP_API StaticAlgorithmName() {
return "ECDSA";}
289 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
299 CRYPTOPP_CONSTEXPR
static const char * CRYPTOPP_API StaticAlgorithmName() {
return "ECNR";}
301 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
307 template <
class EC,
class H>
308 struct ECDSA :
public DL_SS<DL_Keys_ECDSA<EC>, DL_Algorithm_ECDSA<EC>, DL_SignatureMessageEncodingMethod_DSA, H>
310 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
316 template <
class EC,
class H = SHA>
317 struct ECNR :
public DL_SS<DL_Keys_EC<EC>, DL_Algorithm_ECNR<EC>, DL_SignatureMessageEncodingMethod_NR, H>
319 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
328 template <
class EC,
class COFACTOR_OPTION = NoCofactorMultiplication,
bool DHAES_MODE = false>
332 DL_KeyAgreementAlgorithm_DH<typename EC::Point, COFACTOR_OPTION>,
333 DL_KeyDerivationAlgorithm_P1363<typename EC::Point, DHAES_MODE, P1363_KDF2<SHA1> >,
334 DL_EncryptionAlgorithm_Xor<HMAC<SHA1>, DHAES_MODE>,
337 static std::string CRYPTOPP_API StaticAlgorithmName() {
return "ECIES";}
339 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
343 #if (CRYPTOPP_GCC_VERSION >= 40500) || (CRYPTOPP_LLVM_CLANG_VERSION >= 20800)
344 } __attribute__((deprecated (
"ECIES will be changing in the near future due to (1) an implementation bug and (2) an interop issue")));
345 #elif (CRYPTOPP_GCC_VERSION)
346 } __attribute__((deprecated));
353 #ifdef CRYPTOPP_MANUALLY_INSTANTIATE_TEMPLATES
354 #include "eccrypto.cpp"