Skip to content

Commit 1398e7c

Browse files
committed
Merge pull-request 23 (constant-time compare)
2 parents ad29a87 + baed640 commit 1398e7c

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lib/srp.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,16 @@ function getM2(params, A_buf, M_buf, K_buf) {
317317
}
318318

319319
function equal(buf1, buf2) {
320-
// TODO: constant-time comparison. A drop in the ocean compared to our
320+
// constant-time comparison. A drop in the ocean compared to our
321321
// non-constant-time modexp operations, but still good practice.
322-
return buf1.toString('hex') === buf2.toString('hex');
322+
var mismatch = buf1.length - buf2.length;
323+
if (mismatch) {
324+
return false;
325+
}
326+
for (var i = 0; i < buf1.length; i++) {
327+
mismatch |= buf1[i] ^ buf2[i];
328+
}
329+
return mismatch === 0;
323330
}
324331

325332
function Client(params, salt_buf, identity_buf, password_buf, secret1_buf) {

0 commit comments

Comments
 (0)