From 0f02618168da426ffe47161e72b7f8e3541ce892 Mon Sep 17 00:00:00 2001 From: ausiv4 Date: Tue, 4 Aug 2009 03:37:00 +0000 Subject: I've started working on the feature that will allow existing servers to upgrade to SRP. Currently, I've added functionality that will allow the importation of hash.min.js. This is made possible by some code that executes when the script is loaded. This particular code doesn't pack properly, so currently I'm having the pack script append it to the end (unpacked). This requires that clients use the packed version for two reasons. First, the unpacked code lacks the function that gets the source path. Second, it loads hash.min.js. The first problem can be fixed if I can figure out how to get the code to pack properly. The second problem can be solved by checking whether the current script is "srp.js" or "srp.min.js", and loading either (MD5.js & SHA1.js) or hash.min.js respectively. Next we will need to write code where the server detects users who exist in the auth.models.User table, but not the srp.models.User table. --- javascript/SHA1.js | 174 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 174 insertions(+) create mode 100644 javascript/SHA1.js (limited to 'javascript/SHA1.js') diff --git a/javascript/SHA1.js b/javascript/SHA1.js new file mode 100644 index 0000000..e772cbe --- /dev/null +++ b/javascript/SHA1.js @@ -0,0 +1,174 @@ +/** +* +* Secure Hash Algorithm (SHA1) +* http://www.webtoolkit.info/ +* +**/ + +function SHA1 (msg) { + + function rotate_left(n,s) { + var t4 = ( n<>>(32-s)); + return t4; + }; + + function lsb_hex(val) { + var str=""; + var i; + var vh; + var vl; + + for( i=0; i<=6; i+=2 ) { + vh = (val>>>(i*4+4))&0x0f; + vl = (val>>>(i*4))&0x0f; + str += vh.toString(16) + vl.toString(16); + } + return str; + }; + + 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; + }; + + + function Utf8Encode(string) { + string = string.replace(/\r\n/g,"\n"); + var utftext = ""; + + for (var n = 0; n < string.length; n++) { + + var c = string.charCodeAt(n); + + if (c < 128) { + utftext += String.fromCharCode(c); + } + else if((c > 127) && (c < 2048)) { + utftext += String.fromCharCode((c >> 6) | 192); + utftext += String.fromCharCode((c & 63) | 128); + } + else { + utftext += String.fromCharCode((c >> 12) | 224); + utftext += String.fromCharCode(((c >> 6) & 63) | 128); + utftext += String.fromCharCode((c & 63) | 128); + } + + } + + return utftext; + }; + + 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 = Utf8Encode(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