Comments (5)
Overriding block_bytes
and block bits
will not work, as BlockSize
used in the HMAC
implementation to create key arrays.
Probably the easiest way to implement this will be to define two separate types with appropriate bounds on OutputSize. It will look approximately like this:
struct Grostl<OutputSize, BlockSize> {
...
os: PhantomData<OutputSize>,
bs: PhantomData<BlockSize>,
}
pub type GrostlSmall<OutputSize>
where OutputSize: ArrayLength<u8> + Cmp<U512>,
Compare<T1, U257>: Same<Less>
= Grostl<OutputSize, U512>;
pub type GrostlBig<OutputSize>
where OutputSize: ArrayLength<u8> + Cmp<U512>,
Compare<T1, U256>: Same<Greater>
= Grostl<OutputSize, U1024>;
Grostl
will be private and user will only have access to GrostlBig
and GrostlSmall
(and other aliases based on them, e.g. Grostl256
, Grostl384
, Grostl512
, etc.). After that you can implement Digest
generically over OutputSize
and BlockSize
without worrying about incorrect combinations.
This approach is a bit hacky, but I couldn't get with a better one. Probably with specialization it will be possible to write it in a more general manner, but unfortunately I am not that familiar with it.
from hashes.
Thanks, I'll do that. I have some questions though.
- I'm assuming by
T1
you meanOutputSize
? - What's the point of the
Cmp<U512>
bound? - Shouldn't
GrostlBig
have be bounded by something likeCompare<OutputSize, U513>: Same<Less>
as well?
from hashes.
Another point:
pub type GrostlSmall<OutputSize>
where OutputSize: ArrayLength<u8> + Cmp<U512>,
Compare<OutputSize, U257>: Same<Less>
= Grostl<OutputSize, U512>;
With that code, I'd like to not make the Grostl
struct public. Then the user is forced to use a type alias with the correct BlockSize
; they can't mess that up. But I'm hinting the warning E0446 (rust-lang/rust#34537) about exporting a private type in a public API, which will soon be an error. I'll go ahead an make it public for now, but I'm wondering if you have any ideas on the issue.
from hashes.
I'm assuming by T1 you mean
OutputSize
?
Yes, it was leftover from testing code.
What's the point of the Cmp bound?
It allows us to write condition which uses Compare
type operator. You can think about it as of typenum
's implementation detail.
Shouldn't
GrostlBig
have be bounded by something likeCompare<OutputSize, U513>: Same<Less>
as well?
Yes, forgot to add upper bound.
With that code, I'd like to not make the
Grostl
struct public. Then the user is forced to use a type alias with the correctBlockSize
; they can't mess that up. But I'm hinting the warning E0446 (rust-lang/rust#34537) about exporting a private type in a public API, which will soon be an error. I'll go ahead an make it public for now, but I'm wondering if you have any ideas on the issue.
I believe warning also gives a note with a way around it. You just need to place Grostl
in the different module. I've used the same aproach for Streebog
hash function.
from hashes.
Closed in the #10.
from hashes.
Related Issues (20)
- Cannot build on x86_64-unknown-uefi target HOT 10
- Hash functions not working on bare metal HOT 6
- The speed of calculating in rust seems like not as fast as in Node. HOT 2
- ring affected by CVE-2022-37454? HOT 3
- Upgrade issues from sha-1 0.9.8 to sha1 0.10.x HOT 2
- [Feature Request] SHA-3 KMAC HOT 1
- Performance issue on SHA3-Keccak256 since v0.10.7 HOT 12
- comparing after dereferencing or unsafely indexing, which is faster? HOT 1
- Blake2 parameters cannot be used without a key HOT 3
- use keccak crate in k12 HOT 2
- streebog: Use const fn to generate `SHUFFLED_LIN_TABLE`
- fix(?): some `extern` functions couldn't be found HOT 2
- `sha2` fails to build in Windows on an ARM device HOT 2
- blake2: MAC variants should not be constructable with an empty key?
- sha2: Interested in a way to save/restore internal state HOT 1
- Strange quirk in SHA256 impl HOT 1
- "no such associated item" in IDE but build succeeds HOT 3
- jh: remove dependency on `ppv-lite86`
- Sha256::new() is always marked as an error in the vscode HOT 1
- can't build `[email protected]` HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hashes.