asmcrypto / asmcrypto.js

JavaScript Cryptographic Library with performance in mind.
MIT License
659 stars 182 forks source link

random.getValues() API does not seem to work as advertised in NodeJS #149

Closed wu-lee closed 6 years ago

wu-lee commented 6 years ago

I'm using the library from node v8.11.0 / npm v5.8.0 on Ubuntu Linux 16.04.

I have a test case here: https://github.com/wu-lee/asmcrypto-test

Essentially, it installs the latest version (0.22.0) from NPM, and tries to generate a random number, in a number of ways, but things do not work as described in the documentation. The docs could be more clear about the requirements, and the status of getRandomValues

(See comments below.)

Hope this helps.

const asmCrypto = require('asmcrypto.js');

function trycatch(cb) {
    try { return cb() } catch (e) { console.error("failed: " + e.message) };
}

const array = new Uint32Array(10);

trycatch(() => asmCrypto.random.getValues(array)); // getValues is not a function

trycatch(() => asmCrypto.getRandomValues(array)); // No strong PRNG available

asmCrypto.random.skipSystemRNGWarning = true;

trycatch(() => asmCrypto.getRandomValues(array)); // No strong PRNG available

asmCrypto.random.allowWeak = true;

trycatch(() => asmCrypto.getRandomValues(array)); // Succeeds, but still prints the warning
alippai commented 6 years ago

I removed all random generation related code from 2.0.0 as I'm not familiar with this field.