Skip to content

Insufficient PRNG testing #78

Description

@veorq

Here I'd recommend to test not only the output length but also its content (by checking that the result is identical to the expected one):

sphinx/src/crypto/mod.rs

Lines 62 to 76 in b168f70

#[cfg(test)]
mod generating_pseudorandom_bytes {
use super::*;
// TODO: 10,000 is the wrong number, @aniap what is correct here?
#[test]
fn it_generates_output_of_size_10000() {
let key: [u8; STREAM_CIPHER_KEY_SIZE] =
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16];
let iv: [u8; STREAM_CIPHER_KEY_SIZE] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
let rand_bytes = generate_pseudorandom_bytes(&key, &iv, 10000);
assert_eq!(10000, rand_bytes.len());
}
}

Also, it's usually better to use input values other than all-zero (or all-some-constant) to detect potential endianness and byte ordering issues.

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