Skip to content

Commit

Permalink
Raise Argon2id iterations.
Browse files Browse the repository at this point in the history
  • Loading branch information
ncruces committed May 3, 2024
1 parent 1e03c6c commit 19209b3
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 5 deletions.
2 changes: 1 addition & 1 deletion vfs/adiantum/adiantum.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ func (adiantumCreator) KDF(text string) []byte {
n, _ := rand.Read(key)
return key[:n]
}
return argon2.IDKey([]byte(text), []byte(pepper), 1, 64*1024, 4, 32)
return argon2.IDKey([]byte(text), []byte(pepper), 3, 64*1024, 4, 32)
}
53 changes: 53 additions & 0 deletions vfs/adiantum/adiantum_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package adiantum_test

import (
"path/filepath"
"testing"

"github.com/ncruces/go-sqlite3"
_ "github.com/ncruces/go-sqlite3/embed"
_ "github.com/ncruces/go-sqlite3/vfs/adiantum"
)

func Benchmark_nokey(b *testing.B) {
tmp := filepath.Join(b.TempDir(), "test.db")
sqlite3.Initialize()
b.ResetTimer()

for n := 0; n < b.N; n++ {
db, err := sqlite3.Open("file:" + filepath.ToSlash(tmp) + "?nolock=1")
if err != nil {
b.Fatal(err)
}
db.Close()
}
}
func Benchmark_hexkey(b *testing.B) {
tmp := filepath.Join(b.TempDir(), "test.db")
sqlite3.Initialize()
b.ResetTimer()

for n := 0; n < b.N; n++ {
db, err := sqlite3.Open("file:" + filepath.ToSlash(tmp) + "?nolock=1" +
"&vfs=adiantum&hexkey=e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855")
if err != nil {
b.Fatal(err)
}
db.Close()
}
}

func Benchmark_textkey(b *testing.B) {
tmp := filepath.Join(b.TempDir(), "test.db")
sqlite3.Initialize()
b.ResetTimer()

for n := 0; n < b.N; n++ {
db, err := sqlite3.Open("file:" + filepath.ToSlash(tmp) + "?nolock=1" +
"&vfs=adiantum&textkey=correct+horse+battery+staple")
if err != nil {
b.Fatal(err)
}
db.Close()
}
}
8 changes: 7 additions & 1 deletion vfs/adiantum/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,18 @@
// However, this makes your key easily accessible to other parts of
// your application (e.g. through [vfs.Filename.URIParameters]).
//
// To avoid this, use any of the following PRAGMAs:
// To avoid this, invoke any of the following PRAGMAs
// immediately after opening a connection:
//
// PRAGMA key='D41d8cD98f00b204e9800998eCf8427e';
// PRAGMA hexkey='e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855';
// PRAGMA textkey='your-secret-key';
//
// For an ATTACH-ed database, you must specify the schema name:
//
// ATTACH DATABASE 'demo.db' AS demo;
// PRAGMA demo.textkey='your-secret-key';
//
// [URI]: https://sqlite.org/uri.html
package adiantum

Expand Down
6 changes: 3 additions & 3 deletions vfs/adiantum/hbsh.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ func (h *hbshVFS) Open(name string, flags vfs.OpenFlag) (vfs.File, vfs.OpenFlag,
}

func (h *hbshVFS) OpenFilename(name *vfs.Filename, flags vfs.OpenFlag) (file vfs.File, _ vfs.OpenFlag, err error) {
if h, ok := h.VFS.(vfs.VFSFilename); ok {
file, flags, err = h.OpenFilename(name, flags)
if hf, ok := h.VFS.(vfs.VFSFilename); ok {
file, flags, err = hf.OpenFilename(name, flags)
} else {
file, flags, err = h.Open(name.String(), flags)
file, flags, err = h.VFS.Open(name.String(), flags)
}

// Encrypt everything except super journals and memory files.
Expand Down

0 comments on commit 19209b3

Please sign in to comment.