@@ -5,21 +5,16 @@ package crypto
5
5
6
6
import (
7
7
"crypto/elliptic"
8
- "crypto/hmac"
9
8
"crypto/rand"
10
- "crypto/sha1"
11
- "crypto/sha512"
12
9
"crypto/subtle"
13
10
"encoding/base64"
14
11
"errors"
15
12
"fmt"
16
- "hash"
17
13
"io"
18
14
19
15
pb "github.com/libp2p/go-libp2p-core/crypto/pb"
20
16
21
17
"github.com/gogo/protobuf/proto"
22
- "github.com/minio/sha256-simd"
23
18
)
24
19
25
20
const (
@@ -170,106 +165,6 @@ func GenerateEKeyPair(curveName string) ([]byte, GenSharedKey, error) {
170
165
return pubKey , done , nil
171
166
}
172
167
173
- // StretchedKeys ...
174
- type StretchedKeys struct {
175
- IV []byte
176
- MacKey []byte
177
- CipherKey []byte
178
- }
179
-
180
- // PENDING DEPRECATION: KeyStretcher() will be deprecated with secio; for new
181
- // code, please use PBKDF2 (golang.org/x/crypto/pbkdf2) instead.
182
- // KeyStretcher returns a set of keys for each party by stretching the shared key.
183
- // (myIV, theirIV, myCipherKey, theirCipherKey, myMACKey, theirMACKey).
184
- // This function accepts the following cipher types:
185
- // - AES-128
186
- // - AES-256
187
- // The function will panic upon receiving an unknown cipherType
188
- func KeyStretcher (cipherType string , hashType string , secret []byte ) (StretchedKeys , StretchedKeys ) {
189
- var cipherKeySize int
190
- var ivSize int
191
- switch cipherType {
192
- case "AES-128" :
193
- ivSize = 16
194
- cipherKeySize = 16
195
- case "AES-256" :
196
- ivSize = 16
197
- cipherKeySize = 32
198
- default :
199
- panic ("Unrecognized cipher, programmer error?" )
200
- }
201
-
202
- hmacKeySize := 20
203
-
204
- seed := []byte ("key expansion" )
205
-
206
- result := make ([]byte , 2 * (ivSize + cipherKeySize + hmacKeySize ))
207
-
208
- var h func () hash.Hash
209
-
210
- switch hashType {
211
- case "SHA1" :
212
- h = sha1 .New
213
- case "SHA256" :
214
- h = sha256 .New
215
- case "SHA512" :
216
- h = sha512 .New
217
- default :
218
- panic ("Unrecognized hash function, programmer error?" )
219
- }
220
-
221
- m := hmac .New (h , secret )
222
- // note: guaranteed to never return an error
223
- m .Write (seed )
224
-
225
- a := m .Sum (nil )
226
-
227
- j := 0
228
- for j < len (result ) {
229
- m .Reset ()
230
-
231
- // note: guaranteed to never return an error.
232
- m .Write (a )
233
- m .Write (seed )
234
-
235
- b := m .Sum (nil )
236
-
237
- todo := len (b )
238
-
239
- if j + todo > len (result ) {
240
- todo = len (result ) - j
241
- }
242
-
243
- copy (result [j :j + todo ], b )
244
-
245
- j += todo
246
-
247
- m .Reset ()
248
-
249
- // note: guaranteed to never return an error.
250
- m .Write (a )
251
-
252
- a = m .Sum (nil )
253
- }
254
-
255
- half := len (result ) / 2
256
- r1 := result [:half ]
257
- r2 := result [half :]
258
-
259
- var k1 StretchedKeys
260
- var k2 StretchedKeys
261
-
262
- k1 .IV = r1 [0 :ivSize ]
263
- k1 .CipherKey = r1 [ivSize : ivSize + cipherKeySize ]
264
- k1 .MacKey = r1 [ivSize + cipherKeySize :]
265
-
266
- k2 .IV = r2 [0 :ivSize ]
267
- k2 .CipherKey = r2 [ivSize : ivSize + cipherKeySize ]
268
- k2 .MacKey = r2 [ivSize + cipherKeySize :]
269
-
270
- return k1 , k2
271
- }
272
-
273
168
// UnmarshalPublicKey converts a protobuf serialized public key into its
274
169
// representative object
275
170
func UnmarshalPublicKey (data []byte ) (PubKey , error ) {
0 commit comments