Gofmt.
parent
e7f1f3541f
commit
7b01515ff6
16
gen.go
16
gen.go
|
@ -24,13 +24,13 @@ func main() {
|
||||||
// Rotation constants
|
// Rotation constants
|
||||||
x, y := 1, 0
|
x, y := 1, 0
|
||||||
for i := 1; i < 25; i++ {
|
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
|
x, y = y, (2*x+3*y)%5
|
||||||
}
|
}
|
||||||
|
|
||||||
var ctx = struct {
|
var ctx = struct {
|
||||||
Rotc [5][5]int
|
Rotc [5][5]int
|
||||||
} {
|
}{
|
||||||
rotc,
|
rotc,
|
||||||
}
|
}
|
||||||
err := tmpl.Execute(os.Stdout, &ctx)
|
err := tmpl.Execute(os.Stdout, &ctx)
|
||||||
|
@ -41,14 +41,14 @@ func main() {
|
||||||
|
|
||||||
func count(n int) []int {
|
func count(n int) []int {
|
||||||
var out = make([]int, n)
|
var out = make([]int, n)
|
||||||
for i := 0; i < n; i ++ {
|
for i := 0; i < n; i++ {
|
||||||
out[i] = i
|
out[i] = i
|
||||||
}
|
}
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
func add(a, b, m int) int {
|
func add(a, b, m int) int {
|
||||||
return (a+b) % m
|
return (a + b) % m
|
||||||
}
|
}
|
||||||
|
|
||||||
func sub(a, b int) int {
|
func sub(a, b int) int {
|
||||||
|
@ -56,14 +56,14 @@ func sub(a, b int) int {
|
||||||
}
|
}
|
||||||
|
|
||||||
func mul(a, b int) int {
|
func mul(a, b int) int {
|
||||||
return a*b
|
return a * b
|
||||||
}
|
}
|
||||||
|
|
||||||
var funcs = template.FuncMap{
|
var funcs = template.FuncMap{
|
||||||
"count": count,
|
"count": count,
|
||||||
"add": add,
|
"add": add,
|
||||||
"sub": sub,
|
"sub": sub,
|
||||||
"mul": mul,
|
"mul": mul,
|
||||||
}
|
}
|
||||||
|
|
||||||
var tmpl = template.Must(template.New("keccak").Funcs(funcs).Parse(`
|
var tmpl = template.Must(template.New("keccak").Funcs(funcs).Parse(`
|
||||||
|
|
18
sponge.go
18
sponge.go
|
@ -10,18 +10,18 @@ var round = roundGo
|
||||||
|
|
||||||
// digest implements hash.Hash
|
// digest implements hash.Hash
|
||||||
type digest struct {
|
type digest struct {
|
||||||
a [5][5]uint64 // a[y][x][z]
|
a [5][5]uint64 // a[y][x][z]
|
||||||
buf [200]byte
|
buf [200]byte
|
||||||
dsbyte byte
|
dsbyte byte
|
||||||
len int
|
len int
|
||||||
size int
|
size int
|
||||||
}
|
}
|
||||||
|
|
||||||
func New256() hash.Hash { return &digest{size: 256/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 New512() hash.Hash { return &digest{size: 512 / 8, dsbyte: 0x06} }
|
||||||
|
|
||||||
func newKeccak256() hash.Hash { return &digest{size: 256/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 newKeccak512() hash.Hash { return &digest{size: 512 / 8, dsbyte: 0x01} }
|
||||||
|
|
||||||
func (d *digest) Size() int { return d.size }
|
func (d *digest) Size() int { return d.size }
|
||||||
func (d *digest) BlockSize() int { return 200 - d.size*2 }
|
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)
|
n := copy(d.buf[d.len:bs], b)
|
||||||
d.len += n
|
d.len += n
|
||||||
b = b[n:]
|
b = b[n:]
|
||||||
if d.len == bs {
|
if d.len == bs {
|
||||||
d.flush()
|
d.flush()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue