-
Notifications
You must be signed in to change notification settings - Fork 0
/
hash.go
63 lines (56 loc) · 1.02 KB
/
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
61
62
63
package sphincs
import (
"github.com/zeebo/blake3"
)
const (
hashSize = 32
hashC = "expand 32-byte to 64-byte state!"
)
// hashVarlen ...
func hashVarlen(out, in []byte) {
tmp := blake3.Sum256(in)
copy(out[:], tmp[:])
for i := range tmp {
tmp[i] = '0'
}
}
// hashH2nn ...
func hashH2nn(out, in []byte) {
var x [64]byte
for i := 0; i < 32; i++ {
x[i] = in[i]
x[i+32] = hashC[i]
}
chachaPermute(&x)
for i := 0; i < 32; i++ {
x[i] ^= in[i+32]
}
chachaPermute(&x)
copy(out[:hashSize], x[:])
}
// hashH2nnMask ...
func hashH2nnMask(out, in, mask []byte) {
var buf [2 * hashSize]byte
for i := 0; i < len(buf); i++ {
buf[i] = in[i] ^ mask[i]
}
hashH2nn(out, buf[:])
}
// hashHnn ...
func hashHnn(out, in []byte) {
var x [64]byte
for i := 0; i < 32; i++ {
x[i] = in[i]
x[i+32] = hashC[i]
}
chachaPermute(&x)
copy(out[:hashSize], x[:])
}
// hashHnnMask ...
func hashHnnMask(out, in, mask []byte) {
var buf [hashSize]byte
for i := 0; i < len(buf); i++ {
buf[i] = in[i] ^ mask[i]
}
hashHnn(out, buf[:])
}