package granary

  1. Overview
  2. Docs
Pure-OCaml SQL engine

Install

dune-project
 Dependency

Authors

Maintainers

Sources

0.0.3.tar.gz
sha256=8b18780ea373be48301d9f333925860a2f9110fc0ac28684295118d72b65a67e
sha512=25ca3c9c5e2b528704a542502e0f37dc33ba003f65622d969b8c2b800778585f8ef0cf89b36e6679832e3993e8303aecddfc662742baf7044d6afe4a796b8f11

doc/granary.storage/Granary_storage/Crypto/index.html

Module Granary_storage.CryptoSource

Per-page AES-256-GCM codec for at-rest encryption (#84).

Pure: no I/O. The application supplies a 32-byte raw key; nonces are freshly generated per call via Mirage_crypto_rng (the application must seed the RNG at boot — lib/ never seeds, to stay Mirage-clean).

On-disk encrypted page layout (length n = page_size):

 [ ciphertext : n - overhead ] [ nonce : nonce_len ] [ tag : tag_len ] 

The encrypted region is the logical page minus the reserved tail; the B+-tree already keeps its data within that region.

Sourcetype t
Sourceval pp : Format.formatter -> t -> unit

Pretty-printer for t (redacts key material).

Sourceval nonce_len : int

16

Sourceval tag_len : int

16

Sourceval overhead : int

32 — reserved bytes an encrypted page must carve off its tail

Sourceval create : key:string -> (t, [ `Bad_key_length ]) result

Build a cipher from raw key material. Error `Bad_key_length unless the key is exactly 32 bytes (AES-256).

Sourceval encrypt_page : t -> page_id:int64 -> Cstruct.t -> unit

Encrypt the page in place: encrypts bytes 0 .. len-overhead), then writes the freshly-generated nonce and the auth tag into the reserved tail. AAD is the [page_id], binding the ciphertext to its slot. [buf] length must be > [overhead].

Sourceval decrypt_frame_count : unit -> int

Total WAL-frame decrypt invocations since process start. Observability hook used by tests to assert the #246 decrypted-frame cache serves repeated reads with zero extra decrypts and that authentication still runs on every fresh WAL fill. Monotonic; never reset.

Sourceval decrypt_page : t -> page_id:int64 -> Cstruct.t -> (unit, [ `Tag_mismatch ]) result

Decrypt the page in place: verifies the tag over 0 .. len-overhead) using the tail nonce and [page_id] AAD, writes plaintext back, and zeroes the reserved tail (so the page's pre-seal CRC over a zeroed tail still verifies). [Error `Tag_mismatch] on a wrong key or tampering.

Sourceval encrypt_frame : t -> page_id:int64 -> plaintext:Cstruct.t -> Cstruct.t

Encrypt a WAL frame payload. Returns a fresh buffer of length Cstruct.length plaintext + overhead: ciphertext nonce tag .

Sourceval decrypt_frame : t -> page_id:int64 -> Cstruct.t -> (Cstruct.t, [ `Tag_mismatch ]) result

Decrypt a WAL frame payload produced by encrypt_frame. payload length must be plaintext_len + overhead; returns the plaintext_len plaintext or Error `Tag_mismatch.

Sourceval canary_adata : string

Fixed associated data for the key-check canary.

Sourceval make_canary : t -> nonce:string -> string

make_canary t ~nonce returns the tag_len-byte GCM tag over an empty message with canary_adata, under t's key and nonce.

Sourceval check_canary : t -> nonce:string -> tag:string -> bool

check_canary t ~nonce ~tag recomputes the canary and reports whether it matches tag (i.e. the key is correct).