aboutsummaryrefslogtreecommitdiffstats
path: root/oae.go
diff options
context:
space:
mode:
authorRose Hogenson <rosehogenson@posteo.net>2025-11-11 11:43:11 -0800
committerRose Hogenson <rosehogenson@posteo.net>2025-11-11 11:43:11 -0800
commit3b1839e979b843ed5c305970d3e5c61816f06a31 (patch)
treed1c8fc7aae799e5d2643fd37b2a9be75f5fb7f11 /oae.go
parentbd8bb1246cdad558fca64fdcf6af343905746e29 (diff)
downloadsym-3b1839e979b843ed5c305970d3e5c61816f06a31.tar.zst
Add some comments and fix gofmtHEADmain
Diffstat (limited to 'oae.go')
-rw-r--r--oae.go13
1 files changed, 12 insertions, 1 deletions
diff --git a/oae.go b/oae.go
index 0389a91..ca2bcf0 100644
--- a/oae.go
+++ b/oae.go
@@ -1,5 +1,16 @@
package main
+// This file is based on the influential paper
+// [Online Authenticated-Encryption and its Nonce-Reuse Misuse-Resistance].
+// It encrypts a stream of data in 1MiB segments using ChaCha20-Poly1305
+// to encrypt each segment. The nonce is a 12 byte value, the first 11
+// bytes of which are a counter that gets incremented for each segment,
+// and the last byte is 0 for every segment except the last segment
+// (where it is 1). Before the encrypted segments, it writes a 32 byte
+// header containing the salt for the password hash.
+//
+// [Online Authenticated-Encryption and its Nonce-Reuse Misuse-Resistance]: https://eprint.iacr.org/2015/189.pdf
+
import (
"bufio"
"bytes"
@@ -39,7 +50,7 @@ func (se *segmentEncrypter) nextNonce(lastSegment bool) {
// Increment counter
for i := 0; ; i++ {
if i == len(se.nonce)-1 {
- panic("counter overflowed")
+ panic("counter overflowed") // impossible, 11 bytes
}
se.nonce[i]++
if se.nonce[i] != 0 {