sidh_torture/csidh/cmd/torturer/main.go
2019-04-12 11:53:30 +01:00

87 lines
1.8 KiB
Go

package main
import (
"bytes"
"fmt"
"time"
"github.com/henrydcase/nobs/dh/csidh"
"github.com/henrydcase/nobs/drbg"
"github.com/henrydcase/sidh_torture/csidh/ref/go-wrapper"
)
var rng *drbg.CtrDrbg
func TestSS() {
var r wrapper.Ref
var ssRef [csidh.SharedSecretSize]byte
var ss [csidh.SharedSecretSize]byte
// Go types
prA := r.KeygenPrv()
pkA := r.KeygenPub(&prA)
prB := csidh.NewPrivateKey()
pkB := csidh.NewPublicKey()
prB.Generate(rng)
pkB.Generate(&prB)
s1 := time.Now()
// Generate with Go
pkB.DeriveSecret(ss[:], &pkA, &prB)
s2 := time.Since(s1)
// Generate with C
s1 = time.Now()
r.Derive(ssRef[:], &pkB, &prA)
s3 := time.Since(s1)
fmt.Printf("|TestSharedSecret | %.8s | %.8s |\n", s2, s3)
if !bytes.Equal(ss[:], ssRef[:]) {
panic("TestSS")
}
}
func TestKeyGeneration() {
var r wrapper.Ref
var ssRef [csidh.SharedSecretSize]byte
var ss [csidh.SharedSecretSize]byte
// Go types
prA := csidh.NewPrivateKey()
pkA := csidh.NewPublicKey()
prB := csidh.NewPrivateKey()
pkB := csidh.NewPublicKey()
prA.Generate(rng)
pkA.Generate(&prA)
prB.Generate(rng)
pkB.Generate(&prB)
s1 := time.Now()
// Generate with Go
r.Derive(ss[:], &pkA, &prB)
s2 := time.Since(s1)
// Generate with C
s1 = time.Now()
r.Derive(ssRef[:], &pkB, &prA)
s3 := time.Since(s1)
fmt.Printf("|TestKeyGeneration | %.8s | %.8s |\n", s2, s3)
if !bytes.Equal(ss[:], ssRef[:]) {
panic("TestKeyGeneration")
}
}
func main() {
fmt.Printf("| TestName |Go | C |\n")
fmt.Printf("|------------------|----------|----------|\n")
rng = drbg.NewCtrDrbg()
for {
TestSS()
TestKeyGeneration()
}
}