diff options
| author | tb <> | 2025-01-22 10:08:10 +0000 |
|---|---|---|
| committer | tb <> | 2025-01-22 10:08:10 +0000 |
| commit | 08809e17ad814f4314ef0a7cc09287483156803b (patch) | |
| tree | c03d690e046eede7fc63ea2b3900a7b29ce1656e /src/lib/libcrypto/bn/bn_exp.c | |
| parent | 366d7bbfad8ab89b0d053361f974a01a882bd2df (diff) | |
| download | openbsd-08809e17ad814f4314ef0a7cc09287483156803b.tar.gz openbsd-08809e17ad814f4314ef0a7cc09287483156803b.tar.bz2 openbsd-08809e17ad814f4314ef0a7cc09287483156803b.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_exp.c')
| -rw-r--r-- | src/lib/libcrypto/bn/bn_exp.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/lib/libcrypto/bn/bn_exp.c b/src/lib/libcrypto/bn/bn_exp.c index 8ff518e938..129c12495c 100644 --- a/src/lib/libcrypto/bn/bn_exp.c +++ b/src/lib/libcrypto/bn/bn_exp.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: bn_exp.c,v 1.54 2025/01/21 15:44:22 tb Exp $ */ | 1 | /* $OpenBSD: bn_exp.c,v 1.55 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 | * |
| @@ -1023,7 +1023,7 @@ BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m, | |||
| 1023 | 1023 | ||
| 1024 | window = BN_window_bits_for_exponent_size(bits); | 1024 | window = BN_window_bits_for_exponent_size(bits); |
| 1025 | if (window > 1) { | 1025 | if (window > 1) { |
| 1026 | if (!BN_mod_mul_reciprocal(aa, val[0], val[0], recp, ctx)) | 1026 | if (!BN_mod_sqr_reciprocal(aa, val[0], recp, ctx)) |
| 1027 | goto err; | 1027 | goto err; |
| 1028 | j = 1 << (window - 1); | 1028 | j = 1 << (window - 1); |
| 1029 | for (i = 1; i < j; i++) { | 1029 | for (i = 1; i < j; i++) { |
| @@ -1047,7 +1047,7 @@ BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m, | |||
| 1047 | for (;;) { | 1047 | for (;;) { |
| 1048 | if (BN_is_bit_set(q, wstart) == 0) { | 1048 | if (BN_is_bit_set(q, wstart) == 0) { |
| 1049 | if (!start) | 1049 | if (!start) |
| 1050 | if (!BN_mod_mul_reciprocal(r, r, r, recp, ctx)) | 1050 | if (!BN_mod_sqr_reciprocal(r, r, recp, ctx)) |
| 1051 | goto err; | 1051 | goto err; |
| 1052 | if (wstart == 0) | 1052 | if (wstart == 0) |
| 1053 | break; | 1053 | break; |
| @@ -1076,7 +1076,7 @@ BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m, | |||
| 1076 | /* add the 'bytes above' */ | 1076 | /* add the 'bytes above' */ |
| 1077 | if (!start) | 1077 | if (!start) |
| 1078 | for (i = 0; i < j; i++) { | 1078 | for (i = 0; i < j; i++) { |
| 1079 | if (!BN_mod_mul_reciprocal(r, r, r, recp, ctx)) | 1079 | if (!BN_mod_sqr_reciprocal(r, r, recp, ctx)) |
| 1080 | goto err; | 1080 | goto err; |
| 1081 | } | 1081 | } |
| 1082 | 1082 | ||
