|
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 $ */ |
2 | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
3 | 3 | * All rights reserved.
|
4 | 4 | *
|
@@ -82,23 +82,26 @@ main(int argc, char *argv[])
|
82 | 82 |
|
83 | 83 | if ((ctx = BN_CTX_new()) == NULL)
|
84 | 84 | 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) |
86 | 89 | goto err;
|
87 |
| - if ((r_mont_const = BN_new()) == NULL) |
| 90 | + if ((r_mont_const = BN_CTX_get(ctx)) == NULL) |
88 | 91 | goto err;
|
89 |
| - if ((r_mont_ct = BN_new()) == NULL) |
| 92 | + if ((r_mont_ct = BN_CTX_get(ctx)) == NULL) |
90 | 93 | goto err;
|
91 |
| - if ((r_mont_nonct = BN_new()) == NULL) |
| 94 | + if ((r_mont_nonct = BN_CTX_get(ctx)) == NULL) |
92 | 95 | goto err;
|
93 |
| - if ((r_recp = BN_new()) == NULL) |
| 96 | + if ((r_recp = BN_CTX_get(ctx)) == NULL) |
94 | 97 | goto err;
|
95 |
| - if ((r_simple = BN_new()) == NULL) |
| 98 | + if ((r_simple = BN_CTX_get(ctx)) == NULL) |
96 | 99 | goto err;
|
97 |
| - if ((a = BN_new()) == NULL) |
| 100 | + if ((a = BN_CTX_get(ctx)) == NULL) |
98 | 101 | goto err;
|
99 |
| - if ((b = BN_new()) == NULL) |
| 102 | + if ((b = BN_CTX_get(ctx)) == NULL) |
100 | 103 | goto err;
|
101 |
| - if ((m = BN_new()) == NULL) |
| 104 | + if ((m = BN_CTX_get(ctx)) == NULL) |
102 | 105 | goto err;
|
103 | 106 |
|
104 | 107 | if ((out = BIO_new(BIO_s_file())) == NULL)
|
@@ -194,15 +197,8 @@ main(int argc, char *argv[])
|
194 | 197 | exit(1);
|
195 | 198 | }
|
196 | 199 | }
|
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); |
206 | 202 | BN_CTX_free(ctx);
|
207 | 203 | ERR_remove_thread_state(NULL);
|
208 | 204 | CRYPTO_mem_leaks(out);
|
|
0 commit comments