diff --git a/csidh/cmd/vector-creator/main.go b/csidh/cmd/vector-creator/main.go index e7130b2..307f630 100644 --- a/csidh/cmd/vector-creator/main.go +++ b/csidh/cmd/vector-creator/main.go @@ -1,41 +1,44 @@ package main import ( - "bytes" - "encoding/hex" - "encoding/json" - "io/ioutil" + "bytes" + "encoding/hex" + "encoding/json" + "io/ioutil" - "github.com/henrydcase/nobs/dh/csidh" - "github.com/henrydcase/sidh_torture/csidh/ref/go-wrapper" + "github.com/henrydcase/nobs/dh/csidh" + "github.com/henrydcase/sidh_torture/csidh/ref/go-wrapper" ) // Possible values for "Status" const ( - Valid = iota // Indicates that shared secret must be agreed correctly - InvalidSharedSecret // Calculated shared secret must be different than test vector - InvalidPublicKey1 // Public key 1 generated from private key must be different than test vector - InvalidPublicKey2 // Public key 2 must fail validation + Valid = iota // Indicates that shared secret must be agreed correctly + ValidPublicKey2 // Public key 2 must succeed validation + InvalidSharedSecret // Calculated shared secret must be different than test vector + InvalidPublicKey1 // Public key 1 generated from private key must be different than test vector + InvalidPublicKey2 // Public key 2 must fail validation ) var StatusValues = map[int]string{ - Valid: "valid", - InvalidSharedSecret: "invalid_shared_secret", - InvalidPublicKey1: "invalid_public_key1", - InvalidPublicKey2: "invalid_public_key2", + Valid: "valid", + ValidPublicKey2: "valid_public_key2", + InvalidSharedSecret: "invalid_shared_secret", + InvalidPublicKey1: "invalid_public_key1", + InvalidPublicKey2: "invalid_public_key2", } type TestVector struct { - Id int `json:"Id"` - Pk1 string `json:"Pk1"` - Pr1 string `json:"Pr1"` - Pk2 string `json:"Pk2"` - Ss string `json:"Ss"` - Status string `json:"status"` + Id int `json:"Id"` + Pk1 string `json:"Pk1"` + Pr1 string `json:"Pr1"` + Pk2 string `json:"Pk2"` + Ss string `json:"Ss"` + Status string `json:"status"` + Comment string `json:"comment"` } type TestVectors struct { - Vectors []TestVector `json:"Vectors"` + Vectors []TestVector `json:"Vectors"` } // R is a reference to C implementation. @@ -44,139 +47,142 @@ var R wrapper.Ref // createValid creates 'num' of TestVector's. Each vector contains // valid data. func createValid(num int) TestVector { - var tv TestVector - var ss [csidh.SharedSecretSize]byte - var pk [csidh.PublicKeySize]byte - var pr [csidh.PrivateKeySize]byte + var tv TestVector + var ss [csidh.SharedSecretSize]byte + var pk [csidh.PublicKeySize]byte + var pr [csidh.PrivateKeySize]byte - prA := R.KeygenPrv() - pkA := R.KeygenPub(&prA) - prB := R.KeygenPrv() - pkB := R.KeygenPub(&prB) + prA := R.KeygenPrv() + pkA := R.KeygenPub(&prA) + prB := R.KeygenPrv() + pkB := R.KeygenPub(&prB) - R.Derive(ss[:], &pkB, &prA) + R.Derive(ss[:], &pkB, &prA) - tv.Id = num - tv.Status = StatusValues[Valid] + tv.Id = num + tv.Status = StatusValues[Valid] - tv.Ss = hex.EncodeToString(ss[:]) + tv.Ss = hex.EncodeToString(ss[:]) - prA.Export(pr[:]) - tv.Pr1 = hex.EncodeToString(pr[:]) + prA.Export(pr[:]) + tv.Pr1 = hex.EncodeToString(pr[:]) - pkA.Export(pk[:]) - tv.Pk1 = hex.EncodeToString(pk[:]) + pkA.Export(pk[:]) + tv.Pk1 = hex.EncodeToString(pk[:]) - for i, _ := range pk { - pk[i] = 0 - } + for i, _ := range pk { + pk[i] = 0 + } - pkB.Export(pk[:]) - tv.Pk2 = hex.EncodeToString(pk[:]) + pkB.Export(pk[:]) + tv.Pk2 = hex.EncodeToString(pk[:]) - return tv + return tv } func createNegativeSharedSecret(vectors *TestVectors) { - n := len(vectors.Vectors) - tv := createValid(n) - ss, err := hex.DecodeString(tv.Ss) - if err != nil { - panic("Can't decode shared secret") - } + n := len(vectors.Vectors) + tv := createValid(n) + ss, err := hex.DecodeString(tv.Ss) + if err != nil { + panic("Can't decode shared secret") + } - for i:=0; i