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

Hasher expects correct output length #5

Open
zx2c4 opened this issue Jun 25, 2016 · 0 comments

Comments

Projects
None yet
1 participant
@zx2c4
Copy link
Contributor

commented Jun 25, 2016

Symmetric state has h of a fixed maximum size:

    SymmetricState{
        cipherstate: cipherstate,
        hasher: hasher,
        h: [0u8; MAXHASHLEN],
        ck : [0u8; MAXHASHLEN],
        has_key: false,
        has_preshared_key: false,
    }

When initializing, the following code is run:

fn initialize(&mut self, handshake_name: &[u8]) {
    if handshake_name.len() <= self.hasher.hash_len() {
        self.h = [0u8; MAXHASHLEN];
        copy_memory(handshake_name, &mut self.h);
    } else {
        self.hasher.reset();
        self.hasher.input(handshake_name);
        self.hasher.result(&mut self.h);
    }

When using PSK mode and a 32-byte hash function, such as Blake2s, the second branch is taken:

        self.hasher.reset();
        self.hasher.input(handshake_name);
        self.hasher.result(&mut self.h);

This passes self.h to hasher.result, which is 64 bytes:

        h: [0u8; MAXHASHLEN],

Unfortunately, the result function expects for h to be equal to the output length. That is, it expects h to be 32 bytes. From blake2s.rs:

fn finalize( &mut self, out: &mut [u8] ) {
    assert!(out.len() == self.digest_length as usize);

This makes using Blake2s with PSK impossible. The solution is to have the size of h change based on which hash function is being used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.