summaryrefslogtreecommitdiffstats
path: root/lib/rsa.go
diff options
context:
space:
mode:
authorsiddharth ravikumar <s@ricketyspace.net>2024-10-14 19:16:11 -0400
committersiddharth ravikumar <s@ricketyspace.net>2024-10-14 19:16:11 -0400
commit32803d4577151e18252c7e2102738b544e99fcbc (patch)
tree5380965064b597ca72cbcc53d2689a27db1325ae /lib/rsa.go
parent0bede4cd60eafb508598ba2f6098f1792623f984 (diff)
lib: update `RSAGenKey`
Add `size` argument.
Diffstat (limited to 'lib/rsa.go')
-rw-r--r--lib/rsa.go7
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/rsa.go b/lib/rsa.go
index 772b898..9353824 100644
--- a/lib/rsa.go
+++ b/lib/rsa.go
@@ -68,7 +68,8 @@ func InvMod(a, n *big.Int) (*big.Int, error) {
return t0, nil
}
-func RSAGenKey() (*RSAPair, error) {
+// RSAGenKey generates a rsa key pair with N equal to size bits.
+func RSAGenKey(size int) (*RSAPair, error) {
// Initialize.
e := big.NewInt(3)
d := big.NewInt(0)
@@ -77,13 +78,13 @@ func RSAGenKey() (*RSAPair, error) {
// Compute n and d.
for {
// Generate prime p.
- p, err := rand.Prime(rand.Reader, 1024)
+ p, err := rand.Prime(rand.Reader, size/2)
if err != nil {
return nil, CPError{"unable to generate p"}
}
// Generate prime q.
- q, err := rand.Prime(rand.Reader, 1024)
+ q, err := rand.Prime(rand.Reader, size/2)
if err != nil {
return nil, CPError{"unable to generate q"}
}