Formatting

This commit is contained in:
Henry Case 2019-01-31 15:48:44 +00:00
parent 16f0f5b588
commit f143e36c59

View File

@ -13,6 +13,7 @@ import (
// Possible values for "Status" // Possible values for "Status"
const ( const (
Valid = iota // Indicates that shared secret must be agreed correctly 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 InvalidSharedSecret // Calculated shared secret must be different than test vector
InvalidPublicKey1 // Public key 1 generated from private key 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 InvalidPublicKey2 // Public key 2 must fail validation
@ -20,6 +21,7 @@ const (
var StatusValues = map[int]string{ var StatusValues = map[int]string{
Valid: "valid", Valid: "valid",
ValidPublicKey2: "valid_public_key2",
InvalidSharedSecret: "invalid_shared_secret", InvalidSharedSecret: "invalid_shared_secret",
InvalidPublicKey1: "invalid_public_key1", InvalidPublicKey1: "invalid_public_key1",
InvalidPublicKey2: "invalid_public_key2", InvalidPublicKey2: "invalid_public_key2",
@ -32,6 +34,7 @@ type TestVector struct {
Pk2 string `json:"Pk2"` Pk2 string `json:"Pk2"`
Ss string `json:"Ss"` Ss string `json:"Ss"`
Status string `json:"status"` Status string `json:"status"`
Comment string `json:"comment"`
} }
type TestVectors struct { type TestVectors struct {
@ -85,10 +88,10 @@ func createNegativeSharedSecret(vectors *TestVectors) {
panic("Can't decode shared secret") panic("Can't decode shared secret")
} }
for i:=0; i<csidh.SharedSecretSize; i++ { for i := 0; i < csidh.SharedSecretSize; i++ {
var newSs [csidh.SharedSecretSize]byte var newSs [csidh.SharedSecretSize]byte
copy(newSs[:], ss[:]) copy(newSs[:], ss[:])
newSs[i] = ss[i]^ss[(i+1)%csidh.SharedSecretSize] newSs[i] = ss[i] ^ ss[(i+1)%csidh.SharedSecretSize]
if bytes.Equal(newSs[:], ss) { if bytes.Equal(newSs[:], ss) {
tv.Status = StatusValues[Valid] tv.Status = StatusValues[Valid]
@ -110,12 +113,12 @@ func createNegativePk2(vectors *TestVectors) {
panic("Can't decode public key 2") panic("Can't decode public key 2")
} }
for i:=0; i<csidh.PublicKeySize; i++ { for i := 0; i < csidh.PublicKeySize; i++ {
var newPk [csidh.PublicKeySize]byte var newPk [csidh.PublicKeySize]byte
// Modify good public key so it's probably no longer valid // Modify good public key so it's probably no longer valid
copy(newPk[:], pk[:]) copy(newPk[:], pk[:])
newPk[i] = pk[i]^pk[(i+1)%csidh.PublicKeySize] newPk[i] = pk[i] ^ pk[(i+1)%csidh.PublicKeySize]
// Try to validate and set the status // Try to validate and set the status
if R.Validate(newPk[:]) { if R.Validate(newPk[:]) {
@ -132,7 +135,7 @@ func createNegativePk2(vectors *TestVectors) {
// Private key doesn't correspond to public key // Private key doesn't correspond to public key
func createNegativePrivateKey(vectors *TestVectors, num int) { func createNegativePrivateKey(vectors *TestVectors, num int) {
n := len(vectors.Vectors) n := len(vectors.Vectors)
for i:=0; i<num; i++ { for i := 0; i < num; i++ {
var tv TestVector var tv TestVector
var pkBytes1 [csidh.PublicKeySize]byte var pkBytes1 [csidh.PublicKeySize]byte
var pkBytes2 [csidh.PublicKeySize]byte var pkBytes2 [csidh.PublicKeySize]byte
@ -164,10 +167,13 @@ func createNegativePrivateKey(vectors *TestVectors, num int) {
} }
} }
// TODO: Produce test case for a Pk2 with all zeros and status valid_public_key2.
// comment should be "Zero key should validate correctly"
func main() { func main() {
var vectors TestVectors var vectors TestVectors
for i:=0; i<10; i++ { for i := 0; i < 10; i++ {
vectors.Vectors = append(vectors.Vectors, createValid(i)) vectors.Vectors = append(vectors.Vectors, createValid(i))
} }
createNegativeSharedSecret(&vectors) createNegativeSharedSecret(&vectors)