Make BN_mod_inverse a little faster
[openssl.git] / crypto / bn / bn_gcd.c
index d53f32656b2e84927109a1415030d734d7a30834..d361ada8b2183be3465698ee78737e3872493692 100644 (file)
@@ -338,15 +338,15 @@ BIGNUM *BN_mod_inverse(BIGNUM *in,
                                {
                                if (!BN_lshift1(tmp,X)) goto err;
                                }
-                       else if (BN_is_word(D,3))
-                               {
-                               if (!BN_lshift1(tmp,X)) goto err;
-                               if (!BN_add(tmp,tmp,X)) goto err;
-                               }
                        else if (BN_is_word(D,4))
                                {
                                if (!BN_lshift(tmp,X,2)) goto err;
                                }
+                       else if (D->top == 1)
+                               {
+                               if (!BN_copy(tmp,X)) goto err;
+                               if (!BN_mul_word(tmp,D->d[0])) goto err;
+                               }
                        else
                                {
                                if (!BN_mul(tmp,D,X,ctx)) goto err;