@@ -247,7 +247,7 @@ func copyOutUnaligned(api frontend.API, s [][]frontend.Variable, rate, outputLen
247247}
248248
249249type keccak256Circuit struct {
250- P [NHashes ][136 * 8 ]frontend.Variable
250+ P [NHashes ][64 * 8 ]frontend.Variable
251251 Out [NHashes ][CheckBits ]frontend.Variable
252252}
253253
@@ -259,11 +259,21 @@ func checkKeccak(api frontend.API, P, Out []frontend.Variable) {
259259 ss [i ][j ] = 0
260260 }
261261 }
262+ newP := make ([]frontend.Variable , 64 * 8 )
263+ copy (newP , P )
264+ appendData := make ([]byte , 136 - 64 )
265+ appendData [0 ] = 1
266+ appendData [135 - 64 ] = 0x80
267+ for i := 0 ; i < 136 - 64 ; i ++ {
268+ for j := 0 ; j < 8 ; j ++ {
269+ newP = append (newP , int ((appendData [i ]>> j )& 1 ))
270+ }
271+ }
262272 p := make ([][]frontend.Variable , 17 )
263273 for i := 0 ; i < 17 ; i ++ {
264274 p [i ] = make ([]frontend.Variable , 64 )
265275 for j := 0 ; j < 64 ; j ++ {
266- p [i ][j ] = P [i * 64 + j ]
276+ p [i ][j ] = newP [i * 64 + j ]
267277 }
268278 }
269279 ss = xorIn (api , ss , p )
@@ -294,18 +304,14 @@ func main() {
294304 os .WriteFile ("circuit.txt" , c .Serialize (), 0o644 )
295305
296306 for k := 0 ; k < NHashes ; k ++ {
297- for i := 0 ; i < 136 * 8 ; i ++ {
307+ for i := 0 ; i < 64 * 8 ; i ++ {
298308 circuit.P [k ][i ] = 0
299309 }
300310
301- length := rand .Intn (130 + 2 )
302- data := make ([]byte , length )
311+ data := make ([]byte , 64 )
303312 rand .Read (data )
304313 hash := crypto .Keccak256Hash (data )
305- data = append (data , 1 )
306- data = append (data , make ([]byte , 200 )... )
307- data [135 ] = 0x80
308- for i := 0 ; i < 136 ; i ++ {
314+ for i := 0 ; i < 64 ; i ++ {
309315 for j := 0 ; j < 8 ; j ++ {
310316 circuit .P [k ][i * 8 + j ] = int ((data [i ] >> j ) & 1 )
311317 }
0 commit comments