Skip to content

Commit e2260e9

Browse files
rvaggTrott
authored andcommitted
deps: float 415c3356 from openssl (DSA vulnerability)
Low severity timing vulnerability in the DSA signature algorithm Publicly disclosed but unreleased, pending OpenSSL 1.1.0j, not deemed severe enough to be assigned a CVE #. Ref: openssl/openssl#7487 PR-URL: https://github.com/nodejs/node/pull/??? Upstream: openssl/openssl@415c3356 Original commit message: DSA mod inverse fix There is a side channel attack against the division used to calculate one of the modulo inverses in the DSA algorithm. This change takes advantage of the primality of the modulo and Fermat's little theorem to calculate the inverse without leaking information. Thanks to Samuel Weiser for finding and reporting this. Reviewed-by: Matthias St. Pierre <[email protected]> Reviewed-by: Bernd Edlinger <[email protected]> (Merged from openssl/openssl#7487) PR-URL: #23965 Reviewed-By: Ujjwal Sharma <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent c1e6703 commit e2260e9

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

deps/openssl/openssl/crypto/dsa/dsa_ossl.c

+31-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ static int dsa_do_verify(const unsigned char *dgst, int dgst_len,
2525
DSA_SIG *sig, DSA *dsa);
2626
static int dsa_init(DSA *dsa);
2727
static int dsa_finish(DSA *dsa);
28+
static BIGNUM *dsa_mod_inverse_fermat(const BIGNUM *k, const BIGNUM *q,
29+
BN_CTX *ctx);
2830

2931
static DSA_METHOD openssl_dsa_meth = {
3032
"OpenSSL DSA method",
@@ -261,7 +263,7 @@ static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in,
261263
goto err;
262264

263265
/* Compute part of 's = inv(k) (m + xr) mod q' */
264-
if ((kinv = BN_mod_inverse(NULL, k, dsa->q, ctx)) == NULL)
266+
if ((kinv = dsa_mod_inverse_fermat(k, dsa->q, ctx)) == NULL)
265267
goto err;
266268

267269
BN_clear_free(*kinvp);
@@ -395,3 +397,31 @@ static int dsa_finish(DSA *dsa)
395397
BN_MONT_CTX_free(dsa->method_mont_p);
396398
return (1);
397399
}
400+
401+
/*
402+
* Compute the inverse of k modulo q.
403+
* Since q is prime, Fermat's Little Theorem applies, which reduces this to
404+
* mod-exp operation. Both the exponent and modulus are public information
405+
* so a mod-exp that doesn't leak the base is sufficient. A newly allocated
406+
* BIGNUM is returned which the caller must free.
407+
*/
408+
static BIGNUM *dsa_mod_inverse_fermat(const BIGNUM *k, const BIGNUM *q,
409+
BN_CTX *ctx)
410+
{
411+
BIGNUM *res = NULL;
412+
BIGNUM *r, *e;
413+
414+
if ((r = BN_new()) == NULL)
415+
return NULL;
416+
417+
BN_CTX_start(ctx);
418+
if ((e = BN_CTX_get(ctx)) != NULL
419+
&& BN_set_word(r, 2)
420+
&& BN_sub(e, q, r)
421+
&& BN_mod_exp_mont(r, k, e, q, ctx, NULL))
422+
res = r;
423+
else
424+
BN_free(r);
425+
BN_CTX_end(ctx);
426+
return res;
427+
}

0 commit comments

Comments
 (0)