diff options
author | Nick Mathewson <nickm@torproject.org> | 2014-08-26 10:08:44 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2014-08-26 10:08:44 -0400 |
commit | b40ac6808f8a31f2f95de435036a6a7af111fdff (patch) | |
tree | a668d3a32778547b5f91086507cb6be56ab9cad9 /src/ext/ed25519/ref10/d.py | |
parent | fdb7fc70d03d21d967db4928960241a624483a24 (diff) | |
download | tor-b40ac6808f8a31f2f95de435036a6a7af111fdff.tar.gz tor-b40ac6808f8a31f2f95de435036a6a7af111fdff.zip |
Add the ed25519 ref10 code verbatim from supercop-20140622
We might use libsodium or ed25519-donna later on, but for now, let's
see whether this is fast enough. We should use it in all cases when
performance doesn't matter.
Diffstat (limited to 'src/ext/ed25519/ref10/d.py')
-rw-r--r-- | src/ext/ed25519/ref10/d.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/ext/ed25519/ref10/d.py b/src/ext/ed25519/ref10/d.py new file mode 100644 index 0000000000..8995bb86a3 --- /dev/null +++ b/src/ext/ed25519/ref10/d.py @@ -0,0 +1,28 @@ +q = 2**255 - 19 + +def expmod(b,e,m): + if e == 0: return 1 + t = expmod(b,e/2,m)**2 % m + if e & 1: t = (t*b) % m + return t + +def inv(x): + return expmod(x,q-2,q) + +def radix255(x): + x = x % q + if x + x > q: x -= q + x = [x,0,0,0,0,0,0,0,0,0] + bits = [26,25,26,25,26,25,26,25,26,25] + for i in range(9): + carry = (x[i] + 2**(bits[i]-1)) / 2**bits[i] + x[i] -= carry * 2**bits[i] + x[i + 1] += carry + result = "" + for i in range(9): + result = result+str(x[i])+"," + result = result+str(x[9]) + return result + +d = -121665 * inv(121666) +print radix255(d) |