-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvncpasswd_test.go
More file actions
64 lines (55 loc) · 1.93 KB
/
vncpasswd_test.go
File metadata and controls
64 lines (55 loc) · 1.93 KB
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
package vncpasswd
import (
"bytes"
"encoding/hex"
"testing"
)
func TestPasswd(t *testing.T) {
key, _ := hex.DecodeString("0123456789abcdef")
var keyA [8]byte
copy(keyA[:], key)
plain, _ := hex.DecodeString("0123456789abcdef")
cipher, _ := hex.DecodeString("6e09a37726dd560c")
ek := deskey(keyA, false)
dk := deskey(keyA, true)
// expected value for ek & dk (extracted from python version)
ekVal := []uint32{
923729924, 926749207, 255208716, 1010761729, 1059456009, 840638978, 255466756, 977078784,
926025745, 857604618, 523967232, 708578050, 925894929, 791544874, 977077025, 708708610,
1008341508, 1060569144, 1059008544, 421926152, 1007357960, 759103800, 789390368, 490082604,
690946090, 624886064, 789382176, 926224949, 591333410, 892940304, 453452810, 1041965570,
}
dkVal := []uint32{
453452810, 1041965570, 591333410, 892940304, 789382176, 926224949, 690946090, 624886064,
789390368, 490082604, 1007357960, 759103800, 1059008544, 421926152, 1008341508, 1060569144,
977077025, 708708610, 925894929, 791544874, 523967232, 708578050, 926025745, 857604618,
255466756, 977078784, 1059456009, 840638978, 255208716, 1010761729, 923729924, 926749207,
}
errCount := 0
for a, b := range ekVal {
if ek[a] != b {
errCount += 1
}
}
if errCount > 0 {
t.Errorf("ek value not as expected, contains %d errors", errCount)
}
errCount = 0
for a, b := range dkVal {
if dk[a] != b {
errCount += 1
}
}
if errCount > 0 {
t.Errorf("ek value not as expected, contains %d errors", errCount)
}
if !bytes.Equal(desfunc(plain, ek), cipher) {
t.Errorf("desfunc(plain, ek) == cipher failed (got %s instead of %s)", hex.EncodeToString(desfunc(plain, ek)), hex.EncodeToString(cipher))
}
if !bytes.Equal(desfunc(desfunc(plain, ek), dk), plain) {
t.Errorf("desfunc(desfunc(plain, ek), dk) == cipher failed")
}
if !bytes.Equal(desfunc(desfunc(plain, dk), ek), plain) {
t.Errorf("desfunc(desfunc(plain, dk), ek) == cipher failed")
}
}