keycard-go/globalplatform/crypto/crypto_test.go

55 lines
1.7 KiB
Go
Raw Normal View History

2018-09-27 09:26:21 +00:00
package crypto
import (
"testing"
"github.com/status-im/status-go/smartcard/hexutils"
"github.com/stretchr/testify/assert"
)
func TestDeriveKey(t *testing.T) {
cardKey := hexutils.HexToBytes("404142434445464748494a4b4c4d4e4f")
seq := hexutils.HexToBytes("0065")
encKey, err := DeriveKey(cardKey, seq, DerivationPurposeEnc)
assert.NoError(t, err)
expectedEncKey := "85E72AAF47874218A202BF5EF891DD21"
assert.Equal(t, expectedEncKey, hexutils.BytesToHex(encKey))
}
func TestResizeKey24(t *testing.T) {
key := hexutils.HexToBytes("404142434445464748494a4b4c4d4e4f")
resized := resizeKey24(key)
expected := "404142434445464748494A4B4C4D4E4F4041424344454647"
assert.Equal(t, expected, hexutils.BytesToHex(resized))
}
2018-09-27 09:39:35 +00:00
func TestAppendDESPadding(t *testing.T) {
data := hexutils.HexToBytes("AABB")
result := appendDESPadding(data)
expected := "AABB800000000000"
assert.Equal(t, expected, hexutils.BytesToHex(result))
}
2018-09-27 10:08:29 +00:00
func TestVerifyCryptogram(t *testing.T) {
encKey := hexutils.HexToBytes("16B5867FF50BE7239C2BF1245B83A362")
hostChallenge := hexutils.HexToBytes("32da078d7aac1cff")
cardChallenge := hexutils.HexToBytes("007284f64a7d6465")
cardCryptogram := hexutils.HexToBytes("05c4bb8a86014e22")
result, err := VerifyCryptogram(encKey, hostChallenge, cardChallenge, cardCryptogram)
assert.NoError(t, err)
assert.True(t, result)
}
func TestMac3des(t *testing.T) {
key := hexutils.HexToBytes("16B5867FF50BE7239C2BF1245B83A362")
data := hexutils.HexToBytes("32DA078D7AAC1CFF007284F64A7D64658000000000000000")
result, err := mac3des(key, data, nullBytes8)
assert.NoError(t, err)
expected := "05C4BB8A86014E22"
assert.Equal(t, expected, hexutils.BytesToHex(result))
}