From b2300f36cec6c95225a1e813df2e5bfa4d20f893 Mon Sep 17 00:00:00 2001 From: Matthew Iversen Date: Mon, 7 Oct 2013 01:39:22 +1100 Subject: [PATCH 1/2] Speed up by fast unpacking Replace manual bit unpacking of integers with C-speed unpacking using the struct module. Conflicts: ed25519.py --- ed25519.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/ed25519.py b/ed25519.py index 7f9cf6d..731e892 100644 --- a/ed25519.py +++ b/ed25519.py @@ -15,6 +15,8 @@ import hashlib import operator import sys +import struct +import functools __version__ = "1.0.dev0" @@ -27,6 +29,7 @@ indexbytes = operator.getitem intlist2bytes = bytes int2byte = operator.methodcaller("to_bytes", 1, "big") + reduce = functools.reduce else: int2byte = chr range = xrange @@ -201,19 +204,26 @@ def bit(h, i): def publickey(sk): h = H(sk) - a = 2 ** (b - 2) + sum(2 ** i * bit(h, i) for i in range(3, b - 2)) + a = 2 ** (b - 2) \ + + (reduce(lambda a, x: a << 64 | x, + struct.unpack(' Date: Mon, 7 Oct 2013 03:16:04 +1100 Subject: [PATCH 2/2] Refactor reduce into decodeint Add a small comment noting generation of public key --- ed25519.py | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/ed25519.py b/ed25519.py index 731e892..b2062ca 100644 --- a/ed25519.py +++ b/ed25519.py @@ -204,26 +204,23 @@ def bit(h, i): def publickey(sk): h = H(sk) - a = 2 ** (b - 2) \ - + (reduce(lambda a, x: a << 64 | x, - struct.unpack('