summaryrefslogtreecommitdiff
path: root/xed25519.h
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2018-12-11 16:17:56 -0500
committerGitHub <noreply@github.com>2018-12-11 16:17:56 -0500
commit77923a291a5c993cca5c11c9b7dc00891d88bd8e (patch)
treeed0ed532c9632b35322ca67ba858eff54c8074a3 /xed25519.h
parentc1681148a248c21881511b620106dd7e4386d41e (diff)
downloadcryptopp-git-77923a291a5c993cca5c11c9b7dc00891d88bd8e.tar.gz
Add Langley's curve25519 (GH #761, PR# 762)
Diffstat (limited to 'xed25519.h')
-rw-r--r--xed25519.h44
1 files changed, 44 insertions, 0 deletions
diff --git a/xed25519.h b/xed25519.h
new file mode 100644
index 00000000..3d6442fa
--- /dev/null
+++ b/xed25519.h
@@ -0,0 +1,44 @@
+// xed25519.h - written and placed in public domain by Jeffrey Walton
+// Crypto++ specific implementation wrapped around Adam
+// Langley's curve25519-donna.
+
+#ifndef CRYPTOPP_XED25519_H
+#define CRYPTOPP_XED25519_H
+
+#include "cryptlib.h"
+#include "algparam.h"
+
+NAMESPACE_BEGIN(CryptoPP)
+
+class Integer;
+
+/// \brief x25519 with key validation
+class x25519 : public SimpleKeyAgreementDomain, public CryptoParameters
+{
+public:
+ x25519(const byte y[32], const byte x[32]);
+ x25519(const Integer &y, const Integer &x);
+ x25519(RandomNumberGenerator &rng);
+ x25519(BufferedTransformation &params);
+
+ void DEREncode(BufferedTransformation &params) const;
+
+ bool Validate(RandomNumberGenerator &rng, unsigned int level) const;
+ bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const;
+ void AssignFrom(const NameValuePairs &source);
+ CryptoParameters & AccessCryptoParameters() {return *this;}
+ unsigned int AgreedValueLength() const {return 32;}
+ unsigned int PrivateKeyLength() const {return 32;}
+ unsigned int PublicKeyLength() const {return 32;}
+
+ void GeneratePrivateKey(RandomNumberGenerator &rng, byte *privateKey) const;
+ void GeneratePublicKey(RandomNumberGenerator &rng, const byte *privateKey, byte *publicKey) const;
+ bool Agree(byte *agreedValue, const byte *privateKey, const byte *otherPublicKey, bool validateOtherPublicKey=true) const;
+
+private:
+ FixedSizeSecBlock<byte, 32> m_sk, m_pk;
+};
+
+NAMESPACE_END // CryptoPP
+
+#endif // CRYPTOPP_XED25519_H