diff options
author | Jeffrey Walton <noloader@gmail.com> | 2018-12-13 10:19:54 -0500 |
---|---|---|
committer | Jeffrey Walton <noloader@gmail.com> | 2018-12-13 10:19:54 -0500 |
commit | 152ac6177c8227aad52d73fec74a776454f23baa (patch) | |
tree | 8978961b876fa03e20a1eb8a1979bdf93b2e1f24 /donna_64.cpp | |
parent | 20f4d22055ef99c440b62963991359bc3ff6ef27 (diff) | |
download | cryptopp-git-152ac6177c8227aad52d73fec74a776454f23baa.tar.gz |
Add Moon's curve25519 using SSE2 (GH #761)
Moon's code is very fast. In fact it is so fast it broke our benchmarks. Moon's code registers 0.00 milliseconds and 0.00 megacycles/operation.
Diffstat (limited to 'donna_64.cpp')
-rw-r--r-- | donna_64.cpp | 47 |
1 files changed, 34 insertions, 13 deletions
diff --git a/donna_64.cpp b/donna_64.cpp index 564a8a92..18a6fe45 100644 --- a/donna_64.cpp +++ b/donna_64.cpp @@ -54,6 +54,7 @@ #include "config.h"
#include "donna.h"
#include "stdcpp.h"
+#include "cpu.h"
// This macro is not in a header like config.h because
// we don't want it exposed to user code. We also need
@@ -482,32 +483,52 @@ ANONYMOUS_NAMESPACE_END NAMESPACE_BEGIN(CryptoPP)
NAMESPACE_BEGIN(Donna)
-int curve25519(byte publicKey[32], const byte secretKey[32])
-{
- const byte basePoint[32] = {9};
- return curve25519(publicKey, secretKey, basePoint);
-}
-
-int curve25519(byte sharedKey[32], const byte secretKey[32], const byte othersKey[32])
+int curve25519_CXX(byte sharedKey[32], const byte secretKey[32], const byte othersKey[32])
{
- limb bp[5], x[5], z[5], zmone[5];
- uint8_t e[32];
+ limb bp[10], x[10], z[11], zmone[10];
+ byte e[32];
- for (unsigned int i = 0;i < 32;++i)
+ for (unsigned int i = 0; i < 32; ++i)
e[i] = secretKey[i];
- e[0] &= 248;
- e[31] &= 127;
- e[31] |= 64;
+ // I'd like to remove this copy/clamp but I don't
+ // know if an attacker can cause an information
+ // leak if multiply is misused.
+ e[0] &= 248; e[31] &= 127; e[31] |= 64;
fexpand(bp, othersKey);
cmult(x, z, e, bp);
crecip(zmone, z);
fmul(z, x, zmone);
fcontract(sharedKey, z);
+
return 0;
}
+int curve25519(byte publicKey[32], const byte secretKey[32])
+{
+ const byte basePoint[32] = {9};
+
+#if (CRYPTOPP_SSE2_INTRIN_AVAILABLE)
+ if (HasSSE2())
+ return curve25519_SSE2(publicKey, secretKey, basePoint);
+ else
+#endif
+
+ return curve25519_CXX(publicKey, secretKey, basePoint);
+}
+
+int curve25519(byte sharedKey[32], const byte secretKey[32], const byte othersKey[32])
+{
+#if (CRYPTOPP_SSE2_INTRIN_AVAILABLE)
+ if (HasSSE2())
+ return curve25519_SSE2(sharedKey, secretKey, othersKey);
+ else
+#endif
+
+ return curve25519_CXX(sharedKey, secretKey, othersKey);
+}
+
NAMESPACE_END // Donna
NAMESPACE_END // CryptoPP
|