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.c36
1 files changed, 29 insertions, 7 deletions
diff --git a/src/lib/libcrypto/bn/bn_div.c b/src/lib/libcrypto/bn/bn_div.c
index fefc53f9fa..a8f7c9f384 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.23 2015/02/09 15:49:22 jsing Exp $ */ 1/* $OpenBSD: bn_div.c,v 1.24 2017/01/21 10:38:29 beck 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 *
@@ -116,9 +116,9 @@
116 * rm->neg == num->neg (unless the remainder is zero) 116 * rm->neg == num->neg (unless the remainder is zero)
117 * If 'dv' or 'rm' is NULL, the respective value is not returned. 117 * If 'dv' or 'rm' is NULL, the respective value is not returned.
118 */ 118 */
119int 119static int
120BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor, 120BN_div_internal(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,
121 BN_CTX *ctx) 121 BN_CTX *ctx, int ct)
122{ 122{
123 int norm_shift, i, loop; 123 int norm_shift, i, loop;
124 BIGNUM *tmp, wnum, *snum, *sdiv, *res; 124 BIGNUM *tmp, wnum, *snum, *sdiv, *res;
@@ -137,10 +137,8 @@ BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,
137 137
138 bn_check_top(num); 138 bn_check_top(num);
139 139
140 if ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0) || 140 if (ct)
141 (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0)) {
142 no_branch = 1; 141 no_branch = 1;
143 }
144 142
145 bn_check_top(dv); 143 bn_check_top(dv);
146 bn_check_top(rm); 144 bn_check_top(rm);
@@ -379,3 +377,27 @@ err:
379 BN_CTX_end(ctx); 377 BN_CTX_end(ctx);
380 return (0); 378 return (0);
381} 379}
380
381int
382BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,
383 BN_CTX *ctx)
384{
385 int ct = ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0) ||
386 (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0));
387
388 return BN_div_internal(dv, rm, num, divisor, ctx, ct);
389}
390
391int
392BN_div_nonct(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,
393 BN_CTX *ctx)
394{
395 return BN_div_internal(dv, rm, num, divisor, ctx, 0);
396}
397
398int
399BN_div_ct(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,
400 BN_CTX *ctx)
401{
402 return BN_div_internal(dv, rm, num, divisor, ctx, 1);
403}