Skip to content

Commit c3e2e0f

Browse files
committed
Align with BouncyCastle and Botan for DLIES and ECIES. Updated documentation
1 parent b5f04e5 commit c3e2e0f

File tree

2 files changed

+254
-101
lines changed

2 files changed

+254
-101
lines changed

eccrypto.h

Lines changed: 88 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,9 @@ class DL_GroupParameters_EC : public DL_GroupParametersImpl<EcPrecomputation<EC>
147147
mutable bool m_compress, m_encodeAsOID; // presentation details
148148
};
149149

150-
//! EC public key
150+
//! \class DL_PublicKey_EC
151+
//! \brief Elliptic Curve Discrete Log (DL) public key
152+
//! \tparam EC elliptic curve field
151153
template <class EC>
152154
class DL_PublicKey_EC : public DL_PublicKeyImpl<DL_GroupParameters_EC<EC> >
153155
{
@@ -168,7 +170,9 @@ class DL_PublicKey_EC : public DL_PublicKeyImpl<DL_GroupParameters_EC<EC> >
168170
void DEREncodePublicKey(BufferedTransformation &bt) const;
169171
};
170172

171-
//! EC private key
173+
//! \class DL_PrivateKey_EC
174+
//! \brief Elliptic Curve Discrete Log (DL) private key
175+
//! \tparam EC elliptic curve field
172176
template <class EC>
173177
class DL_PrivateKey_EC : public DL_PrivateKeyImpl<DL_GroupParameters_EC<EC> >
174178
{
@@ -193,7 +197,11 @@ class DL_PrivateKey_EC : public DL_PrivateKeyImpl<DL_GroupParameters_EC<EC> >
193197
void DEREncodePrivateKey(BufferedTransformation &bt) const;
194198
};
195199

196-
//! Elliptic Curve Diffie-Hellman, AKA <a href="http://www.weidai.com/scan-mirror/ka.html#ECDH">ECDH</a>
200+
//! \class ECDH
201+
//! \brief Elliptic Curve Diffie-Hellman
202+
//! \tparam EC elliptic curve field
203+
//! \tparam COFACTOR_OPTION \ref CofactorMultiplicationOption "cofactor multiplication option"
204+
//! \sa <a href="http://www.weidai.com/scan-mirror/ka.html#ECDH">Elliptic Curve Diffie-Hellman, AKA ECDH</a>
197205
template <class EC, class COFACTOR_OPTION = CPP_TYPENAME DL_GroupParameters_EC<EC>::DefaultCofactorOption>
198206
struct ECDH
199207
{
@@ -204,7 +212,11 @@ struct ECDH
204212
#endif
205213
};
206214

207-
/// Elliptic Curve Menezes-Qu-Vanstone, AKA <a href="http://www.weidai.com/scan-mirror/ka.html#ECMQV">ECMQV</a>
215+
//! \class ECMQV
216+
//! \brief Elliptic Curve Menezes-Qu-Vanstone
217+
//! \tparam EC elliptic curve field
218+
//! \tparam COFACTOR_OPTION \ref CofactorMultiplicationOption "cofactor multiplication option"
219+
/// \sa <a href="http://www.weidai.com/scan-mirror/ka.html#ECMQV">Elliptic Curve Menezes-Qu-Vanstone, AKA ECMQV</a>
208220
template <class EC, class COFACTOR_OPTION = CPP_TYPENAME DL_GroupParameters_EC<EC>::DefaultCofactorOption>
209221
struct ECMQV
210222
{
@@ -215,7 +227,10 @@ struct ECMQV
215227
#endif
216228
};
217229

218-
//! \brief Hashed Menezes-Qu-Vanstone in ECP or EC2N
230+
//! \class ECHMQV
231+
//! \brief Hashed Elliptic Curve Menezes-Qu-Vanstone
232+
//! \tparam EC elliptic curve field
233+
//! \tparam COFACTOR_OPTION \ref CofactorMultiplicationOption "cofactor multiplication option"
219234
//! \details This implementation follows Hugo Krawczyk's <a href="http://eprint.iacr.org/2005/176">HMQV: A High-Performance
220235
//! Secure Diffie-Hellman Protocol</a>. Note: this implements HMQV only. HMQV-C with Key Confirmation is not provided.
221236
template <class EC, class COFACTOR_OPTION = CPP_TYPENAME DL_GroupParameters_EC<EC>::DefaultCofactorOption, class HASH = SHA256>
@@ -233,7 +248,10 @@ typedef ECHMQV< ECP, DL_GroupParameters_EC< ECP >::DefaultCofactorOption, SHA256
233248
typedef ECHMQV< ECP, DL_GroupParameters_EC< ECP >::DefaultCofactorOption, SHA384 >::Domain ECHMQV384;
234249
typedef ECHMQV< ECP, DL_GroupParameters_EC< ECP >::DefaultCofactorOption, SHA512 >::Domain ECHMQV512;
235250

