Skip to content

Commit

Permalink
Add test for md4.eval(...)
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Scheel <[email protected]>
  • Loading branch information
cipherboy committed Oct 26, 2019
1 parent f79d162 commit b50630d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
12 changes: 8 additions & 4 deletions hash_framework/algorithms/md4.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@ def r3(a, b, c, d, x, l):
state_size = 128
int_size = 32
round_size = 32
shifts = [3, 7, 11, 19] * 4 + [3, 5, 9, 13] * 4 + [3, 9, 11, 15] * 4
shifts = (
[3, 7, 11, 19] * 4
+ [3, 5, 9, 13] * 4
+ [3, 9, 11, 15] * 4
)
block_schedule = (
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
+ [0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15]
+ [0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
+ [0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15]
+ [0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15]
)
block_map = {}
round_funcs = []
Expand Down
14 changes: 14 additions & 0 deletions tests/test_md4.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ def test_known_value():
assert list(map(int, res_known)) == list(map(int, res))


def test_md4_eval():
iv = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476]
rounds = 16
block = [0x00000080] + [0x00000000] * 15

model = cmsh.Model()
h = md4()

output_state, intermediate = h.eval(model, block, iv, rounds)
actual_state = list(map(int, output_state))
expected_state = [0xaddcb303, 0x3665f296, 0x8ee8f245, 0xa483a664]

assert actual_state == expected_state

def test_md4_known_collision():
model = cmsh.Model()
h = md4()
Expand Down

0 comments on commit b50630d

Please sign in to comment.