blake1.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. /**
  2. * Blake1 legacy hash function, one of SHA3 proposals.
  3. * Rarely used. Check out blake2 or blake3 instead.
  4. * https://www.aumasson.jp/blake/blake.pdf
  5. *
  6. * In the best case, there are 0 allocations.
  7. *
  8. * Differences from blake2:
  9. *
  10. * - BE instead of LE
  11. * - Paddings, similar to MD5, RIPEMD, SHA1, SHA2, but:
  12. * - length flag is located before actual length
  13. * - padding block is compressed differently (no lengths)
  14. * Instead of msg[sigma[k]], we have `msg[sigma[k]] ^ constants[sigma[k-1]]`
  15. * (-1 for g1, g2 without -1)
  16. * - Salt is XOR-ed into constants instead of state
  17. * - Salt is XOR-ed with output in `compress`
  18. * - Additional rows (+64 bytes) in SIGMA for new rounds
  19. * - Different round count:
  20. * - 14 / 10 rounds in blake256 / blake2s
  21. * - 16 / 12 rounds in blake512 / blake2b
  22. * - blake512: G1b: rotr 24 -> 25, G2b: rotr 63 -> 11
  23. * @module
  24. */
  25. import { BSIGMA, G1s, G2s } from "./_blake.js";
  26. import { setBigUint64, SHA224_IV, SHA256_IV, SHA384_IV, SHA512_IV } from "./_md.js";
  27. import * as u64 from "./_u64.js";
  28. // prettier-ignore
  29. import { abytes, aexists, aoutput, clean, createOptHasher, createView, Hash, toBytes, } from "./utils.js";
  30. // Empty zero-filled salt
  31. const EMPTY_SALT = /* @__PURE__ */ new Uint32Array(8);
  32. class BLAKE1 extends Hash {
  33. constructor(blockLen, outputLen, lengthFlag, counterLen, saltLen, constants, opts = {}) {
  34. super();
  35. this.finished = false;
  36. this.length = 0;
  37. this.pos = 0;
  38. this.destroyed = false;
  39. const { salt } = opts;
  40. this.blockLen = blockLen;
  41. this.outputLen = outputLen;
  42. this.lengthFlag = lengthFlag;
  43. this.counterLen = counterLen;
  44. this.buffer = new Uint8Array(blockLen);
  45. this.view = createView(this.buffer);
  46. if (salt) {
  47. let slt = salt;
  48. slt = toBytes(slt);
  49. abytes(slt);
  50. if (slt.length !== 4 * saltLen)
  51. throw new Error('wrong salt length');
  52. const salt32 = (this.salt = new Uint32Array(saltLen));
  53. const sv = createView(slt);
  54. this.constants = constants.slice();
  55. for (let i = 0, offset = 0; i < salt32.length; i++, offset += 4) {
  56. salt32[i] = sv.getUint32(offset, false);
  57. this.constants[i] ^= salt32[i];
  58. }
  59. }
  60. else {
  61. this.salt = EMPTY_SALT;
  62. this.constants = constants;
  63. }
  64. }
  65. update(data) {
  66. aexists(this);
  67. data = toBytes(data);
  68. abytes(data);
  69. // From _md, but update length before each compress
  70. const { view, buffer, blockLen } = this;
  71. const len = data.length;
  72. let dataView;
  73. for (let pos = 0; pos < len;) {
  74. const take = Math.min(blockLen - this.pos, len - pos);
  75. // Fast path: we have at least one block in input, cast it to view and process
  76. if (take === blockLen) {
  77. if (!dataView)
  78. dataView = createView(data);
  79. for (; blockLen <= len - pos; pos += blockLen) {
  80. this.length += blockLen;
  81. this.compress(dataView, pos);
  82. }
  83. continue;
  84. }
  85. buffer.set(data.subarray(pos, pos + take), this.pos);
  86. this.pos += take;
  87. pos += take;
  88. if (this.pos === blockLen) {
  89. this.length += blockLen;
  90. this.compress(view, 0, true);
  91. this.pos = 0;
  92. }
  93. }
  94. return this;
  95. }
  96. destroy() {
  97. this.destroyed = true;
  98. if (this.salt !== EMPTY_SALT) {
  99. clean(this.salt, this.constants);
  100. }
  101. }
  102. _cloneInto(to) {
  103. to || (to = new this.constructor());
  104. to.set(...this.get());
  105. const { buffer, length, finished, destroyed, constants, salt, pos } = this;
  106. to.buffer.set(buffer);
  107. to.constants = constants.slice();
  108. to.destroyed = destroyed;
  109. to.finished = finished;
  110. to.length = length;
  111. to.pos = pos;
  112. to.salt = salt.slice();
  113. return to;
  114. }
  115. clone() {
  116. return this._cloneInto();
  117. }
  118. digestInto(out) {
  119. aexists(this);
  120. aoutput(out, this);
  121. this.finished = true;
  122. // Padding
  123. const { buffer, blockLen, counterLen, lengthFlag, view } = this;
  124. clean(buffer.subarray(this.pos)); // clean buf
  125. const counter = BigInt((this.length + this.pos) * 8);
  126. const counterPos = blockLen - counterLen - 1;
  127. buffer[this.pos] |= 128; // End block flag
  128. this.length += this.pos; // add unwritten length
  129. // Not enough in buffer for length: write what we have.
  130. if (this.pos > counterPos) {
  131. this.compress(view, 0);
  132. clean(buffer);
  133. this.pos = 0;
  134. }
  135. // Difference with md: here we have lengthFlag!
  136. buffer[counterPos] |= lengthFlag; // Length flag
  137. // We always set 8 byte length flag. Because length will overflow significantly sooner.
  138. setBigUint64(view, blockLen - 8, counter, false);
  139. this.compress(view, 0, this.pos !== 0); // don't add length if length is not empty block?
  140. // Write output
  141. clean(buffer);
  142. const v = createView(out);
  143. const state = this.get();
  144. for (let i = 0; i < this.outputLen / 4; ++i)
  145. v.setUint32(i * 4, state[i]);
  146. }
  147. digest() {
  148. const { buffer, outputLen } = this;
  149. this.digestInto(buffer);
  150. const res = buffer.slice(0, outputLen);
  151. this.destroy();
  152. return res;
  153. }
  154. }
  155. // Constants
  156. const B64C = /* @__PURE__ */ Uint32Array.from([
  157. 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89,
  158. 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c, 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917,
  159. 0x9216d5d9, 0x8979fb1b, 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, 0xb8e1afed, 0x6a267e96,
  160. 0xba7c9045, 0xf12c7f99, 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16, 0x636920d8, 0x71574e69,
  161. ]);
  162. // first half of C512
  163. const B32C = B64C.slice(0, 16);
  164. const B256_IV = SHA256_IV.slice();
  165. const B224_IV = SHA224_IV.slice();
  166. const B384_IV = SHA384_IV.slice();
  167. const B512_IV = SHA512_IV.slice();
  168. function generateTBL256() {
  169. const TBL = [];
  170. for (let i = 0, j = 0; i < 14; i++, j += 16) {
  171. for (let offset = 1; offset < 16; offset += 2) {
  172. TBL.push(B32C[BSIGMA[j + offset]]);
  173. TBL.push(B32C[BSIGMA[j + offset - 1]]);
  174. }
  175. }
  176. return new Uint32Array(TBL);
  177. }
  178. const TBL256 = /* @__PURE__ */ generateTBL256(); // C256[SIGMA[X]] precompute
  179. // Reusable temporary buffer
  180. const BLAKE256_W = /* @__PURE__ */ new Uint32Array(16);
  181. class Blake1_32 extends BLAKE1 {
  182. constructor(outputLen, IV, lengthFlag, opts = {}) {
  183. super(64, outputLen, lengthFlag, 8, 4, B32C, opts);
  184. this.v0 = IV[0] | 0;
  185. this.v1 = IV[1] | 0;
  186. this.v2 = IV[2] | 0;
  187. this.v3 = IV[3] | 0;
  188. this.v4 = IV[4] | 0;
  189. this.v5 = IV[5] | 0;
  190. this.v6 = IV[6] | 0;
  191. this.v7 = IV[7] | 0;
  192. }
  193. get() {
  194. const { v0, v1, v2, v3, v4, v5, v6, v7 } = this;
  195. return [v0, v1, v2, v3, v4, v5, v6, v7];
  196. }
  197. // prettier-ignore
  198. set(v0, v1, v2, v3, v4, v5, v6, v7) {
  199. this.v0 = v0 | 0;
  200. this.v1 = v1 | 0;
  201. this.v2 = v2 | 0;
  202. this.v3 = v3 | 0;
  203. this.v4 = v4 | 0;
  204. this.v5 = v5 | 0;
  205. this.v6 = v6 | 0;
  206. this.v7 = v7 | 0;
  207. }
  208. destroy() {
  209. super.destroy();
  210. this.set(0, 0, 0, 0, 0, 0, 0, 0);
  211. }
  212. compress(view, offset, withLength = true) {
  213. for (let i = 0; i < 16; i++, offset += 4)
  214. BLAKE256_W[i] = view.getUint32(offset, false);
  215. // NOTE: we cannot re-use compress from blake2s, since there is additional xor over u256[SIGMA[e]]
  216. let v00 = this.v0 | 0;
  217. let v01 = this.v1 | 0;
  218. let v02 = this.v2 | 0;
  219. let v03 = this.v3 | 0;
  220. let v04 = this.v4 | 0;
  221. let v05 = this.v5 | 0;
  222. let v06 = this.v6 | 0;
  223. let v07 = this.v7 | 0;
  224. let v08 = this.constants[0] | 0;
  225. let v09 = this.constants[1] | 0;
  226. let v10 = this.constants[2] | 0;
  227. let v11 = this.constants[3] | 0;
  228. const { h, l } = u64.fromBig(BigInt(withLength ? this.length * 8 : 0));
  229. let v12 = (this.constants[4] ^ l) >>> 0;
  230. let v13 = (this.constants[5] ^ l) >>> 0;
  231. let v14 = (this.constants[6] ^ h) >>> 0;
  232. let v15 = (this.constants[7] ^ h) >>> 0;
  233. // prettier-ignore
  234. for (let i = 0, k = 0, j = 0; i < 14; i++) {
  235. ({ a: v00, b: v04, c: v08, d: v12 } = G1s(v00, v04, v08, v12, BLAKE256_W[BSIGMA[k++]] ^ TBL256[j++]));
  236. ({ a: v00, b: v04, c: v08, d: v12 } = G2s(v00, v04, v08, v12, BLAKE256_W[BSIGMA[k++]] ^ TBL256[j++]));
  237. ({ a: v01, b: v05, c: v09, d: v13 } = G1s(v01, v05, v09, v13, BLAKE256_W[BSIGMA[k++]] ^ TBL256[j++]));
  238. ({ a: v01, b: v05, c: v09, d: v13 } = G2s(v01, v05, v09, v13, BLAKE256_W[BSIGMA[k++]] ^ TBL256[j++]));
  239. ({ a: v02, b: v06, c: v10, d: v14 } = G1s(v02, v06, v10, v14, BLAKE256_W[BSIGMA[k++]] ^ TBL256[j++]));
  240. ({ a: v02, b: v06, c: v10, d: v14 } = G2s(v02, v06, v10, v14, BLAKE256_W[BSIGMA[k++]] ^ TBL256[j++]));
  241. ({ a: v03, b: v07, c: v11, d: v15 } = G1s(v03, v07, v11, v15, BLAKE256_W[BSIGMA[k++]] ^ TBL256[j++]));
  242. ({ a: v03, b: v07, c: v11, d: v15 } = G2s(v03, v07, v11, v15, BLAKE256_W[BSIGMA[k++]] ^ TBL256[j++]));
  243. ({ a: v00, b: v05, c: v10, d: v15 } = G1s(v00, v05, v10, v15, BLAKE256_W[BSIGMA[k++]] ^ TBL256[j++]));
  244. ({ a: v00, b: v05, c: v10, d: v15 } = G2s(v00, v05, v10, v15, BLAKE256_W[BSIGMA[k++]] ^ TBL256[j++]));
  245. ({ a: v01, b: v06, c: v11, d: v12 } = G1s(v01, v06, v11, v12, BLAKE256_W[BSIGMA[k++]] ^ TBL256[j++]));
  246. ({ a: v01, b: v06, c: v11, d: v12 } = G2s(v01, v06, v11, v12, BLAKE256_W[BSIGMA[k++]] ^ TBL256[j++]));
  247. ({ a: v02, b: v07, c: v08, d: v13 } = G1s(v02, v07, v08, v13, BLAKE256_W[BSIGMA[k++]] ^ TBL256[j++]));
  248. ({ a: v02, b: v07, c: v08, d: v13 } = G2s(v02, v07, v08, v13, BLAKE256_W[BSIGMA[k++]] ^ TBL256[j++]));
  249. ({ a: v03, b: v04, c: v09, d: v14 } = G1s(v03, v04, v09, v14, BLAKE256_W[BSIGMA[k++]] ^ TBL256[j++]));
  250. ({ a: v03, b: v04, c: v09, d: v14 } = G2s(v03, v04, v09, v14, BLAKE256_W[BSIGMA[k++]] ^ TBL256[j++]));
  251. }
  252. this.v0 = (this.v0 ^ v00 ^ v08 ^ this.salt[0]) >>> 0;
  253. this.v1 = (this.v1 ^ v01 ^ v09 ^ this.salt[1]) >>> 0;
  254. this.v2 = (this.v2 ^ v02 ^ v10 ^ this.salt[2]) >>> 0;
  255. this.v3 = (this.v3 ^ v03 ^ v11 ^ this.salt[3]) >>> 0;
  256. this.v4 = (this.v4 ^ v04 ^ v12 ^ this.salt[0]) >>> 0;
  257. this.v5 = (this.v5 ^ v05 ^ v13 ^ this.salt[1]) >>> 0;
  258. this.v6 = (this.v6 ^ v06 ^ v14 ^ this.salt[2]) >>> 0;
  259. this.v7 = (this.v7 ^ v07 ^ v15 ^ this.salt[3]) >>> 0;
  260. clean(BLAKE256_W);
  261. }
  262. }
  263. const BBUF = /* @__PURE__ */ new Uint32Array(32);
  264. const BLAKE512_W = /* @__PURE__ */ new Uint32Array(32);
  265. function generateTBL512() {
  266. const TBL = [];
  267. for (let r = 0, k = 0; r < 16; r++, k += 16) {
  268. for (let offset = 1; offset < 16; offset += 2) {
  269. TBL.push(B64C[BSIGMA[k + offset] * 2 + 0]);
  270. TBL.push(B64C[BSIGMA[k + offset] * 2 + 1]);
  271. TBL.push(B64C[BSIGMA[k + offset - 1] * 2 + 0]);
  272. TBL.push(B64C[BSIGMA[k + offset - 1] * 2 + 1]);
  273. }
  274. }
  275. return new Uint32Array(TBL);
  276. }
  277. const TBL512 = /* @__PURE__ */ generateTBL512(); // C512[SIGMA[X]] precompute
  278. // Mixing function G splitted in two halfs
  279. function G1b(a, b, c, d, msg, k) {
  280. const Xpos = 2 * BSIGMA[k];
  281. const Xl = msg[Xpos + 1] ^ TBL512[k * 2 + 1], Xh = msg[Xpos] ^ TBL512[k * 2]; // prettier-ignore
  282. let Al = BBUF[2 * a + 1], Ah = BBUF[2 * a]; // prettier-ignore
  283. let Bl = BBUF[2 * b + 1], Bh = BBUF[2 * b]; // prettier-ignore
  284. let Cl = BBUF[2 * c + 1], Ch = BBUF[2 * c]; // prettier-ignore
  285. let Dl = BBUF[2 * d + 1], Dh = BBUF[2 * d]; // prettier-ignore
  286. // v[a] = (v[a] + v[b] + x) | 0;
  287. let ll = u64.add3L(Al, Bl, Xl);
  288. Ah = u64.add3H(ll, Ah, Bh, Xh) >>> 0;
  289. Al = (ll | 0) >>> 0;
  290. // v[d] = rotr(v[d] ^ v[a], 32)
  291. ({ Dh, Dl } = { Dh: Dh ^ Ah, Dl: Dl ^ Al });
  292. ({ Dh, Dl } = { Dh: u64.rotr32H(Dh, Dl), Dl: u64.rotr32L(Dh, Dl) });
  293. // v[c] = (v[c] + v[d]) | 0;
  294. ({ h: Ch, l: Cl } = u64.add(Ch, Cl, Dh, Dl));
  295. // v[b] = rotr(v[b] ^ v[c], 25)
  296. ({ Bh, Bl } = { Bh: Bh ^ Ch, Bl: Bl ^ Cl });
  297. ({ Bh, Bl } = { Bh: u64.rotrSH(Bh, Bl, 25), Bl: u64.rotrSL(Bh, Bl, 25) });
  298. (BBUF[2 * a + 1] = Al), (BBUF[2 * a] = Ah);
  299. (BBUF[2 * b + 1] = Bl), (BBUF[2 * b] = Bh);
  300. (BBUF[2 * c + 1] = Cl), (BBUF[2 * c] = Ch);
  301. (BBUF[2 * d + 1] = Dl), (BBUF[2 * d] = Dh);
  302. }
  303. function G2b(a, b, c, d, msg, k) {
  304. const Xpos = 2 * BSIGMA[k];
  305. const Xl = msg[Xpos + 1] ^ TBL512[k * 2 + 1], Xh = msg[Xpos] ^ TBL512[k * 2]; // prettier-ignore
  306. let Al = BBUF[2 * a + 1], Ah = BBUF[2 * a]; // prettier-ignore
  307. let Bl = BBUF[2 * b + 1], Bh = BBUF[2 * b]; // prettier-ignore
  308. let Cl = BBUF[2 * c + 1], Ch = BBUF[2 * c]; // prettier-ignore
  309. let Dl = BBUF[2 * d + 1], Dh = BBUF[2 * d]; // prettier-ignore
  310. // v[a] = (v[a] + v[b] + x) | 0;
  311. let ll = u64.add3L(Al, Bl, Xl);
  312. Ah = u64.add3H(ll, Ah, Bh, Xh);
  313. Al = ll | 0;
  314. // v[d] = rotr(v[d] ^ v[a], 16)
  315. ({ Dh, Dl } = { Dh: Dh ^ Ah, Dl: Dl ^ Al });
  316. ({ Dh, Dl } = { Dh: u64.rotrSH(Dh, Dl, 16), Dl: u64.rotrSL(Dh, Dl, 16) });
  317. // v[c] = (v[c] + v[d]) | 0;
  318. ({ h: Ch, l: Cl } = u64.add(Ch, Cl, Dh, Dl));
  319. // v[b] = rotr(v[b] ^ v[c], 11)
  320. ({ Bh, Bl } = { Bh: Bh ^ Ch, Bl: Bl ^ Cl });
  321. ({ Bh, Bl } = { Bh: u64.rotrSH(Bh, Bl, 11), Bl: u64.rotrSL(Bh, Bl, 11) });
  322. (BBUF[2 * a + 1] = Al), (BBUF[2 * a] = Ah);
  323. (BBUF[2 * b + 1] = Bl), (BBUF[2 * b] = Bh);
  324. (BBUF[2 * c + 1] = Cl), (BBUF[2 * c] = Ch);
  325. (BBUF[2 * d + 1] = Dl), (BBUF[2 * d] = Dh);
  326. }
  327. class Blake1_64 extends BLAKE1 {
  328. constructor(outputLen, IV, lengthFlag, opts = {}) {
  329. super(128, outputLen, lengthFlag, 16, 8, B64C, opts);
  330. this.v0l = IV[0] | 0;
  331. this.v0h = IV[1] | 0;
  332. this.v1l = IV[2] | 0;
  333. this.v1h = IV[3] | 0;
  334. this.v2l = IV[4] | 0;
  335. this.v2h = IV[5] | 0;
  336. this.v3l = IV[6] | 0;
  337. this.v3h = IV[7] | 0;
  338. this.v4l = IV[8] | 0;
  339. this.v4h = IV[9] | 0;
  340. this.v5l = IV[10] | 0;
  341. this.v5h = IV[11] | 0;
  342. this.v6l = IV[12] | 0;
  343. this.v6h = IV[13] | 0;
  344. this.v7l = IV[14] | 0;
  345. this.v7h = IV[15] | 0;
  346. }
  347. // prettier-ignore
  348. get() {
  349. let { v0l, v0h, v1l, v1h, v2l, v2h, v3l, v3h, v4l, v4h, v5l, v5h, v6l, v6h, v7l, v7h } = this;
  350. return [v0l, v0h, v1l, v1h, v2l, v2h, v3l, v3h, v4l, v4h, v5l, v5h, v6l, v6h, v7l, v7h];
  351. }
  352. // prettier-ignore
  353. set(v0l, v0h, v1l, v1h, v2l, v2h, v3l, v3h, v4l, v4h, v5l, v5h, v6l, v6h, v7l, v7h) {
  354. this.v0l = v0l | 0;
  355. this.v0h = v0h | 0;
  356. this.v1l = v1l | 0;
  357. this.v1h = v1h | 0;
  358. this.v2l = v2l | 0;
  359. this.v2h = v2h | 0;
  360. this.v3l = v3l | 0;
  361. this.v3h = v3h | 0;
  362. this.v4l = v4l | 0;
  363. this.v4h = v4h | 0;
  364. this.v5l = v5l | 0;
  365. this.v5h = v5h | 0;
  366. this.v6l = v6l | 0;
  367. this.v6h = v6h | 0;
  368. this.v7l = v7l | 0;
  369. this.v7h = v7h | 0;
  370. }
  371. destroy() {
  372. super.destroy();
  373. this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  374. }
  375. compress(view, offset, withLength = true) {
  376. for (let i = 0; i < 32; i++, offset += 4)
  377. BLAKE512_W[i] = view.getUint32(offset, false);
  378. this.get().forEach((v, i) => (BBUF[i] = v)); // First half from state.
  379. BBUF.set(this.constants.subarray(0, 16), 16);
  380. if (withLength) {
  381. const { h, l } = u64.fromBig(BigInt(this.length * 8));
  382. BBUF[24] = (BBUF[24] ^ h) >>> 0;
  383. BBUF[25] = (BBUF[25] ^ l) >>> 0;
  384. BBUF[26] = (BBUF[26] ^ h) >>> 0;
  385. BBUF[27] = (BBUF[27] ^ l) >>> 0;
  386. }
  387. for (let i = 0, k = 0; i < 16; i++) {
  388. G1b(0, 4, 8, 12, BLAKE512_W, k++);
  389. G2b(0, 4, 8, 12, BLAKE512_W, k++);
  390. G1b(1, 5, 9, 13, BLAKE512_W, k++);
  391. G2b(1, 5, 9, 13, BLAKE512_W, k++);
  392. G1b(2, 6, 10, 14, BLAKE512_W, k++);
  393. G2b(2, 6, 10, 14, BLAKE512_W, k++);
  394. G1b(3, 7, 11, 15, BLAKE512_W, k++);
  395. G2b(3, 7, 11, 15, BLAKE512_W, k++);
  396. G1b(0, 5, 10, 15, BLAKE512_W, k++);
  397. G2b(0, 5, 10, 15, BLAKE512_W, k++);
  398. G1b(1, 6, 11, 12, BLAKE512_W, k++);
  399. G2b(1, 6, 11, 12, BLAKE512_W, k++);
  400. G1b(2, 7, 8, 13, BLAKE512_W, k++);
  401. G2b(2, 7, 8, 13, BLAKE512_W, k++);
  402. G1b(3, 4, 9, 14, BLAKE512_W, k++);
  403. G2b(3, 4, 9, 14, BLAKE512_W, k++);
  404. }
  405. this.v0l ^= BBUF[0] ^ BBUF[16] ^ this.salt[0];
  406. this.v0h ^= BBUF[1] ^ BBUF[17] ^ this.salt[1];
  407. this.v1l ^= BBUF[2] ^ BBUF[18] ^ this.salt[2];
  408. this.v1h ^= BBUF[3] ^ BBUF[19] ^ this.salt[3];
  409. this.v2l ^= BBUF[4] ^ BBUF[20] ^ this.salt[4];
  410. this.v2h ^= BBUF[5] ^ BBUF[21] ^ this.salt[5];
  411. this.v3l ^= BBUF[6] ^ BBUF[22] ^ this.salt[6];
  412. this.v3h ^= BBUF[7] ^ BBUF[23] ^ this.salt[7];
  413. this.v4l ^= BBUF[8] ^ BBUF[24] ^ this.salt[0];
  414. this.v4h ^= BBUF[9] ^ BBUF[25] ^ this.salt[1];
  415. this.v5l ^= BBUF[10] ^ BBUF[26] ^ this.salt[2];
  416. this.v5h ^= BBUF[11] ^ BBUF[27] ^ this.salt[3];
  417. this.v6l ^= BBUF[12] ^ BBUF[28] ^ this.salt[4];
  418. this.v6h ^= BBUF[13] ^ BBUF[29] ^ this.salt[5];
  419. this.v7l ^= BBUF[14] ^ BBUF[30] ^ this.salt[6];
  420. this.v7h ^= BBUF[15] ^ BBUF[31] ^ this.salt[7];
  421. clean(BBUF, BLAKE512_W);
  422. }
  423. }
  424. export class BLAKE224 extends Blake1_32 {
  425. constructor(opts = {}) {
  426. super(28, B224_IV, 0, opts);
  427. }
  428. }
  429. export class BLAKE256 extends Blake1_32 {
  430. constructor(opts = {}) {
  431. super(32, B256_IV, 1, opts);
  432. }
  433. }
  434. export class BLAKE384 extends Blake1_64 {
  435. constructor(opts = {}) {
  436. super(48, B384_IV, 0, opts);
  437. }
  438. }
  439. export class BLAKE512 extends Blake1_64 {
  440. constructor(opts = {}) {
  441. super(64, B512_IV, 1, opts);
  442. }
  443. }
  444. /** blake1-224 hash function */
  445. export const blake224 = /* @__PURE__ */ createOptHasher((opts) => new BLAKE224(opts));
  446. /** blake1-256 hash function */
  447. export const blake256 = /* @__PURE__ */ createOptHasher((opts) => new BLAKE256(opts));
  448. /** blake1-384 hash function */
  449. export const blake384 = /* @__PURE__ */ createOptHasher((opts) => new BLAKE384(opts));
  450. /** blake1-512 hash function */
  451. export const blake512 = /* @__PURE__ */ createOptHasher((opts) => new BLAKE512(opts));
  452. //# sourceMappingURL=blake1.js.map