pub struct RandCtx { /* private fields */ }Expand description
A seeded DRBG context (EVP_RAND_CTX*).
Has up_ref so Clone is implemented; wrapping in Arc<RandCtx> is safe.
Implementations§
Source§impl RandCtx
impl RandCtx
Sourcepub fn new(alg: &RandAlg, parent: Option<&RandCtx>) -> Result<Self, ErrorStack>
pub fn new(alg: &RandAlg, parent: Option<&RandCtx>) -> Result<Self, ErrorStack>
Create a new uninstantiated DRBG context from an algorithm descriptor.
Provide parent = None to seed from the global PRNG.
§Errors
Sourcepub fn instantiate(
&mut self,
strength: u32,
prediction_resistance: bool,
params: Option<&Params<'_>>,
) -> Result<(), ErrorStack>
pub fn instantiate( &mut self, strength: u32, prediction_resistance: bool, params: Option<&Params<'_>>, ) -> Result<(), ErrorStack>
Instantiate (seed) the DRBG at the requested security strength.
Must be called before generate if the context was not auto-seeded.
When parent = None was used in new, pass strength ≤ 128 to stay
within the system seed-source’s entropy ceiling.
§Errors
Sourcepub fn generate(
&mut self,
out: &mut [u8],
req: &GenerateRequest<'_>,
) -> Result<(), ErrorStack>
pub fn generate( &mut self, out: &mut [u8], req: &GenerateRequest<'_>, ) -> Result<(), ErrorStack>
Sourcepub fn fill(&mut self, out: &mut [u8]) -> Result<(), ErrorStack>
pub fn fill(&mut self, out: &mut [u8]) -> Result<(), ErrorStack>
Generate random bytes with default parameters (strength=256, no prediction resistance, no additional input).
Equivalent to calling generate with GenerateRequest::default.
Call Self::instantiate before the first fill.
§Errors
Sourcepub fn state(&self) -> RandState
pub fn state(&self) -> RandState
Current lifecycle state of this DRBG context.
Returns RandState::Ready after a successful Self::instantiate.