Permalink
Browse files

less var accesses

  • Loading branch information...
mherkender committed Apr 2, 2012
1 parent b6939a4 commit 4772f4fb10bc6983a030ec678c3f65833134c0c1
Showing with 93 additions and 179 deletions.
  1. +13 −18 sha1-generator.py
  2. +80 −161 sha1.as
View
@@ -1,29 +1,24 @@
vars = ["a", "b", "c", "d", "e"]
for j in xrange(0, 80):
a, b, c, d, e = vars[-j % 5:] + vars[:-j % 5] # rotate var array
if j < 20:
f = "(b & c) | ((~b) & d)"
f = "(%s & %s) | ((~%s) & %s)" % (b, c, b, d)
k = 0x5A827999
elif j < 40:
f = "b ^ c ^ d"
f = "%s ^ %s ^ %s" % (b, c, d)
k = 0x6ED9EBA1
elif j < 60:
f = "(b & c) | (b & d) | (c & d)"
f = "(%s & %s) | (%s & %s) | (%s & %s)" % (b, c, b, d, c, d)
k = 0x8F1BBCDC
else:
f = "b ^ c ^ d"
f = "%s ^ %s ^ %s" % (b, c, d)
k = 0xCA62C1D6
if j < 16:
print "var w%s:uint = byteInput.readUnsignedInt();" % j
print "tmp = ((a << 5) | (a >>> 27)) + (%s) + e + 0x%08X + w%s; " \
"e = d; " \
"d = c; " \
"c = (b << 30) | (b >>> 2); " \
"b = a; " \
"a = tmp;" % (f, k, j % 16)
print "var w%02d:uint = byteInput.readUnsignedInt();" % j,
w_access = "w%02d" % (j % 16)
else:
print "w%s ^= w%s ^ w%s ^ w%s;" % (j % 16, (j - 3) % 16, (j - 8) % 16, (j - 14) % 16)
print "tmp = ((a << 5) | (a >>> 27)) + (%s) + e + 0x%08X + (w%s = (w%s << 1) | (w%s >>> 31)); " \
"e = d; " \
"d = c; " \
"c = (b << 30) | (b >>> 2); " \
"b = a; " \
"a = tmp;" % (f, k, j % 16, j % 16, j % 16)
print "w%02d ^= w%02d ^ w%02d ^ w%02d;" % (j % 16, (j - 3) % 16, (j - 8) % 16, (j - 14) % 16),
w_access = "(w%02d = (w%02d << 1) | (w%02d >>> 31))" % (j % 16, j % 16, j % 16)
print "%s += ((%s << 5) | (%s >>> 27)) + (%s) + 0x%08X + %s;" % (
e, a, a, f, k, w_access),
print "%s = (%s << 30) | (%s >>> 2);" % (b, b, b)
Oops, something went wrong.

0 comments on commit 4772f4f

Please sign in to comment.