Skip to content

Commit

Permalink
#5 Start with encapsulation of key generation code into separate func…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
quapka committed Mar 8, 2019
1 parent d2e25eb commit 4df2ee9
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions gen-keys/generate_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,35 @@ func main() {
}

reader := rand.Reader
dataRow := ""

for id := 0; id < keyCount; id++ {
dataRow = fmt.Sprintf("%d;", id)

start := time.Now()
key, rsaerr := rsa.GenerateKey(reader, bitSize)
end := time.Now()
t1 := end.Sub(start)
if algorithm == "rsa" {
start := time.Now()
key, rsaerr := rsa.GenerateKey(reader, bitSize)
end := time.Now()
t1 := end.Sub(start)

checkError(rsaerr)
checkError(rsaerr)

publicKey := key.PublicKey
publicKey := key.PublicKey

var n = publicKey.N
var e = publicKey.E
var d = key.D
var p = key.Primes[0]
var q = key.Primes[1]
var n = publicKey.N
var e = publicKey.E
var d = key.D
var p = key.Primes[0]
var q = key.Primes[1]

dataRow += fmt.Sprintf("%x;%x;%x;%x;%x;%d;\n", n, e, d, p, q, t1)

} else if algorithm == "ecc" {
log.Fatal("Not implemented yet.")
}

// Write keys
if _, err := f.Write([]byte(fmt.Sprintf("%d;%x;%x;%x;%x;%x;%d;\n", id, n, e, d, p, q, t1))); err != nil {
if _, err := f.Write([]byte(dataRow)); err != nil {
log.Fatal(err)
}

Expand Down

0 comments on commit 4df2ee9

Please sign in to comment.