From 92b993e79e0ea503ca51d3d09e1da2d0e88be196 Mon Sep 17 00:00:00 2001 From: Isaac Good Date: Thu, 14 Aug 2025 21:56:20 -0700 Subject: [PATCH] decrypt: Attempt to use a `NewGCM()` without specifying nonce and tag size before bailing. --- utils.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/utils.go b/utils.go index fd2f35b..a7a3c74 100644 --- a/utils.go +++ b/utils.go @@ -94,7 +94,7 @@ type gcmAble interface { NewGCM(nonceSize, tagSize int) (cipher.AEAD, error) } -func newGCMWithNonceAndTagSize(cipher cipher.Block, nonceSize, tagSize int) (cipher.AEAD, error) { +func newGCMWithNonceAndTagSize(block cipher.Block, nonceSize, tagSize int) (cipher.AEAD, error) { if tagSize < gcmMinimumTagSize || tagSize > gcmBlockSize { return nil, errors.New("cipher: incorrect tag size given to GCM") } @@ -103,9 +103,10 @@ func newGCMWithNonceAndTagSize(cipher cipher.Block, nonceSize, tagSize int) (cip return nil, errors.New("cipher: the nonce can't have zero length, or the security of the key will be immediately compromised") } - if cipher, ok := cipher.(gcmAble); ok { - return cipher.NewGCM(nonceSize, tagSize) + if block, ok := block.(gcmAble); ok { + return block.NewGCM(nonceSize, tagSize) } - - panic("non GCM crypto is not supported") + // Attempt to use cipher.NewGCM() before giving up. + // This matches the encrypt logic and works fine for some privatebin implementations. + return cipher.NewGCM(block) }