Skip to content

Commit 19209b3

Browse files
committed
Raise Argon2id iterations.
1 parent 1e03c6c commit 19209b3

File tree

4 files changed

+64
-5
lines changed

4 files changed

+64
-5
lines changed

vfs/adiantum/adiantum.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ func (adiantumCreator) KDF(text string) []byte {
2828
n, _ := rand.Read(key)
2929
return key[:n]
3030
}
31-
return argon2.IDKey([]byte(text), []byte(pepper), 1, 64*1024, 4, 32)
31+
return argon2.IDKey([]byte(text), []byte(pepper), 3, 64*1024, 4, 32)
3232
}

vfs/adiantum/adiantum_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package adiantum_test
2+
3+
import (
4+
"path/filepath"
5+
"testing"
6+
7+
"github.com/ncruces/go-sqlite3"
8+
_ "github.com/ncruces/go-sqlite3/embed"
9+
_ "github.com/ncruces/go-sqlite3/vfs/adiantum"
10+
)
11+
12+
func Benchmark_nokey(b *testing.B) {
13+
tmp := filepath.Join(b.TempDir(), "test.db")
14+
sqlite3.Initialize()
15+
b.ResetTimer()
16+
17+
for n := 0; n < b.N; n++ {
18+
db, err := sqlite3.Open("file:" + filepath.ToSlash(tmp) + "?nolock=1")
19+
if err != nil {
20+
b.Fatal(err)
21+
}
22+
db.Close()
23+
}
24+
}
25+
func Benchmark_hexkey(b *testing.B) {
26+
tmp := filepath.Join(b.TempDir(), "test.db")
27+
sqlite3.Initialize()
28+
b.ResetTimer()
29+
30+
for n := 0; n < b.N; n++ {
31+
db, err := sqlite3.Open("file:" + filepath.ToSlash(tmp) + "?nolock=1" +
32+
"&vfs=adiantum&hexkey=e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855")
33+
if err != nil {
34+
b.Fatal(err)
35+
}
36+
db.Close()
37+
}
38+
}
39+
40+
func Benchmark_textkey(b *testing.B) {
41+
tmp := filepath.Join(b.TempDir(), "test.db")
42+
sqlite3.Initialize()
43+
b.ResetTimer()
44+
45+
for n := 0; n < b.N; n++ {
46+
db, err := sqlite3.Open("file:" + filepath.ToSlash(tmp) + "?nolock=1" +
47+
"&vfs=adiantum&textkey=correct+horse+battery+staple")
48+
if err != nil {
49+
b.Fatal(err)
50+
}
51+
db.Close()
52+
}
53+
}

vfs/adiantum/api.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,18 @@
1818
// However, this makes your key easily accessible to other parts of
1919
// your application (e.g. through [vfs.Filename.URIParameters]).
2020
//
21-
// To avoid this, use any of the following PRAGMAs:
21+
// To avoid this, invoke any of the following PRAGMAs
22+
// immediately after opening a connection:
2223
//
2324
// PRAGMA key='D41d8cD98f00b204e9800998eCf8427e';
2425
// PRAGMA hexkey='e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855';
2526
// PRAGMA textkey='your-secret-key';
2627
//
28+
// For an ATTACH-ed database, you must specify the schema name:
29+
//
30+
// ATTACH DATABASE 'demo.db' AS demo;
31+
// PRAGMA demo.textkey='your-secret-key';
32+
//
2733
// [URI]: https://sqlite.org/uri.html
2834
package adiantum
2935

vfs/adiantum/hbsh.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ func (h *hbshVFS) Open(name string, flags vfs.OpenFlag) (vfs.File, vfs.OpenFlag,
2121
}
2222

2323
func (h *hbshVFS) OpenFilename(name *vfs.Filename, flags vfs.OpenFlag) (file vfs.File, _ vfs.OpenFlag, err error) {
24-
if h, ok := h.VFS.(vfs.VFSFilename); ok {
25-
file, flags, err = h.OpenFilename(name, flags)
24+
if hf, ok := h.VFS.(vfs.VFSFilename); ok {
25+
file, flags, err = hf.OpenFilename(name, flags)
2626
} else {
27-
file, flags, err = h.Open(name.String(), flags)
27+
file, flags, err = h.VFS.Open(name.String(), flags)
2828
}
2929

3030
// Encrypt everything except super journals and memory files.

0 commit comments

Comments
 (0)