From eb436e38563783b901c271d5779d35ecad7c45f9 Mon Sep 17 00:00:00 2001 From: siddharth ravikumar Date: Sun, 14 Aug 2022 13:04:06 -0400 Subject: lib: update TestInvMod Add new tests. --- lib/rsa_test.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/lib/rsa_test.go b/lib/rsa_test.go index 4f65468..6e04ee7 100644 --- a/lib/rsa_test.go +++ b/lib/rsa_test.go @@ -58,6 +58,7 @@ func TestInvMod(t *testing.T) { i, err := invmod(a, b) if err != nil { t.Errorf("invmod(%v,%v) failed: %v", a, b, err) + return } if i.Cmp(e) != 0 { t.Errorf("gcd(%v,%v) != %v", a, b, e) @@ -69,6 +70,31 @@ func TestInvMod(t *testing.T) { i, err = invmod(a, b) if err != nil { t.Errorf("invmod(%v,%v) failed: %v", a, b, err) + return + } + if i.Cmp(e) != 0 { + t.Errorf("gcd(%v,%v) != %v", a, b, e) + } + + a = big.NewInt(11) + b = big.NewInt(26) + e = big.NewInt(19) // Expected inverse. + i, err = invmod(a, b) + if err != nil { + t.Errorf("invmod(%v,%v) failed: %v", a, b, err) + return + } + if i.Cmp(e) != 0 { + t.Errorf("gcd(%v,%v) != %v", a, b, e) + } + + a = big.NewInt(3) + b = big.NewInt(7) + e = big.NewInt(5) // Expected inverse. + i, err = invmod(a, b) + if err != nil { + t.Errorf("invmod(%v,%v) failed: %v", a, b, err) + return } if i.Cmp(e) != 0 { t.Errorf("gcd(%v,%v) != %v", a, b, e) -- cgit v1.2.3