Return an error from BN_mod_inverse if n is 1 (or -1)
[openssl.git] / crypto / bn / bn_gcd.c
index 22f80939d61eaa4361fa7db7692f7ec9df1fd563..6d8c565575d552a1d3cb200c08f812e05156ae0e 100644 (file)
@@ -140,7 +140,14 @@ BIGNUM *int_bn_mod_inverse(BIGNUM *in,
     BIGNUM *ret = NULL;
     int sign;
 
-    if (pnoinv)
+    /* This is invalid input so we don't worry about constant time here */
+    if (BN_abs_is_word(n, 1) || BN_is_zero(n)) {
+        if (pnoinv != NULL)
+            *pnoinv = 1;
+        return NULL;
+    }
+
+    if (pnoinv != NULL)
         *pnoinv = 0;
 
     if ((BN_get_flags(a, BN_FLG_CONSTTIME) != 0)