mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-21 13:53:55 -07:00
First check in.
This commit is contained in:
parent
4a79e52c0b
commit
f38a152863
103 changed files with 10544 additions and 508 deletions
|
@ -54,7 +54,8 @@ DELETE=del /q
|
|||
MOVE=ren
|
||||
COPY=copy
|
||||
PATHSEP=\\#
|
||||
FLASH_TOOL=winsrc\\prox.exe
|
||||
#FLASH_TOOL=winsrc\\prox.exe
|
||||
FLASH_TOOL=winsrc\\flash.exe
|
||||
DETECTED_OS=Windows
|
||||
|
||||
endif
|
||||
|
@ -67,6 +68,7 @@ INCLUDES = ../include/proxmark3.h ../include/at91sam7s512.h ../include/config_gp
|
|||
|
||||
CFLAGS = -c $(INCLUDE) -Wall -Werror -pedantic -std=c99 $(APP_CFLAGS) -Os
|
||||
LDFLAGS = -nostartfiles -nodefaultlibs -Wl,-gc-sections -n
|
||||
|
||||
LIBS = -lgcc
|
||||
|
||||
THUMBOBJ = $(patsubst %.c,$(OBJDIR)/%.o,$(THUMBSRC))
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
|
||||
#include "cmd.h"
|
||||
#include "string.h"
|
||||
#include "proxmark3.h"
|
||||
#include "../include/proxmark3.h"
|
||||
|
||||
//static UsbCommand txcmd;
|
||||
|
||||
|
|
|
@ -33,8 +33,8 @@
|
|||
#ifndef _PROXMARK_CMD_H_
|
||||
#define _PROXMARK_CMD_H_
|
||||
|
||||
#include <common.h>
|
||||
#include <usb_cmd.h>
|
||||
#include "../include/common.h"
|
||||
#include "../include/usb_cmd.h"
|
||||
#include "usb_cdc.h"
|
||||
|
||||
bool cmd_receive(UsbCommand* cmd);
|
||||
|
|
48
common/crc.h
Normal file
48
common/crc.h
Normal file
|
@ -0,0 +1,48 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
|
||||
// at your option, any later version. See the LICENSE.txt file for the text of
|
||||
// the license.
|
||||
//-----------------------------------------------------------------------------
|
||||
// Generic CRC calculation code.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef __CRC_H
|
||||
#define __CRC_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct crc {
|
||||
uint32_t state;
|
||||
int order;
|
||||
uint32_t polynom;
|
||||
uint32_t initial_value;
|
||||
uint32_t final_xor;
|
||||
uint32_t mask;
|
||||
} crc_t;
|
||||
|
||||
/* Initialize a crc structure. order is the order of the polynom, e.g. 32 for a CRC-32
|
||||
* polynom is the CRC polynom. initial_value is the initial value of a clean state.
|
||||
* final_xor is XORed onto the state before returning it from crc_result(). */
|
||||
extern void crc_init(crc_t *crc, int order, uint32_t polynom, uint32_t initial_value, uint32_t final_xor);
|
||||
|
||||
/* Update the crc state. data is the data of length data_width bits (only the the
|
||||
* data_width lower-most bits are used).
|
||||
*/
|
||||
extern void crc_update(crc_t *crc, uint32_t data, int data_width);
|
||||
|
||||
/* Clean the crc state, e.g. reset it to initial_value */
|
||||
extern void crc_clear(crc_t *crc);
|
||||
|
||||
/* Get the result of the crc calculation */
|
||||
extern uint32_t crc_finish(crc_t *crc);
|
||||
|
||||
/* Static initialization of a crc structure */
|
||||
#define CRC_INITIALIZER(_order, _polynom, _initial_value, _final_xor) { \
|
||||
.state = ((_initial_value) & ((1L<<(_order))-1)), \
|
||||
.order = (_order), \
|
||||
.polynom = (_polynom), \
|
||||
.initial_value = (_initial_value), \
|
||||
.final_xor = (_final_xor), \
|
||||
.mask = ((1L<<(_order))-1) }
|
||||
|
||||
#endif /* __CRC_H */
|
35
common/crc32.c
Normal file
35
common/crc32.c
Normal file
|
@ -0,0 +1,35 @@
|
|||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include "crc32.h"
|
||||
|
||||
#define htole32(x) (x)
|
||||
#define CRC32_PRESET 0xFFFFFFFF
|
||||
|
||||
|
||||
static void crc32_byte (uint32_t *crc, const uint8_t value);
|
||||
|
||||
static void crc32_byte (uint32_t *crc, const uint8_t value) {
|
||||
/* x32 + x26 + x23 + x22 + x16 + x12 + x11 + x10 + x8 + x7 + x5 + x4 + x2 + x + 1 */
|
||||
const uint32_t poly = 0xEDB88320;
|
||||
|
||||
*crc ^= value;
|
||||
for (int current_bit = 7; current_bit >= 0; current_bit--) {
|
||||
int bit_out = (*crc) & 0x00000001;
|
||||
*crc >>= 1;
|
||||
if (bit_out)
|
||||
*crc ^= poly;
|
||||
}
|
||||
}
|
||||
|
||||
void crc32 (const uint8_t *data, const size_t len, uint8_t *crc) {
|
||||
uint32_t desfire_crc = CRC32_PRESET;
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
crc32_byte (&desfire_crc, data[i]);
|
||||
}
|
||||
|
||||
*((uint32_t *)(crc)) = htole32 (desfire_crc);
|
||||
}
|
||||
|
||||
void crc32_append (uint8_t *data, const size_t len) {
|
||||
crc32 (data, len, data + len);
|
||||
}
|
15
common/crc32.h
Normal file
15
common/crc32.h
Normal file
|
@ -0,0 +1,15 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
|
||||
// at your option, any later version. See the LICENSE.txt file for the text of
|
||||
// the license.
|
||||
//-----------------------------------------------------------------------------
|
||||
// CRC32
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef __CRC32_H
|
||||
#define __CRC32_H
|
||||
|
||||
void crc32 (const uint8_t *data, const size_t len, uint8_t *crc);
|
||||
void crc32_append (uint8_t *data, const size_t len);
|
||||
|
||||
#endif
|
177
common/desfire.h
Normal file
177
common/desfire.h
Normal file
|
@ -0,0 +1,177 @@
|
|||
#ifndef __DESFIRE_H
|
||||
#define __DESFIRE_H
|
||||
|
||||
#include "aes.h"
|
||||
#define DESFIRE(tag) ((struct desfire_tag *) tag)
|
||||
#define DESFIRE_KEY(key) ((struct desfire_key *) key)
|
||||
|
||||
#define MAX_CRYPTO_BLOCK_SIZE 16
|
||||
/* Mifare DESFire EV1 Application crypto operations */
|
||||
#define APPLICATION_CRYPTO_DES 0x00
|
||||
#define APPLICATION_CRYPTO_3K3DES 0x40
|
||||
#define APPLICATION_CRYPTO_AES 0x80
|
||||
|
||||
#define MAC_LENGTH 4
|
||||
#define CMAC_LENGTH 8
|
||||
|
||||
typedef enum {
|
||||
MCD_SEND,
|
||||
MCD_RECEIVE
|
||||
} MifareCryptoDirection;
|
||||
|
||||
typedef enum {
|
||||
MCO_ENCYPHER,
|
||||
MCO_DECYPHER
|
||||
} MifareCryptoOperation;
|
||||
|
||||
#define MDCM_MASK 0x000F
|
||||
|
||||
#define CMAC_NONE 0
|
||||
|
||||
// Data send to the PICC is used to update the CMAC
|
||||
#define CMAC_COMMAND 0x010
|
||||
// Data received from the PICC is used to update the CMAC
|
||||
#define CMAC_VERIFY 0x020
|
||||
|
||||
// MAC the command (when MDCM_MACED)
|
||||
#define MAC_COMMAND 0x100
|
||||
// The command returns a MAC to verify (when MDCM_MACED)
|
||||
#define MAC_VERIFY 0x200
|
||||
|
||||
#define ENC_COMMAND 0x1000
|
||||
#define NO_CRC 0x2000
|
||||
|
||||
#define MAC_MASK 0x0F0
|
||||
#define CMAC_MACK 0xF00
|
||||
|
||||
/* Communication mode */
|
||||
#define MDCM_PLAIN 0x00
|
||||
#define MDCM_MACED 0x01
|
||||
#define MDCM_ENCIPHERED 0x03
|
||||
|
||||
/* Error code managed by the library */
|
||||
#define CRYPTO_ERROR 0x01
|
||||
|
||||
|
||||
enum DESFIRE_AUTH_SCHEME {
|
||||
AS_LEGACY,
|
||||
AS_NEW
|
||||
};
|
||||
|
||||
enum DESFIRE_CRYPTOALGO {
|
||||
T_DES = 0x00,
|
||||
T_3DES = 0x01,
|
||||
T_3K3DES = 0x02,
|
||||
T_AES = 0x03
|
||||
};
|
||||
|
||||
struct desfire_key {
|
||||
|
||||
enum DESFIRE_CRYPTOALGO type;
|
||||
uint8_t data[24];
|
||||
// DES_key_schedule ks1;
|
||||
// DES_key_schedule ks2;
|
||||
// DES_key_schedule ks3;
|
||||
AesCtx aes_ks;
|
||||
uint8_t cmac_sk1[24];
|
||||
uint8_t cmac_sk2[24];
|
||||
uint8_t aes_version;
|
||||
};
|
||||
|
||||
typedef struct desfire_key *desfirekey_t;
|
||||
|
||||
struct desfire_tag {
|
||||
iso14a_card_select_t info;
|
||||
int active;
|
||||
uint8_t last_picc_error;
|
||||
uint8_t last_internal_error;
|
||||
uint8_t last_pcd_error;
|
||||
desfirekey_t session_key;
|
||||
enum DESFIRE_AUTH_SCHEME authentication_scheme;
|
||||
uint8_t authenticated_key_no;
|
||||
|
||||
uint8_t ivect[MAX_CRYPTO_BLOCK_SIZE];
|
||||
uint8_t cmac[16];
|
||||
uint8_t *crypto_buffer;
|
||||
size_t crypto_buffer_size;
|
||||
uint32_t selected_application;
|
||||
};
|
||||
typedef struct desfire_tag *desfiretag_t;
|
||||
|
||||
|
||||
/* File types */
|
||||
enum DESFIRE_FILE_TYPES {
|
||||
MDFT_STANDARD_DATA_FILE = 0x00,
|
||||
MDFT_BACKUP_DATA_FILE = 0x01,
|
||||
MDFT_VALUE_FILE_WITH_BACKUP = 0x02,
|
||||
MDFT_LINEAR_RECORD_FILE_WITH_BACKUP = 0x03,
|
||||
MDFT_CYCLIC_RECORD_FILE_WITH_BACKUP = 0x04
|
||||
};
|
||||
|
||||
|
||||
|
||||
enum DESFIRE_STATUS {
|
||||
OPERATION_OK = 0x00,
|
||||
NO_CHANGES = 0x0c,
|
||||
OUT_OF_EEPROM_ERROR = 0x0e,
|
||||
ILLEGAL_COMMAND_CODE = 0x1c,
|
||||
INTEGRITY_ERROR = 0x1e,
|
||||
NO_SUCH_KEY = 0x40,
|
||||
LENGTH_ERROR = 0x7e,
|
||||
PERMISSION_DENIED = 0x9d,
|
||||
PARAMETER_ERROR = 0x9e,
|
||||
APPLICATION_NOT_FOUND = 0xa0,
|
||||
APPL_INTEGRITY_ERROR = 0xa1,
|
||||
AUTHENTICATION_ERROR = 0xae,
|
||||
ADDITIONAL_FRAME = 0xaf,
|
||||
BOUNDARY_ERROR = 0xbe,
|
||||
PICC_INTEGRITY_ERROR = 0xc1,
|
||||
COMMAND_ABORTED = 0xca,
|
||||
PICC_DISABLED_ERROR = 0xcd,
|
||||
COUNT_ERROR = 0xce,
|
||||
DUPLICATE_ERROR = 0xde,
|
||||
EEPROM_ERROR = 0xee,
|
||||
FILE_NOT_FOUND = 0xf0,
|
||||
FILE_INTEGRITY_ERROR = 0xf1
|
||||
};
|
||||
|
||||
enum DESFIRE_CMD {
|
||||
CREATE_APPLICATION = 0xca,
|
||||
DELETE_APPLICATION = 0xda,
|
||||
GET_APPLICATION_IDS = 0x6a,
|
||||
SELECT_APPLICATION = 0x5a,
|
||||
FORMAT_PICC = 0xfc,
|
||||
GET_VERSION = 0x60,
|
||||
READ_DATA = 0xbd,
|
||||
WRITE_DATA = 0x3d,
|
||||
GET_VALUE = 0x6c,
|
||||
CREDIT = 0x0c,
|
||||
DEBIT = 0xdc,
|
||||
LIMITED_CREDIT = 0x1c,
|
||||
WRITE_RECORD = 0x3b,
|
||||
READ_RECORDS = 0xbb,
|
||||
CLEAR_RECORD_FILE = 0xeb,
|
||||
COMMIT_TRANSACTION = 0xc7,
|
||||
ABORT_TRANSACTION = 0xa7,
|
||||
GET_FREE_MEMORY = 0x6e,
|
||||
GET_FILE_IDS = 0x6f,
|
||||
GET_FILE_SETTINGS = 0xf5,
|
||||
CHANGE_FILE_SETTINGS = 0x5f,
|
||||
CREATE_STD_DATA_FILE = 0xcd,
|
||||
CREATE_BACKUP_DATA_FILE = 0xcb,
|
||||
CREATE_VALUE_FILE = 0xcc,
|
||||
CREATE_LINEAR_RECORD_FILE = 0xc1,
|
||||
CREATE_CYCLIC_RECORD_FILE = 0xc0,
|
||||
DELETE_FILE = 0xdf,
|
||||
AUTHENTICATE = 0x0a, // AUTHENTICATE_NATIVE
|
||||
AUTHENTICATE_ISO = 0x1a, // AUTHENTICATE_STANDARD
|
||||
AUTHENTICATE_AES = 0xaa,
|
||||
CHANGE_KEY_SETTINGS = 0x54,
|
||||
GET_KEY_SETTINGS = 0x45,
|
||||
CHANGE_KEY = 0xc4,
|
||||
GET_KEY_VERSION = 0x64,
|
||||
AUTHENTICATION_FRAME = 0xAF
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
// ISO14443 CRC calculation code.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "iso14443crc.h"
|
||||
#include "../common/iso14443crc.h"
|
||||
|
||||
static unsigned short UpdateCrc14443(unsigned char ch, unsigned short *lpwCrc)
|
||||
{
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
#ifndef __ISO14443CRC_H
|
||||
#define __ISO14443CRC_H
|
||||
#include "common.h"
|
||||
#include "../include/common.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Routines to compute the CRCs (two different flavours, just for confusion)
|
||||
|
|
|
@ -7,11 +7,14 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
#include "proxmark3.h"
|
||||
#include "../include/proxmark3.h"
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
//#include "iso15693tools.h"
|
||||
|
||||
#define POLY 0x8408
|
||||
|
||||
|
||||
// The CRC as described in ISO 15693-Part 3-Annex C
|
||||
// v buffer with data
|
||||
// n length
|
||||
|
@ -63,5 +66,31 @@ char* Iso15693sprintUID(char *target,uint8_t *uid) {
|
|||
return target;
|
||||
}
|
||||
|
||||
unsigned short iclass_crc16(char *data_p, unsigned short length)
|
||||
{
|
||||
unsigned char i;
|
||||
unsigned int data;
|
||||
unsigned int crc = 0xffff;
|
||||
|
||||
if (length == 0)
|
||||
return (~crc);
|
||||
|
||||
do
|
||||
{
|
||||
for (i=0, data=(unsigned int)0xff & *data_p++;
|
||||
i < 8;
|
||||
i++, data >>= 1)
|
||||
{
|
||||
if ((crc & 0x0001) ^ (data & 0x0001))
|
||||
crc = (crc >> 1) ^ POLY;
|
||||
else crc >>= 1;
|
||||
}
|
||||
} while (--length);
|
||||
|
||||
crc = ~crc;
|
||||
data = crc;
|
||||
crc = (crc << 8) | (data >> 8 & 0xff);
|
||||
crc = crc ^ 0xBC3;
|
||||
return (crc);
|
||||
}
|
||||
|
||||
|
|
|
@ -70,6 +70,7 @@
|
|||
uint16_t Iso15693Crc(uint8_t *v, int n);
|
||||
int Iso15693AddCrc(uint8_t *req, int n);
|
||||
char* Iso15693sprintUID(char *target,uint8_t *uid);
|
||||
unsigned short iclass_crc16(char *data_p, unsigned short length);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Map a sequence of octets (~layer 2 command) into the set of bits to feed
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
// LEFIC's obfuscation function
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "legic_prng.h"
|
||||
#include "../include/legic_prng.h"
|
||||
|
||||
struct lfsr {
|
||||
uint8_t a;
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
*/
|
||||
|
||||
#include "usb_cdc.h"
|
||||
#include "config_gpio.h"
|
||||
#include "../include/config_gpio.h"
|
||||
|
||||
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
#ifndef _USB_CDC_H_
|
||||
#define _USB_CDC_H_
|
||||
|
||||
#include <common.h>
|
||||
#include "../include/common.h"
|
||||
|
||||
void usb_disable();
|
||||
void usb_enable();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue