Skip to content

Commit

Permalink
chg: LF t55xx trace
Browse files Browse the repository at this point in the history
new:  LF t55xx info
  • Loading branch information
iceman1001 committed Oct 6, 2014
1 parent 7546537 commit f6c1863
Show file tree
Hide file tree
Showing 25 changed files with 924 additions and 799 deletions.
13 changes: 6 additions & 7 deletions armsrc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ APP_CFLAGS = -DWITH_LF -DWITH_ISO15693 -DWITH_ISO14443a -DWITH_ISO14443b -DWITH_
#SRC_LCD = fonts.c LCD.c
SRC_LF = lfops.c hitag2.c
SRC_ISO15693 = iso15693.c iso15693tools.c
SRC_ISO14443a = epa.c iso14443a.c mifareutil.c mifarecmd.c mifaresniff.c
SRC_ISO14443b = iso14443.c
SRC_CRAPTO1 = crapto1.c crypto1.c des.c aes.c
SRC_CRC = iso14443crc.c crc.c crc16.c crc32.c
SRC_ISO14443a = epa.c iso14443a.c mifareutil.c mifarecmd.c mifaresniff.c
SRC_ISO14443b = iso14443.c
SRC_CRAPTO1 = crapto1.c crypto1.c des.c aes.c desfire_key.c desfire_crypto.c
SRC_CRC = iso14443crc.c crc.c crc16.c crc32.c

THUMBSRC = start.c \
$(SRC_LCD) \
Expand All @@ -41,9 +41,8 @@ ARMSRC = fpgaloader.c \
$(SRC_CRC) \
legic_prng.c \
iclass.c \
mifaredesfire.c \
desfire_crypto.c \
desfire_key.c
mifaredesfire.c


# stdint.h provided locally until GCC 4.5 becomes C99 compliant
APP_CFLAGS += -I.
Expand Down
4 changes: 2 additions & 2 deletions armsrc/appmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
#include "util.h"
#include "printf.h"
#include "string.h"

#include <stdarg.h>


#include "legicrf.h"
#include "../include/hitag2.h"

Expand Down Expand Up @@ -842,7 +842,7 @@ void UsbPacketReceived(uint8_t *packet, int len)
MifareDES_Auth1(c->arg[0], c->arg[1], c->arg[2], c->d.asBytes);
break;
case CMD_MIFARE_DESFIRE_AUTH2:
MifareDES_Auth2(c->arg[0],c->d.asBytes);
//MifareDES_Auth2(c->arg[0],c->d.asBytes);
break;
// case CMD_MIFARE_DES_READER:
// ReaderMifareDES(c->arg[0], c->arg[1], c->d.asBytes);
Expand Down
44 changes: 12 additions & 32 deletions armsrc/apps.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,21 @@

#include <stdint.h>
#include <stddef.h>
#include <sys/types.h>

#include <stdlib.h>
#include <sys/types.h>
#include <string.h>
#include <strings.h>


#include "../include/common.h"
#include "../include/hitag2.h"
#include "../include/mifare.h"

//#include <openssl/des.h>
//#include <openssl/aes.h>

//#include "des.h"
//#include "aes.h"
#include "../common/desfire.h"
#include "../common/crc32.h"
//#include "desfire_crypto.h"
//#include "desfire_key.h"


