confium_api/plugin/kdf.rs
1//! `KdfPlugin` trait — the Rust-side counterpart of the KDF v0 wire
2//! protocol.
3//!
4//! Plugin authors implement this trait on their KDF state type, then
5//! apply `#[plugin_interface(name = "kdf", version = 0)]` to the impl
6//! block.
7//!
8//! Method → symbol mapping (see `crates/confium-core/src/ffi/kdf.rs`
9//! for the loader-side wire types):
10//!
11//! | trait method | FFI symbol | purpose |
12//! |--------------|------------|---------|
13//! | [`KdfPlugin::create`] | `cfmp_kdf_create` | construct a new instance |
14//! | [`KdfPlugin::set_salt`] | `cfmp_kdf_set_salt` | set the salt |
15//! | [`KdfPlugin::set_iterations`] | `cfmp_kdf_set_iterations` | set iteration count |
16//! | [`KdfPlugin::set_memory_cost`] | `cfmp_kdf_set_memory_cost` | set memory cost |
17//! | [`KdfPlugin::set_parallelism`] | `cfmp_kdf_set_parallelism` | set parallelism |
18//! | [`KdfPlugin::set_hash`] | `cfmp_kdf_set_hash` | set hash algorithm |
19//! | [`KdfPlugin::derive`] | `cfmp_kdf_derive` | derive key material |
20//! | `Drop` | `cfmp_kdf_destroy` | reclaim the boxed state |
21
22use crate::error::PluginResult;
23use crate::options::OptionView;
24
25/// Trait implemented by KDF plugins.
26pub trait KdfPlugin: Sized {
27 /// Construct a new KDF instance for the named algorithm.
28 fn create(algorithm: &str, opts: Option<OptionView<'_>>) -> PluginResult<Self>;
29
30 /// Set the salt.
31 fn set_salt(&mut self, salt: &[u8]) -> PluginResult<()>;
32
33 /// Set the iteration count.
34 fn set_iterations(&mut self, iterations: u32) -> PluginResult<()>;
35
36 /// Set the memory cost in bytes.
37 fn set_memory_cost(&mut self, bytes: u64) -> PluginResult<()>;
38
39 /// Set the parallelism (number of lanes).
40 fn set_parallelism(&mut self, lanes: u32) -> PluginResult<()>;
41
42 /// Set the hash algorithm name.
43 fn set_hash(&mut self, hash_name: &str) -> PluginResult<()>;
44
45 /// Derive `out.len()` bytes of key material from `input`.
46 fn derive(&mut self, input: &[u8], out: &mut [u8]) -> PluginResult<()>;
47}