randombytes_random() is 32 bits, even in JS.
This commit is contained in:
parent
dd5224791b
commit
add0fcede4
@ -57,7 +57,7 @@ randombytes_stir(void)
|
|||||||
if (Module.getRandomValue === undefined) {
|
if (Module.getRandomValue === undefined) {
|
||||||
try {
|
try {
|
||||||
var randomValuesStandard = function() {
|
var randomValuesStandard = function() {
|
||||||
var buf = new Uint16Array(1);
|
var buf = new Uint32Array(1);
|
||||||
window.crypto.getRandomValues(buf);
|
window.crypto.getRandomValues(buf);
|
||||||
return buf[0] >>> 0;
|
return buf[0] >>> 0;
|
||||||
};
|
};
|
||||||
@ -67,8 +67,8 @@ randombytes_stir(void)
|
|||||||
try {
|
try {
|
||||||
var crypto = require('crypto');
|
var crypto = require('crypto');
|
||||||
var randomValueIOJS = function() {
|
var randomValueIOJS = function() {
|
||||||
var buf = crypto.randomBytes(2);
|
var buf = crypto.randomBytes(4);
|
||||||
return (buf[0] << 8 | buf[1]) >>> 0;
|
return (buf[0] << 24 | buf[1] << 16 || buf[2] << 8 || buf[3]) >>> 0;
|
||||||
};
|
};
|
||||||
randomValueIOJS();
|
randomValueIOJS();
|
||||||
Module.getRandomValue = randomValueIOJS;
|
Module.getRandomValue = randomValueIOJS;
|
||||||
|
@ -35,6 +35,7 @@ static int randombytes_tests(void)
|
|||||||
assert(strcmp(randombytes_implementation_name(), "js"));
|
assert(strcmp(randombytes_implementation_name(), "js"));
|
||||||
#endif
|
#endif
|
||||||
randombytes(x, 1U);
|
randombytes(x, 1U);
|
||||||
|
while (randombytes_random() <= (uint32_t) 0x7fffffff);
|
||||||
randombytes_close();
|
randombytes_close();
|
||||||
|
|
||||||
for (i = 0; i < 256; ++i) {
|
for (i = 0; i < 256; ++i) {
|
||||||
|
Loading…
Reference in New Issue
Block a user