master
magical 2014-12-31 23:59:40 -08:00
parent e7f1f3541f
commit 7b01515ff6
2 changed files with 17 additions and 17 deletions

16
gen.go
View File

@ -24,13 +24,13 @@ func main() {
// Rotation constants
x, y := 1, 0
for i := 1; i < 25; i++ {
rotc[x][y] = (i*(i+1)/2) % 64
rotc[x][y] = (i * (i + 1) / 2) % 64
x, y = y, (2*x+3*y)%5
}
var ctx = struct {
Rotc [5][5]int
} {
}{
rotc,
}
err := tmpl.Execute(os.Stdout, &ctx)
@ -41,14 +41,14 @@ func main() {
func count(n int) []int {
var out = make([]int, n)
for i := 0; i < n; i ++ {
for i := 0; i < n; i++ {
out[i] = i
}
return out
}
func add(a, b, m int) int {
return (a+b) % m
return (a + b) % m
}
func sub(a, b int) int {
@ -56,14 +56,14 @@ func sub(a, b int) int {
}
func mul(a, b int) int {
return a*b
return a * b
}
var funcs = template.FuncMap{
"count": count,
"add": add,
"sub": sub,
"mul": mul,
"add": add,
"sub": sub,
"mul": mul,
}
var tmpl = template.Must(template.New("keccak").Funcs(funcs).Parse(`

View File

@ -10,18 +10,18 @@ var round = roundGo
// digest implements hash.Hash
type digest struct {
a [5][5]uint64 // a[y][x][z]
buf [200]byte
a [5][5]uint64 // a[y][x][z]
buf [200]byte
dsbyte byte
len int
size int
len int
size int
}
func New256() hash.Hash { return &digest{size: 256/8, dsbyte: 0x06} }
func New512() hash.Hash { return &digest{size: 512/8, dsbyte: 0x06} }
func New256() hash.Hash { return &digest{size: 256 / 8, dsbyte: 0x06} }
func New512() hash.Hash { return &digest{size: 512 / 8, dsbyte: 0x06} }
func newKeccak256() hash.Hash { return &digest{size: 256/8, dsbyte: 0x01} }
func newKeccak512() hash.Hash { return &digest{size: 512/8, dsbyte: 0x01} }
func newKeccak256() hash.Hash { return &digest{size: 256 / 8, dsbyte: 0x01} }
func newKeccak512() hash.Hash { return &digest{size: 512 / 8, dsbyte: 0x01} }
func (d *digest) Size() int { return d.size }
func (d *digest) BlockSize() int { return 200 - d.size*2 }
@ -40,7 +40,7 @@ func (d *digest) Write(b []byte) (int, error) {
n := copy(d.buf[d.len:bs], b)
d.len += n
b = b[n:]
if d.len == bs {
if d.len == bs {
d.flush()
}
}