How to use hmac-drbg - 4 common examples

To help you get started, we’ve selected a few hmac-drbg examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github EdgeApp / edge-core-js / src / io / react-native / react-native-worker.js View on Github external
function makeIo(nativeIo: EdgeNativeIo): EdgeIo {
  const clientIo: ClientIo = nativeIo['edge-core']
  const { console, disklet, entropy, scrypt } = clientIo
  const csprng = new HmacDRBG({
    hash: hashjs.sha256,
    entropy: base64.parse(entropy)
  })

  return {
    console,
    disklet,

    random: bytes => csprng.generate(bytes),
    scrypt,

    // Networking:
    fetch(uri: string, opts?: EdgeFetchOptions): Promise {
      return window.fetch(uri, opts)
    },
github Zilliqa / Zilliqa-JavaScript-Library / packages / zilliqa-js-crypto / src / schnorr.ts View on Github external
const getDRBG = (msg: Buffer) => {
  const entropy = randomBytes(ENT_LEN);
  const pers = Buffer.allocUnsafe(ALG_LEN + ENT_LEN);

  Buffer.from(randomBytes(ENT_LEN)).copy(pers, 0);
  ALG.copy(pers, ENT_LEN);

  return new DRBG({
    hash: hashjs.sha256,
    entropy,
    nonce: msg,
    pers,
  });
};
github ipfs-shipyard / js-human-crypto-keys / src / utils / forge-prng.js View on Github external
const createForgePrng = (seed) => {
    const hmacDrgb = new HmacDrgb({
        hash: hash.sha256,
        entropy: util.binary.hex.encode(seed),
        nonce: null,
        pers: null,
    });

    return {
        getBytesSync: (size) => {
            const bytesArray = hmacDrgb.generate(size);
            const bytes = new Uint8Array(bytesArray);

            return util.binary.raw.encode(bytes);
        },
    };
};
github snowypowers / ansy / src / modules / crypto.js View on Github external
genPriKey: () => {
    let key = new Uint8Array(32)
    if (window.crypto) {
      window.crypto.getRandomValues(key)
      key = key.reduce((prev, curr) => {
        let hex = ("0" + curr.toString(16)).slice(-2)
        return prev + hex
      }, "")
    } else {
      let enc = ""
      for (let i = 0; i < 32; i++) {
        key[i] = Math.floor(Math.random() * 256)
        enc += key[i].toString(16)
      }
      let d = new hmacDRBG({
        hash: hash.sha256,
        entropy: enc,
        nonce: enc
      })
      key = d.generate(32, 'hex')
    }
    return key.toString('hex')
  }
}

hmac-drbg

Deterministic random bit generator (hmac)

MIT
Latest version published 8 years ago

Package Health Score

65 / 100
Full package analysis

Popular hmac-drbg functions