X-Git-Url: https://git.openssl.org/gitweb/?a=blobdiff_plain;f=crypto%2Fbn%2Fbn_gcd.c;h=45b417bddc3d171988988e7dee908962feb2bb9f;hb=879bd6e38cad7fc932b37ca0b3ceb34d582910f6;hp=4a352119ba8aafc0a7164f14337df2e09837de32;hpb=6f1a3a310c35b74691c9f91442d204d52b4ddbcb;p=openssl.git diff --git a/crypto/bn/bn_gcd.c b/crypto/bn/bn_gcd.c index 4a352119ba..45b417bddc 100644 --- a/crypto/bn/bn_gcd.c +++ b/crypto/bn/bn_gcd.c @@ -205,13 +205,28 @@ err: /* solves ax == 1 (mod n) */ static BIGNUM *BN_mod_inverse_no_branch(BIGNUM *in, const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx); + BIGNUM *BN_mod_inverse(BIGNUM *in, const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx) { + BIGNUM *rv; + int noinv; + rv = int_bn_mod_inverse(in, a, n, ctx, &noinv); + if (noinv) + BNerr(BN_F_BN_MOD_INVERSE,BN_R_NO_INVERSE); + return rv; + } + +BIGNUM *int_bn_mod_inverse(BIGNUM *in, + const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx, int *pnoinv) + { BIGNUM *A,*B,*X,*Y,*M,*D,*T,*R=NULL; BIGNUM *ret=NULL; int sign; + if (pnoinv) + *pnoinv = 0; + if ((BN_get_flags(a, BN_FLG_CONSTTIME) != 0) || (BN_get_flags(n, BN_FLG_CONSTTIME) != 0)) { return BN_mod_inverse_no_branch(in, a, n, ctx); @@ -488,7 +503,8 @@ BIGNUM *BN_mod_inverse(BIGNUM *in, } else { - BNerr(BN_F_BN_MOD_INVERSE,BN_R_NO_INVERSE); + if (pnoinv) + *pnoinv = 1; goto err; } ret=R;