Skip to content

Commit 335a0f8

Browse files
committed
[dev.boringcrypto] crypto/aes: implement TLS-specific AES-GCM mode from BoringCrypto
Change-Id: I8407310e7d00eafe9208879228dbf4ac3d26a907 Reviewed-on: https://go-review.googlesource.com/55477 Run-TryBot: Russ Cox <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Adam Langley <[email protected]>
1 parent 8d05ec9 commit 335a0f8

File tree

1 file changed

+22
-3
lines changed
  • src/crypto/internal/boring

1 file changed

+22
-3
lines changed

src/crypto/internal/boring/aes.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ type extraModes interface {
3636
NewCBCEncrypter(iv []byte) cipher.BlockMode
3737
NewCBCDecrypter(iv []byte) cipher.BlockMode
3838
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)
4043
}
4144

4245
var _ extraModes = (*aesCipher)(nil)
@@ -172,6 +175,14 @@ type noGCM struct {
172175
}
173176

174177
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) {
175186
if nonceSize != gcmStandardNonceSize {
176187
// Fall back to standard library for GCM with non-standard nonce size.
177188
return cipher.NewGCMWithNonceSize(&noGCM{c}, nonceSize)
@@ -180,9 +191,17 @@ func (c *aesCipher) NewGCM(nonceSize int) (cipher.AEAD, error) {
180191
var aead *C.GO_EVP_AEAD
181192
switch len(c.key) * 8 {
182193
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+
}
184199
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+
}
186205
default:
187206
// Fall back to standard library for GCM with non-standard key size.
188207
return cipher.NewGCMWithNonceSize(&noGCM{c}, nonceSize)

0 commit comments

Comments
 (0)