Add checks against f4jumble test vectors.

This commit is contained in:
Kris Nuttycombe 2021-05-19 08:50:50 -06:00
parent 774d166fff
commit 1dcba34167
2 changed files with 3652 additions and 18 deletions

View File

@ -2,18 +2,25 @@ use blake2b_simd::{Params as Blake2bParams, OUTBYTES};
use std::cmp::min;
use std::ops::RangeInclusive;
#[cfg(test)]
mod test_vectors;
const VALID_LENGTH: RangeInclusive<usize> = 48..=16448;
macro_rules! H_PERS {
( $i:expr ) => {
[85, 65, 95, 70, 52, 74, 117, 109, 98, 108, 101, 95, 72, 95, $i, 0]
}
[
85, 65, 95, 70, 52, 74, 117, 109, 98, 108, 101, 95, 72, 95, $i, 0,
]
};
}
macro_rules! G_PERS {
( $i:expr, $j:expr ) => {
[85, 65, 95, 70, 52, 74, 117, 109, 98, 108, 101, 95, 71, 95, $i, $j]
}
[
85, 65, 95, 70, 52, 74, 117, 109, 98, 108, 101, 95, 71, 95, $i, $j,
]
};
}
struct Hashes {
@ -38,17 +45,18 @@ impl Hashes {
}
fn g(&self, i: u8, u: &[u8]) -> Vec<u8> {
(0..ceildiv(self.l_r, OUTBYTES)).flat_map(|j| {
Blake2bParams::new()
.hash_length(OUTBYTES)
.personal(&G_PERS!(i, j as u8))
.hash(u)
.as_ref()
.to_vec()
.into_iter()
})
.take(self.l_r)
.collect()
(0..ceildiv(self.l_r, OUTBYTES))
.flat_map(|j| {
Blake2bParams::new()
.hash_length(OUTBYTES)
.personal(&G_PERS!(i, j as u8))
.hash(u)
.as_ref()
.to_vec()
.into_iter()
})
.take(self.l_r)
.collect()
}
}
@ -101,13 +109,13 @@ mod tests {
use proptest::collection::vec;
use proptest::prelude::*;
use super::{f4jumble, f4jumble_inv, VALID_LENGTH};
use super::{f4jumble, f4jumble_inv, test_vectors::test_vectors, VALID_LENGTH};
#[test]
fn h_pers() {
assert_eq!(&H_PERS!(7), b"UA_F4Jumble_H_\x07\x00");
}
#[test]
fn g_pers() {
assert_eq!(&G_PERS!(7, 13), b"UA_F4Jumble_G_\x07\x0d");
@ -134,4 +142,12 @@ mod tests {
prop_assert_eq!(msg, unjumbled, "Unjumbled message did not match original message.");
}
}
#[test]
fn f4jumble_check_vectors() {
for v in test_vectors() {
let jumbled = f4jumble(&v.normal).unwrap();
assert_eq!(jumbled, v.jumbled);
}
}
}

File diff suppressed because it is too large Load Diff