summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/bn/bn_div.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/bn/bn_div.c')
-rw-r--r--src/lib/libcrypto/bn/bn_div.c17
1 files changed, 2 insertions, 15 deletions
diff --git a/src/lib/libcrypto/bn/bn_div.c b/src/lib/libcrypto/bn/bn_div.c
index f641386eb8..288ec92ef4 100644
--- a/src/lib/libcrypto/bn/bn_div.c
+++ b/src/lib/libcrypto/bn/bn_div.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_div.c,v 1.26 2022/11/24 01:30:01 jsing Exp $ */ 1/* $OpenBSD: bn_div.c,v 1.27 2022/11/26 13:56:33 jsing 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 *
@@ -127,23 +127,16 @@ BN_div_internal(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor
127 int num_n, div_n; 127 int num_n, div_n;
128 int no_branch = 0; 128 int no_branch = 0;
129 129
130 /* Invalid zero-padding would have particularly bad consequences 130 /* Invalid zero-padding would have particularly bad consequences. */
131 * in the case of 'num', so don't just rely on bn_check_top() for this one
132 * (bn_check_top() works only for BN_DEBUG builds) */
133 if (num->top > 0 && num->d[num->top - 1] == 0) { 131 if (num->top > 0 && num->d[num->top - 1] == 0) {
134 BNerror(BN_R_NOT_INITIALIZED); 132 BNerror(BN_R_NOT_INITIALIZED);
135 return 0; 133 return 0;
136 } 134 }
137 135
138 bn_check_top(num);
139 136
140 if (ct) 137 if (ct)
141 no_branch = 1; 138 no_branch = 1;
142 139
143 bn_check_top(dv);
144 bn_check_top(rm);
145 /* bn_check_top(num); */ /* 'num' has been checked already */
146 bn_check_top(divisor);
147 140
148 if (BN_is_zero(divisor)) { 141 if (BN_is_zero(divisor)) {
149 BNerror(BN_R_DIV_BY_ZERO); 142 BNerror(BN_R_DIV_BY_ZERO);
@@ -234,10 +227,6 @@ BN_div_internal(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor
234 227
235 if (!no_branch) { 228 if (!no_branch) {
236 if (BN_ucmp(&wnum, sdiv) >= 0) { 229 if (BN_ucmp(&wnum, sdiv) >= 0) {
237 /* If BN_DEBUG_RAND is defined BN_ucmp changes (via
238 * bn_pollute) the const bignum arguments =>
239 * clean the values between top and max again */
240 bn_clear_top2max(&wnum);
241 bn_sub_words(wnum.d, wnum.d, sdiv->d, div_n); 230 bn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);
242 *resp = 1; 231 *resp = 1;
243 } else 232 } else
@@ -365,7 +354,6 @@ BN_div_internal(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor
365 BN_rshift(rm, snum, norm_shift); 354 BN_rshift(rm, snum, norm_shift);
366 if (!BN_is_zero(rm)) 355 if (!BN_is_zero(rm))
367 rm->neg = neg; 356 rm->neg = neg;
368 bn_check_top(rm);
369 } 357 }
370 if (no_branch) 358 if (no_branch)
371 bn_correct_top(res); 359 bn_correct_top(res);
@@ -373,7 +361,6 @@ BN_div_internal(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor
373 return (1); 361 return (1);
374 362
375err: 363err:
376 bn_check_top(rm);
377 BN_CTX_end(ctx); 364 BN_CTX_end(ctx);
378 return (0); 365 return (0);
379} 366}