Skip to content

Commit 11ea305

Browse files
committed
feat(crypto): NewGCMWithNonceSizeAndTagSize
1 parent b325151 commit 11ea305

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/crypto/cipher/gcm.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,15 @@ func NewGCMWithTagSize(cipher Block, tagSize int) (AEAD, error) {
6363
return newGCM(cipher, gcmStandardNonceSize, tagSize)
6464
}
6565

66+
// NewGCMWithNonceSizeAndTagSize allows the user to specify the nonce size and tag size.
67+
// This is useful for compatibility with existing cryptosystems that use non-standard nonce sizes and tag sizes.
68+
func NewGCMWithNonceSizeAndTagSize(cipher Block, nonceSize, tagSize int) (AEAD, error) {
69+
if fips140only.Enabled {
70+
return nil, errors.New("crypto/cipher: use of GCM with arbitrary IVs is not allowed in FIPS 140-only mode, use NewGCMWithRandomNonce")
71+
}
72+
return newGCM(cipher, nonceSize, tagSize)
73+
}
74+
6675
func newGCM(cipher Block, nonceSize, tagSize int) (AEAD, error) {
6776
c, ok := cipher.(*aes.Block)
6877
if !ok {

0 commit comments

Comments
 (0)