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);
52 this->SetSubgroupGenerator(G);
56 void Initialize(
const OID &oid);
59 bool GetVoidValue(
const char *name,
const std::type_info &valueType,
void *pValue)
const;
74 bool FastSubgroupCheckAvailable()
const {
return false;}
75 void EncodeElement(
bool reversible,
const Element &element, byte *encoded)
const 78 GetCurve().EncodePoint(encoded, element, m_compress);
80 element.x.Encode(encoded, GetEncodedElementSize(
false));
85 return GetCurve().EncodedPointSize(m_compress);
87 return GetCurve().GetField().MaxElementByteLength();
89 Element
DecodeElement(
const byte *encoded,
bool checkForGroupMembership)
const 92 if (!GetCurve().DecodePoint(result, encoded, GetEncodedElementSize(
true)))
94 if (checkForGroupMembership && !ValidateElement(1, result, NULL))
98 Integer ConvertElementToInteger(
const Element &element)
const;
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();}
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 131 const Point& GetBasePoint()
const {
return this->GetSubgroupGenerator();}
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);}
183 {this->GenerateRandom(rng, params);}
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" implements the SHA-384 standard
void DEREncodePublicKey(BufferedTransformation &bt) const
encode subjectPublicKey part of subjectPublicKeyInfo, without the BIT STRING header ...
Classes for Fully Hashed Menezes-Qu-Vanstone key agreement in GF(p)
implements the SHA-256 standard
Integer GetMaxExponent() const
Retrieves the maximum exponent for the group.
This file contains helper classes/functions for implementing public key algorithms.
Classes for Elliptic Curves over prime fields.
Fully Hashed Menezes-Qu-Vanstone in GF(p)
Fully Hashed Menezes-Qu-Vanstone in ECP or EC2N.
Converts a typename to an enumerated value.
Abstract base classes that provide a uniform interface to this library.
Hashed Menezes-Qu-Vanstone in GF(p)
DL_FixedBasePrecomputation< Element > & AccessBasePrecomputation()
Retrieves the group precomputation.
Library configuration file.
Interface for random number generators.
Discrete Log (DL) encryption scheme.
const Integer & GetSubgroupOrder() const
Retrieves the subgroup order.
bool operator==(const OID &lhs, const OID &rhs)
Compare two OIDs for equality.
Classes for Hashed Menezes-Qu-Vanstone key agreement in GF(p)
Discrete Log (DL) signature scheme.
Classes for Elliptic Curves over binary fields.
Classes for HMAC message authentication codes.
MQV domain for performing authenticated key agreement.
Hashed Menezes-Qu-Vanstone in ECP or EC2N.
Classes for Diffie-Hellman key exchange.
implements the SHA-512 standard
Elliptic Curve Menezes-Qu-Vanstone, AKA ECMQV
Multiple precision integer with arithmetic operations.
Elliptic Curve Integrated Encryption Scheme, AKA ECIES
Implementation of schemes based on DL over GF(p)
virtual unsigned int GetEncodedElementSize(bool reversible) const
Retrieves the encoded element's size.
Element DecodeElement(const byte *encoded, bool checkForGroupMembership) const
Decodes the element.
Exception thrown when an invalid group element is encountered.
Elliptic Curve Diffie-Hellman, AKA ECDH
Classes and functions for working with ANS.1 objects.
Classes for SHA-1 and SHA-2 family of message digests.
Elliptic Curve Parameters.
Multiple precision integer with arithmetic operations.
static const Integer & Zero()
Integer representing 0.
Crypto++ library namespace.
const DL_FixedBasePrecomputation< Element > & GetBasePrecomputation() const
Retrieves the group precomputation.
Base implmentation of Discrete Log (DL) group parameters.
Classes for Menezes–Qu–Vanstone (MQV) key agreement.
void BERDecodePublicKey(BufferedTransformation &bt, bool parametersPresent, size_t size)
decode subjectPublicKey part of subjectPublicKeyInfo, without the BIT STRING header ...
Interface for retrieving values given their names.