diff --git a/libaxolotl/crypto.js b/libaxolotl/crypto.js index e73db018..8205f3e6 100644 --- a/libaxolotl/crypto.js +++ b/libaxolotl/crypto.js @@ -24,9 +24,6 @@ window.axolotl.crypto = { getRandomBytes: function(size) { - // At some point we might consider XORing in hashes of random - // UI events to strengthen ourselves against RNG flaws in crypto.getRandomValues - // ie maybe take a look at how Gibson does it at https://www.grc.com/r&d/js.htm var array = new Uint8Array(size); window.crypto.getRandomValues(array); return array.buffer; diff --git a/libtextsecure/crypto.js b/libtextsecure/crypto.js index e735fcb1..c88e9721 100644 --- a/libtextsecure/crypto.js +++ b/libtextsecure/crypto.js @@ -78,6 +78,12 @@ return encryptedBin.buffer; }); }); + }, + + getRandomBytes: function(size) { + var array = new Uint8Array(size); + window.crypto.getRandomValues(array); + return array.buffer; } }; })(); diff --git a/libtextsecure/helpers.js b/libtextsecure/helpers.js index d3d3c7d7..99f5d433 100644 --- a/libtextsecure/helpers.js +++ b/libtextsecure/helpers.js @@ -242,14 +242,14 @@ textsecure.processDecrypted = function(decrypted, source) { } window.textsecure.registerSingleDevice = function(number, verificationCode, stepDone) { - var signalingKey = axolotl.crypto.getRandomBytes(32 + 20); + var signalingKey = textsecure.crypto.getRandomBytes(32 + 20); textsecure.storage.putEncrypted('signaling_key', signalingKey); - var password = btoa(getString(axolotl.crypto.getRandomBytes(16))); + var password = btoa(getString(textsecure.crypto.getRandomBytes(16))); password = password.substring(0, password.length - 2); textsecure.storage.putEncrypted("password", password); - var registrationId = new Uint16Array(axolotl.crypto.getRandomBytes(2))[0]; + var registrationId = new Uint16Array(textsecure.crypto.getRandomBytes(2))[0]; registrationId = registrationId & 0x3fff; textsecure.storage.putUnencrypted("registrationId", registrationId); @@ -273,14 +273,14 @@ window.textsecure.registerSecondDevice = function(encodedProvisionEnvelope, cryp return cryptoInfo.decryptAndHandleDeviceInit(envelope).then(function(identityKey) { stepDone(1); - var signalingKey = axolotl.crypto.getRandomBytes(32 + 20); + var signalingKey = textsecure.crypto.getRandomBytes(32 + 20); textsecure.storage.putEncrypted('signaling_key', signalingKey); - var password = btoa(getString(axolotl.crypto.getRandomBytes(16))); + var password = btoa(getString(textsecure.crypto.getRandomBytes(16))); password = password.substring(0, password.length - 2); textsecure.storage.putEncrypted("password", password); - var registrationId = new Uint16Array(axolotl.crypto.getRandomBytes(2))[0]; + var registrationId = new Uint16Array(textsecure.crypto.getRandomBytes(2))[0]; registrationId = registrationId & 0x3fff; textsecure.storage.putUnencrypted("registrationId", registrationId); diff --git a/libtextsecure/sendmessage.js b/libtextsecure/sendmessage.js index 2d496f58..604e1369 100644 --- a/libtextsecure/sendmessage.js +++ b/libtextsecure/sendmessage.js @@ -232,9 +232,9 @@ window.textsecure.messaging = function() { makeAttachmentPointer = function(attachment) { var proto = new textsecure.protobuf.PushMessageContent.AttachmentPointer(); - proto.key = axolotl.crypto.getRandomBytes(64); + proto.key = textsecure.crypto.getRandomBytes(64); - var iv = axolotl.crypto.getRandomBytes(16); + var iv = textsecure.crypto.getRandomBytes(16); return textsecure.crypto.encryptAttachment(attachment.data, proto.key, iv).then(function(encryptedBin) { return textsecure.api.putAttachment(encryptedBin).then(function(id) { proto.id = id;