How to use lo method in Best

Best JavaScript code snippet using best

sha512.js

Source:sha512.js Github

copy

Full Screen

1/**2 * Secure Hash Algorithm with a 1024-bit block size implementation.3 *4 * This includes: SHA-512, SHA-384, SHA-512/224, and SHA-512/256. For5 * SHA-256 (block size 512 bits), see sha256.js.6 *7 * See FIPS 180-4 for details.8 *9 * @author Dave Longley10 *11 * Copyright (c) 2014-2015 Digital Bazaar, Inc.12 */13var forge = require('./forge');14require('./md');15require('./util');16var sha512 = module.exports = forge.sha512 = forge.sha512 || {};17// SHA-51218forge.md.sha512 = forge.md.algorithms.sha512 = sha512;19// SHA-38420var sha384 = forge.sha384 = forge.sha512.sha384 = forge.sha512.sha384 || {};21sha384.create = function() {22 return sha512.create('SHA-384');23};24forge.md.sha384 = forge.md.algorithms.sha384 = sha384;25// SHA-512/25626forge.sha512.sha256 = forge.sha512.sha256 || {27 create: function() {28 return sha512.create('SHA-512/256');29 }30};31forge.md['sha512/256'] = forge.md.algorithms['sha512/256'] =32 forge.sha512.sha256;33// SHA-512/22434forge.sha512.sha224 = forge.sha512.sha224 || {35 create: function() {36 return sha512.create('SHA-512/224');37 }38};39forge.md['sha512/224'] = forge.md.algorithms['sha512/224'] =40 forge.sha512.sha224;41/**42 * Creates a SHA-2 message digest object.43 *44 * @param algorithm the algorithm to use (SHA-512, SHA-384, SHA-512/224,45 * SHA-512/256).46 *47 * @return a message digest object.48 */49sha512.create = function(algorithm) {50 // do initialization as necessary51 if(!_initialized) {52 _init();53 }54 if(typeof algorithm === 'undefined') {55 algorithm = 'SHA-512';56 }57 if(!(algorithm in _states)) {58 throw new Error('Invalid SHA-512 algorithm: ' + algorithm);59 }60 // SHA-512 state contains eight 64-bit integers (each as two 32-bit ints)61 var _state = _states[algorithm];62 var _h = null;63 // input buffer64 var _input = forge.util.createBuffer();65 // used for 64-bit word storage66 var _w = new Array(80);67 for(var wi = 0; wi < 80; ++wi) {68 _w[wi] = new Array(2);69 }70 // determine digest length by algorithm name (default)71 var digestLength = 64;72 switch(algorithm) {73 case 'SHA-384':74 digestLength = 48;75 break;76 case 'SHA-512/256':77 digestLength = 32;78 break;79 case 'SHA-512/224':80 digestLength = 28;81 break;82 }83 // message digest object84 var md = {85 // SHA-512 => sha51286 algorithm: algorithm.replace('-', '').toLowerCase(),87 blockLength: 128,88 digestLength: digestLength,89 // 56-bit length of message so far (does not including padding)90 messageLength: 0,91 // true message length92 fullMessageLength: null,93 // size of message length in bytes94 messageLengthSize: 1695 };96 /**97 * Starts the digest.98 *99 * @return this digest object.100 */101 md.start = function() {102 // up to 56-bit message length for convenience103 md.messageLength = 0;104 // full message length (set md.messageLength128 for backwards-compatibility)105 md.fullMessageLength = md.messageLength128 = [];106 var int32s = md.messageLengthSize / 4;107 for(var i = 0; i < int32s; ++i) {108 md.fullMessageLength.push(0);109 }110 _input = forge.util.createBuffer();111 _h = new Array(_state.length);112 for(var i = 0; i < _state.length; ++i) {113 _h[i] = _state[i].slice(0);114 }115 return md;116 };117 // start digest automatically for first time118 md.start();119 /**120 * Updates the digest with the given message input. The given input can121 * treated as raw input (no encoding will be applied) or an encoding of122 * 'utf8' maybe given to encode the input using UTF-8.123 *124 * @param msg the message input to update with.125 * @param encoding the encoding to use (default: 'raw', other: 'utf8').126 *127 * @return this digest object.128 */129 md.update = function(msg, encoding) {130 if(encoding === 'utf8') {131 msg = forge.util.encodeUtf8(msg);132 }133 // update message length134 var len = msg.length;135 md.messageLength += len;136 len = [(len / 0x100000000) >>> 0, len >>> 0];137 for(var i = md.fullMessageLength.length - 1; i >= 0; --i) {138 md.fullMessageLength[i] += len[1];139 len[1] = len[0] + ((md.fullMessageLength[i] / 0x100000000) >>> 0);140 md.fullMessageLength[i] = md.fullMessageLength[i] >>> 0;141 len[0] = ((len[1] / 0x100000000) >>> 0);142 }143 // add bytes to input buffer144 _input.putBytes(msg);145 // process bytes146 _update(_h, _w, _input);147 // compact input buffer every 2K or if empty148 if(_input.read > 2048 || _input.length() === 0) {149 _input.compact();150 }151 return md;152 };153 /**154 * Produces the digest.155 *156 * @return a byte buffer containing the digest value.157 */158 md.digest = function() {159 /* Note: Here we copy the remaining bytes in the input buffer and160 add the appropriate SHA-512 padding. Then we do the final update161 on a copy of the state so that if the user wants to get162 intermediate digests they can do so. */163 /* Determine the number of bytes that must be added to the message164 to ensure its length is congruent to 896 mod 1024. In other words,165 the data to be digested must be a multiple of 1024 bits (or 128 bytes).166 This data includes the message, some padding, and the length of the167 message. Since the length of the message will be encoded as 16 bytes (128168 bits), that means that the last segment of the data must have 112 bytes169 (896 bits) of message and padding. Therefore, the length of the message170 plus the padding must be congruent to 896 mod 1024 because171 1024 - 128 = 896.172 In order to fill up the message length it must be filled with173 padding that begins with 1 bit followed by all 0 bits. Padding174 must *always* be present, so if the message length is already175 congruent to 896 mod 1024, then 1024 padding bits must be added. */176 var finalBlock = forge.util.createBuffer();177 finalBlock.putBytes(_input.bytes());178 // compute remaining size to be digested (include message length size)179 var remaining = (180 md.fullMessageLength[md.fullMessageLength.length - 1] +181 md.messageLengthSize);182 // add padding for overflow blockSize - overflow183 // _padding starts with 1 byte with first bit is set (byte value 128), then184 // there may be up to (blockSize - 1) other pad bytes185 var overflow = remaining & (md.blockLength - 1);186 finalBlock.putBytes(_padding.substr(0, md.blockLength - overflow));187 // serialize message length in bits in big-endian order; since length188 // is stored in bytes we multiply by 8 and add carry from next int189 var next, carry;190 var bits = md.fullMessageLength[0] * 8;191 for(var i = 0; i < md.fullMessageLength.length - 1; ++i) {192 next = md.fullMessageLength[i + 1] * 8;193 carry = (next / 0x100000000) >>> 0;194 bits += carry;195 finalBlock.putInt32(bits >>> 0);196 bits = next >>> 0;197 }198 finalBlock.putInt32(bits);199 var h = new Array(_h.length);200 for(var i = 0; i < _h.length; ++i) {201 h[i] = _h[i].slice(0);202 }203 _update(h, _w, finalBlock);204 var rval = forge.util.createBuffer();205 var hlen;206 if(algorithm === 'SHA-512') {207 hlen = h.length;208 } else if(algorithm === 'SHA-384') {209 hlen = h.length - 2;210 } else {211 hlen = h.length - 4;212 }213 for(var i = 0; i < hlen; ++i) {214 rval.putInt32(h[i][0]);215 if(i !== hlen - 1 || algorithm !== 'SHA-512/224') {216 rval.putInt32(h[i][1]);217 }218 }219 return rval;220 };221 return md;222};223// sha-512 padding bytes not initialized yet224var _padding = null;225var _initialized = false;226// table of constants227var _k = null;228// initial hash states229var _states = null;230/**231 * Initializes the constant tables.232 */233function _init() {234 // create padding235 _padding = String.fromCharCode(128);236 _padding += forge.util.fillString(String.fromCharCode(0x00), 128);237 // create K table for SHA-512238 _k = [239 [0x428a2f98, 0xd728ae22], [0x71374491, 0x23ef65cd],240 [0xb5c0fbcf, 0xec4d3b2f], [0xe9b5dba5, 0x8189dbbc],241 [0x3956c25b, 0xf348b538], [0x59f111f1, 0xb605d019],242 [0x923f82a4, 0xaf194f9b], [0xab1c5ed5, 0xda6d8118],243 [0xd807aa98, 0xa3030242], [0x12835b01, 0x45706fbe],244 [0x243185be, 0x4ee4b28c], [0x550c7dc3, 0xd5ffb4e2],245 [0x72be5d74, 0xf27b896f], [0x80deb1fe, 0x3b1696b1],246 [0x9bdc06a7, 0x25c71235], [0xc19bf174, 0xcf692694],247 [0xe49b69c1, 0x9ef14ad2], [0xefbe4786, 0x384f25e3],248 [0x0fc19dc6, 0x8b8cd5b5], [0x240ca1cc, 0x77ac9c65],249 [0x2de92c6f, 0x592b0275], [0x4a7484aa, 0x6ea6e483],250 [0x5cb0a9dc, 0xbd41fbd4], [0x76f988da, 0x831153b5],251 [0x983e5152, 0xee66dfab], [0xa831c66d, 0x2db43210],252 [0xb00327c8, 0x98fb213f], [0xbf597fc7, 0xbeef0ee4],253 [0xc6e00bf3, 0x3da88fc2], [0xd5a79147, 0x930aa725],254 [0x06ca6351, 0xe003826f], [0x14292967, 0x0a0e6e70],255 [0x27b70a85, 0x46d22ffc], [0x2e1b2138, 0x5c26c926],256 [0x4d2c6dfc, 0x5ac42aed], [0x53380d13, 0x9d95b3df],257 [0x650a7354, 0x8baf63de], [0x766a0abb, 0x3c77b2a8],258 [0x81c2c92e, 0x47edaee6], [0x92722c85, 0x1482353b],259 [0xa2bfe8a1, 0x4cf10364], [0xa81a664b, 0xbc423001],260 [0xc24b8b70, 0xd0f89791], [0xc76c51a3, 0x0654be30],261 [0xd192e819, 0xd6ef5218], [0xd6990624, 0x5565a910],262 [0xf40e3585, 0x5771202a], [0x106aa070, 0x32bbd1b8],263 [0x19a4c116, 0xb8d2d0c8], [0x1e376c08, 0x5141ab53],264 [0x2748774c, 0xdf8eeb99], [0x34b0bcb5, 0xe19b48a8],265 [0x391c0cb3, 0xc5c95a63], [0x4ed8aa4a, 0xe3418acb],266 [0x5b9cca4f, 0x7763e373], [0x682e6ff3, 0xd6b2b8a3],267 [0x748f82ee, 0x5defb2fc], [0x78a5636f, 0x43172f60],268 [0x84c87814, 0xa1f0ab72], [0x8cc70208, 0x1a6439ec],269 [0x90befffa, 0x23631e28], [0xa4506ceb, 0xde82bde9],270 [0xbef9a3f7, 0xb2c67915], [0xc67178f2, 0xe372532b],271 [0xca273ece, 0xea26619c], [0xd186b8c7, 0x21c0c207],272 [0xeada7dd6, 0xcde0eb1e], [0xf57d4f7f, 0xee6ed178],273 [0x06f067aa, 0x72176fba], [0x0a637dc5, 0xa2c898a6],274 [0x113f9804, 0xbef90dae], [0x1b710b35, 0x131c471b],275 [0x28db77f5, 0x23047d84], [0x32caab7b, 0x40c72493],276 [0x3c9ebe0a, 0x15c9bebc], [0x431d67c4, 0x9c100d4c],277 [0x4cc5d4be, 0xcb3e42b6], [0x597f299c, 0xfc657e2a],278 [0x5fcb6fab, 0x3ad6faec], [0x6c44198c, 0x4a475817]279 ];280 // initial hash states281 _states = {};282 _states['SHA-512'] = [283 [0x6a09e667, 0xf3bcc908],284 [0xbb67ae85, 0x84caa73b],285 [0x3c6ef372, 0xfe94f82b],286 [0xa54ff53a, 0x5f1d36f1],287 [0x510e527f, 0xade682d1],288 [0x9b05688c, 0x2b3e6c1f],289 [0x1f83d9ab, 0xfb41bd6b],290 [0x5be0cd19, 0x137e2179]291 ];292 _states['SHA-384'] = [293 [0xcbbb9d5d, 0xc1059ed8],294 [0x629a292a, 0x367cd507],295 [0x9159015a, 0x3070dd17],296 [0x152fecd8, 0xf70e5939],297 [0x67332667, 0xffc00b31],298 [0x8eb44a87, 0x68581511],299 [0xdb0c2e0d, 0x64f98fa7],300 [0x47b5481d, 0xbefa4fa4]301 ];302 _states['SHA-512/256'] = [303 [0x22312194, 0xFC2BF72C],304 [0x9F555FA3, 0xC84C64C2],305 [0x2393B86B, 0x6F53B151],306 [0x96387719, 0x5940EABD],307 [0x96283EE2, 0xA88EFFE3],308 [0xBE5E1E25, 0x53863992],309 [0x2B0199FC, 0x2C85B8AA],310 [0x0EB72DDC, 0x81C52CA2]311 ];312 _states['SHA-512/224'] = [313 [0x8C3D37C8, 0x19544DA2],314 [0x73E19966, 0x89DCD4D6],315 [0x1DFAB7AE, 0x32FF9C82],316 [0x679DD514, 0x582F9FCF],317 [0x0F6D2B69, 0x7BD44DA8],318 [0x77E36F73, 0x04C48942],319 [0x3F9D85A8, 0x6A1D36C8],320 [0x1112E6AD, 0x91D692A1]321 ];322 // now initialized323 _initialized = true;324}325/**326 * Updates a SHA-512 state with the given byte buffer.327 *328 * @param s the SHA-512 state to update.329 * @param w the array to use to store words.330 * @param bytes the byte buffer to update with.331 */332function _update(s, w, bytes) {333 // consume 512 bit (128 byte) chunks334 var t1_hi, t1_lo;335 var t2_hi, t2_lo;336 var s0_hi, s0_lo;337 var s1_hi, s1_lo;338 var ch_hi, ch_lo;339 var maj_hi, maj_lo;340 var a_hi, a_lo;341 var b_hi, b_lo;342 var c_hi, c_lo;343 var d_hi, d_lo;344 var e_hi, e_lo;345 var f_hi, f_lo;346 var g_hi, g_lo;347 var h_hi, h_lo;348 var i, hi, lo, w2, w7, w15, w16;349 var len = bytes.length();350 while(len >= 128) {351 // the w array will be populated with sixteen 64-bit big-endian words352 // and then extended into 64 64-bit words according to SHA-512353 for(i = 0; i < 16; ++i) {354 w[i][0] = bytes.getInt32() >>> 0;355 w[i][1] = bytes.getInt32() >>> 0;356 }357 for(; i < 80; ++i) {358 // for word 2 words ago: ROTR 19(x) ^ ROTR 61(x) ^ SHR 6(x)359 w2 = w[i - 2];360 hi = w2[0];361 lo = w2[1];362 // high bits363 t1_hi = (364 ((hi >>> 19) | (lo << 13)) ^ // ROTR 19365 ((lo >>> 29) | (hi << 3)) ^ // ROTR 61/(swap + ROTR 29)366 (hi >>> 6)) >>> 0; // SHR 6367 // low bits368 t1_lo = (369 ((hi << 13) | (lo >>> 19)) ^ // ROTR 19370 ((lo << 3) | (hi >>> 29)) ^ // ROTR 61/(swap + ROTR 29)371 ((hi << 26) | (lo >>> 6))) >>> 0; // SHR 6372 // for word 15 words ago: ROTR 1(x) ^ ROTR 8(x) ^ SHR 7(x)373 w15 = w[i - 15];374 hi = w15[0];375 lo = w15[1];376 // high bits377 t2_hi = (378 ((hi >>> 1) | (lo << 31)) ^ // ROTR 1379 ((hi >>> 8) | (lo << 24)) ^ // ROTR 8380 (hi >>> 7)) >>> 0; // SHR 7381 // low bits382 t2_lo = (383 ((hi << 31) | (lo >>> 1)) ^ // ROTR 1384 ((hi << 24) | (lo >>> 8)) ^ // ROTR 8385 ((hi << 25) | (lo >>> 7))) >>> 0; // SHR 7386 // sum(t1, word 7 ago, t2, word 16 ago) modulo 2^64 (carry lo overflow)387 w7 = w[i - 7];388 w16 = w[i - 16];389 lo = (t1_lo + w7[1] + t2_lo + w16[1]);390 w[i][0] = (t1_hi + w7[0] + t2_hi + w16[0] +391 ((lo / 0x100000000) >>> 0)) >>> 0;392 w[i][1] = lo >>> 0;393 }394 // initialize hash value for this chunk395 a_hi = s[0][0];396 a_lo = s[0][1];397 b_hi = s[1][0];398 b_lo = s[1][1];399 c_hi = s[2][0];400 c_lo = s[2][1];401 d_hi = s[3][0];402 d_lo = s[3][1];403 e_hi = s[4][0];404 e_lo = s[4][1];405 f_hi = s[5][0];406 f_lo = s[5][1];407 g_hi = s[6][0];408 g_lo = s[6][1];409 h_hi = s[7][0];410 h_lo = s[7][1];411 // round function412 for(i = 0; i < 80; ++i) {413 // Sum1(e) = ROTR 14(e) ^ ROTR 18(e) ^ ROTR 41(e)414 s1_hi = (415 ((e_hi >>> 14) | (e_lo << 18)) ^ // ROTR 14416 ((e_hi >>> 18) | (e_lo << 14)) ^ // ROTR 18417 ((e_lo >>> 9) | (e_hi << 23))) >>> 0; // ROTR 41/(swap + ROTR 9)418 s1_lo = (419 ((e_hi << 18) | (e_lo >>> 14)) ^ // ROTR 14420 ((e_hi << 14) | (e_lo >>> 18)) ^ // ROTR 18421 ((e_lo << 23) | (e_hi >>> 9))) >>> 0; // ROTR 41/(swap + ROTR 9)422 // Ch(e, f, g) (optimized the same way as SHA-1)423 ch_hi = (g_hi ^ (e_hi & (f_hi ^ g_hi))) >>> 0;424 ch_lo = (g_lo ^ (e_lo & (f_lo ^ g_lo))) >>> 0;425 // Sum0(a) = ROTR 28(a) ^ ROTR 34(a) ^ ROTR 39(a)426 s0_hi = (427 ((a_hi >>> 28) | (a_lo << 4)) ^ // ROTR 28428 ((a_lo >>> 2) | (a_hi << 30)) ^ // ROTR 34/(swap + ROTR 2)429 ((a_lo >>> 7) | (a_hi << 25))) >>> 0; // ROTR 39/(swap + ROTR 7)430 s0_lo = (431 ((a_hi << 4) | (a_lo >>> 28)) ^ // ROTR 28432 ((a_lo << 30) | (a_hi >>> 2)) ^ // ROTR 34/(swap + ROTR 2)433 ((a_lo << 25) | (a_hi >>> 7))) >>> 0; // ROTR 39/(swap + ROTR 7)434 // Maj(a, b, c) (optimized the same way as SHA-1)435 maj_hi = ((a_hi & b_hi) | (c_hi & (a_hi ^ b_hi))) >>> 0;436 maj_lo = ((a_lo & b_lo) | (c_lo & (a_lo ^ b_lo))) >>> 0;437 // main algorithm438 // t1 = (h + s1 + ch + _k[i] + _w[i]) modulo 2^64 (carry lo overflow)439 lo = (h_lo + s1_lo + ch_lo + _k[i][1] + w[i][1]);440 t1_hi = (h_hi + s1_hi + ch_hi + _k[i][0] + w[i][0] +441 ((lo / 0x100000000) >>> 0)) >>> 0;442 t1_lo = lo >>> 0;443 // t2 = s0 + maj modulo 2^64 (carry lo overflow)444 lo = s0_lo + maj_lo;445 t2_hi = (s0_hi + maj_hi + ((lo / 0x100000000) >>> 0)) >>> 0;446 t2_lo = lo >>> 0;447 h_hi = g_hi;448 h_lo = g_lo;449 g_hi = f_hi;450 g_lo = f_lo;451 f_hi = e_hi;452 f_lo = e_lo;453 // e = (d + t1) modulo 2^64 (carry lo overflow)454 lo = d_lo + t1_lo;455 e_hi = (d_hi + t1_hi + ((lo / 0x100000000) >>> 0)) >>> 0;456 e_lo = lo >>> 0;457 d_hi = c_hi;458 d_lo = c_lo;459 c_hi = b_hi;460 c_lo = b_lo;461 b_hi = a_hi;462 b_lo = a_lo;463 // a = (t1 + t2) modulo 2^64 (carry lo overflow)464 lo = t1_lo + t2_lo;465 a_hi = (t1_hi + t2_hi + ((lo / 0x100000000) >>> 0)) >>> 0;466 a_lo = lo >>> 0;467 }468 // update hash state (additional modulo 2^64)469 lo = s[0][1] + a_lo;470 s[0][0] = (s[0][0] + a_hi + ((lo / 0x100000000) >>> 0)) >>> 0;471 s[0][1] = lo >>> 0;472 lo = s[1][1] + b_lo;473 s[1][0] = (s[1][0] + b_hi + ((lo / 0x100000000) >>> 0)) >>> 0;474 s[1][1] = lo >>> 0;475 lo = s[2][1] + c_lo;476 s[2][0] = (s[2][0] + c_hi + ((lo / 0x100000000) >>> 0)) >>> 0;477 s[2][1] = lo >>> 0;478 lo = s[3][1] + d_lo;479 s[3][0] = (s[3][0] + d_hi + ((lo / 0x100000000) >>> 0)) >>> 0;480 s[3][1] = lo >>> 0;481 lo = s[4][1] + e_lo;482 s[4][0] = (s[4][0] + e_hi + ((lo / 0x100000000) >>> 0)) >>> 0;483 s[4][1] = lo >>> 0;484 lo = s[5][1] + f_lo;485 s[5][0] = (s[5][0] + f_hi + ((lo / 0x100000000) >>> 0)) >>> 0;486 s[5][1] = lo >>> 0;487 lo = s[6][1] + g_lo;488 s[6][0] = (s[6][0] + g_hi + ((lo / 0x100000000) >>> 0)) >>> 0;489 s[6][1] = lo >>> 0;490 lo = s[7][1] + h_lo;491 s[7][0] = (s[7][0] + h_hi + ((lo / 0x100000000) >>> 0)) >>> 0;492 s[7][1] = lo >>> 0;493 len -= 128;494 }...

