Closed scriby closed 10 years ago
thanks, @scriby. do you think it would be sufficient to keep it light by .map
ing the signatures and then doing an .indexOf
instead?
Can you show a code example of what you're thinking?
this.index = function(data, digest) {
var signKey = sign.bind(null, data)
return keys.map(signKey).indexOf(digest)
}
Ah, I don't think that solves the problem. The problem is in comparing the signature strings themselves, so the indexOf will have the same issue when comparing the digest to the array elements.
I think you just have to replace
if (digest === sign(data, keys[i])) return i
with
if(constantTimeCompare(digest, sign(data, keys[i])) return i
sounds good. would you mind teeing up a pull request?
https://github.com/jed/keygrip/blob/master/index.js#L38
That line uses a short circuiting comparison, which reveals timing information about the key used to an attacker. See http://codahale.com/a-lesson-in-timing-attacks/ for more details.
Here's a constant time comparison function you can use: