Permalink
Browse files

inline w var set

  • Loading branch information...
1 parent 7cce265 commit 0afe394ab7afb475f1f57f3a69d265ab1071e7d9 @mherkender committed Mar 19, 2012
Showing with 33 additions and 18 deletions.
  1. +1 −2 sha1-generator.py
  2. +32 −16 sha1.as
View
@@ -20,8 +20,7 @@
k = "+ 0x%08X" % k
if j < 16:
- print "var w%02d:int = byteInput.readInt();" % j,
- w_access = "w%02d" % (j % 16)
+ w_access = "(w%02d = byteInput.readInt())" % j
else:
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)
View
@@ -27,6 +27,22 @@ package {
var h2:int = -0x67452302;
var h3:int = 0x10325476;
var h4:int = -0x3c2d1e10;
+ var w00:int;
+ var w01:int;
+ var w02:int;
+ var w03:int;
+ var w04:int;
+ var w05:int;
+ var w06:int;
+ var w07:int;
+ var w08:int;
+ var w09:int;
+ var w10:int;
+ var w11:int;
+ var w12:int;
+ var w13:int;
+ var w14:int;
+ var w15:int;
for (i = 0, byteInput.position = 0; i < byteInput.length; i += 64) {
// set up variables for this chunk
@@ -37,22 +53,22 @@ package {
var e:int = h4;
// this does all the heavy processing on the input
- 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);
+ e += ((a << 5) | (a >>> 27)) + (d ^ (b & (c ^ d))) + 0x5A827999 + (w00 = byteInput.readInt()); b = (b << 30) | (b >>> 2);
+ d += ((e << 5) | (e >>> 27)) + (c ^ (a & (b ^ c))) + 0x5A827999 + (w01 = byteInput.readInt()); a = (a << 30) | (a >>> 2);
+ c += ((d << 5) | (d >>> 27)) + (b ^ (e & (a ^ b))) + 0x5A827999 + (w02 = byteInput.readInt()); e = (e << 30) | (e >>> 2);
+ b += ((c << 5) | (c >>> 27)) + (a ^ (d & (e ^ a))) + 0x5A827999 + (w03 = byteInput.readInt()); d = (d << 30) | (d >>> 2);
+ a += ((b << 5) | (b >>> 27)) + (e ^ (c & (d ^ e))) + 0x5A827999 + (w04 = byteInput.readInt()); c = (c << 30) | (c >>> 2);
+ e += ((a << 5) | (a >>> 27)) + (d ^ (b & (c ^ d))) + 0x5A827999 + (w05 = byteInput.readInt()); b = (b << 30) | (b >>> 2);
+ d += ((e << 5) | (e >>> 27)) + (c ^ (a & (b ^ c))) + 0x5A827999 + (w06 = byteInput.readInt()); a = (a << 30) | (a >>> 2);
+ c += ((d << 5) | (d >>> 27)) + (b ^ (e & (a ^ b))) + 0x5A827999 + (w07 = byteInput.readInt()); e = (e << 30) | (e >>> 2);
+ b += ((c << 5) | (c >>> 27)) + (a ^ (d & (e ^ a))) + 0x5A827999 + (w08 = byteInput.readInt()); d = (d << 30) | (d >>> 2);
+ a += ((b << 5) | (b >>> 27)) + (e ^ (c & (d ^ e))) + 0x5A827999 + (w09 = byteInput.readInt()); c = (c << 30) | (c >>> 2);
+ e += ((a << 5) | (a >>> 27)) + (d ^ (b & (c ^ d))) + 0x5A827999 + (w10 = byteInput.readInt()); b = (b << 30) | (b >>> 2);
+ d += ((e << 5) | (e >>> 27)) + (c ^ (a & (b ^ c))) + 0x5A827999 + (w11 = byteInput.readInt()); a = (a << 30) | (a >>> 2);
+ c += ((d << 5) | (d >>> 27)) + (b ^ (e & (a ^ b))) + 0x5A827999 + (w12 = byteInput.readInt()); e = (e << 30) | (e >>> 2);
+ b += ((c << 5) | (c >>> 27)) + (a ^ (d & (e ^ a))) + 0x5A827999 + (w13 = byteInput.readInt()); d = (d << 30) | (d >>> 2);
+ a += ((b << 5) | (b >>> 27)) + (e ^ (c & (d ^ e))) + 0x5A827999 + (w14 = byteInput.readInt()); c = (c << 30) | (c >>> 2);
+ e += ((a << 5) | (a >>> 27)) + (d ^ (b & (c ^ d))) + 0x5A827999 + (w15 = byteInput.readInt()); 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);

0 comments on commit 0afe394

Please sign in to comment.