build/pgo/js-input/crypto-sha1.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/build/pgo/js-input/crypto-sha1.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,274 @@
     1.4 +<!DOCTYPE html>
     1.5 +<head>
     1.6 +<!--
     1.7 + Copyright (C) 2007 Apple Inc.  All rights reserved.
     1.8 +
     1.9 + Redistribution and use in source and binary forms, with or without
    1.10 + modification, are permitted provided that the following conditions
    1.11 + are met:
    1.12 + 1. Redistributions of source code must retain the above copyright
    1.13 +    notice, this list of conditions and the following disclaimer.
    1.14 + 2. Redistributions in binary form must reproduce the above copyright
    1.15 +    notice, this list of conditions and the following disclaimer in the
    1.16 +    documentation and/or other materials provided with the distribution.
    1.17 +
    1.18 + THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
    1.19 + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    1.20 + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    1.21 + PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
    1.22 + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    1.23 + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    1.24 + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
    1.25 + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
    1.26 + OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    1.27 + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    1.28 + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
    1.29 +-->
    1.30 +
    1.31 +<title>SunSpider crypto-sha1</title>
    1.32 +
    1.33 +</head>
    1.34 +
    1.35 +<body>
    1.36 +<h3>crypto-sha1</h3>
    1.37 +<div id="console">
    1.38 +</div>
    1.39 +
    1.40 +<script>
    1.41 +
    1.42 +var _sunSpiderStartDate = new Date();
    1.43 +
    1.44 +/*
    1.45 + * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined
    1.46 + * in FIPS PUB 180-1
    1.47 + * Version 2.1a Copyright Paul Johnston 2000 - 2002.
    1.48 + * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
    1.49 + * Distributed under the BSD License
    1.50 + * See http://pajhome.org.uk/crypt/md5 for details.
    1.51 + */
    1.52 +
    1.53 +/*
    1.54 + * Configurable variables. You may need to tweak these to be compatible with
    1.55 + * the server-side, but the defaults work in most cases.
    1.56 + */
    1.57 +var hexcase = 0;  /* hex output format. 0 - lowercase; 1 - uppercase        */
    1.58 +var b64pad  = ""; /* base-64 pad character. "=" for strict RFC compliance   */
    1.59 +var chrsz   = 8;  /* bits per input character. 8 - ASCII; 16 - Unicode      */
    1.60 +
    1.61 +/*
    1.62 + * These are the functions you'll usually want to call
    1.63 + * They take string arguments and return either hex or base-64 encoded strings
    1.64 + */
    1.65 +function hex_sha1(s){return binb2hex(core_sha1(str2binb(s),s.length * chrsz));}
    1.66 +function b64_sha1(s){return binb2b64(core_sha1(str2binb(s),s.length * chrsz));}
    1.67 +function str_sha1(s){return binb2str(core_sha1(str2binb(s),s.length * chrsz));}
    1.68 +function hex_hmac_sha1(key, data){ return binb2hex(core_hmac_sha1(key, data));}
    1.69 +function b64_hmac_sha1(key, data){ return binb2b64(core_hmac_sha1(key, data));}
    1.70 +function str_hmac_sha1(key, data){ return binb2str(core_hmac_sha1(key, data));}
    1.71 +
    1.72 +/*
    1.73 + * Perform a simple self-test to see if the VM is working
    1.74 + */
    1.75 +function sha1_vm_test()
    1.76 +{
    1.77 +  return hex_sha1("abc") == "a9993e364706816aba3e25717850c26c9cd0d89d";
    1.78 +}
    1.79 +
    1.80 +/*
    1.81 + * Calculate the SHA-1 of an array of big-endian words, and a bit length
    1.82 + */
    1.83 +function core_sha1(x, len)
    1.84 +{
    1.85 +  /* append padding */
    1.86 +  x[len >> 5] |= 0x80 << (24 - len % 32);
    1.87 +  x[((len + 64 >> 9) << 4) + 15] = len;
    1.88 +
    1.89 +  var w = Array(80);
    1.90 +  var a =  1732584193;
    1.91 +  var b = -271733879;
    1.92 +  var c = -1732584194;
    1.93 +  var d =  271733878;
    1.94 +  var e = -1009589776;
    1.95 +
    1.96 +  for(var i = 0; i < x.length; i += 16)
    1.97 +  {
    1.98 +    var olda = a;
    1.99 +    var oldb = b;
   1.100 +    var oldc = c;
   1.101 +    var oldd = d;
   1.102 +    var olde = e;
   1.103 +
   1.104 +    for(var j = 0; j < 80; j++)
   1.105 +    {
   1.106 +      if(j < 16) w[j] = x[i + j];
   1.107 +      else w[j] = rol(w[j-3] ^ w[j-8] ^ w[j-14] ^ w[j-16], 1);
   1.108 +      var t = safe_add(safe_add(rol(a, 5), sha1_ft(j, b, c, d)),
   1.109 +                       safe_add(safe_add(e, w[j]), sha1_kt(j)));
   1.110 +      e = d;
   1.111 +      d = c;
   1.112 +      c = rol(b, 30);
   1.113 +      b = a;
   1.114 +      a = t;
   1.115 +    }
   1.116 +
   1.117 +    a = safe_add(a, olda);
   1.118 +    b = safe_add(b, oldb);
   1.119 +    c = safe_add(c, oldc);
   1.120 +    d = safe_add(d, oldd);
   1.121 +    e = safe_add(e, olde);
   1.122 +  }
   1.123 +  return Array(a, b, c, d, e);
   1.124 +
   1.125 +}
   1.126 +
   1.127 +/*
   1.128 + * Perform the appropriate triplet combination function for the current
   1.129 + * iteration
   1.130 + */
   1.131 +function sha1_ft(t, b, c, d)
   1.132 +{
   1.133 +  if(t < 20) return (b & c) | ((~b) & d);
   1.134 +  if(t < 40) return b ^ c ^ d;
   1.135 +  if(t < 60) return (b & c) | (b & d) | (c & d);
   1.136 +  return b ^ c ^ d;
   1.137 +}
   1.138 +
   1.139 +/*
   1.140 + * Determine the appropriate additive constant for the current iteration
   1.141 + */
   1.142 +function sha1_kt(t)
   1.143 +{
   1.144 +  return (t < 20) ?  1518500249 : (t < 40) ?  1859775393 :
   1.145 +         (t < 60) ? -1894007588 : -899497514;
   1.146 +}
   1.147 +
   1.148 +/*
   1.149 + * Calculate the HMAC-SHA1 of a key and some data
   1.150 + */
   1.151 +function core_hmac_sha1(key, data)
   1.152 +{
   1.153 +  var bkey = str2binb(key);
   1.154 +  if(bkey.length > 16) bkey = core_sha1(bkey, key.length * chrsz);
   1.155 +
   1.156 +  var ipad = Array(16), opad = Array(16);
   1.157 +  for(var i = 0; i < 16; i++)
   1.158 +  {
   1.159 +    ipad[i] = bkey[i] ^ 0x36363636;
   1.160 +    opad[i] = bkey[i] ^ 0x5C5C5C5C;
   1.161 +  }
   1.162 +
   1.163 +  var hash = core_sha1(ipad.concat(str2binb(data)), 512 + data.length * chrsz);
   1.164 +  return core_sha1(opad.concat(hash), 512 + 160);
   1.165 +}
   1.166 +
   1.167 +/*
   1.168 + * Add integers, wrapping at 2^32. This uses 16-bit operations internally
   1.169 + * to work around bugs in some JS interpreters.
   1.170 + */
   1.171 +function safe_add(x, y)
   1.172 +{
   1.173 +  var lsw = (x & 0xFFFF) + (y & 0xFFFF);
   1.174 +  var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
   1.175 +  return (msw << 16) | (lsw & 0xFFFF);
   1.176 +}
   1.177 +
   1.178 +/*
   1.179 + * Bitwise rotate a 32-bit number to the left.
   1.180 + */
   1.181 +function rol(num, cnt)
   1.182 +{
   1.183 +  return (num << cnt) | (num >>> (32 - cnt));
   1.184 +}
   1.185 +
   1.186 +/*
   1.187 + * Convert an 8-bit or 16-bit string to an array of big-endian words
   1.188 + * In 8-bit function, characters >255 have their hi-byte silently ignored.
   1.189 + */
   1.190 +function str2binb(str)
   1.191 +{
   1.192 +  var bin = Array();
   1.193 +  var mask = (1 << chrsz) - 1;
   1.194 +  for(var i = 0; i < str.length * chrsz; i += chrsz)
   1.195 +    bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (32 - chrsz - i%32);
   1.196 +  return bin;
   1.197 +}
   1.198 +
   1.199 +/*
   1.200 + * Convert an array of big-endian words to a string
   1.201 + */
   1.202 +function binb2str(bin)
   1.203 +{
   1.204 +  var str = "";
   1.205 +  var mask = (1 << chrsz) - 1;
   1.206 +  for(var i = 0; i < bin.length * 32; i += chrsz)
   1.207 +    str += String.fromCharCode((bin[i>>5] >>> (32 - chrsz - i%32)) & mask);
   1.208 +  return str;
   1.209 +}
   1.210 +
   1.211 +/*
   1.212 + * Convert an array of big-endian words to a hex string.
   1.213 + */
   1.214 +function binb2hex(binarray)
   1.215 +{
   1.216 +  var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
   1.217 +  var str = "";
   1.218 +  for(var i = 0; i < binarray.length * 4; i++)
   1.219 +  {
   1.220 +    str += hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8+4)) & 0xF) +
   1.221 +           hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8  )) & 0xF);
   1.222 +  }
   1.223 +  return str;
   1.224 +}
   1.225 +
   1.226 +/*
   1.227 + * Convert an array of big-endian words to a base-64 string
   1.228 + */
   1.229 +function binb2b64(binarray)
   1.230 +{
   1.231 +  var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
   1.232 +  var str = "";
   1.233 +  for(var i = 0; i < binarray.length * 4; i += 3)
   1.234 +  {
   1.235 +    var triplet = (((binarray[i   >> 2] >> 8 * (3 -  i   %4)) & 0xFF) << 16)
   1.236 +                | (((binarray[i+1 >> 2] >> 8 * (3 - (i+1)%4)) & 0xFF) << 8 )
   1.237 +                |  ((binarray[i+2 >> 2] >> 8 * (3 - (i+2)%4)) & 0xFF);
   1.238 +    for(var j = 0; j < 4; j++)
   1.239 +    {
   1.240 +      if(i * 8 + j * 6 > binarray.length * 32) str += b64pad;
   1.241 +      else str += tab.charAt((triplet >> 6*(3-j)) & 0x3F);
   1.242 +    }
   1.243 +  }
   1.244 +  return str;
   1.245 +}
   1.246 +
   1.247 +
   1.248 +var plainText = "Two households, both alike in dignity,\n\
   1.249 +In fair Verona, where we lay our scene,\n\
   1.250 +From ancient grudge break to new mutiny,\n\
   1.251 +Where civil blood makes civil hands unclean.\n\
   1.252 +From forth the fatal loins of these two foes\n\
   1.253 +A pair of star-cross'd lovers take their life;\n\
   1.254 +Whole misadventured piteous overthrows\n\
   1.255 +Do with their death bury their parents' strife.\n\
   1.256 +The fearful passage of their death-mark'd love,\n\
   1.257 +And the continuance of their parents' rage,\n\
   1.258 +Which, but their children's end, nought could remove,\n\
   1.259 +Is now the two hours' traffic of our stage;\n\
   1.260 +The which if you with patient ears attend,\n\
   1.261 +What here shall miss, our toil shall strive to mend.";
   1.262 +
   1.263 +for (var i = 0; i <4; i++) {
   1.264 +    plainText += plainText;
   1.265 +}
   1.266 +
   1.267 +var sha1Output = hex_sha1(plainText);
   1.268 +
   1.269 +
   1.270 +var _sunSpiderInterval = new Date() - _sunSpiderStartDate;
   1.271 +
   1.272 +document.getElementById("console").innerHTML = _sunSpiderInterval;
   1.273 +</script>
   1.274 +
   1.275 +
   1.276 +</body>
   1.277 +</html>

mercurial