diff options
Diffstat (limited to 'crypto/bn/bn_test.cc')
-rw-r--r-- | crypto/bn/bn_test.cc | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/crypto/bn/bn_test.cc b/crypto/bn/bn_test.cc index 3405cbdc..20f64d6c 100644 --- a/crypto/bn/bn_test.cc +++ b/crypto/bn/bn_test.cc @@ -584,6 +584,33 @@ static bool TestModSqrt(FileTest *t, BN_CTX *ctx) { return true; } +static bool TestModInv(FileTest *t, BN_CTX *ctx) { + ScopedBIGNUM a = GetBIGNUM(t, "A"); + ScopedBIGNUM m = GetBIGNUM(t, "M"); + ScopedBIGNUM mod_inv = GetBIGNUM(t, "ModInv"); + if (!a || !m || !mod_inv) { + return false; + } + + ScopedBIGNUM ret(BN_new()); + if (!ret || + !BN_mod_inverse(ret.get(), a.get(), m.get(), ctx) || + !ExpectBIGNUMsEqual(t, "inv(A) (mod M)", mod_inv.get(), ret.get())) { + return false; + } + + BN_set_flags(a.get(), BN_FLG_CONSTTIME); + + if (!ret || + !BN_mod_inverse(ret.get(), a.get(), m.get(), ctx) || + !ExpectBIGNUMsEqual(t, "inv(A) (mod M) (constant-time)", mod_inv.get(), + ret.get())) { + return false; + } + + return true; +} + struct Test { const char *name; bool (*func)(FileTest *t, BN_CTX *ctx); @@ -601,6 +628,7 @@ static const Test kTests[] = { {"ModExp", TestModExp}, {"Exp", TestExp}, {"ModSqrt", TestModSqrt}, + {"ModInv", TestModInv}, }; static bool RunTest(FileTest *t, void *arg) { |