Skip to content
This repository has been archived by the owner on Jun 29, 2024. It is now read-only.

Commit

Permalink
refactor: move MD tests into md module
Browse files Browse the repository at this point in the history
  • Loading branch information
codahale committed Nov 9, 2023
1 parent e509510 commit 81654b7
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 47 deletions.
49 changes: 2 additions & 47 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,9 @@ pub fn areion512_dm(
}

#[cfg(test)]
mod tests {
pub mod tests {
use super::*;

use digest::Digest;
use expect_test::expect;

#[test]
Expand Down Expand Up @@ -376,51 +375,7 @@ mod tests {
.assert_eq(&hex_fmt(&x_p));
}

#[test]
fn areion512_md_test_vector_1() {
let data = hex!(
"
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
);

expect![[r#"
7f 22 34 44 5f 3a 72 00 65 93 79 42 01 53 6c 94
09 5d ab d3 fd b5 84 67 48 d3 59 55 5c 52 e6 51"#]]
.assert_eq(&hex_fmt(
&Areion512Md::default().chain_update(data).finalize(),
));
}

#[test]
fn areion512_md_test_vector_2() {
let data = hex!(
"
00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f
10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f
20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f
30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f
40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f
50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f
60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f
70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f"
);

expect![[r#"
3e 4d 31 0f be 21 d0 7b b9 00 46 88 a1 50 36 b7
ab d9 ae 2f e9 e6 0c 9a ca 2a cc 36 98 5e 60 0b"#]]
.assert_eq(&hex_fmt(
&Areion512Md::default().chain_update(data).finalize(),
));
}

fn hex_fmt(b: &[u8]) -> String {
pub fn hex_fmt(b: &[u8]) -> String {
b.iter()
.map(|v| format!("{:02x}", v))
.collect::<Vec<String>>()
Expand Down
54 changes: 54 additions & 0 deletions src/md.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,57 @@ impl AlgorithmName for Core {
}

pub type Areion512Md = CoreWrapper<Core>;

#[cfg(test)]
mod tests {
use super::*;

use crate::tests::hex_fmt;

use digest::Digest;
use expect_test::expect;

#[test]
fn areion512_md_test_vector_1() {
let data = hex!(
"
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
);

expect![[r#"
7f 22 34 44 5f 3a 72 00 65 93 79 42 01 53 6c 94
09 5d ab d3 fd b5 84 67 48 d3 59 55 5c 52 e6 51"#]]
.assert_eq(&hex_fmt(
&Areion512Md::default().chain_update(data).finalize(),
));
}

#[test]
fn areion512_md_test_vector_2() {
let data = hex!(
"
00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f
10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f
20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f
30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f
40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f
50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f
60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f
70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f"
);

expect![[r#"
3e 4d 31 0f be 21 d0 7b b9 00 46 88 a1 50 36 b7
ab d9 ae 2f e9 e6 0c 9a ca 2a cc 36 98 5e 60 0b"#]]
.assert_eq(&hex_fmt(
&Areion512Md::default().chain_update(data).finalize(),
));
}
}

0 comments on commit 81654b7

Please sign in to comment.