master
magical 2014-12-31 15:19:23 -08:00
parent e40b3562fb
commit c9dcfb85a1
5 changed files with 14 additions and 15 deletions

View File

@ -1,3 +1,4 @@
package keccak
var RC = [24]uint64{0x0000000000000001, 0x0000000000008082, 0x800000000000808a, 0x8000000080008000, 0x000000000000808b, 0x0000000080000001, 0x8000000080008081, 0x8000000000008009, 0x000000000000008a, 0x0000000000000088, 0x0000000080008009, 0x000000008000000a, 0x000000008000808b, 0x800000000000008b, 0x8000000000008089, 0x8000000000008003, 0x8000000000008002, 0x8000000000000080, 0x000000000000800a, 0x800000008000000a, 0x8000000080008081, 0x8000000000008080, 0x0000000080000001, 0x8000000080008008}
var rotc = [5][5]uint{[5]uint{0x0, 0x1, 0x3e, 0x1c, 0x1b}, [5]uint{0x24, 0x2c, 0x6, 0x37, 0x14}, [5]uint{0x3, 0xa, 0x2b, 0x19, 0x27}, [5]uint{0x29, 0x2d, 0xf, 0x15, 0x8}, [5]uint{0x12, 0x2, 0x3d, 0x38, 0xe}}

View File

@ -20,7 +20,7 @@ func main() {
var rot [5][5]uint
x, y := 1, 0
for i := 0; i < 24; i++ {
rot[y][x] = uint((i+1)*(i+2)/2)%64
rot[y][x] = uint((i+1)*(i+2)/2) % 64
x, y = y, (2*x+3*y)%5
}
fmt.Printf("var rotc = %#v\n", rot)

View File

@ -29,16 +29,14 @@ func roundGeneric(a *[5][5]uint64) {
// Chi
for y := range a[0] {
c := [5]uint64{b[y][0], b[y][1], b[y][2], b[y][3], b[y][4]}
a[y][0] = b[y][0] ^ ^c[1] & c[2]
a[y][1] = b[y][1] ^ ^c[2] & c[3]
a[y][2] = b[y][2] ^ ^c[3] & c[4]
a[y][3] = b[y][3] ^ ^c[4] & c[0]
a[y][4] = b[y][4] ^ ^c[0] & c[1]
a[y][0] = b[y][0] ^ ^c[1]&c[2]
a[y][1] = b[y][1] ^ ^c[2]&c[3]
a[y][2] = b[y][2] ^ ^c[3]&c[4]
a[y][3] = b[y][3] ^ ^c[4]&c[0]
a[y][4] = b[y][4] ^ ^c[0]&c[1]
}
}
func rotl(a uint64, r uint) uint64 {
return a<<r | a>>(64-r)
}

View File

@ -23,7 +23,7 @@ func Benchmark256(b *testing.B) {
var tmp [Size]byte
h := New()
b.SetBytes(BlockSize)
for i := 0; i < b.N; i ++ {
for i := 0; i < b.N; i++ {
h.Sum(tmp[:])
}
}

View File

@ -2,7 +2,7 @@ package keccak
import "hash"
const Size = 256/8
const Size = 256 / 8
const BlockSize = 1600/8 - Size*2
@ -63,7 +63,7 @@ func keccakf(a *[5][5]uint64) {
func (d0 *digest) Sum(b []byte) []byte {
d := *d0
d.buf[d.len] = 0x01
for i := d.len+1; i < BlockSize; i++ {
for i := d.len + 1; i < BlockSize; i++ {
d.buf[i] = 0
}
d.buf[BlockSize-1] |= 0x80
@ -77,7 +77,7 @@ func (d0 *digest) Sum(b []byte) []byte {
}
func le64dec(b []byte) uint64 {
return uint64(b[0]) << 0 | uint64(b[1])<<8 | uint64(b[2])<<16 | uint64(b[3])<<24 | uint64(b[4])<<32 | uint64(b[5])<<40 | uint64(b[6])<<48 | uint64(b[7])<<56
return uint64(b[0])<<0 | uint64(b[1])<<8 | uint64(b[2])<<16 | uint64(b[3])<<24 | uint64(b[4])<<32 | uint64(b[5])<<40 | uint64(b[6])<<48 | uint64(b[7])<<56
}
func le64enc(b []byte, x uint64) []byte {