diff options
Diffstat (limited to 'lib/libcrypto/bn/bn_div.c')
-rw-r--r-- | lib/libcrypto/bn/bn_div.c | 36 |
1 files changed, 29 insertions, 7 deletions
diff --git a/lib/libcrypto/bn/bn_div.c b/lib/libcrypto/bn/bn_div.c index fefc53f9fad..a8f7c9f3841 100644 --- a/lib/libcrypto/bn/bn_div.c +++ b/lib/libcrypto/bn/bn_div.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bn_div.c,v 1.23 2015/02/09 15:49:22 jsing Exp $ */ +/* $OpenBSD: bn_div.c,v 1.24 2017/01/21 10:38:29 beck Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -116,9 +116,9 @@ * rm->neg == num->neg (unless the remainder is zero) * If 'dv' or 'rm' is NULL, the respective value is not returned. */ -int -BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor, - BN_CTX *ctx) +static int +BN_div_internal(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor, + BN_CTX *ctx, int ct) { int norm_shift, i, loop; BIGNUM *tmp, wnum, *snum, *sdiv, *res; @@ -137,10 +137,8 @@ BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor, bn_check_top(num); - if ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0) || - (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0)) { + if (ct) no_branch = 1; - } bn_check_top(dv); bn_check_top(rm); @@ -379,3 +377,27 @@ err: BN_CTX_end(ctx); return (0); } + +int +BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor, + BN_CTX *ctx) +{ + int ct = ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0) || + (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0)); + + return BN_div_internal(dv, rm, num, divisor, ctx, ct); +} + +int +BN_div_nonct(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor, + BN_CTX *ctx) +{ + return BN_div_internal(dv, rm, num, divisor, ctx, 0); +} + +int +BN_div_ct(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor, + BN_CTX *ctx) +{ + return BN_div_internal(dv, rm, num, divisor, ctx, 1); +} |