Remove fips_constseg references.
[openssl.git] / crypto / bn / bn_gf2m.c
index 7189ae5d82d8d845022c616c926234cda0398ac1..7b6b95c19c1df3544eca2e87b758733cac9ee765 100644 (file)
@@ -524,7 +524,7 @@ err:
  */
 int BN_GF2m_mod_inv(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
        {
-       BIGNUM *b, *c, *u, *v, *tmp;
+       BIGNUM *b, *c = NULL, *u = NULL, *v = NULL, *tmp;
        int ret = 0;
 
        bn_check_top(a);
@@ -630,8 +630,11 @@ int BN_GF2m_mod_inv(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
                        }
                if (ubits==vbits)
                        {
-                       bn_correct_top(u);
-                       ubits = BN_num_bits(u);
+                       BN_ULONG ul;
+                       int utop = (ubits-1)/BN_BITS2;
+
+                       while ((ul=udp[utop])==0 && utop) utop--;
+                       ubits = utop*BN_BITS2 + BN_num_bits_word(ul);
                        }
                }
        bn_correct_top(b);
@@ -643,6 +646,11 @@ int BN_GF2m_mod_inv(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
        ret = 1;
 
 err:
+#ifdef BN_DEBUG /* BN_CTX_end would complain about the expanded form */
+        bn_correct_top(c);
+        bn_correct_top(u);
+        bn_correct_top(v);
+#endif
        BN_CTX_end(ctx);
        return ret;
        }