kjur / jsrsasign

The 'jsrsasign' (RSA-Sign JavaScript Library) is an opensource free cryptography library supporting RSA/RSAPSS/ECDSA/DSA signing/validation, ASN.1, PKCS#1/5/8 private/public key, X.509 certificate, CRL, OCSP, CMS SignedData, TimeStamp, CAdES and JSON Web Signature/Token in pure JavaScript.
https://kjur.github.io/jsrsasign
Other
3.27k stars 643 forks source link

HS algo verification should use constant time comparison #309

Open davedoesdev opened 6 years ago

davedoesdev commented 6 years ago

https://github.com/kjur/jsrsasign/blob/master/src/jws-3.3.js#L484

to prevent timing attacks.

What about doing something like this?

// from https://github.com/goinstant/buffer-equal-constant-time/blob/master/index.js
var const_time_equal = function (s1, s2)
{
    "use strict";
    if (s1.length !== s2.length)
    {
        return false;
    }
    var i, c = 0;
    for (i = 0; i < s1.length; i += 1)
    {
        /*jslint bitwise: true */
        c |= s1.charCodeAt(i) ^ s2.charCodeAt(i); // XOR
        /*jslint bitwise: false */
    }
    return c === 0;
};
davedoesdev commented 6 years ago

Hi @kjur did you manage to do this in a release?