summaryrefslogtreecommitdiffstats
path: root/lib/rsa_test.go
diff options
context:
space:
mode:
authorsiddharth ravikumar <s@ricketyspace.net>2022-08-14 13:05:53 -0400
committersiddharth ravikumar <s@ricketyspace.net>2022-08-14 13:05:53 -0400
commit3aadff0d4782858afb687593ba54a6066467c95d (patch)
treef166a13e56e1d81f036a7eb99f7d409826f17abb /lib/rsa_test.go
parenteb436e38563783b901c271d5779d35ecad7c45f9 (diff)
lib: add `RSAGenKey`
Diffstat (limited to 'lib/rsa_test.go')
-rw-r--r--lib/rsa_test.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/rsa_test.go b/lib/rsa_test.go
index 6e04ee7..f735f75 100644
--- a/lib/rsa_test.go
+++ b/lib/rsa_test.go
@@ -100,3 +100,39 @@ func TestInvMod(t *testing.T) {
t.Errorf("gcd(%v,%v) != %v", a, b, e)
}
}
+
+func TestRSAGenKey(t *testing.T) {
+ pair, err := RSAGenKey()
+ if err != nil {
+ t.Errorf("genkey: %v", err)
+ return
+ }
+ if pair.Public == nil {
+ t.Error("genkey: pub key is nil")
+ return
+ }
+ if pair.Public.e.Cmp(big.NewInt(0)) < 1 {
+ t.Error("genkey: e is invalid")
+ return
+ }
+ if pair.Public.n.Cmp(big.NewInt(0)) < 1 {
+ t.Error("genkey: n is invalid")
+ return
+ }
+ if pair.Private == nil {
+ t.Error("genkey: private key is nil")
+ return
+ }
+ if pair.Private.d.Cmp(big.NewInt(0)) < 1 {
+ t.Error("genkey: d is invalid")
+ return
+ }
+ if pair.Private.n.Cmp(big.NewInt(0)) < 1 {
+ t.Error("genkey: n is invalid")
+ return
+ }
+ if pair.Public.n.Cmp(pair.Private.n) != 0 {
+ t.Error("genkey: public.n != private.n")
+ return
+ }
+}