Files
hanzo-dev fbc1bcce40 feat: pure-Go SQLCipher 4 page format
Port of the SQLCipher codec (sqlcipher/sqlcipher v4.5.6, BSD-3, ZETETIC LLC)
in pure Go, with no third-party dependencies.

The format, and only the format: key derivation, per-page AES-256-CBC,
per-page HMAC-SHA512 over ciphertext||IV||pgno_le32, and page-1 salt
handling. It knows nothing about database/sql or SQLite drivers, so a
driver, a backup path, a migration or a forensic tool can all use it
without dragging in an engine.

Constants taken from the C source and confirmed against libsqlcipher 4.5.6:
kdf_iter 256000, fast_kdf_iter 2, hmac salt mask 0x3a, salt 16 bytes,
key 32, iv 16, hmac 64, reserve 80, LE page numbers.

Decrypt authenticates before it decrypts: a wrong key returns ErrKey, never
garbage.
2026-07-16 12:26:23 -07:00

36 lines
1.6 KiB
Plaintext

Hanzo SQLCipher
Copyright (c) 2026 Hanzo AI, Inc.
Ported from https://github.com/sqlcipher/sqlcipher at v4.5.6.
This product is a pure-Go port of the SQLCipher page codec: the key derivation,
the per-page AES-256-CBC encryption, the per-page HMAC-SHA512 authentication,
and the page-1 salt handling. It implements SQLCipher 4's on-disk format and is
byte-compatible with it in both directions — it reads databases the C library
wrote, and the C library reads databases it writes.
It is a port, not a clean-room reimplementation: the format was taken from the
SQLCipher source, function by function, and verified against it byte for byte.
The Go expression of it is Hanzo's; the design and the format are Zetetic's.
This product includes software from SQLCipher (https://github.com/sqlcipher/sqlcipher),
licensed under BSD-3-Clause:
Copyright (c) 2008-2023, ZETETIC LLC
All rights reserved.
The full BSD-3-Clause notice, conditions and disclaimer are retained verbatim in
the LICENSE file of this repository, as that license requires. Hanzo's copyright
covers only Hanzo's own expression; ZETETIC LLC retains its rights in the work
this was derived from.
SQLCipher is a trademark of ZETETIC LLC. This product is not affiliated with,
endorsed by, or sponsored by ZETETIC LLC. The name is used to identify the file
format this product interoperates with.
DEPENDENCIES
This module has no third-party dependencies. Every cryptographic primitive comes
from the Go standard library: crypto/aes, crypto/cipher, crypto/hmac,
crypto/sha512, crypto/pbkdf2, crypto/rand and crypto/subtle.