@@ -36,7 +36,10 @@ type extraModes interface {
36
36
NewCBCEncrypter (iv []byte ) cipher.BlockMode
37
37
NewCBCDecrypter (iv []byte ) cipher.BlockMode
38
38
NewCTR (iv []byte ) cipher.Stream
39
- NewGCM (size int ) (cipher.AEAD , error )
39
+ NewGCM (nonceSize int ) (cipher.AEAD , error )
40
+
41
+ // Invented for BoringCrypto.
42
+ NewGCMTLS () (cipher.AEAD , error )
40
43
}
41
44
42
45
var _ extraModes = (* aesCipher )(nil )
@@ -172,6 +175,14 @@ type noGCM struct {
172
175
}
173
176
174
177
func (c * aesCipher ) NewGCM (nonceSize int ) (cipher.AEAD , error ) {
178
+ return c .newGCM (nonceSize , false )
179
+ }
180
+
181
+ func (c * aesCipher ) NewGCMTLS () (cipher.AEAD , error ) {
182
+ return c .newGCM (gcmStandardNonceSize , true )
183
+ }
184
+
185
+ func (c * aesCipher ) newGCM (nonceSize int , tls bool ) (cipher.AEAD , error ) {
175
186
if nonceSize != gcmStandardNonceSize {
176
187
// Fall back to standard library for GCM with non-standard nonce size.
177
188
return cipher .NewGCMWithNonceSize (& noGCM {c }, nonceSize )
@@ -180,9 +191,17 @@ func (c *aesCipher) NewGCM(nonceSize int) (cipher.AEAD, error) {
180
191
var aead * C.GO_EVP_AEAD
181
192
switch len (c .key ) * 8 {
182
193
case 128 :
183
- aead = C ._goboringcrypto_EVP_aead_aes_128_gcm ()
194
+ if tls {
195
+ aead = C ._goboringcrypto_EVP_aead_aes_128_gcm_tls12 ()
196
+ } else {
197
+ aead = C ._goboringcrypto_EVP_aead_aes_128_gcm ()
198
+ }
184
199
case 256 :
185
- aead = C ._goboringcrypto_EVP_aead_aes_256_gcm ()
200
+ if tls {
201
+ aead = C ._goboringcrypto_EVP_aead_aes_256_gcm_tls12 ()
202
+ } else {
203
+ aead = C ._goboringcrypto_EVP_aead_aes_256_gcm ()
204
+ }
186
205
default :
187
206
// Fall back to standard library for GCM with non-standard key size.
188
207
return cipher .NewGCMWithNonceSize (& noGCM {c }, nonceSize )
0 commit comments