Uh oh!
There was an error while loading. Please reload this page.
Rework CryptoRng - #1273
Conversation
dhardy
commented
Dec 6, 2022
Er, yes. Please either remove formatting changes to old code or run We should use Is it a major pain to remove formatting-only changes from this PR in the mean-time? (I usually use As for the actual purpose of this PR — these issues would appear related. Didn't we already discuss this? |
newpavlov
commented
Dec 6, 2022
Yeah, I will do it somewhat later. I executed
I think I floated the drafted idea somewhere in issues. |
dhardy
commented
Dec 7, 2022
Summary of this PR: pubtraitRngCore{// keeps methods next_u32, next_u64, fill_bytes// loses try_fill_bytes}// New bound on RngCore:pubtraitCryptoRng:RngCore{fncrypto_fill_bytes(&mutself,dest:&mut[u8]) -> Result<(),Error>{/* default impl */}}// New:pubtraitCryptoBlockRng:BlockRngCore{}// Removed:// pub trait CryptoRngCore: CryptoRng + RngCore { .. }My thoughts, somewhat detached from the above... In the long term, do we even keep Given that, maybe we should make larger changes: // A revised BlockRngCore (maybe renamed or maybe not):pubtraitByteRng{constLEN:usize;fngenerate(&mutself) -> Result<[u8;Self::LEN]>;}// A cut-down RngCore (maybe we should keep the old name):pubtraitNumRng{fnnext_u32(&mutself) -> u32;fnnext_u64(&mutself) -> u64;}pubstructBlockRng<R:ByteRng>(..);impl<R: ..>NumRngforByteRng<R>{}Except, it would be nice to know at compile time the generation size of Maybe we should hold off on such a re-design until Either way, this would mean:
But this is mostly orthogonal to your changes. So:
|
newpavlov
commented
Dec 8, 2022
See #1261 (comment) for reply to the middle part of the previous comment.
I don't think the name is good either, so I am open to changing it. But I am not sure whether it's a good idea to move |
dhardy
commented
Dec 8, 2022
Do these uses even want a
The
Nor is the original, but it seems we don't have a good reason to change it. If we want to simplify, we could probably remove |
@dhardy If such type aliases is the "recommended way" of doing things, then removal of the |
dhardy
commented
Jan 7, 2023
I think the new-type wrappers are used (a) to hide the inner type (thus not an API breaking change to replace it) and (b) to allow custom methods on that type. Without re-examining I don't know how important these are (probably only (b) is applicable to ChaCha). I don't follow why this justifies removing Thanks for cleaning up the PR. |
newpavlov
commented
Jan 7, 2023
It does not look like we have users of |
dhardy
left a comment
There was a problem hiding this comment.
I wish we'd named RngCore as Rng instead, and what is now Rng as RngExt. Is it worth renaming now? It would make the names noted below more consistent, while also being better for common usage (where people use bounds like R: RngCore).
Besides this is the idea that maybe we should move one or some RngCore methods to a different trait. Most users don't need try_fill_bytesandnext_u32. You mentioned moving try_fill_bytes to CryptoRng and we seem to have rejected that idea. If we wanted a separate ByteRng for try_fill_bytes, we'd then need pub trait CryptoByteRng: ByteRng {} too.
Anyway, I'll provisionally approve this PR. If I don't, it might just get stuck.
| /// supposed to be cryptographically secure. | ||
| /// | ||
| /// See [`CryptoRng`][crate::CryptoRng] docs for more information. | ||
| pub trait CryptoBlockRng: BlockRngCore { } |
There was a problem hiding this comment.
The naming seems off: CryptoRng: RngCore, CryptoBlockRng: BlockRngCore.
tarcieri
commented
Jan 8, 2023
Sounds great to me! |
dhardy
commented
Feb 3, 2023
@newpavlov this is still marked as a draft, but I think it's ready to be merged? I already approved. I'm also happy to rename |
This PR introduces the
CryptoBlockRngmarker trait. It's used instead ofCryptoRngon block RNGs, which allows us to markCryptoRngas a subtrait ofRngCoreand makes theCryptoRngCoretrait redundant.Additionally,try_fill_bytesis moved toCryptoRngand renamed tocrypto_fill_bytes. The rationale here is that error checks for potential RNG failures are practically exclusive to cryptographic code.Unfortunately, this PR also contains a bunch of formatting changes introduced bycargo fmt. I think it could be worth to include formatting check into our CI to prevent such changes in future.cc @tarcieri