Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

write zeros in one call

  • Loading branch information...
commit 5ab9f6849aed10ccbbcafaab38c35722c7994000 1 parent af42801
@mherkender authored
Showing with 10 additions and 14 deletions.
  1. +10 −14 sha1.as
View
24 sha1.as
@@ -12,17 +12,9 @@ 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
- 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);
+ const newLen:uint = Math.ceil((originalLength + 9) / 64) * 64 - originalLength - 9;
+ if (newLen) {
+ byteInput.writeBytes(zeroByteArray, 0, newLen);
}
// append the original size of the input
@@ -52,8 +44,9 @@ package {
var w13:int;
var w14:int;
var w15:int;
-
- for (i = byteInput.length >>> 6, byteInput.position = 0; i > 0; --i) {
+
+ byteInput.position = 0;
+ for (var i:int = byteInput.length >>> 6; i > 0; --i) {
// set up variables for this chunk
var a:int = h0;
var b:int = h1;
@@ -150,7 +143,7 @@ package {
h4 += e;
}
- byteInput.length = 0;// cleanup
+ byteInput.length = 0;
var result:String = uint(h4).toString(16);
var zeros:Array = staticZeros;
@@ -180,3 +173,6 @@ const staticByteArray:ByteArray = new ByteArray();
staticByteArray.endian = "bigEndian";
const staticZeros:Array = ["", "0", "00", "000", "0000", "00000", "000000", "0000000"];
+
+const zeroByteArray:ByteArray = new ByteArray();
+zeroByteArray.length = 64; // enough zeros to fill one chunk
Please sign in to comment.
Something went wrong with that request. Please try again.