本文整理汇总了Golang中github.com/dedis/crypto/abstract.Suite.NewKey方法的典型用法代码示例。如果您正苦于以下问题:Golang Suite.NewKey方法的具体用法?Golang Suite.NewKey怎么用?Golang Suite.NewKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/dedis/crypto/abstract.Suite
的用法示例。
在下文中一共展示了Suite.NewKey方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestSuite
// 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)
}
示例2: Gen
// 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)
}