Skip to content

Commit fe7e30b

Browse files
author
Chris Clark
committed
[FIX] Fail if PRNG has not been seeded with at least 256 bits of entropy before generating ECDSA signatures
1 parent a02b8e3 commit fe7e30b

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

src/js/ripple/keypair.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,9 @@ KeyPair.prototype.get_address = function() {
9292
};
9393

9494
KeyPair.prototype.sign = function(hash) {
95+
var PARANOIA_256_BITS = 6; // sjcl constant for ensuring 256 bits of entropy
9596
hash = UInt256.from_json(hash);
96-
var sig = this._secret.sign(hash.to_bits(), 0);
97+
var sig = this._secret.sign(hash.to_bits(), PARANOIA_256_BITS);
9798
sig = this._secret.canonicalizeSignature(sig);
9899
return this._secret.encodeDER(sig);
99100
};

src/js/ripple/transaction.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ Transaction.prototype.sign = function() {
466466
}
467467

468468
var key = seed.get_key(this.tx_json.Account);
469-
var sig = key.sign(hash, 0);
469+
var sig = key.sign(hash);
470470
var hex = sjcl.codec.hex.fromBits(sig).toUpperCase();
471471

472472
this.tx_json.TxnSignature = hex;

test/transaction-manager-test.js

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
var ws = require('ws');
44
var lodash = require('lodash');
55
var assert = require('assert-diff');
6+
var sjcl = require('ripple-lib').sjcl;
67
var Remote = require('ripple-lib').Remote;
78
var SerializedObject = require('ripple-lib').SerializedObject;
89
var Transaction = require('ripple-lib').Transaction;
@@ -42,6 +43,11 @@ describe('TransactionManager', function() {
4243
var account;
4344
var transactionManager;
4445

46+
before(function() {
47+
sjcl.random.addEntropy(
48+
'3045022100A58B0460BC5092CB4F96155C19125A4E079C870663F1D5E8BBC9BD', 256);
49+
});
50+
4551
beforeEach(function(done) {
4652
rippled = new ws.Server({port: 5763});
4753

test/transaction-test.js

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var Transaction = require('ripple-lib').Transaction;
44
var TransactionQueue = require('ripple-lib').TransactionQueue;
55
var Remote = require('ripple-lib').Remote;
66
var Server = require('ripple-lib').Server;
7+
var sjcl = require('ripple-lib').sjcl;
78

89
var transactionResult = {
910
engine_result: 'tesSUCCESS',
@@ -35,6 +36,11 @@ var transactionResult = {
3536
};
3637

3738
describe('Transaction', function() {
39+
before(function() {
40+
sjcl.random.addEntropy(
41+
'3045022100A58B0460BC5092CB4F96155C19125A4E079C870663F1D5E8BBC9BD', 256);
42+
});
43+
3844
it('Success listener', function(done) {
3945
var transaction = new Transaction();
4046

0 commit comments

Comments
 (0)