Skip to content

Commit d7939a7

Browse files
committed
fixed consts docs and moved all consts defintion into consts.rs
added source for test vectors
1 parent 332fb95 commit d7939a7

File tree

5 files changed

+72
-59
lines changed

5 files changed

+72
-59
lines changed

md6/Cargo.toml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ keywords = ["crypto", "md6", "hash", "digest"]
1111
categories = ["cryptography", "no-std"]
1212
rust-version = "1.81"
1313

14-
[lib]
15-
name = "md6"
16-
1714
[dependencies]
1815
digest = "=0.11.0-pre.9"
1916

@@ -27,7 +24,3 @@ default = ["oid", "std"]
2724
std = ["digest/std"]
2825
oid = ["digest/oid"]
2926
zeroize = ["digest/zeroize"]
30-
31-
[package.metadata.docs.rs]
32-
all-features = true
33-
rustdoc-args = ["--cfg", "docsrs"]

md6/src/compress.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,5 @@
11
use crate::consts::*;
22

3-
const W: usize = MD6_W; // number of bits in a word (64)
4-
const C: usize = MD6_C; // size of compression output in words (16)
5-
const N: usize = MD6_N; // size of compression input block in words (89)
6-
const Q: usize = MD6_Q; // Q words in a compression block (>= 0) (15)
7-
const K: usize = MD6_K; // key words per compression block (>= 0) (8)
8-
const U: usize = MD6_U; // words for unique node ID (0 or 64/w)
9-
const V: usize = MD6_V; // words for control word (0 or 64/w)
10-
const B: usize = MD6_B; // data words per compression block (> 0) (64)
11-
12-
const T0: usize = 17; // index for linear feedback
13-
const T1: usize = 18; // index for first input to first and
14-
const T2: usize = 21; // index for second input to first and
15-
const T3: usize = 31; // index for first input to second and
16-
const T4: usize = 67; // index for second input to second and
17-
const T5: usize = 89; // last tap
18-
193
macro_rules! call_loop_bodies {
204
($w: ident, $s: expr, $i: expr) => {
215
if $w == 64 {

md6/src/consts.rs

Lines changed: 58 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,63 @@
11
/// MD6 constants related to standard mode of operation
22
3-
pub(crate) type Md6Word = u64;
4-
pub(crate) type Md6ControlWord = u64;
5-
pub(crate) type Md6NodeID = u64;
3+
pub type Md6Word = u64;
4+
pub type Md6ControlWord = u64;
5+
pub type Md6NodeID = u64;
66

7-
pub(crate) const MD6_MAX_STACK_HEIGHT: usize = 29; // maximum stack height
8-
pub(crate) const MD6_MAX_R: usize = 255; // maximum number of rounds
9-
pub(crate) const MD6_DEFAULT_L: usize = 64; // large so that MD6 is fully hierarchical
7+
/// Maximum stack height
8+
pub const MD6_MAX_STACK_HEIGHT: usize = 29;
9+
/// Maximum number of rounds
10+
pub const MD6_MAX_R: usize = 255;
11+
/// Large so that MD6 is fully hierarchical
12+
pub const MD6_DEFAULT_L: usize = 64;
1013

11-
pub(crate) const MD6_W: usize = 64; // number of bits in a word
12-
pub(crate) const MD6_C: usize = 16; // size of compression output in words
13-
pub(crate) const MD6_N: usize = 89; // size of compression input block in words
14+
/// Number of bits in a word
15+
pub const MD6_W: usize = 64;
16+
/// Size of compression output in words
17+
pub const MD6_C: usize = 16;
18+
/// Size of compression input block in words
19+
pub const MD6_N: usize = 89;
1420

15-
/// These five values give lengths of the components of compression
16-
/// input block; they should sum to MD6_N.
17-
pub(crate) const MD6_Q: usize = 15; // Q words in a compression block (>= 0)
18-
pub(crate) const MD6_K: usize = 8; // key words per compression block (>= 0)
19-
pub(crate) const MD6_U: usize = 64 / MD6_W; // words for unique node ID (0 or 64/w)
20-
pub(crate) const MD6_V: usize = 64 / MD6_W; // words for control word (0 or 64/w)
21-
pub(crate) const MD6_B: usize = 64; // data words per compression block (> 0)
21+
// These five values give lengths of the components of compression
22+
// input block; they should sum to MD6_N.
23+
24+
// Q words in a compression block (>= 0)
25+
pub const MD6_Q: usize = 15;
26+
/// Key words per compression block (>= 0)
27+
pub const MD6_K: usize = 8;
28+
/// Words for unique node ID (0 or 64/w)
29+
pub const MD6_U: usize = 64 / MD6_W;
30+
/// Words for control word (0 or 64/w)
31+
pub const MD6_V: usize = 64 / MD6_W;
32+
/// Data words per compression block (> 0)
33+
pub const MD6_B: usize = 64;
34+
35+
/// Number of bits in a word (64)
36+
pub const W: usize = MD6_W;
37+
/// Size of compression output in words (16)
38+
pub const C: usize = MD6_C;
39+
/// Size of compression input block in words (89)
40+
pub const N: usize = MD6_N;
41+
/// Q words in a compression block (>= 0) (15)
42+
pub const Q: usize = MD6_Q;
43+
/// Key words per compression block (>= 0) (8)
44+
pub const K: usize = MD6_K;
45+
/// Words for unique node ID (0 or 64/w)
46+
pub const U: usize = MD6_U;
47+
/// Words for control word (0 or 64/w)
48+
pub const V: usize = MD6_V;
49+
/// Data words per compression block (> 0) (64)
50+
pub const B: usize = MD6_B;
51+
52+
/// Index for linear feedback
53+
pub const T0: usize = 17;
54+
/// Index for first input to first and
55+
pub const T1: usize = 18;
56+
/// Index for second input to first and
57+
pub const T2: usize = 21;
58+
/// Index for first input to second and
59+
pub const T3: usize = 31;
60+
/// Index for second input to second and
61+
pub const T4: usize = 67;
62+
/// Last tap
63+
pub const T5: usize = 89;

md6/src/md6.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@ use digest::{
1313
HashMarker, Output,
1414
};
1515

16-
const W: usize = MD6_W; // number of bits in a word (64)
17-
const C: usize = MD6_C; // size of compression output in words (16)
18-
const K: usize = MD6_K; // key words per compression block (8)
19-
const B: usize = MD6_B; // data words per compression block (64)
20-
2116
pub struct Md6VarCore {
2217
d: usize,
2318
hashbitlen: usize,
@@ -289,7 +284,6 @@ impl SerializableState for Md6VarCore {
289284
impl Md6VarCore {
290285
#[inline]
291286
fn init(d: usize) -> Self {
292-
//
293287
Self::full_init(d, None, 0, MD6_DEFAULT_L, default_r(d, 0))
294288
}
295289

md6/tests/mod.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
#![no_std]
2-
31
use digest::Digest;
42
use hex_literal::hex;
53

4+
// Test vectors from https://github.com/Snack-X/md6/blob/master/test/result.csv
5+
66
#[test]
77
fn test_md6_64() {
8-
const INPUT: &[(&[u8], &[u8; 8])] = &[
8+
const TEST_VECTOR: &[(&[u8], &[u8; 8])] = &[
99
(b"a", &hex!("32d13030a6815e95")),
1010
(b"aa", &hex!("af7966908a5d9c13")),
1111
(b"aaa", &hex!("3d8a4ff7a21eb0c6")),
@@ -30,7 +30,7 @@ fn test_md6_64() {
3030
(b"md6 FTW", &hex!("47cda109418592ca")),
3131
];
3232

33-
for (msg, &expected_hash) in INPUT.iter() {
33+
for (msg, &expected_hash) in TEST_VECTOR.iter() {
3434
let mut hasher = md6::Md6_64::new();
3535
hasher.update(msg);
3636
let output = hasher.finalize();
@@ -41,7 +41,7 @@ fn test_md6_64() {
4141

4242
#[test]
4343
fn test_md6_128() {
44-
const INPUT: &[(&[u8], &[u8; 16])] = &[
44+
const TEST_VECTOR: &[(&[u8], &[u8; 16])] = &[
4545
(b"a", &hex!("bb691c1bfa4b4345292eb35f364919ea")),
4646
(b"aa", &hex!("19487e566f9ae2584d62628af2795f8c")),
4747
(b"aaa", &hex!("319f1b026f76f9caf62320b4e2e79e29")),
@@ -66,7 +66,7 @@ fn test_md6_128() {
6666
(b"md6 FTW", &hex!("e866b430fa07b5bea28981db1f9b24a6")),
6767
];
6868

69-
for (msg, &expected_hash) in INPUT.iter() {
69+
for (msg, &expected_hash) in TEST_VECTOR.iter() {
7070
let mut hasher = md6::Md6_128::new();
7171
hasher.update(msg);
7272
let output = hasher.finalize();
@@ -77,7 +77,7 @@ fn test_md6_128() {
7777

7878
#[test]
7979
fn test_md6_224() {
80-
const INPUT: &[(&[u8], &[u8; 28])] = &[
80+
const TEST_VECTOR: &[(&[u8], &[u8; 28])] = &[
8181
(
8282
b"a",
8383
&hex!("05de8792a96e024c806eb815f9f30053cf9f1b50661047a4934121b7"),
@@ -168,7 +168,7 @@ fn test_md6_224() {
168168
),
169169
];
170170

171-
for (msg, &expected_hash) in INPUT.iter() {
171+
for (msg, &expected_hash) in TEST_VECTOR.iter() {
172172
let mut hasher = md6::Md6_224::new();
173173
hasher.update(msg);
174174
let output = hasher.finalize();
@@ -179,7 +179,7 @@ fn test_md6_224() {
179179

180180
#[test]
181181
fn test_md6_256() {
182-
const INPUT: &[(&[u8], &[u8; 32])] = &[
182+
const TEST_VECTOR: &[(&[u8], &[u8; 32])] = &[
183183
(
184184
b"a",
185185
&hex!("2b0a697a081c21269514640aab4d74ffafeb3c0212df68ce92922087c69b0a77"),
@@ -270,7 +270,7 @@ fn test_md6_256() {
270270
),
271271
];
272272

273-
for (msg, &expected_hash) in INPUT.iter() {
273+
for (msg, &expected_hash) in TEST_VECTOR.iter() {
274274
let mut hasher = md6::Md6_256::new();
275275
hasher.update(msg);
276276
let output = hasher.finalize();
@@ -281,7 +281,7 @@ fn test_md6_256() {
281281

282282
#[test]
283283
fn test_md6_384() {
284-
const INPUT: &[(&[u8], &[u8; 48])] = &[
284+
const TEST_VECTOR: &[(&[u8], &[u8; 48])] = &[
285285
(b"a", &hex!("a40c8d059495a278fadd30b96e3b2227758090c759b934197265bf632cabf8547a7429e5316d496c2a1ddae8d27e87ee")),
286286
(b"aa", &hex!("330547441b6518e7693ea01bfc55158bcfc084853fa1960a9e8999f98b57cea7d8b0564bf192b6ab1eb7638939dc9bbf")),
287287
(b"aaa", &hex!("f43bb4e108ec31e0cf8ded506f79373e69cddcd8c7c46298f1bd475401132e4c255c08e378c9db988f0de97131cbe36c")),
@@ -306,7 +306,7 @@ fn test_md6_384() {
306306
(b"md6 FTW", &hex!("7a4e8ecd1035ccdf00567595c15aa5a382fef2b6a4ec4bc609e0c655887b1c05e10eee223dd6c0ba5fa4a46159c70757")),
307307
];
308308

309-
for (msg, &expected_hash) in INPUT.iter() {
309+
for (msg, &expected_hash) in TEST_VECTOR.iter() {
310310
let mut hasher = md6::Md6_384::new();
311311
hasher.update(msg);
312312
let output = hasher.finalize();
@@ -317,7 +317,7 @@ fn test_md6_384() {
317317

318318
#[test]
319319
fn test_md6_512() {
320-
const INPUT: &[(&[u8], &[u8; 64])] = &[
320+
const TEST_VECTOR: &[(&[u8], &[u8; 64])] = &[
321321
(b"a", &hex!("c0e4e18acb69cd1a7e5a20981fe6cc6f7b5b70e814d3a13b05ac292aba74c0d8c9d34c211414e7ab755a9559c27211cd749fc3eb09ae670e138881743b8d5051")),
322322
(b"aa", &hex!("2afa253b05702770343e5c46e9d47231812a741d7bba479539a3c5484a412ea419f0d0ca96e124ba92e4ca506ca12684579323051d9d52fe5a669d079a226683")),
323323
(b"aaa", &hex!("56b0131875d458f6d30ed1c594991df1efa8d6cae0c8abb36a9b811df23ac476c58e36d9adbe845e840d3de9175a8ceda11235144c3222587af108b902ce0fc5")),
@@ -342,7 +342,7 @@ fn test_md6_512() {
342342
(b"md6 FTW", &hex!("75df3b6031e8241ef59d01628b093b05906f1a2d80c43908cb2883f7db6fbdd1cadffd7d643505c20b9529b6a5d19f8b6ff1623cabbc14a606caa7bcb239611a")),
343343
];
344344

345-
for (msg, &expected_hash) in INPUT.iter() {
345+
for (msg, &expected_hash) in TEST_VECTOR.iter() {
346346
let mut hasher = md6::Md6_512::new();
347347
hasher.update(msg);
348348
let output = hasher.finalize();

0 commit comments

Comments
 (0)