2014-12-31 22:59:00 +00:00
|
|
|
package keccak
|
|
|
|
|
|
|
|
// roundGeneric implements one round of the keccak-f[1600] permutation.
|
2015-01-01 10:59:03 +00:00
|
|
|
func roundGeneric(a *[25]uint64) {
|
2014-12-31 23:11:40 +00:00
|
|
|
// Theta
|
2014-12-31 22:59:00 +00:00
|
|
|
var c [5]uint64
|
2015-01-01 10:59:03 +00:00
|
|
|
for x := range c {
|
|
|
|
c[x] = a[0+x] ^ a[5+x] ^ a[10+x] ^ a[15+x] ^ a[20+x]
|
2014-12-31 22:59:00 +00:00
|
|
|
}
|
2015-01-01 10:59:03 +00:00
|
|
|
for x := 0; x < 5; x++ {
|
|
|
|
d := c[(x+4)%5] ^ rotl(c[(x+1)%5], 1)
|
|
|
|
for y := 0; y < 5; y++ {
|
|
|
|
a[y*5+x] ^= d
|
|
|
|
}
|
2014-12-31 22:59:00 +00:00
|
|
|
}
|
|
|
|
|
2014-12-31 23:11:40 +00:00
|
|
|
// Rho and pi
|
2014-12-31 22:59:00 +00:00
|
|
|
var b [5][5]uint64
|
2015-01-01 10:59:03 +00:00
|
|
|
for y := 0; y < 5; y++ {
|
|
|
|
for x := 0; x < 5; x++ {
|
2014-12-31 22:59:00 +00:00
|
|
|
x0 := y
|
|
|
|
y0 := (x*2 + y*3) % 5
|
2015-01-01 10:59:03 +00:00
|
|
|
b[y0][x0] = rotl(a[y*5+x], rotc[y][x])
|
2014-12-31 22:59:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-31 23:11:40 +00:00
|
|
|
// Chi
|
2015-01-01 10:59:03 +00:00
|
|
|
for y := 0; y < 5; y++ {
|
|
|
|
a[y*5+0] = b[y][0] ^ ^b[y][1]&b[y][2]
|
|
|
|
a[y*5+1] = b[y][1] ^ ^b[y][2]&b[y][3]
|
|
|
|
a[y*5+2] = b[y][2] ^ ^b[y][3]&b[y][4]
|
|
|
|
a[y*5+3] = b[y][3] ^ ^b[y][4]&b[y][0]
|
|
|
|
a[y*5+4] = b[y][4] ^ ^b[y][0]&b[y][1]
|
2014-12-31 22:59:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func rotl(a uint64, r uint) uint64 {
|
2015-01-01 00:40:56 +00:00
|
|
|
return a<<(r%64) | a>>(64-(r%64))
|
2014-12-31 22:59:00 +00:00
|
|
|
}
|