Skip to content

Commit

Permalink
Fix a SCA leak in BN_generate_dsa_nonce
Browse files Browse the repository at this point in the history
Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Nicola Tuveri <[email protected]>
(Merged from openssl#9782)
  • Loading branch information
bernd-edlinger committed Sep 6, 2019
1 parent d2baf88 commit 31ca194
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions crypto/bn/bn_rand.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,7 @@ int BN_generate_dsa_nonce(BIGNUM *out, const BIGNUM *range,
goto err;

/* We copy |priv| into a local buffer to avoid exposing its length. */
todo = sizeof(priv->d[0]) * priv->top;
if (todo > sizeof(private_bytes)) {
if (BN_bn2binpad(priv, private_bytes, sizeof(private_bytes)) < 0) {
/*
* No reasonable DSA or ECDSA key should have a private key this
* large and we don't handle this case in order to avoid leaking the
Expand All @@ -274,8 +273,6 @@ int BN_generate_dsa_nonce(BIGNUM *out, const BIGNUM *range,
BNerr(BN_F_BN_GENERATE_DSA_NONCE, BN_R_PRIVATE_KEY_TOO_LARGE);
goto err;
}
memcpy(private_bytes, priv->d, todo);
memset(private_bytes + todo, 0, sizeof(private_bytes) - todo);

md = EVP_MD_fetch(libctx, "SHA512", NULL);
if (md == NULL) {
Expand Down

0 comments on commit 31ca194

Please sign in to comment.