Skip to content

Commit

Permalink
Fix test; add comments to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
iwiwsb committed Nov 26, 2023
1 parent 0b9199e commit aa88f5b
Showing 1 changed file with 148 additions and 144 deletions.
292 changes: 148 additions & 144 deletions md6/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ impl MD6 {
Some(Self { rounds, ..self })
}

pub fn with_key(self, key: [u8; 64]) -> Self {
Self { key, ..self }
}

pub fn control_word(
&self,
is_final_compression: bool,
Expand Down Expand Up @@ -367,162 +371,42 @@ mod tests {
];

let result = md6sum.compression_internal([
0x7311_C281_2425_CFA0,
0x6432_2864_34AA_C8E7,
0xB604_50E9_EF68_B7C1,
0xE8FB_2390_8D9F_06F1,
0xDD2E_76CB_A691_E5BF,
0x0CD0_D63B_2C30_BC41,
0x1F8C_CF68_2305_8F8A,
0x54E5_ED5B_88E3_775D,
0x4AD1_2AAE_0A6D_6031,
0x3E7F_16BB_8822_2E0D,
0x8AF8_671D_3FB5_0C2C,
0x995A_D117_8BD2_5C31,
0xC878_C1DD_04C4_B633,
0x3B72_066C_7A15_52AC,
0x0D6F_3522_631E_FFCB,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0100_0000_0000_0000,
0x0005_4010_FE80_0100,
0x6162_6300_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
]);

assert_eq!(result, expected_result);
}

