mirror of
https://github.com/burrow-dev/burrow-server.git
synced 2026-11-21 09:37:50 -05:00
Brought up to date with the private repository (feea4c7)
This commit is contained in:
1 parent
1aa738d692
commit
1b1df1ae48
7925 files changed
+2617237
-20
No files matched your search
@@ -0,0 +1,76 @@
|
||||
package com.hurlant.crypto.hash
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class HMAC
|
||||
{
|
||||
|
||||
private var hash:IHash;
|
||||
|
||||
private var bits:uint;
|
||||
|
||||
public function HMAC(hash:IHash, bits:uint = 0)
|
||||
{
|
||||
super();
|
||||
this.hash = hash;
|
||||
this.bits = bits;
|
||||
}
|
||||
|
||||
public function getHashSize() : uint
|
||||
{
|
||||
if(this.bits != 0)
|
||||
{
|
||||
return this.bits / 8;
|
||||
}
|
||||
return this.hash.getHashSize();
|
||||
}
|
||||
|
||||
public function compute(key:ByteArray, data:ByteArray) : ByteArray
|
||||
{
|
||||
var hashKey:ByteArray = null;
|
||||
if(key.length > this.hash.getInputSize())
|
||||
{
|
||||
hashKey = this.hash.hash(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
hashKey = new ByteArray();
|
||||
hashKey.writeBytes(key);
|
||||
}
|
||||
while(hashKey.length < this.hash.getInputSize())
|
||||
{
|
||||
hashKey[hashKey.length] = 0;
|
||||
}
|
||||
var innerKey:ByteArray = new ByteArray();
|
||||
var outerKey:ByteArray = new ByteArray();
|
||||
for(var i:uint = 0; i < hashKey.length; i++)
|
||||
{
|
||||
innerKey[i] = hashKey[i] ^ 0x36;
|
||||
outerKey[i] = hashKey[i] ^ 0x5C;
|
||||
}
|
||||
innerKey.position = hashKey.length;
|
||||
innerKey.writeBytes(data);
|
||||
var innerHash:ByteArray = this.hash.hash(innerKey);
|
||||
outerKey.position = hashKey.length;
|
||||
outerKey.writeBytes(innerHash);
|
||||
var outerHash:ByteArray = this.hash.hash(outerKey);
|
||||
if(this.bits > 0 && this.bits < 8 * outerHash.length)
|
||||
{
|
||||
outerHash.length = this.bits / 8;
|
||||
}
|
||||
return outerHash;
|
||||
}
|
||||
|
||||
public function dispose() : void
|
||||
{
|
||||
this.hash = null;
|
||||
this.bits = 0;
|
||||
}
|
||||
|
||||
public function toString() : String
|
||||
{
|
||||
return "hmac-" + (this.bits > 0 ? this.bits + "-" : "") + this.hash.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.hurlant.crypto.hash
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public interface IHash
|
||||
{
|
||||
|
||||
function getInputSize() : uint;
|
||||
|
||||
function getHashSize() : uint;
|
||||
|
||||
function hash(param1:ByteArray) : ByteArray;
|
||||
|
||||
function toString() : String;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
package com.hurlant.crypto.hash
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class MD2 implements IHash
|
||||
{
|
||||
|
||||
public static const HASH_SIZE:int = 16;
|
||||
|
||||
private static const S:Array = [41,46,67,201,162,216,124,1,61,54,84,161,236,240,6,19,98,167,5,243,192,199,115,140,152,147,43,217,188,76,130,202,30,155,87,60,253,212,224,22,103,66,111,24,138,23,229,18,190,78,196,214,218,158,222,73,160,251,245,142,187,47,238,122,169,104,121,145,21,178,7,63,148,194,16,137,11,34,95,33,128,127,93,154,90,144,50,39,53,62,204,231,191,247,151,3,255,25,48,179,72,165,181,209,215,94,146,42,172,86,170,198,79,184,56,210,150,164,125,182,118,252,107,226,156,116,4,241,69,157,112,89,100,113,135,32,134,91,207,101,230,45,168,2,27,96,37,173,174,176,185,246,28,70,97,105,52,64,126,15,85,71,163,35,221,81,175,58,195,92,249,206,186,197,234,38,44,83,13,110,133,40,132,9,211,223,205,244,65,129,77,82,106,220,55,200,108,193,171,250,36,225,123,8,12,189,177,74,120,136,149,139,227,99,232,109,233,203,213,254,59,0,29,57,242,239,183,14,102,88,208,228,166,119,114,248,235,117,75,10,49,68,80,180,143,237,31,26,219,153,141,51,159,17,131,20];
|
||||
|
||||
public function MD2()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public function getInputSize() : uint
|
||||
{
|
||||
return 16;
|
||||
}
|
||||
|
||||
public function getHashSize() : uint
|
||||
{
|
||||
return HASH_SIZE;
|
||||
}
|
||||
|
||||
public function hash(src:ByteArray) : ByteArray
|
||||
{
|
||||
var j:uint = 0;
|
||||
var t:uint = 0;
|
||||
var k:uint = 0;
|
||||
var savedLength:uint = src.length;
|
||||
var i:uint = uint(uint(16 - src.length % 16) || 16);
|
||||
do
|
||||
{
|
||||
src[src.length] = i;
|
||||
}
|
||||
while(src.length % 16 != 0);
|
||||
var len:uint = src.length;
|
||||
var checksum:ByteArray = new ByteArray();
|
||||
var L:uint = 0;
|
||||
for(i = 0; i < len; i += 16)
|
||||
{
|
||||
for(j = 0; j < 16; j++)
|
||||
{
|
||||
L = uint(checksum[j] = checksum[j] ^ S[src[i + j] ^ L]);
|
||||
}
|
||||
}
|
||||
src.position = src.length;
|
||||
src.writeBytes(checksum);
|
||||
len += 16;
|
||||
var X:ByteArray = new ByteArray();
|
||||
for(i = 0; i < len; i += 16)
|
||||
{
|
||||
for(j = 0; j < 16; j++)
|
||||
{
|
||||
X[32 + j] = (X[16 + j] = src[i + j]) ^ X[j];
|
||||
}
|
||||
t = 0;
|
||||
for(j = 0; j < 18; j++)
|
||||
{
|
||||
for(k = 0; k < 48; k++)
|
||||
{
|
||||
X[k] = t = uint(X[k] ^ S[t]);
|
||||
}
|
||||
t = uint(t + j & 0xFF);
|
||||
}
|
||||
}
|
||||
X.length = 16;
|
||||
src.length = savedLength;
|
||||
return X;
|
||||
}
|
||||
|
||||
public function toString() : String
|
||||
{
|
||||
return "md2";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,195 @@
|
||||
package com.hurlant.crypto.hash
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
import flash.utils.Endian;
|
||||
|
||||
public class MD5 implements IHash
|
||||
{
|
||||
|
||||
public static const HASH_SIZE:int = 16;
|
||||
|
||||
public function MD5()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public function getInputSize() : uint
|
||||
{
|
||||
return 64;
|
||||
}
|
||||
|
||||
public function getHashSize() : uint
|
||||
{
|
||||
return HASH_SIZE;
|
||||
}
|
||||
|
||||
public function hash(src:ByteArray) : ByteArray
|
||||
{
|
||||
var len:uint = src.length * 8;
|
||||
var savedEndian:String = src.endian;
|
||||
while(src.length % 4 != 0)
|
||||
{
|
||||
src[src.length] = 0;
|
||||
}
|
||||
src.position = 0;
|
||||
var a:Array = [];
|
||||
src.endian = Endian.LITTLE_ENDIAN;
|
||||
for(var i:uint = 0; i < src.length; i += 4)
|
||||
{
|
||||
a.push(src.readUnsignedInt());
|
||||
}
|
||||
var h:Array = this.core_md5(a,len);
|
||||
var out:ByteArray = new ByteArray();
|
||||
out.endian = Endian.LITTLE_ENDIAN;
|
||||
for(i = 0; i < 4; i++)
|
||||
{
|
||||
out.writeUnsignedInt(h[i]);
|
||||
}
|
||||
src.length = len / 8;
|
||||
src.endian = savedEndian;
|
||||
return out;
|
||||
}
|
||||
|
||||
private function core_md5(x:Array, len:uint) : Array
|
||||
{
|
||||
var olda:uint = 0;
|
||||
var oldb:uint = 0;
|
||||
var oldc:uint = 0;
|
||||
var oldd:uint = 0;
|
||||
x[len >> 5] |= 128 << len % 32;
|
||||
x[(len + 64 >>> 9 << 4) + 14] = len;
|
||||
var a:uint = 1732584193;
|
||||
var b:uint = 4023233417;
|
||||
var c:uint = 2562383102;
|
||||
var d:uint = 271733878;
|
||||
for(var i:uint = 0; i < x.length; i += 16)
|
||||
{
|
||||
x[i] = x[i] || 0;
|
||||
x[i + 1] = x[i + 1] || 0;
|
||||
x[i + 2] = x[i + 2] || 0;
|
||||
x[i + 3] = x[i + 3] || 0;
|
||||
x[i + 4] = x[i + 4] || 0;
|
||||
x[i + 5] = x[i + 5] || 0;
|
||||
x[i + 6] = x[i + 6] || 0;
|
||||
x[i + 7] = x[i + 7] || 0;
|
||||
x[i + 8] = x[i + 8] || 0;
|
||||
x[i + 9] = x[i + 9] || 0;
|
||||
x[i + 10] = x[i + 10] || 0;
|
||||
x[i + 11] = x[i + 11] || 0;
|
||||
x[i + 12] = x[i + 12] || 0;
|
||||
x[i + 13] = x[i + 13] || 0;
|
||||
x[i + 14] = x[i + 14] || 0;
|
||||
x[i + 15] = x[i + 15] || 0;
|
||||
olda = a;
|
||||
oldb = b;
|
||||
oldc = c;
|
||||
oldd = d;
|
||||
a = this.ff(a,b,c,d,x[i + 0],7,3614090360);
|
||||
d = this.ff(d,a,b,c,x[i + 1],12,3905402710);
|
||||
c = this.ff(c,d,a,b,x[i + 2],17,606105819);
|
||||
b = this.ff(b,c,d,a,x[i + 3],22,3250441966);
|
||||
a = this.ff(a,b,c,d,x[i + 4],7,4118548399);
|
||||
d = this.ff(d,a,b,c,x[i + 5],12,1200080426);
|
||||
c = this.ff(c,d,a,b,x[i + 6],17,2821735955);
|
||||
b = this.ff(b,c,d,a,x[i + 7],22,4249261313);
|
||||
a = this.ff(a,b,c,d,x[i + 8],7,1770035416);
|
||||
d = this.ff(d,a,b,c,x[i + 9],12,2336552879);
|
||||
c = this.ff(c,d,a,b,x[i + 10],17,4294925233);
|
||||
b = this.ff(b,c,d,a,x[i + 11],22,2304563134);
|
||||
a = this.ff(a,b,c,d,x[i + 12],7,1804603682);
|
||||
d = this.ff(d,a,b,c,x[i + 13],12,4254626195);
|
||||
c = this.ff(c,d,a,b,x[i + 14],17,2792965006);
|
||||
b = this.ff(b,c,d,a,x[i + 15],22,1236535329);
|
||||
a = this.gg(a,b,c,d,x[i + 1],5,4129170786);
|
||||
d = this.gg(d,a,b,c,x[i + 6],9,3225465664);
|
||||
c = this.gg(c,d,a,b,x[i + 11],14,643717713);
|
||||
b = this.gg(b,c,d,a,x[i + 0],20,3921069994);
|
||||
a = this.gg(a,b,c,d,x[i + 5],5,3593408605);
|
||||
d = this.gg(d,a,b,c,x[i + 10],9,38016083);
|
||||
c = this.gg(c,d,a,b,x[i + 15],14,3634488961);
|
||||
b = this.gg(b,c,d,a,x[i + 4],20,3889429448);
|
||||
a = this.gg(a,b,c,d,x[i + 9],5,568446438);
|
||||
d = this.gg(d,a,b,c,x[i + 14],9,3275163606);
|
||||
c = this.gg(c,d,a,b,x[i + 3],14,4107603335);
|
||||
b = this.gg(b,c,d,a,x[i + 8],20,1163531501);
|
||||
a = this.gg(a,b,c,d,x[i + 13],5,2850285829);
|
||||
d = this.gg(d,a,b,c,x[i + 2],9,4243563512);
|
||||
c = this.gg(c,d,a,b,x[i + 7],14,1735328473);
|
||||
b = this.gg(b,c,d,a,x[i + 12],20,2368359562);
|
||||
a = this.hh(a,b,c,d,x[i + 5],4,4294588738);
|
||||
d = this.hh(d,a,b,c,x[i + 8],11,2272392833);
|
||||
c = this.hh(c,d,a,b,x[i + 11],16,1839030562);
|
||||
b = this.hh(b,c,d,a,x[i + 14],23,4259657740);
|
||||
a = this.hh(a,b,c,d,x[i + 1],4,2763975236);
|
||||
d = this.hh(d,a,b,c,x[i + 4],11,1272893353);
|
||||
c = this.hh(c,d,a,b,x[i + 7],16,4139469664);
|
||||
b = this.hh(b,c,d,a,x[i + 10],23,3200236656);
|
||||
a = this.hh(a,b,c,d,x[i + 13],4,681279174);
|
||||
d = this.hh(d,a,b,c,x[i + 0],11,3936430074);
|
||||
c = this.hh(c,d,a,b,x[i + 3],16,3572445317);
|
||||
b = this.hh(b,c,d,a,x[i + 6],23,76029189);
|
||||
a = this.hh(a,b,c,d,x[i + 9],4,3654602809);
|
||||
d = this.hh(d,a,b,c,x[i + 12],11,3873151461);
|
||||
c = this.hh(c,d,a,b,x[i + 15],16,530742520);
|
||||
b = this.hh(b,c,d,a,x[i + 2],23,3299628645);
|
||||
a = this.ii(a,b,c,d,x[i + 0],6,4096336452);
|
||||
d = this.ii(d,a,b,c,x[i + 7],10,1126891415);
|
||||
c = this.ii(c,d,a,b,x[i + 14],15,2878612391);
|
||||
b = this.ii(b,c,d,a,x[i + 5],21,4237533241);
|
||||
a = this.ii(a,b,c,d,x[i + 12],6,1700485571);
|
||||
d = this.ii(d,a,b,c,x[i + 3],10,2399980690);
|
||||
c = this.ii(c,d,a,b,x[i + 10],15,4293915773);
|
||||
b = this.ii(b,c,d,a,x[i + 1],21,2240044497);
|
||||
a = this.ii(a,b,c,d,x[i + 8],6,1873313359);
|
||||
d = this.ii(d,a,b,c,x[i + 15],10,4264355552);
|
||||
c = this.ii(c,d,a,b,x[i + 6],15,2734768916);
|
||||
b = this.ii(b,c,d,a,x[i + 13],21,1309151649);
|
||||
a = this.ii(a,b,c,d,x[i + 4],6,4149444226);
|
||||
d = this.ii(d,a,b,c,x[i + 11],10,3174756917);
|
||||
c = this.ii(c,d,a,b,x[i + 2],15,718787259);
|
||||
b = this.ii(b,c,d,a,x[i + 9],21,3951481745);
|
||||
a += olda;
|
||||
b += oldb;
|
||||
c += oldc;
|
||||
d += oldd;
|
||||
}
|
||||
return [a,b,c,d];
|
||||
}
|
||||
|
||||
private function rol(num:uint, cnt:uint) : uint
|
||||
{
|
||||
return num << cnt | num >>> 32 - cnt;
|
||||
}
|
||||
|
||||
private function cmn(q:uint, a:uint, b:uint, x:uint, s:uint, t:uint) : uint
|
||||
{
|
||||
return this.rol(a + q + x + t,s) + b;
|
||||
}
|
||||
|
||||
private function ff(a:uint, b:uint, c:uint, d:uint, x:uint, s:uint, t:uint) : uint
|
||||
{
|
||||
return this.cmn(b & c | ~b & d,a,b,x,s,t);
|
||||
}
|
||||
|
||||
private function gg(a:uint, b:uint, c:uint, d:uint, x:uint, s:uint, t:uint) : uint
|
||||
{
|
||||
return this.cmn(b & d | c & ~d,a,b,x,s,t);
|
||||
}
|
||||
|
||||
private function hh(a:uint, b:uint, c:uint, d:uint, x:uint, s:uint, t:uint) : uint
|
||||
{
|
||||
return this.cmn(b ^ c ^ d,a,b,x,s,t);
|
||||
}
|
||||
|
||||
private function ii(a:uint, b:uint, c:uint, d:uint, x:uint, s:uint, t:uint) : uint
|
||||
{
|
||||
return this.cmn(c ^ (b | ~d),a,b,x,s,t);
|
||||
}
|
||||
|
||||
public function toString() : String
|
||||
{
|
||||
return "md5";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
package com.hurlant.crypto.hash
|
||||
{
|
||||
public class SHA1 extends SHABase implements IHash
|
||||
{
|
||||
|
||||
public static const HASH_SIZE:int = 20;
|
||||
|
||||
public function SHA1()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
override public function getHashSize() : uint
|
||||
{
|
||||
return HASH_SIZE;
|
||||
}
|
||||
|
||||
override protected function core(x:Array, len:uint) : Array
|
||||
{
|
||||
var olda:uint = 0;
|
||||
var oldb:uint = 0;
|
||||
var oldc:uint = 0;
|
||||
var oldd:uint = 0;
|
||||
var olde:uint = 0;
|
||||
var j:uint = 0;
|
||||
var t:uint = 0;
|
||||
x[len >> 5] |= 128 << 24 - len % 32;
|
||||
x[(len + 64 >> 9 << 4) + 15] = len;
|
||||
var w:Array = [];
|
||||
var a:uint = 1732584193;
|
||||
var b:uint = 4023233417;
|
||||
var c:uint = 2562383102;
|
||||
var d:uint = 271733878;
|
||||
var e:uint = 3285377520;
|
||||
for(var i:uint = 0; i < x.length; i += 16)
|
||||
{
|
||||
olda = a;
|
||||
oldb = b;
|
||||
oldc = c;
|
||||
oldd = d;
|
||||
olde = e;
|
||||
for(j = 0; j < 80; j++)
|
||||
{
|
||||
if(j < 16)
|
||||
{
|
||||
w[j] = x[i + j] || 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
w[j] = this.rol(w[j - 3] ^ w[j - 8] ^ w[j - 14] ^ w[j - 16],1);
|
||||
}
|
||||
t = this.rol(a,5) + this.ft(j,b,c,d) + e + w[j] + this.kt(j);
|
||||
e = d;
|
||||
d = c;
|
||||
c = this.rol(b,30);
|
||||
b = a;
|
||||
a = t;
|
||||
}
|
||||
a += olda;
|
||||
b += oldb;
|
||||
c += oldc;
|
||||
d += oldd;
|
||||
e += olde;
|
||||
}
|
||||
return [a,b,c,d,e];
|
||||
}
|
||||
|
||||
private function rol(num:uint, cnt:uint) : uint
|
||||
{
|
||||
return num << cnt | num >>> 32 - cnt;
|
||||
}
|
||||
|
||||
private function ft(t:uint, b:uint, c:uint, d:uint) : uint
|
||||
{
|
||||
if(t < 20)
|
||||
{
|
||||
return b & c | ~b & d;
|
||||
}
|
||||
if(t < 40)
|
||||
{
|
||||
return b ^ c ^ d;
|
||||
}
|
||||
if(t < 60)
|
||||
{
|
||||
return b & c | b & d | c & d;
|
||||
}
|
||||
return b ^ c ^ d;
|
||||
}
|
||||
|
||||
private function kt(t:uint) : uint
|
||||
{
|
||||
return t < 20 ? 1518500249 : (t < 40 ? 1859775393 : (t < 60 ? uint(2400959708) : uint(3395469782)));
|
||||
}
|
||||
|
||||
override public function toString() : String
|
||||
{
|
||||
return "sha1";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.hurlant.crypto.hash
|
||||
{
|
||||
public class SHA224 extends SHA256
|
||||
{
|
||||
|
||||
public function SHA224()
|
||||
{
|
||||
super();
|
||||
_h = [3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428];
|
||||
}
|
||||
|
||||
override public function getHashSize() : uint
|
||||
{
|
||||
return 28;
|
||||
}
|
||||
|
||||
override public function toString() : String
|
||||
{
|
||||
return "sha224";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
package com.hurlant.crypto.hash
|
||||
{
|
||||
public class SHA256 extends SHABase implements IHash
|
||||
{
|
||||
|
||||
protected static const k:Array = [1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298];
|
||||
|
||||
protected var _h:Array = [1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225];
|
||||
|
||||
public function SHA256()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
override public function getHashSize() : uint
|
||||
{
|
||||
return 32;
|
||||
}
|
||||
|
||||
override protected function core(x:Array, len:uint) : Array
|
||||
{
|
||||
var olda:uint = 0;
|
||||
var oldb:uint = 0;
|
||||
var oldc:uint = 0;
|
||||
var oldd:uint = 0;
|
||||
var olde:uint = 0;
|
||||
var oldf:uint = 0;
|
||||
var oldg:uint = 0;
|
||||
var oldh:uint = 0;
|
||||
var j:uint = 0;
|
||||
var t2:uint = 0;
|
||||
var t1:uint = 0;
|
||||
var s0:uint = 0;
|
||||
var s1:uint = 0;
|
||||
x[len >> 5] |= 128 << 24 - len % 32;
|
||||
x[(len + 64 >> 9 << 4) + 15] = len;
|
||||
var w:Array = [];
|
||||
var a:uint = uint(this._h[0]);
|
||||
var b:uint = uint(this._h[1]);
|
||||
var c:uint = uint(this._h[2]);
|
||||
var d:uint = uint(this._h[3]);
|
||||
var e:uint = uint(this._h[4]);
|
||||
var f:uint = uint(this._h[5]);
|
||||
var g:uint = uint(this._h[6]);
|
||||
var h:uint = uint(this._h[7]);
|
||||
for(var i:uint = 0; i < x.length; i += 16)
|
||||
{
|
||||
olda = a;
|
||||
oldb = b;
|
||||
oldc = c;
|
||||
oldd = d;
|
||||
olde = e;
|
||||
oldf = f;
|
||||
oldg = g;
|
||||
oldh = h;
|
||||
for(j = 0; j < 64; j++)
|
||||
{
|
||||
if(j < 16)
|
||||
{
|
||||
w[j] = x[i + j] || 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
s0 = uint(this.rrol(w[j - 15],7) ^ this.rrol(w[j - 15],18) ^ w[j - 15] >>> 3);
|
||||
s1 = uint(this.rrol(w[j - 2],17) ^ this.rrol(w[j - 2],19) ^ w[j - 2] >>> 10);
|
||||
w[j] = w[j - 16] + s0 + w[j - 7] + s1;
|
||||
}
|
||||
t2 = (this.rrol(a,2) ^ this.rrol(a,13) ^ this.rrol(a,22)) + (a & b ^ a & c ^ b & c);
|
||||
t1 = h + (this.rrol(e,6) ^ this.rrol(e,11) ^ this.rrol(e,25)) + (e & f ^ g & ~e) + k[j] + w[j];
|
||||
h = g;
|
||||
g = f;
|
||||
f = e;
|
||||
e = d + t1;
|
||||
d = c;
|
||||
c = b;
|
||||
b = a;
|
||||
a = t1 + t2;
|
||||
}
|
||||
a += olda;
|
||||
b += oldb;
|
||||
c += oldc;
|
||||
d += oldd;
|
||||
e += olde;
|
||||
f += oldf;
|
||||
g += oldg;
|
||||
h += oldh;
|
||||
}
|
||||
return [a,b,c,d,e,f,g,h];
|
||||
}
|
||||
|
||||
protected function rrol(num:uint, cnt:uint) : uint
|
||||
{
|
||||
return num << 32 - cnt | num >>> cnt;
|
||||
}
|
||||
|
||||
override public function toString() : String
|
||||
{
|
||||
return "sha256";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.hurlant.crypto.hash
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
import flash.utils.Endian;
|
||||
|
||||
public class SHABase implements IHash
|
||||
{
|
||||
|
||||
public function SHABase()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public function getInputSize() : uint
|
||||
{
|
||||
return 64;
|
||||
}
|
||||
|
||||
public function getHashSize() : uint
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function hash(src:ByteArray) : ByteArray
|
||||
{
|
||||
var savedLength:uint = src.length;
|
||||
var savedEndian:String = src.endian;
|
||||
src.endian = Endian.BIG_ENDIAN;
|
||||
var len:uint = savedLength * 8;
|
||||
while(src.length % 4 != 0)
|
||||
{
|
||||
src[src.length] = 0;
|
||||
}
|
||||
src.position = 0;
|
||||
var a:Array = [];
|
||||
for(var i:uint = 0; i < src.length; i += 4)
|
||||
{
|
||||
a.push(src.readUnsignedInt());
|
||||
}
|
||||
var h:Array = this.core(a,len);
|
||||
var out:ByteArray = new ByteArray();
|
||||
var words:uint = this.getHashSize() / 4;
|
||||
for(i = 0; i < words; i++)
|
||||
{
|
||||
out.writeUnsignedInt(h[i]);
|
||||
}
|
||||
src.length = savedLength;
|
||||
src.endian = savedEndian;
|
||||
return out;
|
||||
}
|
||||
|
||||
protected function core(x:Array, len:uint) : Array
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function toString() : String
|
||||
{
|
||||
return "sha";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user