diff options
author | jsing <> | 2021-12-27 15:12:22 +0000 |
---|---|---|
committer | jsing <> | 2021-12-27 15:12:22 +0000 |
commit | 8340c867e544bc54b944619cd264a575571cd5c2 (patch) | |
tree | 8c5ef36ef64759af1adb206502927ac87a219d21 /src/lib | |
parent | beb5b6b62dcf79056f87d52d4e0654370cd670ad (diff) | |
download | openbsd-8340c867e544bc54b944619cd264a575571cd5c2.tar.gz openbsd-8340c867e544bc54b944619cd264a575571cd5c2.tar.bz2 openbsd-8340c867e544bc54b944619cd264a575571cd5c2.zip |
Pull BN_{new,init,clear,clear_free,free} up to the top of bn_lib.c
Discussed with tb@
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/libcrypto/bn/bn_lib.c | 116 |
1 files changed, 58 insertions, 58 deletions
diff --git a/src/lib/libcrypto/bn/bn_lib.c b/src/lib/libcrypto/bn/bn_lib.c index 2544722ea9..6e828f1e74 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.52 2021/12/04 16:02:44 tb Exp $ */ | 1 | /* $OpenBSD: bn_lib.c,v 1.53 2021/12/27 15:12:22 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 | * |
@@ -92,6 +92,63 @@ static int bn_limit_num_high = 8; /* (1<<bn_limit_bits_high) */ | |||
92 | static int bn_limit_bits_mont = 0; | 92 | static int bn_limit_bits_mont = 0; |
93 | static int bn_limit_num_mont = 8; /* (1<<bn_limit_bits_mont) */ | 93 | static int bn_limit_num_mont = 8; /* (1<<bn_limit_bits_mont) */ |
94 | 94 | ||
95 | BIGNUM * | ||
96 | BN_new(void) | ||
97 | { | ||
98 | BIGNUM *ret; | ||
99 | |||
100 | if ((ret = malloc(sizeof(BIGNUM))) == NULL) { | ||
101 | BNerror(ERR_R_MALLOC_FAILURE); | ||
102 | return (NULL); | ||
103 | } | ||
104 | ret->flags = BN_FLG_MALLOCED; | ||
105 | ret->top = 0; | ||
106 | ret->neg = 0; | ||
107 | ret->dmax = 0; | ||
108 | ret->d = NULL; | ||
109 | bn_check_top(ret); | ||
110 | return (ret); | ||
111 | } | ||
112 | |||
113 | void | ||
114 | BN_init(BIGNUM *a) | ||
115 | { | ||
116 | memset(a, 0, sizeof(BIGNUM)); | ||
117 | bn_check_top(a); | ||
118 | } | ||
119 | |||
120 | void | ||
121 | BN_clear(BIGNUM *a) | ||
122 | { | ||
123 | bn_check_top(a); | ||
124 | if (a->d != NULL) | ||
125 | explicit_bzero(a->d, a->dmax * sizeof(a->d[0])); | ||
126 | a->top = 0; | ||
127 | a->neg = 0; | ||
128 | } | ||
129 | |||
130 | void | ||
131 | BN_clear_free(BIGNUM *a) | ||
132 | { | ||
133 | int i; | ||
134 | |||
135 | if (a == NULL) | ||
136 | return; | ||
137 | bn_check_top(a); | ||
138 | if (a->d != NULL && !(BN_get_flags(a, BN_FLG_STATIC_DATA))) | ||
139 | freezero(a->d, a->dmax * sizeof(a->d[0])); | ||
140 | i = BN_get_flags(a, BN_FLG_MALLOCED); | ||
141 | explicit_bzero(a, sizeof(BIGNUM)); | ||
142 | if (i) | ||
143 | free(a); | ||
144 | } | ||
145 | |||
146 | void | ||
147 | BN_free(BIGNUM *a) | ||
148 | { | ||
149 | BN_clear_free(a); | ||
150 | } | ||
151 | |||
95 | void | 152 | void |
96 | BN_set_params(int mult, int high, int low, int mont) | 153 | BN_set_params(int mult, int high, int low, int mont) |
97 | { | 154 | { |
@@ -206,53 +263,6 @@ BN_num_bits(const BIGNUM *a) | |||
206 | return ((i * BN_BITS2) + BN_num_bits_word(a->d[i])); | 263 | return ((i * BN_BITS2) + BN_num_bits_word(a->d[i])); |
207 | } | 264 | } |
208 | 265 | ||
209 | void | ||
210 | BN_clear_free(BIGNUM *a) | ||
211 | { | ||
212 | int i; | ||
213 | |||
214 | if (a == NULL) | ||
215 | return; | ||
216 | bn_check_top(a); | ||
217 | if (a->d != NULL && !(BN_get_flags(a, BN_FLG_STATIC_DATA))) | ||
218 | freezero(a->d, a->dmax * sizeof(a->d[0])); | ||
219 | i = BN_get_flags(a, BN_FLG_MALLOCED); | ||
220 | explicit_bzero(a, sizeof(BIGNUM)); | ||
221 | if (i) | ||
222 | free(a); | ||
223 | } | ||
224 | |||
225 | void | ||
226 | BN_free(BIGNUM *a) | ||
227 | { | ||
228 | BN_clear_free(a); | ||
229 | } | ||
230 | |||
231 | void | ||
232 | BN_init(BIGNUM *a) | ||
233 | { | ||
234 | memset(a, 0, sizeof(BIGNUM)); | ||
235 | bn_check_top(a); | ||
236 | } | ||
237 | |||
238 | BIGNUM * | ||
239 | BN_new(void) | ||
240 | { | ||
241 | BIGNUM *ret; | ||
242 | |||
243 | if ((ret = malloc(sizeof(BIGNUM))) == NULL) { | ||
244 | BNerror(ERR_R_MALLOC_FAILURE); | ||
245 | return (NULL); | ||
246 | } | ||
247 | ret->flags = BN_FLG_MALLOCED; | ||
248 | ret->top = 0; | ||
249 | ret->neg = 0; | ||
250 | ret->dmax = 0; | ||
251 | ret->d = NULL; | ||
252 | bn_check_top(ret); | ||
253 | return (ret); | ||
254 | } | ||
255 | |||
256 | /* This is used both by bn_expand2() and bn_dup_expand() */ | 266 | /* This is used both by bn_expand2() and bn_dup_expand() */ |
257 | /* The caller MUST check that words > b->dmax before calling this */ | 267 | /* The caller MUST check that words > b->dmax before calling this */ |
258 | static BN_ULONG * | 268 | static BN_ULONG * |
@@ -518,16 +528,6 @@ BN_swap(BIGNUM *a, BIGNUM *b) | |||
518 | bn_check_top(b); | 528 | bn_check_top(b); |
519 | } | 529 | } |
520 | 530 | ||
521 | void | ||
522 | BN_clear(BIGNUM *a) | ||
523 | { | ||
524 | bn_check_top(a); | ||
525 | if (a->d != NULL) | ||
526 | explicit_bzero(a->d, a->dmax * sizeof(a->d[0])); | ||
527 | a->top = 0; | ||
528 | a->neg = 0; | ||
529 | } | ||
530 | |||
531 | BN_ULONG | 531 | BN_ULONG |
532 | BN_get_word(const BIGNUM *a) | 532 | BN_get_word(const BIGNUM *a) |
533 | { | 533 | { |