MCPcopy Index your code
hub / github.com/dmarman/sha256algorithm / shaStepped

Function shaStepped

src/App.js:285–349  ·  view source on GitHub ↗
(message, firstLoop, secondLoop, chunksLoop)

Source from the content-addressed store, hash-verified

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);

Callers 7

onClockFunction · 0.85
onInputChangeFunction · 0.85
onClockFastFunction · 0.85
onClockBackFastFunction · 0.85
onClockBackFunction · 0.85
onClockFinishFunction · 0.85
onClockInitFunction · 0.85

Calls 3

paddingFunction · 0.90
chunkStringFunction · 0.90
rotateRightFunction · 0.90

Tested by

no test coverage detected