forked from jedisct1/piknik
-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.go
98 lines (85 loc) · 1.9 KB
/
auth.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
86
87
88
89
90
91
92
93
94
95
96
97
98
package main
import blake2b "github.com/minio/blake2b-simd"
func auth0(conf Conf, clientVersion byte, r []byte) []byte {
hf0, _ := blake2b.New(&blake2b.Config{
Key: conf.Psk,
Person: []byte(DomainStr),
Size: 32,
Salt: []byte{0},
})
hf0.Write([]byte{clientVersion})
hf0.Write(r)
h0 := hf0.Sum(nil)
return h0
}
func auth1(conf Conf, clientVersion byte, h0 []byte, r2 []byte) []byte {
hf1, _ := blake2b.New(&blake2b.Config{
Key: conf.Psk,
Person: []byte(DomainStr),
Size: 32,
Salt: []byte{1},
})
hf1.Write([]byte{clientVersion})
hf1.Write(r2)
hf1.Write(h0)
h1 := hf1.Sum(nil)
return h1
}
func auth2get(conf Conf, clientVersion byte, h1 []byte, opcode byte) []byte {
hf2, _ := blake2b.New(&blake2b.Config{
Key: conf.Psk,
Person: []byte(DomainStr),
Size: 32,
Salt: []byte{2},
})
hf2.Write(h1)
hf2.Write([]byte{opcode})
h2 := hf2.Sum(nil)
return h2
}
func auth2store(conf Conf, clientVersion byte, h1 []byte, opcode byte,
encryptSkID []byte, ts []byte, signature []byte) []byte {
hf2, _ := blake2b.New(&blake2b.Config{
Key: conf.Psk,
Person: []byte(DomainStr),
Size: 32,
Salt: []byte{2},
})
hf2.Write(h1)
hf2.Write([]byte{opcode})
hf2.Write(encryptSkID)
if clientVersion >= 5 {
hf2.Write(ts)
}
hf2.Write(signature)
h2 := hf2.Sum(nil)
return h2
}
func auth3get(conf Conf, clientVersion byte, h2 []byte, encryptSkID []byte,
ts []byte, signature []byte) []byte {
hf3, _ := blake2b.New(&blake2b.Config{
Key: conf.Psk,
Person: []byte(DomainStr),
Size: 32,
Salt: []byte{3},
})
hf3.Write(h2)
hf3.Write(encryptSkID)
if clientVersion >= 5 {
hf3.Write(ts)
}
hf3.Write(signature)
h3 := hf3.Sum(nil)
return h3
}
func auth3store(conf Conf, h2 []byte) []byte {
hf3, _ := blake2b.New(&blake2b.Config{
Key: conf.Psk,
Person: []byte(DomainStr),
Size: 32,
Salt: []byte{3},
})
hf3.Write(h2)
h3 := hf3.Sum(nil)
return h3
}