Skip to main content

Kek

Struct Kek 

Source
pub struct Kek(/* private fields */);
Expand description

Table-level Key-Encryption Key. Derived from a passphrase + salt via Argon2id (the extract step, memory-hard) followed by HKDF-SHA256 expand (domain separation). Never persisted; reconstructable only from the passphrase plus the stored salt.

Implementations§

Source§

impl Kek

Source

pub fn derive(passphrase: &str, salt: &[u8; 16]) -> Result<Self>

Derive a 256-bit KEK from passphrase and salt via Argon2id + HKDF-SHA256.

Source

pub fn from_raw_key(raw: &[u8], salt: &[u8; 16]) -> Result<Self>

Derive a 256-bit KEK from a raw key (e.g. a key file’s contents) via HKDF-SHA256 only — no Argon2id. The raw key must be >= 32 bytes and already high-entropy (machine-generated). ~0.1ms vs ~50ms for the passphrase path.

Source

pub fn derive_wal_key(&self) -> Zeroizing<[u8; 32]>

Derive a WAL DEK from this KEK for frame-level AEAD.

Source

pub fn derive_shared_wal_key(&self) -> Zeroizing<[u8; 32]>

Derive the shared (multi-table) WAL DEK — domain-separated from the per-table WAL so the two logs never share key+nonce space under the same KEK (review fix from P2 peer review).

Source

pub fn derive_table_wal_key(&self, table_id: u64) -> Zeroizing<[u8; 32]>

Derive a per-table WAL DEK unique to table_id, so no two tables share the same DEK even under the same KEK.

Source

pub fn derive_cache_key(&self) -> Zeroizing<[u8; 32]>

Derive a result-cache DEK from this KEK for cache file AEAD.

Source

pub fn derive_idx_key(&self) -> Zeroizing<[u8; 32]>

Derive the index-checkpoint DEK from this KEK (_idx/global.idx).

Source

pub fn derive_run_mac_key(&self) -> Zeroizing<[u8; 32]>

Derive the run-metadata MAC key from this KEK (see run_metadata_mac).

Source

pub fn derive_meta_key(&self) -> Zeroizing<[u8; 32]>

Derive the meta DEK used to encrypt + authenticate DB-wide metadata (catalog, manifest checkpoints). Mirrors Self::derive_idx_key.

Source

pub fn wrap_dek(&self, dek: &[u8; 32], wrap_nonce: &[u8; 12]) -> Result<Vec<u8>>

Wrap a 32-byte DEK with the KEK using AES-256-GCM. wrap_nonce must be unique per use under this KEK (a run’s random nonce_prefix satisfies this).

Source

pub fn unwrap_dek( &self, wrapped: &[u8], wrap_nonce: &[u8; 12], ) -> Result<Zeroizing<[u8; 32]>>

Unwrap a DEK previously produced by Self::wrap_dek.

Source§

impl Kek

Source

pub fn derive_subkey(&self, info: &[u8]) -> Zeroizing<[u8; 32]>

Derive a 256-bit sub-key from this KEK via HKDF-Expand, domain- separated by info. Used for per-column indexable-encryption keys: deriving deterministically from the (stable) KEK makes a column’s tokens identical across runs, so cross-run indexes (bitmap / range) unify them.

Source

pub fn derive_column_key(&self, column_id: u16) -> Zeroizing<[u8; 32]>

Derive the per-column indexable-encryption key.

Source

pub fn wrap_column_key( &self, col_key: &[u8; 32], wrap_nonce: &[u8; 12], ) -> Result<Vec<u8>>

Wrap a column key (for the §7 descriptor). Reuses the run nonce prefix.

Trait Implementations§

Source§

impl Debug for Kek

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Kek

§

impl RefUnwindSafe for Kek

§

impl Send for Kek

§

impl Sync for Kek

§

impl Unpin for Kek

§

impl UnsafeUnpin for Kek

§

impl UnwindSafe for Kek

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.