-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhash_address.go
85 lines (70 loc) · 2.33 KB
/
hash_address.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package xmss
/*
OTC address L-tree addrress Hash Tree address
+-------------------------+ +-------------------------+ +-------------------------+
| layer address (32 bits)| | layer address (32 bits)| | layer address (32 bits)|
+-------------------------+ +-------------------------+ +-------------------------+
| tree address (64 bits)| | tree address (64 bits)| | tree address (64 bits)|
+-------------------------+ +-------------------------+ +-------------------------+
| type = 0 (32 bits)| | type = 1 (32 bits)| | type = 2 (32 bits)|
+-------------------------+ +-------------------------+ +-------------------------+
| OTS address (32 bits)| | L-tree address (32 bits)| | Padding = 0 (32 bits)|
+-------------------------+ +-------------------------+ +-------------------------+
| chain address (32 bits)| | tree height (32 bits)| | tree height (32 bits)|
+-------------------------+ +-------------------------+ +-------------------------+
| hash address (32 bits)| | tree index (32 bits)| | tree index (32 bits)|
+-------------------------+ +-------------------------+ +-------------------------+
| keyAndMask (32 bits)| | keyAndMask (32 bits)| | keyAndMask (32 bits)|
+-------------------------+ +-------------------------+ +-------------------------+
*/
type address [8]uint32
const (
xmssAddrTypeOTS = 0
xmssAddrTypeLTREE = 1
xmssAddrTypeHASHTREE = 2
)
func (a *address) setLayerAddr(layer uint32) {
a[0] = layer
}
func (a *address) setTreeAddr(tree uint64) {
a[1] = uint32(tree >> 32)
a[2] = uint32(tree)
}
func (a *address) setType(typ uint32) {
a[3] = typ
}
func (a *address) setKeyAndMask(keyMask uint32) {
a[7] = keyMask
}
func (a *address) copySubtreeAddr(b address) {
a[0] = b[0]
a[1] = b[1]
a[2] = b[2]
}
func (a *address) setOTSAddr(ots uint32) {
a[4] = ots
}
func (a *address) setChainAddr(chain uint32) {
a[5] = chain
}
func (a *address) setHashAddr(hash uint32) {
a[6] = hash
}
func (a *address) setLTreeAddr(ltree uint32) {
a[4] = ltree
}
func (a *address) setTreeHeight(h uint32) {
a[5] = h
}
func (a *address) setTreeIndex(idx uint32) {
a[6] = idx
}
func (a *address) toByte() (out []byte) {
out = make([]byte, len(a)*4)
j := 0
for i := 0; i < len(out); i += 4 {
copy(out[i:], uint32ToByte(a[j]))
j++
}
return
}