From ed285a247a3a967e02f428fa2b6e69d629e2bd14 Mon Sep 17 00:00:00 2001 From: Rose Hogenson Date: Tue, 30 Sep 2025 19:15:04 -0700 Subject: Fix a small issue with updating the block index For the reader, we should only update the block index once we've successfully read a block. --- internal/cryptoutil/oae2.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'internal/cryptoutil/oae2.go') diff --git a/internal/cryptoutil/oae2.go b/internal/cryptoutil/oae2.go index 2819852..4e667b7 100644 --- a/internal/cryptoutil/oae2.go +++ b/internal/cryptoutil/oae2.go @@ -60,7 +60,6 @@ func (o *oae2) nonce(nonce []byte, lastBlock bool) error { return errors.New("counter overflowed (64 bits??)") } binary.BigEndian.PutUint64(nonce[noncePrefixSize:], o.i) - o.i++ if lastBlock { nonce[gcmNonceSize-1] = 1 } @@ -73,6 +72,7 @@ func (o *oae2) encryptBlock(out, block []byte, lastBlock bool) ([]byte, error) { return nil, err } encrypted := o.aead.Seal(out, nonce, block, o.additionalData) + o.i++ o.additionalData = nil return encrypted, nil } @@ -83,8 +83,12 @@ func (o *oae2) decryptBlock(out, block []byte, lastBlock bool) ([]byte, error) { return nil, err } decrypted, err := o.aead.Open(out, nonce, block, o.additionalData) + if err != nil { + return nil, err + } + o.i++ o.additionalData = nil - return decrypted, err + return decrypted, nil } // An EncryptingWriter encrypts data in segments using the STREAM construction -- cgit v1.3.1