mirror of https://github.com/waku-org/noise.git
Add encrypt benchmark
This commit is contained in:
parent
f585254b83
commit
8a2dc23c1f
|
@ -14,22 +14,7 @@ type S struct{}
|
||||||
var _ = Suite(&S{})
|
var _ = Suite(&S{})
|
||||||
|
|
||||||
func (s *S) TestRoundtrip(c *C) {
|
func (s *S) TestRoundtrip(c *C) {
|
||||||
recvKey, _ := Noise255.GenerateKey(rand.Reader)
|
enc, dec := newCrypters()
|
||||||
sendKey, _ := Noise255.GenerateKey(rand.Reader)
|
|
||||||
|
|
||||||
enc := &Crypter{
|
|
||||||
Cipher: Noise255,
|
|
||||||
SenderKey: sendKey,
|
|
||||||
ReceiverKey: recvKey,
|
|
||||||
}
|
|
||||||
enc.ReceiverKey.Private = nil
|
|
||||||
|
|
||||||
dec := &Crypter{
|
|
||||||
Cipher: Noise255,
|
|
||||||
SenderKey: sendKey,
|
|
||||||
ReceiverKey: recvKey,
|
|
||||||
}
|
|
||||||
dec.SenderKey.Private = nil
|
|
||||||
|
|
||||||
plain := []byte("yellow submarines")
|
plain := []byte("yellow submarines")
|
||||||
padLen := 2
|
padLen := 2
|
||||||
|
@ -51,3 +36,33 @@ func (s *S) TestRoundtrip(c *C) {
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
c.Assert(plaintext, DeepEquals, plain)
|
c.Assert(plaintext, DeepEquals, plain)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func newCrypters() (*Crypter, *Crypter) {
|
||||||
|
recvKey, _ := Noise255.GenerateKey(rand.Reader)
|
||||||
|
sendKey, _ := Noise255.GenerateKey(rand.Reader)
|
||||||
|
|
||||||
|
enc := &Crypter{
|
||||||
|
Cipher: Noise255,
|
||||||
|
SenderKey: sendKey,
|
||||||
|
ReceiverKey: recvKey,
|
||||||
|
}
|
||||||
|
enc.ReceiverKey.Private = nil
|
||||||
|
|
||||||
|
dec := &Crypter{
|
||||||
|
Cipher: Noise255,
|
||||||
|
SenderKey: sendKey,
|
||||||
|
ReceiverKey: recvKey,
|
||||||
|
}
|
||||||
|
dec.SenderKey.Private = nil
|
||||||
|
|
||||||
|
return enc, dec
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkEncrypt(b *testing.B) {
|
||||||
|
enc, _ := newCrypters()
|
||||||
|
b.ReportAllocs()
|
||||||
|
b.ResetTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
enc.Encrypt(nil, nil, []byte("yellow submarine"), 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue