diff options
author | Roberto Hueso Gomez <roberto@robertohueso.org> | 2022-07-26 20:41:02 +0200 |
---|---|---|
committer | Nicola Tuveri <nic.tuv@gmail.com> | 2022-08-04 12:21:18 +0300 |
commit | f76cf4d9885e0d39aa1d200ba851173939fd0bb6 (patch) | |
tree | 08fcc4f1426d7ff75a85143ad607d76597f449c3 /crypto/ec | |
parent | b0501275ef56950bd77950dac1382357d91f8e7f (diff) |
Fix EC_KEY_set_private_key() priv_key regression
This allows to set EC_KEY's private key to NULL and fixes regression
issue following OTC guideline in
https://github.com/openssl/openssl/issues/18744#issuecomment-1195175696
Fixes #18744.
Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com>
Reviewed-by: Todd Short <todd.short@me.com>
(Merged from https://github.com/openssl/openssl/pull/18941)
Diffstat (limited to 'crypto/ec')
-rw-r--r-- | crypto/ec/ec_key.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/crypto/ec/ec_key.c b/crypto/ec/ec_key.c index 979fde116d..729d338b33 100644 --- a/crypto/ec/ec_key.c +++ b/crypto/ec/ec_key.c @@ -721,6 +721,16 @@ int EC_KEY_set_private_key(EC_KEY *key, const BIGNUM *priv_key) return 0; /* + * Return `0` to comply with legacy behavior for this function, see + * https://github.com/openssl/openssl/issues/18744#issuecomment-1195175696 + */ + if (priv_key == NULL) { + BN_clear_free(key->priv_key); + key->priv_key = NULL; + return 0; /* intentional for legacy compatibility */ + } + + /* * We should never leak the bit length of the secret scalar in the key, * so we always set the `BN_FLG_CONSTTIME` flag on the internal `BIGNUM` * holding the secret scalar. |