// Apply a standard set of validation tests to a ciphersuite. func TestSuite(suite abstract.Suite) { // Try hashing something h := suite.Hash() l := h.Size() //println("HashLen: ",l) h.Write([]byte("abc")) hb := h.Sum(nil) //println("Hash:") //println(hex.Dump(hb)) if h.Size() != l || len(hb) != l { panic("inconsistent hash output length") } // Generate some pseudorandom bits s := suite.Cipher(hb) sb := make([]byte, 128) s.XORKeyStream(sb, sb) //println("Stream:") //println(hex.Dump(sb)) // Test if it generates two fresh keys with nil cipher s1 := suite.NewKey(nil) s2 := suite.NewKey(nil) if s1.Equal(s2) { panic("NewKey returns twice the same key given nil") } // Test if it creates the same with the same seed st1 := suite.Cipher(hb) st2 := suite.Cipher(hb) s3 := suite.NewKey(st1) s4 := suite.NewKey(st2) if !s3.Equal(s4) { panic("NewKey returns two different keys given same stream") } // Test if it creates two different with random stream stream := random.Stream s5 := suite.NewKey(stream) s6 := suite.NewKey(stream) if s5.Equal(s6) { panic("NewKey returns same key given random stream") } // Test the public-key group arithmetic TestGroup(suite) }
// Generate a fresh public/private keypair with the given ciphersuite, // using a given source of cryptographic randomness. func (p *KeyPair) Gen(suite abstract.Suite, random cipher.Stream) { p.Suite = suite p.Secret = suite.NewKey(random) p.Public = suite.Point().Mul(nil, p.Secret) }