Blake2s tests
This commit is contained in:
parent
648aab7817
commit
6ae0ef54a4
45
crypto/sharedkey/blake2s_test.go
Normal file
45
crypto/sharedkey/blake2s_test.go
Normal file
@ -0,0 +1,45 @@
|
||||
package sharedkey
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"math/rand"
|
||||
"mpbl3p/shared"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestBlake2s_GenerateVerify(t *testing.T) {
|
||||
t.Run("GeneratedVerifies", func(t *testing.T) {
|
||||
// ASSIGN
|
||||
key := make([]byte, 16)
|
||||
rand.Read(key)
|
||||
buf := make([]byte, 500)
|
||||
rand.Read(buf)
|
||||
|
||||
// ACT
|
||||
b := Blake2s{key}
|
||||
code := b.Generate(buf)
|
||||
|
||||
// ASSERT
|
||||
err := b.Verify(buf, code)
|
||||
assert.Nil(t, err)
|
||||
})
|
||||
|
||||
t.Run("FlippedBitFailsVerify", func(t *testing.T) {
|
||||
// ASSIGN
|
||||
key := make([]byte, 16)
|
||||
rand.Read(key)
|
||||
buf := make([]byte, 500)
|
||||
rand.Read(buf)
|
||||
|
||||
// ACT
|
||||
b := Blake2s{key}
|
||||
code := b.Generate(buf)
|
||||
|
||||
offset := rand.Intn(len(buf) * 8)
|
||||
buf[offset/8] ^= 1 << (offset % 8)
|
||||
|
||||
// ASSERT
|
||||
err := b.Verify(buf, code)
|
||||
assert.Equal(t, shared.ErrBadChecksum, err)
|
||||
})
|
||||
}
|
Loading…
Reference in New Issue
Block a user