summaryrefslogtreecommitdiff
path: root/donna_32.cpp
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2018-12-13 10:19:54 -0500
committerJeffrey Walton <noloader@gmail.com>2018-12-13 10:19:54 -0500
commit152ac6177c8227aad52d73fec74a776454f23baa (patch)
tree8978961b876fa03e20a1eb8a1979bdf93b2e1f24 /donna_32.cpp
parent20f4d22055ef99c440b62963991359bc3ff6ef27 (diff)
downloadcryptopp-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_32.cpp')
-rw-r--r--donna_32.cpp40
1 files changed, 30 insertions, 10 deletions
diff --git a/donna_32.cpp b/donna_32.cpp
index 6e0fe235..168c9aa6 100644
--- a/donna_32.cpp
+++ b/donna_32.cpp
@@ -965,13 +965,7 @@ 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[10], x[10], z[11], zmone[10];
byte e[32];
@@ -979,18 +973,44 @@ int curve25519(byte sharedKey[32], const byte secretKey[32], const byte othersKe
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