mirror of
https://github.com/arnaucube/keccak256-circom.git
synced 2026-01-10 16:01:28 +01:00
Absorb circuit implemented
This commit is contained in:
@@ -2,6 +2,7 @@ package keccak
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
@@ -107,6 +108,62 @@ func TestKeccakf(t *testing.T) {
|
||||
13518516210247555620})
|
||||
}
|
||||
|
||||
func printBytes(name string, b []byte) {
|
||||
fmt.Printf("%s\n", name)
|
||||
for _, v := range b {
|
||||
fmt.Printf("\"%v\", ", v)
|
||||
}
|
||||
fmt.Println("")
|
||||
}
|
||||
func printU64Array(name string, b []uint64) {
|
||||
fmt.Printf("%s\n", name)
|
||||
for _, v := range b {
|
||||
fmt.Printf("\"%v\", ", v)
|
||||
}
|
||||
fmt.Println("")
|
||||
}
|
||||
|
||||
func TestAbsorb(t *testing.T) {
|
||||
s, _ := newS()
|
||||
block := []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
||||
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
|
||||
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128}
|
||||
// printU64Array("s", bitsToU64Array(s[:]))
|
||||
// printBytes("block", block[:])
|
||||
|
||||
absorbed := absorb(s, bytesToBits(block))
|
||||
// printU64Array("absorbed", bitsToU64Array(absorbed[:]))
|
||||
|
||||
qt.Assert(t, bitsToU64Array(absorbed[:]), qt.DeepEquals,
|
||||
[]uint64{8342348566319207042, 319359607942176202, 14410076088654599075,
|
||||
15666111399434436772, 9558421567405313402, 3396178318116504023,
|
||||
794353847439963108, 12717011319735989377, 3503398863218919239,
|
||||
5517201702366862678, 15999361614129160496, 1325524015888689985,
|
||||
11971708408118944333, 14874486179441062217, 12554876384974234666,
|
||||
11129975558302206043, 11257826431949606534, 2740710607956478714,
|
||||
15000019752453010167, 15593606854132419294, 2598425978562809333,
|
||||
8872504799797239246, 1212062965004664308, 5443427421087086722,
|
||||
10946808592826700411})
|
||||
|
||||
absorbed = absorb(absorbed, bytesToBits(block))
|
||||
// printU64Array("absorbed", bitsToU64Array(absorbed[:]))
|
||||
|
||||
qt.Assert(t, bitsToU64Array(absorbed[:]), qt.DeepEquals,
|
||||
[]uint64{8909243822027471379, 1111840847970088140,
|
||||
12093072708540612559, 11255033638786021658, 2082116894939842214,
|
||||
12821085060245261575, 6901785969834988344, 3182430130277914993,
|
||||
2164708585929408975, 14402143231999718904, 16231444410553803968,
|
||||
1850945423480060493, 12856855675247400303, 1137248620532111171,
|
||||
7389129221921446308, 12932467982741614601, 1350606937385760406,
|
||||
10983682292859713641, 10305595434820307765, 13958651111365489854,
|
||||
17206620388135196198, 4238113785249530092, 7230868147643218103,
|
||||
603011106238724524, 16480095441097880488})
|
||||
}
|
||||
|
||||
func TestFinal(t *testing.T) {
|
||||
b := make([]byte, 32)
|
||||
for i := 0; i < len(b); i++ {
|
||||
|
||||
Reference in New Issue
Block a user