summaryrefslogtreecommitdiffstats
path: root/lib/md4_test.go
blob: 31b7b3147c28464a03a4f8fd0b45fc7682a56d33 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright © 2021 rsiddharth <s@ricketyspace.net>
// SPDX-License-Identifier: ISC

package lib

import "testing"

func TestMd4Hash(t *testing.T) {
	md4 := Md4{}
	md4.Init([]uint32{})

	// Test 1
	m := "abc"
	md4.Message(StrToBytes(m))
	h := md4.Hash()
	e := "a448017aaf21d8525fc10ae87aa6729d" // Expected hash.
	if BytesToHexStr(h) != e {
		t.Errorf("md4 test 1 failed: %x != %s\n", h, e)
	}

	// Test 2
	m = "message digest"
	md4.Message(StrToBytes(m))
	h = md4.Hash()
	e = "d9130a8164549fe818874806e1c7014b" // Expected hash.
	if BytesToHexStr(h) != e {
		t.Errorf("md4 test 2 failed: %x != %s\n", h, e)
	}

	// Test 3
	m = "abcdefghijklmnopqrstuvwxyz"
	md4.Message(StrToBytes(m))
	h = md4.Hash()
	e = "d79e1c308aa5bbcdeea8ed63df412da9" // Expected hash.
	if BytesToHexStr(h) != e {
		t.Errorf("md4 test 3 failed: %x != %s\n", h, e)
	}

	// Test 4
	m = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
	md4.Message(StrToBytes(m))
	h = md4.Hash()
	e = "043f8582f241db351ce627e153e7f0e4" // Expected hash.
	if BytesToHexStr(h) != e {
		t.Errorf("md4 test 4 failed: %x != %s\n", h, e)
	}

	// Test 5
	m = "123456789012345678901234567890123456789012345678901234567890123456"
	m += "78901234567890"
	md4.Message(StrToBytes(m))
	h = md4.Hash()
	e = "e33b4ddc9c38f2199c3e7b164fcc0536" // Expected hash.
	if BytesToHexStr(h) != e {
		t.Errorf("md4 test 5 failed: %x != %s\n", h, e)
	}

}