Skip to content

Commit 431b39f

Browse files
committed
Documentation.
1 parent 2c30bc9 commit 431b39f

File tree

3 files changed

+28
-15
lines changed

3 files changed

+28
-15
lines changed

vfs/adiantum/README.md

+14-5
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,23 @@ In general, any HBSH construction can be used to wrap any VFS.
1616

1717
The default Adiantum construction uses XChaCha12 for its stream cipher,
1818
AES for its block cipher, and NH and Poly1305 for hashing.
19-
It uses Argon2id to derive 256-bit keys from plain text.
19+
Additionally, we use Argon2id to derive 256-bit keys from plain text.
2020

21-
The VFS encrypts database files, rollback and statement journals, and WAL files.
21+
The VFS encrypts all files _except_
22+
[super journals](https://sqlite.org/tempfiles.html#super_journal_files):
23+
super journals _never_ contain database data, only filenames,
24+
and padding them to the block size is problematic.
25+
26+
Temporary files _are_ encrypted, as they _will_ contain database data.
27+
To avoid the overhead of encrypting temporary files,
28+
keep them in memory:
29+
30+
PRAGMA temp_store = memory;
2231

2332
> [!IMPORTANT]
2433
> Adiantum is typically used for disk encryption.
2534
> The standard threat model for disk encryption considers an adversary
2635
> that can read multiple snapshots of a disk.
27-
> The security property that disk encryption provides is that
28-
> the only information such an adversary can determine is
29-
> whether the data in a sector has or has not changed over time.
36+
> The only security property that disk encryption (and this package)
37+
> provides is that the only information such an adversary can determine
38+
> is whether the data in a sector has or has not changed over time.

vfs/adiantum/hbsh.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,8 @@ func (h *hbshVFS) Open(name string, flags vfs.OpenFlag) (vfs.File, vfs.OpenFlag,
2222
}
2323

2424
func (h *hbshVFS) OpenParams(name string, flags vfs.OpenFlag, params url.Values) (file vfs.File, _ vfs.OpenFlag, err error) {
25-
encrypt := flags&(0|
26-
vfs.OPEN_MAIN_DB|
27-
vfs.OPEN_MAIN_JOURNAL|
28-
vfs.OPEN_SUBJOURNAL|
29-
vfs.OPEN_WAL) != 0
25+
// Encrypt everything except super journals.
26+
encrypt := flags&vfs.OPEN_SUPER_JOURNAL == 0
3027

3128
var hbsh *hbsh.HBSH
3229
if encrypt {

vfs/memdb/memdb.go

+12-5
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,22 @@ import (
1111
"github.com/ncruces/go-sqlite3/vfs"
1212
)
1313

14+
// Must be a multiple of 64K (the largest page size).
15+
const sectorSize = 65536
16+
1417
type memVFS struct{}
1518

1619
func (memVFS) Open(name string, flags vfs.OpenFlag) (vfs.File, vfs.OpenFlag, error) {
17-
// Allowed file types:
20+
// For simplicity, we do not support reading or writing data
21+
// across "sector" boundaries.
22+
//
23+
// This is not a problem for most SQLite file types:
1824
// - databases, which only do page aligned reads/writes;
19-
// - temp journals, used by the sorter, which does the same.
25+
// - temp journals, as used by the sorter, which does the same:
26+
// https://sqlite.org/src/artifact/237840?ln=409-412
27+
//
28+
// We refuse to open all other file types,
29+
// but returning OPEN_MEMORY means SQLite won't ask us to.
2030
const types = vfs.OPEN_MAIN_DB |
2131
vfs.OPEN_TRANSIENT_DB |
2232
vfs.OPEN_TEMP_DB |
@@ -61,9 +71,6 @@ func (memVFS) FullPathname(name string) (string, error) {
6171
return name, nil
6272
}
6373

64-
// Must be a multiple of 64K (the largest page size).
65-
const sectorSize = 65536
66-
6774
type memDB struct {
6875
// +checklocks:lockMtx
6976
pending *memFile

0 commit comments

Comments
 (0)