2019-01-30 16:17:20 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/henrydcase/nobs/dh/csidh"
|
2019-04-12 11:53:30 +01:00
|
|
|
"github.com/henrydcase/nobs/drbg"
|
2019-04-10 00:26:12 +01:00
|
|
|
"github.com/henrydcase/sidh_torture/csidh/ref/go-wrapper"
|
2019-01-30 16:17:20 +00:00
|
|
|
)
|
|
|
|
|
2019-04-12 11:53:30 +01:00
|
|
|
var rng *drbg.CtrDrbg
|
|
|
|
|
2019-01-30 16:17:20 +00:00
|
|
|
func TestSS() {
|
|
|
|
var r wrapper.Ref
|
2019-01-30 20:30:11 +00:00
|
|
|
var ssRef [csidh.SharedSecretSize]byte
|
|
|
|
var ss [csidh.SharedSecretSize]byte
|
2019-11-22 18:05:18 +00:00
|
|
|
var prB csidh.PrivateKey
|
|
|
|
var pkB csidh.PublicKey
|
2019-01-30 16:17:20 +00:00
|
|
|
|
|
|
|
// Go types
|
|
|
|
prA := r.KeygenPrv()
|
|
|
|
pkA := r.KeygenPub(&prA)
|
|
|
|
|
2019-11-22 18:05:18 +00:00
|
|
|
csidh.GeneratePrivateKey(&prB, rng)
|
|
|
|
csidh.GeneratePublicKey(&pkB, &prB, rng)
|
2019-01-30 16:17:20 +00:00
|
|
|
|
|
|
|
s1 := time.Now()
|
|
|
|
// Generate with Go
|
2019-11-22 18:05:18 +00:00
|
|
|
csidh.DeriveSecret(ss[:], &pkA, &prB, rng)
|
2019-01-30 16:17:20 +00:00
|
|
|
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
|
2019-01-30 20:30:11 +00:00
|
|
|
var ssRef [csidh.SharedSecretSize]byte
|
|
|
|
var ss [csidh.SharedSecretSize]byte
|
2019-01-30 16:17:20 +00:00
|
|
|
|
|
|
|
// Go types
|
2019-11-22 18:05:18 +00:00
|
|
|
var prA csidh.PrivateKey
|
|
|
|
var pkA csidh.PublicKey
|
|
|
|
var prB csidh.PrivateKey
|
|
|
|
var pkB csidh.PublicKey
|
|
|
|
|
|
|
|
csidh.GeneratePrivateKey(&prA, rng)
|
|
|
|
csidh.GeneratePublicKey(&pkA, &prA, rng)
|
|
|
|
csidh.GeneratePrivateKey(&prB, rng)
|
|
|
|
csidh.GeneratePublicKey(&pkB, &prB, rng)
|
2019-01-30 16:17:20 +00:00
|
|
|
|
|
|
|
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")
|
|
|
|
|
2019-04-12 11:53:30 +01:00
|
|
|
rng = drbg.NewCtrDrbg()
|
2019-01-30 16:17:20 +00:00
|
|
|
for {
|
|
|
|
TestSS()
|
|
|
|
TestKeyGeneration()
|
|
|
|
}
|
|
|
|
}
|