54 lines
1.3 KiB
Go
54 lines
1.3 KiB
Go
package keccak
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
var vector256 = []byte{
|
|
0xc5, 0xd2, 0x46, 0x01, 0x86, 0xf7, 0x23, 0x3c,
|
|
0x92, 0x7e, 0x7d, 0xb2, 0xdc, 0xc7, 0x03, 0xc0,
|
|
0xe5, 0x00, 0xb6, 0x53, 0xca, 0x82, 0x27, 0x3b,
|
|
0x7b, 0xfa, 0xd8, 0x04, 0x5d, 0x85, 0xa4, 0x70,
|
|
}
|
|
|
|
var vector512 = []byte{
|
|
0x0e, 0xab, 0x42, 0xde, 0x4c, 0x3c, 0xeb, 0x92,
|
|
0x35, 0xfc, 0x91, 0xac, 0xff, 0xe7, 0x46, 0xb2,
|
|
0x9c, 0x29, 0xa8, 0xc3, 0x66, 0xb7, 0xc6, 0x0e,
|
|
0x4e, 0x67, 0xc4, 0x66, 0xf3, 0x6a, 0x43, 0x04,
|
|
0xc0, 0x0f, 0xa9, 0xca, 0xf9, 0xd8, 0x79, 0x76,
|
|
0xba, 0x46, 0x9b, 0xcb, 0xe0, 0x67, 0x13, 0xb4,
|
|
0x35, 0xf0, 0x91, 0xef, 0x27, 0x69, 0xfb, 0x16,
|
|
0x0c, 0xda, 0xb3, 0x3d, 0x36, 0x70, 0x68, 0x0e,
|
|
}
|
|
|
|
func TestKeccak256(t *testing.T) {
|
|
h := newKeccak256()
|
|
sum := h.Sum(nil)
|
|
if !reflect.DeepEqual(sum, vector256) {
|
|
t.Errorf("Keccak-256(\"\"): want % x, got % x", vector256, sum)
|
|
}
|
|
}
|
|
|
|
func TestKeccak512(t *testing.T) {
|
|
h := newKeccak512()
|
|
sum := h.Sum(nil)
|
|
if !reflect.DeepEqual(sum, vector512) {
|
|
t.Errorf("Keccak-512(\"\"): want % x, got % x", vector512, sum)
|
|
}
|
|
}
|
|
|
|
func Benchmark256(b *testing.B) {
|
|
var tmp [Size]byte
|
|
h := New256()
|
|
var msg [BlockSize]byte
|
|
if len(msg) != h.BlockSize() {
|
|
b.Fatalf("message length does not match block size: want %d got %d", h.BlockSize(), len(msg))
|
|
}
|
|
b.SetBytes(BlockSize)
|
|
for i := 0; i < b.N; i++ {
|
|
h.Sum(tmp[:])
|
|
}
|
|
}
|