236-
//! \brief Fully Hashed Menezes-Qu-Vanstone in ECP or EC2N
251+
//! \class ECFHMQV
252+
//! \brief Fully Hashed Elliptic Curve Menezes-Qu-Vanstone
253+
//! \tparam EC elliptic curve field
254+
//! \tparam COFACTOR_OPTION \ref CofactorMultiplicationOption "cofactor multiplication option"
237255
//! \details This implementation follows Augustin P. Sarr and Philippe Elbaz–Vincent, and Jean–Claude Bajard's
238256
//! <a href="http://eprint.iacr.org/2009/408">A Secure and Efficient Authenticated Diffie-Hellman Protocol</a>.
239257
//! Note: this is FHMQV, Protocol 5, from page 11; and not FHMQV-C.
@@ -252,7 +270,9 @@ typedef ECFHMQV< ECP, DL_GroupParameters_EC< ECP >::DefaultCofactorOption, SHA25
252270
typedef ECFHMQV< ECP, DL_GroupParameters_EC< ECP >::DefaultCofactorOption, SHA384 >::Domain ECFHMQV384;
253271
typedef ECFHMQV< ECP, DL_GroupParameters_EC< ECP >::DefaultCofactorOption, SHA512 >::Domain ECFHMQV512;
254272

255-
//! EC keys
273+
//! \class DL_Keys_EC
274+
//! \brief Elliptic Curve Discrete Log (DL) keys
275+
//! \tparam EC elliptic curve field
256276
template <class EC>
257277
struct DL_Keys_EC
258278
{
@@ -264,10 +284,16 @@ struct DL_Keys_EC
264284
#endif
265285
};
266286

287+
//! \class ECDSA
288+
//! \brief Elliptic Curve DSA
289+
//! \tparam EC elliptic curve field
290+
//! \tparam H HashTransformation derived class
267291
template <class EC, class H>
268292
struct ECDSA;
269293

270-
//! ECDSA keys
294+
//! \class DL_Keys_ECDSA
295+
//! \brief Elliptic Curve DSA keys
296+
//! \tparam EC elliptic curve field
271297
template <class EC>
272298
struct DL_Keys_ECDSA
273299
{
@@ -279,7 +305,9 @@ struct DL_Keys_ECDSA
279305
#endif
280306
};
281307

282-
//! ECDSA algorithm
308+
//! \class DL_Algorithm_ECDSA
309+
//! \brief Elliptic Curve DSA (ECDSA) signature algorithm
310+
//! \tparam EC elliptic curve field
283311
template <class EC>
284312
class DL_Algorithm_ECDSA : public DL_Algorithm_GDSA<typename EC::Point>
285313
{
@@ -291,7 +319,9 @@ class DL_Algorithm_ECDSA : public DL_Algorithm_GDSA<typename EC::Point>
291319
#endif
292320
};
293321

294-
//! ECNR algorithm
322+
//! \class DL_Algorithm_ECNR
323+
//! \brief Elliptic Curve NR (ECNR) signature algorithm
324+
//! \tparam EC elliptic curve field
295325
template <class EC>
296326
class DL_Algorithm_ECNR : public DL_Algorithm_NR<typename EC::Point>
297327
{
@@ -303,7 +333,11 @@ class DL_Algorithm_ECNR : public DL_Algorithm_NR<typename EC::Point>
303333
#endif
304334
};
305335

306-
//! <a href="http://www.weidai.com/scan-mirror/sig.html#ECDSA">ECDSA</a>
336+
//! \class ECDSA
337+
//! \brief Elliptic Curve DSA (ECDSA) signature scheme
338+
//! \tparam EC elliptic curve field
339+
//! \tparam H HashTransformation derived class
340+
//! \sa <a href="http://www.weidai.com/scan-mirror/sig.html#ECDSA">ECDSA</a>
307341
template <class EC, class H>
308342
struct ECDSA : public DL_SS<DL_Keys_ECDSA<EC>, DL_Algorithm_ECDSA<EC>, DL_SignatureMessageEncodingMethod_DSA, H>
309343
{
@@ -312,7 +346,10 @@ struct ECDSA : public DL_SS<DL_Keys_ECDSA<EC>, DL_Algorithm_ECDSA<EC>, DL_Signat
312346
#endif
313347
};
314348

315-
//! ECNR
349+
//! \class ECNR
350+
//! \brief Elliptic Curve NR (ECNR) signature scheme
351+
//! \tparam EC elliptic curve field
352+
//! \tparam H HashTransformation derived class
316353
template <class EC, class H = SHA>
317354
struct ECNR : public DL_SS<DL_Keys_EC<EC>, DL_Algorithm_ECNR<EC>, DL_SignatureMessageEncodingMethod_NR, H>
318355
{
@@ -321,26 +358,56 @@ struct ECNR : public DL_SS<DL_Keys_EC<EC>, DL_Algorithm_ECNR<EC>, DL_SignatureMe
321358
#endif
322359
};
323360

