randombytes_random() is 32 bits, even in JS.

This commit is contained in:
Frank Denis 2015-01-18 09:50:17 +01:00
parent dd5224791b
commit add0fcede4
2 changed files with 4 additions and 3 deletions

View File

@ -57,7 +57,7 @@ randombytes_stir(void)
if (Module.getRandomValue === undefined) {
try {
var randomValuesStandard = function() {
var buf = new Uint16Array(1);
var buf = new Uint32Array(1);
window.crypto.getRandomValues(buf);
return buf[0] >>> 0;
};
@ -67,8 +67,8 @@ randombytes_stir(void)
try {
var crypto = require('crypto');
var randomValueIOJS = function() {
var buf = crypto.randomBytes(2);
return (buf[0] << 8 | buf[1]) >>> 0;
var buf = crypto.randomBytes(4);
return (buf[0] << 24 | buf[1] << 16 || buf[2] << 8 || buf[3]) >>> 0;
};
randomValueIOJS();
Module.getRandomValue = randomValueIOJS;

View File

@ -35,6 +35,7 @@ static int randombytes_tests(void)
assert(strcmp(randombytes_implementation_name(), "js"));
#endif
randombytes(x, 1U);
while (randombytes_random() <= (uint32_t) 0x7fffffff);
randombytes_close();
for (i = 0; i < 256; ++i) {