Skip to content

Commit a4daaec

Browse files
author
tb
committed
bn_mod_exp: we have a BN_CTX available...
Use BN_CTX_get() instead of BN_new()/BN_free().
1 parent 2b745f2 commit a4daaec

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

src/regress/lib/libcrypto/bn/bn_mod_exp.c

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: bn_mod_exp.c,v 1.3 2022/12/02 17:42:45 tb Exp $ */
1+
/* $OpenBSD: bn_mod_exp.c,v 1.4 2022/12/02 18:24:01 tb Exp $ */
22
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
33
* All rights reserved.
44
*
@@ -82,23 +82,26 @@ main(int argc, char *argv[])
8282

8383
if ((ctx = BN_CTX_new()) == NULL)
8484
goto err;
85-
if ((r_mont = BN_new()) == NULL)
85+
86+
BN_CTX_start(ctx);
87+
88+
if ((r_mont = BN_CTX_get(ctx)) == NULL)
8689
goto err;
87-
if ((r_mont_const = BN_new()) == NULL)
90+
if ((r_mont_const = BN_CTX_get(ctx)) == NULL)
8891
goto err;
89-
if ((r_mont_ct = BN_new()) == NULL)
92+
if ((r_mont_ct = BN_CTX_get(ctx)) == NULL)
9093
goto err;
91-
if ((r_mont_nonct = BN_new()) == NULL)
94+
if ((r_mont_nonct = BN_CTX_get(ctx)) == NULL)
9295
goto err;
93-
if ((r_recp = BN_new()) == NULL)
96+
if ((r_recp = BN_CTX_get(ctx)) == NULL)
9497
goto err;
95-
if ((r_simple = BN_new()) == NULL)
98+
if ((r_simple = BN_CTX_get(ctx)) == NULL)
9699
goto err;
97-
if ((a = BN_new()) == NULL)
100+
if ((a = BN_CTX_get(ctx)) == NULL)
98101
goto err;
99-
if ((b = BN_new()) == NULL)
102+
if ((b = BN_CTX_get(ctx)) == NULL)
100103
goto err;
101-
if ((m = BN_new()) == NULL)
104+
if ((m = BN_CTX_get(ctx)) == NULL)
102105
goto err;
103106

104107
if ((out = BIO_new(BIO_s_file())) == NULL)
@@ -194,15 +197,8 @@ main(int argc, char *argv[])
194197
exit(1);
195198
}
196199
}
197-
BN_free(r_mont);
198-
BN_free(r_mont_const);
199-
BN_free(r_mont_ct);
200-
BN_free(r_mont_nonct);
201-
BN_free(r_recp);
202-
BN_free(r_simple);
203-
BN_free(a);
204-
BN_free(b);
205-
BN_free(m);
200+
201+
BN_CTX_end(ctx);
206202
BN_CTX_free(ctx);
207203
ERR_remove_thread_state(NULL);
208204
CRYPTO_mem_leaks(out);

0 commit comments

Comments
 (0)