diff --git a/AGENTS.md b/AGENTS.md index 79e4383..4c90905 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -17,7 +17,7 @@ go build -o /tmp/ward ./cmd/ward # build the CLI binary ``` There is no Makefile or CI config; the commands above are the full toolchain. -Go version is pinned to **1.26.4** in `go.mod`. +Go version is pinned to **1.27.1** in `go.mod`. ## Architecture diff --git a/README.md b/README.md index 7b56c0e..37393b4 100644 --- a/README.md +++ b/README.md @@ -88,7 +88,7 @@ ward install ## ⚡ Requirements -- Go >= **1.26** (to build) +- Go >= **1.27** (to build) - `git` on `PATH` (used by the pre-commit hook to stage the store) - Optional: `gpg` with gpg-agent (for the gpg unlock path) - Optional: an ssh key at `~/.ssh/id_ed25519` or `~/.ssh/id_rsa` (for the ssh unlock path) diff --git a/go.mod b/go.mod index f4ee098..5a19601 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/taigrr/gitward -go 1.26.5 +go 1.27.1 require ( filippo.io/age v1.3.1 diff --git a/internal/crypto/crypto.go b/internal/crypto/crypto.go index 771e616..9e86117 100644 --- a/internal/crypto/crypto.go +++ b/internal/crypto/crypto.go @@ -31,6 +31,10 @@ import ( // DEKSize is the data-encryption-key length (AES-256). const DEKSize = 32 +const defaultScryptWorkFactor = 18 + +var scryptWorkFactor = defaultScryptWorkFactor + // NewDEK returns a fresh random data-encryption key. func NewDEK() ([]byte, error) { k := make([]byte, DEKSize) @@ -160,6 +164,7 @@ func WrapDEKPassphrase(dek []byte, passphrase string) (string, error) { if err != nil { return "", err } + r.SetWorkFactor(scryptWorkFactor) var buf bytes.Buffer armorW := armor.NewWriter(&buf) w, err := age.Encrypt(armorW, r) diff --git a/internal/crypto/scrypt_testhook.go b/internal/crypto/scrypt_testhook.go new file mode 100644 index 0000000..0d44b5d --- /dev/null +++ b/internal/crypto/scrypt_testhook.go @@ -0,0 +1,12 @@ +package crypto + +// SetScryptWorkFactorForTesting lowers the passphrase KDF cost in tests that +// create many throwaway stores. It returns a restore function for callers that +// need to preserve the previous setting. +func SetScryptWorkFactorForTesting(logN int) func() { + old := scryptWorkFactor + scryptWorkFactor = logN + return func() { + scryptWorkFactor = old + } +} diff --git a/internal/engine/engine_test.go b/internal/engine/engine_test.go index dc9da71..e426fa3 100644 --- a/internal/engine/engine_test.go +++ b/internal/engine/engine_test.go @@ -16,6 +16,13 @@ import ( const pass = "test-passphrase-123" +func TestMain(m *testing.M) { + restore := crypto.SetScryptWorkFactorForTesting(4) + code := m.Run() + restore() + os.Exit(code) +} + // newRepo creates a throwaway git repo (via go-git, no git binary) and returns // its root. func newRepo(t *testing.T) (string, *git.Repository) {