Open nstilt1 opened 10 months ago
struct ChaCha20Rng(BlockRng<ChaCha20Core>);
impl ChaCha20Rng {
fn set_block_pos(x: _) {
self.0.core.set_block_pos(x);
self.0.reset(); // or generate_and_set(index)
}
}
This should be enough for a == b
. I don't think we need any impls directly on BlockRng
.
Definitely an important feature for verification. For example, when one needs to replay an RNG.
Related: #1458.
Background
1369 has brought up a use for
set_block_pos()
andget_block_pos()
forrand_chacha
.In implementing it for
chacha20
withBlockRng
, there is a minor issue with the API without using a new trait. The methods seem like they should belong on thecore
instead of therng
, but when implementing just those 2 methods, it results in these calls:This could be simplified by adding a
ChaCha20Rng::get_core_mut()
method, down to:But now there are even more characters to type.
There is also a potential issue regarding
set_block_pos()
located on thecore
. The following code will fail because changing theblock_pos
on thecore
will not affect theindex
of therng
. So we will need to decide if that is okay or not:A
SeekableRng
trait might suffice, allowing for a shorter method call, and it could also handle the above issue depending on if that is an issue that needs to be fixed.Feature request
I don't know if it would be possible to make a simplified call such as this:
But it seems like for that method to be called that way,
SeekableRng
would need to be implemented forBlockRng
if the rng is a wrapper around it. The method does not need to be called that way though. I personally don't mind whether it is on the rng or the core, but it just seems like something that would go on the core.Proposed trait definition: