summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authortb <>2023-05-04 13:51:59 +0000
committertb <>2023-05-04 13:51:59 +0000
commite3c1dd7076a51b72841ed695f4e5ef951ed13317 (patch)
tree3d40bcae9802c25e4b67e88b71ddaf435853b462 /src/lib
parent1c4c17f353740a60425b1b54272d5a8fef5387cf (diff)
downloadopenbsd-e3c1dd7076a51b72841ed695f4e5ef951ed13317.tar.gz
openbsd-e3c1dd7076a51b72841ed695f4e5ef951ed13317.tar.bz2
openbsd-e3c1dd7076a51b72841ed695f4e5ef951ed13317.zip
Rewrite ECParameters_dup()
This should leak slightly less than the direct expansion of ASN1_dup_of(). Use freezero() since the DER could contain a private key. ok jsing
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libcrypto/ec/ec_lib.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/lib/libcrypto/ec/ec_lib.c b/src/lib/libcrypto/ec/ec_lib.c
index f560aa9991..308a0f0061 100644
--- a/src/lib/libcrypto/ec/ec_lib.c
+++ b/src/lib/libcrypto/ec/ec_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec_lib.c,v 1.56 2023/04/25 19:53:30 tb Exp $ */ 1/* $OpenBSD: ec_lib.c,v 1.57 2023/05/04 13:51:59 tb Exp $ */
2/* 2/*
3 * Originally written by Bodo Moeller for the OpenSSL project. 3 * Originally written by Bodo Moeller for the OpenSSL project.
4 */ 4 */
@@ -1459,15 +1459,20 @@ ec_group_simple_order_bits(const EC_GROUP *group)
1459EC_KEY * 1459EC_KEY *
1460ECParameters_dup(EC_KEY *key) 1460ECParameters_dup(EC_KEY *key)
1461{ 1461{
1462 unsigned char *p = NULL; 1462 const unsigned char *p;
1463 EC_KEY *k = NULL; 1463 unsigned char *der = NULL;
1464 EC_KEY *dup = NULL;
1464 int len; 1465 int len;
1465 1466
1466 if (key == NULL) 1467 if (key == NULL)
1467 return (NULL); 1468 return NULL;
1469
1470 if ((len = i2d_ECParameters(key, &der)) <= 0)
1471 return NULL;
1468 1472
1469 if ((len = i2d_ECParameters(key, &p)) > 0) 1473 p = der;
1470 k = d2i_ECParameters(NULL, (const unsigned char **)&p, len); 1474 dup = d2i_ECParameters(NULL, &p, len);
1475 freezero(der, len);
1471 1476
1472 return (k); 1477 return dup;
1473} 1478}