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

HandshakeState: Add function to find out size of next write #88

Open
fogti opened this issue Jun 6, 2020 · 0 comments
Open

HandshakeState: Add function to find out size of next write #88

fogti opened this issue Jun 6, 2020 · 0 comments

Comments

@fogti
Copy link
Contributor

fogti commented Jun 6, 2020

It would be useful to find out which size (w/o payload) the next HandshakeState::write_message will produce, so that the payload may be used to pad up the message to make it harder for an attacker to find out that a re-handshake happened (which means that I can't simply save the length of the padding outside of the more-or-less-encrypted payload, as it would be noticable w/o decrypting it).

e.g. I'm currently able to pad transport messages (https://github.com/YZITE/encsess2/blob/297b279a9274750bb83d9c5ab7a3ea3cfee29184/lib/src/lib.rs#L106-L135), but because the size of handshake messages depends on the handshake pattern, vary between different handshake messages (e.g. are at least different for initiator and responder) and I really don't want to hardcode them, an API for that would be necessary.

idea:

const PAD_TRG_SIZE: usize = 64;
let mut noise: HandshakeState = ...;
// ...
if noise.is_my_turn() {
    let next_msg_len = noise.simulate_write_message(&[]).unwrap();
    let padding_len = PAD_TRG_SIZE - (next_msg_len % PAD_TRG_SIZE);
    let mut padding = Vec::new();
    padding.resize(padding_len);
    rand::RngCore::fill_bytes(&mut rand::thread_rng(), &mut padding[..]);
    let mut hsmsg = [0u8; 0xffff];
    let real_len = noise.write_message(&padding[..], &mut hsmsg[..]).unwrap();
    assert_eq!(real_len, next_msg_len + padding_len);
    // send hsmsg via network...
}
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

Successfully merging a pull request may close this issue.

1 participant