summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjsing <>2021-12-27 15:12:22 +0000
committerjsing <>2021-12-27 15:12:22 +0000
commit8340c867e544bc54b944619cd264a575571cd5c2 (patch)
tree8c5ef36ef64759af1adb206502927ac87a219d21
parentbeb5b6b62dcf79056f87d52d4e0654370cd670ad (diff)
downloadopenbsd-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@
-rw-r--r--src/lib/libcrypto/bn/bn_lib.c116
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) */
92static int bn_limit_bits_mont = 0; 92static int bn_limit_bits_mont = 0;
93static int bn_limit_num_mont = 8; /* (1<<bn_limit_bits_mont) */ 93static int bn_limit_num_mont = 8; /* (1<<bn_limit_bits_mont) */
94 94
95BIGNUM *
96BN_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
113void
114BN_init(BIGNUM *a)
115{
116 memset(a, 0, sizeof(BIGNUM));
117 bn_check_top(a);
118}
119
120void
121BN_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
130void
131BN_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
146void
147BN_free(BIGNUM *a)
148{
149 BN_clear_free(a);
150}
151
95void 152void
96BN_set_params(int mult, int high, int low, int mont) 153BN_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
209void
210BN_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
225void
226BN_free(BIGNUM *a)
227{
228 BN_clear_free(a);
229}
230
231void
232BN_init(BIGNUM *a)
233{
234 memset(a, 0, sizeof(BIGNUM));
235 bn_check_top(a);
236}
237
238BIGNUM *
239BN_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 */
258static BN_ULONG * 268static 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
521void
522BN_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
531BN_ULONG 531BN_ULONG
532BN_get_word(const BIGNUM *a) 532BN_get_word(const BIGNUM *a)
533{ 533{