Skip to content

Instantly share code, notes, and snippets.

@kunigami
Last active April 20, 2020 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kunigami/0e09bab60377dbd401151bf42f082b04 to your computer and use it in GitHub Desktop.
Save kunigami/0e09bab60377dbd401151bf42f082b04 to your computer and use it in GitHub Desktop.
if (bigvalue < a.length) {
value = a[bigvalue];
if (value & 1 > 0) {
x = a[100];
} else {
x = a[200];
}
}
// Timing attack
const t1 = performance.now();
const y1 = a[100];
const duration1 = performance.now() - t1;
const t2 = performance.now();
const y2 = a[200];
const duration2 = performance.now() - t2;
if (duration1 * 10 < duration2) {
// a[100] is cached, value & 1 = 1
} else if (duration2 * 10 < duration1) {
// a[200] is cached, value & 1 = 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment