-
Notifications
You must be signed in to change notification settings - Fork 0
/
cipher_suite_tls_ecdhe_ecdsa_with_aes_256_cbc_sha.go
70 lines (56 loc) · 1.71 KB
/
cipher_suite_tls_ecdhe_ecdsa_with_aes_256_cbc_sha.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
package dtls
import (
"crypto/sha256"
"errors"
"hash"
)
type cipherSuiteTLSEcdheEcdsaWithAes256CbcSha struct {
cbc *cryptoCBC
}
func (c cipherSuiteTLSEcdheEcdsaWithAes256CbcSha) certificateType() clientCertificateType {
return clientCertificateTypeECDSASign
}
func (c cipherSuiteTLSEcdheEcdsaWithAes256CbcSha) ID() cipherSuiteID {
return 0xc00a
}
func (c cipherSuiteTLSEcdheEcdsaWithAes256CbcSha) String() string {
return "TLSEcdheEcdsaWithAes256CbcSha"
}
func (c cipherSuiteTLSEcdheEcdsaWithAes256CbcSha) hashFunc() func() hash.Hash {
return sha256.New
}
func (c *cipherSuiteTLSEcdheEcdsaWithAes256CbcSha) init(masterSecret, clientRandom, serverRandom []byte, isClient bool) error {
const (
prfMacLen = 20
prfKeyLen = 32
prfIvLen = 16
)
keys, err := prfEncryptionKeys(masterSecret, clientRandom, serverRandom, prfMacLen, prfKeyLen, prfIvLen, c.hashFunc())
if err != nil {
return err
}
if isClient {
c.cbc, err = newCryptoCBC(
keys.clientWriteKey, keys.clientWriteIV, keys.clientMACKey,
keys.serverWriteKey, keys.serverWriteIV, keys.serverMACKey,
)
} else {
c.cbc, err = newCryptoCBC(
keys.serverWriteKey, keys.serverWriteIV, keys.serverMACKey,
keys.clientWriteKey, keys.clientWriteIV, keys.clientMACKey,
)
}
return err
}
func (c *cipherSuiteTLSEcdheEcdsaWithAes256CbcSha) encrypt(pkt *recordLayer, raw []byte) ([]byte, error) {
if c.cbc == nil {
return nil, errors.New("CipherSuite has not been initalized, unable to encrypt")
}
return c.cbc.encrypt(pkt, raw)
}
func (c *cipherSuiteTLSEcdheEcdsaWithAes256CbcSha) decrypt(raw []byte) ([]byte, error) {
if c.cbc == nil {
return nil, errors.New("CipherSuite has not been initalized, unable to decrypt ")
}
return c.cbc.decrypt(raw)
}