2010-07-26 23:48:18 +02:00
|
|
|
#include <cutter.h>
|
|
|
|
#include <freefare.h>
|
|
|
|
#include "freefare_internal.h"
|
|
|
|
|
|
|
|
void
|
2017-06-27 13:58:31 +02:00
|
|
|
test_mifare_rol(void)
|
2010-07-26 23:48:18 +02:00
|
|
|
{
|
|
|
|
uint8_t data[8] = "01234567";
|
2017-06-27 13:58:31 +02:00
|
|
|
rol(data, 8);
|
|
|
|
cut_assert_equal_memory("12345670", 8, data, 8, cut_message("Wrong data"));
|
2010-10-29 15:02:55 +02:00
|
|
|
|
|
|
|
uint8_t data2[16] = "0123456789abcdef";
|
2017-06-27 13:58:31 +02:00
|
|
|
rol(data2, 16);
|
|
|
|
cut_assert_equal_memory(data2, 16, "123456789abcdef0", 16, cut_message("Wrong data"));
|
2010-07-26 23:48:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-06-27 13:58:31 +02:00
|
|
|
test_mifare_desfire_des_receive(void)
|
2010-07-26 23:48:18 +02:00
|
|
|
{
|
2010-12-24 13:58:44 +01:00
|
|
|
uint8_t null_ivect[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
|
|
|
|
2010-07-26 23:48:18 +02:00
|
|
|
uint8_t data[8] = { 0xd6, 0x59, 0xe1, 0x70, 0x43, 0xa8, 0x40, 0x68 };
|
|
|
|
uint8_t key_data[8] = { 1, 1, 1, 1, 1, 1, 1, 1 };
|
2017-06-27 13:58:31 +02:00
|
|
|
MifareDESFireKey key = mifare_desfire_des_key_new_with_version(key_data);
|
2010-07-26 23:48:18 +02:00
|
|
|
|
|
|
|
uint8_t expected_data[8] = { 0x73, 0x0d, 0xdf, 0xad, 0xa4, 0xd2, 0x07, 0x89 };
|
|
|
|
uint8_t expected_key[8] = { 1, 1, 1, 1, 1, 1, 1, 1 };
|
|
|
|
|
2017-06-27 13:58:31 +02:00
|
|
|
mifare_cypher_blocks_chained(NULL, key, null_ivect, data, 8, MCD_RECEIVE, MCO_DECYPHER);
|
2010-07-26 23:48:18 +02:00
|
|
|
|
2017-06-27 13:58:31 +02:00
|
|
|
cut_assert_equal_memory(&expected_data, 8, &data, 8, cut_message("Wrong data"));
|
|
|
|
cut_assert_equal_memory(&expected_key, 8, key->data, 8, cut_message("Wrong key"));
|
2010-07-26 23:48:18 +02:00
|
|
|
|
2017-06-27 13:58:31 +02:00
|
|
|
mifare_desfire_key_free(key);
|
2010-07-26 23:48:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2017-06-27 13:58:31 +02:00
|
|
|
test_mifare_desfire_des_send(void)
|
2010-07-26 23:48:18 +02:00
|
|
|
{
|
2010-12-24 13:58:44 +01:00
|
|
|
uint8_t null_ivect[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
|
|
|
|
2010-07-26 23:48:18 +02:00
|
|
|
uint8_t data[8] = { 0x73, 0x0d, 0xdf, 0xad, 0xa4, 0xd2, 0x07, 0x89 };
|
|
|
|
uint8_t key_data[8] = { 1, 1, 1, 1, 1, 1, 1, 1 };
|
2017-06-27 13:58:31 +02:00
|
|
|
MifareDESFireKey key = mifare_desfire_des_key_new_with_version(key_data);
|
2010-07-26 23:48:18 +02:00
|
|
|
|
|
|
|
uint8_t expected_data[8] = { 0xd6, 0x59, 0xe1, 0x70, 0x43, 0xa8, 0x40, 0x68 };
|
|
|
|
uint8_t expected_key[8] = { 1, 1, 1, 1, 1, 1, 1, 1 };
|
|
|
|
|
2017-06-27 13:58:31 +02:00
|
|
|
mifare_cypher_blocks_chained(NULL, key, null_ivect, data, 8, MCD_SEND, MCO_DECYPHER);
|
2010-07-26 23:48:18 +02:00
|
|
|
|
2017-06-27 13:58:31 +02:00
|
|
|
cut_assert_equal_memory(&expected_data, 8, &data, 8, cut_message("Wrong data"));
|
|
|
|
cut_assert_equal_memory(&expected_key, 8, key->data, 8, cut_message("Wrong key"));
|
2010-07-26 23:48:18 +02:00
|
|
|
|
2017-06-27 13:58:31 +02:00
|
|
|
mifare_desfire_key_free(key);
|
2010-07-26 23:48:18 +02:00
|
|
|
}
|
2010-12-17 23:53:40 +01:00
|
|
|
|
|
|
|
void
|
2017-06-27 13:58:31 +02:00
|
|
|
test_mifare_desfire_padded_data_length(void)
|
2010-12-17 23:53:40 +01:00
|
|
|
{
|
|
|
|
size_t res;
|
|
|
|
|
2017-06-27 13:58:31 +02:00
|
|
|
res = padded_data_length(0, 8);
|
|
|
|
cut_assert_equal_int(res, 8, cut_message("Invalid size"));
|
|
|
|
res = padded_data_length(1, 8);
|
|
|
|
cut_assert_equal_int(res, 8, cut_message("Invalid size"));
|
|
|
|
res = padded_data_length(8, 8);
|
|
|
|
cut_assert_equal_int(res, 8, cut_message("Invalid size"));
|
|
|
|
res = padded_data_length(9, 8);
|
|
|
|
cut_assert_equal_int(res, 16, cut_message("Invalid size"));
|
|
|
|
res = padded_data_length(0, 16);
|
|
|
|
cut_assert_equal_int(res, 16, cut_message("Invalid size"));
|
|
|
|
res = padded_data_length(33, 16);
|
|
|
|
cut_assert_equal_int(res, 48, cut_message("Invalid size"));
|
2010-12-17 23:53:40 +01:00
|
|
|
}
|