00001
00002
00003
00004
00005
00006 #ifndef CRYPTOPP_ECCRYPTO_H
00007 #define CRYPTOPP_ECCRYPTO_H
00008
00009 #include "config.h"
00010 #include "cryptlib.h"
00011 #include "pubkey.h"
00012 #include "integer.h"
00013 #include "asn.h"
00014 #include "hmac.h"
00015 #include "sha.h"
00016 #include "gfpcrypt.h"
00017 #include "dh.h"
00018 #include "mqv.h"
00019 #include "ecp.h"
00020 #include "ec2n.h"
00021
00022 NAMESPACE_BEGIN(CryptoPP)
00023
00024
00025
00026
00027
00028 template <class EC>
00029 class DL_GroupParameters_EC : public DL_GroupParametersImpl<EcPrecomputation<EC> >
00030 {
00031 typedef DL_GroupParameters_EC<EC> ThisClass;
00032
00033 public:
00034 typedef EC EllipticCurve;
00035 typedef typename EllipticCurve::Point Point;
00036 typedef Point Element;
00037 typedef IncompatibleCofactorMultiplication DefaultCofactorOption;
00038
00039 DL_GroupParameters_EC() : m_compress(false), m_encodeAsOID(false) {}
00040 DL_GroupParameters_EC(const OID &oid)
00041 : m_compress(false), m_encodeAsOID(false) {Initialize(oid);}
00042 DL_GroupParameters_EC(const EllipticCurve &ec, const Point &G, const Integer &n, const Integer &k = Integer::Zero())
00043 : m_compress(false), m_encodeAsOID(false) {Initialize(ec, G, n, k);}
00044 DL_GroupParameters_EC(BufferedTransformation &bt)
00045 : m_compress(false), m_encodeAsOID(false) {BERDecode(bt);}
00046
00047 void Initialize(const EllipticCurve &ec, const Point &G, const Integer &n, const Integer &k = Integer::Zero())
00048 {
00049 this->m_groupPrecomputation.SetCurve(ec);
00050 this->SetSubgroupGenerator(G);
00051 m_n = n;
00052 m_k = k;
00053 }
00054 void Initialize(const OID &oid);
00055
00056
00057 bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const;
00058 void AssignFrom(const NameValuePairs &source);
00059
00060
00061
00062
00063 void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg);
00064
00065
00066 const DL_FixedBasePrecomputation<Element> & GetBasePrecomputation() const {return this->m_gpc;}
00067 DL_FixedBasePrecomputation<Element> & AccessBasePrecomputation() {return this->m_gpc;}
00068 const Integer & GetSubgroupOrder() const {return m_n;}
00069 Integer GetCofactor() const;
00070 bool ValidateGroup(RandomNumberGenerator &rng, unsigned int level) const;
00071 bool ValidateElement(unsigned int level, const Element &element, const DL_FixedBasePrecomputation<Element> *precomp) const;
00072 bool FastSubgroupCheckAvailable() const {return false;}
00073 void EncodeElement(bool reversible, const Element &element, byte *encoded) const
00074 {
00075 if (reversible)
00076 GetCurve().EncodePoint(encoded, element, m_compress);
00077 else
00078 element.x.Encode(encoded, GetEncodedElementSize(false));
00079 }
00080 virtual unsigned int GetEncodedElementSize(bool reversible) const
00081 {
00082 if (reversible)
00083 return GetCurve().EncodedPointSize(m_compress);
00084 else
00085 return GetCurve().GetField().MaxElementByteLength();
00086 }
00087 Element DecodeElement(const byte *encoded, bool checkForGroupMembership) const
00088 {
00089 Point result;
00090 if (!GetCurve().DecodePoint(result, encoded, GetEncodedElementSize(true)))
00091 throw DL_BadElement();
00092 if (checkForGroupMembership && !ValidateElement(1, result, NULL))
00093 throw DL_BadElement();
00094 return result;
00095 }
00096 Integer ConvertElementToInteger(const Element &element) const;
00097 Integer GetMaxExponent() const {return GetSubgroupOrder()-1;}
00098 bool IsIdentity(const Element &element) const {return element.identity;}
00099 void SimultaneousExponentiate(Element *results, const Element &base, const Integer *exponents, unsigned int exponentsCount) const;
00100 static std::string CRYPTOPP_API StaticAlgorithmNamePrefix() {return "EC";}
00101
00102
00103 OID GetAlgorithmID() const;
00104
00105
00106 Element MultiplyElements(const Element &a, const Element &b) const;
00107 Element CascadeExponentiate(const Element &element1, const Integer &exponent1, const Element &element2, const Integer &exponent2) const;
00108
00109
00110
00111
00112 static OID CRYPTOPP_API GetNextRecommendedParametersOID(const OID &oid);
00113
00114 void BERDecode(BufferedTransformation &bt);
00115 void DEREncode(BufferedTransformation &bt) const;
00116
00117 void SetPointCompression(bool compress) {m_compress = compress;}
00118 bool GetPointCompression() const {return m_compress;}
00119
00120 void SetEncodeAsOID(bool encodeAsOID) {m_encodeAsOID = encodeAsOID;}
00121 bool GetEncodeAsOID() const {return m_encodeAsOID;}
00122
00123 const EllipticCurve& GetCurve() const {return this->m_groupPrecomputation.GetCurve();}
00124
00125 bool operator==(const ThisClass &rhs) const
00126 {return this->m_groupPrecomputation.GetCurve() == rhs.m_groupPrecomputation.GetCurve() && this->m_gpc.GetBase(this->m_groupPrecomputation) == rhs.m_gpc.GetBase(rhs.m_groupPrecomputation);}
00127
00128 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY
00129 const Point& GetBasePoint() const {return this->GetSubgroupGenerator();}
00130 const Integer& GetBasePointOrder() const {return this->GetSubgroupOrder();}
00131 void LoadRecommendedParameters(const OID &oid) {Initialize(oid);}
00132 #endif
00133
00134 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
00135 virtual ~DL_GroupParameters_EC() {}
00136 #endif
00137
00138 protected:
00139 unsigned int FieldElementLength() const {return GetCurve().GetField().MaxElementByteLength();}
00140 unsigned int ExponentLength() const {return m_n.ByteCount();}
00141
00142 OID m_oid;
00143 Integer m_n;
00144 mutable Integer m_k;
00145 mutable bool m_compress, m_encodeAsOID;
00146 };
00147
00148
00149 template <class EC>
00150 class DL_PublicKey_EC : public DL_PublicKeyImpl<DL_GroupParameters_EC<EC> >
00151 {
00152 public:
00153 typedef typename EC::Point Element;
00154
00155 void Initialize(const DL_GroupParameters_EC<EC> ¶ms, const Element &Q)
00156 {this->AccessGroupParameters() = params; this->SetPublicElement(Q);}
00157 void Initialize(const EC &ec, const Element &G, const Integer &n, const Element &Q)
00158 {this->AccessGroupParameters().Initialize(ec, G, n); this->SetPublicElement(Q);}
00159
00160
00161 void BERDecodePublicKey(BufferedTransformation &bt, bool parametersPresent, size_t size);
00162 void DEREncodePublicKey(BufferedTransformation &bt) const;
00163
00164 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
00165 virtual ~DL_PublicKey_EC() {}
00166 #endif
00167 };
00168
00169
00170 template <class EC>
00171 class DL_PrivateKey_EC : public DL_PrivateKeyImpl<DL_GroupParameters_EC<EC> >
00172 {
00173 public:
00174 typedef typename EC::Point Element;
00175
00176 void Initialize(const DL_GroupParameters_EC<EC> ¶ms, const Integer &x)
00177 {this->AccessGroupParameters() = params; this->SetPrivateExponent(x);}
00178 void Initialize(const EC &ec, const Element &G, const Integer &n, const Integer &x)
00179 {this->AccessGroupParameters().Initialize(ec, G, n); this->SetPrivateExponent(x);}
00180 void Initialize(RandomNumberGenerator &rng, const DL_GroupParameters_EC<EC> ¶ms)
00181 {this->GenerateRandom(rng, params);}
00182 void Initialize(RandomNumberGenerator &rng, const EC &ec, const Element &G, const Integer &n)
00183 {this->GenerateRandom(rng, DL_GroupParameters_EC<EC>(ec, G, n));}
00184
00185
00186 void BERDecodePrivateKey(BufferedTransformation &bt, bool parametersPresent, size_t size);
00187 void DEREncodePrivateKey(BufferedTransformation &bt) const;
00188
00189 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
00190 virtual ~DL_PrivateKey_EC() {}
00191 #endif
00192 };
00193
00194
00195 template <class EC, class COFACTOR_OPTION = CPP_TYPENAME DL_GroupParameters_EC<EC>::DefaultCofactorOption>
00196 struct ECDH
00197 {
00198 typedef DH_Domain<DL_GroupParameters_EC<EC>, COFACTOR_OPTION> Domain;
00199
00200 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
00201 virtual ~ECDH() {}
00202 #endif
00203 };
00204
00205
00206 template <class EC, class COFACTOR_OPTION = CPP_TYPENAME DL_GroupParameters_EC<EC>::DefaultCofactorOption>
00207 struct ECMQV
00208 {
00209 typedef MQV_Domain<DL_GroupParameters_EC<EC>, COFACTOR_OPTION> Domain;
00210
00211 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
00212 virtual ~ECMQV() {}
00213 #endif
00214 };
00215
00216
00217 template <class EC>
00218 struct DL_Keys_EC
00219 {
00220 typedef DL_PublicKey_EC<EC> PublicKey;
00221 typedef DL_PrivateKey_EC<EC> PrivateKey;
00222
00223 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
00224 virtual ~DL_Keys_EC() {}
00225 #endif
00226 };
00227
00228 template <class EC, class H>
00229 struct ECDSA;
00230
00231
00232 template <class EC>
00233 struct DL_Keys_ECDSA
00234 {
00235 typedef DL_PublicKey_EC<EC> PublicKey;
00236 typedef DL_PrivateKey_WithSignaturePairwiseConsistencyTest<DL_PrivateKey_EC<EC>, ECDSA<EC, SHA256> > PrivateKey;
00237
00238 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
00239 virtual ~DL_Keys_ECDSA() {}
00240 #endif
00241 };
00242
00243
00244 template <class EC>
00245 class DL_Algorithm_ECDSA : public DL_Algorithm_GDSA<typename EC::Point>
00246 {
00247 public:
00248 static const char * CRYPTOPP_API StaticAlgorithmName() {return "ECDSA";}
00249
00250 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
00251 virtual ~DL_Algorithm_ECDSA() {}
00252 #endif
00253 };
00254
00255
00256 template <class EC>
00257 class DL_Algorithm_ECNR : public DL_Algorithm_NR<typename EC::Point>
00258 {
00259 public:
00260 static const char * CRYPTOPP_API StaticAlgorithmName() {return "ECNR";}
00261
00262 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
00263 virtual ~DL_Algorithm_ECNR() {}
00264 #endif
00265 };
00266
00267
00268 template <class EC, class H>
00269 struct ECDSA : public DL_SS<DL_Keys_ECDSA<EC>, DL_Algorithm_ECDSA<EC>, DL_SignatureMessageEncodingMethod_DSA, H>
00270 {
00271 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
00272 virtual ~ECDSA() {}
00273 #endif
00274 };
00275
00276
00277 template <class EC, class H = SHA>
00278 struct ECNR : public DL_SS<DL_Keys_EC<EC>, DL_Algorithm_ECNR<EC>, DL_SignatureMessageEncodingMethod_NR, H>
00279 {
00280 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
00281 virtual ~ECNR() {}
00282 #endif
00283 };
00284
00285
00286
00287
00288
00289 template <class EC, class COFACTOR_OPTION = NoCofactorMultiplication, bool DHAES_MODE = false>
00290 struct ECIES
00291 : public DL_ES<
00292 DL_Keys_EC<EC>,
00293 DL_KeyAgreementAlgorithm_DH<typename EC::Point, COFACTOR_OPTION>,
00294 DL_KeyDerivationAlgorithm_P1363<typename EC::Point, DHAES_MODE, P1363_KDF2<SHA1> >,
00295 DL_EncryptionAlgorithm_Xor<HMAC<SHA1>, DHAES_MODE>,
00296 ECIES<EC> >
00297 {
00298 static std::string CRYPTOPP_API StaticAlgorithmName() {return "ECIES";}
00299
00300 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
00301 virtual ~ECIES() {}
00302 #endif
00303
00304 #if (CRYPTOPP_GCC_VERSION >= 40500) || (CRYPTOPP_CLANG_VERSION >= 30000)
00305 } __attribute__((deprecated ("ECIES will be changing in the near future due to (1) an implementation bug and (2) an interop issue.")));
00306 #elif (CRYPTOPP_GCC_VERSION )
00307 } __attribute__((deprecated));
00308 #else
00309 };
00310 #endif
00311
00312 NAMESPACE_END
00313
00314 #ifdef CRYPTOPP_MANUALLY_INSTANTIATE_TEMPLATES
00315 #include "eccrypto.cpp"
00316 #endif
00317
00318 NAMESPACE_BEGIN(CryptoPP)
00319
00320 CRYPTOPP_DLL_TEMPLATE_CLASS DL_GroupParameters_EC<ECP>;
00321 CRYPTOPP_DLL_TEMPLATE_CLASS DL_GroupParameters_EC<EC2N>;
00322 CRYPTOPP_DLL_TEMPLATE_CLASS DL_PublicKeyImpl<DL_GroupParameters_EC<ECP> >;
00323 CRYPTOPP_DLL_TEMPLATE_CLASS DL_PublicKeyImpl<DL_GroupParameters_EC<EC2N> >;
00324 CRYPTOPP_DLL_TEMPLATE_CLASS DL_PublicKey_EC<ECP>;
00325 CRYPTOPP_DLL_TEMPLATE_CLASS DL_PublicKey_EC<EC2N>;
00326 CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKeyImpl<DL_GroupParameters_EC<ECP> >;
00327 CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKeyImpl<DL_GroupParameters_EC<EC2N> >;
00328 CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKey_EC<ECP>;
00329 CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKey_EC<EC2N>;
00330 CRYPTOPP_DLL_TEMPLATE_CLASS DL_Algorithm_GDSA<ECP::Point>;
00331 CRYPTOPP_DLL_TEMPLATE_CLASS DL_Algorithm_GDSA<EC2N::Point>;
00332 CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKey_WithSignaturePairwiseConsistencyTest<DL_PrivateKey_EC<ECP>, ECDSA<ECP, SHA256> >;
00333 CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKey_WithSignaturePairwiseConsistencyTest<DL_PrivateKey_EC<EC2N>, ECDSA<EC2N, SHA256> >;
00334
00335 NAMESPACE_END
00336
00337 #endif
00338 #ifndef CRYPTOPP_ECCRYPTO_H
00339 #define CRYPTOPP_ECCRYPTO_H
00340
00341
00342
00343
00344 #include "cryptlib.h"
00345 #include "pubkey.h"
00346 #include "integer.h"
00347 #include "asn.h"
00348 #include "hmac.h"
00349 #include "sha.h"
00350 #include "gfpcrypt.h"
00351 #include "dh.h"
00352 #include "mqv.h"
00353 #include "ecp.h"
00354 #include "ec2n.h"
00355
00356 NAMESPACE_BEGIN(CryptoPP)
00357
00358
00359
00360
00361
00362 template <class EC>
00363 class DL_GroupParameters_EC : public DL_GroupParametersImpl<EcPrecomputation<EC> >
00364 {
00365 typedef DL_GroupParameters_EC<EC> ThisClass;
00366
00367 public:
00368 typedef EC EllipticCurve;
00369 typedef typename EllipticCurve::Point Point;
00370 typedef Point Element;
00371 typedef IncompatibleCofactorMultiplication DefaultCofactorOption;
00372
00373 DL_GroupParameters_EC() : m_compress(false), m_encodeAsOID(false) {}
00374 DL_GroupParameters_EC(const OID &oid)
00375 : m_compress(false), m_encodeAsOID(false) {Initialize(oid);}
00376 DL_GroupParameters_EC(const EllipticCurve &ec, const Point &G, const Integer &n, const Integer &k = Integer::Zero())
00377 : m_compress(false), m_encodeAsOID(false) {Initialize(ec, G, n, k);}
00378 DL_GroupParameters_EC(BufferedTransformation &bt)
00379 : m_compress(false), m_encodeAsOID(false) {BERDecode(bt);}
00380
00381 void Initialize(const EllipticCurve &ec, const Point &G, const Integer &n, const Integer &k = Integer::Zero())
00382 {
00383 this->m_groupPrecomputation.SetCurve(ec);
00384 this->SetSubgroupGenerator(G);
00385 m_n = n;
00386 m_k = k;
00387 }
00388 void Initialize(const OID &oid);
00389
00390
00391 bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const;
00392 void AssignFrom(const NameValuePairs &source);
00393
00394
00395
00396
00397 void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg);
00398
00399
00400 const DL_FixedBasePrecomputation<Element> & GetBasePrecomputation() const {return this->m_gpc;}
00401 DL_FixedBasePrecomputation<Element> & AccessBasePrecomputation() {return this->m_gpc;}
00402 const Integer & GetSubgroupOrder() const {return m_n;}
00403 Integer GetCofactor() const;
00404 bool ValidateGroup(RandomNumberGenerator &rng, unsigned int level) const;
00405 bool ValidateElement(unsigned int level, const Element &element, const DL_FixedBasePrecomputation<Element> *precomp) const;
00406 bool FastSubgroupCheckAvailable() const {return false;}
00407 void EncodeElement(bool reversible, const Element &element, byte *encoded) const
00408 {
00409 if (reversible)
00410 GetCurve().EncodePoint(encoded, element, m_compress);
00411 else
00412 element.x.Encode(encoded, GetEncodedElementSize(false));
00413 }
00414 virtual unsigned int GetEncodedElementSize(bool reversible) const
00415 {
00416 if (reversible)
00417 return GetCurve().EncodedPointSize(m_compress);
00418 else
00419 return GetCurve().GetField().MaxElementByteLength();
00420 }
00421 Element DecodeElement(const byte *encoded, bool checkForGroupMembership) const
00422 {
00423 Point result;
00424 if (!GetCurve().DecodePoint(result, encoded, GetEncodedElementSize(true)))
00425 throw DL_BadElement();
00426 if (checkForGroupMembership && !ValidateElement(1, result, NULL))
00427 throw DL_BadElement();
00428 return result;
00429 }
00430 Integer ConvertElementToInteger(const Element &element) const;
00431 Integer GetMaxExponent() const {return GetSubgroupOrder()-1;}
00432 bool IsIdentity(const Element &element) const {return element.identity;}
00433 void SimultaneousExponentiate(Element *results, const Element &base, const Integer *exponents, unsigned int exponentsCount) const;
00434 static std::string CRYPTOPP_API StaticAlgorithmNamePrefix() {return "EC";}
00435
00436
00437 OID GetAlgorithmID() const;
00438
00439
00440 Element MultiplyElements(const Element &a, const Element &b) const;
00441 Element CascadeExponentiate(const Element &element1, const Integer &exponent1, const Element &element2, const Integer &exponent2) const;
00442
00443
00444
00445
00446 static OID CRYPTOPP_API GetNextRecommendedParametersOID(const OID &oid);
00447
00448 void BERDecode(BufferedTransformation &bt);
00449 void DEREncode(BufferedTransformation &bt) const;
00450
00451 void SetPointCompression(bool compress) {m_compress = compress;}
00452 bool GetPointCompression() const {return m_compress;}
00453
00454 void SetEncodeAsOID(bool encodeAsOID) {m_encodeAsOID = encodeAsOID;}
00455 bool GetEncodeAsOID() const {return m_encodeAsOID;}
00456
00457 const EllipticCurve& GetCurve() const {return this->m_groupPrecomputation.GetCurve();}
00458
00459 bool operator==(const ThisClass &rhs) const
00460 {return this->m_groupPrecomputation.GetCurve() == rhs.m_groupPrecomputation.GetCurve() && this->m_gpc.GetBase(this->m_groupPrecomputation) == rhs.m_gpc.GetBase(rhs.m_groupPrecomputation);}
00461
00462 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY
00463 const Point& GetBasePoint() const {return this->GetSubgroupGenerator();}
00464 const Integer& GetBasePointOrder() const {return this->GetSubgroupOrder();}
00465 void LoadRecommendedParameters(const OID &oid) {Initialize(oid);}
00466 #endif
00467
00468 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
00469 virtual ~DL_GroupParameters_EC() {}
00470 #endif
00471
00472 protected:
00473 unsigned int FieldElementLength() const {return GetCurve().GetField().MaxElementByteLength();}
00474 unsigned int ExponentLength() const {return m_n.ByteCount();}
00475
00476 OID m_oid;
00477 Integer m_n;
00478 mutable Integer m_k;
00479 mutable bool m_compress, m_encodeAsOID;
00480 };
00481
00482
00483 template <class EC>
00484 class DL_PublicKey_EC : public DL_PublicKeyImpl<DL_GroupParameters_EC<EC> >
00485 {
00486 public:
00487 typedef typename EC::Point Element;
00488
00489 void Initialize(const DL_GroupParameters_EC<EC> ¶ms, const Element &Q)
00490 {this->AccessGroupParameters() = params; this->SetPublicElement(Q);}
00491 void Initialize(const EC &ec, const Element &G, const Integer &n, const Element &Q)
00492 {this->AccessGroupParameters().Initialize(ec, G, n); this->SetPublicElement(Q);}
00493
00494
00495 void BERDecodePublicKey(BufferedTransformation &bt, bool parametersPresent, size_t size);
00496 void DEREncodePublicKey(BufferedTransformation &bt) const;
00497
00498 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
00499 virtual ~DL_PublicKey_EC() {}
00500 #endif
00501 };
00502
00503
00504 template <class EC>
00505 class DL_PrivateKey_EC : public DL_PrivateKeyImpl<DL_GroupParameters_EC<EC> >
00506 {
00507 public:
00508 typedef typename EC::Point Element;
00509
00510 void Initialize(const DL_GroupParameters_EC<EC> ¶ms, const Integer &x)
00511 {this->AccessGroupParameters() = params; this->SetPrivateExponent(x);}
00512 void Initialize(const EC &ec, const Element &G, const Integer &n, const Integer &x)
00513 {this->AccessGroupParameters().Initialize(ec, G, n); this->SetPrivateExponent(x);}
00514 void Initialize(RandomNumberGenerator &rng, const DL_GroupParameters_EC<EC> ¶ms)
00515 {this->GenerateRandom(rng, params);}
00516 void Initialize(RandomNumberGenerator &rng, const EC &ec, const Element &G, const Integer &n)
00517 {this->GenerateRandom(rng, DL_GroupParameters_EC<EC>(ec, G, n));}
00518
00519
00520 void BERDecodePrivateKey(BufferedTransformation &bt, bool parametersPresent, size_t size);
00521 void DEREncodePrivateKey(BufferedTransformation &bt) const;
00522
00523 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
00524 virtual ~DL_PrivateKey_EC() {}
00525 #endif
00526 };
00527
00528
00529 template <class EC, class COFACTOR_OPTION = CPP_TYPENAME DL_GroupParameters_EC<EC>::DefaultCofactorOption>
00530 struct ECDH
00531 {
00532 typedef DH_Domain<DL_GroupParameters_EC<EC>, COFACTOR_OPTION> Domain;
00533
00534 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
00535 virtual ~ECDH() {}
00536 #endif
00537 };
00538
00539
00540 template <class EC, class COFACTOR_OPTION = CPP_TYPENAME DL_GroupParameters_EC<EC>::DefaultCofactorOption>
00541 struct ECMQV
00542 {
00543 typedef MQV_Domain<DL_GroupParameters_EC<EC>, COFACTOR_OPTION> Domain;
00544
00545 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
00546 virtual ~ECMQV() {}
00547 #endif
00548 };
00549
00550
00551 template <class EC>
00552 struct DL_Keys_EC
00553 {
00554 typedef DL_PublicKey_EC<EC> PublicKey;
00555 typedef DL_PrivateKey_EC<EC> PrivateKey;
00556
00557 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
00558 virtual ~DL_Keys_EC() {}
00559 #endif
00560 };
00561
00562 template <class EC, class H>
00563 struct ECDSA;
00564
00565
00566 template <class EC>
00567 struct DL_Keys_ECDSA
00568 {
00569 typedef DL_PublicKey_EC<EC> PublicKey;
00570 typedef DL_PrivateKey_WithSignaturePairwiseConsistencyTest<DL_PrivateKey_EC<EC>, ECDSA<EC, SHA256> > PrivateKey;
00571
00572 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
00573 virtual ~DL_Keys_ECDSA() {}
00574 #endif
00575 };
00576
00577
00578 template <class EC>
00579 class DL_Algorithm_ECDSA : public DL_Algorithm_GDSA<typename EC::Point>
00580 {
00581 public:
00582 static const char * CRYPTOPP_API StaticAlgorithmName() {return "ECDSA";}
00583
00584 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
00585 virtual ~DL_Algorithm_ECDSA() {}
00586 #endif
00587 };
00588
00589
00590 template <class EC>
00591 class DL_Algorithm_ECNR : public DL_Algorithm_NR<typename EC::Point>
00592 {
00593 public:
00594 static const char * CRYPTOPP_API StaticAlgorithmName() {return "ECNR";}
00595
00596 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
00597 virtual ~DL_Algorithm_ECNR() {}
00598 #endif
00599 };
00600
00601
00602 template <class EC, class H>
00603 struct ECDSA : public DL_SS<DL_Keys_ECDSA<EC>, DL_Algorithm_ECDSA<EC>, DL_SignatureMessageEncodingMethod_DSA, H>
00604 {
00605 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
00606 virtual ~ECDSA() {}
00607 #endif
00608 };
00609
00610
00611 template <class EC, class H = SHA>
00612 struct ECNR : public DL_SS<DL_Keys_EC<EC>, DL_Algorithm_ECNR<EC>, DL_SignatureMessageEncodingMethod_NR, H>
00613 {
00614 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
00615 virtual ~ECNR() {}
00616 #endif
00617 };
00618
00619
00620
00621
00622
00623 template <class EC, class COFACTOR_OPTION = NoCofactorMultiplication, bool DHAES_MODE = false>
00624 struct ECIES
00625 : public DL_ES<
00626 DL_Keys_EC<EC>,
00627 DL_KeyAgreementAlgorithm_DH<typename EC::Point, COFACTOR_OPTION>,
00628 DL_KeyDerivationAlgorithm_P1363<typename EC::Point, DHAES_MODE, P1363_KDF2<SHA1> >,
00629 DL_EncryptionAlgorithm_Xor<HMAC<SHA1>, DHAES_MODE>,
00630 ECIES<EC> >
00631 {
00632 static std::string CRYPTOPP_API StaticAlgorithmName() {return "ECIES";}
00633
00634 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
00635 virtual ~ECIES() {}
00636 #endif
00637
00638 #if (CRYPTOPP_GCC_VERSION >= 40500) || (CRYPTOPP_CLANG_VERSION >= 20800)
00639 } __attribute__((deprecated ("ECIES will be changing in the near future due to (1) an implementation bug and (2) an interop issue")));
00640 #elif (CRYPTOPP_GCC_VERSION)
00641 } __attribute__((deprecated));
00642 #else
00643 };
00644 #endif
00645
00646 NAMESPACE_END
00647
00648 #ifdef CRYPTOPP_MANUALLY_INSTANTIATE_TEMPLATES
00649 #include "eccrypto.cpp"
00650 #endif
00651
00652 NAMESPACE_BEGIN(CryptoPP)
00653
00654 CRYPTOPP_DLL_TEMPLATE_CLASS DL_GroupParameters_EC<ECP>;
00655 CRYPTOPP_DLL_TEMPLATE_CLASS DL_GroupParameters_EC<EC2N>;
00656 CRYPTOPP_DLL_TEMPLATE_CLASS DL_PublicKeyImpl<DL_GroupParameters_EC<ECP> >;
00657 CRYPTOPP_DLL_TEMPLATE_CLASS DL_PublicKeyImpl<DL_GroupParameters_EC<EC2N> >;
00658 CRYPTOPP_DLL_TEMPLATE_CLASS DL_PublicKey_EC<ECP>;
00659 CRYPTOPP_DLL_TEMPLATE_CLASS DL_PublicKey_EC<EC2N>;
00660 CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKeyImpl<DL_GroupParameters_EC<ECP> >;
00661 CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKeyImpl<DL_GroupParameters_EC<EC2N> >;
00662 CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKey_EC<ECP>;
00663 CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKey_EC<EC2N>;
00664 CRYPTOPP_DLL_TEMPLATE_CLASS DL_Algorithm_GDSA<ECP::Point>;
00665 CRYPTOPP_DLL_TEMPLATE_CLASS DL_Algorithm_GDSA<EC2N::Point>;
00666 CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKey_WithSignaturePairwiseConsistencyTest<DL_PrivateKey_EC<ECP>, ECDSA<ECP, SHA256> >;
00667 CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKey_WithSignaturePairwiseConsistencyTest<DL_PrivateKey_EC<EC2N>, ECDSA<EC2N, SHA256> >;
00668
00669 NAMESPACE_END
00670
00671 #endif