(message, firstLoop, secondLoop, chunksLoop)
| 283 | } |
| 284 | |
| 285 | function shaStepped(message, firstLoop, secondLoop, chunksLoop) { |
| 286 | let h0 = 0x6a09e667; let h1 = 0xbb67ae85; let h2 = 0x3c6ef372; let h3 = 0xa54ff53a; let h4 = 0x510e527f; let h5 = 0x9b05688c; let h6 = 0x1f83d9ab; let h7 = 0x5be0cd19; |
| 287 | let s0, s1, S1, S0, a, b, c, d, e, f, g, h, ch, temp1, temp2, maj = 0; |
| 288 | let w = []; |
| 289 | let hsBefore = []; |
| 290 | let lettersBefore = []; |
| 291 | let input = padding(message, inputBase); |
| 292 | let chunks = chunkString(input); |
| 293 | |
| 294 | setChunksCount(chunks.length); |
| 295 | |
| 296 | for(let n = 0; n < chunksLoop; n++) { |
| 297 | let chunk = chunks[n]; |
| 298 | |
| 299 | w = new Array(64).fill('0'.padStart(32, '0')); |
| 300 | |
| 301 | chunkString(chunk, 32).forEach((messageWord, i) => { |
| 302 | w[i] = parseInt(messageWord, 2) |
| 303 | }); |
| 304 | |
| 305 | let firstLoopForCurrentChunk = n < chunksLoop - 1 ? 63 : firstLoop; |
| 306 | for(let i = 16; i <= firstLoopForCurrentChunk; i++) { //63 |
| 307 | s0 = (rotateRight(w[i-15], 7) ^ rotateRight(w[i-15], 18) ^ (w[i-15] >>> 3)) >>> 0; |
| 308 | s1 = (rotateRight(w[i-2], 17) ^ rotateRight(w[i-2], 19) ^ (w[i-2] >>> 10)) >>> 0; |
| 309 | w[i] = (w[i-16] + s0 + w[i-7] + s1)%(2**32) |
| 310 | } |
| 311 | |
| 312 | a = h0; b = h1; c = h2; d = h3; e = h4; f = h5; g = h6; h = h7; |
| 313 | |
| 314 | let secondLoopForCurrentChunk = n < chunksLoop - 1 ? 63 : secondLoop; |
| 315 | for(let i = 0; i <= secondLoopForCurrentChunk; i++) { // 63 |
| 316 | S1 = (rotateRight(e, 6) ^ rotateRight(e, 11) ^ rotateRight(e, 25)) >>> 0; |
| 317 | ch = (e & f) ^ ((~e) & g) >>> 0; |
| 318 | temp1 = (h + S1 + ch + k[i] + w[i])%(2**32) >>> 0; |
| 319 | S0 = (rotateRight(a, 2) ^ rotateRight(a, 13) ^ rotateRight(a, 22)) >>> 0; |
| 320 | maj = ((a & b) ^ (a & c) ^ (b & c)) >>> 0; |
| 321 | temp2 = (S0 + maj)%(2**32) >>> 0; |
| 322 | |
| 323 | lettersBefore = [a, b, c, d, e, f, g, h]; |
| 324 | |
| 325 | h = g >>> 0; |
| 326 | g = f >>> 0; |
| 327 | f = e >>> 0; |
| 328 | e = (d + temp1)%(2**32); |
| 329 | d = c >>> 0; |
| 330 | c = b >>> 0; |
| 331 | b = a >>> 0; |
| 332 | a = (temp1 + temp2)%(2**32); |
| 333 | } |
| 334 | |
| 335 | hsBefore = [h0, h1, h2, h3, h4, h5, h6, h7]; |
| 336 | |
| 337 | h0 = (h0 + a)%(2**32); |
| 338 | h1 = (h1 + b)%(2**32); |
| 339 | h2 = (h2 + c)%(2**32); |
| 340 | h3 = (h3 + d)%(2**32); |
| 341 | h4 = (h4 + e)%(2**32); |
| 342 | h5 = (h5 + f)%(2**32); |
no test coverage detected