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

Add chunked input processing of KATs #326

Open
brycx opened this issue Mar 15, 2023 · 0 comments
Open

Add chunked input processing of KATs #326

brycx opened this issue Mar 15, 2023 · 0 comments
Labels
testing All testing, except for fuzzing related

Comments

@brycx
Copy link
Member

brycx commented Mar 15, 2023

While differential fuzzing does this, the standard test suite of Orion does not in all cases. For example, StreamingContextConsistencyTester does use this approach, for default input and quickcheck property tests. But the test runners in /tests don't seem to. At least not NIST CAVP. Let's extend these to enable processing KATs input in random chunks, if streaming state is available for the primitive, and compare with a one-shot call. Not just calling update() once, but at least two times.

Example of extended new test:

fn sha256_test_runner(data: &[u8], output: &[u8]) {
    let mut state = sha2::sha256::Sha256::new();
    
    let bytes = data;
    let mut data_len = data.len();
    let mut rng = rand::task_rng();
    
    while (data.len() != 0) {
        let n: usize = rng.gen_range(0, data.len());
        state.update(bytes[..n]).unwrap();
        bytes = &bytes[n..];
        data_len -= n;
     }

    let digest = state.finalize().unwrap();
    let digest_one_shot = sha2::sha256::Sha256::digest(data).unwrap();

    assert_eq!(digest.as_ref(), digest_one_shot.as_ref());
    assert_eq!(digest.as_ref(), output);
}
@brycx brycx added the testing All testing, except for fuzzing related label Mar 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
testing All testing, except for fuzzing related
Projects
None yet
Development

No branches or pull requests

1 participant