-
Notifications
You must be signed in to change notification settings - Fork 256
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
Shake output should be variable length #14
Comments
You are right to bring this issue. I've known about it and planned to fix it later, but I am not completely sure what approach to use. One way is to create three traits, which I imagined would look somewhat like this:
Here length of the passed slice will be length of the output. Disadvantage here is need to import two traits instead of one for all users. Alternative approach would be to create
It would be a bit more ergonomic to use for most of the cases, but solution is a less elegant. Also it can cause problems and be unergonomic in case if Currently I am leaning towards the second solution without method renaming. I wanted to experiment with it after fixing #5 based on |
Is there some restriction of the
Also, these four methods for the block or output size in bytes and bits only return a runtime representation anyways, so maybe you want them to be type level numbers in a separate |
AFAIK when using As for dropping type level numbers from Regarding methods |
There was a type-o in my comment, oops. I'd meant that the I'd also ignored that Another approach might be :
Any conventional mode would simply consume the hasher with finalize and return the fixed length
In this, there is no allowance for modes that intermix input and output operations however, not sure if that's allowed by any common modes. It's possible one should always drop down to the underlying permutation function for that sort of thing. |
With I will try to play around this problem a little more. Also it possible that someone else will come up with a good solution to it later. |
Just to be clear, any normal mode would only satisfy |
Are there any hash functions with modes that allow intermixed input after output? |
If I understood your question correctly, this use-case is not covered explicitly and as far as I remember all hashes in this repository have some kind of finalization, but you can take advantage of |
Right. I realized OS PRNGs do this without cloning, but they pull randomness from various outside sources as they cannot know how much they'll be expected to produce at any given time. You could avoid that with a better permutation, but afaik cryptographers do not do so currently, if only because their constructions mirror the underlying mathematics. Anyways if anybody wants to do this in the future then they can make a special API. No need to worry about it here. |
Just fyi, a degree of support for defining arrays whose length is given by an associated constant just landed rust-lang/rust#40008 It currently depends upon not using parameters rust-lang/rfcs#1915 (comment) but that's probably fine. |
But in this PR it's clearly written that:
Or am I missing something? Also note that for example in case of groestl we use conditions on constants, so unfortunately until something like this will land we'll have to use |
I've no idea how long before array lengths can be controlled by type parameters, but it's seemingly on the way, while const dependent types sound distant future if ever. |
I've updated crates to a new version of digest crate, which now includes traits It works mostly fine, but does not fit for Groestl, which requires output size to be passed at hasher initialization. I think I'll just create |
I've merged |
As an aside, I'm nervous about A prioir, I think |
Though you are right that it's not always sensible to use HMAC construct (e.g. for BLAKE2), in those cases MAC trait will be implemented directly on the digest struct. It will be done for BLAKE2 and probably for SHA-3 (using simple prepending of the key). I should not forget to add to documentation a discouragement of using HMAC in case if digest already implements MAC. But I don't think we need to artificially restrict ability to use HMAC on such functions. A more philosophical note: as I see it, users of "low-level" RustCrypto crates should have a bare minimum understanding of that they are doing. It's a bit risky, but it's an intentional decision to open a path for a more flexible ecosystem. As a result, for example, it allows inclusion of compromised or experimental algorithms. |
Yes, it makes sense to implement RFC 2104 where you have older hash functions, but one could still place I'm not suggesting this influences usability, safety, etc. It's just pure aesthetics for hash functions without any sensible |
Lets move this discussion into #20. |
Sha3's shake mode should provides variable length output determined at runtime, but it's currently a user defined type level numeric. I'd think the
OutputSize
type of theDigest
trait should be replaced by aOutput
type to fix this, but I have no looked into doing it.The text was updated successfully, but these errors were encountered: