diff options
author | siddharth ravikumar <s@ricketyspace.net> | 2022-08-14 13:04:06 -0400 |
---|---|---|
committer | siddharth ravikumar <s@ricketyspace.net> | 2022-08-14 13:04:06 -0400 |
commit | eb436e38563783b901c271d5779d35ecad7c45f9 (patch) | |
tree | 5111eac5aadfcf6a206179314845b2246508a9a2 /lib/rsa_test.go | |
parent | e12ccae7a96c01dce5e86aa17c27e20644c75a15 (diff) |
lib: update TestInvMod
Add new tests.
Diffstat (limited to 'lib/rsa_test.go')
-rw-r--r-- | lib/rsa_test.go | 26 |
1 files changed, 26 insertions, 0 deletions
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) |