Merge pull request #309 from ryanxcharles/bug/signing
iterate array correctly so that random number is actually used in signing
This commit is contained in:
commit
1f49286b2a
|
@ -99,7 +99,7 @@ Key.prototype.signSync = function(hash) {
|
||||||
rng.nextBytes = function(array) {
|
rng.nextBytes = function(array) {
|
||||||
var buf = SecureRandom.getRandomBuffer(array.length);
|
var buf = SecureRandom.getRandomBuffer(array.length);
|
||||||
var a = bufferToArray(SecureRandom.getRandomBuffer(array.length));
|
var a = bufferToArray(SecureRandom.getRandomBuffer(array.length));
|
||||||
for (var i in array) {
|
for (var i in a) {
|
||||||
array[i] = a[i];
|
array[i] = a[i];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -130,4 +130,19 @@ describe('Key', function() {
|
||||||
ret.should.equal(false);
|
ret.should.equal(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('signSync', function() {
|
||||||
|
it('should sign 10 times and have a different signature each time', function() {
|
||||||
|
var key = new Key();
|
||||||
|
key.private = coinUtil.sha256('my fake private key');
|
||||||
|
key.regenerateSync();
|
||||||
|
var data = coinUtil.sha256('the data i am signing');
|
||||||
|
var sigs = [];
|
||||||
|
for (var i = 0; i < 10; i++)
|
||||||
|
sigs[i] = key.signSync(data);
|
||||||
|
for (var i = 0; i < 10; i++)
|
||||||
|
for (var j = i + 1; j < 10; j++)
|
||||||
|
sigs[i].toString('hex').should.not.equal(sigs[j].toString('hex'));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -22,6 +22,15 @@ describe('SecureRandom', function() {
|
||||||
bytes1.toString('hex').should.not.equal(bytes2.toString('hex'));
|
bytes1.toString('hex').should.not.equal(bytes2.toString('hex'));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should generate 1000 8 byte buffers in a row that are not equal', function() {
|
||||||
|
var bufs = [];
|
||||||
|
for (var i = 0; i < 100; i++)
|
||||||
|
bufs[i] = SecureRandom.getRandomBuffer(8);
|
||||||
|
for (var i = 0; i < 100; i++)
|
||||||
|
for (var j = i + 1; j < 100; j++)
|
||||||
|
bufs[i].toString('hex').should.not.equal(bufs[j].toString('hex'));
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getPseudoRandomBuffer', function() {
|
describe('getPseudoRandomBuffer', function() {
|
||||||
|
|
Loading…
Reference in New Issue