message: Faster async pbkdf2 polyfill for Edge browser (using W3C hmac)
diff: @@ -5,10 +5,67 @@ but not pbkdf2.
  Extracted from crypto-browserify/pbkdf2 and modified to use WebCrypto
  for hashing/hmac operations.
  -See original at: https://github.com/crypto-browserify/pbkdf2/blob/a572cbc655a1cc626ae72ccf8bb29f25418d394e/lib/sync-browser.js
  +See original at: https://github.com/crypto-browserify/pbkdf2/tree/v3.0.17/lib
  */
  +function createHmacDigest(algorithm: 'sha512' | 'sha256') {
  + let algo: string
  + if (algorithm === 'sha256') {
  + algo = 'SHA-256'
  + } else if (algorithm === 'sha512') {
  + algo = 'SHA-512'
  + } else {
  + throw new Error(`Unsupported hash algorithm ${algorithm}`)
  + }
  + const subtleCrypto = crypto.subtle
  + const algoOpts = { name: 'HMAC', hash: algo }
  + return async (key: Buffer, data: Buffer) => {
  + const cryptoKey = await subtleCrypto.importKey('raw', key, algoOpts, true, ['sign'])
  + const sig = await subtleCrypto.sign(algoOpts, cryptoKey, data)
  + return Buffer.from(sig)
  + }
  +}
  +
  +export default async function pbkdf2(
  + key: Buffer,
  + salt: Buffer,
  + iterations: number,
  + keyLength: number,
  + algorithm: 'sha256' | 'sha512'
  +) {
  + const hmacDigest = createHmacDigest(algorithm)
  +
  + const DK = Buffer.alloc(keyLength)
  + const saltLength = salt.length
  + const block1 = Buffer.alloc(saltLength + 4)
  + salt.copy(block1, 0, 0, saltLength)
  +
  + let destPos = 0
  +
  + const hLen = algorithm === 'sha512' ? 64 : 32
  + const l = Math.ceil(keyLength / hLen)
  +
  + for (let i = 1; i <= l; i++) {
  + block1.writeUInt32BE(i, saltLength)
  +
  + // eslint-disable-next-line no-await-in-loop
  + const T = await hmacDigest(key, block1)
  + let U = T
  +
  + for (let j = 1; j < iterations; j++) {
  + // eslint-disable-next-line no-await-in-loop
  + U = await hmacDigest(key, U)
  + for (let k = 0; k < hLen; k++) {
  + T[k] ^= U[k]
  + }
  + }
  + T.copy(DK, destPos)
  + destPos += hLen
  + }
  + return DK
  +}
  +
  function createDigest(algorithm: 'sha512' | 'sha256') {
  let algo: string
  if (algorithm === 'sha256') {
  @@ -25,7 +82,7 @@ function createDigest(algorithm: 'sha512' | 'sha256') {
  }
  }
  -export default async function pbkdf2(
  +export async function pbkdf2NoHmacSupport(
  key: Buffer,
  salt: Buffer,
  iterations: number,
  