summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/bn/bn_recp.c
diff options
context:
space:
mode:
authortb <>2025-01-22 10:08:10 +0000
committertb <>2025-01-22 10:08:10 +0000
commit2a03b7cb56aaed711ed59aee8972dbd1c4129344 (patch)
treec03d690e046eede7fc63ea2b3900a7b29ce1656e /src/lib/libcrypto/bn/bn_recp.c
parente7605a5f9628e0963785991b55f4323b645d578d (diff)
downloadopenbsd-2a03b7cb56aaed711ed59aee8972dbd1c4129344.tar.gz
openbsd-2a03b7cb56aaed711ed59aee8972dbd1c4129344.tar.bz2
openbsd-2a03b7cb56aaed711ed59aee8972dbd1c4129344.zip
Split BN_mod_sqr_reciprocal() out of BN_mod_mul_reciprocal()
There's no need for BN_mod_mul_reciprocal() to have this complication. The caller knows when x == y, so place the burden on the caller. This simplifies both the caller side and the implementation in bn_recp.c. ok jsing
Diffstat (limited to 'src/lib/libcrypto/bn/bn_recp.c')
-rw-r--r--src/lib/libcrypto/bn/bn_recp.c30
1 files changed, 12 insertions, 18 deletions
diff --git a/src/lib/libcrypto/bn/bn_recp.c b/src/lib/libcrypto/bn/bn_recp.c
index 8dd6b8af65..bf38380710 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.27 2025/01/22 09:39:56 tb Exp $ */ 1/* $OpenBSD: bn_recp.c,v 1.28 2025/01/22 10:08:10 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 *
@@ -230,24 +230,18 @@ int
230BN_mod_mul_reciprocal(BIGNUM *r, const BIGNUM *x, const BIGNUM *y, 230BN_mod_mul_reciprocal(BIGNUM *r, const BIGNUM *x, const BIGNUM *y,
231 BN_RECP_CTX *recp, BN_CTX *ctx) 231 BN_RECP_CTX *recp, BN_CTX *ctx)
232{ 232{
233 int ret = 0; 233 if (!BN_mul(r, x, y, ctx))
234 BIGNUM *a; 234 return 0;
235 235
236 BN_CTX_start(ctx); 236 return BN_div_recp(NULL, r, r, recp, ctx);
237 if ((a = BN_CTX_get(ctx)) == NULL) 237}
238 goto err;
239
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 238
248 ret = BN_div_recp(NULL, r, a, recp, ctx); 239/* Compute r = x^2 % m. */
240int
241BN_mod_sqr_reciprocal(BIGNUM *r, const BIGNUM *x, BN_RECP_CTX *recp, BN_CTX *ctx)
242{
243 if (!BN_sqr(r, x, ctx))
244 return 0;
249 245
250err: 246 return BN_div_recp(NULL, r, r, recp, ctx);
251 BN_CTX_end(ctx);
252 return ret;
253} 247}