diff options
| author | Rose Hogenson <rosehogenson@posteo.net> | 2025-11-11 06:43:34 -0800 |
|---|---|---|
| committer | Rose Hogenson <rosehogenson@posteo.net> | 2025-11-11 06:43:34 -0800 |
| commit | f57b3ba29eff4e5fcd02fa8923dc17f5eea1efb7 (patch) | |
| tree | 402f2391315858a02fb69ad8b5d90dd897b7ae50 | |
| parent | ef91824ac2f7953daa23eef47765447259d79f23 (diff) | |
| download | sym-f57b3ba29eff4e5fcd02fa8923dc17f5eea1efb7.tar.zst | |
Store the last segment tag inside the nonce
| -rw-r--r-- | oae.go | 15 |
1 files changed, 7 insertions, 8 deletions
@@ -35,10 +35,10 @@ func (se *segmentEncrypter) initialize(salt []byte) error { return err } -func (se *segmentEncrypter) ad(lastSegment bool) []byte { +func (se *segmentEncrypter) nextNonce(lastSegment bool) { // Increment counter for i := 0; ; i++ { - if i == len(se.nonce) { + if i == len(se.nonce)-1 { panic("counter overflowed") } se.nonce[i]++ @@ -47,19 +47,18 @@ func (se *segmentEncrypter) ad(lastSegment bool) []byte { } } if lastSegment { - return []byte{1} + se.nonce[len(se.nonce)-1] = 1 } - return []byte{0} } func (se *segmentEncrypter) encrypt(out, buf []byte, lastSegment bool) []byte { - ad := se.ad(lastSegment) - return se.aead.Seal(out, se.nonce[:], buf, ad) + se.nextNonce(lastSegment) + return se.aead.Seal(out, se.nonce[:], buf, nil) } func (se *segmentEncrypter) decrypt(out, buf []byte, lastSegment bool) ([]byte, error) { - ad := se.ad(lastSegment) - return se.aead.Open(out, se.nonce[:], buf, ad) + se.nextNonce(lastSegment) + return se.aead.Open(out, se.nonce[:], buf, nil) } type encryptingWriter struct { |
