Permalink
Browse files

attempt to simplify some of the operations during chunk processing

  • Loading branch information...
1 parent 506c007 commit 7cce2655cb2645c43b7ff20347f117cab9db81ea @mherkender committed Mar 19, 2012
Showing with 42 additions and 42 deletions.
  1. +2 −2 sha1-generator.py
  2. +40 −40 sha1.as
View
@@ -2,13 +2,13 @@
for j in xrange(0, 80):
a, b, c, d, e = vars[-j % 5:] + vars[:-j % 5] # rotate var array
if j < 20:
- f = "(%s & %s) | ((~%s) & %s)" % (b, c, b, d)
+ f = "%s ^ (%s & (%s ^ %s))" % (d, b, c, d)
k = 0x5A827999
elif j < 40:
f = "%s ^ %s ^ %s" % (b, c, d)
k = 0x6ED9EBA1
elif j < 60:
- f = "(%s & %s) | (%s & %s) | (%s & %s)" % (b, c, b, d, c, d)
+ f = "(%s & %s) | (%s & (%s | %s))" % (b, c, d, b, c)
k = 0x8F1BBCDC
else:
f = "%s ^ %s ^ %s" % (b, c, d)
View
@@ -37,26 +37,26 @@ package {
var e:int = h4;
// this does all the heavy processing on the input
- var w00:int = byteInput.readInt(); e += ((a << 5) | (a >>> 27)) + ((b & c) | ((~b) & d)) + 0x5A827999 + w00; b = (b << 30) | (b >>> 2);
- var w01:int = byteInput.readInt(); d += ((e << 5) | (e >>> 27)) + ((a & b) | ((~a) & c)) + 0x5A827999 + w01; a = (a << 30) | (a >>> 2);
- var w02:int = byteInput.readInt(); c += ((d << 5) | (d >>> 27)) + ((e & a) | ((~e) & b)) + 0x5A827999 + w02; e = (e << 30) | (e >>> 2);
- var w03:int = byteInput.readInt(); b += ((c << 5) | (c >>> 27)) + ((d & e) | ((~d) & a)) + 0x5A827999 + w03; d = (d << 30) | (d >>> 2);
- var w04:int = byteInput.readInt(); a += ((b << 5) | (b >>> 27)) + ((c & d) | ((~c) & e)) + 0x5A827999 + w04; c = (c << 30) | (c >>> 2);
- var w05:int = byteInput.readInt(); e += ((a << 5) | (a >>> 27)) + ((b & c) | ((~b) & d)) + 0x5A827999 + w05; b = (b << 30) | (b >>> 2);
- var w06:int = byteInput.readInt(); d += ((e << 5) | (e >>> 27)) + ((a & b) | ((~a) & c)) + 0x5A827999 + w06; a = (a << 30) | (a >>> 2);
- var w07:int = byteInput.readInt(); c += ((d << 5) | (d >>> 27)) + ((e & a) | ((~e) & b)) + 0x5A827999 + w07; e = (e << 30) | (e >>> 2);
- var w08:int = byteInput.readInt(); b += ((c << 5) | (c >>> 27)) + ((d & e) | ((~d) & a)) + 0x5A827999 + w08; d = (d << 30) | (d >>> 2);
- var w09:int = byteInput.readInt(); a += ((b << 5) | (b >>> 27)) + ((c & d) | ((~c) & e)) + 0x5A827999 + w09; c = (c << 30) | (c >>> 2);
- var w10:int = byteInput.readInt(); e += ((a << 5) | (a >>> 27)) + ((b & c) | ((~b) & d)) + 0x5A827999 + w10; b = (b << 30) | (b >>> 2);
- var w11:int = byteInput.readInt(); d += ((e << 5) | (e >>> 27)) + ((a & b) | ((~a) & c)) + 0x5A827999 + w11; a = (a << 30) | (a >>> 2);
- var w12:int = byteInput.readInt(); c += ((d << 5) | (d >>> 27)) + ((e & a) | ((~e) & b)) + 0x5A827999 + w12; e = (e << 30) | (e >>> 2);
- var w13:int = byteInput.readInt(); b += ((c << 5) | (c >>> 27)) + ((d & e) | ((~d) & a)) + 0x5A827999 + w13; d = (d << 30) | (d >>> 2);
- var w14:int = byteInput.readInt(); a += ((b << 5) | (b >>> 27)) + ((c & d) | ((~c) & e)) + 0x5A827999 + w14; c = (c << 30) | (c >>> 2);
- var w15:int = byteInput.readInt(); e += ((a << 5) | (a >>> 27)) + ((b & c) | ((~b) & d)) + 0x5A827999 + w15; b = (b << 30) | (b >>> 2);
- w00 ^= w13 ^ w08 ^ w02; d += ((e << 5) | (e >>> 27)) + ((a & b) | ((~a) & c)) + 0x5A827999 + (w00 = (w00 << 1) | (w00 >>> 31)); a = (a << 30) | (a >>> 2);
- w01 ^= w14 ^ w09 ^ w03; c += ((d << 5) | (d >>> 27)) + ((e & a) | ((~e) & b)) + 0x5A827999 + (w01 = (w01 << 1) | (w01 >>> 31)); e = (e << 30) | (e >>> 2);
- w02 ^= w15 ^ w10 ^ w04; b += ((c << 5) | (c >>> 27)) + ((d & e) | ((~d) & a)) + 0x5A827999 + (w02 = (w02 << 1) | (w02 >>> 31)); d = (d << 30) | (d >>> 2);
- w03 ^= w00 ^ w11 ^ w05; a += ((b << 5) | (b >>> 27)) + ((c & d) | ((~c) & e)) + 0x5A827999 + (w03 = (w03 << 1) | (w03 >>> 31)); c = (c << 30) | (c >>> 2);
+ var w00:int = byteInput.readInt(); e += ((a << 5) | (a >>> 27)) + (d ^ (b & (c ^ d))) + 0x5A827999 + w00; b = (b << 30) | (b >>> 2);
+ var w01:int = byteInput.readInt(); d += ((e << 5) | (e >>> 27)) + (c ^ (a & (b ^ c))) + 0x5A827999 + w01; a = (a << 30) | (a >>> 2);
+ var w02:int = byteInput.readInt(); c += ((d << 5) | (d >>> 27)) + (b ^ (e & (a ^ b))) + 0x5A827999 + w02; e = (e << 30) | (e >>> 2);
+ var w03:int = byteInput.readInt(); b += ((c << 5) | (c >>> 27)) + (a ^ (d & (e ^ a))) + 0x5A827999 + w03; d = (d << 30) | (d >>> 2);
+ var w04:int = byteInput.readInt(); a += ((b << 5) | (b >>> 27)) + (e ^ (c & (d ^ e))) + 0x5A827999 + w04; c = (c << 30) | (c >>> 2);
+ var w05:int = byteInput.readInt(); e += ((a << 5) | (a >>> 27)) + (d ^ (b & (c ^ d))) + 0x5A827999 + w05; b = (b << 30) | (b >>> 2);
+ var w06:int = byteInput.readInt(); d += ((e << 5) | (e >>> 27)) + (c ^ (a & (b ^ c))) + 0x5A827999 + w06; a = (a << 30) | (a >>> 2);
+ var w07:int = byteInput.readInt(); c += ((d << 5) | (d >>> 27)) + (b ^ (e & (a ^ b))) + 0x5A827999 + w07; e = (e << 30) | (e >>> 2);
+ var w08:int = byteInput.readInt(); b += ((c << 5) | (c >>> 27)) + (a ^ (d & (e ^ a))) + 0x5A827999 + w08; d = (d << 30) | (d >>> 2);
+ var w09:int = byteInput.readInt(); a += ((b << 5) | (b >>> 27)) + (e ^ (c & (d ^ e))) + 0x5A827999 + w09; c = (c << 30) | (c >>> 2);
+ var w10:int = byteInput.readInt(); e += ((a << 5) | (a >>> 27)) + (d ^ (b & (c ^ d))) + 0x5A827999 + w10; b = (b << 30) | (b >>> 2);
+ var w11:int = byteInput.readInt(); d += ((e << 5) | (e >>> 27)) + (c ^ (a & (b ^ c))) + 0x5A827999 + w11; a = (a << 30) | (a >>> 2);
+ var w12:int = byteInput.readInt(); c += ((d << 5) | (d >>> 27)) + (b ^ (e & (a ^ b))) + 0x5A827999 + w12; e = (e << 30) | (e >>> 2);
+ var w13:int = byteInput.readInt(); b += ((c << 5) | (c >>> 27)) + (a ^ (d & (e ^ a))) + 0x5A827999 + w13; d = (d << 30) | (d >>> 2);
+ var w14:int = byteInput.readInt(); a += ((b << 5) | (b >>> 27)) + (e ^ (c & (d ^ e))) + 0x5A827999 + w14; c = (c << 30) | (c >>> 2);
+ var w15:int = byteInput.readInt(); e += ((a << 5) | (a >>> 27)) + (d ^ (b & (c ^ d))) + 0x5A827999 + w15; b = (b << 30) | (b >>> 2);
+ w00 ^= w13 ^ w08 ^ w02; d += ((e << 5) | (e >>> 27)) + (c ^ (a & (b ^ c))) + 0x5A827999 + (w00 = (w00 << 1) | (w00 >>> 31)); a = (a << 30) | (a >>> 2);
+ w01 ^= w14 ^ w09 ^ w03; c += ((d << 5) | (d >>> 27)) + (b ^ (e & (a ^ b))) + 0x5A827999 + (w01 = (w01 << 1) | (w01 >>> 31)); e = (e << 30) | (e >>> 2);
+ w02 ^= w15 ^ w10 ^ w04; b += ((c << 5) | (c >>> 27)) + (a ^ (d & (e ^ a))) + 0x5A827999 + (w02 = (w02 << 1) | (w02 >>> 31)); d = (d << 30) | (d >>> 2);
+ w03 ^= w00 ^ w11 ^ w05; a += ((b << 5) | (b >>> 27)) + (e ^ (c & (d ^ e))) + 0x5A827999 + (w03 = (w03 << 1) | (w03 >>> 31)); c = (c << 30) | (c >>> 2);
w04 ^= w01 ^ w12 ^ w06; e += ((a << 5) | (a >>> 27)) + (b ^ c ^ d) + 0x6ED9EBA1 + (w04 = (w04 << 1) | (w04 >>> 31)); b = (b << 30) | (b >>> 2);
w05 ^= w02 ^ w13 ^ w07; d += ((e << 5) | (e >>> 27)) + (a ^ b ^ c) + 0x6ED9EBA1 + (w05 = (w05 << 1) | (w05 >>> 31)); a = (a << 30) | (a >>> 2);
w06 ^= w03 ^ w14 ^ w08; c += ((d << 5) | (d >>> 27)) + (e ^ a ^ b) + 0x6ED9EBA1 + (w06 = (w06 << 1) | (w06 >>> 31)); e = (e << 30) | (e >>> 2);
@@ -77,26 +77,26 @@ package {
w05 ^= w02 ^ w13 ^ w07; c += ((d << 5) | (d >>> 27)) + (e ^ a ^ b) + 0x6ED9EBA1 + (w05 = (w05 << 1) | (w05 >>> 31)); e = (e << 30) | (e >>> 2);
w06 ^= w03 ^ w14 ^ w08; b += ((c << 5) | (c >>> 27)) + (d ^ e ^ a) + 0x6ED9EBA1 + (w06 = (w06 << 1) | (w06 >>> 31)); d = (d << 30) | (d >>> 2);
w07 ^= w04 ^ w15 ^ w09; a += ((b << 5) | (b >>> 27)) + (c ^ d ^ e) + 0x6ED9EBA1 + (w07 = (w07 << 1) | (w07 >>> 31)); c = (c << 30) | (c >>> 2);
- w08 ^= w05 ^ w00 ^ w10; e += ((a << 5) | (a >>> 27)) + ((b & c) | (b & d) | (c & d)) - 0x70E44324 + (w08 = (w08 << 1) | (w08 >>> 31)); b = (b << 30) | (b >>> 2);
- w09 ^= w06 ^ w01 ^ w11; d += ((e << 5) | (e >>> 27)) + ((a & b) | (a & c) | (b & c)) - 0x70E44324 + (w09 = (w09 << 1) | (w09 >>> 31)); a = (a << 30) | (a >>> 2);
- w10 ^= w07 ^ w02 ^ w12; c += ((d << 5) | (d >>> 27)) + ((e & a) | (e & b) | (a & b)) - 0x70E44324 + (w10 = (w10 << 1) | (w10 >>> 31)); e = (e << 30) | (e >>> 2);
- w11 ^= w08 ^ w03 ^ w13; b += ((c << 5) | (c >>> 27)) + ((d & e) | (d & a) | (e & a)) - 0x70E44324 + (w11 = (w11 << 1) | (w11 >>> 31)); d = (d << 30) | (d >>> 2);
- w12 ^= w09 ^ w04 ^ w14; a += ((b << 5) | (b >>> 27)) + ((c & d) | (c & e) | (d & e)) - 0x70E44324 + (w12 = (w12 << 1) | (w12 >>> 31)); c = (c << 30) | (c >>> 2);
- w13 ^= w10 ^ w05 ^ w15; e += ((a << 5) | (a >>> 27)) + ((b & c) | (b & d) | (c & d)) - 0x70E44324 + (w13 = (w13 << 1) | (w13 >>> 31)); b = (b << 30) | (b >>> 2);
- w14 ^= w11 ^ w06 ^ w00; d += ((e << 5) | (e >>> 27)) + ((a & b) | (a & c) | (b & c)) - 0x70E44324 + (w14 = (w14 << 1) | (w14 >>> 31)); a = (a << 30) | (a >>> 2);
- w15 ^= w12 ^ w07 ^ w01; c += ((d << 5) | (d >>> 27)) + ((e & a) | (e & b) | (a & b)) - 0x70E44324 + (w15 = (w15 << 1) | (w15 >>> 31)); e = (e << 30) | (e >>> 2);
- w00 ^= w13 ^ w08 ^ w02; b += ((c << 5) | (c >>> 27)) + ((d & e) | (d & a) | (e & a)) - 0x70E44324 + (w00 = (w00 << 1) | (w00 >>> 31)); d = (d << 30) | (d >>> 2);
- w01 ^= w14 ^ w09 ^ w03; a += ((b << 5) | (b >>> 27)) + ((c & d) | (c & e) | (d & e)) - 0x70E44324 + (w01 = (w01 << 1) | (w01 >>> 31)); c = (c << 30) | (c >>> 2);
- w02 ^= w15 ^ w10 ^ w04; e += ((a << 5) | (a >>> 27)) + ((b & c) | (b & d) | (c & d)) - 0x70E44324 + (w02 = (w02 << 1) | (w02 >>> 31)); b = (b << 30) | (b >>> 2);
- w03 ^= w00 ^ w11 ^ w05; d += ((e << 5) | (e >>> 27)) + ((a & b) | (a & c) | (b & c)) - 0x70E44324 + (w03 = (w03 << 1) | (w03 >>> 31)); a = (a << 30) | (a >>> 2);
- w04 ^= w01 ^ w12 ^ w06; c += ((d << 5) | (d >>> 27)) + ((e & a) | (e & b) | (a & b)) - 0x70E44324 + (w04 = (w04 << 1) | (w04 >>> 31)); e = (e << 30) | (e >>> 2);
- w05 ^= w02 ^ w13 ^ w07; b += ((c << 5) | (c >>> 27)) + ((d & e) | (d & a) | (e & a)) - 0x70E44324 + (w05 = (w05 << 1) | (w05 >>> 31)); d = (d << 30) | (d >>> 2);
- w06 ^= w03 ^ w14 ^ w08; a += ((b << 5) | (b >>> 27)) + ((c & d) | (c & e) | (d & e)) - 0x70E44324 + (w06 = (w06 << 1) | (w06 >>> 31)); c = (c << 30) | (c >>> 2);
- w07 ^= w04 ^ w15 ^ w09; e += ((a << 5) | (a >>> 27)) + ((b & c) | (b & d) | (c & d)) - 0x70E44324 + (w07 = (w07 << 1) | (w07 >>> 31)); b = (b << 30) | (b >>> 2);
- w08 ^= w05 ^ w00 ^ w10; d += ((e << 5) | (e >>> 27)) + ((a & b) | (a & c) | (b & c)) - 0x70E44324 + (w08 = (w08 << 1) | (w08 >>> 31)); a = (a << 30) | (a >>> 2);
- w09 ^= w06 ^ w01 ^ w11; c += ((d << 5) | (d >>> 27)) + ((e & a) | (e & b) | (a & b)) - 0x70E44324 + (w09 = (w09 << 1) | (w09 >>> 31)); e = (e << 30) | (e >>> 2);
- w10 ^= w07 ^ w02 ^ w12; b += ((c << 5) | (c >>> 27)) + ((d & e) | (d & a) | (e & a)) - 0x70E44324 + (w10 = (w10 << 1) | (w10 >>> 31)); d = (d << 30) | (d >>> 2);
- w11 ^= w08 ^ w03 ^ w13; a += ((b << 5) | (b >>> 27)) + ((c & d) | (c & e) | (d & e)) - 0x70E44324 + (w11 = (w11 << 1) | (w11 >>> 31)); c = (c << 30) | (c >>> 2);
+ w08 ^= w05 ^ w00 ^ w10; e += ((a << 5) | (a >>> 27)) + ((b & c) | (d & (b | c))) - 0x70E44324 + (w08 = (w08 << 1) | (w08 >>> 31)); b = (b << 30) | (b >>> 2);
+ w09 ^= w06 ^ w01 ^ w11; d += ((e << 5) | (e >>> 27)) + ((a & b) | (c & (a | b))) - 0x70E44324 + (w09 = (w09 << 1) | (w09 >>> 31)); a = (a << 30) | (a >>> 2);
+ w10 ^= w07 ^ w02 ^ w12; c += ((d << 5) | (d >>> 27)) + ((e & a) | (b & (e | a))) - 0x70E44324 + (w10 = (w10 << 1) | (w10 >>> 31)); e = (e << 30) | (e >>> 2);
+ w11 ^= w08 ^ w03 ^ w13; b += ((c << 5) | (c >>> 27)) + ((d & e) | (a & (d | e))) - 0x70E44324 + (w11 = (w11 << 1) | (w11 >>> 31)); d = (d << 30) | (d >>> 2);
+ w12 ^= w09 ^ w04 ^ w14; a += ((b << 5) | (b >>> 27)) + ((c & d) | (e & (c | d))) - 0x70E44324 + (w12 = (w12 << 1) | (w12 >>> 31)); c = (c << 30) | (c >>> 2);
+ w13 ^= w10 ^ w05 ^ w15; e += ((a << 5) | (a >>> 27)) + ((b & c) | (d & (b | c))) - 0x70E44324 + (w13 = (w13 << 1) | (w13 >>> 31)); b = (b << 30) | (b >>> 2);
+ w14 ^= w11 ^ w06 ^ w00; d += ((e << 5) | (e >>> 27)) + ((a & b) | (c & (a | b))) - 0x70E44324 + (w14 = (w14 << 1) | (w14 >>> 31)); a = (a << 30) | (a >>> 2);
+ w15 ^= w12 ^ w07 ^ w01; c += ((d << 5) | (d >>> 27)) + ((e & a) | (b & (e | a))) - 0x70E44324 + (w15 = (w15 << 1) | (w15 >>> 31)); e = (e << 30) | (e >>> 2);
+ w00 ^= w13 ^ w08 ^ w02; b += ((c << 5) | (c >>> 27)) + ((d & e) | (a & (d | e))) - 0x70E44324 + (w00 = (w00 << 1) | (w00 >>> 31)); d = (d << 30) | (d >>> 2);
+ w01 ^= w14 ^ w09 ^ w03; a += ((b << 5) | (b >>> 27)) + ((c & d) | (e & (c | d))) - 0x70E44324 + (w01 = (w01 << 1) | (w01 >>> 31)); c = (c << 30) | (c >>> 2);
+ w02 ^= w15 ^ w10 ^ w04; e += ((a << 5) | (a >>> 27)) + ((b & c) | (d & (b | c))) - 0x70E44324 + (w02 = (w02 << 1) | (w02 >>> 31)); b = (b << 30) | (b >>> 2);
+ w03 ^= w00 ^ w11 ^ w05; d += ((e << 5) | (e >>> 27)) + ((a & b) | (c & (a | b))) - 0x70E44324 + (w03 = (w03 << 1) | (w03 >>> 31)); a = (a << 30) | (a >>> 2);
+ w04 ^= w01 ^ w12 ^ w06; c += ((d << 5) | (d >>> 27)) + ((e & a) | (b & (e | a))) - 0x70E44324 + (w04 = (w04 << 1) | (w04 >>> 31)); e = (e << 30) | (e >>> 2);
+ w05 ^= w02 ^ w13 ^ w07; b += ((c << 5) | (c >>> 27)) + ((d & e) | (a & (d | e))) - 0x70E44324 + (w05 = (w05 << 1) | (w05 >>> 31)); d = (d << 30) | (d >>> 2);
+ w06 ^= w03 ^ w14 ^ w08; a += ((b << 5) | (b >>> 27)) + ((c & d) | (e & (c | d))) - 0x70E44324 + (w06 = (w06 << 1) | (w06 >>> 31)); c = (c << 30) | (c >>> 2);
+ w07 ^= w04 ^ w15 ^ w09; e += ((a << 5) | (a >>> 27)) + ((b & c) | (d & (b | c))) - 0x70E44324 + (w07 = (w07 << 1) | (w07 >>> 31)); b = (b << 30) | (b >>> 2);
+ w08 ^= w05 ^ w00 ^ w10; d += ((e << 5) | (e >>> 27)) + ((a & b) | (c & (a | b))) - 0x70E44324 + (w08 = (w08 << 1) | (w08 >>> 31)); a = (a << 30) | (a >>> 2);
+ w09 ^= w06 ^ w01 ^ w11; c += ((d << 5) | (d >>> 27)) + ((e & a) | (b & (e | a))) - 0x70E44324 + (w09 = (w09 << 1) | (w09 >>> 31)); e = (e << 30) | (e >>> 2);
+ w10 ^= w07 ^ w02 ^ w12; b += ((c << 5) | (c >>> 27)) + ((d & e) | (a & (d | e))) - 0x70E44324 + (w10 = (w10 << 1) | (w10 >>> 31)); d = (d << 30) | (d >>> 2);
+ w11 ^= w08 ^ w03 ^ w13; a += ((b << 5) | (b >>> 27)) + ((c & d) | (e & (c | d))) - 0x70E44324 + (w11 = (w11 << 1) | (w11 >>> 31)); c = (c << 30) | (c >>> 2);
w12 ^= w09 ^ w04 ^ w14; e += ((a << 5) | (a >>> 27)) + (b ^ c ^ d) - 0x359D3E2A + (w12 = (w12 << 1) | (w12 >>> 31)); b = (b << 30) | (b >>> 2);
w13 ^= w10 ^ w05 ^ w15; d += ((e << 5) | (e >>> 27)) + (a ^ b ^ c) - 0x359D3E2A + (w13 = (w13 << 1) | (w13 >>> 31)); a = (a << 30) | (a >>> 2);
w14 ^= w11 ^ w06 ^ w00; c += ((d << 5) | (d >>> 27)) + (e ^ a ^ b) - 0x359D3E2A + (w14 = (w14 << 1) | (w14 >>> 31)); e = (e << 30) | (e >>> 2);

0 comments on commit 7cce265

Please sign in to comment.