Giter VIP home page Giter VIP logo

Comments (5)

newpavlov avatar newpavlov commented on May 30, 2024

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.

gsingh93 avatar gsingh93 commented on May 30, 2024

Thanks, I'll do that. I have some questions though.

  • I'm assuming by T1 you mean OutputSize?
  • What's the point of the Cmp<U512> bound?
  • Shouldn't GrostlBig have be bounded by something like Compare<OutputSize, U513>: Same<Less> as well?

from hashes.

gsingh93 avatar gsingh93 commented on May 30, 2024

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.

newpavlov avatar newpavlov commented on May 30, 2024

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 like Compare<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 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.

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.

newpavlov avatar newpavlov commented on May 30, 2024

Closed in the #10.

from hashes.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.