#[test]
fn test_compression_function_2() {
let md6sum = MD6::new(28)
.expect("Hasher object must be created")
.with_rounds(5)
.unwrap();
let expected_result: [u64; 16] = [
0xE86A_6F80_5FB8_10CA,
0x991D_E071_2998_31A9,
0xC595_17FB_7F5C_5E74,
0x0E2B_5F69_481C_68E6,
0x8DDB_33A8_B069_B4C2,
0x558B_3513_A004_6DBD,
0xE1DF_B672_6949_AB7E,
0xF48B_AE51_5E89_EE94,
0xD31D_1F87_D97D_A302,
0x5D34_9E9B_0D69_B270,
0xB409_D2EE_2C3E_5577,
0x9976_21D4_03CD_954E,
0x7A35_3E0E_F294_90A3,
0x716D_1239_DFFF_51DC,
0x5974_4BE8_98CF_7C0A,
0x0795_1A90_E19D_A429,
];

let result = md6sum.compression_internal([
0x7311_C281_2425_CFA0, // Q[0]
0x6432_2864_34AA_C8E7, // Q[1]
0xB604_50E9_EF68_B7C1, // Q[2]
0xE8FB_2390_8D9F_06F1, // Q[3]
0xDD2E_76CB_A691_E5BF, // Q[4]
0x0CD0_D63B_2C30_BC41, // Q[5]
0x1F8C_CF68_2305_8F8A, // Q[6]
0x54E5_ED5B_88E3_775D, // Q[7]
0x4AD1_2AAE_0A6D_6031, // Q[8]
0x3E7F_16BB_8822_2E0D, // Q[9]
0x7311_C281_2425_CFA0, // Q[ 0]
0x6432_2864_34AA_C8E7, // Q[ 1]
0xB604_50E9_EF68_B7C1, // Q[ 2]
0xE8FB_2390_8D9F_06F1, // Q[ 3]
0xDD2E_76CB_A691_E5BF, // Q[ 4]
0x0CD0_D63B_2C30_BC41, // Q[ 5]
0x1F8C_CF68_2305_8F8A, // Q[ 6]
0x54E5_ED5B_88E3_775D, // Q[ 7]
0x4AD1_2AAE_0A6D_6031, // Q[ 8]
0x3E7F_16BB_8822_2E0D, // Q[ 9]
0x8AF8_671D_3FB5_0C2C, // Q[10]
0x995A_D117_8BD2_5C31, // Q[11]
0xC878_C1DD_04C4_B633, // Q[12]
0x3B72_066C_7A15_52AC, // Q[13]
0x0D6F_3522_631E_FFCB, // Q[14]
0x6162_6364_6531_3233, // key K[0]
0x3435_0000_0000_0000, // key K[1]
0x0000_0000_0000_0000, // key K[0]
0x0000_0000_0000_0000, // key K[1]
0x0000_0000_0000_0000, // key K[2]
0x0000_0000_0000_0000, // key K[3]
0x0000_0000_0000_0000, // key K[4]
0x0000_0000_0000_0000, // key K[5]
0x0000_0000_0000_0000, // key K[6]
0x0000_0000_0000_0000, // key K[7]
0x0100_0000_0000_0000, // nodeID U = (ell,i) = (1,0)
0x0005_4000_0000_A0E0, // control word V = (r,L,z,p,keylen,d) = (5,64,0,0,10,224)
0x2233_4455_6677_1122, // data B[ 0] input message word
0x3344_5566_7711_2233, // data B[ 1] input message word
0x4455_6677_1122_3344, // data B[ 2] input message word
0x5566_7711_2233_4455, // data B[ 3] input message word
0x6677_1122_3344_5566, // data B[ 4] input message word
0x7711_2233_4455_6677, // data B[ 5] input message word
0x1122_3344_5566_7711, // data B[ 6] input message word
0x2233_4455_6677_1122, // data B[ 7] input message word
0x3344_5566_7711_2233, // data B[ 8] input message word
0x4455_6677_1122_3344, // data B[ 9] input message word
0x5566_7711_2233_4455, // data B[10] input message word
0x0005_4010_FE80_0100, // control word V = (r,L,z,p,keylen,d) = (5,64,1,4072,10,256)
0x6162_6300_0000_0000, // data B[ 0] input message word
0x0000_0000_0000_0000, // data B[ 1] padding
0x0000_0000_0000_0000, // data B[ 2] padding
0x0000_0000_0000_0000, // data B[ 3] padding
0x0000_0000_0000_0000, // data B[ 4] padding
0x0000_0000_0000_0000, // data B[ 5] padding
0x0000_0000_0000_0000, // data B[ 6] padding
0x0000_0000_0000_0000, // data B[ 7] padding
0x0000_0000_0000_0000, // data B[ 8] padding
0x0000_0000_0000_0000, // data B[ 9] padding
0x0000_0000_0000_0000, // data B[10] padding
0x0000_0000_0000_0000, // data B[11] padding
0x0000_0000_0000_0000, // data B[12] padding
0x0000_0000_0000_0000, // data B[13] padding
Expand Down Expand Up @@ -581,6 +465,126 @@ mod tests {
assert_eq!(result, expected_result);
}

#[test]
fn test_compression_function_2() {
let md6sum = MD6::new(28)
.expect("Hasher object must be created")
.with_rounds(5)
.unwrap();
let expected_result: [u64; 16] = [
0xE86A_6F80_5FB8_10CA,
0x991D_E071_2998_31A9,
0xC595_17FB_7F5C_5E74,
0x0E2B_5F69_481C_68E6,
0x8DDB_33A8_B069_B4C2,
0x558B_3513_A004_6DBD,
0xE1DF_B672_6949_AB7E,
0xF48B_AE51_5E89_EE94,
0xD31D_1F87_D97D_A302,
0x5D34_9E9B_0D69_B270,
0xB409_D2EE_2C3E_5577,
0x9976_21D4_03CD_954E,
0x7A35_3E0E_F294_90A3,
0x716D_1239_DFFF_51DC,
0x5974_4BE8_98CF_7C0A,
0x0795_1A90_E19D_A429,
];

let result = md6sum.compression_internal([
0x7311_C281_2425_CFA0, // Q[ 0]
0x6432_2864_34AA_C8E7, // Q[ 1]
0xB604_50E9_EF68_B7C1, // Q[ 2]
0xE8FB_2390_8D9F_06F1, // Q[ 3]
0xDD2E_76CB_A691_E5BF, // Q[ 4]
0x0CD0_D63B_2C30_BC41, // Q[ 5]
0x1F8C_CF68_2305_8F8A, // Q[ 6]
0x54E5_ED5B_88E3_775D, // Q[ 7]
0x4AD1_2AAE_0A6D_6031, // Q[ 8]
0x3E7F_16BB_8822_2E0D, // Q[ 9]
0x8AF8_671D_3FB5_0C2C, // Q[10]
0x995A_D117_8BD2_5C31, // Q[11]
0xC878_C1DD_04C4_B633, // Q[12]
0x3B72_066C_7A15_52AC, // Q[13]
0x0D6F_3522_631E_FFCB, // Q[14]
0x6162_6364_6531_3233, // key K[0]
0x3435_0000_0000_0000, // key K[1]
0x0000_0000_0000_0000, // key K[2]
0x0000_0000_0000_0000, // key K[3]
0x0000_0000_0000_0000, // key K[4]
0x0000_0000_0000_0000, // key K[5]
0x0000_0000_0000_0000, // key K[6]
0x0000_0000_0000_0000, // key K[7]
0x0100_0000_0000_0000, // nodeID U = (ell,i) = (1,0)
0x0005_4000_0000_A0E0, // control word V = (r,L,z,p,keylen,d) = (5,64,0,0,10,224)
0x1122_3344_5566_7711, // data B[ 0] input message word 0
0x2233_4455_6677_1122, // data B[ 1] input message word 1
0x3344_5566_7711_2233, // data B[ 2] input message word 2
0x4455_6677_1122_3344, // data B[ 3] input message word 3
0x5566_7711_2233_4455, // data B[ 4] input message word 4
0x6677_1122_3344_5566, // data B[ 5] input message word 5
0x7711_2233_4455_6677, // data B[ 6] input message word 6
0x1122_3344_5566_7711, // data B[ 7] input message word 7
0x2233_4455_6677_1122, // data B[ 8] input message word 8
0x3344_5566_7711_2233, // data B[ 9] input message word 9
0x4455_6677_1122_3344, // data B[10] input message word 10
0x5566_7711_2233_4455, // data B[11] input message word 11
0x6677_1122_3344_5566, // data B[12] input message word 12
0x7711_2233_4455_6677, // data B[13] input message word 13
0x1122_3344_5566_7711, // data B[14] input message word 14
0x2233_4455_6677_1122, // data B[15] input message word 15
0x3344_5566_7711_2233, // data B[16] input message word 16
0x4455_6677_1122_3344, // data B[17] input message word 17
0x5566_7711_2233_4455, // data B[18] input message word 18
0x6677_1122_3344_5566, // data B[19] input message word 19
0x7711_2233_4455_6677, // data B[20] input message word 20
0x1122_3344_5566_7711, // data B[21] input message word 21
0x2233_4455_6677_1122, // data B[22] input message word 22
0x3344_5566_7711_2233, // data B[23] input message word 23
0x4455_6677_1122_3344, // data B[24] input message word 24
0x5566_7711_2233_4455, // data B[25] input message word 25
0x6677_1122_3344_5566, // data B[26] input message word 26
0x7711_2233_4455_6677, // data B[27] input message word 27
0x1122_3344_5566_7711, // data B[28] input message word 28
0x2233_4455_6677_1122, // data B[29] input message word 29
0x3344_5566_7711_2233, // data B[30] input message word 30
0x4455_6677_1122_3344, // data B[31] input message word 31
0x5566_7711_2233_4455, // data B[32] input message word 32
0x6677_1122_3344_5566, // data B[33] input message word 33
0x7711_2233_4455_6677, // data B[34] input message word 34
0x1122_3344_5566_7711, // data B[35] input message word 35
0x2233_4455_6677_1122, // data B[36] input message word 36
0x3344_5566_7711_2233, // data B[37] input message word 37
0x4455_6677_1122_3344, // data B[38] input message word 38
0x5566_7711_2233_4455, // data B[39] input message word 39
0x6677_1122_3344_5566, // data B[40] input message word 40
0x7711_2233_4455_6677, // data B[41] input message word 41
0x1122_3344_5566_7711, // data B[42] input message word 42
0x2233_4455_6677_1122, // data B[43] input message word 43
0x3344_5566_7711_2233, // data B[44] input message word 44
0x4455_6677_1122_3344, // data B[45] input message word 45
0x5566_7711_2233_4455, // data B[46] input message word 46
0x6677_1122_3344_5566, // data B[47] input message word 47
0x7711_2233_4455_6677, // data B[48] input message word 48
0x1122_3344_5566_7711, // data B[49] input message word 49
0x2233_4455_6677_1122, // data B[50] input message word 50
0x3344_5566_7711_2233, // data B[51] input message word 51
0x4455_6677_1122_3344, // data B[52] input message word 52
0x5566_7711_2233_4455, // data B[53] input message word 53
0x6677_1122_3344_5566, // data B[54] input message word 54
0x7711_2233_4455_6677, // data B[55] input message word 55
0x1122_3344_5566_7711, // data B[56] input message word 56
0x2233_4455_6677_1122, // data B[57] input message word 57
0x3344_5566_7711_2233, // data B[58] input message word 58
0x4455_6677_1122_3344, // data B[59] input message word 59
0x5566_7711_2233_4455, // data B[60] input message word 60
0x6677_1122_3344_5566, // data B[61] input message word 61
0x7711_2233_4455_6677, // data B[62] input message word 62
0x1122_3344_5566_7711, // data B[63] input message word 63
]);

assert_eq!(result, expected_result);
}

#[test]
fn test_compression_function_3() {
let md6sum = MD6::new(28)
Expand Down

0 comments on commit aa88f5b

Please sign in to comment.