import { __exports as r } from "../../../../../../_virtual/sha3.js";
import { __require as P } from "./_assert.js";
import { __require as U } from "./_u64.js";
import { __require as v } from "./utils.js";
var S;
function W() {
  if (S) return r;
  S = 1, Object.defineProperty(r, "__esModule", { value: !0 }), r.shake256 = r.shake128 = r.keccak_512 = r.keccak_384 = r.keccak_256 = r.keccak_224 = r.sha3_512 = r.sha3_384 = r.sha3_256 = r.sha3_224 = r.Keccak = void 0, r.keccakP = g;
  const l = /* @__PURE__ */ P(), _ = /* @__PURE__ */ U(), a = /* @__PURE__ */ v(), w = [], y = [], I = [], m = /* @__PURE__ */ BigInt(0), k = /* @__PURE__ */ BigInt(1), A = /* @__PURE__ */ BigInt(2), H = /* @__PURE__ */ BigInt(7), q = /* @__PURE__ */ BigInt(256), T = /* @__PURE__ */ BigInt(113);
  for (let i = 0, t = k, s = 1, n = 0; i < 24; i++) {
    [s, n] = [n, (2 * s + 3 * n) % 5], w.push(2 * (5 * n + s)), y.push((i + 1) * (i + 2) / 2 % 64);
    let o = m;
    for (let h = 0; h < 7; h++)
      t = (t << k ^ (t >> H) * T) % q, t & A && (o ^= k << (k << /* @__PURE__ */ BigInt(h)) - k);
    I.push(o);
  }
  const [F, X] = /* @__PURE__ */ (0, _.split)(I, !0), L = (i, t, s) => s > 32 ? (0, _.rotlBH)(i, t, s) : (0, _.rotlSH)(i, t, s), b = (i, t, s) => s > 32 ? (0, _.rotlBL)(i, t, s) : (0, _.rotlSL)(i, t, s);
  function g(i, t = 24) {
    const s = new Uint32Array(10);
    for (let n = 24 - t; n < 24; n++) {
      for (let e = 0; e < 10; e++)
        s[e] = i[e] ^ i[e + 10] ^ i[e + 20] ^ i[e + 30] ^ i[e + 40];
      for (let e = 0; e < 10; e += 2) {
        const c = (e + 8) % 10, d = (e + 2) % 10, x = s[d], f = s[d + 1], j = L(x, f, 1) ^ s[c], E = b(x, f, 1) ^ s[c + 1];
        for (let O = 0; O < 50; O += 10)
          i[e + O] ^= j, i[e + O + 1] ^= E;
      }
      let o = i[2], h = i[3];
      for (let e = 0; e < 24; e++) {
        const c = y[e], d = L(o, h, c), x = b(o, h, c), f = w[e];
        o = i[f], h = i[f + 1], i[f] = d, i[f + 1] = x;
      }
      for (let e = 0; e < 50; e += 10) {
        for (let c = 0; c < 10; c++)
          s[c] = i[e + c];
        for (let c = 0; c < 10; c++)
          i[e + c] ^= ~s[(c + 2) % 10] & s[(c + 4) % 10];
      }
      i[0] ^= F[n], i[1] ^= X[n];
    }
    s.fill(0);
  }
  class p extends a.Hash {
    // NOTE: we accept arguments in bytes instead of bits here.
    constructor(t, s, n, o = !1, h = 24) {
      if (super(), this.blockLen = t, this.suffix = s, this.outputLen = n, this.enableXOF = o, this.rounds = h, this.pos = 0, this.posOut = 0, this.finished = !1, this.destroyed = !1, (0, l.anumber)(n), 0 >= this.blockLen || this.blockLen >= 200)
        throw new Error("Sha3 supports only keccak-f1600 function");
      this.state = new Uint8Array(200), this.state32 = (0, a.u32)(this.state);
    }
    keccak() {
      a.isLE || (0, a.byteSwap32)(this.state32), g(this.state32, this.rounds), a.isLE || (0, a.byteSwap32)(this.state32), this.posOut = 0, this.pos = 0;
    }
    update(t) {
      (0, l.aexists)(this);
      const { blockLen: s, state: n } = this;
      t = (0, a.toBytes)(t);
      const o = t.length;
      for (let h = 0; h < o; ) {
        const e = Math.min(s - this.pos, o - h);
        for (let c = 0; c < e; c++)
          n[this.pos++] ^= t[h++];
        this.pos === s && this.keccak();
      }
      return this;
    }
    finish() {
      if (this.finished)
        return;
      this.finished = !0;
      const { state: t, suffix: s, pos: n, blockLen: o } = this;
      t[n] ^= s, (s & 128) !== 0 && n === o - 1 && this.keccak(), t[o - 1] ^= 128, this.keccak();
    }
    writeInto(t) {
      (0, l.aexists)(this, !1), (0, l.abytes)(t), this.finish();
      const s = this.state, { blockLen: n } = this;
      for (let o = 0, h = t.length; o < h; ) {
        this.posOut >= n && this.keccak();
        const e = Math.min(n - this.posOut, h - o);
        t.set(s.subarray(this.posOut, this.posOut + e), o), this.posOut += e, o += e;
      }
      return t;
    }
    xofInto(t) {
      if (!this.enableXOF)
        throw new Error("XOF is not possible for this instance");
      return this.writeInto(t);
    }
    xof(t) {
      return (0, l.anumber)(t), this.xofInto(new Uint8Array(t));
    }
    digestInto(t) {
      if ((0, l.aoutput)(t, this), this.finished)
        throw new Error("digest() was already called");
      return this.writeInto(t), this.destroy(), t;
    }
    digest() {
      return this.digestInto(new Uint8Array(this.outputLen));
    }
    destroy() {
      this.destroyed = !0, this.state.fill(0);
    }
    _cloneInto(t) {
      const { blockLen: s, suffix: n, outputLen: o, rounds: h, enableXOF: e } = this;
      return t || (t = new p(s, n, o, e, h)), t.state32.set(this.state32), t.pos = this.pos, t.posOut = this.posOut, t.finished = this.finished, t.rounds = h, t.suffix = n, t.outputLen = o, t.enableXOF = e, t.destroyed = this.destroyed, t;
    }
  }
  r.Keccak = p;
  const u = (i, t, s) => (0, a.wrapConstructor)(() => new p(t, i, s));
  r.sha3_224 = u(6, 144, 224 / 8), r.sha3_256 = u(6, 136, 256 / 8), r.sha3_384 = u(6, 104, 384 / 8), r.sha3_512 = u(6, 72, 512 / 8), r.keccak_224 = u(1, 144, 224 / 8), r.keccak_256 = u(1, 136, 256 / 8), r.keccak_384 = u(1, 104, 384 / 8), r.keccak_512 = u(1, 72, 512 / 8);
  const B = (i, t, s) => (0, a.wrapXOFConstructorWithOpts)((n = {}) => new p(t, i, n.dkLen === void 0 ? s : n.dkLen, !0));
  return r.shake128 = B(31, 168, 128 / 8), r.shake256 = B(31, 136, 256 / 8), r;
}
export {
  W as __require
};
//# sourceMappingURL=sha3.js.map
