summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-09-04 13:43:45 +0200
committerDimitri Sokolyuk <demon@dim13.org>2015-09-04 13:43:45 +0200
commit90743adf4c0b32ad6508d1e8517813f55e10085a (patch)
tree91d61f38f8f6335644f294f6ad7ba77554932d1a
parent3c8364d1493f1a8a917a4e218d774268154df34e (diff)
Update seed
-rw-r--r--main.go31
1 files changed, 16 insertions, 15 deletions
diff --git a/main.go b/main.go
index c2a89aa..0f2cde0 100644
--- a/main.go
+++ b/main.go
@@ -1,6 +1,6 @@
package main
-//go:generate openssl genrsa -out test.key 64
+//go:generate openssl genrsa -out test.key 48
import (
"crypto/rsa"
@@ -42,19 +42,6 @@ func prev(N *big.Int) <-chan *big.Int {
return ch
}
-func pubKey(f string) rsa.PublicKey {
- file, err := ioutil.ReadFile(f)
- if err != nil {
- log.Fatal(err)
- }
- block, _ := pem.Decode(file)
- key, err := x509.ParsePKCS1PrivateKey(block.Bytes)
- if err != nil {
- log.Fatal(err)
- }
- return key.PublicKey
-}
-
func factor(N *big.Int) (*big.Int, *big.Int) {
p, q := seed(N)
nxt := next(p)
@@ -76,10 +63,24 @@ func factor(N *big.Int) (*big.Int, *big.Int) {
func seed(N *big.Int) (*big.Int, *big.Int) {
p := mathutil.SqrtBig(N)
p.SetBit(p, 0, 1) // ensure it's odd
- q := new(big.Int).Set(p)
+ q := new(big.Int).Div(N, p)
+ q.SetBit(p, 0, 1) // ensure it's odd
return p, q
}
+func pubKey(f string) rsa.PublicKey {
+ file, err := ioutil.ReadFile(f)
+ if err != nil {
+ log.Fatal(err)
+ }
+ block, _ := pem.Decode(file)
+ key, err := x509.ParsePKCS1PrivateKey(block.Bytes)
+ if err != nil {
+ log.Fatal(err)
+ }
+ return key.PublicKey
+}
+
func main() {
pub := pubKey("test.key")
fmt.Println(factor(pub.N))