Skip to content

Commit b47ce8b

Browse files
FiloSottilegopherbot
authored andcommitted
crypto/cipher: block non-AES CTR and CBC in fips140=only mode
Somehow I had missed these. For #69536 Change-Id: I5e60b6f052bbfb707742ad15f663517c6c5f68d3 Reviewed-on: https://go-review.googlesource.com/c/go/+/636795 Auto-Submit: Filippo Valsorda <[email protected]> Reviewed-by: Roland Shoemaker <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: David Chase <[email protected]>
1 parent dd7a7ba commit b47ce8b

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/crypto/cipher/cbc.go

+7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"bytes"
1616
"crypto/internal/fips140/aes"
1717
"crypto/internal/fips140/alias"
18+
"crypto/internal/fips140only"
1819
"crypto/subtle"
1920
)
2021

@@ -53,6 +54,9 @@ func NewCBCEncrypter(b Block, iv []byte) BlockMode {
5354
if b, ok := b.(*aes.Block); ok {
5455
return aes.NewCBCEncrypter(b, [16]byte(iv))
5556
}
57+
if fips140only.Enabled {
58+
panic("crypto/cipher: use of CBC with non-AES ciphers is not allowed in FIPS 140-only mode")
59+
}
5660
if cbc, ok := b.(cbcEncAble); ok {
5761
return cbc.NewCBCEncrypter(iv)
5862
}
@@ -129,6 +133,9 @@ func NewCBCDecrypter(b Block, iv []byte) BlockMode {
129133
if b, ok := b.(*aes.Block); ok {
130134
return aes.NewCBCDecrypter(b, [16]byte(iv))
131135
}
136+
if fips140only.Enabled {
137+
panic("crypto/cipher: use of CBC with non-AES ciphers is not allowed in FIPS 140-only mode")
138+
}
132139
if cbc, ok := b.(cbcDecAble); ok {
133140
return cbc.NewCBCDecrypter(iv)
134141
}

src/crypto/cipher/ctr.go

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"bytes"
1717
"crypto/internal/fips140/aes"
1818
"crypto/internal/fips140/alias"
19+
"crypto/internal/fips140only"
1920
"crypto/subtle"
2021
)
2122

@@ -41,6 +42,9 @@ func NewCTR(block Block, iv []byte) Stream {
4142
if block, ok := block.(*aes.Block); ok {
4243
return aesCtrWrapper{aes.NewCTR(block, iv)}
4344
}
45+
if fips140only.Enabled {
46+
panic("crypto/cipher: use of CTR with non-AES ciphers is not allowed in FIPS 140-only mode")
47+
}
4448
if ctr, ok := block.(ctrAble); ok {
4549
return ctr.NewCTR(iv)
4650
}

0 commit comments

Comments
 (0)