diff options
author | tb <> | 2025-02-13 11:04:20 +0000 |
---|---|---|
committer | tb <> | 2025-02-13 11:04:20 +0000 |
commit | ade8722cf772f75a9dd24ace7878bf2f0730171c (patch) | |
tree | 6331480d1d99f90f319b23c696f38c97cf3908da | |
parent | 70b5e4a9ddfad29232b45bb7cfe175cb06edf1a7 (diff) | |
download | openbsd-ade8722cf772f75a9dd24ace7878bf2f0730171c.tar.gz openbsd-ade8722cf772f75a9dd24ace7878bf2f0730171c.tar.bz2 openbsd-ade8722cf772f75a9dd24ace7878bf2f0730171c.zip |
bn: add internal BN_MONT_CTX_create()
This does what the public BN_MONT_CTX_new() should have done in the first
place rather than doing the toolkit thing of returning an invalid object
that you need to figure out how to populate and with what because the docs
are abysmal.
It takes the required arguments and calls BN_MONT_CTX_set(), which all
callers do immediately after _new() (except for DSA which managed to
squeeze 170 lines of garbage between the two calls).
ok jsing
-rw-r--r-- | src/lib/libcrypto/bn/bn_local.h | 4 | ||||
-rw-r--r-- | src/lib/libcrypto/bn/bn_mont.c | 20 |
2 files changed, 22 insertions, 2 deletions
diff --git a/src/lib/libcrypto/bn/bn_local.h b/src/lib/libcrypto/bn/bn_local.h index 4b42ae95ee..067ffab3d9 100644 --- a/src/lib/libcrypto/bn/bn_local.h +++ b/src/lib/libcrypto/bn/bn_local.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bn_local.h,v 1.49 2025/02/12 21:21:34 tb Exp $ */ | 1 | /* $OpenBSD: bn_local.h,v 1.50 2025/02/13 11:04:20 tb 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 | * |
@@ -271,6 +271,8 @@ int bn_rand_interval(BIGNUM *rnd, BN_ULONG lower_word, const BIGNUM *upper_exc); | |||
271 | 271 | ||
272 | void BN_init(BIGNUM *); | 272 | void BN_init(BIGNUM *); |
273 | 273 | ||
274 | BN_MONT_CTX *BN_MONT_CTX_create(const BIGNUM *bn, BN_CTX *ctx); | ||
275 | |||
274 | BN_RECP_CTX *BN_RECP_CTX_create(const BIGNUM *N); | 276 | BN_RECP_CTX *BN_RECP_CTX_create(const BIGNUM *N); |
275 | void BN_RECP_CTX_free(BN_RECP_CTX *recp); | 277 | void BN_RECP_CTX_free(BN_RECP_CTX *recp); |
276 | int BN_div_reciprocal(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, | 278 | int BN_div_reciprocal(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, |
diff --git a/src/lib/libcrypto/bn/bn_mont.c b/src/lib/libcrypto/bn/bn_mont.c index c7e2eefb58..cfdc7e510f 100644 --- a/src/lib/libcrypto/bn/bn_mont.c +++ b/src/lib/libcrypto/bn/bn_mont.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bn_mont.c,v 1.63 2024/03/26 04:23:04 jsing Exp $ */ | 1 | /* $OpenBSD: bn_mont.c,v 1.64 2025/02/13 11:04:20 tb 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 | * |
@@ -154,6 +154,24 @@ BN_MONT_CTX_free(BN_MONT_CTX *mctx) | |||
154 | LCRYPTO_ALIAS(BN_MONT_CTX_free); | 154 | LCRYPTO_ALIAS(BN_MONT_CTX_free); |
155 | 155 | ||
156 | BN_MONT_CTX * | 156 | BN_MONT_CTX * |
157 | BN_MONT_CTX_create(const BIGNUM *bn, BN_CTX *bn_ctx) | ||
158 | { | ||
159 | BN_MONT_CTX *mctx; | ||
160 | |||
161 | if ((mctx = BN_MONT_CTX_new()) == NULL) | ||
162 | goto err; | ||
163 | if (!BN_MONT_CTX_set(mctx, bn, bn_ctx)) | ||
164 | goto err; | ||
165 | |||
166 | return mctx; | ||
167 | |||
168 | err: | ||
169 | BN_MONT_CTX_free(mctx); | ||
170 | |||
171 | return NULL; | ||
172 | } | ||
173 | |||
174 | BN_MONT_CTX * | ||
157 | BN_MONT_CTX_copy(BN_MONT_CTX *dst, BN_MONT_CTX *src) | 175 | BN_MONT_CTX_copy(BN_MONT_CTX *dst, BN_MONT_CTX *src) |
158 | { | 176 | { |
159 | if (dst == src) | 177 | if (dst == src) |