Full Screen

Full Screen

512.js

Source:512.js Github

copy

Full Screen

...84 for (var i = 0; i < 32; i++)85 W[i] = msg[start + i];86 for (; i < W.length; i += 2) {87 var c0_hi = g1_512_hi(W[i - 4], W[i - 3]); // i - 288 var c0_lo = g1_512_lo(W[i - 4], W[i - 3]);89 var c1_hi = W[i - 14]; // i - 790 var c1_lo = W[i - 13];91 var c2_hi = g0_512_hi(W[i - 30], W[i - 29]); // i - 1592 var c2_lo = g0_512_lo(W[i - 30], W[i - 29]);93 var c3_hi = W[i - 32]; // i - 1694 var c3_lo = W[i - 31];95 W[i] = sum64_4_hi(96 c0_hi, c0_lo,97 c1_hi, c1_lo,98 c2_hi, c2_lo,99 c3_hi, c3_lo);100 W[i + 1] = sum64_4_lo(101 c0_hi, c0_lo,102 c1_hi, c1_lo,103 c2_hi, c2_lo,104 c3_hi, c3_lo);105 }106};107SHA512.prototype._update = function _update(msg, start) {108 this._prepareBlock(msg, start);109 var W = this.W;110 var ah = this.h[0];111 var al = this.h[1];112 var bh = this.h[2];113 var bl = this.h[3];114 var ch = this.h[4];115 var cl = this.h[5];116 var dh = this.h[6];117 var dl = this.h[7];118 var eh = this.h[8];119 var el = this.h[9];120 var fh = this.h[10];121 var fl = this.h[11];122 var gh = this.h[12];123 var gl = this.h[13];124 var hh = this.h[14];125 var hl = this.h[15];126 assert(this.k.length === W.length);127 for (var i = 0; i < W.length; i += 2) {128 var c0_hi = hh;129 var c0_lo = hl;130 var c1_hi = s1_512_hi(eh, el);131 var c1_lo = s1_512_lo(eh, el);132 var c2_hi = ch64_hi(eh, el, fh, fl, gh, gl);133 var c2_lo = ch64_lo(eh, el, fh, fl, gh, gl);134 var c3_hi = this.k[i];135 var c3_lo = this.k[i + 1];136 var c4_hi = W[i];137 var c4_lo = W[i + 1];138 var T1_hi = sum64_5_hi(139 c0_hi, c0_lo,140 c1_hi, c1_lo,141 c2_hi, c2_lo,142 c3_hi, c3_lo,143 c4_hi, c4_lo);144 var T1_lo = sum64_5_lo(145 c0_hi, c0_lo,146 c1_hi, c1_lo,147 c2_hi, c2_lo,148 c3_hi, c3_lo,149 c4_hi, c4_lo);150 c0_hi = s0_512_hi(ah, al);151 c0_lo = s0_512_lo(ah, al);152 c1_hi = maj64_hi(ah, al, bh, bl, ch, cl);153 c1_lo = maj64_lo(ah, al, bh, bl, ch, cl);154 var T2_hi = sum64_hi(c0_hi, c0_lo, c1_hi, c1_lo);155 var T2_lo = sum64_lo(c0_hi, c0_lo, c1_hi, c1_lo);156 hh = gh;157 hl = gl;158 gh = fh;159 gl = fl;160 fh = eh;161 fl = el;162 eh = sum64_hi(dh, dl, T1_hi, T1_lo);163 el = sum64_lo(dl, dl, T1_hi, T1_lo);164 dh = ch;165 dl = cl;166 ch = bh;167 cl = bl;168 bh = ah;169 bl = al;170 ah = sum64_hi(T1_hi, T1_lo, T2_hi, T2_lo);171 al = sum64_lo(T1_hi, T1_lo, T2_hi, T2_lo);172 }173 sum64(this.h, 0, ah, al);174 sum64(this.h, 2, bh, bl);175 sum64(this.h, 4, ch, cl);176 sum64(this.h, 6, dh, dl);177 sum64(this.h, 8, eh, el);178 sum64(this.h, 10, fh, fl);179 sum64(this.h, 12, gh, gl);180 sum64(this.h, 14, hh, hl);181};182SHA512.prototype._digest = function digest(enc) {183 if (enc === 'hex')184 return utils.toHex32(this.h, 'big');185 else186 return utils.split32(this.h, 'big');187};188function ch64_hi(xh, xl, yh, yl, zh) {189 var r = (xh & yh) ^ ((~xh) & zh);190 if (r < 0)191 r += 0x100000000;192 return r;193}194function ch64_lo(xh, xl, yh, yl, zh, zl) {195 var r = (xl & yl) ^ ((~xl) & zl);196 if (r < 0)197 r += 0x100000000;198 return r;199}200function maj64_hi(xh, xl, yh, yl, zh) {201 var r = (xh & yh) ^ (xh & zh) ^ (yh & zh);202 if (r < 0)203 r += 0x100000000;204 return r;205}206function maj64_lo(xh, xl, yh, yl, zh, zl) {207 var r = (xl & yl) ^ (xl & zl) ^ (yl & zl);208 if (r < 0)209 r += 0x100000000;210 return r;211}212function s0_512_hi(xh, xl) {213 var c0_hi = rotr64_hi(xh, xl, 28);214 var c1_hi = rotr64_hi(xl, xh, 2); // 34215 var c2_hi = rotr64_hi(xl, xh, 7); // 39216 var r = c0_hi ^ c1_hi ^ c2_hi;217 if (r < 0)218 r += 0x100000000;219 return r;220}221function s0_512_lo(xh, xl) {222 var c0_lo = rotr64_lo(xh, xl, 28);223 var c1_lo = rotr64_lo(xl, xh, 2); // 34224 var c2_lo = rotr64_lo(xl, xh, 7); // 39225 var r = c0_lo ^ c1_lo ^ c2_lo;226 if (r < 0)227 r += 0x100000000;228 return r;229}230function s1_512_hi(xh, xl) {231 var c0_hi = rotr64_hi(xh, xl, 14);232 var c1_hi = rotr64_hi(xh, xl, 18);233 var c2_hi = rotr64_hi(xl, xh, 9); // 41234 var r = c0_hi ^ c1_hi ^ c2_hi;235 if (r < 0)236 r += 0x100000000;237 return r;238}239function s1_512_lo(xh, xl) {240 var c0_lo = rotr64_lo(xh, xl, 14);241 var c1_lo = rotr64_lo(xh, xl, 18);242 var c2_lo = rotr64_lo(xl, xh, 9); // 41243 var r = c0_lo ^ c1_lo ^ c2_lo;244 if (r < 0)245 r += 0x100000000;246 return r;247}248function g0_512_hi(xh, xl) {249 var c0_hi = rotr64_hi(xh, xl, 1);250 var c1_hi = rotr64_hi(xh, xl, 8);251 var c2_hi = shr64_hi(xh, xl, 7);252 var r = c0_hi ^ c1_hi ^ c2_hi;253 if (r < 0)254 r += 0x100000000;255 return r;256}257function g0_512_lo(xh, xl) {258 var c0_lo = rotr64_lo(xh, xl, 1);259 var c1_lo = rotr64_lo(xh, xl, 8);260 var c2_lo = shr64_lo(xh, xl, 7);261 var r = c0_lo ^ c1_lo ^ c2_lo;262 if (r < 0)263 r += 0x100000000;264 return r;265}266function g1_512_hi(xh, xl) {267 var c0_hi = rotr64_hi(xh, xl, 19);268 var c1_hi = rotr64_hi(xl, xh, 29); // 61269 var c2_hi = shr64_hi(xh, xl, 6);270 var r = c0_hi ^ c1_hi ^ c2_hi;271 if (r < 0)272 r += 0x100000000;273 return r;274}275function g1_512_lo(xh, xl) {276 var c0_lo = rotr64_lo(xh, xl, 19);277 var c1_lo = rotr64_lo(xl, xh, 29); // 61278 var c2_lo = shr64_lo(xh, xl, 6);279 var r = c0_lo ^ c1_lo ^ c2_lo;280 if (r < 0)281 r += 0x100000000;282 return r;...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Best automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful