]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Fix EC_KEY_set_private_key() priv_key regression
authorRoberto Hueso Gomez <roberto@robertohueso.org>
Tue, 26 Jul 2022 18:41:02 +0000 (20:41 +0200)
committerNicola Tuveri <nic.tuv@gmail.com>
Thu, 4 Aug 2022 09:17:06 +0000 (12:17 +0300)
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/18942)

crypto/ec/ec_key.c

index 0ae1c3f367702cf5d99ff7c8711db450937b9361..1bbca360e2f5e3e3fe67e66a3e10bf635b7cf65d 100644 (file)
@@ -720,6 +720,16 @@ int EC_KEY_set_private_key(EC_KEY *key, const BIGNUM *priv_key)
         && key->meth->set_private(key, priv_key) == 0)
         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`