Merge branch 'master' into mfdes-chk-keylogic

This commit is contained in:
Chloé Franke committed 2026-08-19 13:40:11 +02:00
commit 4b51fea936
149 files changed
+126456 -129

No files matched your search

+2 -2
View File
@@ -2902,8 +2902,8 @@ static int CmdDiff(const char *Cmd) {
CLIParserFree(ctx);
// sanity check
if (IfPm3Rdv4Fw() == false && (splenA > 0 || splenB > 0)) {
PrintAndLogEx(WARNING, "No RDV4 Flashmemory available");
if (IfPm3Flash() == false && (splenA > 0 || splenB > 0)) {
PrintAndLogEx(WARNING, "No Flashmemory available");
return PM3_EINVARG;
}
+202
View File
@@ -0,0 +1,202 @@
#include "fileutils.h"
#include "cmdparser.h" // command_t
#include "cliparser.h"
#include "comms.h"
#include "cmdfpga.h"
#include "ui.h"
static int CmdHelp(const char *Cmd);
static int CmdConfigFpga(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "hw fpga config ",
"Read the bin file and write it to the fpga [sram|flash]",
"hw fpga config -s -f myfile -> config fpga sram by bin file\n"
"hw fpga config -f myfile -> config fpga flash by bin file\n"
);
void *argtable[] = {
arg_param_begin,
arg_lit0("s", "sram", "config to sram, or config to flash"),
arg_str0("f", "file", "<fn>", "save to file, not suffix include"),
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, false);
// config to sram or flash by -s option
bool sram_mode = arg_get_lit(ctx, 1);
// check for -file option first to determine the output mode
int fnlen = 0;
char filename[FILE_PATH_SIZE] = {0};
CLIParamStrToBuf(arg_get_str(ctx, 2), (uint8_t *)filename, FILE_PATH_SIZE, &fnlen);
CLIParserFree(ctx);
if ((! sram_mode) && (! IfFpgaFlash())) {
PrintAndLogEx(WARNING, "This device does not support FPGA flash configuration");
return PM3_ENOTIMPL;
}
// Check if file name is provided
if (fnlen == 0) {
PrintAndLogEx(WARNING, "No file specified");
return PM3_EINVARG;
}
// Load the file content into data buffer
uint8_t *data = NULL;
size_t datalen = 0;
int res = loadFile_safe(filename, ".bin", (void **)&data, &datalen);
if (res != PM3_SUCCESS) {
free(data);
return PM3_EFILE;
}
// TODO DXL Maybe length check for device model is required.
// coming soon
// TODO DXL check response result is required
struct {
uint8_t sram_mode;
uint32_t file_length;
} PACKED params;
params.sram_mode = sram_mode;
params.file_length = datalen;
PacketResponseNG resp;
PrintAndLogEx(INFO, "Starting FPGA configuration in " _YELLOW_("%s"), sram_mode ? "SRAM" : "Flash");
// Start fpga config by mode
SendCommandNG(CMD_FPGA_BITSTREAM_CONFIG_START, (uint8_t *)&params, sizeof(params));
// Wait for response before sending data
if (WaitForResponseTimeout(CMD_FPGA_BITSTREAM_CONFIG_START, &resp, 15000) == false) {
PrintAndLogEx(WARNING, "start config for fpga timeout while waiting for reply");
free(data);
return PM3_ETIMEOUT;
}
if (resp.status == PM3_ENOTIMPL) {
PrintAndLogEx(ERR, "Feature not implemented");
free(data);
return resp.status;
}
if (resp.status != PM3_SUCCESS) {
PrintAndLogEx(ERR, "Failed to start FPGA configuration: %d", resp.status);
free(data);
return resp.status;
}
// Start to send data in chunks
size_t offset = 0;
while (offset < datalen) {
size_t chunk_size = (datalen - offset) > PM3_CMD_DATA_SIZE ? PM3_CMD_DATA_SIZE : (datalen - offset);
SendCommandNG(CMD_FPGA_BITSTREAM_CONFIG_WRITE, data + offset, chunk_size);
// Wait for response before sending next chunk
if (WaitForResponseTimeout(CMD_FPGA_BITSTREAM_CONFIG_WRITE, &resp, 5000) == false) {
PrintAndLogEx(WARNING, "transfer data for fpga timeout while waiting for reply");
free(data);
return PM3_ETIMEOUT;
}
if (resp.status != PM3_SUCCESS) {
PrintAndLogEx(ERR, "Failed to transfer FPGA configuration data: %d", resp.status);
free(data);
return resp.status;
}
offset += chunk_size;
// Print progress
PrintAndLogEx(INFO, "Sent "_YELLOW_("%zu")" bytes, progress: "_YELLOW_("%.2f%%"), chunk_size, (offset / (float)datalen) * 100);
}
PrintAndLogEx(SUCCESS, "FPGA configuration transfer complete!");
// Stop fpga config
SendCommandNG(CMD_FPGA_BITSTREAM_CONFIG_FINISH, NULL, 0);
if (WaitForResponseTimeout(CMD_FPGA_BITSTREAM_CONFIG_FINISH, &resp, 5000) == false) {
PrintAndLogEx(WARNING, "stop config for fpga timeout while waiting for reply");
free(data);
return PM3_ETIMEOUT;
}
if (resp.status != PM3_SUCCESS) {
PrintAndLogEx(ERR, "Failed to finish FPGA configuration: %d", resp.status);
free(data);
return resp.status;
}
PrintAndLogEx(SUCCESS, "FPGA configuration successfully!");
free(data);
return PM3_SUCCESS;
}
static int CmdFpgaSetPowerPWM(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "hw fpga pwrpwm ",
"Set the proportion of low levels of PWM output from FPGA for controlling driver voltage.",
"hw fpga pwrpwm -c 1000 -> Set pwm low-level count to 1000 for HF driver power.\n"
"hw fpga pwrpwm -c 1000 -l -> Set pwm low-level count to 1000 for LF driver power.\n");
void *argtable[] = {
arg_param_begin,
arg_lit0("l", "lf", "Set the driver voltage for LF. When not specified as LF, default setting for HF."),
arg_int0("c", "count", "<int>", "PWM output low level counting used to control the voltage of the driver. "
"The larger the value, the higher the voltage; "
"the smaller the value, the lower the voltage."),
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, false);
// Is setting for lf?
bool is_lf = arg_get_lit(ctx, 1);
// the count of low levels of pwm output
int count = arg_get_int_def(ctx, 2, 1000);
CLIParserFree(ctx);
// TODO DXL check response result is required
if (count < 0 || count > 4095) {
PrintAndLogEx(ERR, "Invalid count value: %d. It should be between 0 and 4095.", count);
return PM3_EINVARG;
}
struct {
uint8_t is_lf;
uint16_t count;
} PACKED params = {
.is_lf = is_lf,
.count = count,
};
// Start fpga config by mode
PacketResponseNG resp;
SendCommandNG(CMD_FPGA_CMD_SET_PWR_PWM_LOW_COUNT, (uint8_t *)&params, sizeof(params));
PrintAndLogEx(INFO, "PWM value: " _YELLOW_("%d") ", for %s", count, is_lf ? "LF driver" : "HF driver");
// Wait for response before sending data
if (WaitForResponseTimeout(CMD_FPGA_CMD_SET_PWR_PWM_LOW_COUNT, &resp, 15000) == false) {
PrintAndLogEx(WARNING, "set power pwm for fpga timeout while waiting for reply");
return PM3_ETIMEOUT;
}
PrintAndLogEx(SUCCESS, "Set PWM to FPGA for driver power control complete!");
return PM3_SUCCESS;
}
static command_t CommandTable[] = {
{"help", CmdHelp, AlwaysAvailable, "This help"},
{"-------------", CmdHelp, AlwaysAvailable, "----------------------- " _CYAN_("Operation") " -----------------------"},
{"config", CmdConfigFpga, IfPm3Present, "Configure FPGA for sram or flash"},
{"pwrpwm", CmdFpgaSetPowerPWM, IfPm5, "Adjust the input voltage of the driver through FPGA."},
{NULL, NULL, NULL, NULL}
};
static int CmdHelp(const char *Cmd) {
(void)Cmd; // Cmd is not used so far
CmdsHelp(CommandTable);
return PM3_SUCCESS;
}
int CmdFPGA(const char *Cmd) {
clearCommandBuffer();
return CmdsParse(CommandTable, Cmd);
}
+6
View File
@@ -0,0 +1,6 @@
#ifndef CMD_FPGA_H
#define CMD_FPGA_H
int CmdFPGA(const char *Cmd);
#endif // CMD_FPGA_H
+8 -2
View File
@@ -373,12 +373,18 @@ int CmdHFTune(const char *Cmd) {
break;
}
if ((resp.status == PM3_EOPABORTED) || (resp.length != sizeof(uint16_t))) {
if ((resp.status == PM3_EOPABORTED) || (resp.length != sizeof(uint16_t) && resp.length != sizeof(uint32_t))) {
PrintAndLogEx(NORMAL, "");
break;
}
uint16_t volt = resp.data.asDwords[0] & 0xFFFF;
uint32_t volt;
if (resp.length == sizeof(uint16_t)) {
volt = resp.data.asDwords[0] & 0xFFFF;
} else {
volt = resp.data.asDwords[0]; // U32. It can exceed 65.535V.
}
if (first) {
v_max = volt;
v_min = volt;
+181 -13
View File
@@ -3309,6 +3309,79 @@ static int CmdHF15Restore(const char *Cmd) {
return PM3_SUCCESS;
}
// ISO15693 magic "V3" tag support
#define ISO15_MAGIC_V3_BLK_UID_LO 0x10
#define ISO15_MAGIC_V3_BLK_UID_HI 0x11
#define ISO15_MAGIC_V3_BLK_SIG_A 0x14
#define ISO15_MAGIC_V3_BLK_SIG_B 0x15
// signature check in block 0x14/0x15
static const uint8_t iso15_magic_v3_sig_a[4] = {0xA5, 0x2B, 0x44, 0x2C};
static const uint8_t iso15_magic_v3_sig_b[4] = {0x21, 0xAE, 0x93, 0x00};
// finalize command write in block 0x14/0x15
// hf 15 raw -wac -d 022114A52B442C
// hf 15 raw -wac -d 02211569E25D00
static const uint8_t iso15_magic_v3_fin_a[4] = {0xA5, 0x2B, 0x44, 0x2C};
static const uint8_t iso15_magic_v3_fin_b[4] = {0x69, 0xE2, 0x5D, 0x00};
// Read one 4-byte block from a magic V3 tag in unaddressed mode.
static int hf15_magic_v3_read_blk(uint8_t blockno, uint8_t out[4]) {
uint16_t approxlen = 2 + 1 + 2;
iso15_raw_cmd_t *packet = (iso15_raw_cmd_t *)calloc(1, sizeof(iso15_raw_cmd_t) + approxlen);
if (packet == NULL) {
PrintAndLogEx(WARNING, "Failed to allocate memory");
return PM3_EMALLOC;
}
// enforce OPTION flag so we get the lock byte, keeping data at offset 2
packet->raw[packet->rawlen++] = arg_get_raw_flag(0, true, false, true);
packet->raw[packet->rawlen++] = ISO15693_READBLOCK;
packet->raw[packet->rawlen++] = blockno;
AddCrc15(packet->raw, packet->rawlen);
packet->rawlen += 2;
packet->flags = (ISO15_CONNECT | ISO15_READ_RESPONSE);
clearCommandBuffer();
SendCommandNG(CMD_HF_ISO15693_COMMAND, (uint8_t *)packet, ISO15_RAW_LEN(packet->rawlen));
free(packet);
PacketResponseNG resp;
if (WaitForResponseTimeout(CMD_HF_ISO15693_COMMAND, &resp, 2000) == false) {
PrintAndLogEx(DEBUG, "iso15693 timeout");
return PM3_ETIMEOUT;
}
ISO15_ERROR_HANDLING_RESPONSE
uint8_t *d = resp.data.asBytes;
ISO15_ERROR_HANDLING_CARD_RESPONSE(d, resp.length)
memcpy(out, d + 2, 4);
return PM3_SUCCESS;
}
// Write one 4-byte block to a magic V3 tag in unaddressed mode.
static int hf15_magic_v3_write_blk(uint8_t blockno, const uint8_t *data) {
uint16_t flags = arg_get_raw_flag(0, true, false, false);
return hf_15_write_blk(NULL, flags, NULL, true, blockno, data, 4);
}
// Detect an un-finalized magic V3 tag by its configuration-mode signature.
static bool hf15_magic_v3_is_config_mode(void) {
uint8_t a[4] = {0};
uint8_t b[4] = {0};
if (hf15_magic_v3_read_blk(ISO15_MAGIC_V3_BLK_SIG_A, a) != PM3_SUCCESS) {
return false;
}
if (hf15_magic_v3_read_blk(ISO15_MAGIC_V3_BLK_SIG_B, b) != PM3_SUCCESS) {
return false;
}
return (memcmp(a, iso15_magic_v3_sig_a, 4) == 0) && (memcmp(b, iso15_magic_v3_sig_b, 4) == 0);
}
/**
* Commandline handling: HF15 CMD CSETUID
* Set UID for magic Chinese card
@@ -3317,15 +3390,19 @@ static int CmdHF15CSetUID(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "hf 15 csetuid",
"Set UID for magic Chinese card (only works with such cards)\n",
"Set UID for magic Chinese card (only works with such cards)\n"
"For magic 'V3' tags this writes the UID configuration only and is repeatable;\n"
"run `" _YELLOW_("hf 15 cfinalize") "` afterwards to lock the UID permanently.",
"hf 15 csetuid -u E011223344556677 -> use gen1 command\n"
"hf 15 csetuid -u E011223344556677 --v2 -> use gen2 command"
"hf 15 csetuid -u E011223344556677 --v2 -> use gen2 command\n"
"hf 15 csetuid -u E011223344556677 --v3 -> use gen3 (V3) magic tag"
);
void *argtable[] = {
arg_param_begin,
arg_str1("u", "uid", "<hex>", "UID, 8 hex bytes"),
arg_lit0("2", "v2", "Use gen2 magic command"),
arg_lit0("3", "v3", "Use gen3 (V3) magic tag (repeatable, needs cfinalize)"),
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, false);
@@ -3337,8 +3414,14 @@ static int CmdHF15CSetUID(const char *Cmd) {
int uidlen = 0;
CLIGetHexWithReturn(ctx, 1, payload.uid, &uidlen);
bool use_v2 = arg_get_lit(ctx, 2);
bool use_v3 = arg_get_lit(ctx, 3);
CLIParserFree(ctx);
if (use_v2 && use_v3) {
PrintAndLogEx(WARNING, "Select only one of " _YELLOW_("--v2") " / " _YELLOW_("--v3"));
return PM3_EINVARG;
}
if (uidlen != ISO15693_UID_LENGTH) {
PrintAndLogEx(WARNING, "UID must include 8 hex bytes, got " _RED_("%i"), uidlen);
return PM3_EINVARG;
@@ -3360,19 +3443,40 @@ static int CmdHF15CSetUID(const char *Cmd) {
}
PrintAndLogEx(INFO, "Writing...");
PacketResponseNG resp;
clearCommandBuffer();
uint16_t cmd = CMD_HF_ISO15693_CSETUID;
if (use_v2) {
cmd = CMD_HF_ISO15693_CSETUID_V2;
}
if (use_v3) {
/*
for example id: E011223344556677
[=] 16 | 77 66 55 44 | 0 | wfUD
[=] 17 | 33 22 11 E0 | 0 | 3"..
*/
uint8_t blk_lo[4] = {0};
uint8_t blk_hi[4] = {0};
reverse_array_copy(payload.uid + 4, 4, blk_lo);
reverse_array_copy(payload.uid, 4, blk_hi);
SendCommandNG(cmd, (uint8_t *)&payload, sizeof(payload));
if (WaitForResponseTimeout(cmd, &resp, 2000) == false) {
PrintAndLogEx(WARNING, "timeout while waiting for reply");
DropField();
return PM3_ESOFT;
if (hf15_magic_v3_write_blk(ISO15_MAGIC_V3_BLK_UID_LO, blk_lo) != PM3_SUCCESS ||
hf15_magic_v3_write_blk(ISO15_MAGIC_V3_BLK_UID_HI, blk_hi) != PM3_SUCCESS) {
PrintAndLogEx(FAILED, "Setting new UID ( " _RED_("fail") " )");
PrintAndLogEx(NORMAL, "");
return PM3_ESOFT;
}
} else {
PacketResponseNG resp;
clearCommandBuffer();
uint16_t cmd = CMD_HF_ISO15693_CSETUID;
if (use_v2) {
cmd = CMD_HF_ISO15693_CSETUID_V2;
}
SendCommandNG(cmd, (uint8_t *)&payload, sizeof(payload));
if (WaitForResponseTimeout(cmd, &resp, 2000) == false) {
PrintAndLogEx(WARNING, "timeout while waiting for reply");
DropField();
return PM3_ESOFT;
}
}
PrintAndLogEx(INFO, "Verifying...");
@@ -3397,6 +3501,69 @@ static int CmdHF15CSetUID(const char *Cmd) {
return PM3_ESOFT;
}
/**
* Commandline handling: HF15 CMD CFINALIZE
* Finalize a magic 'V3' tag - irreversible
*/
static int CmdHF15CFinalize(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "hf 15 cfinalize",
"Finalize a magic ISO15693 'V3' tag.\n"
_RED_("This operation is irreversible.") " After finalize the configuration\n"
"area is erased and the UID can no longer be changed. Set the UID with\n"
"`" _YELLOW_("hf 15 csetuid --v3") "` first, then lock it in with this command.",
"hf 15 cfinalize -y"
);
void *argtable[] = {
arg_param_begin,
arg_lit0("y", "yes", "Confirm the irreversible finalize operation"),
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, true);
bool confirmed = arg_get_lit(ctx, 1);
CLIParserFree(ctx);
PrintAndLogEx(INFO, "Get current tag");
uint8_t carduid[ISO15693_UID_LENGTH] = {0x00};
if (getUID(true, false, carduid) != PM3_SUCCESS) {
PrintAndLogEx(FAILED, "no tag found");
return PM3_ESOFT;
}
// Safety: only proceed on a tag that is actually an un-finalized magic V3.
// Writing the finalize values to any other tag may permanently brick it.
if (hf15_magic_v3_is_config_mode() == false) {
PrintAndLogEx(FAILED, "tag is not an un-finalized magic " _YELLOW_("V3") " tag");
PrintAndLogEx(HINT, "Hint: signature in blocks 0x14/0x15 not found - already finalized or not a V3 tag");
return PM3_ESOFT;
}
PrintAndLogEx(SUCCESS, "Magic " _GREEN_("V3") " tag in configuration mode ( " _GREEN_("ok") " )");
if (confirmed == false) {
PrintAndLogEx(WARNING, _RED_("This operation is irreversible!") " The UID will be locked permanently.");
PrintAndLogEx(WARNING, "Add " _YELLOW_("-y") " to confirm and proceed.");
return PM3_EINVARG;
}
PrintAndLogEx(INFO, "Finalizing...");
if (hf15_magic_v3_write_blk(ISO15_MAGIC_V3_BLK_SIG_A, iso15_magic_v3_fin_a) != PM3_SUCCESS ||
hf15_magic_v3_write_blk(ISO15_MAGIC_V3_BLK_SIG_B, iso15_magic_v3_fin_b) != PM3_SUCCESS) {
PrintAndLogEx(FAILED, "Finalize ( " _RED_("fail") " )");
PrintAndLogEx(NORMAL, "");
return PM3_ESOFT;
}
PrintAndLogEx(SUCCESS, "Finalize ( " _GREEN_("ok") " )");
PrintAndLogEx(HINT, "Hint: UID is now locked; the tag behaves like a normal ISO15693 tag");
PrintAndLogEx(NORMAL, "");
return PM3_SUCCESS;
}
static int CmdHF15SlixEASEnable(const char *Cmd) {
CLIParserContext *ctx;
@@ -4146,6 +4313,7 @@ static command_t CommandTable[] = {
{"writedsfid", CmdHF15WriteDsfid, IfPm3Iso15693, "Writes the DSFID on an ISO-15693 tag"},
{"-----------", CmdHF15Help, IfPm3Iso15693, "------------------------- " _CYAN_("Magic") " -----------------------"},
{"csetuid", CmdHF15CSetUID, IfPm3Iso15693, "Set UID for magic card"},
{"cfinalize", CmdHF15CFinalize, IfPm3Iso15693, "Finalize a magic V3 tag (irreversible)"},
{NULL, NULL, NULL, NULL}
};
+115 -4
View File
@@ -21,6 +21,7 @@
#include <string.h>
#include <ctype.h>
#include <inttypes.h>
#include <time.h>
#include "cmdparser.h" // command_t
#include "comms.h"
#include "cmdtrace.h"
@@ -82,6 +83,7 @@
#define FELICA_POLLING_REQUEST_SYSTEM_CODE 0x01U
#define FELICA_SYSTEM_LIST_JSON "felica/felica_system_code_list"
#define FELICA_IC_CODE_LIST_JSON "felica/felica_ic_code_list"
#define FELICA_CONTAINER_ISSUE_LIST_JSON "felica/felica_container_issue_information_list"
#define FELICA_REQUEST_SERVICE_DISCOVERY_BATCH_SIZE 32U
#define FELICA_MAX_NODE_NUMBER 0x03FFU
@@ -457,6 +459,8 @@ static json_t *felica_system_list = NULL;
static bool felica_system_list_loaded = false;
static json_t *felica_ic_code_list = NULL;
static bool felica_ic_code_list_loaded = false;
static json_t *felica_container_issue_list = NULL;
static bool felica_container_issue_list_loaded = false;
static void set_last_known_card(felica_card_select_t card) {
last_known_card = card;
@@ -771,6 +775,100 @@ static json_t *felica_get_ic_code_list(void) {
return felica_ic_code_list;
}
static json_t *felica_get_container_issue_list(void) {
if (felica_container_issue_list_loaded) {
return felica_container_issue_list;
}
felica_container_issue_list_loaded = true;
char *path = NULL;
if (searchFile(&path, RESOURCES_SUBDIR, FELICA_CONTAINER_ISSUE_LIST_JSON, ".json", true) != PM3_SUCCESS) {
return NULL;
}
json_error_t error;
json_t *root = json_load_file(path, 0, &error);
if (root == NULL) {
PrintAndLogEx(WARNING, "Failed to parse `%s` line %d: %s", path, error.line, error.text);
free(path);
return NULL;
}
if (json_is_array(root) == false) {
PrintAndLogEx(WARNING, "Invalid `%s` format, expected array root", path);
json_decref(root);
free(path);
return NULL;
}
felica_container_issue_list = root;
free(path);
return felica_container_issue_list;
}
static bool felica_container_issue_matches(const felica_get_container_issue_info_response_t *response,
const json_t *entry) {
if (response == NULL || json_is_object(entry) == false) {
return false;
}
const char *format_hex = felica_get_json_string(entry, "format_version_carrier_info");
const char *model = felica_get_json_string(entry, "mobile_phone_model_info");
if (format_hex == NULL || model == NULL ||
strlen(format_hex) != (sizeof(response->format_version_carrier_information) * 2U)) {
return false;
}
uint8_t expected_format[sizeof(response->format_version_carrier_information)] = {0};
size_t expected_format_len = 0;
if (hexstr_to_byte_array(format_hex, expected_format, &expected_format_len) == false ||
expected_format_len != sizeof(expected_format) ||
memcmp(response->format_version_carrier_information, expected_format, sizeof(expected_format)) != 0) {
return false;
}
const size_t model_len = strlen(model);
if (model_len == 0 || model_len > sizeof(response->mobile_phone_model_information) ||
memcmp(response->mobile_phone_model_information, model, model_len) != 0) {
return false;
}
for (size_t i = model_len; i < sizeof(response->mobile_phone_model_information); i++) {
if (response->mobile_phone_model_information[i] != 0x00) {
return false;
}
}
return true;
}
static void felica_print_container_issue_annotations(const felica_get_container_issue_info_response_t *response) {
json_t *list = felica_get_container_issue_list();
if (response == NULL || list == NULL) {
return;
}
size_t index = 0;
json_t *entry = NULL;
json_array_foreach(list, index, entry) {
if (felica_container_issue_matches(response, entry) == false) {
continue;
}
const char *name = felica_get_json_string(entry, "name");
if (name == NULL) {
continue;
}
const char *carrier = felica_get_json_string(entry, "carrier");
PrintAndLogEx(INFO, " Device Model.......... " _GREEN_("%s"), name);
if (carrier) {
PrintAndLogEx(INFO, " Carrier............... " _GREEN_("%s"), carrier);
}
}
}
static const json_t *felica_find_ic_annotation(uint8_t rom_type, uint8_t ic_type) {
json_t *ic_code_list = felica_get_ic_code_list();
if (ic_code_list == NULL) {
@@ -2397,6 +2495,18 @@ static int info_felica(bool verbose) {
PrintAndLogEx(INFO, " Code......... " _GREEN_("%s"), sprint_hex_inrow(card.code, sizeof(card.code)));
}
PrintAndLogEx(INFO, " NFCID2....... " _GREEN_("%s"), sprint_hex_inrow(card.uid, sizeof(card.uid)));
const int16_t days_since_2000 = (int16_t)(((uint16_t)card.IDm[5] << 8) | card.IDm[4]);
const time_t felica_epoch = (time_t)946684800; // 2000-01-01 UTC
const time_t now = time(NULL);
if (days_since_2000 >= 0 && now != (time_t)-1 && now >= felica_epoch &&
(time_t)days_since_2000 <= (now - felica_epoch) / 86400) {
const time_t manufacturing_time = felica_epoch + ((time_t)days_since_2000 * 86400);
const struct tm *date = gmtime(&manufacturing_time);
char date_string[11] = {0};
if (date != NULL && strftime(date_string, sizeof(date_string), "%Y-%m-%d", date) != 0) {
PrintAndLogEx(INFO, " Mfg date..... " _GREEN_("%s"), date_string);
}
}
PrintAndLogEx(INFO, "PMM............ " _YELLOW_("%s"), sprint_hex_inrow(card.PMm, sizeof(card.PMm)));
PrintAndLogEx(INFO, " IC code...... " _GREEN_("%s") " ( %s )",
sprint_hex_inrow(card.iccode, sizeof(card.iccode)),
@@ -2469,18 +2579,19 @@ static int info_felica(bool verbose) {
sizeof(container_issue_info_response.mobile_phone_model_information),
model_ascii,
sizeof(model_ascii)
);
);
PrintAndLogEx(INFO, "Container issue info:");
PrintAndLogEx(INFO, " Format/Carrier... " _YELLOW_("%s"),
PrintAndLogEx(INFO, " Format/Carrier info... " _YELLOW_("%s"),
sprint_hex_inrow(container_issue_info_response.format_version_carrier_information,
sizeof(container_issue_info_response.format_version_carrier_information)));
if (model_is_ascii) {
PrintAndLogEx(INFO, " Model............ " _GREEN_("%s") " (ASCII)", model_ascii);
PrintAndLogEx(INFO, " Model info............ " _GREEN_("%s") " (ASCII)", model_ascii);
} else {
PrintAndLogEx(INFO, " Model............ " _YELLOW_("%s") " (HEX)",
PrintAndLogEx(INFO, " Model info............ " _YELLOW_("%s") " (HEX)",
sprint_hex_inrow(container_issue_info_response.mobile_phone_model_information,
sizeof(container_issue_info_response.mobile_phone_model_information)));
}
felica_print_container_issue_annotations(&container_issue_info_response);
}
const uint16_t container_properties[] = {0x0000, 0x0001};
+24 -4
View File
@@ -1937,8 +1937,12 @@ static int CmdHFiClassELoad(const char *Cmd) {
}
if (verbose) {
print_picopass_header((picopass_hdr_t *) dump);
print_picopass_info((picopass_hdr_t *) dump);
if (bytes_read < sizeof(picopass_hdr_t)) {
PrintAndLogEx(FAILED, "Error, dump file is too small to be a valid iCLASS dump - bytes: %zu, expected at least: %zu", bytes_read, sizeof(picopass_hdr_t));
} else {
print_picopass_header((picopass_hdr_t *) dump);
print_picopass_info((picopass_hdr_t *) dump);
}
}
PrintAndLogEx(NORMAL, "");
@@ -2059,8 +2063,12 @@ static int CmdHFiClassEView(const char *Cmd) {
}
if (verbose) {
print_picopass_header((picopass_hdr_t *) dump);
print_picopass_info((picopass_hdr_t *) dump);
if (bytes < sizeof(picopass_hdr_t)) {
PrintAndLogEx(FAILED, "Error, only %u bytes downloaded, too small to be a valid iCLASS dump - expected at least: %zu", bytes, sizeof(picopass_hdr_t));
} else {
print_picopass_header((picopass_hdr_t *) dump);
print_picopass_info((picopass_hdr_t *) dump);
}
}
PrintAndLogEx(NORMAL, "");
@@ -2326,6 +2334,18 @@ static int CmdHFiClassDecrypt(const char *Cmd) {
return res;
}
// Below (and in iclass_decode_credentials()) we unconditionally probe
// fixed offsets up through block 9 -- app_issuer_area (block 5), the
// aa1_encryption flag and block 7 in iclass_decode_credentials(), and
// the block 9 PACS/PIN check here -- regardless of what applimit or
// decryptedlen/8 say the "real" block count is. All 10 blocks (0-9)
// must actually be present in the loaded file before any of that runs.
if (decryptedlen < 10 * PICOPASS_BLOCK_SIZE) {
PrintAndLogEx(FAILED, "Error, dump file is too small - bytes: %zu, expected at least: %d", decryptedlen, 10 * PICOPASS_BLOCK_SIZE);
free(decrypted);
return PM3_EFILE;
}
have_file = true;
}
+5 -2
View File
@@ -1085,9 +1085,12 @@ static int mfc_read_tag(iso14a_card_select_t *card, uint8_t *carddata, uint8_t n
uint8_t *data = resp.data.asBytes;
if (mfIsSectorTrailerBasedOnBlocks(sectorNo, blockNo)) {
// sector trailer. Fill in the keys.
// sector trailer. Key A is never readable; preserve Key B when ACL allows it.
memcpy(data, keyA + (sectorNo * MIFARE_KEY_SIZE), MIFARE_KEY_SIZE);
memcpy(data + 10, keyB + (sectorNo * MIFARE_KEY_SIZE), MIFARE_KEY_SIZE);
uint8_t trailer_acl = mf_get_accesscondition(3, &data[6]);
if (trailer_acl != 0 && trailer_acl != 1 && trailer_acl != 2) {
memcpy(data + 10, keyB + (sectorNo * MIFARE_KEY_SIZE), MIFARE_KEY_SIZE);
}
}
memcpy(carddata + (MFBLOCK_SIZE * (mfFirstBlockOfSector(sectorNo) + blockNo)), data, MFBLOCK_SIZE);
+21 -3
View File
@@ -639,7 +639,7 @@ static int CmdDesGetSessionParameters(CLIParserContext *ctx, DesfireContext_t *d
return PM3_SUCCESS;
}
static int DesfirePCRun(DesfireContext_t *dctx, const uint8_t proximity_key[MFDES_PC_KEY_LEN], uint8_t rounds, bool verbose) {
static int DesfirePCRun(DesfireContext_t *dctx, const uint8_t proximity_key[MFDES_PC_KEY_LEN], uint8_t rounds, bool activate_field, bool verbose) {
if (dctx == NULL || proximity_key == NULL || rounds < 1 || rounds > MFDES_PC_MAX_ROUNDS) {
return PM3_EINVARG;
}
@@ -655,7 +655,7 @@ static int DesfirePCRun(DesfireContext_t *dctx, const uint8_t proximity_key[MFDE
uint8_t prepare_resp[APDU_RES_LEN] = {0};
size_t prepare_resp_len = 0;
uint8_t respcode = 0xFF;
res = DesfireExchangeEx(true, dctx, MFDES_PREPARE_PC, NULL, 0, &respcode, prepare_resp, &prepare_resp_len, true, 0);
res = DesfireExchangeEx(activate_field, dctx, MFDES_PREPARE_PC, NULL, 0, &respcode, prepare_resp, &prepare_resp_len, true, 0);
if (res != PM3_SUCCESS) {
uint16_t sw = status(respcode);
PrintAndLogEx(ERR, "Prepare proximity check command failed. Result: %d %s", res, DesfireGetErrorString(res, &sw));
@@ -4571,6 +4571,7 @@ static int CmdHF14ADesPC(const char *Cmd) {
"This command uses plain communication with a dedicated 16-byte AES proximity key.",
"hf mfdes pc --key 00000000000000000000000000000000\n"
"hf mfdes pc --key 00112233445566778899aabbccddeeff --rounds 4\n"
"hf mfdes pc --aid 123456 --key 00112233445566778899aabbccddeeff\n"
"hf mfdes pc --key 00112233445566778899aabbccddeeff -c native -a");
void *argtable[] = {
@@ -4580,6 +4581,7 @@ static int CmdHF14ADesPC(const char *Cmd) {
arg_str1("k", "key", "<hex>", "Key (AES-128, exactly 16 bytes)"),
arg_int0("r", "rounds", "<dec>", "Number of rounds (1..8), default 8"),
arg_str0("c", "ccset", "<native|niso>", "Communication command set (default from `hf mfdes default`)"),
arg_str0(NULL, "aid", "<hex>", "Application ID (3 hex bytes, big endian)"),
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, true);
@@ -4615,6 +4617,13 @@ static int CmdHF14ADesPC(const char *Cmd) {
return PM3_EINVARG;
}
uint32_t appid = 0;
bool appid_present = false;
if (CLIGetUint32Hex(ctx, 6, 0, &appid, &appid_present, 3, "AID must have 3 bytes length")) {
CLIParserFree(ctx);
return PM3_EINVARG;
}
SetAPDULogging(APDULogging);
CLIParserFree(ctx);
@@ -4623,7 +4632,16 @@ static int CmdHF14ADesPC(const char *Cmd) {
DesfireSetCommMode(&dctx, DCMPlain);
DesfireSetSecureChannel(&dctx, DACNone);
int res = DesfirePCRun(&dctx, proximity_key, rounds, verbose);
int res = PM3_SUCCESS;
if (appid_present) {
res = DesfireSelectAndAuthenticateAppW(&dctx, DACNone, ISW6bAID, appid, true, verbose);
if (res != PM3_SUCCESS) {
DropField();
return res;
}
}
res = DesfirePCRun(&dctx, proximity_key, rounds, !appid_present, verbose);
DropField();
return res;
}
+225
View File
@@ -36,6 +36,7 @@
#include "ui.h"
#include "fpga.h"
#include "cmdhw.h"
#include "cmdfpga.h"
#include "cmddata.h"
#include "commonutil.h"
#include "preferences.h"
@@ -1701,6 +1702,215 @@ int set_fpga_mode(uint8_t mode) {
return resp.status;
}
static int CmdPM5Ant(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "hw ant_pm5",
"Control the antennal of pm5",
"hw ant_pm5 --set <u8_data> -> Write the data of IO data register\n"
"hw ant_pm5 -m --set <u8_data> -> Write the data of IO map register\n"
);
void *argtable[] = {
arg_param_begin,
arg_lit0("m", "map", "Write the IO map register"),
arg_u64_0("s", "set", "<u8_data>", "Set PM5 antenna"),
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, true);
bool rw_map = arg_get_lit(ctx, 1);
uint64_t io = arg_get_u64_def(ctx, 2, -1);
CLIParserFree(ctx);
PacketResponseNG resp;
// Read the current value of the register before writing
struct {
uint8_t reg_type; // 0 is io reg, 1 is map reg.
} PACKED payload_read = {
.reg_type = rw_map ? 1 : 0,
};
clearCommandBuffer();
SendCommandNG(CMD_ANT_CONTROL_READ, (uint8_t*)&payload_read, sizeof(payload_read));
if (WaitForResponseTimeout(CMD_ANT_CONTROL_READ, &resp, 1000) == false) {
PrintAndLogEx(WARNING, "command execution time out");
return PM3_ETIMEOUT;
}
if (resp.status != PM3_SUCCESS) {
PrintAndLogEx(ERR, "failed to read PM5 antenna register");
return resp.status;
}
PrintAndLogEx(INFO, "PM5 antenna register read: 0x%02X", resp.data.asBytes[0]);
// Write the new value to the register(If need)
if (io != (uint64_t)-1) {
struct {
uint8_t data;
uint8_t reg_type; // 0 is io reg, 1 is map reg.
} PACKED payload_write = {
.reg_type = rw_map ? 1 : 0,
.data = io & 0xFF,
};
clearCommandBuffer();
SendCommandNG(CMD_ANT_CONTROL_WRITE, (uint8_t*)&payload_write, sizeof(payload_write));
if (WaitForResponseTimeout(CMD_ANT_CONTROL_WRITE, &resp, 1000) == false) {
PrintAndLogEx(WARNING, "command execution time out");
return PM3_ETIMEOUT;
}
if (resp.status != PM3_SUCCESS) {
PrintAndLogEx(ERR, "failed to write PM5 antenna register");
return resp.status;
}
PrintAndLogEx(INFO, "PM5 antenna register written: 0x%02X", payload_write.data);
}
return PM3_SUCCESS;
}
static int CmdDeviceFactoryData(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "hw factorydata",
"Get/Set the factory data for Device",
"hw factorydata --load <file> -> Write the factory data to device from file\n"
"hw factorydata -> Read and parse the factory data from device\n"
);
void *argtable[] = {
arg_param_begin,
arg_str0(NULL, "load", "<fn>", "Load factory data from file to device"),
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, true);
int fnlen = 0;
char filename[FILE_PATH_SIZE] = {0};
CLIParamStrToBuf(arg_get_str(ctx, 1), (uint8_t *)filename, FILE_PATH_SIZE, &fnlen);
CLIParserFree(ctx);
// Read the factory data from device
clearCommandBuffer();
SendCommandNG(CMD_EEPROM_FACTORY_INFO_READ, NULL, 0);
PacketResponseNG resp;
if (WaitForResponseTimeout(CMD_EEPROM_FACTORY_INFO_READ, &resp, 1000) == false) {
PrintAndLogEx(WARNING, "command execution time out");
return PM3_ETIMEOUT;
}
if (resp.status != PM3_SUCCESS) {
PrintAndLogEx(ERR, "failed to read factory data, maybe eeprom unavailable.");
return resp.status;
}
// Parse the factory data
if (resp.length) {
proxmark5_factory_info_v1_t *factory = (proxmark5_factory_info_v1_t *)resp.data.asBytes;
PrintAndLogEx(INFO, "Factory data read from device:");
PrintAndLogEx(INFO, " - Data raw(hex) : 0x%s", sprint_hex_inrow(resp.data.asBytes, resp.length));
PrintAndLogEx(INFO, " - Version : %d", factory->factory_info_version);
PrintAndLogEx(INFO, " - Signature : %s",
sprint_hex_inrow(factory->ecdsa_secp256k1_signature, sizeof(factory->ecdsa_secp256k1_signature)));
PrintAndLogEx(INFO, " - Timestamp : %" PRIu64, factory->info.unix_timestamp);
PrintAndLogEx(INFO, " - Chip Unique ID : %s",
sprint_hex_inrow(factory->info.chip_unique_id, sizeof(factory->info.chip_unique_id)));
PrintAndLogEx(INFO, " - Production ID : %" PRIu32, factory->info.production_id);
PrintAndLogEx(INFO, " - Hardware Version : %" PRIu32, factory->info.hardware_version);
PrintAndLogEx(INFO, " - AES key : %s",
sprint_hex_inrow(factory->info.aes_key, sizeof(factory->info.aes_key)));
}
// If data is provided, it needs to be written
if (fnlen) {
// Load the file content into data buffer
uint8_t *data = NULL;
size_t datalen = 0;
int res = loadFile_safe(filename, ".bin", (void **)&data, &datalen);
if (res != PM3_SUCCESS) {
free(data);
return PM3_EFILE;
}
if (datalen != resp.length) {
PrintAndLogEx(WARNING, _RED_("The length of the data to write (%zu) does not match the length "
"of the factory data read from device (%u)."), datalen, (unsigned int)resp.length);
free(data);
return PM3_EINVARG;
}
// Write the data to the device
clearCommandBuffer();
SendCommandNG(CMD_EEPROM_FACTORY_INFO_WRITE, data, datalen);
PacketResponseNG resp_write;
if (WaitForResponseTimeout(CMD_EEPROM_FACTORY_INFO_WRITE, &resp_write, 1000) == false) {
PrintAndLogEx(WARNING, "command execution time out");
free(data);
return PM3_ETIMEOUT;
}
if (resp_write.status != PM3_SUCCESS) {
PrintAndLogEx(ERR, "failed to write factory data, maybe eeprom unavailable.");
free(data);
return resp_write.status;
}
// Verify the data write
clearCommandBuffer();
SendCommandNG(CMD_EEPROM_FACTORY_INFO_READ, NULL, 0);
if (WaitForResponseTimeout(CMD_EEPROM_FACTORY_INFO_READ, &resp, 1000) == false) {
PrintAndLogEx(WARNING, "command execution time out");
free(data);
return PM3_ETIMEOUT;
}
if (resp.status != PM3_SUCCESS) {
PrintAndLogEx(ERR, "failed to read factory data after write, maybe eeprom unavailable.");
free(data);
return resp.status;
}
bool verify_result = false;
if (resp.length == datalen) {
verify_result = memcmp(resp.data.asBytes, data, datalen) == 0;
}
if (verify_result) {
PrintAndLogEx(SUCCESS, "Factory data written and verified successfully.");
} else {
PrintAndLogEx(ERR, "Factory data verification failed after write.");
free(data);
return PM3_EFAILED;
}
free(data);
}
return PM3_SUCCESS;
}
static int CmdPM5QCTest(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "hw qcpm5", "QC Test for the PM5", "hf qcpm5");
void *argtable[] = {
arg_param_begin,
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, true);
CLIParserFree(ctx);
PrintAndLogEx(INFO, "Performing QC test for the PM5...");
clearCommandBuffer();
SendCommandNG(CMD_PM5_QC_TEST, NULL, 0);
PacketResponseNG resp;
if (WaitForResponseTimeout(CMD_PM5_QC_TEST, &resp, 20 * 1000) == false) {
SendCommandNG(CMD_BREAK_LOOP, NULL, 0);
PrintAndLogEx(WARNING, "command execution time out");
return PM3_ETIMEOUT;
}
if (resp.status != PM3_SUCCESS) {
PrintAndLogEx(ERR, "failed to perform QC test on PM5, failed item: %d", resp.data.asBytes[0]);
return resp.status;
}
PrintAndLogEx(INFO, "PM5 QC test successful.");
return PM3_SUCCESS;
}
static command_t CommandTable[] = {
{"help", CmdHelp, AlwaysAvailable, "This help"},
{"-------------", CmdHelp, AlwaysAvailable, "----------------------- " _CYAN_("Operation") " -----------------------"},
@@ -1714,7 +1924,11 @@ static command_t CommandTable[] = {
{"bootloader", CmdBootloader, IfPm3Present, "Reboot into bootloader mode"},
{"connect", CmdConnect, AlwaysAvailable, "Connect to the device via serial port"},
{"dbg", CmdDbg, IfPm3Present, "Set device side debug level"},
{"fpga", CmdFPGA, IfPm3Present, "Fpga commands"},
{"fpgaoff", CmdFPGAOff, IfPm3Present, "Turn off FPGA on device"},
{"ant_pm5", CmdPM5Ant, IfPm5StdAnt, "Control the antennal of pm5"},
{"qc_pm5", CmdPM5QCTest, IfPm5, "Perform QC test for the PM5"},
{"factorydata", CmdDeviceFactoryData, IfI2cEeprom, "Get/Set the factory data for Device"},
{"lcd", CmdLCD, IfPm3Lcd, "Send command/data to LCD"},
{"lcdreset", CmdLCDReset, IfPm3Lcd, "Hardware reset LCD"},
{"ping", CmdPing, IfPm3Present, "Test if the Proxmark3 is responsive"},
@@ -2021,6 +2235,17 @@ void pm3_version(bool verbose, bool oneliner) {
}
lookupChipID(payload->id, payload->section_size);
// Get unique id of mainchip
clearCommandBuffer();
SendCommandNG(CMD_MAIN_CHIP_UNIQUEID, NULL, 0);
if (WaitForResponseTimeout(CMD_MAIN_CHIP_UNIQUEID, &resp, 1000)) {
if (resp.length) { // Some processor maybe no unique id.
char* uniqueid_hex = sprint_hex_inrow(resp.data.asBytes, resp.length);
PrintAndLogEx(NORMAL, " --= Processor Unique ID: " _YELLOW_("0x%s"), uniqueid_hex);
}
}
if (armsrc_mismatch) {
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(WARNING, _RED_("ARM firmware does not match the source at the time the client was compiled"));
+2 -1
View File
@@ -200,7 +200,8 @@ static int doPreambleSearch(size_t *startIdx) {
size_t size = (11 > g_DemodBufferLen) ? g_DemodBufferLen : 11;
*startIdx = 0;
// skip first two 0 bits as they might have been missed in the demod
// A long time ago, the first two zeros of the preamble were skipped
// because previous decoders had a probability of missing the first part of the data.
uint8_t preamble[EM_PREAMBLE_LEN] = {0, 0, 0, 0, 1, 0, 1, 0};
if (!preambleSearchEx(g_DemodBuffer, preamble, EM_PREAMBLE_LEN, &size, startIdx, true)) {
+24
View File
@@ -122,6 +122,30 @@ bool IfPm3FpcUsartFromUsb(void) {
return IfPm3FpcUsartHostFromUsb() || IfPm3FpcUsartDevFromUsb();
}
bool IfPm5(void) {
if (IfPm3Present() == false)
return false;
return g_pm3_capabilities.is_pm5;
}
bool IfPm5StdAnt(void) {
if (IfPm3Present() == false)
return false;
return g_pm3_capabilities.is_pm5_std_ant;
}
bool IfFpgaFlash(void) {
if (IfPm3Present() == false)
return false;
return g_pm3_capabilities.hw_available_fpga_flash;
}
bool IfI2cEeprom(void) {
if (IfPm3Present() == false)
return false;
return g_pm3_capabilities.hw_available_i2c_eeprom;
}
bool IfPm3Lf(void) {
if (IfPm3Present() == false)
return false;
+4
View File
@@ -41,6 +41,10 @@ bool IfPm3FpcUsartHost(void);
bool IfPm3FpcUsartHostFromUsb(void);
bool IfPm3FpcUsartDevFromUsb(void);
bool IfPm3FpcUsartFromUsb(void);
bool IfPm5(void);
bool IfPm5StdAnt(void);
bool IfFpgaFlash(void);
bool IfI2cEeprom(void);
bool IfPm3Lf(void);
bool IfPm3Hitag(void);
bool IfPm3EM4x50(void);
+18 -10
View File
@@ -18,10 +18,14 @@
#include <immintrin.h>
#if (defined(__GNUC__) || defined(__clang__)) && !defined(__ANDROID__)
#if !defined(__ANDROID__)
#if defined(__clang__)
#pragma clang attribute push(__attribute__((target("avx2"))), apply_to = function)
#elif defined(__GNUC__)
#pragma GCC push_options
#pragma GCC target("avx2")
#endif
#endif
#define BS_ZERO _mm256_setzero_si256()
#define BS_ONES _mm256_set1_epi64x(-1)
@@ -121,7 +125,7 @@ static const uint64_t LANE_BITS_256_RAW[8][BS256_WORDS] = {
};
static inline __m256i lane_bits_256(int k) {
return _mm256_loadu_si256((const __m256i *)LANE_BITS_256_RAW[k]);
return _mm256_loadu_si256((const __m256i *)(const void *)LANE_BITS_256_RAW[k]);
}
static inline void bs_init_state(const __m256i kb[64], __m256i l[8], __m256i r[8], __m256i b[8], __m256i t[16]) {
@@ -174,7 +178,7 @@ static inline void bs_init_state(const __m256i kb[64], __m256i l[8], __m256i r[8
}
void prepare_ccnr_bits_bs256(const uint8_t *cc_nr, uint64_t y_bits_bs[96 * BS256_WORDS]) {
__m256i *y = (__m256i *)y_bits_bs;
__m256i *y = (__m256i *)(void *)y_bits_bs;
for (int i = 0; i < 12; i++) {
const uint8_t byte = cc_nr[i];
for (int bit = 0; bit < 8; bit++) {
@@ -184,7 +188,7 @@ void prepare_ccnr_bits_bs256(const uint8_t *cc_nr, uint64_t y_bits_bs[96 * BS256
}
void prepare_target_mac_bs256(const uint8_t target_mac[4], uint64_t target_mac_bs[32 * BS256_WORDS]) {
__m256i *tm = (__m256i *)target_mac_bs;
__m256i *tm = (__m256i *)(void *)target_mac_bs;
for (int i = 0; i < 4; i++) {
const uint8_t byte = target_mac[i];
for (int bit = 0; bit < 8; bit++) {
@@ -194,7 +198,7 @@ void prepare_target_mac_bs256(const uint8_t target_mac[4], uint64_t target_mac_b
}
void build_bitslice_key_256(const uint8_t partial_key[8], uint64_t index_start, uint64_t kb[64 * BS256_WORDS]) {
__m256i *k = (__m256i *)kb;
__m256i *k = (__m256i *)(void *)kb;
for (int j = 0; j < 8; j++) {
_mm256_storeu_si256(&k[j * 8 + 0], (partial_key[j] & 0x01) ? BS_ONES : BS_ZERO);
@@ -226,7 +230,7 @@ void doMAC_brute_match256(const uint64_t y_bits_bs[96 * BS256_WORDS],
// Load key into local __m256i array for fast access.
__m256i k[64];
const __m256i *kb_m = (const __m256i *)kb;
const __m256i *kb_m = (const __m256i *)(const void *)kb;
for (int i = 0; i < 64; i++) {
k[i] = _mm256_loadu_si256(&kb_m[i]);
}
@@ -234,8 +238,8 @@ void doMAC_brute_match256(const uint64_t y_bits_bs[96 * BS256_WORDS],
__m256i l[8], r[8], b[8], t[16];
bs_init_state(k, l, r, b, t);
const __m256i *y = (const __m256i *)y_bits_bs;
const __m256i *tm = (const __m256i *)target_mac_bs;
const __m256i *y = (const __m256i *)(const void *)y_bits_bs;
const __m256i *tm = (const __m256i *)(const void *)target_mac_bs;
for (int i = 0; i < 96; i++) {
bs_tick(t, b, l, r, k, _mm256_loadu_si256(&y[i]));
@@ -260,12 +264,16 @@ void doMAC_brute_match256(const uint64_t y_bits_bs[96 * BS256_WORDS],
}
}
_mm256_storeu_si256((__m256i *)match_out, mac_match);
_mm256_storeu_si256((__m256i *)(void *)match_out, mac_match);
}
#if (defined(__GNUC__) || defined(__clang__)) && !defined(__ANDROID__)
#if !defined(__ANDROID__)
#if defined(__clang__)
#pragma clang attribute pop
#elif defined(__GNUC__)
#pragma GCC pop_options
#endif
#endif
bool bs_avx2_supported(void) {
static int cached = -1;
+10 -2
View File
@@ -19,10 +19,14 @@
#include <immintrin.h>
#if (defined(__GNUC__) || defined(__clang__)) && !defined(__ANDROID__)
#if !defined(__ANDROID__)
#if defined(__clang__)
#pragma clang attribute push(__attribute__((target("avx512f"))), apply_to = function)
#elif defined(__GNUC__)
#pragma GCC push_options
#pragma GCC target("avx512f")
#endif
#endif
#define BS_ZERO _mm512_setzero_si512()
#define BS_ONES _mm512_set1_epi64(-1)
@@ -291,9 +295,13 @@ void doMAC_brute_match512(const uint64_t y_bits_bs[96 * BS512_WORDS],
_mm512_storeu_si512((void *)match_out, mac_match);
}
#if (defined(__GNUC__) || defined(__clang__)) && !defined(__ANDROID__)
#if !defined(__ANDROID__)
#if defined(__clang__)
#pragma clang attribute pop
#elif defined(__GNUC__)
#pragma GCC pop_options
#endif
#endif
bool bs_avx512_supported(void) {
static int cached = -1;
+3 -3
View File
@@ -1404,8 +1404,8 @@ static int DesfireAuthenticateEV1(DesfireContext_t *dctx, DesfireSecureChannel s
DesfireCryptoEncDecEx(dctx, DCOMainKey, encRndB, rndlen, RndB, false, false, IV);
if (g_debugMode > 1) {
PrintAndLogEx(DEBUG, "encRndB: %s", sprint_hex(encRndB, 8));
PrintAndLogEx(DEBUG, "RndB: %s", sprint_hex(RndB, 8));
PrintAndLogEx(DEBUG, "encRndB: %s", sprint_hex(encRndB, rndlen));
PrintAndLogEx(DEBUG, "RndB: %s", sprint_hex(RndB, rndlen));
}
// - Rotate RndB by 8 bits
@@ -1435,7 +1435,7 @@ static int DesfireAuthenticateEV1(DesfireContext_t *dctx, DesfireSecureChannel s
memcpy(tmp + rndlen, rotRndB, rndlen);
if (g_debugMode > 1) {
PrintAndLogEx(DEBUG, "rotRndB: %s", sprint_hex(rotRndB, rndlen));
PrintAndLogEx(DEBUG, "Both : %s", sprint_hex(tmp, 32));
PrintAndLogEx(DEBUG, "Both : %s", sprint_hex(tmp, rndlen * 2));
}
DesfireCryptoEncDecEx(dctx, DCOMainKey, tmp, rndlen * 2, both, true, true, IV);
}