// The large multi-purpose buffer, typically used to hold A/D samples,
// maybe processed in some way.
Expand Down Expand Up @@ -156,6 +150,7 @@ void CopyIndala224toT55x7(int uid1, int uid2, int uid3, int uid4, int uid5, int
void T55xxWriteBlock(uint32_t Data, uint32_t Block, uint32_t Pwd, uint8_t PwdMode);
void T55xxReadBlock(uint32_t Block, uint32_t Pwd, uint8_t PwdMode );
void T55xxReadTrace(void);
void TurnReadLFOn();
int DemodPCF7931(uint8_t **outBlocks);
int IsBlock0PCF7931(uint8_t *Block);
int IsBlock1PCF7931(uint8_t *Block);
Expand Down Expand Up @@ -209,30 +204,17 @@ void MifareCSetBlock(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datai
void MifareCGetBlock(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain);

// mifaredesfire.h
bool InitDesfireCard();
void MifareSendCommand(uint8_t arg0,uint8_t arg1, uint8_t *datain);
void MifareDesfireGetInformation();
void MifareDES_Auth1(uint8_t arg0,uint8_t arg1,uint8_t arg2, uint8_t *datain);
void MifareDES_Auth2(uint32_t arg0, uint8_t *datain);
int mifare_des_auth2(uint32_t uid, uint8_t *key, uint8_t *blockData);
void ReaderMifareDES(uint32_t param, uint32_t param2, uint8_t * datain);
int DesfireAPDU(uint8_t *cmd, size_t cmd_len, uint8_t *dataout);
size_t CreateAPDU( uint8_t *datain, size_t len, uint8_t *dataout);
void OnSuccess();
void OnError();
bool InitDesfireCard();
void MifareSendCommand(uint8_t arg0,uint8_t arg1, uint8_t *datain);
void MifareDesfireGetInformation();
void MifareDES_Auth1(uint8_t arg0,uint8_t arg1,uint8_t arg2, uint8_t *datain);
void ReaderMifareDES(uint32_t param, uint32_t param2, uint8_t * datain);
int DesfireAPDU(uint8_t *cmd, size_t cmd_len, uint8_t *dataout);
size_t CreateAPDU( uint8_t *datain, size_t len, uint8_t *dataout);
void OnSuccess();
void OnError();


// desfire_key.h
desfirekey_t Desfire_des_key_new (const uint8_t value[8]);
desfirekey_t Desfire_3des_key_new (const uint8_t value[16]);
desfirekey_t Desfire_des_key_new_with_version (const uint8_t value[8]);
desfirekey_t Desfire_3des_key_new_with_version (const uint8_t value[16]);
desfirekey_t Desfire_3k3des_key_new (const uint8_t value[24]);
desfirekey_t Desfire_3k3des_key_new_with_version (const uint8_t value[24]);
desfirekey_t Desfire_aes_key_new (const uint8_t value[16]);
desfirekey_t Desfire_aes_key_new_with_version (const uint8_t value[16], uint8_t version);
uint8_t Desfire_key_get_version (desfirekey_t key);
void Desfire_key_set_version (desfirekey_t key, uint8_t version);
desfirekey_t Desfire_session_key_new (const uint8_t rnda[], const uint8_t rndb[], desfirekey_t authkey);

// desfire_crypto.h
void *mifare_cryto_preprocess_data (desfiretag_t tag, void *data, size_t *nbytes, off_t offset, int communication_settings);
Expand All @@ -247,8 +229,6 @@ void cmac_generate_subkeys (desfirekey_t key);
void cmac (const desfirekey_t key, uint8_t *ivect, const uint8_t *data, size_t len, uint8_t *cmac);




/// iso15693.h
void RecordRawAdcSamplesIso15693(void);
void AcquireRawAdcSamplesIso15693(void);
Expand Down
2 changes: 1 addition & 1 deletion armsrc/crapto1.c
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ lfsr_common_prefix(uint32_t pfx, uint32_t rr, uint8_t ks[8], uint8_t par[8][8])

odd = lfsr_prefix_ks(ks, 1);
even = lfsr_prefix_ks(ks, 0);

s = statelist = malloc((sizeof *statelist) << 20);
if(!s || !odd || !even) {
free(statelist);
Expand Down
1 change: 0 additions & 1 deletion armsrc/desfire_crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@
#include "des.h"
//#include "aes.h"


#endif
85 changes: 41 additions & 44 deletions armsrc/desfire_key.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
*
* $Id$
*/

#include "desfire_key.h"
#include <stdlib.h>
#include "desfire_key.h"

static inline void update_key_schedules (desfirekey_t key);

Expand All @@ -29,67 +29,68 @@ static inline void update_key_schedules (desfirekey_t key) {
// }
}

desfirekey_t Desfire_des_key_new (const uint8_t value[8]) {
void Desfire_des_key_new (const uint8_t value[8], desfirekey_t key) {
uint8_t data[8];
memcpy (data, value, 8);
for (int n=0; n < 8; n++)
data[n] &= 0xfe;
return Desfire_des_key_new_with_version (data);
Desfire_des_key_new_with_version (data, key);
}

desfirekey_t Desfire_des_key_new_with_version (const uint8_t value[8]) {
desfirekey_t key = NULL;
key->type = T_DES;
memcpy (key->data, value, 8);
memcpy (key->data+8, value, 8);
update_key_schedules (key);
return key;
void Desfire_des_key_new_with_version (const uint8_t value[8], desfirekey_t key) {
if ( key != NULL) {
key->type = T_DES;
memcpy (key->data, value, 8);
memcpy (key->data+8, value, 8);
update_key_schedules (key);
}
}

desfirekey_t Desfire_3des_key_new (const uint8_t value[16]) {
void Desfire_3des_key_new (const uint8_t value[16], desfirekey_t key) {
uint8_t data[16];
memcpy (data, value, 16);
for (int n=0; n < 8; n++)
data[n] &= 0xfe;
for (int n=8; n < 16; n++)
data[n] |= 0x01;
return Desfire_3des_key_new_with_version (data);
Desfire_3des_key_new_with_version (data, key);
}

desfirekey_t Desfire_3des_key_new_with_version (const uint8_t value[16]) {
desfirekey_t key = NULL;
key->type = T_3DES;
memcpy (key->data, value, 16);
update_key_schedules (key);
return key;
void Desfire_3des_key_new_with_version (const uint8_t value[16], desfirekey_t key) {
if ( key != NULL ){
key->type = T_3DES;
memcpy (key->data, value, 16);
update_key_schedules (key);
}
}

desfirekey_t Desfire_3k3des_key_new (const uint8_t value[24]) {
void Desfire_3k3des_key_new (const uint8_t value[24], desfirekey_t key) {
uint8_t data[24];
memcpy (data, value, 24);
for (int n=0; n < 8; n++)
data[n] &= 0xfe;
return Desfire_3k3des_key_new_with_version (data);
Desfire_3k3des_key_new_with_version (data, key);
}

desfirekey_t Desfire_3k3des_key_new_with_version (const uint8_t value[24]) {
desfirekey_t key = NULL;
key->type = T_3K3DES;
memcpy (key->data, value, 24);
update_key_schedules (key);
return key;
void Desfire_3k3des_key_new_with_version (const uint8_t value[24], desfirekey_t key) {
if ( key != NULL){
key->type = T_3K3DES;
memcpy (key->data, value, 24);
update_key_schedules (key);
}
}

desfirekey_t Desfire_aes_key_new (const uint8_t value[16]) {
return Desfire_aes_key_new_with_version (value, 0);
void Desfire_aes_key_new (const uint8_t value[16], desfirekey_t key) {
Desfire_aes_key_new_with_version (value, 0, key);
}

desfirekey_t Desfire_aes_key_new_with_version (const uint8_t value[16], uint8_t version) {
desfirekey_t key = NULL;
memcpy (key->data, value, 16);
key->type = T_AES;
key->aes_version = version;
return key;
void Desfire_aes_key_new_with_version (const uint8_t value[16], uint8_t version, desfirekey_t key) {

if (key != NULL) {
memcpy (key->data, value, 16);
key->type = T_AES;
key->aes_version = version;
}
}

uint8_t Desfire_key_get_version (desfirekey_t key) {
Expand All @@ -98,7 +99,6 @@ uint8_t Desfire_key_get_version (desfirekey_t key) {
for (int n = 0; n < 8; n++) {
version |= ((key->data[n] & 1) << (7 - n));
}

return version;
}

Expand All @@ -118,24 +118,22 @@ void Desfire_key_set_version (desfirekey_t key, uint8_t version)
}
}

desfirekey_t Desfire_session_key_new (const uint8_t rnda[], const uint8_t rndb[], desfirekey_t authkey) {

desfirekey_t key = NULL;
void Desfire_session_key_new (const uint8_t rnda[], const uint8_t rndb[], desfirekey_t authkey, desfirekey_t key) {

uint8_t buffer[24];

switch (authkey->type) {
case T_DES:
memcpy (buffer, rnda, 4);
memcpy (buffer+4, rndb, 4);
key = Desfire_des_key_new_with_version (buffer);
Desfire_des_key_new_with_version (buffer, key);
break;
case T_3DES:
memcpy (buffer, rnda, 4);
memcpy (buffer+4, rndb, 4);
memcpy (buffer+8, rnda+4, 4);
memcpy (buffer+12, rndb+4, 4);
key = Desfire_3des_key_new_with_version (buffer);
Desfire_3des_key_new_with_version (buffer, key);
break;
case T_3K3DES:
memcpy (buffer, rnda, 4);
Expand All @@ -144,15 +142,14 @@ desfirekey_t Desfire_session_key_new (const uint8_t rnda[], const uint8_t rndb[]
memcpy (buffer+12, rndb+6, 4);
memcpy (buffer+16, rnda+12, 4);
memcpy (buffer+20, rndb+12, 4);
key = Desfire_3k3des_key_new (buffer);
Desfire_3k3des_key_new (buffer, key);
break;
case T_AES:
memcpy (buffer, rnda, 4);
memcpy (buffer+4, rndb, 4);
memcpy (buffer+8, rnda+12, 4);
memcpy (buffer+12, rndb+12, 4);
key = Desfire_aes_key_new (buffer);
Desfire_aes_key_new (buffer, key);
break;
}
return key;
}
23 changes: 15 additions & 8 deletions armsrc/desfire_key.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
#ifndef __DESFIRE_KEY_H
#define __DESFIRE_KEY_H

#include <string.h>
#include <stdint.h>
#include <stdarg.h>

#ifndef __DESFIRE_KEY_INCLUDED
#define __DESFIRE_KEY_INCLUDED
#include "iso14443a.h"
#include "../common/desfire.h"
// desfire_key.h
void Desfire_des_key_new (const uint8_t value[8], desfirekey_t key);
void Desfire_3des_key_new (const uint8_t value[16], desfirekey_t key);
void Desfire_des_key_new_with_version (const uint8_t value[8], desfirekey_t key);
void Desfire_3des_key_new_with_version (const uint8_t value[16], desfirekey_t key);
void Desfire_3k3des_key_new (const uint8_t value[24], desfirekey_t key);
void Desfire_3k3des_key_new_with_version (const uint8_t value[24], desfirekey_t key);
void Desfire_aes_key_new (const uint8_t value[16], desfirekey_t key);
void Desfire_aes_key_new_with_version (const uint8_t value[16], uint8_t version,desfirekey_t key);
uint8_t Desfire_key_get_version (desfirekey_t key);
void Desfire_key_set_version (desfirekey_t key, uint8_t version);
void Desfire_session_key_new (const uint8_t rnda[], const uint8_t rndb[], desfirekey_t authkey, desfirekey_t key);

#endif
10 changes: 1 addition & 9 deletions armsrc/iso14443a.c
Original file line number Diff line number Diff line change
Expand Up @@ -1205,13 +1205,6 @@ static void TransmitFor14443a(const uint8_t *cmd, int len, uint32_t *timing)
// clear TXRDY
AT91C_BASE_SSC->SSC_THR = SEC_Y;

// for(uint16_t c = 0; c < 10;) { // standard delay for each transfer (allow tag to be ready after last transmission)
// if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) {
// AT91C_BASE_SSC->SSC_THR = SEC_Y;
// c++;
// }
// }

uint16_t c = 0;
for(;;) {
if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) {
Expand All @@ -1223,8 +1216,7 @@ static void TransmitFor14443a(const uint8_t *cmd, int len, uint32_t *timing)
}
}

NextTransferTime = MAX(NextTransferTime, LastTimeProxToAirStart + REQUEST_GUARD_TIME);

NextTransferTime = MAX(NextTransferTime, LastTimeProxToAirStart + REQUEST_GUARD_TIME);
}


Expand Down
Loading

0 comments on commit f6c1863

Please sign in to comment.