Make our binary comparisons constant time (#2047)
This commit is contained in:
parent
4033a9f813
commit
2cfdaca3c1
2 changed files with 6 additions and 6 deletions
|
@ -32,13 +32,13 @@
|
||||||
if (ab1.byteLength !== ab2.byteLength) {
|
if (ab1.byteLength !== ab2.byteLength) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
var result = true;
|
var result = 0;
|
||||||
var ta1 = new Uint8Array(ab1);
|
var ta1 = new Uint8Array(ab1);
|
||||||
var ta2 = new Uint8Array(ab2);
|
var ta2 = new Uint8Array(ab2);
|
||||||
for (var i = 0; i < ab1.byteLength; ++i) {
|
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({
|
Whisper.Conversation = Backbone.Model.extend({
|
||||||
|
|
|
@ -78,13 +78,13 @@
|
||||||
if (ab1.byteLength !== ab2.byteLength) {
|
if (ab1.byteLength !== ab2.byteLength) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
var result = true;
|
var result = 0;
|
||||||
var ta1 = new Uint8Array(ab1);
|
var ta1 = new Uint8Array(ab1);
|
||||||
var ta2 = new Uint8Array(ab2);
|
var ta2 = new Uint8Array(ab2);
|
||||||
for (var i = 0; i < ab1.byteLength; ++i) {
|
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 });
|
var Model = Backbone.Model.extend({ database: Whisper.Database });
|
||||||
|
|
Loading…
Reference in a new issue