diff --git a/source/Ox/js/Hash.js b/source/Ox/js/Hash.js index 20175b9e..7471604d 100644 --- a/source/Ox/js/Hash.js +++ b/source/Ox/js/Hash.js @@ -11,7 +11,7 @@ Ox.oshash = function(file, callback) { read(0); function add(A, B) { - var a, b, c, d; + var a, b, c, d; d = A[3] + B[3]; c = A[2] + B[2] + (d >> 16); d &= 0xffff; @@ -23,7 +23,7 @@ Ox.oshash = function(file, callback) { a &= 0xffff; return [a, b, c, d]; } - + function fromData(s, offset) { offset = offset || 0; return [ @@ -96,3 +96,133 @@ Ox.oshash = function(file, callback) { } }; + +/*@ +Ox.SHA1 Calculates SHA1 hash of the given string +@*/ +Ox.SHA1 = function(msg) { + + function rotate_left(n,s) { + var t4 = ( n<>>(32-s)); + return t4; + }; + + function cvt_hex(val) { + var str=""; + var i; + var v; + for ( i=7; i>=0; i-- ) { + v = (val>>>(i*4))&0x0f; + str += v.toString(16); + } + return str; + }; + + var blockstart; + var i, j; + var W = new Array(80); + var H0 = 0x67452301; + var H1 = 0xEFCDAB89; + var H2 = 0x98BADCFE; + var H3 = 0x10325476; + var H4 = 0xC3D2E1F0; + var A, B, C, D, E; + var temp; + + msg = Ox.encodeUTF8(msg); + + var msg_len = msg.length; + + var word_array = new Array(); + for ( i=0; i>>29 ); + word_array.push( (msg_len<<3)&0x0ffffffff ); + + + for ( blockstart=0; blockstart