summaryrefslogtreecommitdiff
path: root/src/libsodium/crypto_scalarmult/curve25519/ref10/scalarmult_curve25519_ref10.c
diff options
context:
space:
mode:
authorMicah Anderson <micah@riseup.net>2014-08-11 13:49:21 -0400
committerMicah Anderson <micah@riseup.net>2014-08-11 13:49:21 -0400
commit2e59f9740a29439df7c7a56cf0ae83dec3081d31 (patch)
treed5e7c4e74c9a0f1ea999327d2e68b1dd27be00e0 /src/libsodium/crypto_scalarmult/curve25519/ref10/scalarmult_curve25519_ref10.c
initial import of debian version from mentors0.6.1
Diffstat (limited to 'src/libsodium/crypto_scalarmult/curve25519/ref10/scalarmult_curve25519_ref10.c')
-rw-r--r--src/libsodium/crypto_scalarmult/curve25519/ref10/scalarmult_curve25519_ref10.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/libsodium/crypto_scalarmult/curve25519/ref10/scalarmult_curve25519_ref10.c b/src/libsodium/crypto_scalarmult/curve25519/ref10/scalarmult_curve25519_ref10.c
new file mode 100644
index 0000000..a081430
--- /dev/null
+++ b/src/libsodium/crypto_scalarmult/curve25519/ref10/scalarmult_curve25519_ref10.c
@@ -0,0 +1,54 @@
+
+#include "api.h"
+#include "crypto_scalarmult.h"
+#include "fe.h"
+
+#ifndef HAVE_TI_MODE
+
+int crypto_scalarmult(unsigned char *q,
+ const unsigned char *n,
+ const unsigned char *p)
+{
+ unsigned char e[32];
+ unsigned int i;
+ fe x1;
+ fe x2;
+ fe z2;
+ fe x3;
+ fe z3;
+ fe tmp0;
+ fe tmp1;
+ int pos;
+ unsigned int swap;
+ unsigned int b;
+
+ for (i = 0;i < 32;++i) e[i] = n[i];
+ e[0] &= 248;
+ e[31] &= 127;
+ e[31] |= 64;
+ fe_frombytes(x1,p);
+ fe_1(x2);
+ fe_0(z2);
+ fe_copy(x3,x1);
+ fe_1(z3);
+
+ swap = 0;
+ for (pos = 254;pos >= 0;--pos) {
+ b = e[pos / 8] >> (pos & 7);
+ b &= 1;
+ swap ^= b;
+ fe_cswap(x2,x3,swap);
+ fe_cswap(z2,z3,swap);
+ swap = b;
+#include "montgomery.h"
+ }
+ fe_cswap(x2,x3,swap);
+ fe_cswap(z2,z3,swap);
+
+ fe_invert(z2,z2);
+ fe_mul(x2,x2,z2);
+ fe_tobytes(q,x2);
+ return 0;
+}
+
+#endif