#![allow(non_snake_case)]
mod common;
use osom_lib_hashes::{siphash::SipHash, traits::HashFunction};
use rstest::rstest;
const TEST_KEY: &[u8] = &[
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
];
const TEST_KEY_2: &[u8] = &[
0x10, 0x23, 0xa4, 0x56, 0x78, 0x90, 0xbc, 0xde, 0xf1, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
];
#[rstest]
#[case(
// The first test case is taken from the SipHash paper itself.
TEST_KEY,
&[0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e],
&[0xe5, 0x45, 0xbe, 0x49, 0x61, 0xca, 0x29, 0xa1],
)]
#[case(
TEST_KEY,
b"",
&[0x31, 0x0e, 0x0e, 0xdd, 0x47, 0xdb, 0x6f, 0x72]
)]
#[case(
TEST_KEY,
b"a",
&[0xca, 0x48, 0x11, 0xa7, 0xe9, 0xe8, 0xa3, 0x2b]
)]
#[case(
TEST_KEY,
b"A",
&[0x65, 0x90, 0xb7, 0xad, 0xe8, 0x10, 0x29, 0x71]
)]
#[case(
TEST_KEY,
b"AB",
&[0x60, 0x34, 0xa0, 0xc1, 0x80, 0x4c, 0x78, 0xcd]
)]
#[case(
TEST_KEY,
b"ab",
&[0xf3, 0xd2, 0xa0, 0x99, 0xc0, 0x52, 0x24, 0x04]
)]
#[case(
TEST_KEY,
b"aB",
&[0x68, 0x85, 0x5f, 0x44, 0x57, 0x30, 0x9b, 0x72]
)]
#[case(
TEST_KEY,
b"Ab",
&[0x32, 0x89, 0x92, 0x00, 0xdb, 0xc0, 0x38, 0xb8]
)]
#[case(
TEST_KEY,
b"012345678",
&[0xcb, 0xfc, 0xac, 0xbd, 0x5e, 0x78, 0x4b, 0x62]
)]
#[case(
TEST_KEY,
b"0123456789",
&[0x04, 0xfd, 0x35, 0x06, 0xed, 0xb4, 0x6f, 0x26]
)]
#[case(
TEST_KEY,
b"01234567890",
&[0xa6, 0x12, 0x43, 0x80, 0x3e, 0xad, 0x66, 0x99]
)]
#[case(
TEST_KEY_2,
b"012345678",
&[0x60, 0x44, 0x8a, 0xb8, 0x0a, 0xb9, 0xd3, 0xac]
)]
#[case(
TEST_KEY_2,
b"0123456789",
&[0x9e, 0x29, 0x78, 0xec, 0xe9, 0x5b, 0x1c, 0x5a]
)]
#[case(
TEST_KEY_2,
b"01234567890",
&[0xac, 0x6d, 0x1b, 0x95, 0x06, 0xb9, 0xc8, 0x9b]
)]
fn test_siphash(#[case] key: &[u8], #[case] input: &[u8], #[case] expected: &[u8]) {
let mut hash = SipHash::for_slice_key(key);
hash.update(input);
let block = hash.result();
assert_eq!(&block, expected);
}
#[rstest]
#[case(5000, &[0x6e, 0x4d, 0x6a, 0x0e, 0x75, 0x88, 0x52, 0x13])]
#[case(5001, &[0xef, 0x28, 0x8f, 0x2e, 0xfd, 0x98, 0x58, 0xc8])]
#[case(5002, &[0xc8, 0xfb, 0x9c, 0xbe, 0xed, 0x28, 0x7c, 0xfe])]
#[case(5003, &[0x54, 0x33, 0x2c, 0x27, 0xde, 0x7f, 0x27, 0x80])]
#[case(5004, &[0xa6, 0xe5, 0x7f, 0xc6, 0xc1, 0x0e, 0xbf, 0x41])]
#[case(5005, &[0x41, 0xa6, 0xc2, 0x14, 0xe7, 0x62, 0x4e, 0x1c])]
#[case(5006, &[0xb7, 0xe3, 0xc1, 0xc3, 0xc5, 0x5c, 0x03, 0x9e])]
#[case(5007, &[0x55, 0x20, 0xaf, 0xc1, 0x9d, 0x1d, 0xed, 0x44])]
#[case(5008, &[0x87, 0xef, 0x9a, 0x44, 0x46, 0x8e, 0xb6, 0xdd])]
fn test_long_siphash(#[case] size: usize, #[case] expected: &[u8]) {
common::test_pseudo_random_hashing(|| SipHash::for_keys(0, 1), size, expected);
}