-
Notifications
You must be signed in to change notification settings - Fork 24
/
ssh_interface.go
72 lines (53 loc) · 1.33 KB
/
ssh_interface.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
package ssh
import (
"crypto"
)
// 加密接口
type Cipher interface {
// 名称
Name() string
// 值大小
KeySize() int
// 块大小
BlockSize() int
// 加密, 返回: [加密后数据, error]
Encrypt(key, plaintext []byte) ([]byte, error)
// 解密
Decrypt(key, ciphertext []byte) ([]byte, error)
}
// KDF 设置接口
type KDFOpts interface {
// 名称
Name() string
// 生成密钥
DeriveKey(password []byte, size int) (key []byte, params string, err error)
// 随机数大小
GetSaltSize() int
}
// 数据接口
type KDFParameters interface {
// 生成密钥
DeriveKey(password []byte, kdfOpts string, size int) (key []byte, err error)
}
// Key 接口
type Key interface {
// 包装
Marshal(key crypto.PrivateKey, comment string) (string, []byte, []byte, error)
// 解析
Parse(data []byte) (crypto.PrivateKey, string, error)
}
var ciphers = make(map[string]func() Cipher)
// 添加加密
func AddCipher(name string, cipher func() Cipher) {
ciphers[name] = cipher
}
var kdfs = make(map[string]func() KDFParameters)
// 添加 kdf 方式
func AddKDF(name string, params func() KDFParameters) {
kdfs[name] = params
}
var keys = make(map[string]func() Key)
// 添加Key
func AddKey(name string, key func() Key) {
keys[name] = key
}