import { ay as g, az as P, aA as A, aB as F, aC as I, aD as L, U as R } from "./index-BpgHIKBe.mjs";
function _(u, p, d, i) {
  A(u);
  const f = F({ dkLen: 32, asyncTick: 10 }, i), { c: y, dkLen: l, asyncTick: t } = f;
  if (I(y), I(l), I(t), y < 1)
    throw new Error("PBKDF2: iterations (c) should be >= 1");
  const n = L(p), o = L(d), s = new Uint8Array(l), b = R.create(u, n), e = b._cloneInto().update(o);
  return { c: y, dkLen: l, asyncTick: t, DK: s, PRF: b, PRFSalt: e };
}
function h(u, p, d, i, f) {
  return u.destroy(), p.destroy(), i && i.destroy(), f.fill(0), d;
}
function T(u, p, d, i) {
  const { c: f, dkLen: y, DK: l, PRF: t, PRFSalt: n } = _(u, p, d, i);
  let o;
  const s = new Uint8Array(4), b = g(s), e = new Uint8Array(t.outputLen);
  for (let a = 1, k = 0; k < y; a++, k += t.outputLen) {
    const r = l.subarray(k, k + t.outputLen);
    b.setInt32(0, a, !1), (o = n._cloneInto(o)).update(s).digestInto(e), r.set(e.subarray(0, r.length));
    for (let w = 1; w < f; w++) {
      t._cloneInto(o).update(e).digestInto(e);
      for (let c = 0; c < r.length; c++)
        r[c] ^= e[c];
    }
  }
  return h(t, n, l, o, e);
}
async function U(u, p, d, i) {
  const { c: f, dkLen: y, asyncTick: l, DK: t, PRF: n, PRFSalt: o } = _(u, p, d, i);
  let s;
  const b = new Uint8Array(4), e = g(b), a = new Uint8Array(n.outputLen);
  for (let k = 1, r = 0; r < y; k++, r += n.outputLen) {
    const w = t.subarray(r, r + n.outputLen);
    e.setInt32(0, k, !1), (s = o._cloneInto(s)).update(b).digestInto(a), w.set(a.subarray(0, w.length)), await P(f - 1, l, () => {
      n._cloneInto(s).update(a).digestInto(a);
      for (let c = 0; c < w.length; c++)
        w[c] ^= a[c];
    });
  }
  return h(n, o, t, s, a);
}
const D = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  pbkdf2: T,
  pbkdf2Async: U
}, Symbol.toStringTag, { value: "Module" }));
export {
  D as a,
  T as p
};
