summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/rsa_test.go26
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)