-
Notifications
You must be signed in to change notification settings - Fork 25
/
cipher_setting.go
236 lines (208 loc) · 5.54 KB
/
cipher_setting.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
package ssh
import (
"crypto/aes"
"crypto/des"
"crypto/cipher"
"golang.org/x/crypto/cast5"
"golang.org/x/crypto/blowfish"
"golang.org/x/crypto/chacha20poly1305"
"github.com/tjfoc/gmsm/sm4"
)
var (
SSHDESEDE3CBC = "3des-cbc"
SSHAES128CBC = "aes128-cbc"
SSHAES192CBC = "aes192-cbc"
SSHAES256CBC = "aes256-cbc"
SSHAES128CTR = "aes128-ctr"
SSHAES192CTR = "aes192-ctr"
SSHAES256CTR = "aes256-ctr"
SSHAES128GCM = "aes128-gcm@openssh.com"
SSHAES256GCM = "aes256-gcm@openssh.com"
// RC4 = arcfour
SSHArcfour = "arcfour"
SSHArcfour128 = "arcfour128"
SSHArcfour256 = "arcfour256"
SSHBlowfishCBC = "blowfish-cbc"
// cast5 = cast128
SSHCast128CBC = "cast128-cbc"
SSHChacha20poly1305 = "chacha20-poly1305@openssh.com"
SSHSM4CBC = "sm4-cbc"
SSHSM4CTR = "sm4-ctr"
)
var (
newBlowfishCipher = func(key []byte) (cipher.Block, error) {
return blowfish.NewCipher(key)
}
newCast5Cipher = func(key []byte) (cipher.Block, error) {
return cast5.NewCipher(key)
}
)
// DESEDE3CBC is the 168-bit key 3DES cipher in CBC mode.
var DESEDE3CBC = CipherCBC{
cipherFunc: des.NewTripleDESCipher,
keySize: 24,
blockSize: des.BlockSize,
identifier: SSHDESEDE3CBC,
}
// BlowfishCBC is the key (from 1 to 56 bytes) blowfish cipher in CBC mode.
var BlowfishCBC = CipherCBC{
cipherFunc: newBlowfishCipher,
keySize: 24,
blockSize: blowfish.BlockSize,
identifier: SSHBlowfishCBC,
}
// Chacha20poly1305 is the 256-bit chacha20poly1305 cipher.
var Chacha20poly1305 = CipherChacha20poly1305{
keySize: 32,
nonceSize: chacha20poly1305.NonceSize,
identifier: SSHChacha20poly1305,
}
// Cast128CBC is the 128-bit key cast5 cipher in CBC mode.
var Cast128CBC = CipherCBC{
cipherFunc: newCast5Cipher,
keySize: 16,
blockSize: cast5.BlockSize,
identifier: SSHCast128CBC,
}
// AES128CBC is the 128-bit key AES cipher in CBC mode.
var AES128CBC = CipherCBC{
cipherFunc: aes.NewCipher,
keySize: 16,
blockSize: aes.BlockSize,
identifier: SSHAES128CBC,
}
// AES192CBC is the 192-bit key AES cipher in CBC mode.
var AES192CBC = CipherCBC{
cipherFunc: aes.NewCipher,
keySize: 24,
blockSize: aes.BlockSize,
identifier: SSHAES192CBC,
}
// AES256CBC is the 256-bit key AES cipher in CBC mode.
var AES256CBC = CipherCBC{
cipherFunc: aes.NewCipher,
keySize: 32,
blockSize: aes.BlockSize,
identifier: SSHAES256CBC,
}
// AES128CTR is the 128-bit key AES cipher in CTR mode.
var AES128CTR = CipherCTR{
cipherFunc: aes.NewCipher,
keySize: 16,
blockSize: aes.BlockSize,
identifier: SSHAES128CTR,
}
// AES192CTR is the 192-bit key AES cipher in CTR mode.
var AES192CTR = CipherCTR{
cipherFunc: aes.NewCipher,
keySize: 24,
blockSize: aes.BlockSize,
identifier: SSHAES192CTR,
}
// AES256CTR is the 256-bit key AES cipher in CTR mode.
var AES256CTR = CipherCTR{
cipherFunc: aes.NewCipher,
keySize: 32,
blockSize: aes.BlockSize,
identifier: SSHAES256CTR,
}
// AES128GCM is the 128-bit key AES cipher in GCM mode.
var AES128GCM = CipherGCM{
cipherFunc: aes.NewCipher,
keySize: 16,
nonceSize: 12,
identifier: SSHAES128GCM,
}
// AES256GCM is the 256-bit key AES cipher in GCM mode.
var AES256GCM = CipherGCM{
cipherFunc: aes.NewCipher,
keySize: 32,
nonceSize: 12,
identifier: SSHAES256GCM,
}
// Arcfour is the (from 1 to 256 bytes) key RC4 cipher.
var Arcfour = CipherRC4{
keySize: 8,
blockSize: 0,
identifier: SSHArcfour,
}
// Arcfour128 is the 128-bit key RC4 cipher.
var Arcfour128 = CipherRC4{
keySize: 16,
blockSize: 0,
identifier: SSHArcfour128,
}
// Arcfour256 is the 256-bit key RC4 cipher.
var Arcfour256 = CipherRC4{
keySize: 32,
blockSize: 0,
identifier: SSHArcfour256,
}
// SM4CBC is the 128-bit SM4 AES cipher in CBC mode.
var SM4CBC = CipherCBC{
cipherFunc: sm4.NewCipher,
keySize: 16,
blockSize: sm4.BlockSize,
identifier: SSHSM4CBC,
}
// SM4CTR is the 128-bit SM4 AES cipher in CTR mode.
var SM4CTR = CipherCTR{
cipherFunc: sm4.NewCipher,
keySize: 16,
blockSize: sm4.BlockSize,
identifier: SSHSM4CTR,
}
func init() {
AddCipher(SSHDESEDE3CBC, func() Cipher {
return DESEDE3CBC
})
AddCipher(SSHBlowfishCBC, func() Cipher {
return BlowfishCBC
})
AddCipher(SSHChacha20poly1305, func() Cipher {
return Chacha20poly1305
})
// Cast128CBC
AddCipher(SSHCast128CBC, func() Cipher {
return Cast128CBC
})
AddCipher(SSHAES128CBC, func() Cipher {
return AES128CBC
})
AddCipher(SSHAES128CTR, func() Cipher {
return AES128CTR
})
AddCipher(SSHAES192CBC, func() Cipher {
return AES192CBC
})
AddCipher(SSHAES192CTR, func() Cipher {
return AES192CTR
})
AddCipher(SSHAES256CBC, func() Cipher {
return AES256CBC
})
AddCipher(SSHAES256CTR, func() Cipher {
return AES256CTR
})
AddCipher(SSHAES128GCM, func() Cipher {
return AES128GCM
})
AddCipher(SSHAES256GCM, func() Cipher {
return AES256GCM
})
AddCipher(SSHArcfour, func() Cipher {
return Arcfour
})
AddCipher(SSHArcfour128, func() Cipher {
return Arcfour128
})
AddCipher(SSHArcfour256, func() Cipher {
return Arcfour256
})
AddCipher(SSHSM4CBC, func() Cipher {
return SM4CBC
})
AddCipher(SSHSM4CTR, func() Cipher {
return SM4CTR
})
}