-
Notifications
You must be signed in to change notification settings - Fork 12
/
zaes.go
86 lines (75 loc) · 1.74 KB
/
zaes.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
// Code generated by cmd/genaesmodes. DO NOT EDIT.
//go:build cgo && !cmd_go_bootstrap
package openssl
import "crypto/cipher"
type cipherWithCBC struct {
aesCipher
}
type cipherWithCTR struct {
aesCipher
}
type cipherWithCBC_CTR struct {
aesCipher
cipherWithCBC
cipherWithCTR
}
type cipherWithGCM struct {
aesCipher
}
type cipherWithCBC_GCM struct {
aesCipher
cipherWithCBC
cipherWithGCM
}
type cipherWithCTR_GCM struct {
aesCipher
cipherWithCTR
cipherWithGCM
}
type cipherWithCBC_CTR_GCM struct {
aesCipher
cipherWithCBC
cipherWithCTR
cipherWithGCM
}
func newAESBlock(c *evpCipher, kind cipherKind) cipher.Block {
aes := aesCipher{c}
var block cipher.Block
supportsCBC := loadCipher(kind, cipherModeCBC) != nil
supportsCTR := loadCipher(kind, cipherModeCTR) != nil
supportsGCM := loadCipher(kind, cipherModeGCM) != nil
switch {
case !supportsCBC && !supportsCTR && !supportsGCM:
block = aes
case supportsCBC && !supportsCTR && !supportsGCM:
block = cipherWithCBC{aes}
case !supportsCBC && supportsCTR && !supportsGCM:
block = cipherWithCTR{aes}
case supportsCBC && supportsCTR && !supportsGCM:
block = cipherWithCBC_CTR{aes,
cipherWithCBC{aes},
cipherWithCTR{aes},
}
case !supportsCBC && !supportsCTR && supportsGCM:
block = cipherWithGCM{aes}
case supportsCBC && !supportsCTR && supportsGCM:
block = cipherWithCBC_GCM{aes,
cipherWithCBC{aes},
cipherWithGCM{aes},
}
case !supportsCBC && supportsCTR && supportsGCM:
block = cipherWithCTR_GCM{aes,
cipherWithCTR{aes},
cipherWithGCM{aes},
}
case supportsCBC && supportsCTR && supportsGCM:
block = cipherWithCBC_CTR_GCM{aes,
cipherWithCBC{aes},
cipherWithCTR{aes},
cipherWithGCM{aes},
}
default:
panic("unreachable")
}
return block
}