keccak256-circom/go-keccak256-bits-impl/stepmappings_test.go
go-keccak256-bits-impl/stepmappings_test.goRaw
1package keccak
2
3import (
4 "encoding/json"
5 "fmt"
6 "testing"
7
8 qt "github.com/frankban/quicktest"
9)
10
11func printS(n string, s []uint64) {
12 jS, err := json.Marshal(s)
13 if err != nil {
14 panic(err)
15 }
16 fmt.Printf("%s: %s\n", n, string(jS))
17}
18func newS() ([25 * 64]bool, [25]uint64) {
19 var s [25 * 64]bool
20 var sU64 [25]uint64
21 for i := 0; i < len(s)/64; i++ {
22 copy(s[i*64:i*64+64], u64ToBits(uint64(i)))
23 sU64[i] = uint64(i)
24 }
25 return s, sU64
26}
27
28func TestTheta(t *testing.T) {
29 s, sU64 := newS()
30
31 s = theta(s)
32 sU64 = thetaU64Version(sU64)
33
34 qt.Assert(t, bitsToU64Array(s[:]), qt.DeepEquals, sU64[:])
35 qt.Assert(t, bitsToU64Array(s[:]), qt.DeepEquals,
36 []uint64{26, 9, 13, 29, 47, 31, 14, 8, 22, 34, 16, 3, 3,
37 19, 37, 21, 24, 30, 12, 56, 14, 29, 25, 9, 51})
38
39 // compute again theta on the current state
40 s = theta(s)
41 sU64 = thetaU64Version(sU64)
42 qt.Assert(t, bitsToU64Array(s[:]), qt.DeepEquals, sU64[:])
43}