aboutsummaryrefslogtreecommitdiffstats
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
parentbd8bb1246cdad558fca64fdcf6af343905746e29 (diff)
downloadsym-main.tar.zst
Add some comments and fix gofmtHEADmain
-rw-r--r--dec_test.go4
-rw-r--r--enc.go2
-rw-r--r--enc_test.go6
-rw-r--r--oae.go13
-rw-r--r--sym_test.go22
5 files changed, 29 insertions, 18 deletions
diff --git a/dec_test.go b/dec_test.go
index b06c722..ea73cd0 100644
--- a/dec_test.go
+++ b/dec_test.go
@@ -169,8 +169,8 @@ func TestDecCmd_Run_Stdin(t *testing.T) {
gotContentBuf := new(bytes.Buffer)
if err := (&decCmd{
password: password,
- stdin: bytes.NewReader(encrypted.Bytes()),
- stdout: gotContentBuf,
+ stdin: bytes.NewReader(encrypted.Bytes()),
+ stdout: gotContentBuf,
}).run(); err != nil {
t.Fatalf("run failed: %s", err)
}
diff --git a/enc.go b/enc.go
index 898fc10..f50665d 100644
--- a/enc.go
+++ b/enc.go
@@ -26,7 +26,7 @@ type encCmd struct {
stdout io.Writer
}
-func (*encCmd) Name() string { return "enc" }
+func (*encCmd) Name() string { return "enc" }
func (*encCmd) Synopsis() string { return "encrypt" }
func (*encCmd) Usage() string {
return `usage: sym enc [OPTION]... [FILE]...
diff --git a/enc_test.go b/enc_test.go
index c800652..5dea92d 100644
--- a/enc_test.go
+++ b/enc_test.go
@@ -125,7 +125,7 @@ func TestEncCmd_Run_GeneratePassword(t *testing.T) {
password := new(strings.Builder)
opts := &encCmd{
generatePassword: true,
- passwordOut: password,
+ passwordOut: password,
}
if err := opts.run(fileName); err != nil {
t.Fatalf("encCmd.run(%+v) failed: %s", opts, err)
@@ -151,8 +151,8 @@ func TestEncCmd_Run_Stdin(t *testing.T) {
stdout := new(strings.Builder)
if err := (&encCmd{
password: password,
- stdin: strings.NewReader(input),
- stdout: stdout,
+ stdin: strings.NewReader(input),
+ stdout: stdout,
}).run(); err != nil {
t.Errorf("encCmd.run failed: %s", err)
}
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 {
diff --git a/sym_test.go b/sym_test.go
index 8ae82cc..69bc26a 100644
--- a/sym_test.go
+++ b/sym_test.go
@@ -113,24 +113,24 @@ func TestCommander_Errors(t *testing.T) {
t.Parallel()
for _, tc := range []struct {
- desc string
- cmd []string
+ desc string
+ cmd []string
wantStatus subcommands.ExitStatus
- } {{
- desc: "EncUsageError",
- cmd: []string{"enc", "-g", "-p=asdf", "file.txt"},
+ }{{
+ desc: "EncUsageError",
+ cmd: []string{"enc", "-g", "-p=asdf", "file.txt"},
wantStatus: subcommands.ExitUsageError,
}, {
- desc: "EncNoSuchFile",
- cmd: []string{"enc", "-p=asdf", "nonexistent-file.txt"},
+ desc: "EncNoSuchFile",
+ cmd: []string{"enc", "-p=asdf", "nonexistent-file.txt"},
wantStatus: subcommands.ExitFailure,
}, {
- desc: "DecUsageError",
- cmd: []string{"dec"},
+ desc: "DecUsageError",
+ cmd: []string{"dec"},
wantStatus: subcommands.ExitUsageError,
}, {
- desc: "DecNoSuchFile",
- cmd: []string{"dec", "-p=asdf", "nonexistent-file.txt.enc"},
+ desc: "DecNoSuchFile",
+ cmd: []string{"dec", "-p=asdf", "nonexistent-file.txt.enc"},
wantStatus: subcommands.ExitFailure,
}} {
t.Run(tc.desc, func(t *testing.T) {