summaryrefslogtreecommitdiff
path: root/eccrypto.h
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2016-12-13 16:20:41 -0500
committerJeffrey Walton <noloader@gmail.com>2016-12-13 16:20:41 -0500
commitcecf719fcd8cde0724567d4b38360daae52b4597 (patch)
treeeb1d45b7c9911f4fef3e32bbe1e91e584ee04b39 /eccrypto.h
parent1a17ade299c3a05e5a63a8cb3f390d21845c21c6 (diff)
downloadcryptopp-git-cecf719fcd8cde0724567d4b38360daae52b4597.tar.gz
Add German digital signature algorithm (ECGDSA) (Issue 113)
Also see ISO/IEC 15946 and http://www.teletrust.de/fileadmin/files/oid/ecgdsa_final.pdf
Diffstat (limited to 'eccrypto.h')
-rw-r--r--eccrypto.h180
1 files changed, 180 insertions, 0 deletions
diff --git a/eccrypto.h b/eccrypto.h
index caa85037..3e084695 100644
--- a/eccrypto.h
+++ b/eccrypto.h
@@ -403,6 +403,182 @@ struct ECNR : public DL_SS<DL_Keys_EC<EC>, DL_Algorithm_ECNR<EC>, DL_SignatureMe
{
};
+// ******************************************
+
+template <class EC>
+class DL_PublicKey_ECGDSA_ISO15946;
+template <class EC>
+class DL_PrivateKey_ECGDSA_ISO15946;
+
+//! \class DL_PrivateKey_ECGDSA_ISO15946
+//! \brief Elliptic Curve German DSA key for ISO/IEC 15946
+//! \tparam EC elliptic curve field
+//! \sa ECGDSA_ISO15946
+//! \since Crypto++ 5.7
+template <class EC>
+class DL_PrivateKey_ECGDSA_ISO15946 : public DL_PrivateKeyImpl<DL_GroupParameters_EC<EC> >
+{
+public:
+ typedef typename EC::Point Element;
+
+ virtual ~DL_PrivateKey_ECGDSA_ISO15946() {}
+
+ //! \brief Initialize an EC Private Key using {GP,x}
+ //! \param params group parameters
+ //! \param x the private exponent
+ //! \details This Initialize() function overload initializes a private key from existing parameters.
+ void Initialize(const DL_GroupParameters_EC<EC> &params, const Integer &x)
+ {this->AccessGroupParameters() = params; this->SetPrivateExponent(x);}
+
+ //! \brief Initialize an EC Private Key using {EC,G,n,x}
+ //! \param ec the elliptic curve
+ //! \param G the base point
+ //! \param n the order of the base point
+ //! \param x the private exponent
+ //! \details This Initialize() function overload initializes a private key from existing parameters.
+ void Initialize(const EC &ec, const Element &G, const Integer &n, const Integer &x)
+ {this->AccessGroupParameters().Initialize(ec, G, n); this->SetPrivateExponent(x);}
+
+ //! \brief Create an EC private key
+ //! \param rng a RandomNumberGenerator derived class
+ //! \param params the EC group parameters
+ //! \details This function overload of Initialize() creates a new private key because it
+ //! takes a RandomNumberGenerator() as a parameter. If you have an existing keypair,
+ //! then use one of the other Initialize() overloads.
+ void Initialize(RandomNumberGenerator &rng, const DL_GroupParameters_EC<EC> &params)
+ {this->GenerateRandom(rng, params);}
+
+ //! \brief Create an EC private key
+ //! \param rng a RandomNumberGenerator derived class
+ //! \param ec the elliptic curve
+ //! \param G the base point
+ //! \param n the order of the base point
+ //! \details This function overload of Initialize() creates a new private key because it
+ //! takes a RandomNumberGenerator() as a parameter. If you have an existing keypair,
+ //! then use one of the other Initialize() overloads.
+ void Initialize(RandomNumberGenerator &rng, const EC &ec, const Element &G, const Integer &n)
+ {this->GenerateRandom(rng, DL_GroupParameters_EC<EC>(ec, G, n));}
+
+ virtual void MakePublicKey(DL_PublicKey_ECGDSA_ISO15946<EC> &pub) const
+ {
+ const DL_GroupParameters<Element>& params = this->GetAbstractGroupParameters();
+ pub.AccessAbstractGroupParameters().AssignFrom(params);
+ const Integer &xInv = this->GetPrivateExponent().InverseMod(params.GetGroupOrder());
+ pub.SetPublicElement(params.ExponentiateBase(xInv));
+ }
+
+ virtual bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const
+ {
+ return GetValueHelper<DL_PrivateKey_ECGDSA_ISO15946<EC>,
+ DL_PrivateKey_ECGDSA_ISO15946<EC> >(this, name, valueType, pValue).Assignable();
+ }
+
+ virtual void AssignFrom(const NameValuePairs &source)
+ {
+ AssignFromHelper<DL_PrivateKey_ECGDSA_ISO15946<EC>,
+ DL_PrivateKey_ECGDSA_ISO15946<EC> >(this, source);
+ }
+
+ // PKCS8PrivateKey
+ void BERDecodePrivateKey(BufferedTransformation &bt, bool parametersPresent, size_t size);
+ void DEREncodePrivateKey(BufferedTransformation &bt) const;
+};
+
+//! \class DL_PublicKey_ECGDSA_ISO15946
+//! \brief Elliptic Curve German DSA key for ISO/IEC 15946
+//! \tparam EC elliptic curve field
+//! \sa ECGDSA_ISO15946
+//! \since Crypto++ 5.7
+template <class EC>
+class DL_PublicKey_ECGDSA_ISO15946 : public DL_PublicKeyImpl<DL_GroupParameters_EC<EC> >
+{
+ typedef DL_PublicKey_ECGDSA_ISO15946<EC> ThisClass;
+
+public:
+ typedef typename EC::Point Element;
+
+ virtual ~DL_PublicKey_ECGDSA_ISO15946() {}
+
+ //! \brief Initialize an EC Public Key using {GP,Q}
+ //! \param params group parameters
+ //! \param Q the public point
+ //! \details This Initialize() function overload initializes a public key from existing parameters.
+ void Initialize(const DL_GroupParameters_EC<EC> &params, const Element &Q)
+ {this->AccessGroupParameters() = params; this->SetPublicElement(Q);}
+
+ //! \brief Initialize an EC Public Key using {EC,G,n,Q}
+ //! \param ec the elliptic curve
+ //! \param G the base point
+ //! \param n the order of the base point
+ //! \param Q the public point
+ //! \details This Initialize() function overload initializes a public key from existing parameters.
+ void Initialize(const EC &ec, const Element &G, const Integer &n, const Element &Q)
+ {this->AccessGroupParameters().Initialize(ec, G, n); this->SetPublicElement(Q);}
+
+ virtual void AssignFrom(const NameValuePairs &source)
+ {
+ DL_PrivateKey_ECGDSA_ISO15946<EC> *pPrivateKey = NULL;
+ if (source.GetThisPointer(pPrivateKey))
+ pPrivateKey->MakePublicKey(*this);
+ else
+ {
+ this->AccessAbstractGroupParameters().AssignFrom(source);
+ AssignFromHelper(this, source)
+ CRYPTOPP_SET_FUNCTION_ENTRY(PublicElement);
+ }
+ }
+
+ // DL_PublicKey<T>
+ virtual void SetPublicElement(const Element &y)
+ {this->AccessPublicPrecomputation().SetBase(this->GetAbstractGroupParameters().GetGroupPrecomputation(), y);}
+
+ // X509PublicKey
+ void BERDecodePublicKey(BufferedTransformation &bt, bool parametersPresent, size_t size);
+ void DEREncodePublicKey(BufferedTransformation &bt) const;
+};
+
+//! \class DL_Keys_ECGDSA_ISO15946
+//! \brief Elliptic Curve German DSA keys for ISO/IEC 15946
+//! \tparam EC elliptic curve field
+//! \sa ECGDSA_ISO15946
+//! \since Crypto++ 5.7
+template <class EC>
+struct DL_Keys_ECGDSA_ISO15946
+{
+ typedef DL_PublicKey_ECGDSA_ISO15946<EC> PublicKey;
+ typedef DL_PrivateKey_ECGDSA_ISO15946<EC> PrivateKey;
+};
+
+//! \class DL_Algorithm_ECGDSA_ISO15946
+//! \brief Elliptic Curve German DSA signature algorithm
+//! \tparam EC elliptic curve field
+//! \sa ECGDSA_ISO15946
+//! \since Crypto++ 5.7
+template <class EC>
+class DL_Algorithm_ECGDSA_ISO15946 : public DL_Algorithm_GDSA_ISO15946<typename EC::Point>
+{
+public:
+ CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "ECGDSA";}
+};
+
+//! \class ECGDSA_ISO15946
+//! \brief Elliptic Curve German Digital Signature Algorithm signature scheme
+//! \tparam EC elliptic curve field
+//! \tparam H HashTransformation derived class
+//! \sa Erwin Hess, Marcus Schafheutle, and Pascale Serf <A HREF="http://www.teletrust.de/fileadmin/files/oid/ecgdsa_final.pdf">The
+//! Digital Signature Scheme ECGDSA (October 24, 2006)</A>
+template <class EC, class H>
+struct ECGDSA : public DL_SS<
+ DL_Keys_ECGDSA_ISO15946<EC>,
+ DL_Algorithm_ECGDSA_ISO15946<EC>,
+ DL_SignatureMessageEncodingMethod_DSA,
+ H>
+{
+ static std::string CRYPTOPP_API StaticAlgorithmName() {return std::string("ECGDSA-ISO15946/") + H::StaticAlgorithmName();}
+};
+
+// ******************************************
+
//! \class ECIES
//! \brief Elliptic Curve Integrated Encryption Scheme
//! \tparam COFACTOR_OPTION \ref CofactorMultiplicationOption "cofactor multiplication option"
@@ -464,10 +640,14 @@ CRYPTOPP_DLL_TEMPLATE_CLASS DL_PublicKeyImpl<DL_GroupParameters_EC<ECP> >;
CRYPTOPP_DLL_TEMPLATE_CLASS DL_PublicKeyImpl<DL_GroupParameters_EC<EC2N> >;
CRYPTOPP_DLL_TEMPLATE_CLASS DL_PublicKey_EC<ECP>;
CRYPTOPP_DLL_TEMPLATE_CLASS DL_PublicKey_EC<EC2N>;
+CRYPTOPP_DLL_TEMPLATE_CLASS DL_PublicKey_ECGDSA_ISO15946<ECP>;
+CRYPTOPP_DLL_TEMPLATE_CLASS DL_PublicKey_ECGDSA_ISO15946<EC2N>;
CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKeyImpl<DL_GroupParameters_EC<ECP> >;
CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKeyImpl<DL_GroupParameters_EC<EC2N> >;
CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKey_EC<ECP>;
CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKey_EC<EC2N>;
+CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKey_ECGDSA_ISO15946<ECP>;
+CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKey_ECGDSA_ISO15946<EC2N>;
CRYPTOPP_DLL_TEMPLATE_CLASS DL_Algorithm_GDSA<ECP::Point>;
CRYPTOPP_DLL_TEMPLATE_CLASS DL_Algorithm_GDSA<EC2N::Point>;
CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKey_WithSignaturePairwiseConsistencyTest<DL_PrivateKey_EC<ECP>, ECDSA<ECP, SHA256> >;