summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortb <>2024-11-15 08:49:07 +0000
committertb <>2024-11-15 08:49:07 +0000
commit636afcedc4ba1da9edad50f789eccdd0549bcf94 (patch)
tree700ee1472594cead5a7812a2922513748278ff91
parentdd6a5fc8d64e518e49055663d3e0e11a67d4b858 (diff)
downloadopenbsd-636afcedc4ba1da9edad50f789eccdd0549bcf94.tar.gz
openbsd-636afcedc4ba1da9edad50f789eccdd0549bcf94.tar.bz2
openbsd-636afcedc4ba1da9edad50f789eccdd0549bcf94.zip
EC_KEY_copy() don't leave stale private keys in place
As most other objects, EC_KEYs can be as sparsely and invalidly populated as imagination permits and the competent designers of EC_KEY_copy() chose to just copy over what's available (yeah, what kind of copy is that?) and leave in place what happens to be there. In particular, if the dest EC key was used with a different group and has a private key, but the source key doesn't, the dest private key remains intact, as invalid, incompatible and unusable as it may be. Fix this by clearing said private key. ok jsing
-rw-r--r--src/lib/libcrypto/ec/ec_key.c9
1 files changed, 3 insertions, 6 deletions
diff --git a/src/lib/libcrypto/ec/ec_key.c b/src/lib/libcrypto/ec/ec_key.c
index 1aef634349..662a7c0f49 100644
--- a/src/lib/libcrypto/ec/ec_key.c
+++ b/src/lib/libcrypto/ec/ec_key.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec_key.c,v 1.46 2024/11/08 22:10:18 tb Exp $ */ 1/* $OpenBSD: ec_key.c,v 1.47 2024/11/15 08:49:07 tb Exp $ */
2/* 2/*
3 * Written by Nils Larsch for the OpenSSL project. 3 * Written by Nils Larsch for the OpenSSL project.
4 */ 4 */
@@ -150,12 +150,9 @@ EC_KEY_copy(EC_KEY *dest, const EC_KEY *src)
150 } 150 }
151 } 151 }
152 152
153 /* 153 BN_free(dest->priv_key);
154 * XXX - if there's no priv_key on src, dest retains its probably 154 dest->priv_key = NULL;
155 * invalid priv_key. This makes no sense. Can we change this?
156 */
157 if (src->priv_key != NULL) { 155 if (src->priv_key != NULL) {
158 BN_free(dest->priv_key);
159 if ((dest->priv_key = BN_dup(src->priv_key)) == NULL) 156 if ((dest->priv_key = BN_dup(src->priv_key)) == NULL)
160 return NULL; 157 return NULL;
161 } 158 }