324-
//! Elliptic Curve Integrated Encryption Scheme, AKA <a href="http://www.weidai.com/scan-mirror/ca.html#ECIES">ECIES</a>
325-
/*! Default to (NoCofactorMultiplication and DHAES_MODE = false) for compatibilty with SEC1 and Crypto++ 4.2.
326-
The combination of (IncompatibleCofactorMultiplication and DHAES_MODE = true) is recommended for best
327-
efficiency and security. */
328-
template <class EC, class COFACTOR_OPTION = NoCofactorMultiplication, bool DHAES_MODE = false>
361+
362+
//! \class ECIES
363+
//! \brief Elliptic Curve Integrated Encryption Scheme
364+
//! \tparam COFACTOR_OPTION \ref CofactorMultiplicationOption "cofactor multiplication option"
365+
//! \tparam HASH HashTransformation derived class used for key drivation and MAC computation
366+
//! \tparam DHAES_MODE flag indicating if the MAC includes additional context parameters such as <em>u·V</em>, <em>v·U</em> and label
367+
//! \tparam LABEL_OCTETS flag indicating if the label size is specified in octets or bits
368+
//! \details ECIES is an Elliptic Curve based Integrated Encryption Scheme (IES). The scheme combines a Key Encapsulation
369+
//! Method (KEM) with a Data Encapsulation Method (DEM) and a MAC tag. The scheme is
370+
//! <A HREF="http://en.wikipedia.org/wiki/ciphertext_indistinguishability">IND-CCA2</A>, which is a strong notion of security.
371+
//! You should prefer an Integrated Encryption Scheme over homegrown schemes.
372+
//! \details The library's original implementation is based on an early P1363 draft, which itself appears to be based on an early Certicom
373+
//! SEC-1 draft (or an early SEC-1 draft was based on a P1363 draft). Crypto++ 4.2 used the early draft in its Integrated Ecryption
374+
//! Schemes with <tt>NoCofactorMultiplication</tt>, <tt>DHAES_MODE=false</tt> and <tt>LABEL_OCTETS=true</tt>.
375+
//! \details If you desire an Integrated Encryption Scheme with Crypto++ 4.2 compatibility, then use the ECIES template class with
376+
//! <tt>NoCofactorMultiplication</tt>, <tt>DHAES_MODE=false</tt> and <tt>LABEL_OCTETS=true</tt>.
377+
//! \details If you desire an Integrated Encryption Scheme with Bouncy Castle 1.55 and Botan 1.11 compatibility, then use the ECIES
378+
//! template class with <tt>NoCofactorMultiplication</tt>, <tt>DHAES_MODE=true</tt> and <tt>LABEL_OCTETS=false</tt>.
379+
//! \details Bouncy Castle 1.55 and Botan 1.11 compatibility are the default template parameters. The combination of
380+
//! <tt>IncompatibleCofactorMultiplication</tt> and <tt>DHAES_MODE=true</tt> is recommended for best efficiency and security.
381+
//! SHA1 is used for compatibility reasons, but it can be changed of if desired. SHA-256 or another hash will likely improve the
382+
//! security provided by the MAC. The hash is also used in the key derivation function as a PRF.
383+
//! \details Below is an example of constructing a Crypto++ 4.2 compatible ECIES encryptor and decryptor.
384+
//! <pre>
385+
//! AutoSeededRandomPool prng;
386+
//! DL_PrivateKey_EC<ECP> key;
387+
//! key.Initialize(prng, ASN1::secp160r1());
388+
//!
389+
//! ECIES<ECP,SHA1,NoCofactorMultiplication,true,true>::Decryptor decryptor(key);
390+
//! ECIES<ECP,SHA1,NoCofactorMultiplication,true,true>::Encryptor encryptor(decryptor);
391+
//! </pre>
392+
//! \sa DLIES, <a href="http://www.weidai.com/scan-mirror/ca.html#ECIES">Elliptic Curve Integrated Encryption Scheme (ECIES)</a>,
393+
//! Martínez, Encinas, and Ávila's <A HREF="http://digital.csic.es/bitstream/10261/32671/1/V2-I2-P7-13.pdf">A Survey of the Elliptic
394+
//! Curve Integrated Encryption Schemes</A>
395+
//! \since Crypto++ 4.0
396+
template <class EC, class HASH = SHA1, class COFACTOR_OPTION = NoCofactorMultiplication, bool DHAES_MODE = true, bool LABEL_OCTETS = false>
329397
struct ECIES
330398
: public DL_ES<
331399
DL_Keys_EC<EC>,
332400
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>,
401+
DL_KeyDerivationAlgorithm_P1363<typename EC::Point, DHAES_MODE, P1363_KDF2<HASH> >,
402+
DL_EncryptionAlgorithm_Xor<HMAC<HASH>, DHAES_MODE, LABEL_OCTETS>,
335403
ECIES<EC> >
336404
{
337405
static std::string CRYPTOPP_API StaticAlgorithmName() {return "ECIES";} // TODO: fix this after name is standardized
338406

339407
#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
340408
virtual ~ECIES() {}
341409
#endif
342-
343-
} CRYPTOPP_DEPRECATED ("ECIES will be changing in the near future due to an interop issue");
410+
};
344411

345412
NAMESPACE_END
346413

0 commit comments

Comments
 (0)