You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

561 lines
17 KiB

4 years ago
  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. For
  5. * SHA-256 (block size 512 bits), see sha256.js.
  6. *
  7. * See FIPS 180-4 for details.
  8. *
  9. * @author Dave Longley
  10. *
  11. * Copyright (c) 2014-2015 Digital Bazaar, Inc.
  12. */
  13. var forge = require('./forge');
  14. require('./md');
  15. require('./util');
  16. var sha512 = module.exports = forge.sha512 = forge.sha512 || {};
  17. // SHA-512
  18. forge.md.sha512 = forge.md.algorithms.sha512 = sha512;
  19. // SHA-384
  20. var sha384 = forge.sha384 = forge.sha512.sha384 = forge.sha512.sha384 || {};
  21. sha384.create = function() {
  22. return sha512.create('SHA-384');
  23. };
  24. forge.md.sha384 = forge.md.algorithms.sha384 = sha384;
  25. // SHA-512/256
  26. forge.sha512.sha256 = forge.sha512.sha256 || {
  27. create: function() {
  28. return sha512.create('SHA-512/256');
  29. }
  30. };
  31. forge.md['sha512/256'] = forge.md.algorithms['sha512/256'] =
  32. forge.sha512.sha256;
  33. // SHA-512/224
  34. forge.sha512.sha224 = forge.sha512.sha224 || {
  35. create: function() {
  36. return sha512.create('SHA-512/224');
  37. }
  38. };
  39. forge.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. */
  49. sha512.create = function(algorithm) {
  50. // do initialization as necessary
  51. 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 buffer
  64. var _input = forge.util.createBuffer();
  65. // used for 64-bit word storage
  66. 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 object
  84. var md = {
  85. // SHA-512 => sha512
  86. 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 length
  92. fullMessageLength: null,
  93. // size of message length in bytes
  94. messageLengthSize: 16
  95. };
  96. /**
  97. * Starts the digest.
  98. *
  99. * @return this digest object.
  100. */
  101. md.start = function() {
  102. // up to 56-bit message length for convenience
  103. 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 time
  118. md.start();
  119. /**
  120. * Updates the digest with the given message input. The given input can
  121. * treated as raw input (no encoding will be applied) or an encoding of
  122. * '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 length
  134. 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 buffer
  144. _input.putBytes(msg);
  145. // process bytes
  146. _update(_h, _w, _input);
  147. // compact input buffer every 2K or if empty
  148. 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 and
  160. add the appropriate SHA-512 padding. Then we do the final update
  161. on a copy of the state so that if the user wants to get
  162. intermediate digests they can do so. */
  163. /* Determine the number of bytes that must be added to the message
  164. 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 the
  167. message. Since the length of the message will be encoded as 16 bytes (128
  168. bits), that means that the last segment of the data must have 112 bytes
  169. (896 bits) of message and padding. Therefore, the length of the message
  170. plus the padding must be congruent to 896 mod 1024 because
  171. 1024 - 128 = 896.
  172. In order to fill up the message length it must be filled with
  173. padding that begins with 1 bit followed by all 0 bits. Padding
  174. must *always* be present, so if the message length is already
  175. 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 - overflow
  183. // _padding starts with 1 byte with first bit is set (byte value 128), then
  184. // there may be up to (blockSize - 1) other pad bytes
  185. 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 length
  188. // is stored in bytes we multiply by 8 and add carry from next int
  189. 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 yet
  224. var _padding = null;
  225. var _initialized = false;
  226. // table of constants
  227. var _k = null;
  228. // initial hash states
  229. var _states = null;
  230. /**
  231. * Initializes the constant tables.
  232. */
  233. function _init() {
  234. // create padding
  235. _padding = String.fromCharCode(128);
  236. _padding += forge.util.fillString(String.fromCharCode(0x00), 128);
  237. // create K table for SHA-512
  238. _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 states
  281. _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 initialized
  323. _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. */
  332. function _update(s, w, bytes) {
  333. // consume 512 bit (128 byte) chunks
  334. 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 words
  352. // and then extended into 64 64-bit words according to SHA-512
  353. 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 bits
  363. t1_hi = (
  364. ((hi >>> 19) | (lo << 13)) ^ // ROTR 19
  365. ((lo >>> 29) | (hi << 3)) ^ // ROTR 61/(swap + ROTR 29)
  366. (hi >>> 6)) >>> 0; // SHR 6
  367. // low bits
  368. t1_lo = (
  369. ((hi << 13) | (lo >>> 19)) ^ // ROTR 19
  370. ((lo << 3) | (hi >>> 29)) ^ // ROTR 61/(swap + ROTR 29)
  371. ((hi << 26) | (lo >>> 6))) >>> 0; // SHR 6
  372. // 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 bits
  377. t2_hi = (
  378. ((hi >>> 1) | (lo << 31)) ^ // ROTR 1
  379. ((hi >>> 8) | (lo << 24)) ^ // ROTR 8
  380. (hi >>> 7)) >>> 0; // SHR 7
  381. // low bits
  382. t2_lo = (
  383. ((hi << 31) | (lo >>> 1)) ^ // ROTR 1
  384. ((hi << 24) | (lo >>> 8)) ^ // ROTR 8
  385. ((hi << 25) | (lo >>> 7))) >>> 0; // SHR 7
  386. // 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 chunk
  395. 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 function
  412. 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 14
  416. ((e_hi >>> 18) | (e_lo << 14)) ^ // ROTR 18
  417. ((e_lo >>> 9) | (e_hi << 23))) >>> 0; // ROTR 41/(swap + ROTR 9)
  418. s1_lo = (
  419. ((e_hi << 18) | (e_lo >>> 14)) ^ // ROTR 14
  420. ((e_hi << 14) | (e_lo >>> 18)) ^ // ROTR 18
  421. ((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 28
  428. ((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 28
  432. ((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 algorithm
  438. // 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. }
  495. }