Merge pull request #3 from RfidResearchGroup/master

Update
This commit is contained in:
Bjoern Kerler
2020-04-28 18:09:12 +02:00
committed by GitHub
33 changed files with 1047 additions and 338 deletions
+14 -18
View File
@@ -371,40 +371,36 @@ void RunMod() {
Dbhexdump(len, receivedCmd, false);
if (receivedCmd[0] == 0x02 || receivedCmd[0] == 0x03) { //Emulate a Visa MSD(Magnetic stripe data) card
uint8_t ppsea[39] = {0x6F, 0x23, 0x84, 0x0E, 0x32, 0x50, 0x41, 0x59, 0x2E, 0x53, 0x59, 0x53, 0x2E, 0x44, 0x44, 0x46, 0x30, 0x31, 0xA5, 0x11, 0xBF, 0x0C, 0x0E, 0x61, 0x0C, 0x4F, 0x07, 0xA0, 0x00, 0x00, 0x00, 0x03, 0x10, 0x10, 0x87, 0x01, 0x01, 0x90, 0x00};
uint8_t processing[10] = {0x80, 0x06, 0x00, 0x80, 0x08, 0x01, 0x01, 0x00, 0x90, 0x00};
uint8_t visauid[34] = {0x6F, 0x1E, 0x84, 0x07, 0xA0, 0x00, 0x00, 0x00, 0x03, 0x10, 0x10, 0xA5, 0x13, 0x50, 0x0B, 0x56, 0x49, 0x53, 0x41, 0x20, 0x43, 0x52, 0x45, 0x44, 0x49, 0x54, 0x9F, 0x38, 0x03, 0x9F, 0x66, 0x02, 0x90, 0x00};
uint8_t last[4] = {0x70, 0x15, 0x57, 0x13};
uint8_t card[25];
uint8_t statusapdu[2] = {0x90, 0x00};
uint8_t finished[2] = {0x6f, 0x00};
memcpy(&card[0], last, sizeof(last));
memcpy(&card[4], token, sizeof(token));
memcpy(&card[23], statusapdu, sizeof(statusapdu));
dynamic_response_info.response[0] = receivedCmd[0];
//Depending on card reader commands, the Proxmark will answer to fool the reader
if (receivedCmd[2] == 0xA4 && receivedCmd[6] == 0x32 && prevCmd == 0) { //Respond with PPSE
uint8_t ppsea[39] = {0x6F, 0x23, 0x84, 0x0E, 0x32, 0x50, 0x41, 0x59, 0x2E, 0x53, 0x59, 0x53, 0x2E, 0x44, 0x44, 0x46, 0x30, 0x31, 0xA5, 0x11, 0xBF, 0x0C, 0x0E, 0x61, 0x0C, 0x4F, 0x07, 0xA0, 0x00, 0x00, 0x00, 0x03, 0x10, 0x10, 0x87, 0x01, 0x01, 0x90, 0x00};
memcpy(&dynamic_response_info.response[1], ppsea, sizeof(ppsea));
dynamic_response_info.response_n = sizeof(ppsea) + 1;
prevCmd++;
} else if (receivedCmd[2] == 0xA4 && receivedCmd[10] == 0x03 && receivedCmd[11] == 0x10 && prevCmd == 1) { //Respond Visa AID
memcpy(&dynamic_response_info.response[1], visauid, sizeof(visauid));
dynamic_response_info.response_n = sizeof(visauid) + 1;
uint8_t visauid_long[34] = {0x6F, 0x1E, 0x84, 0x07, 0xA0, 0x00, 0x00, 0x00, 0x03, 0x10, 0x10, 0xA5, 0x13, 0x50, 0x0B, 0x56, 0x49, 0x53, 0x41, 0x20, 0x43, 0x52, 0x45, 0x44, 0x49, 0x54, 0x9F, 0x38, 0x03, 0x9F, 0x66, 0x02, 0x90, 0x00};
memcpy(&dynamic_response_info.response[1], visauid_long, sizeof(visauid_long));
dynamic_response_info.response_n = sizeof(visauid_long) + 1;
prevCmd++;
} else if (receivedCmd[1] == 0x80 && receivedCmd[2] == 0xA8 && receivedCmd[6] == 0x83 && prevCmd == 2) { //GET PROCESSING
memcpy(&dynamic_response_info.response[1], processing, sizeof(processing));
dynamic_response_info.response_n = sizeof(processing) + 1;
uint8_t processing_long[10] = {0x80, 0x06, 0x00, 0x80, 0x08, 0x01, 0x01, 0x00, 0x90, 0x00};
memcpy(&dynamic_response_info.response[1], processing_long, sizeof(processing_long));
dynamic_response_info.response_n = sizeof(processing_long) + 1;
prevCmd++;
} else if (receivedCmd[1] == 0x00 && receivedCmd[2] == 0xB2 && prevCmd == 3) { //SFI
uint8_t last[4] = {0x70, 0x15, 0x57, 0x13};
uint8_t statusapdu[2] = {0x90, 0x00};
uint8_t card[25];
memcpy(&card[0], last, sizeof(last));
memcpy(&card[4], token, sizeof(token));
memcpy(&card[23], statusapdu, sizeof(statusapdu));
memcpy(&dynamic_response_info.response[1], card, sizeof(card));
dynamic_response_info.response_n = sizeof(card) + 1;
prevCmd++;
} else {
uint8_t finished[2] = {0x6f, 0x00};
memcpy(&dynamic_response_info.response[1], finished, sizeof(finished));
dynamic_response_info.response_n = sizeof(finished) + 1;
if (prevCmd == 5) {
+17 -7
View File
@@ -780,8 +780,7 @@ int json_printf_array(struct json_out *out, va_list *ap) {
}
#ifdef _WIN32
int cs_win_vsnprintf(char *str, size_t size, const char *format,
va_list ap) WEAK;
int cs_win_vsnprintf(char *str, size_t size, const char *format, va_list ap) WEAK;
int cs_win_vsnprintf(char *str, size_t size, const char *format, va_list ap) {
int res = _vsnprintf(str, size, format, ap);
va_end(ap);
@@ -863,14 +862,21 @@ struct json_scanf_info {
int json_unescape(const char *src, int slen, char *dst, int dlen) WEAK;
int json_unescape(const char *src, int slen, char *dst, int dlen) {
char *send = (char *) src + slen, *dend = dst + dlen, *orig_dst = dst, *p;
if (dst == NULL || dlen == 0)
return JSON_STRING_INVALID;
char *send = (char *) src + slen;
char *dend = dst + dlen;
char *orig_dst = dst;
char *p;
const char *esc1 = "\"\\/bfnrt", *esc2 = "\"\\/\b\f\n\r\t";
while (src < send) {
if (*src == '\\') {
if (++src >= send) return JSON_STRING_INCOMPLETE;
if (++src >= send) { return JSON_STRING_INCOMPLETE; }
if (*src == 'u') {
if (send - src < 5) return JSON_STRING_INCOMPLETE;
if (send - src < 5) { return JSON_STRING_INCOMPLETE; }
/* Here we go: this is a \u.... escape. Process simple one-byte chars */
if (src[1] == '0' && src[2] == '0') {
/* This is \u00xx character from the ASCII range */
@@ -881,12 +887,16 @@ int json_unescape(const char *src, int slen, char *dst, int dlen) {
return JSON_STRING_INVALID;
}
} else if ((p = (char *) strchr(esc1, *src)) != NULL) {
if (dst < dend) *dst = esc2[p - esc1];
if (dst < dend) {
*dst = esc2[p - esc1];
}
} else {
return JSON_STRING_INVALID;
}
} else {
if (dst < dend) *dst = *src;
if (dst < dend) {
*dst = *src;
}
}
dst++;
src++;
+1 -3
View File
@@ -32,7 +32,7 @@ bool hitag2_crack(uint8_t *response, uint8_t *nrarhex) {
uint8_t uid[32];
uint8_t nrar[64];
uint8_t e_firstcmd[10];
uint8_t e_page0cmd[10];
// uint8_t e_page0cmd[10];
uint8_t keybits[42];
uint8_t pagehex[9];
uint8_t temp[20];
@@ -298,7 +298,6 @@ bool hitag2crack_read_page(uint8_t *responsestr, uint8_t pagenum, uint8_t *nrar,
uint8_t e_responsestr[9];
uint8_t e_response[32];
uint8_t response[32];
int i;
if (pagenum > 7) {
UserMessage("hitag2crack_read_page:\r\n invalid pagenum\r\n");
@@ -354,7 +353,6 @@ bool hitag2crack_send_e_cmd(uint8_t *responsestr, uint8_t *nrar, uint8_t *cmd, i
// uint8_t tmp[37];
uint8_t uid[9];
uint8_t e_page3str[9];
int ret = 0;
// get the UID
if (!hitag2_get_uid(uid)) {
+1 -1
View File
@@ -82,7 +82,7 @@ uint32_t getSampleCounter();
* 0 or 95 ==> 125 kHz
*
**/
void LFSetupFPGAForADC(int divisor, bool lf_field);
void LFSetupFPGAForADC(int divisor, bool reader_field);
/**
* Called from the USB-handler to set the sampling configuration
+2 -1
View File
@@ -270,7 +270,8 @@ void MifareDES_Auth1(uint8_t *datain) {
LED_B_OFF();
LED_C_OFF();
if (payload->key == NULL) {
if (payload->keylen == 0) {
if (payload->algo == MFDES_AUTH_DES) {
memcpy(keybytes, PICC_MASTER_KEY8, 8);
} else if (payload->algo == MFDES_ALGO_AES || payload->algo == MFDES_ALGO_3DES) {
+9 -9
View File
@@ -83,7 +83,7 @@ else
LDLIBS := -L/usr/local/opt/readline/lib $(LDLIBS)
LIBS := -I/usr/local/opt/readline/include $(LIBS)
# cf brew info qt: qt not symlinked anymore
PKG_CONFIG_PATH := PKG_CONFIG_PATH=/usr/local/opt/qt/lib/pkgconfig
PKG_CONFIG_ENV := PKG_CONFIG_ENV=/usr/local/opt/qt/lib/pkgconfig
else
LUALIB += -ldl
LUAPLATFORM = linux
@@ -92,16 +92,16 @@ endif
ifneq ($(SKIPQT),1)
# Check for correctly configured Qt5
QTINCLUDES = $(shell $(PKG_CONFIG_PATH) pkg-config --cflags Qt5Core Qt5Widgets 2>/dev/null)
QTLDLIBS = $(shell $(PKG_CONFIG_PATH) pkg-config --libs Qt5Core Qt5Widgets 2>/dev/null)
MOC = $(shell $(PKG_CONFIG_PATH) pkg-config --variable=host_bins Qt5Core)/moc
UIC = $(shell $(PKG_CONFIG_PATH) pkg-config --variable=host_bins Qt5Core)/uic
QTINCLUDES = $(shell $(PKG_CONFIG_ENV) pkg-config --cflags Qt5Core Qt5Widgets 2>/dev/null)
QTLDLIBS = $(shell $(PKG_CONFIG_ENV) pkg-config --libs Qt5Core Qt5Widgets 2>/dev/null)
MOC = $(shell $(PKG_CONFIG_ENV) pkg-config --variable=host_bins Qt5Core)/moc
UIC = $(shell $(PKG_CONFIG_ENV) pkg-config --variable=host_bins Qt5Core)/uic
ifeq ($(QTINCLUDES), )
# if Qt5 not found check for correctly configured Qt4
QTINCLUDES = $(shell $(PKG_CONFIG_PATH) pkg-config --cflags QtCore QtGui 2>/dev/null)
QTLDLIBS = $(shell $(PKG_CONFIG_PATH) pkg-config --libs QtCore QtGui 2>/dev/null)
MOC = $(shell $(PKG_CONFIG_PATH) pkg-config --variable=moc_location QtCore)
UIC = $(shell $(PKG_CONFIG_PATH) pkg-config --variable=uic_location QtCore)
QTINCLUDES = $(shell $(PKG_CONFIG_ENV) pkg-config --cflags QtCore QtGui 2>/dev/null)
QTLDLIBS = $(shell $(PKG_CONFIG_ENV) pkg-config --libs QtCore QtGui 2>/dev/null)
MOC = $(shell $(PKG_CONFIG_ENV) pkg-config --variable=moc_location QtCore)
UIC = $(shell $(PKG_CONFIG_ENV) pkg-config --variable=uic_location QtCore)
else
# On OSX Qt5 is claiming for a C++11 compiler (gnu++14 works too, but if nothing it fails)
PM3CXXFLAGS += -fPIC -std=c++11
+2 -2
View File
@@ -86,7 +86,7 @@ int main(int argc, char **argv) {
return 1;
}
nfc3d_amiibo_keys amiiboKeys;
nfc3d_amiibo_keys amiiboKeys = {0};
if (! LoadAmiikey(amiiboKeys, keyfile))
return 5;
@@ -136,7 +136,7 @@ int main(int argc, char **argv) {
return 3;
}
}
size_t readPages = fread(original, 4, NTAG215_SIZE / 4, f);
readPages = fread(original, 4, NTAG215_SIZE / 4, f);
if (readPages < NFC3D_AMIIBO_SIZE / 4) {
fprintf(stderr, "Could not read from save\n");
fclose(f);
+1 -1
View File
@@ -185,7 +185,7 @@ static char *read_string(scanner_t *s, va_list *ap,
length = va_arg(*ap, size_t);
} else {
prev_token(s);
length = s->has_error ? 0 : strlen(str);
length = s->has_error == 1 ? 0 : strlen(str);
}
if (!s->has_error && strbuffer_append_bytes(&strbuff, str, length) == -1) {
+8 -1
View File
@@ -313,5 +313,12 @@ FFFFFF General Issuer Information (FIDs 00: MAD Version; 01: Card Holder; 02: Ca
"Description": "Campus Card",
"Type": "student"
},
}
{
"AID": "C26001",
"Vendor": "CAR2GO",
"Country": "DE",
"Name": "MemberCard",
"Description": "CAR2GO - Member Card",
"Type": "carsharing"
}
]
+2 -2
View File
@@ -1024,7 +1024,7 @@ static int CmdHF14ACmdRaw(const char *Cmd) {
active_select = true;
break;
case 'b':
sscanf(Cmd + i + 2, "%d", &temp);
sscanf(Cmd + i + 2, "%u", &temp);
numbits = temp & 0xFFFF;
i += 3;
while (Cmd[i] != ' ' && Cmd[i] != '\0') { i++; }
@@ -1032,7 +1032,7 @@ static int CmdHF14ACmdRaw(const char *Cmd) {
break;
case 't':
bTimeout = true;
sscanf(Cmd + i + 2, "%d", &temp);
sscanf(Cmd + i + 2, "%u", &temp);
timeout = temp;
i += 3;
while (Cmd[i] != ' ' && Cmd[i] != '\0') { i++; }
+171 -102
View File
File diff suppressed because it is too large Load Diff
+10 -9
View File
@@ -2705,7 +2705,8 @@ static int CmdHF14AMfuOtpTearoff(const char *Cmd) {
return usage_hf_mfu_otp_tearoff();
case 'b':
blockNoUint = param_get8(Cmd, cmdp + 1);
if (blockNoUint < 0) {
//iceman, which blocks can be targeted? UID blocks?
if (blockNoUint < 2) {
PrintAndLogEx(WARNING, "Wrong block number");
errors = true;
}
@@ -2713,7 +2714,7 @@ static int CmdHF14AMfuOtpTearoff(const char *Cmd) {
break;
case 'i':
interval = param_get32ex(Cmd, cmdp + 1, interval, 10);
if (interval <= 0) {
if (interval == 0) {
PrintAndLogEx(WARNING, "Wrong interval number");
errors = true;
}
@@ -2758,13 +2759,14 @@ static int CmdHF14AMfuOtpTearoff(const char *Cmd) {
if (errors) return usage_hf_mfu_otp_tearoff();
PrintAndLogEx(INFO, "Starting TearOff test - Selected Block no: %u", blockNoUint);
uint32_t actualTime = startTime;
printf("\nStarting TearOff test - Selected Block no: %d ...\n", blockNoUint);
while (actualTime <= (timeLimit - interval)) {
printf("\nTrying attack at: %d us\n", actualTime);
printf("\n.....\n");
printf("\nReading block before attack: \n");
PrintAndLogEx(INFO, "Using tear-off at: %" PRIu32 " us", actualTime);
PrintAndLogEx(INFO, "Reading block BEFORE attack");
clearCommandBuffer();
SendCommandOLD(CMD_HF_MIFAREU_READBL, blockNoUint, 0, 0, NULL, 0);
@@ -2780,7 +2782,7 @@ static int CmdHF14AMfuOtpTearoff(const char *Cmd) {
}
}
printf("\n.....\n");
PrintAndLogEx(INFO, ".....");
clearCommandBuffer();
SendCommandOLD(CMD_HF_MFU_OTP_TEAROFF, blockNoUint, actualTime, 0, teardata, 8);
@@ -2789,8 +2791,7 @@ static int CmdHF14AMfuOtpTearoff(const char *Cmd) {
return PM3_ESOFT;
}
printf("\nReading block after attack: \n");
PrintAndLogEx(INFO, "Reading block AFTER attack");
clearCommandBuffer();
SendCommandOLD(CMD_HF_MIFAREU_READBL, blockNoUint, 0, 0, NULL, 0);
+18 -5
View File
@@ -177,8 +177,9 @@ static int ecdsa_init(mbedtls_ecdsa_context *ctx, mbedtls_ecp_group_id curveid,
int ecdsa_key_create(mbedtls_ecp_group_id curveid, uint8_t *key_d, uint8_t *key_xy) {
int res;
mbedtls_ecdsa_context ctx;
ecdsa_init(&ctx, curveid, NULL, NULL);
res = ecdsa_init(&ctx, curveid, NULL, NULL);
if (res)
goto exit;
mbedtls_entropy_context entropy;
mbedtls_ctr_drbg_context ctr_drbg;
@@ -276,7 +277,10 @@ int ecdsa_signature_create(mbedtls_ecp_group_id curveid, uint8_t *key_d, uint8_t
goto exit;
mbedtls_ecdsa_context ctx;
ecdsa_init(&ctx, curveid, key_d, key_xy);
res = ecdsa_init(&ctx, curveid, key_d, key_xy);
if (res)
goto exit;
res = mbedtls_ecdsa_write_signature(
&ctx,
MBEDTLS_MD_SHA256,
@@ -308,7 +312,10 @@ static int ecdsa_signature_create_test(mbedtls_ecp_group_id curveid, const char
param_gethex_to_eol(random, 0, fixed_rand_value, sizeof(fixed_rand_value), &rndlen);
mbedtls_ecdsa_context ctx;
ecdsa_init_str(&ctx, curveid, key_d, key_x, key_y);
res = ecdsa_init_str(&ctx, curveid, key_d, key_x, key_y);
if (res)
return res;
res = mbedtls_ecdsa_write_signature(&ctx, MBEDTLS_MD_SHA256, shahash, sizeof(shahash), signature, signaturelen, fixed_rand, NULL);
mbedtls_ecdsa_free(&ctx);
@@ -323,7 +330,10 @@ static int ecdsa_signature_verify_keystr(mbedtls_ecp_group_id curveid, const cha
return res;
mbedtls_ecdsa_context ctx;
ecdsa_init_str(&ctx, curveid, NULL, key_x, key_y);
res = ecdsa_init_str(&ctx, curveid, NULL, key_x, key_y);
if (res)
return res;
res = mbedtls_ecdsa_read_signature(
&ctx,
hash ? shahash : input,
@@ -347,6 +357,9 @@ int ecdsa_signature_verify(mbedtls_ecp_group_id curveid, uint8_t *key_xy, uint8_
mbedtls_ecdsa_context ctx;
res = ecdsa_init(&ctx, curveid, NULL, key_xy);
if (res)
return res;
res = mbedtls_ecdsa_read_signature(
&ctx,
hash ? shahash : input,
+5 -3
View File
@@ -359,10 +359,11 @@ bool CheckrpIdHash(json_t *json, uint8_t *hash) {
// check ANSI X9.62 format ECDSA signature (on P-256)
static int FIDO2CheckSignature(json_t *root, uint8_t *publickey, uint8_t *sign, size_t signLen, uint8_t *authData, size_t authDataLen, bool verbose) {
int res;
uint8_t rval[300] = {0};
uint8_t sval[300] = {0};
res = ecdsa_asn1_get_signature(sign, signLen, rval, sval);
int res = ecdsa_asn1_get_signature(sign, signLen, rval, sval);
if (!res) {
if (verbose) {
PrintAndLogEx(NORMAL, " r: %s", sprint_hex(rval, 32));
@@ -383,7 +384,8 @@ static int FIDO2CheckSignature(json_t *root, uint8_t *publickey, uint8_t *sign,
authData, authDataLen, // rpIdHash[32] + flags[1] + signCount[4]
clientDataHash, 32, // Hash of the serialized client data. "$.ClientDataHash" from json
NULL, 0);
//PrintAndLogEx(NORMAL, "--xbuf(%d)[%d]: %s", res, xbuflen, sprint_hex(xbuf, xbuflen));
PrintAndLogEx(DEBUG, "--xbuf(%d)[%zu]: %s", res, xbuflen, sprint_hex(xbuf, xbuflen));
res = ecdsa_signature_verify(MBEDTLS_ECP_DP_SECP256R1, publickey, xbuf, xbuflen, sign, signLen, true);
if (res) {
if (res == MBEDTLS_ERR_ECP_VERIFY_FAILED) {
+82 -1
View File
@@ -49,6 +49,7 @@
#include "util.h"
#ifdef _WIN32
#include "scandir.h"
#include <direct.h>
#endif
#define PATH_MAX_LENGTH 200
@@ -130,7 +131,87 @@ static bool is_directory(const char *filename) {
return S_ISDIR(st.st_mode) != 0;
}
/**
* @brief create a new directory.
* @param dirname
* @return
*/
// Not used...
/*
#ifdef _WIN32
#define make_dir(a) _mkdir(a)
#else
#define make_dir(a) mkdir(a,0755) //note 0755 MUST have leading 0 for octal linux file permissions
#endif
bool create_path(const char *dirname) {
if (dirname == NULL) // nothing to do
return false;
if ((strlen(dirname) == 1) && (dirname[0] == '/'))
return true;
if ((strlen(dirname) == 2) && (dirname[1] == ':'))
return true;
if (fileExists(dirname) == 0) {
char *bs = strrchr(dirname, '\\');
char *fs = strrchr(dirname, '/');
if ((bs == NULL) && (fs != NULL)) {
*fs = 0x00;
create_path (dirname);
*fs = '/';
}
if ((bs != NULL) && (fs == NULL)) {
*bs = 0x00;
create_path (dirname);
*bs = '\\';
}
if ((bs != NULL) && (fs != NULL)) {
if (strlen (bs) > strlen (fs)) {
*fs = 0x00; // No slash
create_path (dirname);
*fs = '/';
} else {
*bs = 0x00;
create_path (dirname);
*bs = '\\';
}
}
if (make_dir(dirname) != 0) {
PrintAndLogEx(ERR, "could not create directory.... "_RED_("%s"),dirname);
return false;
}
}
return true;
}
*/
/*
bool setDefaultPath (savePaths_t pathIndex,const char *Path) {
if (pathIndex < spItemCount) {
if ((Path == NULL) && (session.defaultPaths[pathIndex] != NULL)) {
free (session.defaultPaths[pathIndex]);
session.defaultPaths[pathIndex] = NULL;
}
if (Path != NULL) {
session.defaultPaths[pathIndex] = (char *)realloc(session.defaultPaths[pathIndex], strlen(Path) + 1);
strcpy(session.defaultPaths[pathIndex], Path);
}
} else {
return false;
}
return true;
}
*/
static char *filenamemcopy(const char *preferredName, const char *suffix) {
if (preferredName == NULL) return NULL;
if (suffix == NULL) return NULL;
@@ -905,10 +986,10 @@ int loadFileJSON(const char *preferredName, void *data, size_t maxdatalen, size_
}
*datalen = sptr;
}
PrintAndLogEx(SUCCESS, "loaded from JSON file " _YELLOW_("%s"), fileName);
if (!strcmp(ctype, "settings")) {
preferences_load_callback(root);
}
PrintAndLogEx(SUCCESS, "loaded from JSON file " _YELLOW_("%s"), fileName);
out:
json_decref(root);
free(fileName);
+3
View File
@@ -74,6 +74,9 @@ typedef enum {
} DumpFileType_t;
int fileExists(const char *filename);
//bool create_path(const char *dirname);
//bool setDefaultPath (savePaths_t pathIndex,const char *Path); // set a path in the path list session.defaultPaths
/**
* @brief Utility function to save data to a binary file. This method takes a preferred name, but if that
+44 -9
View File
@@ -68,6 +68,7 @@ typedef struct {
* T (x 0 x 1 . . . . . . x 15 ) = x 0 x 1 x 5 x 7 x 10 x 11 x 14 x 15 .
**/
static bool T(State state) {
/*
bool x0 = state.t & 0x8000;
bool x1 = state.t & 0x4000;
bool x5 = state.t & 0x0400;
@@ -77,19 +78,33 @@ static bool T(State state) {
bool x14 = state.t & 0x0002;
bool x15 = state.t & 0x0001;
return x0 ^ x1 ^ x5 ^ x7 ^ x10 ^ x11 ^ x14 ^ x15;
*/
#define _x0 ((state.t & 0x8000) >> 15 )
#define _x1 ((state.t & 0x4000) >> 14 )
#define _x5 ((state.t & 0x0400) >> 10 )
#define _x7 ((state.t & 0x0100) >> 8 )
#define _x10 ((state.t & 0x0020) >> 5 )
#define _x11 ((state.t & 0x0010) >> 4 )
#define _x14 ((state.t & 0x0002) >> 1 )
#define _x15 (state.t & 0x0001)
return (_x0) ^ (_x1) ^ (_x5) ^ (_x7) ^ (_x10) ^ (_x11) ^ (_x14) ^ (_x15);
}
/**
* Similarly, the feedback function for the bottom register B : F 8/2 F 2 is defined as
* B(x 0 x 1 . . . x 7 ) = x 1 x 2 x 3 x 7 .
**/
static bool B(State state) {
/*static bool B(State state) {
bool x1 = state.b & 0x40;
bool x2 = state.b & 0x20;
bool x3 = state.b & 0x10;
bool x7 = state.b & 0x01;
return x1 ^ x2 ^ x3 ^ x7;
}
*/
#define B(x) (((x.b & 0x40) >> 6) ^ ((x.b & 0x20) >> 5) ^ ((x.b & 0x10) >> 4) ^ (x.b & 0x01))
// 12 3456
// 0100 0000
/**
* Definition 3 (Selection function). The selection function select : F 2 × F 2 ×
@@ -99,14 +114,28 @@ static bool B(State state) {
* z 2 = (r 3 r 5 ) (r 4 r 6 ) r 7 x
**/
static uint8_t _select(bool x, bool y, uint8_t r) {
bool r0 = r >> 7 & 0x1;
bool r1 = r >> 6 & 0x1;
bool r2 = r >> 5 & 0x1;
bool r3 = r >> 4 & 0x1;
bool r4 = r >> 3 & 0x1;
bool r5 = r >> 2 & 0x1;
bool r6 = r >> 1 & 0x1;
bool r7 = r & 0x1;
#define _r0 ((r >> 7) & 0x01)
#define _r1 ((r >> 6) & 0x01)
#define _r2 ((r >> 5) & 0x01)
#define _r3 ((r >> 4) & 0x01)
#define _r4 ((r >> 3) & 0x01)
#define _r5 ((r >> 2) & 0x01)
#define _r6 ((r >> 1) & 0x01)
#define _r7 (r & 0x01)
#define _z0 ( (_r0 & _r2) ^ ( _r1 & (!_r3)) ^ (_r2 | _r4) )
#define _z1 ( (_r0 | _r2) ^ ( _r5 | _r7) ^_r1 ^ _r6 ^ x ^ y )
#define _z2 ( (_r3 & (!_r5)) ^ (_r4 & _r6) ^ _r7 ^ x )
/*
uint8_t r0 = r >> 7 & 0x1;
uint8_t r1 = r >> 6 & 0x1;
uint8_t r2 = r >> 5 & 0x1;
uint8_t r3 = r >> 4 & 0x1;
uint8_t r4 = r >> 3 & 0x1;
uint8_t r5 = r >> 2 & 0x1;
uint8_t r6 = r >> 1 & 0x1;
uint8_t r7 = r & 0x1;
bool z0 = (r0 & r2) ^ (r1 & (!r3)) ^ (r2 | r4);
bool z1 = (r0 | r2) ^ (r5 | r7) ^ r1 ^ r6 ^ x ^ y;
@@ -115,6 +144,11 @@ static uint8_t _select(bool x, bool y, uint8_t r) {
// The three bitz z0.. z1 are packed into a uint8_t:
// 00000ZZZ
//Return value is a uint8_t
return ((z0 << 2) & 4) | ((z1 << 1) & 2) | (z2 & 1);
*/
return ((_z0 << 2) & 4) | ((_z1 << 1) & 2) | (_z2 & 1);
/*
uint8_t retval = 0;
retval |= (z0 << 2) & 4;
retval |= (z1 << 1) & 2;
@@ -122,6 +156,7 @@ static uint8_t _select(bool x, bool y, uint8_t r) {
// Return value 0 <= retval <= 7
return retval;
*/
}
/**
+4
View File
@@ -281,6 +281,10 @@ 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) {
int kbs = key_block_size(key);
if (kbs == 0) {
return;
}
uint8_t *buffer = malloc(padded_data_length(len, kbs));
memcpy(buffer, data, len);
+457 -106
View File
File diff suppressed because it is too large Load Diff
+1
View File
@@ -9,6 +9,7 @@
#define PREFERENCES_H_
#include "fileutils.h"
#include <errno.h>
// Current working directory will be prepended.
#define preferencesFilename "preferences.json"

Some files were not shown because too many files have changed in this diff Show More