summaryrefslogtreecommitdiffstats
path: root/internal/cryptoutil
diff options
context:
space:
mode:
authorRose Hogenson <rosehogenson@posteo.net>2025-09-30 19:15:04 -0700
committerRose Hogenson <rosehogenson@posteo.net>2025-09-30 19:15:04 -0700
commited285a247a3a967e02f428fa2b6e69d629e2bd14 (patch)
treea6b21dbcec8783bfa431c0bef8f33ecede3021f8 /internal/cryptoutil
parentc6b35440c6ea8f934606ab6f3f47057c77b971bf (diff)
downloadroseh.moe-ed285a247a3a967e02f428fa2b6e69d629e2bd14.tar.zst
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.
Diffstat (limited to 'internal/cryptoutil')
-rw-r--r--internal/cryptoutil/oae2.go8
1 files changed, 6 insertions, 2 deletions
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