1/** 2 * [js-sha256]{@link https://github.com/emn178/js-sha256} 3 * 4 * @version 0.11.0 5 * @author Chen, Yi-Cyuan [[email protected]] 6 * @copyright Chen, Yi-Cyuan 2014-2024 7 * @license MIT 8 */ 9/*jslint bitwise: true */ 10(function () { 11 'use strict'; 12 13 var ERROR = 'input is invalid type'; 14 var WINDOW = typeof window === 'object'; 15 var root = WINDOW ? window : {}; 16 if (root.JS_SHA256_NO_WINDOW) { 17 WINDOW = false; 18 } 19 var WEB_WORKER = !WINDOW && typeof self === 'object'; 20 var NODE_JS = !root.JS_SHA256_NO_NODE_JS && typeof process === 'object' && process.versions && process.versions.node; 21 if (NODE_JS) { 22 root = global; 23 } else if (WEB_WORKER) { 24 root = self; 25 } 26 var COMMON_JS = !root.JS_SHA256_NO_COMMON_JS && typeof module === 'object' && module.exports; 27 var AMD = typeof define === 'function' && define.amd; 28 var ARRAY_BUFFER = !root.JS_SHA256_NO_ARRAY_BUFFER && typeof ArrayBuffer !== 'undefined'; 29 var HEX_CHARS = '0123456789abcdef'.split(''); 30 var EXTRA = [-2147483648, 8388608, 32768, 128]; 31 var SHIFT = [24, 16, 8, 0]; 32 var K = [ 33 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 34 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 35 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 36 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 37 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 38 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 39 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, 40 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 41 ]; 42 var OUTPUT_TYPES = ['hex', 'array', 'digest', 'arrayBuffer']; 43 44 var blocks = []; 45 46 if (root.JS_SHA256_NO_NODE_JS || !Array.isArray) { 47 Array.isArray = function (obj) { 48 return Object.prototype.toString.call(obj) === '[object Array]'; 49 }; 50 } 51 52 if (ARRAY_BUFFER && (root.JS_SHA256_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView)) { 53 ArrayBuffer.isView = function (obj) { 54 return typeof obj === 'object' && obj.buffer && obj.buffer.constructor === ArrayBuffer; 55 }; 56 } 57 58 var createOutputMethod = function (outputType, is224) { 59 return function (message) { 60 return new Sha256(is224, true).update(message)[outputType](); 61 }; 62 }; 63 64 var createMethod = function (is224) { 65 var method = createOutputMethod('hex', is224); 66 if (NODE_JS) { 67 method = nodeWrap(method, is224); 68 } 69 method.create = function () { 70 return new Sha256(is224); 71 }; 72 method.update = function (message) { 73 return method.create().update(message); 74 }; 75 for (var i = 0; i < OUTPUT_TYPES.length; ++i) { 76 var type = OUTPUT_TYPES[i]; 77 method[type] = createOutputMethod(type, is224); 78 } 79 return method; 80 }; 81 82 var nodeWrap = function (method, is224) { 83 var crypto = require('crypto') 84 var Buffer = require('buffer').Buffer; 85 var algorithm = is224 ? 'sha224' : 'sha256'; 86 var bufferFrom; 87 if (Buffer.from && !root.JS_SHA256_NO_BUFFER_FROM) { 88 bufferFrom = Buffer.from; 89 } else { 90 bufferFrom = function (message) { 91 return new Buffer(message); 92 }; 93 } 94 var nodeMethod = function (message) { 95 if (typeof message === 'string') { 96 return crypto.createHash(algorithm).update(message, 'utf8').digest('hex'); 97 } else { 98 if (message === null || message === undefined) { 99 throw new Error(ERROR); 100 } else if (message.constructor === ArrayBuffer) { 101 message = new Uint8Array(message); 102 } 103 } 104 if (Array.isArray(message) || ArrayBuffer.isView(message) || 105 message.constructor === Buffer) { 106 return crypto.createHash(algorithm).update(bufferFrom(message)).digest('hex'); 107 } else { 108 return method(message); 109 } 110 }; 111 return nodeMethod; 112 }; 113 114 var createHmacOutputMethod = function (outputType, is224) { 115 return function (key, message) { 116 return new HmacSha256(key, is224, true).update(message)[outputType](); 117 }; 118 }; 119 120 var createHmacMethod = function (is224) { 121 var method = createHmacOutputMethod('hex', is224); 122 method.create = function (key) { 123 return new HmacSha256(key, is224); 124 }; 125 method.update = function (key, message) { 126 return method.create(key).update(message); 127 }; 128 for (var i = 0; i < OUTPUT_TYPES.length; ++i) { 129 var type = OUTPUT_TYPES[i]; 130 method[type] = createHmacOutputMethod(type, is224); 131 } 132 return method; 133 }; 134 135 function Sha256(is224, sharedMemory) { 136 if (sharedMemory) { 137 blocks[0] = blocks[16] = blocks[1] = blocks[2] = blocks[3]
vendor: 13,172 bytes, lines 137-441
137= 138 blocks[4] = blocks[5] = blocks[6] = blocks[7] = 139 blocks[8] = blocks[9] = blocks[10] = blocks[11] = 140 blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0; 141 this.blocks = blocks; 142 } else { 143 this.blocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; 144 } 145 146 if (is224) { 147 this.h0 = 0xc1059ed8; 148 this.h1 = 0x367cd507; 149 this.h2 = 0x3070dd17; 150 this.h3 = 0xf70e5939; 151 this.h4 = 0xffc00b31; 152 this.h5 = 0x68581511; 153 this.h6 = 0x64f98fa7; 154 this.h7 = 0xbefa4fa4; 155 } else { // 256 156 this.h0 = 0x6a09e667; 157 this.h1 = 0xbb67ae85; 158 this.h2 = 0x3c6ef372; 159 this.h3 = 0xa54ff53a; 160 this.h4 = 0x510e527f; 161 this.h5 = 0x9b05688c; 162 this.h6 = 0x1f83d9ab; 163 this.h7 = 0x5be0cd19; 164 } 165 166 this.block = this.start = this.bytes = this.hBytes = 0; 167 this.finalized = this.hashed = false; 168 this.first = true; 169 this.is224 = is224; 170 } 171 172 Sha256.prototype.update = function (message) { 173 if (this.finalized) { 174 return; 175 } 176 var notString, type = typeof message; 177 if (type !== 'string') { 178 if (type === 'object') { 179 if (message === null) { 180 throw new Error(ERROR); 181 } else if (ARRAY_BUFFER && message.constructor === ArrayBuffer) { 182 message = new Uint8Array(message); 183 } else if (!Array.isArray(message)) { 184 if (!ARRAY_BUFFER || !ArrayBuffer.isView(message)) { 185 throw new Error(ERROR); 186 } 187 } 188 } else { 189 throw new Error(ERROR); 190 } 191 notString = true; 192 } 193 var code, index = 0, i, length = message.length, blocks = this.blocks; 194 while (index < length) { 195 if (this.hashed) { 196 this.hashed = false; 197 blocks[0] = this.block; 198 this.block = blocks[16] = blocks[1] = blocks[2] = blocks[3] = 199 blocks[4] = blocks[5] = blocks[6] = blocks[7] = 200 blocks[8] = blocks[9] = blocks[10] = blocks[11] = 201 blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0; 202 } 203 204 if (notString) { 205 for (i = this.start; index < length && i < 64; ++index) { 206 blocks[i >>> 2] |= message[index] << SHIFT[i++ & 3]; 207 } 208 } else { 209 for (i = this.start; index < length && i < 64; ++index) { 210 code = message.charCodeAt(index); 211 if (code < 0x80) { 212 blocks[i >>> 2] |= code << SHIFT[i++ & 3]; 213 } else if (code < 0x800) { 214 blocks[i >>> 2] |= (0xc0 | (code >>> 6)) << SHIFT[i++ & 3]; 215 blocks[i >>> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3]; 216 } else if (code < 0xd800 || code >= 0xe000) { 217 blocks[i >>> 2] |= (0xe0 | (code >>> 12)) << SHIFT[i++ & 3]; 218 blocks[i >>> 2] |= (0x80 | ((code >>> 6) & 0x3f)) << SHIFT[i++ & 3]; 219 blocks[i >>> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3]; 220 } else { 221 code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff)); 222 blocks[i >>> 2] |= (0xf0 | (code >>> 18)) << SHIFT[i++ & 3]; 223 blocks[i >>> 2] |= (0x80 | ((code >>> 12) & 0x3f)) << SHIFT[i++ & 3]; 224 blocks[i >>> 2] |= (0x80 | ((code >>> 6) & 0x3f)) << SHIFT[i++ & 3]; 225 blocks[i >>> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3]; 226 } 227 } 228 } 229 230 this.lastByteIndex = i; 231 this.bytes += i - this.start; 232 if (i >= 64) { 233 this.block = blocks[16]; 234 this.start = i - 64; 235 this.hash(); 236 this.hashed = true; 237 } else { 238 this.start = i; 239 } 240 } 241 if (this.bytes > 4294967295) { 242 this.hBytes += this.bytes / 4294967296 << 0; 243 this.bytes = this.bytes % 4294967296; 244 } 245 return this; 246 }; 247 248 Sha256.prototype.finalize = function () { 249 if (this.finalized) { 250 return; 251 } 252 this.finalized = true; 253 var blocks = this.blocks, i = this.lastByteIndex; 254 blocks[16] = this.block; 255 blocks[i >>> 2] |= EXTRA[i & 3]; 256 this.block = blocks[16]; 257 if (i >= 56) { 258 if (!this.hashed) { 259 this.hash(); 260 } 261 blocks[0] = this.block; 262 blocks[16] = blocks[1] = blocks[2] = blocks[3] = 263 blocks[4] = blocks[5] = blocks[6] = blocks[7] = 264 blocks[8] = blocks[9] = blocks[10] = blocks[11] = 265 blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0; 266 } 267 blocks[14] = this.hBytes << 3 | this.bytes >>> 29; 268 blocks[15] = this.bytes << 3; 269 this.hash(); 270 }; 271 272 Sha256.prototype.hash = function () { 273 var a = this.h0, b = this.h1, c = this.h2, d = this.h3, e = this.h4, f = this.h5, g = this.h6, 274 h = this.h7, blocks = this.blocks, j, s0, s1, maj, t1, t2, ch, ab, da, cd, bc; 275 276 for (j = 16; j < 64; ++j) { 277 // rightrotate 278 t1 = blocks[j - 15]; 279 s0 = ((t1 >>> 7) | (t1 << 25)) ^ ((t1 >>> 18) | (t1 << 14)) ^ (t1 >>> 3); 280 t1 = blocks[j - 2]; 281 s1 = ((t1 >>> 17) | (t1 << 15)) ^ ((t1 >>> 19) | (t1 << 13)) ^ (t1 >>> 10); 282 blocks[j] = blocks[j - 16] + s0 + blocks[j - 7] + s1 << 0; 283 } 284 285 bc = b & c; 286 for (j = 0; j < 64; j += 4) { 287 if (this.first) { 288 if (this.is224) { 289 ab = 300032; 290 t1 = blocks[0] - 1413257819; 291 h = t1 - 150054599 << 0; 292 d = t1 + 24177077 << 0; 293 } else { 294 ab = 704751109; 295 t1 = blocks[0] - 210244248; 296 h = t1 - 1521486534 << 0; 297 d = t1 + 143694565 << 0; 298 } 299 this.first = false; 300 } else { 301 s0 = ((a >>> 2) | (a << 30)) ^ ((a >>> 13) | (a << 19)) ^ ((a >>> 22) | (a << 10)); 302 s1 = ((e >>> 6) | (e << 26)) ^ ((e >>> 11) | (e << 21)) ^ ((e >>> 25) | (e << 7)); 303 ab = a & b; 304 maj = ab ^ (a & c) ^ bc; 305 ch = (e & f) ^ (~e & g); 306 t1 = h + s1 + ch + K[j] + blocks[j]; 307 t2 = s0 + maj; 308 h = d + t1 << 0; 309 d = t1 + t2 << 0; 310 } 311 s0 = ((d >>> 2) | (d << 30)) ^ ((d >>> 13) | (d << 19)) ^ ((d >>> 22) | (d << 10)); 312 s1 = ((h >>> 6) | (h << 26)) ^ ((h >>> 11) | (h << 21)) ^ ((h >>> 25) | (h << 7)); 313 da = d & a; 314 maj = da ^ (d & b) ^ ab; 315 ch = (h & e) ^ (~h & f); 316 t1 = g + s1 + ch + K[j + 1] + blocks[j + 1]; 317 t2 = s0 + maj; 318 g = c + t1 << 0; 319 c = t1 + t2 << 0; 320 s0 = ((c >>> 2) | (c << 30)) ^ ((c >>> 13) | (c << 19)) ^ ((c >>> 22) | (c << 10)); 321 s1 = ((g >>> 6) | (g << 26)) ^ ((g >>> 11) | (g << 21)) ^ ((g >>> 25) | (g << 7)); 322 cd = c & d; 323 maj = cd ^ (c & a) ^ da; 324 ch = (g & h) ^ (~g & e); 325 t1 = f + s1 + ch + K[j + 2] + blocks[j + 2]; 326 t2 = s0 + maj; 327 f = b + t1 << 0; 328 b = t1 + t2 << 0; 329 s0 = ((b >>> 2) | (b << 30)) ^ ((b >>> 13) | (b << 19)) ^ ((b >>> 22) | (b << 10)); 330 s1 = ((f >>> 6) | (f << 26)) ^ ((f >>> 11) | (f << 21)) ^ ((f >>> 25) | (f << 7)); 331 bc = b & c; 332 maj = bc ^ (b & d) ^ cd; 333 ch = (f & g) ^ (~f & h); 334 t1 = e + s1 + ch + K[j + 3] + blocks[j + 3]; 335 t2 = s0 + maj; 336 e = a + t1 << 0; 337 a = t1 + t2 << 0; 338 this.chromeBugWorkAround = true; 339 } 340 341 this.h0 = this.h0 + a << 0; 342 this.h1 = this.h1 + b << 0; 343 this.h2 = this.h2 + c << 0; 344 this.h3 = this.h3 + d << 0; 345 this.h4 = this.h4 + e << 0; 346 this.h5 = this.h5 + f << 0; 347 this.h6 = this.h6 + g << 0; 348 this.h7 = this.h7 + h << 0; 349 }; 350 351 Sha256.prototype.hex = function () { 352 this.finalize(); 353 354 var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3, h4 = this.h4, h5 = this.h5, 355 h6 = this.h6, h7 = this.h7; 356 357 var hex = HEX_CHARS[(h0 >>> 28) & 0x0F] + HEX_CHARS[(h0 >>> 24) & 0x0F] + 358 HEX_CHARS[(h0 >>> 20) & 0x0F] + HEX_CHARS[(h0 >>> 16) & 0x0F] + 359 HEX_CHARS[(h0 >>> 12) & 0x0F] + HEX_CHARS[(h0 >>> 8) & 0x0F] + 360 HEX_CHARS[(h0 >>> 4) & 0x0F] + HEX_CHARS[h0 & 0x0F] + 361 HEX_CHARS[(h1 >>> 28) & 0x0F] + HEX_CHARS[(h1 >>> 24) & 0x0F] + 362 HEX_CHARS[(h1 >>> 20) & 0x0F] + HEX_CHARS[(h1 >>> 16) & 0x0F] + 363 HEX_CHARS[(h1 >>> 12) & 0x0F] + HEX_CHARS[(h1 >>> 8) & 0x0F] + 364 HEX_CHARS[(h1 >>> 4) & 0x0F] + HEX_CHARS[h1 & 0x0F] + 365 HEX_CHARS[(h2 >>> 28) & 0x0F] + HEX_CHARS[(h2 >>> 24) & 0x0F] + 366 HEX_CHARS[(h2 >>> 20) & 0x0F] + HEX_CHARS[(h2 >>> 16) & 0x0F] + 367 HEX_CHARS[(h2 >>> 12) & 0x0F] + HEX_CHARS[(h2 >>> 8) & 0x0F] + 368 HEX_CHARS[(h2 >>> 4) & 0x0F] + HEX_CHARS[h2 & 0x0F] + 369 HEX_CHARS[(h3 >>> 28) & 0x0F] + HEX_CHARS[(h3 >>> 24) & 0x0F] + 370 HEX_CHARS[(h3 >>> 20) & 0x0F] + HEX_CHARS[(h3 >>> 16) & 0x0F] + 371 HEX_CHARS[(h3 >>> 12) & 0x0F] + HEX_CHARS[(h3 >>> 8) & 0x0F] + 372 HEX_CHARS[(h3 >>> 4) & 0x0F] + HEX_CHARS[h3 & 0x0F] + 373 HEX_CHARS[(h4 >>> 28) & 0x0F] + HEX_CHARS[(h4 >>> 24) & 0x0F] + 374 HEX_CHARS[(h4 >>> 20) & 0x0F] + HEX_CHARS[(h4 >>> 16) & 0x0F] + 375 HEX_CHARS[(h4 >>> 12) & 0x0F] + HEX_CHARS[(h4 >>> 8) & 0x0F] + 376 HEX_CHARS[(h4 >>> 4) & 0x0F] + HEX_CHARS[h4 & 0x0F] + 377 HEX_CHARS[(h5 >>> 28) & 0x0F] + HEX_CHARS[(h5 >>> 24) & 0x0F] + 378 HEX_CHARS[(h5 >>> 20) & 0x0F] + HEX_CHARS[(h5 >>> 16) & 0x0F] + 379 HEX_CHARS[(h5 >>> 12) & 0x0F] + HEX_CHARS[(h5 >>> 8) & 0x0F] + 380 HEX_CHARS[(h5 >>> 4) & 0x0F] + HEX_CHARS[h5 & 0x0F] + 381 HEX_CHARS[(h6 >>> 28) & 0x0F] + HEX_CHARS[(h6 >>> 24) & 0x0F] + 382 HEX_CHARS[(h6 >>> 20) & 0x0F] + HEX_CHARS[(h6 >>> 16) & 0x0F] + 383 HEX_CHARS[(h6 >>> 12) & 0x0F] + HEX_CHARS[(h6 >>> 8) & 0x0F] + 384 HEX_CHARS[(h6 >>> 4) & 0x0F] + HEX_CHARS[h6 & 0x0F]; 385 if (!this.is224) { 386 hex += HEX_CHARS[(h7 >>> 28) & 0x0F] + HEX_CHARS[(h7 >>> 24) & 0x0F] + 387 HEX_CHARS[(h7 >>> 20) & 0x0F] + HEX_CHARS[(h7 >>> 16) & 0x0F] + 388 HEX_CHARS[(h7 >>> 12) & 0x0F] + HEX_CHARS[(h7 >>> 8) & 0x0F] + 389 HEX_CHARS[(h7 >>> 4) & 0x0F] + HEX_CHARS[h7 & 0x0F]; 390 } 391 return hex; 392 }; 393 394 Sha256.prototype.toString = Sha256.prototype.hex; 395 396 Sha256.prototype.digest = function () { 397 this.finalize(); 398 399 var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3, h4 = this.h4, h5 = this.h5, 400 h6 = this.h6, h7 = this.h7; 401 402 var arr = [ 403 (h0 >>> 24) & 0xFF, (h0 >>> 16) & 0xFF, (h0 >>> 8) & 0xFF, h0 & 0xFF, 404 (h1 >>> 24) & 0xFF, (h1 >>> 16) & 0xFF, (h1 >>> 8) & 0xFF, h1 & 0xFF, 405 (h2 >>> 24) & 0xFF, (h2 >>> 16) & 0xFF, (h2 >>> 8) & 0xFF, h2 & 0xFF, 406 (h3 >>> 24) & 0xFF, (h3 >>> 16) & 0xFF, (h3 >>> 8) & 0xFF, h3 & 0xFF, 407 (h4 >>> 24) & 0xFF, (h4 >>> 16) & 0xFF, (h4 >>> 8) & 0xFF, h4 & 0xFF, 408 (h5 >>> 24) & 0xFF, (h5 >>> 16) & 0xFF, (h5 >>> 8) & 0xFF, h5 & 0xFF, 409 (h6 >>> 24) & 0xFF, (h6 >>> 16) & 0xFF, (h6 >>> 8) & 0xFF, h6 & 0xFF 410 ]; 411 if (!this.is224) { 412 arr.push((h7 >>> 24) & 0xFF, (h7 >>> 16) & 0xFF, (h7 >>> 8) & 0xFF, h7 & 0xFF); 413 } 414 return arr; 415 }; 416 417 Sha256.prototype.array = Sha256.prototype.digest; 418 419 Sha256.prototype.arrayBuffer = function () { 420 this.finalize(); 421 422 var buffer = new ArrayBuffer(this.is224 ? 28 : 32); 423 var dataView = new DataView(buffer); 424 dataView.setUint32(0, this.h0); 425 dataView.setUint32(4, this.h1); 426 dataView.setUint32(8, this.h2); 427 dataView.setUint32(12, this.h3); 428 dataView.setUint32(16, this.h4); 429 dataView.setUint32(20, this.h5); 430 dataView.setUint32(24, this.h6); 431 if (!this.is224) { 432 dataView.setUint32(28, this.h7); 433 } 434 return buffer; 435 }; 436 437 function HmacSha256(key, is224, sharedMemory) { 438 var i, type = typeof key; 439 if (type === 'string') { 440 var bytes = [], length = key.length, index = 0, code; 441 for (i = 0; i < length; ++i) {
442 code = key.charCodeAt(i); 443 if (code < 0x80) { 444 bytes[index++] = code; 445 } else if (code < 0x800) { 446 bytes[index++] = (0xc0 | (code >>> 6)); 447 bytes[index++] = (0x80 | (code & 0x3f)); 448 } else if (code < 0xd800 || code >= 0xe000) { 449 bytes[index++] = (0xe0 | (code >>> 12)); 450 bytes[index++] = (0x80 | ((code >>> 6) & 0x3f)); 451 bytes[index++] = (0x80 | (code & 0x3f)); 452 } else { 453 code = 0x10000 + (((code & 0x3ff) << 10) | (key.charCodeAt(++i) & 0x3ff)); 454 bytes[index++] = (0xf0 | (code >>> 18)); 455 bytes[index++] = (0x80 | ((code >>> 12) & 0x3f)); 456 bytes[index++] = (0x80 | ((code >>> 6) & 0x3f)); 457 bytes[index++] = (0x80 | (code & 0x3f)); 458 } 459 } 460 key = bytes; 461 } else { 462 if (type === 'object') { 463 if (key === null) { 464 throw new Error(ERROR); 465 } else if (ARRAY_BUFFER && key.constructor === ArrayBuffer) { 466 key = new Uint8Array(key); 467 } else if (!Array.isArray(key)) { 468 if (!ARRAY_BUFFER || !ArrayBuffer.isView(key)) { 469 throw new Error(ERROR); 470 } 471 } 472 } else { 473 throw new Error(ERROR); 474 } 475 } 476 477 if (key.length > 64) { 478 key = (new Sha256(is224, true)).update(key).array(); 479 } 480 481 var oKeyPad = [], iKeyPad = []; 482 for (i = 0; i < 64; ++i) { 483 var b = key[i] || 0; 484 oKeyPad[i] = 0x5c ^ b; 485 iKeyPad[i] = 0x36 ^ b; 486 } 487 488 Sha256.call(this, is224, sharedMemory); 489 490 this.update(iKeyPad); 491 this.oKeyPad = oKeyPad; 492 this.inner = true; 493 this.sharedMemory = sharedMemory; 494 } 495 HmacSha256.prototype = new Sha256(); 496 497 HmacSha256.prototype.finalize = function () { 498 Sha256.prototype.finalize.call(this); 499 if (this.inner) { 500 this.inner = false; 501 var innerHash = this.array(); 502 Sha256.call(this, this.is224, this.sharedMemory); 503 this.update(this.oKeyPad); 504 this.update(innerHash); 505 Sha256.prototype.finalize.call(this); 506 } 507 }; 508 509 var exports = createMethod(); 510 exports.sha256 = exports; 511 exports.sha224 = createMethod(true); 512 exports.sha256.hmac = createHmacMethod(); 513 exports.sha224.hmac = createHmacMethod(true); 514 515 if (COMMON_JS) { 516 module.exports = exports; 517 } else { 518 root.sha256 = exports.sha256; 519 root.sha224 = exports.sha224; 520 if (AMD) { 521 define(function () { 522 return exports; 523 }); 524 } 525 } 526})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.