-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhight_test.go
41 lines (32 loc) · 1.61 KB
/
hight_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
package krcrypt
import (
"bytes"
"testing"
)
// http://tools.ietf.org/html/draft-kisa-hight-00
// http://seed.kisa.or.kr/kor/hight/hightInfo.jsp -> "HIGHT Algorithm Test Vectors"
var hightTestVectors = []struct {
key []byte
plain []byte
cipher []byte
}{
{[]byte{0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}, []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, []byte{0x00, 0xf4, 0x18, 0xae, 0xd9, 0x4f, 0x03, 0xf2}},
{[]byte{0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00}, []byte{0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77}, []byte{0x23, 0xce, 0x9f, 0x72, 0xe5, 0x43, 0xe6, 0xd8}},
{[]byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, []byte{0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef}, []byte{0x7a, 0x6f, 0xb2, 0xa2, 0x8d, 0x23, 0xf4, 0x66}},
{[]byte{0x28, 0xdb, 0xc3, 0xbc, 0x49, 0xff, 0xd8, 0x7d, 0xcf, 0xa5, 0x09, 0xb1, 0x1d, 0x42, 0x2b, 0xe7}, []byte{0xb4, 0x1e, 0x6b, 0xe2, 0xeb, 0xa8, 0x4a, 0x14}, []byte{0xcc, 0x04, 0x7a, 0x75, 0x20, 0x9c, 0x1f, 0xc6}},
}
// make sure we can encrypt to produce our test vectors, and decrypt to produce the original plaintext.
func TestHIGHTEncrypt(t *testing.T) {
for _, v := range hightTestVectors {
h, _ := NewHIGHT(v.key)
var c, p [8]byte
h.Encrypt(c[:], v.plain)
if !bytes.Equal(v.cipher, c[:]) {
t.Errorf("hight encrypt failed: got %#v wanted %#v\n", c, v.cipher)
}
h.Decrypt(p[:], c[:])
if !bytes.Equal(v.plain, p[:]) {
t.Errorf("hight decrypt failed: got %#v wanted %#v\n", p, v.plain)
}
}
}