Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type PageCipher ¶
type PageCipher struct {
// contains filtered or unexported fields
}
PageCipher encrypts and decrypts individual database pages using AES-256-CTR. Each page has its own independent keystream derived from its page index, so pages can be encrypted or decrypted independently and in any order.
The key is derived from the caller-supplied key material and a per-database salt using HKDF (RFC 5869) with HMAC-SHA256, so the raw user key is never used directly for AES.
func NewPageCipher ¶
func NewPageCipher(userKey, salt []byte) (*PageCipher, error)
NewPageCipher derives a 256-bit AES key from userKey and salt using HKDF-Extract + HKDF-Expand (RFC 5869, HMAC-SHA256) and returns a PageCipher ready for use.
func (*PageCipher) XORKeyStream ¶
func (c *PageCipher) XORKeyStream(buf []byte, pageIdx uint32)
XORKeyStream encrypts or decrypts buf in-place using AES-256-CTR. The nonce is deterministic: 8 zero bytes followed by the 8-byte big-endian encoding of pageIdx. Since each page has a unique index the keystream is unique per page, which is acceptable for a data-at-rest threat model where the on-disk content is fixed for a given (key, pageIdx) pair.
For page 0, callers must pass pageIdx=0 but only supply the sub-slice that excludes the plaintext database header (bytes 0-99 of page 0 are never encrypted so the salt can be bootstrapped on open).