Copy getRandomBytes from libaxolotl to libtextsecure

This commit is contained in:
Matt Corallo 2015-01-15 21:57:48 -10:00 committed by lilia
parent 12844590f5
commit 7d2d2d92fc
4 changed files with 14 additions and 11 deletions

View file

@ -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;

View file

@ -78,6 +78,12 @@
return encryptedBin.buffer;
});
});
},
getRandomBytes: function(size) {
var array = new Uint8Array(size);
window.crypto.getRandomValues(array);
return array.buffer;
}
};
})();

View file

@ -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);

View file

@ -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;