Don't recompute outgoing message padding
We can use the same padded plaintext across multiple numbers or attempts rather than re-creating it every time we encrypt to a particular number. // FREEBIE
This commit is contained in:
parent
30201969be
commit
d47ced1199
2 changed files with 30 additions and 16 deletions
|
@ -38798,20 +38798,27 @@ OutgoingMessage.prototype = {
|
||||||
return messagePartCount * 160;
|
return messagePartCount * 160;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getPlaintext: function() {
|
||||||
|
if (!this.plaintext) {
|
||||||
|
var messageBuffer = this.message.toArrayBuffer();
|
||||||
|
this.plaintext = new Uint8Array(
|
||||||
|
this.getPaddedMessageLength(messageBuffer.byteLength + 1) - 1
|
||||||
|
);
|
||||||
|
this.plaintext.set(new Uint8Array(messageBuffer));
|
||||||
|
this.plaintext[messageBuffer.byteLength] = 0x80;
|
||||||
|
}
|
||||||
|
return this.plaintext;
|
||||||
|
},
|
||||||
|
|
||||||
doSendMessage: function(number, deviceIds, recurse) {
|
doSendMessage: function(number, deviceIds, recurse) {
|
||||||
var ciphers = {};
|
var ciphers = {};
|
||||||
var plaintext = this.message.toArrayBuffer();
|
var plaintext = this.getPlaintext();
|
||||||
var paddedPlaintext = new Uint8Array(
|
|
||||||
this.getPaddedMessageLength(plaintext.byteLength + 1) - 1
|
|
||||||
);
|
|
||||||
paddedPlaintext.set(new Uint8Array(plaintext));
|
|
||||||
paddedPlaintext[plaintext.byteLength] = 0x80;
|
|
||||||
|
|
||||||
return Promise.all(deviceIds.map(function(deviceId) {
|
return Promise.all(deviceIds.map(function(deviceId) {
|
||||||
var address = new libsignal.SignalProtocolAddress(number, deviceId);
|
var address = new libsignal.SignalProtocolAddress(number, deviceId);
|
||||||
var sessionCipher = new libsignal.SessionCipher(textsecure.storage.protocol, address);
|
var sessionCipher = new libsignal.SessionCipher(textsecure.storage.protocol, address);
|
||||||
ciphers[address.getDeviceId()] = sessionCipher;
|
ciphers[address.getDeviceId()] = sessionCipher;
|
||||||
return sessionCipher.encrypt(paddedPlaintext).then(function(ciphertext) {
|
return sessionCipher.encrypt(plaintext).then(function(ciphertext) {
|
||||||
return {
|
return {
|
||||||
type : ciphertext.type,
|
type : ciphertext.type,
|
||||||
destinationDeviceId : address.getDeviceId(),
|
destinationDeviceId : address.getDeviceId(),
|
||||||
|
|
|
@ -119,20 +119,27 @@ OutgoingMessage.prototype = {
|
||||||
return messagePartCount * 160;
|
return messagePartCount * 160;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getPlaintext: function() {
|
||||||
|
if (!this.plaintext) {
|
||||||
|
var messageBuffer = this.message.toArrayBuffer();
|
||||||
|
this.plaintext = new Uint8Array(
|
||||||
|
this.getPaddedMessageLength(messageBuffer.byteLength + 1) - 1
|
||||||
|
);
|
||||||
|
this.plaintext.set(new Uint8Array(messageBuffer));
|
||||||
|
this.plaintext[messageBuffer.byteLength] = 0x80;
|
||||||
|
}
|
||||||
|
return this.plaintext;
|
||||||
|
},
|
||||||
|
|
||||||
doSendMessage: function(number, deviceIds, recurse) {
|
doSendMessage: function(number, deviceIds, recurse) {
|
||||||
var ciphers = {};
|
var ciphers = {};
|
||||||
var plaintext = this.message.toArrayBuffer();
|
var plaintext = this.getPlaintext();
|
||||||
var paddedPlaintext = new Uint8Array(
|
|
||||||
this.getPaddedMessageLength(plaintext.byteLength + 1) - 1
|
|
||||||
);
|
|
||||||
paddedPlaintext.set(new Uint8Array(plaintext));
|
|
||||||
paddedPlaintext[plaintext.byteLength] = 0x80;
|
|
||||||
|
|
||||||
return Promise.all(deviceIds.map(function(deviceId) {
|
return Promise.all(deviceIds.map(function(deviceId) {
|
||||||
var address = new libsignal.SignalProtocolAddress(number, deviceId);
|
var address = new libsignal.SignalProtocolAddress(number, deviceId);
|
||||||
var sessionCipher = new libsignal.SessionCipher(textsecure.storage.protocol, address);
|
var sessionCipher = new libsignal.SessionCipher(textsecure.storage.protocol, address);
|
||||||
ciphers[address.getDeviceId()] = sessionCipher;
|
ciphers[address.getDeviceId()] = sessionCipher;
|
||||||
return sessionCipher.encrypt(paddedPlaintext).then(function(ciphertext) {
|
return sessionCipher.encrypt(plaintext).then(function(ciphertext) {
|
||||||
return {
|
return {
|
||||||
type : ciphertext.type,
|
type : ciphertext.type,
|
||||||
destinationDeviceId : address.getDeviceId(),
|
destinationDeviceId : address.getDeviceId(),
|
||||||
|
|
Loading…
Reference in a new issue