Skip to content
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

Remove alloc dependancy #8

Open
burdges opened this issue Feb 12, 2023 · 0 comments
Open

Remove alloc dependancy #8

burdges opened this issue Feb 12, 2023 · 0 comments

Comments

@burdges
Copy link

burdges commented Feb 12, 2023

A priori, hasher code like this should really run without an alloc or std dependency, so in particular Vec should not be used anywhere. It may be unavoidable if the standard is bad of course, but things like an XoF mode clearly never need Vec. There is also a lot of redundant hashing.

An expander trait could look like this for example:

pub trait Expander {
    fn construct_dst_prime(&self) -> ArrayVec::<[u8; { MAX_DST_LENGTH +1 }]>;
    fn expand<const LENGTH: usize>(&self, msg: &[u8]) -> [u8; LENGTH];
}

As this trait is internal, construct_dst_prime should really be some setup method, thus avoiding the AtomicRefCell, so maybe:

pub trait Expander {
    fn set_dst(&mut self, dst: &[u8]);
    fn expand<const LENGTH: usize>(&self, msg: &[u8]) -> [u8; LENGTH];
}

pub(super) struct ExpanderXof<T: Update + Clone + ExtendableOutput> {
    pub(super) xofer: T,
    pub(super) dst_prime: ArrayVec::<[u8; { MAX_DST_LENGTH +1 }]>,
    pub(super) k: usize,
}

pub(super) struct ExpanderXmd<T: DynDigest + Clone> {
    pub(super) hasher: T,
    pub(super) dst_prime: ArrayVec::<[u8; { MAX_DST_LENGTH +1 }]>,
    pub(super) block_size: usize,
}

Also, MAX_DST_LENGTH = 256 is enforced by the "I2OSP(len(DST), 1)" in the standard, but where does this DST shortening logic? I'm only seeing "ABORT .. if len(DST) > 256" in https://datatracker.ietf.org/doc/draft-irtf-cfrg-hash-to-curve/16/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant