replace jsbn's rng with module secure-random

This uses window.crypto.getRandomValues on browser
and crypto.randomBytes on node
This commit is contained in:
Wei Lu 2014-03-20 17:18:45 +08:00
parent ff625968ce
commit b7861e4336
8 changed files with 18 additions and 141 deletions

View file

@ -2,6 +2,7 @@
var assert = require('assert');
var BigInteger = require('../src/jsbn/jsbn.js')
var bytesToHex = require('../src/convert.js').bytesToHex;
var secureRandom = require('secure-random');
describe('BigInteger', function() {
describe('toByteArraySigned', function() {
@ -25,4 +26,12 @@ describe('BigInteger', function() {
assert.equal(hex(-62300), '0x80f35c');
})
})
describe('with RNG passed into constructor as the 2nd argument', function(){
it('returns a BigInteger with the limit of the specified length', function(){
var bitLength = 256
var i = new BigInteger(bitLength, secureRandom)
assert(i.bitLength() <= 256)
})
})
})