BN_mod_exp_mont_consttime: check for zero modulus.
[openssl.git] / crypto / bn / bn_exp.c
index 10dc3eb35843b5650ee468d18a29b9d1cf67ede2..66feddcf962daf67bf21174f6caad2d86c3830c7 100644 (file)
@@ -662,12 +662,13 @@ int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,
     bn_check_top(p);
     bn_check_top(m);
 
-    top = m->top;
-
-    if (!(m->d[0] & 1)) {
+    if (!BN_is_odd(m)) {
         BNerr(BN_F_BN_MOD_EXP_MONT_CONSTTIME, BN_R_CALLED_WITH_EVEN_MODULUS);
         return (0);
     }
+
+    top = m->top;
+
     bits = BN_num_bits(p);
     if (bits == 0) {
         ret = BN_one(rr);