Bug 460926 A11y hierachy is broken on Ubuntu 8.10 (GNOME 2.24), r=Evan.Yan sr=roc
[wine-gecko.git] / testing / performance / talos / page_load_test / sunspider / crypto-sha1.html
blobb914525b58a706b51fbbb116967f4e432ceee374
1 <!DOCTYPE html>
2 <head>
3 <!--
4 Copyright (C) 2007 Apple Inc. All rights reserved.
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
8 are met:
9 1. Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
11 2. Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in the
13 documentation and/or other materials provided with the distribution.
15 THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
16 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
19 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 -->
28 <title>SunSpider crypto-sha1</title>
29 <link rel="stylesheet" href="sunspider.css"></link>
30 </head>
32 <body>
33 <h3>crypto-sha1</h3>
34 <div id="console">
35 </div>
36 <script>
40 * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined
41 * in FIPS PUB 180-1
42 * Version 2.1a Copyright Paul Johnston 2000 - 2002.
43 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
44 * Distributed under the BSD License
45 * See http://pajhome.org.uk/crypt/md5 for details.
49 * Configurable variables. You may need to tweak these to be compatible with
50 * the server-side, but the defaults work in most cases.
52 var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */
53 var b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance */
54 var chrsz = 8; /* bits per input character. 8 - ASCII; 16 - Unicode */
57 * These are the functions you'll usually want to call
58 * They take string arguments and return either hex or base-64 encoded strings
60 function hex_sha1(s){return binb2hex(core_sha1(str2binb(s),s.length * chrsz));}
61 function b64_sha1(s){return binb2b64(core_sha1(str2binb(s),s.length * chrsz));}
62 function str_sha1(s){return binb2str(core_sha1(str2binb(s),s.length * chrsz));}
63 function hex_hmac_sha1(key, data){ return binb2hex(core_hmac_sha1(key, data));}
64 function b64_hmac_sha1(key, data){ return binb2b64(core_hmac_sha1(key, data));}
65 function str_hmac_sha1(key, data){ return binb2str(core_hmac_sha1(key, data));}
68 * Perform a simple self-test to see if the VM is working
70 function sha1_vm_test()
72 return hex_sha1("abc") == "a9993e364706816aba3e25717850c26c9cd0d89d";
76 * Calculate the SHA-1 of an array of big-endian words, and a bit length
78 function core_sha1(x, len)
80 /* append padding */
81 x[len >> 5] |= 0x80 << (24 - len % 32);
82 x[((len + 64 >> 9) << 4) + 15] = len;
84 var w = Array(80);
85 var a = 1732584193;
86 var b = -271733879;
87 var c = -1732584194;
88 var d = 271733878;
89 var e = -1009589776;
91 for(var i = 0; i < x.length; i += 16)
93 var olda = a;
94 var oldb = b;
95 var oldc = c;
96 var oldd = d;
97 var olde = e;
99 for(var j = 0; j < 80; j++)
101 if(j < 16) w[j] = x[i + j];
102 else w[j] = rol(w[j-3] ^ w[j-8] ^ w[j-14] ^ w[j-16], 1);
103 var t = safe_add(safe_add(rol(a, 5), sha1_ft(j, b, c, d)),
104 safe_add(safe_add(e, w[j]), sha1_kt(j)));
105 e = d;
106 d = c;
107 c = rol(b, 30);
108 b = a;
109 a = t;
112 a = safe_add(a, olda);
113 b = safe_add(b, oldb);
114 c = safe_add(c, oldc);
115 d = safe_add(d, oldd);
116 e = safe_add(e, olde);
118 return Array(a, b, c, d, e);
123 * Perform the appropriate triplet combination function for the current
124 * iteration
126 function sha1_ft(t, b, c, d)
128 if(t < 20) return (b & c) | ((~b) & d);
129 if(t < 40) return b ^ c ^ d;
130 if(t < 60) return (b & c) | (b & d) | (c & d);
131 return b ^ c ^ d;
135 * Determine the appropriate additive constant for the current iteration
137 function sha1_kt(t)
139 return (t < 20) ? 1518500249 : (t < 40) ? 1859775393 :
140 (t < 60) ? -1894007588 : -899497514;
144 * Calculate the HMAC-SHA1 of a key and some data
146 function core_hmac_sha1(key, data)
148 var bkey = str2binb(key);
149 if(bkey.length > 16) bkey = core_sha1(bkey, key.length * chrsz);
151 var ipad = Array(16), opad = Array(16);
152 for(var i = 0; i < 16; i++)
154 ipad[i] = bkey[i] ^ 0x36363636;
155 opad[i] = bkey[i] ^ 0x5C5C5C5C;
158 var hash = core_sha1(ipad.concat(str2binb(data)), 512 + data.length * chrsz);
159 return core_sha1(opad.concat(hash), 512 + 160);
163 * Add integers, wrapping at 2^32. This uses 16-bit operations internally
164 * to work around bugs in some JS interpreters.
166 function safe_add(x, y)
168 var lsw = (x & 0xFFFF) + (y & 0xFFFF);
169 var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
170 return (msw << 16) | (lsw & 0xFFFF);
174 * Bitwise rotate a 32-bit number to the left.
176 function rol(num, cnt)
178 return (num << cnt) | (num >>> (32 - cnt));
182 * Convert an 8-bit or 16-bit string to an array of big-endian words
183 * In 8-bit function, characters >255 have their hi-byte silently ignored.
185 function str2binb(str)
187 var bin = Array();
188 var mask = (1 << chrsz) - 1;
189 for(var i = 0; i < str.length * chrsz; i += chrsz)
190 bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (32 - chrsz - i%32);
191 return bin;
195 * Convert an array of big-endian words to a string
197 function binb2str(bin)
199 var str = "";
200 var mask = (1 << chrsz) - 1;
201 for(var i = 0; i < bin.length * 32; i += chrsz)
202 str += String.fromCharCode((bin[i>>5] >>> (32 - chrsz - i%32)) & mask);
203 return str;
207 * Convert an array of big-endian words to a hex string.
209 function binb2hex(binarray)
211 var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
212 var str = "";
213 for(var i = 0; i < binarray.length * 4; i++)
215 str += hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8+4)) & 0xF) +
216 hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8 )) & 0xF);
218 return str;
222 * Convert an array of big-endian words to a base-64 string
224 function binb2b64(binarray)
226 var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
227 var str = "";
228 for(var i = 0; i < binarray.length * 4; i += 3)
230 var triplet = (((binarray[i >> 2] >> 8 * (3 - i %4)) & 0xFF) << 16)
231 | (((binarray[i+1 >> 2] >> 8 * (3 - (i+1)%4)) & 0xFF) << 8 )
232 | ((binarray[i+2 >> 2] >> 8 * (3 - (i+2)%4)) & 0xFF);
233 for(var j = 0; j < 4; j++)
235 if(i * 8 + j * 6 > binarray.length * 32) str += b64pad;
236 else str += tab.charAt((triplet >> 6*(3-j)) & 0x3F);
239 return str;
243 var plainText = "Two households, both alike in dignity,\n\
244 In fair Verona, where we lay our scene,\n\
245 From ancient grudge break to new mutiny,\n\
246 Where civil blood makes civil hands unclean.\n\
247 From forth the fatal loins of these two foes\n\
248 A pair of star-cross'd lovers take their life;\n\
249 Whole misadventured piteous overthrows\n\
250 Do with their death bury their parents' strife.\n\
251 The fearful passage of their death-mark'd love,\n\
252 And the continuance of their parents' rage,\n\
253 Which, but their children's end, nought could remove,\n\
254 Is now the two hours' traffic of our stage;\n\
255 The which if you with patient ears attend,\n\
256 What here shall miss, our toil shall strive to mend.";
258 for (var i = 0; i <4; i++) {
259 plainText += plainText;
262 var sha1Output = hex_sha1(plainText);
266 </script>
269 </body>
270 </html>