Skip to content

salsa20: incorrect counter implementation in the SSE2 backend #445

@newpavlov

Description

@newpavlov

The following test fails on x86 targets:

let mut cipher = Salsa20::new(key, iv);

let block_size = 64;
let pos = block_size * u64::from(u32::MAX);

let mut buf = [0u8; 256];
cipher.seek(pos);
cipher.write_keystream(&mut buf1);

let cur_pos: u64 = cipher.current_pos();
assert_eq!(cur_pos, pos + u64::try_from(buf.len()).unwrap());

The SSE2 backend uses 32 bit counter here. Unfortunately, because of how the state is represented, just replacing it with _mm_add_epi64 will not fix the issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions