@@ -20,7 +20,7 @@ type extraModes interface {
20
20
NewGCMTLS () (cipher.AEAD , error )
21
21
}
22
22
23
- var _ extraModes = (* aesCipher )(nil )
23
+ var _ extraModes = (* aesWithCTR )(nil )
24
24
25
25
func NewAESCipher (key []byte ) (cipher.Block , error ) {
26
26
var kind cipherKind
@@ -38,19 +38,32 @@ func NewAESCipher(key []byte) (cipher.Block, error) {
38
38
if err != nil {
39
39
return nil , err
40
40
}
41
- return & aesCipher {c }, nil
41
+ ac := aesCipher {c }
42
+ // The SymCrypt provider doesn't support AES-CTR.
43
+ // Prove that the provider supports AES-CTR before
44
+ // returning an aesWithCTR.
45
+ if loadCipher (kind , cipherModeCTR ) != nil {
46
+ return & aesWithCTR {ac }, nil
47
+ }
48
+ return & ac , nil
42
49
}
43
50
44
51
// NewGCMTLS returns a GCM cipher specific to TLS
45
52
// and should not be used for non-TLS purposes.
46
53
func NewGCMTLS (c cipher.Block ) (cipher.AEAD , error ) {
47
- return c .(* aesCipher ).NewGCMTLS ()
54
+ if c , ok := c .(* aesCipher ); ok {
55
+ return c .NewGCMTLS ()
56
+ }
57
+ return c .(* aesWithCTR ).NewGCMTLS ()
48
58
}
49
59
50
60
// NewGCMTLS13 returns a GCM cipher specific to TLS 1.3 and should not be used
51
61
// for non-TLS purposes.
52
62
func NewGCMTLS13 (c cipher.Block ) (cipher.AEAD , error ) {
53
- return c .(* aesCipher ).NewGCMTLS13 ()
63
+ if c , ok := c .(* aesCipher ); ok {
64
+ return c .NewGCMTLS13 ()
65
+ }
66
+ return c .(* aesWithCTR ).NewGCMTLS13 ()
54
67
}
55
68
56
69
type aesCipher struct {
@@ -83,10 +96,6 @@ func (c *aesCipher) NewCBCDecrypter(iv []byte) cipher.BlockMode {
83
96
return c .newCBC (iv , cipherOpDecrypt )
84
97
}
85
98
86
- func (c * aesCipher ) NewCTR (iv []byte ) cipher.Stream {
87
- return c .newCTR (iv )
88
- }
89
-
90
99
func (c * aesCipher ) NewGCM (nonceSize , tagSize int ) (cipher.AEAD , error ) {
91
100
return c .newGCMChecked (nonceSize , tagSize )
92
101
}
@@ -98,3 +107,11 @@ func (c *aesCipher) NewGCMTLS() (cipher.AEAD, error) {
98
107
func (c * aesCipher ) NewGCMTLS13 () (cipher.AEAD , error ) {
99
108
return c .newGCM (cipherGCMTLS13 )
100
109
}
110
+
111
+ type aesWithCTR struct {
112
+ aesCipher
113
+ }
114
+
115
+ func (c * aesWithCTR ) NewCTR (iv []byte ) cipher.Stream {
116
+ return c .newCTR (iv )
117
+ }
0 commit comments