Commit 326ed0af authored by Vincent Pelletier's avatar Vincent Pelletier

erp5_pajs: Initial import as of upstream-published version 2.2 .

parent 19257da2
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Folder" module="OFS.Folder"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_objects</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>erp5_pajs</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Folder" module="OFS.Folder"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_objects</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>pajs</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_EtagSupport__etag</string> </key>
<value> <string>ts16390871.46</string> </value>
</item>
<item>
<key> <string>__name__</string> </key>
<value> <string>md5.js</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>application/javascript</string> </value>
</item>
<item>
<key> <string>data</string> </key>
<value> <string encoding="cdata"><![CDATA[
/*\r\n
* A JavaScript implementation of the RSA Data Security, Inc. MD5 Message\r\n
* Digest Algorithm, as defined in RFC 1321.\r\n
* Version 2.2 Copyright (C) Paul Johnston 1999 - 2009\r\n
* Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet\r\n
* Distributed under the BSD License\r\n
* See http://pajhome.org.uk/crypt/md5 for more info.\r\n
*/\r\n
\r\n
/*\r\n
* Configurable variables. You may need to tweak these to be compatible with\r\n
* the server-side, but the defaults work in most cases.\r\n
*/\r\n
var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */\r\n
var b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance */\r\n
\r\n
/*\r\n
* These are the functions you\'ll usually want to call\r\n
* They take string arguments and return either hex or base-64 encoded strings\r\n
*/\r\n
function hex_md5(s) { return rstr2hex(rstr_md5(str2rstr_utf8(s))); }\r\n
function b64_md5(s) { return rstr2b64(rstr_md5(str2rstr_utf8(s))); }\r\n
function any_md5(s, e) { return rstr2any(rstr_md5(str2rstr_utf8(s)), e); }\r\n
function hex_hmac_md5(k, d)\r\n
{ return rstr2hex(rstr_hmac_md5(str2rstr_utf8(k), str2rstr_utf8(d))); }\r\n
function b64_hmac_md5(k, d)\r\n
{ return rstr2b64(rstr_hmac_md5(str2rstr_utf8(k), str2rstr_utf8(d))); }\r\n
function any_hmac_md5(k, d, e)\r\n
{ return rstr2any(rstr_hmac_md5(str2rstr_utf8(k), str2rstr_utf8(d)), e); }\r\n
\r\n
/*\r\n
* Perform a simple self-test to see if the VM is working\r\n
*/\r\n
function md5_vm_test()\r\n
{\r\n
return hex_md5("abc").toLowerCase() == "900150983cd24fb0d6963f7d28e17f72";\r\n
}\r\n
\r\n
/*\r\n
* Calculate the MD5 of a raw string\r\n
*/\r\n
function rstr_md5(s)\r\n
{\r\n
return binl2rstr(binl_md5(rstr2binl(s), s.length * 8));\r\n
}\r\n
\r\n
/*\r\n
* Calculate the HMAC-MD5, of a key and some data (raw strings)\r\n
*/\r\n
function rstr_hmac_md5(key, data)\r\n
{\r\n
var bkey = rstr2binl(key);\r\n
if(bkey.length > 16) bkey = binl_md5(bkey, key.length * 8);\r\n
\r\n
var ipad = Array(16), opad = Array(16);\r\n
for(var i = 0; i < 16; i++)\r\n
{\r\n
ipad[i] = bkey[i] ^ 0x36363636;\r\n
opad[i] = bkey[i] ^ 0x5C5C5C5C;\r\n
}\r\n
\r\n
var hash = binl_md5(ipad.concat(rstr2binl(data)), 512 + data.length * 8);\r\n
return binl2rstr(binl_md5(opad.concat(hash), 512 + 128));\r\n
}\r\n
\r\n
/*\r\n
* Convert a raw string to a hex string\r\n
*/\r\n
function rstr2hex(input)\r\n
{\r\n
try { hexcase } catch(e) { hexcase=0; }\r\n
var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";\r\n
var output = "";\r\n
var x;\r\n
for(var i = 0; i < input.length; i++)\r\n
{\r\n
x = input.charCodeAt(i);\r\n
output += hex_tab.charAt((x >>> 4) & 0x0F)\r\n
+ hex_tab.charAt( x & 0x0F);\r\n
}\r\n
return output;\r\n
}\r\n
\r\n
/*\r\n
* Convert a raw string to a base-64 string\r\n
*/\r\n
function rstr2b64(input)\r\n
{\r\n
try { b64pad } catch(e) { b64pad=\'\'; }\r\n
var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";\r\n
var output = "";\r\n
var len = input.length;\r\n
for(var i = 0; i < len; i += 3)\r\n
{\r\n
var triplet = (input.charCodeAt(i) << 16)\r\n
| (i + 1 < len ? input.charCodeAt(i+1) << 8 : 0)\r\n
| (i + 2 < len ? input.charCodeAt(i+2) : 0);\r\n
for(var j = 0; j < 4; j++)\r\n
{\r\n
if(i * 8 + j * 6 > input.length * 8) output += b64pad;\r\n
else output += tab.charAt((triplet >>> 6*(3-j)) & 0x3F);\r\n
}\r\n
}\r\n
return output;\r\n
}\r\n
\r\n
/*\r\n
* Convert a raw string to an arbitrary string encoding\r\n
*/\r\n
function rstr2any(input, encoding)\r\n
{\r\n
var divisor = encoding.length;\r\n
var i, j, q, x, quotient;\r\n
\r\n
/* Convert to an array of 16-bit big-endian values, forming the dividend */\r\n
var dividend = Array(Math.ceil(input.length / 2));\r\n
for(i = 0; i < dividend.length; i++)\r\n
{\r\n
dividend[i] = (input.charCodeAt(i * 2) << 8) | input.charCodeAt(i * 2 + 1);\r\n
}\r\n
\r\n
/*\r\n
* Repeatedly perform a long division. The binary array forms the dividend,\r\n
* the length of the encoding is the divisor. Once computed, the quotient\r\n
* forms the dividend for the next step. All remainders are stored for later\r\n
* use.\r\n
*/\r\n
var full_length = Math.ceil(input.length * 8 /\r\n
(Math.log(encoding.length) / Math.log(2)));\r\n
var remainders = Array(full_length);\r\n
for(j = 0; j < full_length; j++)\r\n
{\r\n
quotient = Array();\r\n
x = 0;\r\n
for(i = 0; i < dividend.length; i++)\r\n
{\r\n
x = (x << 16) + dividend[i];\r\n
q = Math.floor(x / divisor);\r\n
x -= q * divisor;\r\n
if(quotient.length > 0 || q > 0)\r\n
quotient[quotient.length] = q;\r\n
}\r\n
remainders[j] = x;\r\n
dividend = quotient;\r\n
}\r\n
\r\n
/* Convert the remainders to the output string */\r\n
var output = "";\r\n
for(i = remainders.length - 1; i >= 0; i--)\r\n
output += encoding.charAt(remainders[i]);\r\n
\r\n
return output;\r\n
}\r\n
\r\n
/*\r\n
* Encode a string as utf-8.\r\n
* For efficiency, this assumes the input is valid utf-16.\r\n
*/\r\n
function str2rstr_utf8(input)\r\n
{\r\n
var output = "";\r\n
var i = -1;\r\n
var x, y;\r\n
\r\n
while(++i < input.length)\r\n
{\r\n
/* Decode utf-16 surrogate pairs */\r\n
x = input.charCodeAt(i);\r\n
y = i + 1 < input.length ? input.charCodeAt(i + 1) : 0;\r\n
if(0xD800 <= x && x <= 0xDBFF && 0xDC00 <= y && y <= 0xDFFF)\r\n
{\r\n
x = 0x10000 + ((x & 0x03FF) << 10) + (y & 0x03FF);\r\n
i++;\r\n
}\r\n
\r\n
/* Encode output as utf-8 */\r\n
if(x <= 0x7F)\r\n
output += String.fromCharCode(x);\r\n
else if(x <= 0x7FF)\r\n
output += String.fromCharCode(0xC0 | ((x >>> 6 ) & 0x1F),\r\n
0x80 | ( x & 0x3F));\r\n
else if(x <= 0xFFFF)\r\n
output += String.fromCharCode(0xE0 | ((x >>> 12) & 0x0F),\r\n
0x80 | ((x >>> 6 ) & 0x3F),\r\n
0x80 | ( x & 0x3F));\r\n
else if(x <= 0x1FFFFF)\r\n
output += String.fromCharCode(0xF0 | ((x >>> 18) & 0x07),\r\n
0x80 | ((x >>> 12) & 0x3F),\r\n
0x80 | ((x >>> 6 ) & 0x3F),\r\n
0x80 | ( x & 0x3F));\r\n
}\r\n
return output;\r\n
}\r\n
\r\n
/*\r\n
* Encode a string as utf-16\r\n
*/\r\n
function str2rstr_utf16le(input)\r\n
{\r\n
var output = "";\r\n
for(var i = 0; i < input.length; i++)\r\n
output += String.fromCharCode( input.charCodeAt(i) & 0xFF,\r\n
(input.charCodeAt(i) >>> 8) & 0xFF);\r\n
return output;\r\n
}\r\n
\r\n
function str2rstr_utf16be(input)\r\n
{\r\n
var output = "";\r\n
for(var i = 0; i < input.length; i++)\r\n
output += String.fromCharCode((input.charCodeAt(i) >>> 8) & 0xFF,\r\n
input.charCodeAt(i) & 0xFF);\r\n
return output;\r\n
}\r\n
\r\n
/*\r\n
* Convert a raw string to an array of little-endian words\r\n
* Characters >255 have their high-byte silently ignored.\r\n
*/\r\n
function rstr2binl(input)\r\n
{\r\n
var output = Array(input.length >> 2);\r\n
for(var i = 0; i < output.length; i++)\r\n
output[i] = 0;\r\n
for(var i = 0; i < input.length * 8; i += 8)\r\n
output[i>>5] |= (input.charCodeAt(i / 8) & 0xFF) << (i%32);\r\n
return output;\r\n
}\r\n
\r\n
/*\r\n
* Convert an array of little-endian words to a string\r\n
*/\r\n
function binl2rstr(input)\r\n
{\r\n
var output = "";\r\n
for(var i = 0; i < input.length * 32; i += 8)\r\n
output += String.fromCharCode((input[i>>5] >>> (i % 32)) & 0xFF);\r\n
return output;\r\n
}\r\n
\r\n
/*\r\n
* Calculate the MD5 of an array of little-endian words, and a bit length.\r\n
*/\r\n
function binl_md5(x, len)\r\n
{\r\n
/* append padding */\r\n
x[len >> 5] |= 0x80 << ((len) % 32);\r\n
x[(((len + 64) >>> 9) << 4) + 14] = len;\r\n
\r\n
var a = 1732584193;\r\n
var b = -271733879;\r\n
var c = -1732584194;\r\n
var d = 271733878;\r\n
\r\n
for(var i = 0; i < x.length; i += 16)\r\n
{\r\n
var olda = a;\r\n
var oldb = b;\r\n
var oldc = c;\r\n
var oldd = d;\r\n
\r\n
a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936);\r\n
d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586);\r\n
c = md5_ff(c, d, a, b, x[i+ 2], 17, 606105819);\r\n
b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330);\r\n
a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897);\r\n
d = md5_ff(d, a, b, c, x[i+ 5], 12, 1200080426);\r\n
c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341);\r\n
b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983);\r\n
a = md5_ff(a, b, c, d, x[i+ 8], 7 , 1770035416);\r\n
d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417);\r\n
c = md5_ff(c, d, a, b, x[i+10], 17, -42063);\r\n
b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162);\r\n
a = md5_ff(a, b, c, d, x[i+12], 7 , 1804603682);\r\n
d = md5_ff(d, a, b, c, x[i+13], 12, -40341101);\r\n
c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290);\r\n
b = md5_ff(b, c, d, a, x[i+15], 22, 1236535329);\r\n
\r\n
a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510);\r\n
d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632);\r\n
c = md5_gg(c, d, a, b, x[i+11], 14, 643717713);\r\n
b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302);\r\n
a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691);\r\n
d = md5_gg(d, a, b, c, x[i+10], 9 , 38016083);\r\n
c = md5_gg(c, d, a, b, x[i+15], 14, -660478335);\r\n
b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848);\r\n
a = md5_gg(a, b, c, d, x[i+ 9], 5 , 568446438);\r\n
d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690);\r\n
c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961);\r\n
b = md5_gg(b, c, d, a, x[i+ 8], 20, 1163531501);\r\n
a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467);\r\n
d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784);\r\n
c = md5_gg(c, d, a, b, x[i+ 7], 14, 1735328473);\r\n
b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734);\r\n
\r\n
a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558);\r\n
d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463);\r\n
c = md5_hh(c, d, a, b, x[i+11], 16, 1839030562);\r\n
b = md5_hh(b, c, d, a, x[i+14], 23, -35309556);\r\n
a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060);\r\n
d = md5_hh(d, a, b, c, x[i+ 4], 11, 1272893353);\r\n
c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632);\r\n
b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640);\r\n
a = md5_hh(a, b, c, d, x[i+13], 4 , 681279174);\r\n
d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222);\r\n
c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979);\r\n
b = md5_hh(b, c, d, a, x[i+ 6], 23, 76029189);\r\n
a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487);\r\n
d = md5_hh(d, a, b, c, x[i+12], 11, -421815835);\r\n
c = md5_hh(c, d, a, b, x[i+15], 16, 530742520);\r\n
b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651);\r\n
\r\n
a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844);\r\n
d = md5_ii(d, a, b, c, x[i+ 7], 10, 1126891415);\r\n
c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905);\r\n
b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055);\r\n
a = md5_ii(a, b, c, d, x[i+12], 6 , 1700485571);\r\n
d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606);\r\n
c = md5_ii(c, d, a, b, x[i+10], 15, -1051523);\r\n
b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799);\r\n
a = md5_ii(a, b, c, d, x[i+ 8], 6 , 1873313359);\r\n
d = md5_ii(d, a, b, c, x[i+15], 10, -30611744);\r\n
c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380);\r\n
b = md5_ii(b, c, d, a, x[i+13], 21, 1309151649);\r\n
a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070);\r\n
d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379);\r\n
c = md5_ii(c, d, a, b, x[i+ 2], 15, 718787259);\r\n
b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551);\r\n
\r\n
a = safe_add(a, olda);\r\n
b = safe_add(b, oldb);\r\n
c = safe_add(c, oldc);\r\n
d = safe_add(d, oldd);\r\n
}\r\n
return Array(a, b, c, d);\r\n
}\r\n
\r\n
/*\r\n
* These functions implement the four basic operations the algorithm uses.\r\n
*/\r\n
function md5_cmn(q, a, b, x, s, t)\r\n
{\r\n
return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b);\r\n
}\r\n
function md5_ff(a, b, c, d, x, s, t)\r\n
{\r\n
return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);\r\n
}\r\n
function md5_gg(a, b, c, d, x, s, t)\r\n
{\r\n
return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);\r\n
}\r\n
function md5_hh(a, b, c, d, x, s, t)\r\n
{\r\n
return md5_cmn(b ^ c ^ d, a, b, x, s, t);\r\n
}\r\n
function md5_ii(a, b, c, d, x, s, t)\r\n
{\r\n
return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);\r\n
}\r\n
\r\n
/*\r\n
* Add integers, wrapping at 2^32. This uses 16-bit operations internally\r\n
* to work around bugs in some JS interpreters.\r\n
*/\r\n
function safe_add(x, y)\r\n
{\r\n
var lsw = (x & 0xFFFF) + (y & 0xFFFF);\r\n
var msw = (x >> 16) + (y >> 16) + (lsw >> 16);\r\n
return (msw << 16) | (lsw & 0xFFFF);\r\n
}\r\n
\r\n
/*\r\n
* Bitwise rotate a 32-bit number to the left.\r\n
*/\r\n
function bit_rol(num, cnt)\r\n
{\r\n
return (num << cnt) | (num >>> (32 - cnt));\r\n
}\r\n
]]></string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>size</string> </key>
<value> <int>12297</int> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_EtagSupport__etag</string> </key>
<value> <string>ts16390927.01</string> </value>
</item>
<item>
<key> <string>__name__</string> </key>
<value> <string>ripemd160.js</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>application/javascript</string> </value>
</item>
<item>
<key> <string>data</string> </key>
<value> <string encoding="cdata"><![CDATA[
/*\n
* A JavaScript implementation of the RIPEMD-160 Algorithm\n
* Version 2.2 Copyright Jeremy Lin, Paul Johnston 2000 - 2009.\n
* Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet\n
* Distributed under the BSD License\n
* See http://pajhome.org.uk/crypt/md5 for details.\n
* Also http://www.ocf.berkeley.edu/~jjlin/jsotp/\n
*/\n
\n
/*\n
* Configurable variables. You may need to tweak these to be compatible with\n
* the server-side, but the defaults work in most cases.\n
*/\n
var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */\n
var b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance */\n
\n
/*\n
* These are the functions you\'ll usually want to call\n
* They take string arguments and return either hex or base-64 encoded strings\n
*/\n
function hex_rmd160(s) { return rstr2hex(rstr_rmd160(str2rstr_utf8(s))); }\n
function b64_rmd160(s) { return rstr2b64(rstr_rmd160(str2rstr_utf8(s))); }\n
function any_rmd160(s, e) { return rstr2any(rstr_rmd160(str2rstr_utf8(s)), e); }\n
function hex_hmac_rmd160(k, d)\n
{ return rstr2hex(rstr_hmac_rmd160(str2rstr_utf8(k), str2rstr_utf8(d))); }\n
function b64_hmac_rmd160(k, d)\n
{ return rstr2b64(rstr_hmac_rmd160(str2rstr_utf8(k), str2rstr_utf8(d))); }\n
function any_hmac_rmd160(k, d, e)\n
{ return rstr2any(rstr_hmac_rmd160(str2rstr_utf8(k), str2rstr_utf8(d)), e); }\n
\n
/*\n
* Perform a simple self-test to see if the VM is working\n
*/\n
function rmd160_vm_test()\n
{\n
return hex_rmd160("abc").toLowerCase() == "8eb208f7e05d987a9b044a8e98c6b087f15a0bfc";\n
}\n
\n
/*\n
* Calculate the rmd160 of a raw string\n
*/\n
function rstr_rmd160(s)\n
{\n
return binl2rstr(binl_rmd160(rstr2binl(s), s.length * 8));\n
}\n
\n
/*\n
* Calculate the HMAC-rmd160 of a key and some data (raw strings)\n
*/\n
function rstr_hmac_rmd160(key, data)\n
{\n
var bkey = rstr2binl(key);\n
if(bkey.length > 16) bkey = binl_rmd160(bkey, key.length * 8);\n
\n
var ipad = Array(16), opad = Array(16);\n
for(var i = 0; i < 16; i++)\n
{\n
ipad[i] = bkey[i] ^ 0x36363636;\n
opad[i] = bkey[i] ^ 0x5C5C5C5C;\n
}\n
\n
var hash = binl_rmd160(ipad.concat(rstr2binl(data)), 512 + data.length * 8);\n
return binl2rstr(binl_rmd160(opad.concat(hash), 512 + 160));\n
}\n
\n
/*\n
* Convert a raw string to a hex string\n
*/\n
function rstr2hex(input)\n
{\n
try { hexcase } catch(e) { hexcase=0; }\n
var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";\n
var output = "";\n
var x;\n
for(var i = 0; i < input.length; i++)\n
{\n
x = input.charCodeAt(i);\n
output += hex_tab.charAt((x >>> 4) & 0x0F)\n
+ hex_tab.charAt( x & 0x0F);\n
}\n
return output;\n
}\n
\n
/*\n
* Convert a raw string to a base-64 string\n
*/\n
function rstr2b64(input)\n
{\n
try { b64pad } catch(e) { b64pad=\'\'; }\n
var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";\n
var output = "";\n
var len = input.length;\n
for(var i = 0; i < len; i += 3)\n
{\n
var triplet = (input.charCodeAt(i) << 16)\n
| (i + 1 < len ? input.charCodeAt(i+1) << 8 : 0)\n
| (i + 2 < len ? input.charCodeAt(i+2) : 0);\n
for(var j = 0; j < 4; j++)\n
{\n
if(i * 8 + j * 6 > input.length * 8) output += b64pad;\n
else output += tab.charAt((triplet >>> 6*(3-j)) & 0x3F);\n
}\n
}\n
return output;\n
}\n
\n
/*\n
* Convert a raw string to an arbitrary string encoding\n
*/\n
function rstr2any(input, encoding)\n
{\n
var divisor = encoding.length;\n
var remainders = Array();\n
var i, q, x, quotient;\n
\n
/* Convert to an array of 16-bit big-endian values, forming the dividend */\n
var dividend = Array(Math.ceil(input.length / 2));\n
for(i = 0; i < dividend.length; i++)\n
{\n
dividend[i] = (input.charCodeAt(i * 2) << 8) | input.charCodeAt(i * 2 + 1);\n
}\n
\n
/*\n
* Repeatedly perform a long division. The binary array forms the dividend,\n
* the length of the encoding is the divisor. Once computed, the quotient\n
* forms the dividend for the next step. We stop when the dividend is zero.\n
* All remainders are stored for later use.\n
*/\n
while(dividend.length > 0)\n
{\n
quotient = Array();\n
x = 0;\n
for(i = 0; i < dividend.length; i++)\n
{\n
x = (x << 16) + dividend[i];\n
q = Math.floor(x / divisor);\n
x -= q * divisor;\n
if(quotient.length > 0 || q > 0)\n
quotient[quotient.length] = q;\n
}\n
remainders[remainders.length] = x;\n
dividend = quotient;\n
}\n
\n
/* Convert the remainders to the output string */\n
var output = "";\n
for(i = remainders.length - 1; i >= 0; i--)\n
output += encoding.charAt(remainders[i]);\n
\n
/* Append leading zero equivalents */\n
var full_length = Math.ceil(input.length * 8 /\n
(Math.log(encoding.length) / Math.log(2)))\n
for(i = output.length; i < full_length; i++)\n
output = encoding[0] + output;\n
\n
return output;\n
}\n
\n
/*\n
* Encode a string as utf-8.\n
* For efficiency, this assumes the input is valid utf-16.\n
*/\n
function str2rstr_utf8(input)\n
{\n
var output = "";\n
var i = -1;\n
var x, y;\n
\n
while(++i < input.length)\n
{\n
/* Decode utf-16 surrogate pairs */\n
x = input.charCodeAt(i);\n
y = i + 1 < input.length ? input.charCodeAt(i + 1) : 0;\n
if(0xD800 <= x && x <= 0xDBFF && 0xDC00 <= y && y <= 0xDFFF)\n
{\n
x = 0x10000 + ((x & 0x03FF) << 10) + (y & 0x03FF);\n
i++;\n
}\n
\n
/* Encode output as utf-8 */\n
if(x <= 0x7F)\n
output += String.fromCharCode(x);\n
else if(x <= 0x7FF)\n
output += String.fromCharCode(0xC0 | ((x >>> 6 ) & 0x1F),\n
0x80 | ( x & 0x3F));\n
else if(x <= 0xFFFF)\n
output += String.fromCharCode(0xE0 | ((x >>> 12) & 0x0F),\n
0x80 | ((x >>> 6 ) & 0x3F),\n
0x80 | ( x & 0x3F));\n
else if(x <= 0x1FFFFF)\n
output += String.fromCharCode(0xF0 | ((x >>> 18) & 0x07),\n
0x80 | ((x >>> 12) & 0x3F),\n
0x80 | ((x >>> 6 ) & 0x3F),\n
0x80 | ( x & 0x3F));\n
}\n
return output;\n
}\n
\n
/*\n
* Encode a string as utf-16\n
*/\n
function str2rstr_utf16le(input)\n
{\n
var output = "";\n
for(var i = 0; i < input.length; i++)\n
output += String.fromCharCode( input.charCodeAt(i) & 0xFF,\n
(input.charCodeAt(i) >>> 8) & 0xFF);\n
return output;\n
}\n
\n
function str2rstr_utf16be(input)\n
{\n
var output = "";\n
for(var i = 0; i < input.length; i++)\n
output += String.fromCharCode((input.charCodeAt(i) >>> 8) & 0xFF,\n
input.charCodeAt(i) & 0xFF);\n
return output;\n
}\n
\n
/*\n
* Convert a raw string to an array of little-endian words\n
* Characters >255 have their high-byte silently ignored.\n
*/\n
function rstr2binl(input)\n
{\n
var output = Array(input.length >> 2);\n
for(var i = 0; i < output.length; i++)\n
output[i] = 0;\n
for(var i = 0; i < input.length * 8; i += 8)\n
output[i>>5] |= (input.charCodeAt(i / 8) & 0xFF) << (i%32);\n
return output;\n
}\n
\n
/*\n
* Convert an array of little-endian words to a string\n
*/\n
function binl2rstr(input)\n
{\n
var output = "";\n
for(var i = 0; i < input.length * 32; i += 8)\n
output += String.fromCharCode((input[i>>5] >>> (i % 32)) & 0xFF);\n
return output;\n
}\n
\n
/*\n
* Calculate the RIPE-MD160 of an array of little-endian words, and a bit length.\n
*/\n
function binl_rmd160(x, len)\n
{\n
/* append padding */\n
x[len >> 5] |= 0x80 << (len % 32);\n
x[(((len + 64) >>> 9) << 4) + 14] = len;\n
\n
var h0 = 0x67452301;\n
var h1 = 0xefcdab89;\n
var h2 = 0x98badcfe;\n
var h3 = 0x10325476;\n
var h4 = 0xc3d2e1f0;\n
\n
for (var i = 0; i < x.length; i += 16) {\n
var T;\n
var A1 = h0, B1 = h1, C1 = h2, D1 = h3, E1 = h4;\n
var A2 = h0, B2 = h1, C2 = h2, D2 = h3, E2 = h4;\n
for (var j = 0; j <= 79; ++j) {\n
T = safe_add(A1, rmd160_f(j, B1, C1, D1));\n
T = safe_add(T, x[i + rmd160_r1[j]]);\n
T = safe_add(T, rmd160_K1(j));\n
T = safe_add(bit_rol(T, rmd160_s1[j]), E1);\n
A1 = E1; E1 = D1; D1 = bit_rol(C1, 10); C1 = B1; B1 = T;\n
T = safe_add(A2, rmd160_f(79-j, B2, C2, D2));\n
T = safe_add(T, x[i + rmd160_r2[j]]);\n
T = safe_add(T, rmd160_K2(j));\n
T = safe_add(bit_rol(T, rmd160_s2[j]), E2);\n
A2 = E2; E2 = D2; D2 = bit_rol(C2, 10); C2 = B2; B2 = T;\n
}\n
T = safe_add(h1, safe_add(C1, D2));\n
h1 = safe_add(h2, safe_add(D1, E2));\n
h2 = safe_add(h3, safe_add(E1, A2));\n
h3 = safe_add(h4, safe_add(A1, B2));\n
h4 = safe_add(h0, safe_add(B1, C2));\n
h0 = T;\n
}\n
return [h0, h1, h2, h3, h4];\n
}\n
\n
function rmd160_f(j, x, y, z)\n
{\n
return ( 0 <= j && j <= 15) ? (x ^ y ^ z) :\n
(16 <= j && j <= 31) ? (x & y) | (~x & z) :\n
(32 <= j && j <= 47) ? (x | ~y) ^ z :\n
(48 <= j && j <= 63) ? (x & z) | (y & ~z) :\n
(64 <= j && j <= 79) ? x ^ (y | ~z) :\n
"rmd160_f: j out of range";\n
}\n
function rmd160_K1(j)\n
{\n
return ( 0 <= j && j <= 15) ? 0x00000000 :\n
(16 <= j && j <= 31) ? 0x5a827999 :\n
(32 <= j && j <= 47) ? 0x6ed9eba1 :\n
(48 <= j && j <= 63) ? 0x8f1bbcdc :\n
(64 <= j && j <= 79) ? 0xa953fd4e :\n
"rmd160_K1: j out of range";\n
}\n
function rmd160_K2(j)\n
{\n
return ( 0 <= j && j <= 15) ? 0x50a28be6 :\n
(16 <= j && j <= 31) ? 0x5c4dd124 :\n
(32 <= j && j <= 47) ? 0x6d703ef3 :\n
(48 <= j && j <= 63) ? 0x7a6d76e9 :\n
(64 <= j && j <= 79) ? 0x00000000 :\n
"rmd160_K2: j out of range";\n
}\n
var rmd160_r1 = [\n
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,\n
7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,\n
3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12,\n
1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2,\n
4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13\n
];\n
var rmd160_r2 = [\n
5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12,\n
6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2,\n
15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13,\n
8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14,\n
12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11\n
];\n
var rmd160_s1 = [\n
11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8,\n
7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12,\n
11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5,\n
11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12,\n
9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6\n
];\n
var rmd160_s2 = [\n
8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6,\n
9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11,\n
9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5,\n
15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8,\n
8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11\n
];\n
\n
/*\n
* Add integers, wrapping at 2^32. This uses 16-bit operations internally\n
* to work around bugs in some JS interpreters.\n
*/\n
function safe_add(x, y)\n
{\n
var lsw = (x & 0xFFFF) + (y & 0xFFFF);\n
var msw = (x >> 16) + (y >> 16) + (lsw >> 16);\n
return (msw << 16) | (lsw & 0xFFFF);\n
}\n
\n
/*\n
* Bitwise rotate a 32-bit number to the left.\n
*/\n
function bit_rol(num, cnt)\n
{\n
return (num << cnt) | (num >>> (32 - cnt));\n
}\n
]]></string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>size</string> </key>
<value> <int>11181</int> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_EtagSupport__etag</string> </key>
<value> <string>ts16390902.5</string> </value>
</item>
<item>
<key> <string>__name__</string> </key>
<value> <string>sha1.js</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>application/javascript</string> </value>
</item>
<item>
<key> <string>data</string> </key>
<value> <string encoding="cdata"><![CDATA[
/*\r\n
* A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined\r\n
* in FIPS 180-1\r\n
* Version 2.2 Copyright Paul Johnston 2000 - 2009.\r\n
* Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet\r\n
* Distributed under the BSD License\r\n
* See http://pajhome.org.uk/crypt/md5 for details.\r\n
*/\r\n
\r\n
/*\r\n
* Configurable variables. You may need to tweak these to be compatible with\r\n
* the server-side, but the defaults work in most cases.\r\n
*/\r\n
var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */\r\n
var b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance */\r\n
\r\n
/*\r\n
* These are the functions you\'ll usually want to call\r\n
* They take string arguments and return either hex or base-64 encoded strings\r\n
*/\r\n
function hex_sha1(s) { return rstr2hex(rstr_sha1(str2rstr_utf8(s))); }\r\n
function b64_sha1(s) { return rstr2b64(rstr_sha1(str2rstr_utf8(s))); }\r\n
function any_sha1(s, e) { return rstr2any(rstr_sha1(str2rstr_utf8(s)), e); }\r\n
function hex_hmac_sha1(k, d)\r\n
{ return rstr2hex(rstr_hmac_sha1(str2rstr_utf8(k), str2rstr_utf8(d))); }\r\n
function b64_hmac_sha1(k, d)\r\n
{ return rstr2b64(rstr_hmac_sha1(str2rstr_utf8(k), str2rstr_utf8(d))); }\r\n
function any_hmac_sha1(k, d, e)\r\n
{ return rstr2any(rstr_hmac_sha1(str2rstr_utf8(k), str2rstr_utf8(d)), e); }\r\n
\r\n
/*\r\n
* Perform a simple self-test to see if the VM is working\r\n
*/\r\n
function sha1_vm_test()\r\n
{\r\n
return hex_sha1("abc").toLowerCase() == "a9993e364706816aba3e25717850c26c9cd0d89d";\r\n
}\r\n
\r\n
/*\r\n
* Calculate the SHA1 of a raw string\r\n
*/\r\n
function rstr_sha1(s)\r\n
{\r\n
return binb2rstr(binb_sha1(rstr2binb(s), s.length * 8));\r\n
}\r\n
\r\n
/*\r\n
* Calculate the HMAC-SHA1 of a key and some data (raw strings)\r\n
*/\r\n
function rstr_hmac_sha1(key, data)\r\n
{\r\n
var bkey = rstr2binb(key);\r\n
if(bkey.length > 16) bkey = binb_sha1(bkey, key.length * 8);\r\n
\r\n
var ipad = Array(16), opad = Array(16);\r\n
for(var i = 0; i < 16; i++)\r\n
{\r\n
ipad[i] = bkey[i] ^ 0x36363636;\r\n
opad[i] = bkey[i] ^ 0x5C5C5C5C;\r\n
}\r\n
\r\n
var hash = binb_sha1(ipad.concat(rstr2binb(data)), 512 + data.length * 8);\r\n
return binb2rstr(binb_sha1(opad.concat(hash), 512 + 160));\r\n
}\r\n
\r\n
/*\r\n
* Convert a raw string to a hex string\r\n
*/\r\n
function rstr2hex(input)\r\n
{\r\n
try { hexcase } catch(e) { hexcase=0; }\r\n
var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";\r\n
var output = "";\r\n
var x;\r\n
for(var i = 0; i < input.length; i++)\r\n
{\r\n
x = input.charCodeAt(i);\r\n
output += hex_tab.charAt((x >>> 4) & 0x0F)\r\n
+ hex_tab.charAt( x & 0x0F);\r\n
}\r\n
return output;\r\n
}\r\n
\r\n
/*\r\n
* Convert a raw string to a base-64 string\r\n
*/\r\n
function rstr2b64(input)\r\n
{\r\n
try { b64pad } catch(e) { b64pad=\'\'; }\r\n
var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";\r\n
var output = "";\r\n
var len = input.length;\r\n
for(var i = 0; i < len; i += 3)\r\n
{\r\n
var triplet = (input.charCodeAt(i) << 16)\r\n
| (i + 1 < len ? input.charCodeAt(i+1) << 8 : 0)\r\n
| (i + 2 < len ? input.charCodeAt(i+2) : 0);\r\n
for(var j = 0; j < 4; j++)\r\n
{\r\n
if(i * 8 + j * 6 > input.length * 8) output += b64pad;\r\n
else output += tab.charAt((triplet >>> 6*(3-j)) & 0x3F);\r\n
}\r\n
}\r\n
return output;\r\n
}\r\n
\r\n
/*\r\n
* Convert a raw string to an arbitrary string encoding\r\n
*/\r\n
function rstr2any(input, encoding)\r\n
{\r\n
var divisor = encoding.length;\r\n
var remainders = Array();\r\n
var i, q, x, quotient;\r\n
\r\n
/* Convert to an array of 16-bit big-endian values, forming the dividend */\r\n
var dividend = Array(Math.ceil(input.length / 2));\r\n
for(i = 0; i < dividend.length; i++)\r\n
{\r\n
dividend[i] = (input.charCodeAt(i * 2) << 8) | input.charCodeAt(i * 2 + 1);\r\n
}\r\n
\r\n
/*\r\n
* Repeatedly perform a long division. The binary array forms the dividend,\r\n
* the length of the encoding is the divisor. Once computed, the quotient\r\n
* forms the dividend for the next step. We stop when the dividend is zero.\r\n
* All remainders are stored for later use.\r\n
*/\r\n
while(dividend.length > 0)\r\n
{\r\n
quotient = Array();\r\n
x = 0;\r\n
for(i = 0; i < dividend.length; i++)\r\n
{\r\n
x = (x << 16) + dividend[i];\r\n
q = Math.floor(x / divisor);\r\n
x -= q * divisor;\r\n
if(quotient.length > 0 || q > 0)\r\n
quotient[quotient.length] = q;\r\n
}\r\n
remainders[remainders.length] = x;\r\n
dividend = quotient;\r\n
}\r\n
\r\n
/* Convert the remainders to the output string */\r\n
var output = "";\r\n
for(i = remainders.length - 1; i >= 0; i--)\r\n
output += encoding.charAt(remainders[i]);\r\n
\r\n
/* Append leading zero equivalents */\r\n
var full_length = Math.ceil(input.length * 8 /\r\n
(Math.log(encoding.length) / Math.log(2)))\r\n
for(i = output.length; i < full_length; i++)\r\n
output = encoding[0] + output;\r\n
\r\n
return output;\r\n
}\r\n
\r\n
/*\r\n
* Encode a string as utf-8.\r\n
* For efficiency, this assumes the input is valid utf-16.\r\n
*/\r\n
function str2rstr_utf8(input)\r\n
{\r\n
var output = "";\r\n
var i = -1;\r\n
var x, y;\r\n
\r\n
while(++i < input.length)\r\n
{\r\n
/* Decode utf-16 surrogate pairs */\r\n
x = input.charCodeAt(i);\r\n
y = i + 1 < input.length ? input.charCodeAt(i + 1) : 0;\r\n
if(0xD800 <= x && x <= 0xDBFF && 0xDC00 <= y && y <= 0xDFFF)\r\n
{\r\n
x = 0x10000 + ((x & 0x03FF) << 10) + (y & 0x03FF);\r\n
i++;\r\n
}\r\n
\r\n
/* Encode output as utf-8 */\r\n
if(x <= 0x7F)\r\n
output += String.fromCharCode(x);\r\n
else if(x <= 0x7FF)\r\n
output += String.fromCharCode(0xC0 | ((x >>> 6 ) & 0x1F),\r\n
0x80 | ( x & 0x3F));\r\n
else if(x <= 0xFFFF)\r\n
output += String.fromCharCode(0xE0 | ((x >>> 12) & 0x0F),\r\n
0x80 | ((x >>> 6 ) & 0x3F),\r\n
0x80 | ( x & 0x3F));\r\n
else if(x <= 0x1FFFFF)\r\n
output += String.fromCharCode(0xF0 | ((x >>> 18) & 0x07),\r\n
0x80 | ((x >>> 12) & 0x3F),\r\n
0x80 | ((x >>> 6 ) & 0x3F),\r\n
0x80 | ( x & 0x3F));\r\n
}\r\n
return output;\r\n
}\r\n
\r\n
/*\r\n
* Encode a string as utf-16\r\n
*/\r\n
function str2rstr_utf16le(input)\r\n
{\r\n
var output = "";\r\n
for(var i = 0; i < input.length; i++)\r\n
output += String.fromCharCode( input.charCodeAt(i) & 0xFF,\r\n
(input.charCodeAt(i) >>> 8) & 0xFF);\r\n
return output;\r\n
}\r\n
\r\n
function str2rstr_utf16be(input)\r\n
{\r\n
var output = "";\r\n
for(var i = 0; i < input.length; i++)\r\n
output += String.fromCharCode((input.charCodeAt(i) >>> 8) & 0xFF,\r\n
input.charCodeAt(i) & 0xFF);\r\n
return output;\r\n
}\r\n
\r\n
/*\r\n
* Convert a raw string to an array of big-endian words\r\n
* Characters >255 have their high-byte silently ignored.\r\n
*/\r\n
function rstr2binb(input)\r\n
{\r\n
var output = Array(input.length >> 2);\r\n
for(var i = 0; i < output.length; i++)\r\n
output[i] = 0;\r\n
for(var i = 0; i < input.length * 8; i += 8)\r\n
output[i>>5] |= (input.charCodeAt(i / 8) & 0xFF) << (24 - i % 32);\r\n
return output;\r\n
}\r\n
\r\n
/*\r\n
* Convert an array of big-endian words to a string\r\n
*/\r\n
function binb2rstr(input)\r\n
{\r\n
var output = "";\r\n
for(var i = 0; i < input.length * 32; i += 8)\r\n
output += String.fromCharCode((input[i>>5] >>> (24 - i % 32)) & 0xFF);\r\n
return output;\r\n
}\r\n
\r\n
/*\r\n
* Calculate the SHA-1 of an array of big-endian words, and a bit length\r\n
*/\r\n
function binb_sha1(x, len)\r\n
{\r\n
/* append padding */\r\n
x[len >> 5] |= 0x80 << (24 - len % 32);\r\n
x[((len + 64 >> 9) << 4) + 15] = len;\r\n
\r\n
var w = Array(80);\r\n
var a = 1732584193;\r\n
var b = -271733879;\r\n
var c = -1732584194;\r\n
var d = 271733878;\r\n
var e = -1009589776;\r\n
\r\n
for(var i = 0; i < x.length; i += 16)\r\n
{\r\n
var olda = a;\r\n
var oldb = b;\r\n
var oldc = c;\r\n
var oldd = d;\r\n
var olde = e;\r\n
\r\n
for(var j = 0; j < 80; j++)\r\n
{\r\n
if(j < 16) w[j] = x[i + j];\r\n
else w[j] = bit_rol(w[j-3] ^ w[j-8] ^ w[j-14] ^ w[j-16], 1);\r\n
var t = safe_add(safe_add(bit_rol(a, 5), sha1_ft(j, b, c, d)),\r\n
safe_add(safe_add(e, w[j]), sha1_kt(j)));\r\n
e = d;\r\n
d = c;\r\n
c = bit_rol(b, 30);\r\n
b = a;\r\n
a = t;\r\n
}\r\n
\r\n
a = safe_add(a, olda);\r\n
b = safe_add(b, oldb);\r\n
c = safe_add(c, oldc);\r\n
d = safe_add(d, oldd);\r\n
e = safe_add(e, olde);\r\n
}\r\n
return Array(a, b, c, d, e);\r\n
\r\n
}\r\n
\r\n
/*\r\n
* Perform the appropriate triplet combination function for the current\r\n
* iteration\r\n
*/\r\n
function sha1_ft(t, b, c, d)\r\n
{\r\n
if(t < 20) return (b & c) | ((~b) & d);\r\n
if(t < 40) return b ^ c ^ d;\r\n
if(t < 60) return (b & c) | (b & d) | (c & d);\r\n
return b ^ c ^ d;\r\n
}\r\n
\r\n
/*\r\n
* Determine the appropriate additive constant for the current iteration\r\n
*/\r\n
function sha1_kt(t)\r\n
{\r\n
return (t < 20) ? 1518500249 : (t < 40) ? 1859775393 :\r\n
(t < 60) ? -1894007588 : -899497514;\r\n
}\r\n
\r\n
/*\r\n
* Add integers, wrapping at 2^32. This uses 16-bit operations internally\r\n
* to work around bugs in some JS interpreters.\r\n
*/\r\n
function safe_add(x, y)\r\n
{\r\n
var lsw = (x & 0xFFFF) + (y & 0xFFFF);\r\n
var msw = (x >> 16) + (y >> 16) + (lsw >> 16);\r\n
return (msw << 16) | (lsw & 0xFFFF);\r\n
}\r\n
\r\n
/*\r\n
* Bitwise rotate a 32-bit number to the left.\r\n
*/\r\n
function bit_rol(num, cnt)\r\n
{\r\n
return (num << cnt) | (num >>> (32 - cnt));\r\n
}\r\n
]]></string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>size</string> </key>
<value> <int>9362</int> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_EtagSupport__etag</string> </key>
<value> <string>ts16390937.04</string> </value>
</item>
<item>
<key> <string>__name__</string> </key>
<value> <string>sha256.js</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>application/javascript</string> </value>
</item>
<item>
<key> <string>data</string> </key>
<value> <string encoding="cdata"><![CDATA[
/*\r\n
* A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined\r\n
* in FIPS 180-2\r\n
* Version 2.2 Copyright Angel Marin, Paul Johnston 2000 - 2009.\r\n
* Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet\r\n
* Distributed under the BSD License\r\n
* See http://pajhome.org.uk/crypt/md5 for details.\r\n
* Also http://anmar.eu.org/projects/jssha2/\r\n
*/\r\n
\r\n
/*\r\n
* Configurable variables. You may need to tweak these to be compatible with\r\n
* the server-side, but the defaults work in most cases.\r\n
*/\r\n
var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */\r\n
var b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance */\r\n
\r\n
/*\r\n
* These are the functions you\'ll usually want to call\r\n
* They take string arguments and return either hex or base-64 encoded strings\r\n
*/\r\n
function hex_sha256(s) { return rstr2hex(rstr_sha256(str2rstr_utf8(s))); }\r\n
function b64_sha256(s) { return rstr2b64(rstr_sha256(str2rstr_utf8(s))); }\r\n
function any_sha256(s, e) { return rstr2any(rstr_sha256(str2rstr_utf8(s)), e); }\r\n
function hex_hmac_sha256(k, d)\r\n
{ return rstr2hex(rstr_hmac_sha256(str2rstr_utf8(k), str2rstr_utf8(d))); }\r\n
function b64_hmac_sha256(k, d)\r\n
{ return rstr2b64(rstr_hmac_sha256(str2rstr_utf8(k), str2rstr_utf8(d))); }\r\n
function any_hmac_sha256(k, d, e)\r\n
{ return rstr2any(rstr_hmac_sha256(str2rstr_utf8(k), str2rstr_utf8(d)), e); }\r\n
\r\n
/*\r\n
* Perform a simple self-test to see if the VM is working\r\n
*/\r\n
function sha256_vm_test()\r\n
{\r\n
return hex_sha256("abc").toLowerCase() ==\r\n
"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad";\r\n
}\r\n
\r\n
/*\r\n
* Calculate the sha256 of a raw string\r\n
*/\r\n
function rstr_sha256(s)\r\n
{\r\n
return binb2rstr(binb_sha256(rstr2binb(s), s.length * 8));\r\n
}\r\n
\r\n
/*\r\n
* Calculate the HMAC-sha256 of a key and some data (raw strings)\r\n
*/\r\n
function rstr_hmac_sha256(key, data)\r\n
{\r\n
var bkey = rstr2binb(key);\r\n
if(bkey.length > 16) bkey = binb_sha256(bkey, key.length * 8);\r\n
\r\n
var ipad = Array(16), opad = Array(16);\r\n
for(var i = 0; i < 16; i++)\r\n
{\r\n
ipad[i] = bkey[i] ^ 0x36363636;\r\n
opad[i] = bkey[i] ^ 0x5C5C5C5C;\r\n
}\r\n
\r\n
var hash = binb_sha256(ipad.concat(rstr2binb(data)), 512 + data.length * 8);\r\n
return binb2rstr(binb_sha256(opad.concat(hash), 512 + 256));\r\n
}\r\n
\r\n
/*\r\n
* Convert a raw string to a hex string\r\n
*/\r\n
function rstr2hex(input)\r\n
{\r\n
try { hexcase } catch(e) { hexcase=0; }\r\n
var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";\r\n
var output = "";\r\n
var x;\r\n
for(var i = 0; i < input.length; i++)\r\n
{\r\n
x = input.charCodeAt(i);\r\n
output += hex_tab.charAt((x >>> 4) & 0x0F)\r\n
+ hex_tab.charAt( x & 0x0F);\r\n
}\r\n
return output;\r\n
}\r\n
\r\n
/*\r\n
* Convert a raw string to a base-64 string\r\n
*/\r\n
function rstr2b64(input)\r\n
{\r\n
try { b64pad } catch(e) { b64pad=\'\'; }\r\n
var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";\r\n
var output = "";\r\n
var len = input.length;\r\n
for(var i = 0; i < len; i += 3)\r\n
{\r\n
var triplet = (input.charCodeAt(i) << 16)\r\n
| (i + 1 < len ? input.charCodeAt(i+1) << 8 : 0)\r\n
| (i + 2 < len ? input.charCodeAt(i+2) : 0);\r\n
for(var j = 0; j < 4; j++)\r\n
{\r\n
if(i * 8 + j * 6 > input.length * 8) output += b64pad;\r\n
else output += tab.charAt((triplet >>> 6*(3-j)) & 0x3F);\r\n
}\r\n
}\r\n
return output;\r\n
}\r\n
\r\n
/*\r\n
* Convert a raw string to an arbitrary string encoding\r\n
*/\r\n
function rstr2any(input, encoding)\r\n
{\r\n
var divisor = encoding.length;\r\n
var remainders = Array();\r\n
var i, q, x, quotient;\r\n
\r\n
/* Convert to an array of 16-bit big-endian values, forming the dividend */\r\n
var dividend = Array(Math.ceil(input.length / 2));\r\n
for(i = 0; i < dividend.length; i++)\r\n
{\r\n
dividend[i] = (input.charCodeAt(i * 2) << 8) | input.charCodeAt(i * 2 + 1);\r\n
}\r\n
\r\n
/*\r\n
* Repeatedly perform a long division. The binary array forms the dividend,\r\n
* the length of the encoding is the divisor. Once computed, the quotient\r\n
* forms the dividend for the next step. We stop when the dividend is zero.\r\n
* All remainders are stored for later use.\r\n
*/\r\n
while(dividend.length > 0)\r\n
{\r\n
quotient = Array();\r\n
x = 0;\r\n
for(i = 0; i < dividend.length; i++)\r\n
{\r\n
x = (x << 16) + dividend[i];\r\n
q = Math.floor(x / divisor);\r\n
x -= q * divisor;\r\n
if(quotient.length > 0 || q > 0)\r\n
quotient[quotient.length] = q;\r\n
}\r\n
remainders[remainders.length] = x;\r\n
dividend = quotient;\r\n
}\r\n
\r\n
/* Convert the remainders to the output string */\r\n
var output = "";\r\n
for(i = remainders.length - 1; i >= 0; i--)\r\n
output += encoding.charAt(remainders[i]);\r\n
\r\n
/* Append leading zero equivalents */\r\n
var full_length = Math.ceil(input.length * 8 /\r\n
(Math.log(encoding.length) / Math.log(2)))\r\n
for(i = output.length; i < full_length; i++)\r\n
output = encoding[0] + output;\r\n
\r\n
return output;\r\n
}\r\n
\r\n
/*\r\n
* Encode a string as utf-8.\r\n
* For efficiency, this assumes the input is valid utf-16.\r\n
*/\r\n
function str2rstr_utf8(input)\r\n
{\r\n
var output = "";\r\n
var i = -1;\r\n
var x, y;\r\n
\r\n
while(++i < input.length)\r\n
{\r\n
/* Decode utf-16 surrogate pairs */\r\n
x = input.charCodeAt(i);\r\n
y = i + 1 < input.length ? input.charCodeAt(i + 1) : 0;\r\n
if(0xD800 <= x && x <= 0xDBFF && 0xDC00 <= y && y <= 0xDFFF)\r\n
{\r\n
x = 0x10000 + ((x & 0x03FF) << 10) + (y & 0x03FF);\r\n
i++;\r\n
}\r\n
\r\n
/* Encode output as utf-8 */\r\n
if(x <= 0x7F)\r\n
output += String.fromCharCode(x);\r\n
else if(x <= 0x7FF)\r\n
output += String.fromCharCode(0xC0 | ((x >>> 6 ) & 0x1F),\r\n
0x80 | ( x & 0x3F));\r\n
else if(x <= 0xFFFF)\r\n
output += String.fromCharCode(0xE0 | ((x >>> 12) & 0x0F),\r\n
0x80 | ((x >>> 6 ) & 0x3F),\r\n
0x80 | ( x & 0x3F));\r\n
else if(x <= 0x1FFFFF)\r\n
output += String.fromCharCode(0xF0 | ((x >>> 18) & 0x07),\r\n
0x80 | ((x >>> 12) & 0x3F),\r\n
0x80 | ((x >>> 6 ) & 0x3F),\r\n
0x80 | ( x & 0x3F));\r\n
}\r\n
return output;\r\n
}\r\n
\r\n
/*\r\n
* Encode a string as utf-16\r\n
*/\r\n
function str2rstr_utf16le(input)\r\n
{\r\n
var output = "";\r\n
for(var i = 0; i < input.length; i++)\r\n
output += String.fromCharCode( input.charCodeAt(i) & 0xFF,\r\n
(input.charCodeAt(i) >>> 8) & 0xFF);\r\n
return output;\r\n
}\r\n
\r\n
function str2rstr_utf16be(input)\r\n
{\r\n
var output = "";\r\n
for(var i = 0; i < input.length; i++)\r\n
output += String.fromCharCode((input.charCodeAt(i) >>> 8) & 0xFF,\r\n
input.charCodeAt(i) & 0xFF);\r\n
return output;\r\n
}\r\n
\r\n
/*\r\n
* Convert a raw string to an array of big-endian words\r\n
* Characters >255 have their high-byte silently ignored.\r\n
*/\r\n
function rstr2binb(input)\r\n
{\r\n
var output = Array(input.length >> 2);\r\n
for(var i = 0; i < output.length; i++)\r\n
output[i] = 0;\r\n
for(var i = 0; i < input.length * 8; i += 8)\r\n
output[i>>5] |= (input.charCodeAt(i / 8) & 0xFF) << (24 - i % 32);\r\n
return output;\r\n
}\r\n
\r\n
/*\r\n
* Convert an array of big-endian words to a string\r\n
*/\r\n
function binb2rstr(input)\r\n
{\r\n
var output = "";\r\n
for(var i = 0; i < input.length * 32; i += 8)\r\n
output += String.fromCharCode((input[i>>5] >>> (24 - i % 32)) & 0xFF);\r\n
return output;\r\n
}\r\n
\r\n
/*\r\n
* Main sha256 function, with its support functions\r\n
*/\r\n
function sha256_S (X, n) {return ( X >>> n ) | (X << (32 - n));}\r\n
function sha256_R (X, n) {return ( X >>> n );}\r\n
function sha256_Ch(x, y, z) {return ((x & y) ^ ((~x) & z));}\r\n
function sha256_Maj(x, y, z) {return ((x & y) ^ (x & z) ^ (y & z));}\r\n
function sha256_Sigma0256(x) {return (sha256_S(x, 2) ^ sha256_S(x, 13) ^ sha256_S(x, 22));}\r\n
function sha256_Sigma1256(x) {return (sha256_S(x, 6) ^ sha256_S(x, 11) ^ sha256_S(x, 25));}\r\n
function sha256_Gamma0256(x) {return (sha256_S(x, 7) ^ sha256_S(x, 18) ^ sha256_R(x, 3));}\r\n
function sha256_Gamma1256(x) {return (sha256_S(x, 17) ^ sha256_S(x, 19) ^ sha256_R(x, 10));}\r\n
function sha256_Sigma0512(x) {return (sha256_S(x, 28) ^ sha256_S(x, 34) ^ sha256_S(x, 39));}\r\n
function sha256_Sigma1512(x) {return (sha256_S(x, 14) ^ sha256_S(x, 18) ^ sha256_S(x, 41));}\r\n
function sha256_Gamma0512(x) {return (sha256_S(x, 1) ^ sha256_S(x, 8) ^ sha256_R(x, 7));}\r\n
function sha256_Gamma1512(x) {return (sha256_S(x, 19) ^ sha256_S(x, 61) ^ sha256_R(x, 6));}\r\n
\r\n
var sha256_K = new Array\r\n
(\r\n
1116352408, 1899447441, -1245643825, -373957723, 961987163, 1508970993,\r\n
-1841331548, -1424204075, -670586216, 310598401, 607225278, 1426881987,\r\n
1925078388, -2132889090, -1680079193, -1046744716, -459576895, -272742522,\r\n
264347078, 604807628, 770255983, 1249150122, 1555081692, 1996064986,\r\n
-1740746414, -1473132947, -1341970488, -1084653625, -958395405, -710438585,\r\n
113926993, 338241895, 666307205, 773529912, 1294757372, 1396182291,\r\n
1695183700, 1986661051, -2117940946, -1838011259, -1564481375, -1474664885,\r\n
-1035236496, -949202525, -778901479, -694614492, -200395387, 275423344,\r\n
430227734, 506948616, 659060556, 883997877, 958139571, 1322822218,\r\n
1537002063, 1747873779, 1955562222, 2024104815, -2067236844, -1933114872,\r\n
-1866530822, -1538233109, -1090935817, -965641998\r\n
);\r\n
\r\n
function binb_sha256(m, l)\r\n
{\r\n
var HASH = new Array(1779033703, -1150833019, 1013904242, -1521486534,\r\n
1359893119, -1694144372, 528734635, 1541459225);\r\n
var W = new Array(64);\r\n
var a, b, c, d, e, f, g, h;\r\n
var i, j, T1, T2;\r\n
\r\n
/* append padding */\r\n
m[l >> 5] |= 0x80 << (24 - l % 32);\r\n
m[((l + 64 >> 9) << 4) + 15] = l;\r\n
\r\n
for(i = 0; i < m.length; i += 16)\r\n
{\r\n
a = HASH[0];\r\n
b = HASH[1];\r\n
c = HASH[2];\r\n
d = HASH[3];\r\n
e = HASH[4];\r\n
f = HASH[5];\r\n
g = HASH[6];\r\n
h = HASH[7];\r\n
\r\n
for(j = 0; j < 64; j++)\r\n
{\r\n
if (j < 16) W[j] = m[j + i];\r\n
else W[j] = safe_add(safe_add(safe_add(sha256_Gamma1256(W[j - 2]), W[j - 7]),\r\n
sha256_Gamma0256(W[j - 15])), W[j - 16]);\r\n
\r\n
T1 = safe_add(safe_add(safe_add(safe_add(h, sha256_Sigma1256(e)), sha256_Ch(e, f, g)),\r\n
sha256_K[j]), W[j]);\r\n
T2 = safe_add(sha256_Sigma0256(a), sha256_Maj(a, b, c));\r\n
h = g;\r\n
g = f;\r\n
f = e;\r\n
e = safe_add(d, T1);\r\n
d = c;\r\n
c = b;\r\n
b = a;\r\n
a = safe_add(T1, T2);\r\n
}\r\n
\r\n
HASH[0] = safe_add(a, HASH[0]);\r\n
HASH[1] = safe_add(b, HASH[1]);\r\n
HASH[2] = safe_add(c, HASH[2]);\r\n
HASH[3] = safe_add(d, HASH[3]);\r\n
HASH[4] = safe_add(e, HASH[4]);\r\n
HASH[5] = safe_add(f, HASH[5]);\r\n
HASH[6] = safe_add(g, HASH[6]);\r\n
HASH[7] = safe_add(h, HASH[7]);\r\n
}\r\n
return HASH;\r\n
}\r\n
\r\n
function safe_add (x, y)\r\n
{\r\n
var lsw = (x & 0xFFFF) + (y & 0xFFFF);\r\n
var msw = (x >> 16) + (y >> 16) + (lsw >> 16);\r\n
return (msw << 16) | (lsw & 0xFFFF);\r\n
}\r\n
]]></string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>size</string> </key>
<value> <int>11067</int> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_EtagSupport__etag</string> </key>
<value> <string>ts16390948.7</string> </value>
</item>
<item>
<key> <string>__name__</string> </key>
<value> <string>sha512.js</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>application/javascript</string> </value>
</item>
<item>
<key> <string>data</string> </key>
<value> <string encoding="cdata"><![CDATA[
/*\r\n
* A JavaScript implementation of the Secure Hash Algorithm, SHA-512, as defined\r\n
* in FIPS 180-2\r\n
* Version 2.2 Copyright Anonymous Contributor, Paul Johnston 2000 - 2009.\r\n
* Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet\r\n
* Distributed under the BSD License\r\n
* See http://pajhome.org.uk/crypt/md5 for details.\r\n
*/\r\n
\r\n
/*\r\n
* Configurable variables. You may need to tweak these to be compatible with\r\n
* the server-side, but the defaults work in most cases.\r\n
*/\r\n
var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */\r\n
var b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance */\r\n
\r\n
/*\r\n
* These are the functions you\'ll usually want to call\r\n
* They take string arguments and return either hex or base-64 encoded strings\r\n
*/\r\n
function hex_sha512(s) { return rstr2hex(rstr_sha512(str2rstr_utf8(s))); }\r\n
function b64_sha512(s) { return rstr2b64(rstr_sha512(str2rstr_utf8(s))); }\r\n
function any_sha512(s, e) { return rstr2any(rstr_sha512(str2rstr_utf8(s)), e);}\r\n
function hex_hmac_sha512(k, d)\r\n
{ return rstr2hex(rstr_hmac_sha512(str2rstr_utf8(k), str2rstr_utf8(d))); }\r\n
function b64_hmac_sha512(k, d)\r\n
{ return rstr2b64(rstr_hmac_sha512(str2rstr_utf8(k), str2rstr_utf8(d))); }\r\n
function any_hmac_sha512(k, d, e)\r\n
{ return rstr2any(rstr_hmac_sha512(str2rstr_utf8(k), str2rstr_utf8(d)), e);}\r\n
\r\n
/*\r\n
* Perform a simple self-test to see if the VM is working\r\n
*/\r\n
function sha512_vm_test()\r\n
{\r\n
return hex_sha512("abc").toLowerCase() ==\r\n
"ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a" +\r\n
"2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f";\r\n
}\r\n
\r\n
/*\r\n
* Calculate the SHA-512 of a raw string\r\n
*/\r\n
function rstr_sha512(s)\r\n
{\r\n
return binb2rstr(binb_sha512(rstr2binb(s), s.length * 8));\r\n
}\r\n
\r\n
/*\r\n
* Calculate the HMAC-SHA-512 of a key and some data (raw strings)\r\n
*/\r\n
function rstr_hmac_sha512(key, data)\r\n
{\r\n
var bkey = rstr2binb(key);\r\n
if(bkey.length > 32) bkey = binb_sha512(bkey, key.length * 8);\r\n
\r\n
var ipad = Array(32), opad = Array(32);\r\n
for(var i = 0; i < 32; i++)\r\n
{\r\n
ipad[i] = bkey[i] ^ 0x36363636;\r\n
opad[i] = bkey[i] ^ 0x5C5C5C5C;\r\n
}\r\n
\r\n
var hash = binb_sha512(ipad.concat(rstr2binb(data)), 1024 + data.length * 8);\r\n
return binb2rstr(binb_sha512(opad.concat(hash), 1024 + 512));\r\n
}\r\n
\r\n
/*\r\n
* Convert a raw string to a hex string\r\n
*/\r\n
function rstr2hex(input)\r\n
{\r\n
try { hexcase } catch(e) { hexcase=0; }\r\n
var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";\r\n
var output = "";\r\n
var x;\r\n
for(var i = 0; i < input.length; i++)\r\n
{\r\n
x = input.charCodeAt(i);\r\n
output += hex_tab.charAt((x >>> 4) & 0x0F)\r\n
+ hex_tab.charAt( x & 0x0F);\r\n
}\r\n
return output;\r\n
}\r\n
\r\n
/*\r\n
* Convert a raw string to a base-64 string\r\n
*/\r\n
function rstr2b64(input)\r\n
{\r\n
try { b64pad } catch(e) { b64pad=\'\'; }\r\n
var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";\r\n
var output = "";\r\n
var len = input.length;\r\n
for(var i = 0; i < len; i += 3)\r\n
{\r\n
var triplet = (input.charCodeAt(i) << 16)\r\n
| (i + 1 < len ? input.charCodeAt(i+1) << 8 : 0)\r\n
| (i + 2 < len ? input.charCodeAt(i+2) : 0);\r\n
for(var j = 0; j < 4; j++)\r\n
{\r\n
if(i * 8 + j * 6 > input.length * 8) output += b64pad;\r\n
else output += tab.charAt((triplet >>> 6*(3-j)) & 0x3F);\r\n
}\r\n
}\r\n
return output;\r\n
}\r\n
\r\n
/*\r\n
* Convert a raw string to an arbitrary string encoding\r\n
*/\r\n
function rstr2any(input, encoding)\r\n
{\r\n
var divisor = encoding.length;\r\n
var i, j, q, x, quotient;\r\n
\r\n
/* Convert to an array of 16-bit big-endian values, forming the dividend */\r\n
var dividend = Array(Math.ceil(input.length / 2));\r\n
for(i = 0; i < dividend.length; i++)\r\n
{\r\n
dividend[i] = (input.charCodeAt(i * 2) << 8) | input.charCodeAt(i * 2 + 1);\r\n
}\r\n
\r\n
/*\r\n
* Repeatedly perform a long division. The binary array forms the dividend,\r\n
* the length of the encoding is the divisor. Once computed, the quotient\r\n
* forms the dividend for the next step. All remainders are stored for later\r\n
* use.\r\n
*/\r\n
var full_length = Math.ceil(input.length * 8 /\r\n
(Math.log(encoding.length) / Math.log(2)));\r\n
var remainders = Array(full_length);\r\n
for(j = 0; j < full_length; j++)\r\n
{\r\n
quotient = Array();\r\n
x = 0;\r\n
for(i = 0; i < dividend.length; i++)\r\n
{\r\n
x = (x << 16) + dividend[i];\r\n
q = Math.floor(x / divisor);\r\n
x -= q * divisor;\r\n
if(quotient.length > 0 || q > 0)\r\n
quotient[quotient.length] = q;\r\n
}\r\n
remainders[j] = x;\r\n
dividend = quotient;\r\n
}\r\n
\r\n
/* Convert the remainders to the output string */\r\n
var output = "";\r\n
for(i = remainders.length - 1; i >= 0; i--)\r\n
output += encoding.charAt(remainders[i]);\r\n
\r\n
return output;\r\n
}\r\n
\r\n
/*\r\n
* Encode a string as utf-8.\r\n
* For efficiency, this assumes the input is valid utf-16.\r\n
*/\r\n
function str2rstr_utf8(input)\r\n
{\r\n
var output = "";\r\n
var i = -1;\r\n
var x, y;\r\n
\r\n
while(++i < input.length)\r\n
{\r\n
/* Decode utf-16 surrogate pairs */\r\n
x = input.charCodeAt(i);\r\n
y = i + 1 < input.length ? input.charCodeAt(i + 1) : 0;\r\n
if(0xD800 <= x && x <= 0xDBFF && 0xDC00 <= y && y <= 0xDFFF)\r\n
{\r\n
x = 0x10000 + ((x & 0x03FF) << 10) + (y & 0x03FF);\r\n
i++;\r\n
}\r\n
\r\n
/* Encode output as utf-8 */\r\n
if(x <= 0x7F)\r\n
output += String.fromCharCode(x);\r\n
else if(x <= 0x7FF)\r\n
output += String.fromCharCode(0xC0 | ((x >>> 6 ) & 0x1F),\r\n
0x80 | ( x & 0x3F));\r\n
else if(x <= 0xFFFF)\r\n
output += String.fromCharCode(0xE0 | ((x >>> 12) & 0x0F),\r\n
0x80 | ((x >>> 6 ) & 0x3F),\r\n
0x80 | ( x & 0x3F));\r\n
else if(x <= 0x1FFFFF)\r\n
output += String.fromCharCode(0xF0 | ((x >>> 18) & 0x07),\r\n
0x80 | ((x >>> 12) & 0x3F),\r\n
0x80 | ((x >>> 6 ) & 0x3F),\r\n
0x80 | ( x & 0x3F));\r\n
}\r\n
return output;\r\n
}\r\n
\r\n
/*\r\n
* Encode a string as utf-16\r\n
*/\r\n
function str2rstr_utf16le(input)\r\n
{\r\n
var output = "";\r\n
for(var i = 0; i < input.length; i++)\r\n
output += String.fromCharCode( input.charCodeAt(i) & 0xFF,\r\n
(input.charCodeAt(i) >>> 8) & 0xFF);\r\n
return output;\r\n
}\r\n
\r\n
function str2rstr_utf16be(input)\r\n
{\r\n
var output = "";\r\n
for(var i = 0; i < input.length; i++)\r\n
output += String.fromCharCode((input.charCodeAt(i) >>> 8) & 0xFF,\r\n
input.charCodeAt(i) & 0xFF);\r\n
return output;\r\n
}\r\n
\r\n
/*\r\n
* Convert a raw string to an array of big-endian words\r\n
* Characters >255 have their high-byte silently ignored.\r\n
*/\r\n
function rstr2binb(input)\r\n
{\r\n
var output = Array(input.length >> 2);\r\n
for(var i = 0; i < output.length; i++)\r\n
output[i] = 0;\r\n
for(var i = 0; i < input.length * 8; i += 8)\r\n
output[i>>5] |= (input.charCodeAt(i / 8) & 0xFF) << (24 - i % 32);\r\n
return output;\r\n
}\r\n
\r\n
/*\r\n
* Convert an array of big-endian words to a string\r\n
*/\r\n
function binb2rstr(input)\r\n
{\r\n
var output = "";\r\n
for(var i = 0; i < input.length * 32; i += 8)\r\n
output += String.fromCharCode((input[i>>5] >>> (24 - i % 32)) & 0xFF);\r\n
return output;\r\n
}\r\n
\r\n
/*\r\n
* Calculate the SHA-512 of an array of big-endian dwords, and a bit length\r\n
*/\r\n
var sha512_k;\r\n
function binb_sha512(x, len)\r\n
{\r\n
if(sha512_k == undefined)\r\n
{\r\n
//SHA512 constants\r\n
sha512_k = new Array(\r\n
new int64(0x428a2f98, -685199838), new int64(0x71374491, 0x23ef65cd),\r\n
new int64(-1245643825, -330482897), new int64(-373957723, -2121671748),\r\n
new int64(0x3956c25b, -213338824), new int64(0x59f111f1, -1241133031),\r\n
new int64(-1841331548, -1357295717), new int64(-1424204075, -630357736),\r\n
new int64(-670586216, -1560083902), new int64(0x12835b01, 0x45706fbe),\r\n
new int64(0x243185be, 0x4ee4b28c), new int64(0x550c7dc3, -704662302),\r\n
new int64(0x72be5d74, -226784913), new int64(-2132889090, 0x3b1696b1),\r\n
new int64(-1680079193, 0x25c71235), new int64(-1046744716, -815192428),\r\n
new int64(-459576895, -1628353838), new int64(-272742522, 0x384f25e3),\r\n
new int64(0xfc19dc6, -1953704523), new int64(0x240ca1cc, 0x77ac9c65),\r\n
new int64(0x2de92c6f, 0x592b0275), new int64(0x4a7484aa, 0x6ea6e483),\r\n
new int64(0x5cb0a9dc, -1119749164), new int64(0x76f988da, -2096016459),\r\n
new int64(-1740746414, -295247957), new int64(-1473132947, 0x2db43210),\r\n
new int64(-1341970488, -1728372417), new int64(-1084653625, -1091629340),\r\n
new int64(-958395405, 0x3da88fc2), new int64(-710438585, -1828018395),\r\n
new int64(0x6ca6351, -536640913), new int64(0x14292967, 0xa0e6e70),\r\n
new int64(0x27b70a85, 0x46d22ffc), new int64(0x2e1b2138, 0x5c26c926),\r\n
new int64(0x4d2c6dfc, 0x5ac42aed), new int64(0x53380d13, -1651133473),\r\n
new int64(0x650a7354, -1951439906), new int64(0x766a0abb, 0x3c77b2a8),\r\n
new int64(-2117940946, 0x47edaee6), new int64(-1838011259, 0x1482353b),\r\n
new int64(-1564481375, 0x4cf10364), new int64(-1474664885, -1136513023),\r\n
new int64(-1035236496, -789014639), new int64(-949202525, 0x654be30),\r\n
new int64(-778901479, -688958952), new int64(-694614492, 0x5565a910),\r\n
new int64(-200395387, 0x5771202a), new int64(0x106aa070, 0x32bbd1b8),\r\n
new int64(0x19a4c116, -1194143544), new int64(0x1e376c08, 0x5141ab53),\r\n
new int64(0x2748774c, -544281703), new int64(0x34b0bcb5, -509917016),\r\n
new int64(0x391c0cb3, -976659869), new int64(0x4ed8aa4a, -482243893),\r\n
new int64(0x5b9cca4f, 0x7763e373), new int64(0x682e6ff3, -692930397),\r\n
new int64(0x748f82ee, 0x5defb2fc), new int64(0x78a5636f, 0x43172f60),\r\n
new int64(-2067236844, -1578062990), new int64(-1933114872, 0x1a6439ec),\r\n
new int64(-1866530822, 0x23631e28), new int64(-1538233109, -561857047),\r\n
new int64(-1090935817, -1295615723), new int64(-965641998, -479046869),\r\n
new int64(-903397682, -366583396), new int64(-779700025, 0x21c0c207),\r\n
new int64(-354779690, -840897762), new int64(-176337025, -294727304),\r\n
new int64(0x6f067aa, 0x72176fba), new int64(0xa637dc5, -1563912026),\r\n
new int64(0x113f9804, -1090974290), new int64(0x1b710b35, 0x131c471b),\r\n
new int64(0x28db77f5, 0x23047d84), new int64(0x32caab7b, 0x40c72493),\r\n
new int64(0x3c9ebe0a, 0x15c9bebc), new int64(0x431d67c4, -1676669620),\r\n
new int64(0x4cc5d4be, -885112138), new int64(0x597f299c, -60457430),\r\n
new int64(0x5fcb6fab, 0x3ad6faec), new int64(0x6c44198c, 0x4a475817));\r\n
}\r\n
\r\n
//Initial hash values\r\n
var H = new Array(\r\n
new int64(0x6a09e667, -205731576),\r\n
new int64(-1150833019, -2067093701),\r\n
new int64(0x3c6ef372, -23791573),\r\n
new int64(-1521486534, 0x5f1d36f1),\r\n
new int64(0x510e527f, -1377402159),\r\n
new int64(-1694144372, 0x2b3e6c1f),\r\n
new int64(0x1f83d9ab, -79577749),\r\n
new int64(0x5be0cd19, 0x137e2179));\r\n
\r\n
var T1 = new int64(0, 0),\r\n
T2 = new int64(0, 0),\r\n
a = new int64(0,0),\r\n
b = new int64(0,0),\r\n
c = new int64(0,0),\r\n
d = new int64(0,0),\r\n
e = new int64(0,0),\r\n
f = new int64(0,0),\r\n
g = new int64(0,0),\r\n
h = new int64(0,0),\r\n
//Temporary variables not specified by the document\r\n
s0 = new int64(0, 0),\r\n
s1 = new int64(0, 0),\r\n
Ch = new int64(0, 0),\r\n
Maj = new int64(0, 0),\r\n
r1 = new int64(0, 0),\r\n
r2 = new int64(0, 0),\r\n
r3 = new int64(0, 0);\r\n
var j, i;\r\n
var W = new Array(80);\r\n
for(i=0; i<80; i++)\r\n
W[i] = new int64(0, 0);\r\n
\r\n
// append padding to the source string. The format is described in the FIPS.\r\n
x[len >> 5] |= 0x80 << (24 - (len & 0x1f));\r\n
x[((len + 128 >> 10)<< 5) + 31] = len;\r\n
\r\n
for(i = 0; i<x.length; i+=32) //32 dwords is the block size\r\n
{\r\n
int64copy(a, H[0]);\r\n
int64copy(b, H[1]);\r\n
int64copy(c, H[2]);\r\n
int64copy(d, H[3]);\r\n
int64copy(e, H[4]);\r\n
int64copy(f, H[5]);\r\n
int64copy(g, H[6]);\r\n
int64copy(h, H[7]);\r\n
\r\n
for(j=0; j<16; j++)\r\n
{\r\n
W[j].h = x[i + 2*j];\r\n
W[j].l = x[i + 2*j + 1];\r\n
}\r\n
\r\n
for(j=16; j<80; j++)\r\n
{\r\n
//sigma1\r\n
int64rrot(r1, W[j-2], 19);\r\n
int64revrrot(r2, W[j-2], 29);\r\n
int64shr(r3, W[j-2], 6);\r\n
s1.l = r1.l ^ r2.l ^ r3.l;\r\n
s1.h = r1.h ^ r2.h ^ r3.h;\r\n
//sigma0\r\n
int64rrot(r1, W[j-15], 1);\r\n
int64rrot(r2, W[j-15], 8);\r\n
int64shr(r3, W[j-15], 7);\r\n
s0.l = r1.l ^ r2.l ^ r3.l;\r\n
s0.h = r1.h ^ r2.h ^ r3.h;\r\n
\r\n
int64add4(W[j], s1, W[j-7], s0, W[j-16]);\r\n
}\r\n
\r\n
for(j = 0; j < 80; j++)\r\n
{\r\n
//Ch\r\n
Ch.l = (e.l & f.l) ^ (~e.l & g.l);\r\n
Ch.h = (e.h & f.h) ^ (~e.h & g.h);\r\n
\r\n
//Sigma1\r\n
int64rrot(r1, e, 14);\r\n
int64rrot(r2, e, 18);\r\n
int64revrrot(r3, e, 9);\r\n
s1.l = r1.l ^ r2.l ^ r3.l;\r\n
s1.h = r1.h ^ r2.h ^ r3.h;\r\n
\r\n
//Sigma0\r\n
int64rrot(r1, a, 28);\r\n
int64revrrot(r2, a, 2);\r\n
int64revrrot(r3, a, 7);\r\n
s0.l = r1.l ^ r2.l ^ r3.l;\r\n
s0.h = r1.h ^ r2.h ^ r3.h;\r\n
\r\n
//Maj\r\n
Maj.l = (a.l & b.l) ^ (a.l & c.l) ^ (b.l & c.l);\r\n
Maj.h = (a.h & b.h) ^ (a.h & c.h) ^ (b.h & c.h);\r\n
\r\n
int64add5(T1, h, s1, Ch, sha512_k[j], W[j]);\r\n
int64add(T2, s0, Maj);\r\n
\r\n
int64copy(h, g);\r\n
int64copy(g, f);\r\n
int64copy(f, e);\r\n
int64add(e, d, T1);\r\n
int64copy(d, c);\r\n
int64copy(c, b);\r\n
int64copy(b, a);\r\n
int64add(a, T1, T2);\r\n
}\r\n
int64add(H[0], H[0], a);\r\n
int64add(H[1], H[1], b);\r\n
int64add(H[2], H[2], c);\r\n
int64add(H[3], H[3], d);\r\n
int64add(H[4], H[4], e);\r\n
int64add(H[5], H[5], f);\r\n
int64add(H[6], H[6], g);\r\n
int64add(H[7], H[7], h);\r\n
}\r\n
\r\n
//represent the hash as an array of 32-bit dwords\r\n
var hash = new Array(16);\r\n
for(i=0; i<8; i++)\r\n
{\r\n
hash[2*i] = H[i].h;\r\n
hash[2*i + 1] = H[i].l;\r\n
}\r\n
return hash;\r\n
}\r\n
\r\n
//A constructor for 64-bit numbers\r\n
function int64(h, l)\r\n
{\r\n
this.h = h;\r\n
this.l = l;\r\n
//this.toString = int64toString;\r\n
}\r\n
\r\n
//Copies src into dst, assuming both are 64-bit numbers\r\n
function int64copy(dst, src)\r\n
{\r\n
dst.h = src.h;\r\n
dst.l = src.l;\r\n
}\r\n
\r\n
//Right-rotates a 64-bit number by shift\r\n
//Won\'t handle cases of shift>=32\r\n
//The function revrrot() is for that\r\n
function int64rrot(dst, x, shift)\r\n
{\r\n
dst.l = (x.l >>> shift) | (x.h << (32-shift));\r\n
dst.h = (x.h >>> shift) | (x.l << (32-shift));\r\n
}\r\n
\r\n
//Reverses the dwords of the source and then rotates right by shift.\r\n
//This is equivalent to rotation by 32+shift\r\n
function int64revrrot(dst, x, shift)\r\n
{\r\n
dst.l = (x.h >>> shift) | (x.l << (32-shift));\r\n
dst.h = (x.l >>> shift) | (x.h << (32-shift));\r\n
}\r\n
\r\n
//Bitwise-shifts right a 64-bit number by shift\r\n
//Won\'t handle shift>=32, but it\'s never needed in SHA512\r\n
function int64shr(dst, x, shift)\r\n
{\r\n
dst.l = (x.l >>> shift) | (x.h << (32-shift));\r\n
dst.h = (x.h >>> shift);\r\n
}\r\n
\r\n
//Adds two 64-bit numbers\r\n
//Like the original implementation, does not rely on 32-bit operations\r\n
function int64add(dst, x, y)\r\n
{\r\n
var w0 = (x.l & 0xffff) + (y.l & 0xffff);\r\n
var w1 = (x.l >>> 16) + (y.l >>> 16) + (w0 >>> 16);\r\n
var w2 = (x.h & 0xffff) + (y.h & 0xffff) + (w1 >>> 16);\r\n
var w3 = (x.h >>> 16) + (y.h >>> 16) + (w2 >>> 16);\r\n
dst.l = (w0 & 0xffff) | (w1 << 16);\r\n
dst.h = (w2 & 0xffff) | (w3 << 16);\r\n
}\r\n
\r\n
//Same, except with 4 addends. Works faster than adding them one by one.\r\n
function int64add4(dst, a, b, c, d)\r\n
{\r\n
var w0 = (a.l & 0xffff) + (b.l & 0xffff) + (c.l & 0xffff) + (d.l & 0xffff);\r\n
var w1 = (a.l >>> 16) + (b.l >>> 16) + (c.l >>> 16) + (d.l >>> 16) + (w0 >>> 16);\r\n
var w2 = (a.h & 0xffff) + (b.h & 0xffff) + (c.h & 0xffff) + (d.h & 0xffff) + (w1 >>> 16);\r\n
var w3 = (a.h >>> 16) + (b.h >>> 16) + (c.h >>> 16) + (d.h >>> 16) + (w2 >>> 16);\r\n
dst.l = (w0 & 0xffff) | (w1 << 16);\r\n
dst.h = (w2 & 0xffff) | (w3 << 16);\r\n
}\r\n
\r\n
//Same, except with 5 addends\r\n
function int64add5(dst, a, b, c, d, e)\r\n
{\r\n
var w0 = (a.l & 0xffff) + (b.l & 0xffff) + (c.l & 0xffff) + (d.l & 0xffff) + (e.l & 0xffff);\r\n
var w1 = (a.l >>> 16) + (b.l >>> 16) + (c.l >>> 16) + (d.l >>> 16) + (e.l >>> 16) + (w0 >>> 16);\r\n
var w2 = (a.h & 0xffff) + (b.h & 0xffff) + (c.h & 0xffff) + (d.h & 0xffff) + (e.h & 0xffff) + (w1 >>> 16);\r\n
var w3 = (a.h >>> 16) + (b.h >>> 16) + (c.h >>> 16) + (d.h >>> 16) + (e.h >>> 16) + (w2 >>> 16);\r\n
dst.l = (w0 & 0xffff) | (w1 << 16);\r\n
dst.h = (w2 & 0xffff) | (w3 << 16);\r\n
}\r\n
]]></string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>size</string> </key>
<value> <int>16337</int> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
2.2 (30 June 2009)
- More algorithms - RIPEMD-160, SHA-256 and SHA-512 are now supported, based on contributed code. Support for MD4 has been dropped.
- Compressed versions of the scripts are available, processed by YUI Compressor. sha1-min.js is less than 3KB.
- Improved Unicode support. By default, the input string is now encoded as utf-8, before being hashed, which is what most people want. It is still possible to use utf-16, but the chrsz configuration variable is gone.
- Arbitrary output encoding. You can specify a string of characters to use for output encoding; the string length does not need to be a power of two. This is helpful for password makers, which want to use as much unpredictability as possible, in a short password.
- Bug fixes:
- The scripts now work correctly if immediate code is not executed, so they support some unusual platforms, including GreaseMonkey.
- rstr2binl now preinitialises the array with zeros, to work around bugs in some browsers.
- md5_vm_test now works if hex_case is set to 1
\ No newline at end of file
http://pajhome.org.uk/crypt/md5/scripts.html
\ No newline at end of file
1998 - 2012 Paul Johnston
\ No newline at end of file
Paj's javascript hash library.
Collection of a few widespread hash algorythms in small, standalone javascript files.
\ No newline at end of file
BSD
\ No newline at end of file
vincent
\ No newline at end of file
1
\ No newline at end of file
erp5_pajs
\ No newline at end of file
erp5_pajs
\ No newline at end of file
2.2
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment