Skip to content

Commit c7ba822

Browse files
Chris Clarkgeertweening
Chris Clark
authored andcommitted
Improve entropy security and increase CCM tag length
1 parent ef3ce46 commit c7ba822

File tree

3 files changed

+9
-21
lines changed

3 files changed

+9
-21
lines changed

src/js/ripple/crypt.js

+6-8
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var Crypt = { };
1212
var cryptConfig = {
1313
cipher : 'aes',
1414
mode : 'ccm',
15-
ts : 64, // tag length
15+
ts : 128, // tag length
1616
ks : 256, // key size
1717
iter : 1000 // iterations (key derivation)
1818
};
@@ -60,12 +60,9 @@ function keyHash(key, token) {
6060
* add entropy at each call to get random words
6161
* @param {number} nWords
6262
*/
63-
function randomWords (nWords) {
64-
for (var i = 0; i < 8; i++) {
65-
sjcl.random.addEntropy(Math.random(), 32, "Math.random()");
66-
}
67-
68-
return sjcl.random.randomWords(nWords);
63+
function randomWords(nWords) {
64+
var PARANOIA_256_BITS = 6; // sjcl constant for ensuring 256 bits of entropy
65+
return sjcl.random.randomWords(nWords, PARANOIA_256_BITS);
6966
}
7067

7168
/****** exposed functions ******/
@@ -113,9 +110,10 @@ Crypt.derive = function(opts, purpose, username, secret, fn) {
113110
}
114111

115112
var iRandom;
113+
var PARANOIA_256_BITS = 6; // sjcl constant for ensuring 256 bits of entropy
116114

117115
for (;;) {
118-
iRandom = sjcl.bn.random(iModulus, 0);
116+
iRandom = sjcl.bn.random(iModulus, PARANOIA_256_BITS);
119117
if (iRandom.jacobi(iModulus) === 1) {
120118
break;
121119
}

src/js/ripple/message.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ Message.signHash = function(hash, secret_key, account) {
6767
secret_key = Seed.from_json(secret_key).get_key(account)._secret;
6868
}
6969

70-
var signature_bits = secret_key.signWithRecoverablePublicKey(hash);
70+
var PARANOIA_256_BITS = 6; // sjcl constant for ensuring 256 bits of entropy
71+
var signature_bits = secret_key.signWithRecoverablePublicKey(hash,
72+
PARANOIA_256_BITS);
7173
var signature_base64 = sjcl.codec.base64.fromBits(signature_bits);
7274

7375
return signature_base64;

src/js/ripple/remote.js

-12
Original file line numberDiff line numberDiff line change
@@ -1760,19 +1760,7 @@ Remote.prototype._serverPrepareSubscribe = function(server, callback) {
17601760
function serverSubscribed(message) {
17611761
self._stand_alone = !!message.stand_alone;
17621762
self._testnet = !!message.testnet;
1763-
1764-
if (typeof message.random === 'string') {
1765-
var rand = message.random.match(/[0-9A-F]{8}/ig);
1766-
1767-
while (rand && rand.length) {
1768-
sjcl.random.addEntropy(parseInt(rand.pop(), 16));
1769-
}
1770-
1771-
self.emit('random', utils.hexToArray(message.random));
1772-
}
1773-
17741763
self._handleLedgerClosed(message, server);
1775-
17761764
self.emit('subscribed');
17771765
}
17781766

0 commit comments

Comments
 (0)