bn/bn_gf2m.c: make new BN_GF2m_mod_inv work with BN_DEBUG_RAND [from HEAD].
authorAndy Polyakov <appro@openssl.org>
Fri, 30 Mar 2012 17:41:00 +0000 (17:41 +0000)
committerAndy Polyakov <appro@openssl.org>
Fri, 30 Mar 2012 17:41:00 +0000 (17:41 +0000)
crypto/bn/bn_gf2m.c

index 08ab9fd22743578607119fa53fcb45c08b97fe5b..8a4dc20ad980d9b3bf9849bef739e0cedc3fcb7c 100644 (file)
@@ -628,8 +628,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);