github.com/jincm/wesharechain@v0.0.0-20210122032815-1537409ce26a/app/lib/crypto1/sha256/sha256.js (about) 1 /*! 2 * Crypto-JS v1.1.0 3 * http://code.google.com/p/crypto-js/ 4 * Copyright (c) 2009, Jeff Mott. All rights reserved. 5 * http://code.google.com/p/crypto-js/wiki/License 6 */ 7 (function(){ 8 9 // Shortcut 10 var util = Crypto.util; 11 12 // Constants 13 var K = [ 0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5, 14 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5, 15 0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3, 16 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174, 17 0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC, 18 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA, 19 0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7, 20 0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967, 21 0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13, 22 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85, 23 0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3, 24 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070, 25 0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5, 26 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3, 27 0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208, 28 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2 ]; 29 30 // Public API 31 var SHA256 = Crypto.SHA256 = function (message, options) { 32 var digestbytes = util.wordsToBytes(SHA256._sha256(message)); 33 return options && options.asBytes ? digestbytes : 34 options && options.asString ? util.bytesToString(digestbytes) : 35 util.bytesToHex(digestbytes); 36 }; 37 38 // The core 39 SHA256._sha256 = function (message) { 40 41 var m = util.stringToWords(message), 42 l = message.length * 8, 43 H = [ 0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A, 44 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19 ], 45 w = [], 46 a, b, c, d, e, f, g, h, i, j, 47 t1, t2; 48 49 // Padding 50 m[l >> 5] |= 0x80 << (24 - l % 32); 51 m[((l + 64 >> 9) << 4) + 15] = l; 52 53 for (var i = 0; i < m.length; i += 16) { 54 55 a = H[0]; 56 b = H[1]; 57 c = H[2]; 58 d = H[3]; 59 e = H[4]; 60 f = H[5]; 61 g = H[6]; 62 h = H[7]; 63 64 for (var j = 0; j < 64; j++) { 65 66 if (j < 16) w[j] = m[j + i]; 67 else { 68 69 var gamma0x = w[j - 15], 70 gamma1x = w[j - 2], 71 gamma0 = ((gamma0x << 25) | (gamma0x >>> 7)) ^ 72 ((gamma0x << 14) | (gamma0x >>> 18)) ^ 73 (gamma0x >>> 3), 74 gamma1 = ((gamma1x << 15) | (gamma1x >>> 17)) ^ 75 ((gamma1x << 13) | (gamma1x >>> 19)) ^ 76 (gamma1x >>> 10); 77 78 w[j] = gamma0 + (w[j - 7] >>> 0) + 79 gamma1 + (w[j - 16] >>> 0); 80 81 } 82 83 var ch = e & f ^ ~e & g, 84 maj = a & b ^ a & c ^ b & c, 85 sigma0 = ((a << 30) | (a >>> 2)) ^ 86 ((a << 19) | (a >>> 13)) ^ 87 ((a << 10) | (a >>> 22)), 88 sigma1 = ((e << 26) | (e >>> 6)) ^ 89 ((e << 21) | (e >>> 11)) ^ 90 ((e << 7) | (e >>> 25)); 91 92 93 t1 = (h >>> 0) + sigma1 + ch + (K[j]) + (w[j] >>> 0); 94 t2 = sigma0 + maj; 95 96 h = g; 97 g = f; 98 f = e; 99 e = d + t1; 100 d = c; 101 c = b; 102 b = a; 103 a = t1 + t2; 104 105 } 106 107 H[0] += a; 108 H[1] += b; 109 H[2] += c; 110 H[3] += d; 111 H[4] += e; 112 H[5] += f; 113 H[6] += g; 114 H[7] += h; 115 116 } 117 118 return H; 119 120 }; 121 122 // Package private blocksize 123 SHA256._blocksize = 16; 124 125 })();