package main import ( "bytes" "encoding/hex" "encoding/json" "io/ioutil" "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 ) var StatusValues = map[int]string{ Valid: "valid", 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"` } type TestVectors struct { Vectors []TestVector `json:"Vectors"` } // R is a reference to C implementation. 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 prA := R.KeygenPrv() pkA := R.KeygenPub(&prA) prB := R.KeygenPrv() pkB := R.KeygenPub(&prB) R.Derive(ss[:], &pkB, &prA) tv.Id = num tv.Status = StatusValues[Valid] tv.Ss = hex.EncodeToString(ss[:]) prA.Export(pr[:]) tv.Pr1 = hex.EncodeToString(pr[:]) pkA.Export(pk[:]) tv.Pk1 = hex.EncodeToString(pk[:]) for i, _ := range pk { pk[i] = 0 } pkB.Export(pk[:]) tv.Pk2 = hex.EncodeToString(pk[:]) 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") } for i:=0; i