-
-
Notifications
You must be signed in to change notification settings - Fork 463
Full specification of PRNGs / (un)aligned reads #655
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I think that sounds fine for say Isaac where output is specified in words, but I think ChaCha's output is specified as byte aligned and little endian, even though the internals are word aligned. A priori I'd think I do however also see advantage in using some standard Are alignment issues actually impacting performance? If so, then maybe |
It could even look vaguely like:
Afaik, you need a macro instead of I hope I'm not making any messes or causing too many distractions! :) |
But our ChaCha is called
I haven't done proper testing, and I think it would be arch-specific. There is bound to be at least a little overhead in the case that a new block must be generated in the middle of a word read.
But read alignment isn't a property of the core, it's a property of the wrapper. The core just generates a whole block at a time. In fact, we might be able to drop the |
It appears Another question: Is it actually hard to write a specification for code using Also, if the Also, there are PRNGs that allocate
except this leaves
|
No, actually it does: pub struct ChaChaRng(BlockRng<ChaChaCore>); We don't use a type-def because we want inherent methods and don't use a derive macro because at the time pitdicker wasn't a fan of macros (though I wrote one). What's wrong with the current impl BlockRngCore for ChaChaCore {
type Item = u32;
type Results = [u32; STATE_WORDS]; // STATE_WORDS = 16
fn generate(&mut self, results: &mut Self::Results) { |
I don't have much interest in adding an unaligned version of block RNGs; we'd have significant complications of code in With the current block RNG code:
This is all documented, so I think we can just close this issue since the original point was mostly about specification. |
@burdges (here):
There are two points here:
fill_bytes
drop extra bytes to align future reads?I believe currently all our PRNGs align all reads to their word boundary (
u32
oru64
, or possibly mixed depending on the read).The question is less about reproducibility (which can be achieved with any rigorous specification), but about use in ciphers where the text is split into arbitrary chunks.
Proposal: status quo + unaligned wrapper
We could keep the current code as-is, but add e.g.
ChaChaUnaligned
orChaChaCipher
.Our current CSPRNGs are built using a
BlockRng
orBlockRng64
struct around an implementation ofBlockRngCore
. We could add aBlockRngUnaligned
(or maybeBlockCipher
) struct to use a different implementation ofnext_*
andfill_bytes
around the same core, but with different alignment behaviour (i.e. still implementRngCore
but potentially not drop any unused bytes, forcing unaligned reads).In theory this struct could also have an
xor_bytes
function (see here).The text was updated successfully, but these errors were encountered: