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}
44
45func TestRhoPi(t *testing.T) {
46 s, sU64 := newS()
47
48 s = rhopi(s)
49 sU64 = rhopiU64Version(sU64)
50
51 qt.Assert(t, bitsToU64Array(s[:]), qt.DeepEquals, sU64[:])
52 qt.Assert(t, bitsToU64Array(s[:]), qt.DeepEquals,
53 []uint64{0, 105553116266496, 105553116266496, 37748736, 393216,
54 805306368, 9437184, 80, 562949953421312, 13835058055282163714,
55 2, 448, 436207616, 4864, 5242880, 536870912, 343597383680,
56 11264, 557056, 1657324662872342528, 9223372036854775808,
57 288230376151711744, 7696581394432, 32985348833280, 84})
58
59 // compute again rhopi on the current state
60 s = rhopi(s)
61 sU64 = rhopiU64Version(sU64)
62 qt.Assert(t, bitsToU64Array(s[:]), qt.DeepEquals, sU64[:])
63}