_blake.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.BSIGMA = void 0;
  4. exports.G1s = G1s;
  5. exports.G2s = G2s;
  6. /**
  7. * Internal helpers for blake hash.
  8. * @module
  9. */
  10. const utils_ts_1 = require("./utils.js");
  11. /**
  12. * Internal blake variable.
  13. * For BLAKE2b, the two extra permutations for rounds 10 and 11 are SIGMA[10..11] = SIGMA[0..1].
  14. */
  15. // prettier-ignore
  16. exports.BSIGMA = Uint8Array.from([
  17. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
  18. 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3,
  19. 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4,
  20. 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8,
  21. 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13,
  22. 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9,
  23. 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11,
  24. 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10,
  25. 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5,
  26. 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0,
  27. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
  28. 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3,
  29. // Blake1, unused in others
  30. 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4,
  31. 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8,
  32. 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13,
  33. 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9,
  34. ]);
  35. // Mixing function G splitted in two halfs
  36. function G1s(a, b, c, d, x) {
  37. a = (a + b + x) | 0;
  38. d = (0, utils_ts_1.rotr)(d ^ a, 16);
  39. c = (c + d) | 0;
  40. b = (0, utils_ts_1.rotr)(b ^ c, 12);
  41. return { a, b, c, d };
  42. }
  43. function G2s(a, b, c, d, x) {
  44. a = (a + b + x) | 0;
  45. d = (0, utils_ts_1.rotr)(d ^ a, 8);
  46. c = (c + d) | 0;
  47. b = (0, utils_ts_1.rotr)(b ^ c, 7);
  48. return { a, b, c, d };
  49. }
  50. //# sourceMappingURL=_blake.js.map