aboutsummaryrefslogtreecommitdiff
path: root/src/Specific/Framework
diff options
context:
space:
mode:
authorGravatar Jason Gross <jgross@mit.edu>2017-10-31 18:35:38 -0400
committerGravatar Jason Gross <jgross@mit.edu>2017-11-02 02:35:08 -0400
commitafddaceed8a54d9b1ef26efea6ea69aa01725d67 (patch)
tree2e359c423c1ba7bc0e1c7d07c3f717da59755982 /src/Specific/Framework
parentb27927fa530bc750a905b05884beb9a8c51cfac4 (diff)
Allow passing -Dq, -Dmodulus_bytes, -Da24 to montladder.py
Diffstat (limited to 'src/Specific/Framework')
-rw-r--r--src/Specific/Framework/bench/montladder.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/Specific/Framework/bench/montladder.py b/src/Specific/Framework/bench/montladder.py
index da32c73d2..e30e3454c 100644
--- a/src/Specific/Framework/bench/montladder.py
+++ b/src/Specific/Framework/bench/montladder.py
@@ -1,7 +1,44 @@
+#!/usr/bin/env python
+import sys, re
+
q = 2**448 - 2**224 - 1
modulus_bytes = 56
a24 = 39081
+def eval_numexpr(numexpr):
+ # copying from https://stackoverflow.com/a/25437733/377022
+ numexpr = re.sub(r"\.(?![0-9])", "", numexpr) # purge any instance of '.' not followed by a number
+ return eval(numexpr, {'__builtins__':None})
+
+def usage(args, updates, retcode=0):
+ print('USAGE: %s %s' % (args[0], ' '.join('[-D%s=NUMEXPR]' % k for k, v in updates)))
+ sys.exit(retcode)
+
+def update_defaults(args):
+ global q
+ global modulus_bytes
+ global a24
+ updates = (('q',q), ('modulus_bytes',modulus_bytes), ('a24',a24))
+ if '--help' in args or '-h' in args: usage(args, updates)
+ updates = dict(updates)
+ found = []
+ for k in updates.keys():
+ for arg in args[1:]:
+ if arg.startswith('-D%s=' % k):
+ found.append(arg)
+ updates[k] = eval_numexpr(arg[len('-D%s=' % k):])
+ elif arg.startswith('-D%s' % k):
+ found.append(arg)
+ updates[k] = eval_numexpr(arg[len('-D%s' % k):])
+ unfound = [arg for arg in args[1:] if arg not in found]
+ if len(unfound) > 0:
+ print('ERROR: unrecognized arguments: ' + ' '.join(map(repr, unfound)))
+ usage(args, updates, retcode=1)
+ q = updates['q']
+ modulus_bytes = updates['modulus_bytes']
+ a24 = updates['a24']
+ print('q: %(q)s, modulus_bytes: %(modulus_bytes)s, a24: %(a24)s' % updates)
+
def ladderstep(x1, x, z, x_p, z_p):
origx = x
x = (x + z)%q
@@ -44,6 +81,7 @@ def crypto_scalarmult(secret, secretbits, point):
return [((x >> (8*i)) & 0xff) for i in range(modulus_bytes)]
if __name__ == '__main__':
+ update_defaults(sys.argv)
BASE = [5]+(modulus_bytes-1)*[0]
print (crypto_scalarmult([1]+(modulus_bytes-1)*[0], 8*modulus_bytes, BASE))