-
Notifications
You must be signed in to change notification settings - Fork 74
/
Copy pathcrypto_test.go
64 lines (56 loc) · 1.67 KB
/
crypto_test.go
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
59
60
61
62
63
64
//Copyright 2013 Thomson Reuters Global Resources. BSD License please see License file for more information
package ntlm
import (
"bytes"
"encoding/hex"
"testing"
)
func TestMd4(t *testing.T) {
data := []byte{1, 2, 3, 4, 5}
byteData, _ := hex.DecodeString("93ebafdfedd1994e8018cc295cc1a8ee")
if !bytes.Equal(md4(data), byteData) {
t.Error("MD4 result not correct")
}
}
func TestHmacMd5(t *testing.T) {
data := []byte{1, 2, 3, 4, 5}
byteData, _ := hex.DecodeString("9155578efbf3810a2adb4dee232a5fee")
if !bytes.Equal(hmacMd5(data, data), byteData) {
t.Error("HmacMd5 result not correct")
}
}
func TestNonce(t *testing.T) {
data := nonce(10)
if len(data) != 10 {
t.Error("Nonce is incorrect length")
}
}
func TestRc4K(t *testing.T) {
data := []byte{1, 2, 3, 4, 5}
key := []byte{1, 2, 3, 4, 5}
result, err := rc4K(key, data)
if err != nil {
// TODO: Need some sample data to test RC4K
// t.Error("Error returned for RC4K")
}
if !bytes.Equal(result, data) {
// t.Error("RC4K result not correct")
}
}
func TestDesL(t *testing.T) {
key, _ := hex.DecodeString("e52cac67419a9a224a3b108f3fa6cb6d")
message := []byte("12345678")
result, _ := desL(key, message)
expected, _ := hex.DecodeString("1192855D461A9754D189D8AE94D82488E3707C0662C0476A")
if !bytes.Equal(result, expected) {
t.Errorf("DesL did not produce correct result, got %s expected %s", hex.EncodeToString(result), hex.EncodeToString(expected))
}
}
func TestCRC32(t *testing.T) {
bytes := []byte("Discard medicine more than two years old.")
result := crc32(bytes)
expected := uint32(0x6b9cdfe7)
if expected != result {
t.Errorf("CRC 32 data is not correct got %d expected %d", result, expected)
}
}