This repository has been archived by the owner on Aug 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
algorithms.go
259 lines (249 loc) · 7.21 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
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
// COSE Algorithms
//
package cose
import (
"crypto"
"crypto/elliptic"
)
// KeyType is the type to use in keyOptions to tell MakeDEREndEntity
// which type of crypto.PrivateKey to generate
type KeyType int
const (
// KeyTypeUnsupported is the type to not generate a key
KeyTypeUnsupported KeyType = iota
// KeyTypeRSA is the type to generate an rsa.PrivateKey
KeyTypeRSA KeyType = iota
// KeyTypeECDSA is the type to generate an ecdsa.PrivateKey
KeyTypeECDSA KeyType = iota
)
// Algorithm represents an IANA algorithm's parameters (Name,
// Value/ID, and optional extra data)
//
// From the spec:
//
// NOTE: The assignment of algorithm identifiers in this document was
// done so that positive numbers were used for the first layer objects
// (COSE_Sign, COSE_Sign1, COSE_Encrypt, COSE_Encrypt0, COSE_Mac, and
// COSE_Mac0). Negative numbers were used for second layer objects
// (COSE_Signature and COSE_recipient).
//
// https://www.iana.org/assignments/cose/cose.xhtml#header-algorithm-parameters
//
// https://tools.ietf.org/html/rfc8152#section-16.4
//
type Algorithm struct {
Name string
Value int
// optional fields
HashFunc crypto.Hash // hash function for SignMessages
privateKeyType KeyType // private key type to generate for new Signers
minRSAKeyBitLen int // minimimum RSA key size to generate in bits
privateKeyECDSACurve elliptic.Curve // ecdsa private key curve type
}
// algorithms is an array/slice of IANA algorithms
var algorithms = []Algorithm{
Algorithm{
Name: "RSAES-OAEP w/ SHA-512", // RSAES-OAEP w/ SHA-512 from [RFC8230]
Value: -42,
},
Algorithm{
Name: "RSAES-OAEP w/ SHA-256", // RSAES-OAEP w/ SHA-256 from [RFC8230]
Value: -41,
},
Algorithm{
Name: "RSAES-OAEP w/ RFC 8017 default parameters", // RSAES-OAEP w/ SHA-1 from [RFC8230]
Value: -40,
},
Algorithm{
Name: "PS512", // RSASSA-PSS w/ SHA-512 from [RFC8230]
Value: -39,
},
Algorithm{
Name: "PS384", // RSASSA-PSS w/ SHA-384 from [RFC8230]
Value: -38,
},
Algorithm{
Name: "PS256", // RSASSA-PSS w/ SHA-256 from [RFC8230]
Value: -37,
HashFunc: crypto.SHA256,
privateKeyType: KeyTypeRSA,
minRSAKeyBitLen: 2048,
},
Algorithm{
Name: "ES512", // ECDSA w/ SHA-512 from [RFC8152]
Value: -36,
HashFunc: crypto.SHA512,
privateKeyType: KeyTypeECDSA,
privateKeyECDSACurve: elliptic.P521(),
},
Algorithm{
Name: "ES384", // ECDSA w/ SHA-384 from [RFC8152]
Value: -35,
HashFunc: crypto.SHA384,
privateKeyType: KeyTypeECDSA,
privateKeyECDSACurve: elliptic.P384(),
},
Algorithm{
Name: "ECDH-SS + A256KW", // ECDH SS w/ Concat KDF and AES Key Wrap w/ 256-bit key from [RFC8152]
Value: -34,
},
Algorithm{
Name: "ECDH-SS + A192KW", // ECDH SS w/ Concat KDF and AES Key Wrap w/ 192-bit key from [RFC8152]
Value: -33,
},
Algorithm{
Name: "ECDH-SS + A128KW", // ECDH SS w/ Concat KDF and AES Key Wrap w/ 128-bit key from [RFC8152]
Value: -32,
},
Algorithm{
Name: "ECDH-ES + A256KW", // ECDH ES w/ Concat KDF and AES Key Wrap w/ 256-bit key from [RFC8152]
Value: -31,
},
Algorithm{
Name: "ECDH-ES + A192KW", // ECDH ES w/ Concat KDF and AES Key Wrap w/ 192-bit key from [RFC8152]
Value: -30,
},
Algorithm{
Name: "ECDH-ES + A128KW", // ECDH ES w/ Concat KDF and AES Key Wrap w/ 128-bit key from [RFC8152]
Value: -29,
},
Algorithm{
Name: "ECDH-SS + HKDF-512", // ECDH SS w/ HKDF - generate key directly from [RFC8152]
Value: -28,
},
Algorithm{
Name: "ECDH-SS + HKDF-256", // ECDH SS w/ HKDF - generate key directly from [RFC8152]
Value: -27,
},
Algorithm{
Name: "ECDH-ES + HKDF-512", // ECDH ES w/ HKDF - generate key directly from [RFC8152]
Value: -26,
},
Algorithm{
Name: "ECDH-ES + HKDF-256", // ECDH ES w/ HKDF - generate key directly from [RFC8152]
Value: -25,
},
Algorithm{
Name: "direct+HKDF-AES-256", // Shared secret w/ AES-MAC 256-bit key from [RFC8152]
Value: -13,
},
Algorithm{
Name: "direct+HKDF-AES-128", // Shared secret w/ AES-MAC 128-bit key from [RFC8152]
Value: -12,
},
Algorithm{
Name: "direct+HKDF-SHA-512", // Shared secret w/ HKDF and SHA-512 from [RFC8152]
Value: -11,
},
Algorithm{
Name: "direct+HKDF-SHA-256", // Shared secret w/ HKDF and SHA-256 from [RFC8152]
Value: -10,
},
Algorithm{
Name: "EdDSA", // EdDSA from [RFC8152]
Value: -8,
},
Algorithm{
Name: "ES256", // ECDSA w/ SHA-256 from [RFC8152]
Value: -7,
HashFunc: crypto.SHA256,
privateKeyType: KeyTypeECDSA,
privateKeyECDSACurve: elliptic.P256(),
},
Algorithm{
Name: "direct", // Direct use of CEK from [RFC8152]
Value: -6,
},
Algorithm{
Name: "A256KW", // AES Key Wrap w/ 256-bit key from [RFC8152]
Value: -5,
},
Algorithm{
Name: "A192KW", // AES Key Wrap w/ 192-bit key from [RFC8152]
Value: -4,
},
Algorithm{
Name: "A128KW", // AES Key Wrap w/ 128-bit key from [RFC8152]
Value: -3,
},
Algorithm{
Name: "A128GCM", // AES-GCM mode w/ 128-bit key, 128-bit tag from [RFC8152]
Value: 1,
},
Algorithm{
Name: "A192GCM", // AES-GCM mode w/ 192-bit key, 128-bit tag from [RFC8152]
Value: 2,
},
Algorithm{
Name: "A256GCM", // AES-GCM mode w/ 256-bit key, 128-bit tag from [RFC8152]
Value: 3,
},
Algorithm{
Name: "HMAC 256/64", // HMAC w/ SHA-256 truncated to 64 bits from [RFC8152]
Value: 4,
},
Algorithm{
Name: "HMAC 256/256", // HMAC w/ SHA-256 from [RFC8152]
Value: 5,
},
Algorithm{
Name: "HMAC 384/384", // HMAC w/ SHA-384 from [RFC8152]
Value: 6,
},
Algorithm{
Name: "HMAC 512/512", // HMAC w/ SHA-512 from [RFC8152]
Value: 7,
},
Algorithm{
Name: "AES-CCM-16-64-128", // AES-CCM mode 128-bit key, 64-bit tag, 13-byte nonce from [RFC8152]
Value: 10,
},
Algorithm{
Name: "AES-CCM-16-64-256", // AES-CCM mode 256-bit key, 64-bit tag, 13-byte nonce from [RFC8152]
Value: 11,
},
Algorithm{
Name: "AES-CCM-64-64-128", // AES-CCM mode 128-bit key, 64-bit tag, 7-byte nonce from [RFC8152]
Value: 12,
},
Algorithm{
Name: "AES-CCM-64-64-256", // AES-CCM mode 256-bit key, 64-bit tag, 7-byte nonce from [RFC8152]
Value: 13,
},
Algorithm{
Name: "AES-MAC 128/64", // AES-MAC 128-bit key, 64-bit tag from [RFC8152]
Value: 14,
},
Algorithm{
Name: "AES-MAC 256/64", // AES-MAC 256-bit key, 64-bit tag from [RFC8152]
Value: 15,
},
Algorithm{
Name: "ChaCha20/Poly1305", // ChaCha20/Poly1305 w/ 256-bit key, 128-bit tag from [RFC8152]
Value: 24,
},
Algorithm{
Name: "AES-MAC 128/128", // AES-MAC 128-bit key, 128-bit tag from [RFC8152]
Value: 25,
},
Algorithm{
Name: "AES-MAC 256/128", // AES-MAC 256-bit key, 128-bit tag from [RFC8152]
Value: 26,
},
Algorithm{
Name: "AES-CCM-16-128-128", // AES-CCM mode 128-bit key, 128-bit tag, 13-byte nonce from [RFC8152]
Value: 30,
},
Algorithm{
Name: "AES-CCM-16-128-256", // AES-CCM mode 256-bit key, 128-bit tag, 13-byte nonce from [RFC8152]
Value: 31,
},
Algorithm{
Name: "AES-CCM-64-128-128", // AES-CCM mode 128-bit key, 128-bit tag, 7-byte nonce from [RFC8152]
Value: 32,
},
Algorithm{
Name: "AES-CCM-64-128-256", // AES-CCM mode 256-bit key, 128-bit tag, 7-byte nonce from [RFC8152]
Value: 33,
},
}