Skip to content

crypto/cipher: add a new func NewGCMWithNonceSizeAndTagSize allows the user to specify the nonce size and tag size. #74467

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/crypto/cipher/gcm.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ func NewGCMWithTagSize(cipher Block, tagSize int) (AEAD, error) {
return newGCM(cipher, gcmStandardNonceSize, tagSize)
}

// NewGCMWithNonceSizeAndTagSize allows the user to specify the nonce size and tag size.
// This is useful for compatibility with existing cryptosystems that use non-standard nonce sizes and tag sizes.
func NewGCMWithNonceSizeAndTagSize(cipher Block, nonceSize, tagSize int) (AEAD, error) {
if fips140only.Enabled {
return nil, errors.New("crypto/cipher: use of GCM with arbitrary IVs is not allowed in FIPS 140-only mode, use NewGCMWithRandomNonce")
}
return newGCM(cipher, nonceSize, tagSize)
}

func newGCM(cipher Block, nonceSize, tagSize int) (AEAD, error) {
c, ok := cipher.(*aes.Block)
if !ok {
Expand Down