/
algorithms.go
71 lines (58 loc) · 1.1 KB
/
algorithms.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
//
// algorithms.go
//
// Copyright (c) 2018 Markku Rossi
//
// All rights reserved.
//
package zone
import (
"fmt"
)
type Suite byte
func (s Suite) String() string {
name, ok := suites[s]
if ok {
return name
}
return fmt.Sprintf("{Suite %d}", s)
}
func (s Suite) IDHashKeyLen() int {
len, ok := suiteIDHashKeyLengths[s]
if !ok {
panic(fmt.Sprintf("Unknown suite: %d", s))
}
return len
}
func (s Suite) CipherKeyLen() int {
len, ok := suiteCipherKeyLengths[s]
if !ok {
panic(fmt.Sprintf("Unknown suite: %d", s))
}
return len
}
func (s Suite) HMACKeyLen() int {
len, ok := suiteHMACKeyLengths[s]
if !ok {
panic(fmt.Sprintf("Unknown suite: %d", s))
}
return len
}
func (s Suite) KeyLen() int {
return s.IDHashKeyLen() + s.CipherKeyLen() + s.HMACKeyLen()
}
const (
AES256CBCHMACSHA256 Suite = 0
)
var suites = map[Suite]string{
AES256CBCHMACSHA256: "AES256-CBC-HMAC-SHA256",
}
var suiteIDHashKeyLengths = map[Suite]int{
AES256CBCHMACSHA256: 32,
}
var suiteCipherKeyLengths = map[Suite]int{
AES256CBCHMACSHA256: 32,
}
var suiteHMACKeyLengths = map[Suite]int{
AES256CBCHMACSHA256: 32,
}