made SJCL seeder public

This commit is contained in:
Arik Sosman 2016-01-12 20:30:15 -08:00
parent cf3b46a9a7
commit 4fed3623a0
1 changed files with 7 additions and 7 deletions

View File

@ -3,7 +3,6 @@ if (typeof Buffer === 'undefined') {
} }
var sjcl = require('sjcl'); var sjcl = require('sjcl');
var sjclRandom = new sjcl.prng(10);
var explicitReq = require; var explicitReq = require;
var RNRandomBytes = explicitReq('react-native').NativeModules.RNRandomBytes; var RNRandomBytes = explicitReq('react-native').NativeModules.RNRandomBytes;
@ -13,7 +12,8 @@ var randomBytes = function(length, cb) {
if (!cb) { if (!cb) {
var size = length; var size = length;
var wordCount = Math.ceil(size * 0.25); var wordCount = Math.ceil(size * 0.25);
var randomBytes = sjclRandom.randomWords(wordCount); console.log('SEED LEVEL: '+sjcl.random.getProgress(10));
var randomBytes = sjcl.random.randomWords(wordCount, 10);
var hexString = sjcl.codec.hex.fromBits(randomBytes); var hexString = sjcl.codec.hex.fromBits(randomBytes);
hexString = hexString.substr(0, size * 2); hexString = hexString.substr(0, size * 2);
@ -30,18 +30,18 @@ var randomBytes = function(length, cb) {
}; };
var seedStanford = function(){ var seedSJCL = function(currentSJCL){
randomBytes(4096, function(err, buffer){ randomBytes(4096, function(err, buffer){
var hexString = buffer.toString('hex'); var hexString = buffer.toString('hex');
var stanfordSeed = sjcl.codec.hex.toBits(hexString); var stanfordSeed = currentSJCL.codec.hex.toBits(hexString);
sjclRandom.addEntropy(stanfordSeed); currentSJCL.random.addEntropy(stanfordSeed);
}); });
}; };
// initialize the seed // initialize the seed
seedStanford(); seedSJCL(sjcl);
module.exports = { module.exports = {
randomBytes: randomBytes, randomBytes: randomBytes,
seedStanford: seedStanford seedSJCL: seedSJCL
}; };