Skip to content

Commit

Permalink
less calls to writeInt
Browse files Browse the repository at this point in the history
  • Loading branch information
mherkender committed Apr 2, 2012
1 parent ec203c5 commit fea6568
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions sha1.as
Expand Up @@ -12,8 +12,17 @@ package {

// sha-1 adds a 64-bit integer that has the size
// BUT enough zeros need to be added so that they'll be at the end of a chunk
for (var i:uint = Math.ceil((byteInput.length + 8) / 64) * 64 - byteInput.length - 8; i > 0; --i) {
byteInput.writeByte(0x00);
var i:int = Math.ceil((originalLength + 9) / 64) * 64 - originalLength - 9;
for (; i >= 4; i -= 4) {
byteInput.writeInt(0x0);
}
if (i >= 2) {
byteInput.writeShort(0x0);
if (i === 3) {
byteInput.writeByte(0x0);
}
} else if (i === 1) {
byteInput.writeByte(0x0);
}

// append the original size of the input
Expand Down Expand Up @@ -44,7 +53,8 @@ package {
var w14:int;
var w15:int;

for (i = 0, byteInput.position = 0; i < byteInput.length; i += 64) {
const len:int = byteInput.length >>> 6;
for (i = 0, byteInput.position = 0; i < len; ++i) {
// set up variables for this chunk
var a:int = h0;
var b:int = h1;
Expand Down

0 comments on commit fea6568

Please sign in to comment.