diff --git a/crypto/bn/montgomery.c b/crypto/bn/montgomery.c index 078e9b42..7e4a76fb 100644 --- a/crypto/bn/montgomery.c +++ b/crypto/bn/montgomery.c @@ -410,23 +410,24 @@ static int BN_from_montgomery_word(BIGNUM *ret, BIGNUM *r, return 1; } -int BN_from_montgomery(BIGNUM *ret, const BIGNUM *a, const BN_MONT_CTX *mont, +int BN_from_montgomery(BIGNUM *r, const BIGNUM *a, const BN_MONT_CTX *mont, BN_CTX *ctx) { - int retn = 0; + int ret = 0; BIGNUM *t; BN_CTX_start(ctx); t = BN_CTX_get(ctx); - if (t == NULL) { - return 0; + if (t == NULL || + !BN_copy(t, a)) { + goto err; } - if (BN_copy(t, a)) { - retn = BN_from_montgomery_word(ret, t, mont); - } + ret = BN_from_montgomery_word(r, t, mont); + +err: BN_CTX_end(ctx); - return retn; + return ret; } int BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,