gen: Alter mod function. Purely cosmetic.

master
magical 2015-01-03 01:40:42 -08:00
parent 7b92fe3532
commit 902ec9e896
2 changed files with 26 additions and 7 deletions

13
gen.go
View File

@ -45,7 +45,7 @@ func count(n int) []int {
func add(a, b int) int { return a + b }
func sub(a, b int) int { return a - b }
func mul(a, b int) int { return a * b }
func mod(a, b int) int { return a % b }
func mod(a int) int { return a % 5 }
func afunc(x, y int) string {
return fmt.Sprintf("a[%d]", y%5*5+x%5)
@ -89,16 +89,16 @@ func roundGo(a *[25]uint64) {
{{ end }}
var d uint64
{{ range $x := count 5 }}
{{ $x4 := mod (add $x 4) 5 }}
{{ $x1 := mod (add $x 1) 5 }}
{{ $x4 := add $x 4 | mod }}
{{ $x1 := add $x 1 | mod }}
d = c{{$x4}} ^ (c{{$x1}}<<1 | c{{$x1}}>>63)
{{ range $y := count 5 }}
{{b $x $y}} = {{a $x $y}} ^ d
{{ end }}
{{ end }}
// Rho / Pi / Chi / output
{{ range $y := count 5 }}
// Rho / Pi
{{ range $x := count 5 }}
{{ $x0 := add $x (mul $y 3) }}
{{ $y0 := $x }}
@ -106,9 +106,10 @@ func roundGo(a *[25]uint64) {
{{ $r := rotc $x0 $y0 }}
c{{$x}} = {{$b}}<<{{$r}} | {{$b}}>>{{sub 64 $r}}
{{ end }}
// Chi
{{ range $x := count 5 }}
{{ $x1 := mod (add $x 1) 5 }}
{{ $x2 := mod (add $x 2) 5 }}
{{ $x1 := add $x 1 | mod }}
{{ $x2 := add $x 2 | mod }}
{{a $x $y}} = c{{$x}} ^ (c{{$x2}} &^ c{{$x1}})
{{ end }}
{{ end }}

View File

@ -91,7 +91,7 @@ func roundGo(a *[25]uint64) {
b44 = a[24] ^ d
// Rho / Pi / Chi / output
// Rho / Pi
c0 = b00<<0 | b00>>64
@ -103,6 +103,8 @@ func roundGo(a *[25]uint64) {
c4 = b44<<14 | b44>>50
// Chi
a[0] = c0 ^ (c2 &^ c1)
a[1] = c1 ^ (c3 &^ c2)
@ -113,6 +115,8 @@ func roundGo(a *[25]uint64) {
a[4] = c4 ^ (c1 &^ c0)
// Rho / Pi
c0 = b30<<28 | b30>>36
c1 = b41<<20 | b41>>44
@ -123,6 +127,8 @@ func roundGo(a *[25]uint64) {
c4 = b24<<61 | b24>>3
// Chi
a[5] = c0 ^ (c2 &^ c1)
a[6] = c1 ^ (c3 &^ c2)
@ -133,6 +139,8 @@ func roundGo(a *[25]uint64) {
a[9] = c4 ^ (c1 &^ c0)
// Rho / Pi
c0 = b10<<1 | b10>>63
c1 = b21<<6 | b21>>58
@ -143,6 +151,8 @@ func roundGo(a *[25]uint64) {
c4 = b04<<18 | b04>>46
// Chi
a[10] = c0 ^ (c2 &^ c1)
a[11] = c1 ^ (c3 &^ c2)
@ -153,6 +163,8 @@ func roundGo(a *[25]uint64) {
a[14] = c4 ^ (c1 &^ c0)
// Rho / Pi
c0 = b40<<27 | b40>>37
c1 = b01<<36 | b01>>28
@ -163,6 +175,8 @@ func roundGo(a *[25]uint64) {
c4 = b34<<56 | b34>>8
// Chi
a[15] = c0 ^ (c2 &^ c1)
a[16] = c1 ^ (c3 &^ c2)
@ -173,6 +187,8 @@ func roundGo(a *[25]uint64) {
a[19] = c4 ^ (c1 &^ c0)
// Rho / Pi
c0 = b20<<62 | b20>>2
c1 = b31<<55 | b31>>9
@ -183,6 +199,8 @@ func roundGo(a *[25]uint64) {
c4 = b14<<2 | b14>>62
// Chi
a[20] = c0 ^ (c2 &^ c1)
a[21] = c1 ^ (c3 &^ c2)