summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortb <>2025-01-22 09:39:56 +0000
committertb <>2025-01-22 09:39:56 +0000
commit96a1e660b2205dd364475572ad5939f41dbf268e (patch)
treec04a50a7a91c89d282229e22b59cbe432f010d09 /src
parent17d58a5817a97aeba20512f824ec7f28f5a638cb (diff)
downloadopenbsd-96a1e660b2205dd364475572ad5939f41dbf268e.tar.gz
openbsd-96a1e660b2205dd364475572ad5939f41dbf268e.tar.bz2
openbsd-96a1e660b2205dd364475572ad5939f41dbf268e.zip
BN_mod_mul_reciprocal: remove y == NULL complication
No caller ever passes y == NULL, so remove the corresponding contortions and unindent the relevant bits. ok jsing
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/bn/bn_recp.c25
1 files changed, 11 insertions, 14 deletions
diff --git a/src/lib/libcrypto/bn/bn_recp.c b/src/lib/libcrypto/bn/bn_recp.c
index e7484f9f4b..8dd6b8af65 100644
--- a/src/lib/libcrypto/bn/bn_recp.c
+++ b/src/lib/libcrypto/bn/bn_recp.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_recp.c,v 1.26 2025/01/21 15:44:22 tb Exp $ */ 1/* $OpenBSD: bn_recp.c,v 1.27 2025/01/22 09:39:56 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 *
@@ -225,30 +225,27 @@ err:
225 return ret; 225 return ret;
226} 226}
227 227
228/* Compute r = (x * y) % m. */
228int 229int
229BN_mod_mul_reciprocal(BIGNUM *r, const BIGNUM *x, const BIGNUM *y, 230BN_mod_mul_reciprocal(BIGNUM *r, const BIGNUM *x, const BIGNUM *y,
230 BN_RECP_CTX *recp, BN_CTX *ctx) 231 BN_RECP_CTX *recp, BN_CTX *ctx)
231{ 232{
232 int ret = 0; 233 int ret = 0;
233 BIGNUM *a; 234 BIGNUM *a;
234 const BIGNUM *ca;
235 235
236 BN_CTX_start(ctx); 236 BN_CTX_start(ctx);
237 if ((a = BN_CTX_get(ctx)) == NULL) 237 if ((a = BN_CTX_get(ctx)) == NULL)
238 goto err; 238 goto err;
239 if (y != NULL) {
240 if (x == y) {
241 if (!BN_sqr(a, x, ctx))
242 goto err;
243 } else {
244 if (!BN_mul(a, x, y, ctx))
245 goto err;
246 }
247 ca = a;
248 } else
249 ca = x; /* Just do the mod */
250 239
251 ret = BN_div_recp(NULL, r, ca, recp, ctx); 240 if (x == y) {
241 if (!BN_sqr(a, x, ctx))
242 goto err;
243 } else {
244 if (!BN_mul(a, x, y, ctx))
245 goto err;
246 }
247
248 ret = BN_div_recp(NULL, r, a, recp, ctx);
252 249
253err: 250err:
254 BN_CTX_end(ctx); 251 BN_CTX_end(ctx);