remove a bunch of blank lines in keccak_gen.go

master
magical 2024-10-05 20:47:40 -07:00
parent b64eff8ecd
commit 5e1178f8c2
2 changed files with 18 additions and 107 deletions

34
gen.go
View File

@ -8,6 +8,8 @@ import (
"text/template"
)
// Requires Go 1.6+ for whitespace control in text/template
var roundc [24]uint64
var rotc [5][5]int
@ -78,38 +80,38 @@ package keccak
// round implements one round of the keccak-f[1600] permutation.
func roundGo(a *[25]uint64) {
{{ range $x := count 5 }}
{{ range $x := count 5 -}}
var b{{$x}}0, b{{$x}}1, b{{$x}}2, b{{$x}}3, b{{$x}}4 uint64
{{ end }}
// Theta
var c0, c1, c2, c3, c4 uint64
{{ range $x := count 5 }}
{{ range $x := count 5 -}}
c{{$x}} = {{a $x 0}} ^ {{a $x 1}} ^ {{a $x 2}} ^ {{a $x 3}} ^ {{a $x 4}}
{{ end }}
var d0, d1, d2, d3, d4 uint64
{{ range $x := count 5 }}
{{ $x4 := add $x 4 | mod }}
{{ $x1 := add $x 1 | mod }}
{{ range $x := count 5 -}}
{{ $x4 := add $x 4 | mod -}}
{{ $x1 := add $x 1 | mod -}}
d{{$x}} = c{{$x4}} ^ (c{{$x1}}<<1 | c{{$x1}}>>63)
{{ range $y := count 5 }}
{{ range $y := count 5 -}}
{{b $x $y}} = {{a $x $y}} ^ d{{$x}}
{{ end }}
{{ end }}
{{ range $y := count 5 }}
{{ range $y := count 5 -}}
// Rho / Pi
{{ range $x := count 5 }}
{{ $x0 := add $x (mul $y 3) }}
{{ $y0 := $x }}
{{ $b := b $x0 $y0 }}
{{ $r := rotc $x0 $y0 }}
{{ range $x := count 5 -}}
{{ $x0 := add $x (mul $y 3) -}}
{{ $y0 := $x -}}
{{ $b := b $x0 $y0 -}}
{{ $r := rotc $x0 $y0 -}}
c{{$x}} = {{$b}}<<{{$r}} | {{$b}}>>{{sub 64 $r}}
{{ end }}
{{ end -}}
// Chi
{{ range $x := count 5 }}
{{ $x1 := add $x 1 | mod }}
{{ $x2 := add $x 2 | mod }}
{{ range $x := count 5 -}}
{{ $x1 := add $x 1 | mod -}}
{{ $x2 := add $x 2 | mod -}}
{{a $x $y}} = c{{$x}} ^ (c{{$x2}} &^ c{{$x1}})
{{ end }}
{{ end }}

View File

@ -5,210 +5,119 @@ package keccak
// round implements one round of the keccak-f[1600] permutation.
func roundGo(a *[25]uint64) {
var b00, b01, b02, b03, b04 uint64
var b10, b11, b12, b13, b14 uint64
var b20, b21, b22, b23, b24 uint64
var b30, b31, b32, b33, b34 uint64
var b40, b41, b42, b43, b44 uint64
// Theta
var c0, c1, c2, c3, c4 uint64
c0 = a[0] ^ a[5] ^ a[10] ^ a[15] ^ a[20]
c1 = a[1] ^ a[6] ^ a[11] ^ a[16] ^ a[21]
c2 = a[2] ^ a[7] ^ a[12] ^ a[17] ^ a[22]
c3 = a[3] ^ a[8] ^ a[13] ^ a[18] ^ a[23]
c4 = a[4] ^ a[9] ^ a[14] ^ a[19] ^ a[24]
var d0, d1, d2, d3, d4 uint64
d0 = c4 ^ (c1<<1 | c1>>63)
b00 = a[0] ^ d0
b01 = a[5] ^ d0
b02 = a[10] ^ d0
b03 = a[15] ^ d0
b04 = a[20] ^ d0
d1 = c0 ^ (c2<<1 | c2>>63)
b10 = a[1] ^ d1
b11 = a[6] ^ d1
b12 = a[11] ^ d1
b13 = a[16] ^ d1
b14 = a[21] ^ d1
d2 = c1 ^ (c3<<1 | c3>>63)
b20 = a[2] ^ d2
b21 = a[7] ^ d2
b22 = a[12] ^ d2
b23 = a[17] ^ d2
b24 = a[22] ^ d2
d3 = c2 ^ (c4<<1 | c4>>63)
b30 = a[3] ^ d3
b31 = a[8] ^ d3
b32 = a[13] ^ d3
b33 = a[18] ^ d3
b34 = a[23] ^ d3
d4 = c3 ^ (c0<<1 | c0>>63)
b40 = a[4] ^ d4
b41 = a[9] ^ d4
b42 = a[14] ^ d4
b43 = a[19] ^ d4
b44 = a[24] ^ d4
// Rho / Pi
c0 = b00<<0 | b00>>64
c1 = b11<<44 | b11>>20
c2 = b22<<43 | b22>>21
c3 = b33<<21 | b33>>43
c4 = b44<<14 | b44>>50
// Chi
a[0] = c0 ^ (c2 &^ c1)
a[1] = c1 ^ (c3 &^ c2)
a[2] = c2 ^ (c4 &^ c3)
a[3] = c3 ^ (c0 &^ c4)
a[4] = c4 ^ (c1 &^ c0)
// Rho / Pi
c0 = b30<<28 | b30>>36
c1 = b41<<20 | b41>>44
c2 = b02<<3 | b02>>61
c3 = b13<<45 | b13>>19
c4 = b24<<61 | b24>>3
// Chi
a[5] = c0 ^ (c2 &^ c1)
a[6] = c1 ^ (c3 &^ c2)
a[7] = c2 ^ (c4 &^ c3)
a[8] = c3 ^ (c0 &^ c4)
a[9] = c4 ^ (c1 &^ c0)
// Rho / Pi
c0 = b10<<1 | b10>>63
c1 = b21<<6 | b21>>58
c2 = b32<<25 | b32>>39
c3 = b43<<8 | b43>>56
c4 = b04<<18 | b04>>46
// Chi
a[10] = c0 ^ (c2 &^ c1)
a[11] = c1 ^ (c3 &^ c2)
a[12] = c2 ^ (c4 &^ c3)
a[13] = c3 ^ (c0 &^ c4)
a[14] = c4 ^ (c1 &^ c0)
// Rho / Pi
c0 = b40<<27 | b40>>37
c1 = b01<<36 | b01>>28
c2 = b12<<10 | b12>>54
c3 = b23<<15 | b23>>49
c4 = b34<<56 | b34>>8
// Chi
a[15] = c0 ^ (c2 &^ c1)
a[16] = c1 ^ (c3 &^ c2)
a[17] = c2 ^ (c4 &^ c3)
a[18] = c3 ^ (c0 &^ c4)
a[19] = c4 ^ (c1 &^ c0)
// Rho / Pi
c0 = b20<<62 | b20>>2
c1 = b31<<55 | b31>>9
c2 = b42<<39 | b42>>25
c3 = b03<<41 | b03>>23
c4 = b14<<2 | b14>>62
// Chi
a[20] = c0 ^ (c2 &^ c1)
a[21] = c1 ^ (c3 &^ c2)
a[22] = c2 ^ (c4 &^ c3)
a[23] = c3 ^ (c0 &^ c4)
a[24] = c4 ^ (c1 &^ c0)
}