PHP WebShell

Текущая директория: /opt/BitGoJS/node_modules/asmcrypto.js/src/pbkdf2

Просмотр файла: pbkdf2-hmac-sha256.js

import { pbkdf2_constructor } from './pbkdf2';
import { get_hmac_sha256_instance, hmac_sha256_constructor } from '../hmac/hmac-sha256';
import { is_string } from '../utils';
import { IllegalArgumentError, IllegalStateError } from '../errors';

export class pbkdf2_hmac_sha256_constructor extends pbkdf2_constructor {
  constructor(options) {
    options = options || {};

    if (!(options.hmac instanceof hmac_sha256_constructor)) options.hmac = get_hmac_sha256_instance();

    super(options);
  }

  generate(salt, count, length) {
    if (this.result !== null) throw new IllegalStateError('state must be reset before processing new data');

    if (!salt && !is_string(salt)) throw new IllegalArgumentError("bad 'salt' value");

    count = count || this.count;
    length = length || this.length;

    this.result = new Uint8Array(length);

    var blocks = Math.ceil(length / this.hmac.HMAC_SIZE);

    for (var i = 1; i <= blocks; ++i) {
      var j = (i - 1) * this.hmac.HMAC_SIZE;
      var l = (i < blocks ? 0 : length % this.hmac.HMAC_SIZE) || this.hmac.HMAC_SIZE;

      this.hmac.reset().process(salt);
      this.hmac.hash.asm.pbkdf2_generate_block(this.hmac.hash.pos, this.hmac.hash.len, i, count, 0);

      this.result.set(this.hmac.hash.heap.subarray(0, l), j);
    }

    return this;
  }
}

var pbkdf2_hmac_sha256_instance = null;

export function get_pbkdf2_hmac_sha256_instance() {
  if (pbkdf2_hmac_sha256_instance === null) pbkdf2_hmac_sha256_instance = new pbkdf2_hmac_sha256_constructor();
  return pbkdf2_hmac_sha256_instance;
}

Выполнить команду


Для локальной разработки. Не используйте в интернете!