From 508e4776cb6985b13557db07fe34152ecf97ca2f Mon Sep 17 00:00:00 2001 From: Jeff Williams Date: Tue, 16 Oct 2012 07:54:19 -0700 Subject: [PATCH] replace MD5 hash code --- Jake/templates/package.json.tmpl | 1 + node_modules/jsMD5/LICENSE | 26 ++ node_modules/jsMD5/md5.js | 167 +++++++++ node_modules/jsMD5/package.json | 24 ++ nodejs_modules/pajhome/hash.js | 383 --------------------- package.json | 3 +- rhino_modules/jsdoc/util/templateHelper.js | 4 +- 7 files changed, 222 insertions(+), 386 deletions(-) create mode 100644 node_modules/jsMD5/LICENSE create mode 100644 node_modules/jsMD5/md5.js create mode 100644 node_modules/jsMD5/package.json delete mode 100644 nodejs_modules/pajhome/hash.js diff --git a/Jake/templates/package.json.tmpl b/Jake/templates/package.json.tmpl index f39fc894..487afa5a 100644 --- a/Jake/templates/package.json.tmpl +++ b/Jake/templates/package.json.tmpl @@ -18,6 +18,7 @@ ], "dependencies": { "js2xmlparser": "0.1.0", + "jsMD5": "git://github.com/hegemonic/jsMD5.git", "markdown": "0.4.0", "taffydb": "git://github.com/hegemonic/taffydb.git", "underscore": "1.4.2", diff --git a/node_modules/jsMD5/LICENSE b/node_modules/jsMD5/LICENSE new file mode 100644 index 00000000..7746880e --- /dev/null +++ b/node_modules/jsMD5/LICENSE @@ -0,0 +1,26 @@ +Copyright (c) 2011, Yoshinori Kohyama (http://algobit.jp/) +All rights reserved. + +Redistribution and use in source and binary forms, with or +without modification, are permitted provided that the following +conditions are met: + +Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. +Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following +disclaimer in the documentation and/or other materials provided +with the distribution. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +THE POSSIBILITY OF SUCH DAMAGE. diff --git a/node_modules/jsMD5/md5.js b/node_modules/jsMD5/md5.js new file mode 100644 index 00000000..be54b674 --- /dev/null +++ b/node_modules/jsMD5/md5.js @@ -0,0 +1,167 @@ +/** + * md5.js + * Copyright (c) 2011, Yoshinori Kohyama (http://algobit.jp/) + * all rights reserved. + */ + +exports.digest = function (M) { + function F(x, y, z) { return (x & y) | (~x & z); } + function G(x, y, z) { return (x & z) | (y & ~z); } + function H(x, y, z) { return x ^ y ^ z; } + function I(x, y, z) { return y ^ (x | ~z); } + + function to4bytes(n) { + return [n&0xff, (n>>>8)&0xff, (n>>>16)&0xff, (n>>>24)&0xff]; + } + + var originalLength = M.length; // for Step.2 + + // 3.1 Step 1. Append Padding Bits + M.push(0x80); + var l = (56 - M.length)&0x3f; + for (var i = 0; i < l; i++) + M.push(0); + + // 3.2 Step 2. Append Length + to4bytes(8*originalLength).forEach(function (e) { M.push(e); }); + [0, 0, 0, 0].forEach(function (e) { M.push(e); }); + + // 3.3 Step 3. Initialize MD Buffer + var A = [0x67452301]; + var B = [0xefcdab89]; + var C = [0x98badcfe]; + var D = [0x10325476]; + var AA, BB, CC, DD; + + // 3.4 Step 4. Process Message in 16-Word Blocks + function rounds(a, b, c, d, k, s, t, f) { + a[0] += f(b[0], c[0], d[0]) + X[k] + t; + a[0] = ((a[0]<>>(32 - s))); + a[0] += b[0]; + } + var X; + for (var i = 0; i < M.length; i += 64) { + X = []; + for (var j = 0; j < 64; j += 4) { + k = i + j; + X.push(M[k]|(M[k + 1]<<8)|(M[k + 2]<<16)|(M[k + 3]<<24)); + } + AA = A[0]; + BB = B[0]; + CC = C[0]; + DD = D[0]; + + // Round 1. + rounds(A, B, C, D, 0, 7, 0xd76aa478, F); + rounds(D, A, B, C, 1, 12, 0xe8c7b756, F); + rounds(C, D, A, B, 2, 17, 0x242070db, F); + rounds(B, C, D, A, 3, 22, 0xc1bdceee, F); + rounds(A, B, C, D, 4, 7, 0xf57c0faf, F); + rounds(D, A, B, C, 5, 12, 0x4787c62a, F); + rounds(C, D, A, B, 6, 17, 0xa8304613, F); + rounds(B, C, D, A, 7, 22, 0xfd469501, F); + rounds(A, B, C, D, 8, 7, 0x698098d8, F); + rounds(D, A, B, C, 9, 12, 0x8b44f7af, F); + rounds(C, D, A, B, 10, 17, 0xffff5bb1, F); + rounds(B, C, D, A, 11, 22, 0x895cd7be, F); + rounds(A, B, C, D, 12, 7, 0x6b901122, F); + rounds(D, A, B, C, 13, 12, 0xfd987193, F); + rounds(C, D, A, B, 14, 17, 0xa679438e, F); + rounds(B, C, D, A, 15, 22, 0x49b40821, F); + + // Round 2. + rounds(A, B, C, D, 1, 5, 0xf61e2562, G); + rounds(D, A, B, C, 6, 9, 0xc040b340, G); + rounds(C, D, A, B, 11, 14, 0x265e5a51, G); + rounds(B, C, D, A, 0, 20, 0xe9b6c7aa, G); + rounds(A, B, C, D, 5, 5, 0xd62f105d, G); + rounds(D, A, B, C, 10, 9, 0x02441453, G); + rounds(C, D, A, B, 15, 14, 0xd8a1e681, G); + rounds(B, C, D, A, 4, 20, 0xe7d3fbc8, G); + rounds(A, B, C, D, 9, 5, 0x21e1cde6, G); + rounds(D, A, B, C, 14, 9, 0xc33707d6, G); + rounds(C, D, A, B, 3, 14, 0xf4d50d87, G); + rounds(B, C, D, A, 8, 20, 0x455a14ed, G); + rounds(A, B, C, D, 13, 5, 0xa9e3e905, G); + rounds(D, A, B, C, 2, 9, 0xfcefa3f8, G); + rounds(C, D, A, B, 7, 14, 0x676f02d9, G); + rounds(B, C, D, A, 12, 20, 0x8d2a4c8a, G); + + // Round 3. + rounds(A, B, C, D, 5, 4, 0xfffa3942, H); + rounds(D, A, B, C, 8, 11, 0x8771f681, H); + rounds(C, D, A, B, 11, 16, 0x6d9d6122, H); + rounds(B, C, D, A, 14, 23, 0xfde5380c, H); + rounds(A, B, C, D, 1, 4, 0xa4beea44, H); + rounds(D, A, B, C, 4, 11, 0x4bdecfa9, H); + rounds(C, D, A, B, 7, 16, 0xf6bb4b60, H); + rounds(B, C, D, A, 10, 23, 0xbebfbc70, H); + rounds(A, B, C, D, 13, 4, 0x289b7ec6, H); + rounds(D, A, B, C, 0, 11, 0xeaa127fa, H); + rounds(C, D, A, B, 3, 16, 0xd4ef3085, H); + rounds(B, C, D, A, 6, 23, 0x04881d05, H); + rounds(A, B, C, D, 9, 4, 0xd9d4d039, H); + rounds(D, A, B, C, 12, 11, 0xe6db99e5, H); + rounds(C, D, A, B, 15, 16, 0x1fa27cf8, H); + rounds(B, C, D, A, 2, 23, 0xc4ac5665, H); + + // Round 4. + rounds(A, B, C, D, 0, 6, 0xf4292244, I); + rounds(D, A, B, C, 7, 10, 0x432aff97, I); + rounds(C, D, A, B, 14, 15, 0xab9423a7, I); + rounds(B, C, D, A, 5, 21, 0xfc93a039, I); + rounds(A, B, C, D, 12, 6, 0x655b59c3, I); + rounds(D, A, B, C, 3, 10, 0x8f0ccc92, I); + rounds(C, D, A, B, 10, 15, 0xffeff47d, I); + rounds(B, C, D, A, 1, 21, 0x85845dd1, I); + rounds(A, B, C, D, 8, 6, 0x6fa87e4f, I); + rounds(D, A, B, C, 15, 10, 0xfe2ce6e0, I); + rounds(C, D, A, B, 6, 15, 0xa3014314, I); + rounds(B, C, D, A, 13, 21, 0x4e0811a1, I); + rounds(A, B, C, D, 4, 6, 0xf7537e82, I); + rounds(D, A, B, C, 11, 10, 0xbd3af235, I); + rounds(C, D, A, B, 2, 15, 0x2ad7d2bb, I); + rounds(B, C, D, A, 9, 21, 0xeb86d391, I); + + A[0] += AA; + B[0] += BB; + C[0] += CC; + D[0] += DD; + } + + var rval = []; + to4bytes(A[0]).forEach(function (e) { rval.push(e); }); + to4bytes(B[0]).forEach(function (e) { rval.push(e); }); + to4bytes(C[0]).forEach(function (e) { rval.push(e); }); + to4bytes(D[0]).forEach(function (e) { rval.push(e); }); + return rval; +} + +exports.digest_s = function (s) { + var M = []; + for (var i = 0; i < s.length; i++) + M.push(s.charCodeAt(i)); + var d = exports.digest(M); + var rstr = ''; + d.forEach(function (e) { + var s = e.toString(16); + while (s.length < 2) + s = '0' + s; + rstr += s; + }); + return rstr; +} + +// to test +/* +function test(s) { + console.log('MD5 ("' + s + '") = ' + exports.digest_s(s)); +} +test(''); +test('a'); +test('abc'); +test('message digest'); +test('abcdefghijklmnopqrstuvwxyz'); +test('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'); +test('12345678901234567890123456789012345678901234567890123456789012345678901234567890'); +*/ diff --git a/node_modules/jsMD5/package.json b/node_modules/jsMD5/package.json new file mode 100644 index 00000000..bd6d0078 --- /dev/null +++ b/node_modules/jsMD5/package.json @@ -0,0 +1,24 @@ +{ + "name": "jsMD5", + "version": "0.1.0", + "description": "An implementation of RFC 1321 - The MD5 Message-Digest Algorithm in JavaScript.", + "main": "md5.js", + "repository": { + "type": "git", + "url": "git://github.com/hegemonic/jsMD5.git" + }, + "keywords": [ + "javascript", + "md5" + ], + "author": { + "name": "Yoshinori Kohyama" + }, + "license": "MIT", + "readme": "English\n=======\n\nWhat is this\n------------\n\njsMD5 is an implementation of [RFC 1321 - The MD5 Message-Digest Algorithm] (http://tools.ietf.org/html/rfc1321) in JavaScript.\n\nUsage\n-----\n\nTo use this do as below:\n\n var md5 = require('./md5');\n var na = md5.digest();\n // na is an array of numbers\n var str = md5.digest_s();\n // str is an string\n\n\"array of numbers\" is an array of unsigned integer of each bytes to digest or of each bytes of digested.\n\nLicense\n-------\n\nCopyright (c) 2011, Yoshinori Kohyama (http://algobit.jp/) \nAll rights reserved. \n\nRedistribution and use in source and binary forms, with or \nwithout modification, are permitted provided that the following \nconditions are met: \n\nRedistributions of source code must retain the above copyright \nnotice, this list of conditions and the following disclaimer. \nRedistributions in binary form must reproduce the above \ncopyright notice, this list of conditions and the following \ndisclaimer in the documentation and/or other materials provided \nwith the distribution. \nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND \nCONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, \nINCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF \nMERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE \nDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR \nCONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, \nSPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT \nLIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF \nUSE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED \nAND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT \nLIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING \nIN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF \nTHE POSSIBILITY OF SUCH DAMAGE. \n\n\nJapanese\n========\n\nこれは何\n--------\n\njsMD5 は [RFC 1321 - The MD5 Message-Digest Algorithm] (http://tools.ietf.org/html/rfc1321) の JavaScript による実装です.\n\n使い方\n------\n\n利用するには\n\n var md5 = require('./md5'); \n var na = md5.digest(数値の配列); \n // na は数値配列\n var str = md5.digest_s(文字列);\n // str は文字列\n\nのようにします.\n数値の配列はダイジェストを取りたいバイト列およびダイジェスト計算を行った後のバイト列の, 各バイトを非符号整数にしたものの配列です.\n\nライセンス\n----------\n\n修正 BSD ライセンスです.\n上記英文だけが法律的に有効です.\n参考のため以下に日本語訳を掲載します.\n\nCopyright (c) 2011, Yoshinori Kohyama (http://algobit.jp/) \nAll rights reserved. \n\nソースコード形式であれバイナリ形式であれ、変更の有無に関わらず、 \n以下の条件を満たす限りにおいて、再配布および使用を許可します: \n\nソースコード形式で再配布する場合、上記著作権表示、 本条件書およ \nび下記責任限定規定を必ず含めてください。 \nバイナリ形式で再配布する場合、上記著作権表示、 本条件書および下 \n記責任限定規定を、配布物とともに提供される文書 および/または \n他の資料に必ず含めてください。 \n本ソフトウェアは著作権保持者によって、”現状のまま” 提供される \nものとします。 本ソフトウェアについては、明示黙示を問わず、 商 \n用品として通常そなえるべき品質をそなえているとの保証も、 特定の \n目的に適合するとの保証を含め、何の保証もなされません。 事由のい \nかんを問わず、 損害発生の原因いかんを問わず、且つ、 責任の根拠 \nが契約であるか厳格責任であるか (過失その他) 不法行為であるか \nを問わず、 著作権保持者も寄与者も、 仮にそのような損害が発生す \nる可能性を知らされていたとしても、 本ソフトウェアの使用から発生 \nした直接損害、間接損害、偶発的な損害、 特別損害、懲罰的損害また \nは結果損害のいずれに対しても (代替品またはサービスの提供; 使 \n用機会、データまたは利益の損失の補償; または、業務の中断に対す \nる補償を含め) 責任をいっさい負いません。 \n\nこのソフトウェアと文書に含まれる意見や結論はそれらの著作者による \nものであって、 著作者の公式な方針を、明示黙示を問わず、 あらわ \nしているものととってはならない。 \n", + "_id": "jsMD5@0.1.0", + "dist": { + "shasum": "3bc75f1c6d183eb3cc545ca473c34b7242845ba3" + }, + "_from": "git://github.com/hegemonic/jsMD5.git" +} diff --git a/nodejs_modules/pajhome/hash.js b/nodejs_modules/pajhome/hash.js deleted file mode 100644 index edd9c8ee..00000000 --- a/nodejs_modules/pajhome/hash.js +++ /dev/null @@ -1,383 +0,0 @@ -/* - * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message - * Digest Algorithm, as defined in RFC 1321. - * Version 2.2 Copyright (C) Paul Johnston 1999 - 2009 - * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet - * Distributed under the BSD License - * See http://pajhome.org.uk/crypt/md5 for more info. - */ - -/* - * Configurable variables. You may need to tweak these to be compatible with - * the server-side, but the defaults work in most cases. - */ -var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */ -var b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance */ - -/* - * These are the functions you'll usually want to call - * They take string arguments and return either hex or base-64 encoded strings - */ -function hex_md5(s) { return rstr2hex(rstr_md5(str2rstr_utf8(s))); } -function b64_md5(s) { return rstr2b64(rstr_md5(str2rstr_utf8(s))); } -function any_md5(s, e) { return rstr2any(rstr_md5(str2rstr_utf8(s)), e); } -function hex_hmac_md5(k, d) - { return rstr2hex(rstr_hmac_md5(str2rstr_utf8(k), str2rstr_utf8(d))); } -function b64_hmac_md5(k, d) - { return rstr2b64(rstr_hmac_md5(str2rstr_utf8(k), str2rstr_utf8(d))); } -function any_hmac_md5(k, d, e) - { return rstr2any(rstr_hmac_md5(str2rstr_utf8(k), str2rstr_utf8(d)), e); } - -/* - * Perform a simple self-test to see if the VM is working - */ -function md5_vm_test() -{ - return hex_md5("abc").toLowerCase() == "900150983cd24fb0d6963f7d28e17f72"; -} - -/* - * Calculate the MD5 of a raw string - */ -function rstr_md5(s) -{ - return binl2rstr(binl_md5(rstr2binl(s), s.length * 8)); -} - -/* - * Calculate the HMAC-MD5, of a key and some data (raw strings) - */ -function rstr_hmac_md5(key, data) -{ - var bkey = rstr2binl(key); - if(bkey.length > 16) bkey = binl_md5(bkey, key.length * 8); - - var ipad = Array(16), opad = Array(16); - for(var i = 0; i < 16; i++) - { - ipad[i] = bkey[i] ^ 0x36363636; - opad[i] = bkey[i] ^ 0x5C5C5C5C; - } - - var hash = binl_md5(ipad.concat(rstr2binl(data)), 512 + data.length * 8); - return binl2rstr(binl_md5(opad.concat(hash), 512 + 128)); -} - -/* - * Convert a raw string to a hex string - */ -function rstr2hex(input) -{ - try { hexcase } catch(e) { hexcase=0; } - var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef"; - var output = ""; - var x; - for(var i = 0; i < input.length; i++) - { - x = input.charCodeAt(i); - output += hex_tab.charAt((x >>> 4) & 0x0F) - + hex_tab.charAt( x & 0x0F); - } - return output; -} - -/* - * Convert a raw string to a base-64 string - */ -function rstr2b64(input) -{ - try { b64pad } catch(e) { b64pad=''; } - var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - var output = ""; - var len = input.length; - for(var i = 0; i < len; i += 3) - { - var triplet = (input.charCodeAt(i) << 16) - | (i + 1 < len ? input.charCodeAt(i+1) << 8 : 0) - | (i + 2 < len ? input.charCodeAt(i+2) : 0); - for(var j = 0; j < 4; j++) - { - if(i * 8 + j * 6 > input.length * 8) output += b64pad; - else output += tab.charAt((triplet >>> 6*(3-j)) & 0x3F); - } - } - return output; -} - -/* - * Convert a raw string to an arbitrary string encoding - */ -function rstr2any(input, encoding) -{ - var divisor = encoding.length; - var i, j, q, x, quotient; - - /* Convert to an array of 16-bit big-endian values, forming the dividend */ - var dividend = Array(Math.ceil(input.length / 2)); - for(i = 0; i < dividend.length; i++) - { - dividend[i] = (input.charCodeAt(i * 2) << 8) | input.charCodeAt(i * 2 + 1); - } - - /* - * Repeatedly perform a long division. The binary array forms the dividend, - * the length of the encoding is the divisor. Once computed, the quotient - * forms the dividend for the next step. All remainders are stored for later - * use. - */ - var full_length = Math.ceil(input.length * 8 / - (Math.log(encoding.length) / Math.log(2))); - var remainders = Array(full_length); - for(j = 0; j < full_length; j++) - { - quotient = Array(); - x = 0; - for(i = 0; i < dividend.length; i++) - { - x = (x << 16) + dividend[i]; - q = Math.floor(x / divisor); - x -= q * divisor; - if(quotient.length > 0 || q > 0) - quotient[quotient.length] = q; - } - remainders[j] = x; - dividend = quotient; - } - - /* Convert the remainders to the output string */ - var output = ""; - for(i = remainders.length - 1; i >= 0; i--) - output += encoding.charAt(remainders[i]); - - return output; -} - -/* - * Encode a string as utf-8. - * For efficiency, this assumes the input is valid utf-16. - */ -function str2rstr_utf8(input) -{ - var output = ""; - var i = -1; - var x, y; - - while(++i < input.length) - { - /* Decode utf-16 surrogate pairs */ - x = input.charCodeAt(i); - y = i + 1 < input.length ? input.charCodeAt(i + 1) : 0; - if(0xD800 <= x && x <= 0xDBFF && 0xDC00 <= y && y <= 0xDFFF) - { - x = 0x10000 + ((x & 0x03FF) << 10) + (y & 0x03FF); - i++; - } - - /* Encode output as utf-8 */ - if(x <= 0x7F) - output += String.fromCharCode(x); - else if(x <= 0x7FF) - output += String.fromCharCode(0xC0 | ((x >>> 6 ) & 0x1F), - 0x80 | ( x & 0x3F)); - else if(x <= 0xFFFF) - output += String.fromCharCode(0xE0 | ((x >>> 12) & 0x0F), - 0x80 | ((x >>> 6 ) & 0x3F), - 0x80 | ( x & 0x3F)); - else if(x <= 0x1FFFFF) - output += String.fromCharCode(0xF0 | ((x >>> 18) & 0x07), - 0x80 | ((x >>> 12) & 0x3F), - 0x80 | ((x >>> 6 ) & 0x3F), - 0x80 | ( x & 0x3F)); - } - return output; -} - -/* - * Encode a string as utf-16 - */ -function str2rstr_utf16le(input) -{ - var output = ""; - for(var i = 0; i < input.length; i++) - output += String.fromCharCode( input.charCodeAt(i) & 0xFF, - (input.charCodeAt(i) >>> 8) & 0xFF); - return output; -} - -function str2rstr_utf16be(input) -{ - var output = ""; - for(var i = 0; i < input.length; i++) - output += String.fromCharCode((input.charCodeAt(i) >>> 8) & 0xFF, - input.charCodeAt(i) & 0xFF); - return output; -} - -/* - * Convert a raw string to an array of little-endian words - * Characters >255 have their high-byte silently ignored. - */ -function rstr2binl(input) -{ - var output = Array(input.length >> 2); - for(var i = 0; i < output.length; i++) - output[i] = 0; - for(var i = 0; i < input.length * 8; i += 8) - output[i>>5] |= (input.charCodeAt(i / 8) & 0xFF) << (i%32); - return output; -} - -/* - * Convert an array of little-endian words to a string - */ -function binl2rstr(input) -{ - var output = ""; - for(var i = 0; i < input.length * 32; i += 8) - output += String.fromCharCode((input[i>>5] >>> (i % 32)) & 0xFF); - return output; -} - -/* - * Calculate the MD5 of an array of little-endian words, and a bit length. - */ -function binl_md5(x, len) -{ - /* append padding */ - x[len >> 5] |= 0x80 << ((len) % 32); - x[(((len + 64) >>> 9) << 4) + 14] = len; - - var a = 1732584193; - var b = -271733879; - var c = -1732584194; - var d = 271733878; - - for(var i = 0; i < x.length; i += 16) - { - var olda = a; - var oldb = b; - var oldc = c; - var oldd = d; - - a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936); - d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586); - c = md5_ff(c, d, a, b, x[i+ 2], 17, 606105819); - b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330); - a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897); - d = md5_ff(d, a, b, c, x[i+ 5], 12, 1200080426); - c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341); - b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983); - a = md5_ff(a, b, c, d, x[i+ 8], 7 , 1770035416); - d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417); - c = md5_ff(c, d, a, b, x[i+10], 17, -42063); - b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162); - a = md5_ff(a, b, c, d, x[i+12], 7 , 1804603682); - d = md5_ff(d, a, b, c, x[i+13], 12, -40341101); - c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290); - b = md5_ff(b, c, d, a, x[i+15], 22, 1236535329); - - a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510); - d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632); - c = md5_gg(c, d, a, b, x[i+11], 14, 643717713); - b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302); - a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691); - d = md5_gg(d, a, b, c, x[i+10], 9 , 38016083); - c = md5_gg(c, d, a, b, x[i+15], 14, -660478335); - b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848); - a = md5_gg(a, b, c, d, x[i+ 9], 5 , 568446438); - d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690); - c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961); - b = md5_gg(b, c, d, a, x[i+ 8], 20, 1163531501); - a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467); - d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784); - c = md5_gg(c, d, a, b, x[i+ 7], 14, 1735328473); - b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734); - - a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558); - d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463); - c = md5_hh(c, d, a, b, x[i+11], 16, 1839030562); - b = md5_hh(b, c, d, a, x[i+14], 23, -35309556); - a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060); - d = md5_hh(d, a, b, c, x[i+ 4], 11, 1272893353); - c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632); - b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640); - a = md5_hh(a, b, c, d, x[i+13], 4 , 681279174); - d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222); - c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979); - b = md5_hh(b, c, d, a, x[i+ 6], 23, 76029189); - a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487); - d = md5_hh(d, a, b, c, x[i+12], 11, -421815835); - c = md5_hh(c, d, a, b, x[i+15], 16, 530742520); - b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651); - - a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844); - d = md5_ii(d, a, b, c, x[i+ 7], 10, 1126891415); - c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905); - b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055); - a = md5_ii(a, b, c, d, x[i+12], 6 , 1700485571); - d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606); - c = md5_ii(c, d, a, b, x[i+10], 15, -1051523); - b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799); - a = md5_ii(a, b, c, d, x[i+ 8], 6 , 1873313359); - d = md5_ii(d, a, b, c, x[i+15], 10, -30611744); - c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380); - b = md5_ii(b, c, d, a, x[i+13], 21, 1309151649); - a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070); - d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379); - c = md5_ii(c, d, a, b, x[i+ 2], 15, 718787259); - b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551); - - a = safe_add(a, olda); - b = safe_add(b, oldb); - c = safe_add(c, oldc); - d = safe_add(d, oldd); - } - return Array(a, b, c, d); -} - -/* - * These functions implement the four basic operations the algorithm uses. - */ -function md5_cmn(q, a, b, x, s, t) -{ - return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b); -} -function md5_ff(a, b, c, d, x, s, t) -{ - return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t); -} -function md5_gg(a, b, c, d, x, s, t) -{ - return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t); -} -function md5_hh(a, b, c, d, x, s, t) -{ - return md5_cmn(b ^ c ^ d, a, b, x, s, t); -} -function md5_ii(a, b, c, d, x, s, t) -{ - return md5_cmn(c ^ (b | (~d)), a, b, x, s, t); -} - -/* - * Add integers, wrapping at 2^32. This uses 16-bit operations internally - * to work around bugs in some JS interpreters. - */ -function safe_add(x, y) -{ - var lsw = (x & 0xFFFF) + (y & 0xFFFF); - var msw = (x >> 16) + (y >> 16) + (lsw >> 16); - return (msw << 16) | (lsw & 0xFFFF); -} - -/* - * Bitwise rotate a 32-bit number to the left. - */ -function bit_rol(num, cnt) -{ - return (num << cnt) | (num >>> (32 - cnt)); -} - -exports.hex_md5 = hex_md5; -exports.b64_md5 = b64_md5; -exports.rstr_md5 = rstr_md5; \ No newline at end of file diff --git a/package.json b/package.json index 21dd1336..dd26f9c7 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "JSDoc", "version": "3.0.0", - "revision": "1350390807590", + "revision": "1350399199104", "description": "An automatic documentation generator for javascript.", "keywords": [ "documentation", "javascript" ], "licenses": [ @@ -18,6 +18,7 @@ ], "dependencies": { "js2xmlparser": "0.1.0", + "jsMD5": "git://github.com/hegemonic/jsMD5.git", "markdown": "0.4.0", "taffydb": "git://github.com/hegemonic/taffydb.git", "underscore": "1.4.2", diff --git a/rhino_modules/jsdoc/util/templateHelper.js b/rhino_modules/jsdoc/util/templateHelper.js index 6e05b832..d36ff373 100644 --- a/rhino_modules/jsdoc/util/templateHelper.js +++ b/rhino_modules/jsdoc/util/templateHelper.js @@ -3,7 +3,7 @@ * @module jsdoc/util/templateHelper */ -var hash = require('pajhome/hash'); +var md5 = require('jsMD5').digest_s; var dictionary = require('jsdoc/tag/dictionary'); var files = {}; @@ -49,7 +49,7 @@ function strToFilename(str) { var basename = str.replace(nsprefix, '$1-'); if ( /[^$a-z0-9._\-]/i.test(basename) ) { - return hash.hex_md5(str).substr(0, 10); + return md5(str).substr(0, 10); } return makeFilenameUnique(basename, str); }