diff options
-rw-r--r-- | src/lib/libcrypto/bn/bn_recp.c | 25 |
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. */ | ||
228 | int | 229 | int |
229 | BN_mod_mul_reciprocal(BIGNUM *r, const BIGNUM *x, const BIGNUM *y, | 230 | BN_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 | ||
253 | err: | 250 | err: |
254 | BN_CTX_end(ctx); | 251 | BN_CTX_end(ctx); |