diff options
author | jsing <> | 2023-01-07 16:17:29 +0000 |
---|---|---|
committer | jsing <> | 2023-01-07 16:17:29 +0000 |
commit | 096ef5ab2a7243f1cd6cb8aaaa679dce8b766cdf (patch) | |
tree | ab972a1588a39e12a9b25e946d3436640b3d01c3 | |
parent | 647a51042d43cddabf51a51f62a8a250a284f399 (diff) | |
download | openbsd-096ef5ab2a7243f1cd6cb8aaaa679dce8b766cdf.tar.gz openbsd-096ef5ab2a7243f1cd6cb8aaaa679dce8b766cdf.tar.bz2 openbsd-096ef5ab2a7243f1cd6cb8aaaa679dce8b766cdf.zip |
Rewrite/simplify BN_free().
ok tb@
-rw-r--r-- | src/lib/libcrypto/bn/bn_lib.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/src/lib/libcrypto/bn/bn_lib.c b/src/lib/libcrypto/bn/bn_lib.c index 70b6899a42..e8802300ce 100644 --- a/src/lib/libcrypto/bn/bn_lib.c +++ b/src/lib/libcrypto/bn/bn_lib.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bn_lib.c,v 1.70 2023/01/07 16:13:46 jsing Exp $ */ | 1 | /* $OpenBSD: bn_lib.c,v 1.71 2023/01/07 16:17:29 jsing Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -97,18 +97,20 @@ BN_clear(BIGNUM *a) | |||
97 | } | 97 | } |
98 | 98 | ||
99 | void | 99 | void |
100 | BN_free(BIGNUM *a) | 100 | BN_free(BIGNUM *bn) |
101 | { | 101 | { |
102 | int i; | 102 | if (bn == NULL) |
103 | return; | ||
103 | 104 | ||
104 | if (a == NULL) | 105 | if (!BN_get_flags(bn, BN_FLG_STATIC_DATA)) |
106 | freezero(bn->d, bn->dmax * sizeof(bn->d[0])); | ||
107 | |||
108 | if (!BN_get_flags(bn, BN_FLG_MALLOCED)) { | ||
109 | explicit_bzero(bn, sizeof(*bn)); | ||
105 | return; | 110 | return; |
106 | if (a->d != NULL && !(BN_get_flags(a, BN_FLG_STATIC_DATA))) | 111 | } |
107 | freezero(a->d, a->dmax * sizeof(a->d[0])); | 112 | |
108 | i = BN_get_flags(a, BN_FLG_MALLOCED); | 113 | freezero(bn, sizeof(*bn)); |
109 | explicit_bzero(a, sizeof(BIGNUM)); | ||
110 | if (i) | ||
111 | free(a); | ||
112 | } | 114 | } |
113 | 115 | ||
114 | void | 116 | void |