Make our binary comparisons constant time (#2047)

This commit is contained in:
Scott Nonnenberg 2018-02-14 12:15:26 -08:00 committed by GitHub
parent 4033a9f813
commit 2cfdaca3c1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 6 deletions

View file

@ -32,13 +32,13 @@
if (ab1.byteLength !== ab2.byteLength) {
return false;
}
var result = true;
var result = 0;
var ta1 = new Uint8Array(ab1);
var ta2 = new Uint8Array(ab2);
for (var i = 0; i < ab1.byteLength; ++i) {
if (ta1[i] !== ta2[i]) { result = false; }
result = result | ta1[i] ^ ta2[i];
}
return result;
return result === 0;
}
Whisper.Conversation = Backbone.Model.extend({

View file

@ -78,13 +78,13 @@
if (ab1.byteLength !== ab2.byteLength) {
return false;
}
var result = true;
var result = 0;
var ta1 = new Uint8Array(ab1);
var ta2 = new Uint8Array(ab2);
for (var i = 0; i < ab1.byteLength; ++i) {
if (ta1[i] !== ta2[i]) { result = false; }
result = result | ta1[i] ^ ta2[i];
}
return result;
return result === 0;
}
var Model = Backbone.Model.extend({ database: Whisper.Database });