Skip to content

Conversation

@jacksonwalters
Copy link
Member

this creates a function which sets the DRBG seed and creates a DrbgCtx object as an optional instance parameter. This can be used to generate DRBG random bytes. The default is to use getrandom system randomness if no seed is set. We add a unit test to check this. We add this function currently as a parameter to params. It could probably be moved to a utils function.

It doesn't seem possible to set a default function, but then also set that same variable to be a function which depends on this DrbgCtx element since it is an instantiated variable depending on seed. There may be a way, but I don't see it.

for now, we initialize the aes_drbg with an instance function, and store the drbg as an `Option<DrbgCtx>` in the struct. we create a function `gen_random_bytes` which takes an `Option<DrbgCtx>`. if present, it uses the DRBG to generate randomness. If absent, it uses `getrandom`, which is the lowest level system crate to generate randomness.

this is a bit of a compromise, because ideally one would just set a single function which either is system randomness or is the DRBG, once it's been set. since Rust is finnicky about memory management, and having a function which depends on the current state of an object is difficult, we avoid this for now.
@jacksonwalters jacksonwalters self-assigned this Mar 27, 2025
@jacksonwalters jacksonwalters merged commit bc32377 into main Mar 27, 2025
1 check passed
@jacksonwalters jacksonwalters deleted the add_set_drbg_seed_method branch March 27, 2025 21:39
@jacksonwalters jacksonwalters linked an issue Mar 28, 2025 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

use appropriate entropy sources

2 participants