-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhash.go
60 lines (52 loc) · 984 Bytes
/
hash.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package SPHINCS_golang
import (
"github.com/dchest/blake256"
)
func Varlen(out, in []byte) {
h := blake256.New()
h.Write(in)
tmp := h.Sum(nil)
copy(out[:], tmp[:])
zerobytes(tmp[:])
}
func Hash_2n_n(out, in []byte) {
var x [64]byte
for i := 0; i < 32; i++ {
x[i] = in[i]
x[i+32] = HASHC[i]
}
permute(&x)
for i := 0; i < 32; i++ {
x[i] ^= in[i+32]
}
permute(&x)
copy(out[:HASHSIZE], x[:])
}
func Hash_2n_n_mask(out, in, mask []byte) {
var buf [2 * HASHSIZE]byte
for i := 0; i < len(buf); i++ {
buf[i] = in[i] ^ mask[i]
}
Hash_2n_n(out, buf[:])
}
func Hash_n_n(out, in []byte) {
var x [64]byte
for i := 0; i < 32; i++ {
x[i] = in[i]
x[i+32] = HASHC[i]
}
permute(&x)
copy(out[:HASHSIZE], x[:])
}
func Hash_n_n_mask(out, in, mask []byte) {
var buf [HASHSIZE]byte
for i := 0; i < len(buf); i++ {
buf[i] = in[i] ^ mask[i]
}
Hash_n_n(out, buf[:])
}
func init() {
if HASHSIZE != 32 {
panic("current code only supports 32-byte hashes")
}
}