From: jsing Date: Sat, 7 Jan 2023 16:17:29 +0000 (+0000) Subject: Rewrite/simplify BN_free(). X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=a11cae131adf37a2b6887620bc6cf10af60399ae;p=openbsd Rewrite/simplify BN_free(). ok tb@ --- diff --git a/lib/libcrypto/bn/bn_lib.c b/lib/libcrypto/bn/bn_lib.c index 70b6899a427..e8802300ce7 100644 --- a/lib/libcrypto/bn/bn_lib.c +++ b/lib/libcrypto/bn/bn_lib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bn_lib.c,v 1.70 2023/01/07 16:13:46 jsing Exp $ */ +/* $OpenBSD: bn_lib.c,v 1.71 2023/01/07 16:17:29 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -97,18 +97,20 @@ BN_clear(BIGNUM *a) } void -BN_free(BIGNUM *a) +BN_free(BIGNUM *bn) { - int i; + if (bn == NULL) + return; - if (a == NULL) + if (!BN_get_flags(bn, BN_FLG_STATIC_DATA)) + freezero(bn->d, bn->dmax * sizeof(bn->d[0])); + + if (!BN_get_flags(bn, BN_FLG_MALLOCED)) { + explicit_bzero(bn, sizeof(*bn)); return; - if (a->d != NULL && !(BN_get_flags(a, BN_FLG_STATIC_DATA))) - freezero(a->d, a->dmax * sizeof(a->d[0])); - i = BN_get_flags(a, BN_FLG_MALLOCED); - explicit_bzero(a, sizeof(BIGNUM)); - if (i) - free(a); + } + + freezero(bn, sizeof(*bn)); } void