make style
This commit is contained in:
1 parent
a0a3eb4bbf
commit
35c098d489
197 files changed
+30157
-35538
No files matched your search
@@ -139,8 +139,8 @@ static int CmdFpgaSetPowerPWM(const char *Cmd) {
|
||||
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."),
|
||||
"The larger the value, the higher the voltage; "
|
||||
"the smaller the value, the lower the voltage."),
|
||||
arg_param_end
|
||||
};
|
||||
CLIExecWithReturn(ctx, Cmd, argtable, false);
|
||||
@@ -199,4 +199,4 @@ static int CmdHelp(const char *Cmd) {
|
||||
int CmdFPGA(const char *Cmd) {
|
||||
clearCommandBuffer();
|
||||
return CmdsParse(CommandTable, Cmd);
|
||||
}
|
||||
}
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
int CmdFPGA(const char *Cmd);
|
||||
|
||||
#endif // CMD_FPGA_H
|
||||
#endif // CMD_FPGA_H
|
||||
@@ -3466,7 +3466,7 @@ static int CmdHF15CSetUID(const char *Cmd) {
|
||||
[=] 16 | 77 66 55 44 | 0 | wfUD
|
||||
[=] 17 | 33 22 11 E0 | 0 | 3"..
|
||||
*/
|
||||
uint8_t blk_lo[4] = {0};
|
||||
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);
|
||||
|
||||
@@ -626,7 +626,7 @@ static bool calypso_parse_fcp_value(const uint8_t *value, size_t value_len, caly
|
||||
|
||||
if (value_len >= 0x16) {
|
||||
uint16_t tail = ((uint16_t)value[value_len - 2] << 8) | value[value_len - 1];
|
||||
if (tail == 0x3F3F) {
|
||||
if (tail == 0x3F3F) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1420,7 +1420,7 @@ static int calypso_exchange_once(sAPDU_t apdu, bool include_le, uint16_t le, cal
|
||||
response->len = 0;
|
||||
response->sw = 0;
|
||||
int res = Iso7816ExchangeEx(CC_CONTACTLESS, false, true, apdu, include_le, le,
|
||||
response->data, sizeof(response->data), &response->len, &response->sw);
|
||||
response->data, sizeof(response->data), &response->len, &response->sw);
|
||||
|
||||
// Iso7816ExchangeEx currently returns a positive status for a valid error
|
||||
// R-APDU only when APDU logging is enabled. A received SW is transport
|
||||
|
||||
@@ -455,11 +455,11 @@ static int CmdHFCryptoRFELoad(const char *Cmd) {
|
||||
return PM3_EFILE;
|
||||
}
|
||||
|
||||
// ICEMAN: Once we have CryptoRF dump files, we can implement an upload
|
||||
// ICEMAN: Once we have CryptoRF dump files, we can implement an upload
|
||||
PrintAndLogEx(INFO, "to be implemented");
|
||||
//PrintAndLogEx(SUCCESS, "Uploading to emulator memory");
|
||||
//uint32_t bytes_sent = 0;
|
||||
|
||||
|
||||
free(data);
|
||||
//PrintAndLogEx(SUCCESS, "sent " _YELLOW_("%d") " bytes of data to device emulator memory", bytes_sent);
|
||||
return PM3_SUCCESS;
|
||||
|
||||
+52
-52
@@ -398,7 +398,7 @@ static void felica_auth_collect_codes(const felica_auth_key_store_t *store, uint
|
||||
uint16_t *codes, size_t *count);
|
||||
static void felica_auth_add_unique_code(uint16_t *codes, size_t *count, uint16_t code);
|
||||
static const felica_node_t *felica_find_node(const felica_node_t *versions,
|
||||
size_t version_count, uint16_t code_be);
|
||||
size_t version_count, uint16_t code_be);
|
||||
static bool felica_node_present(const felica_node_t *node);
|
||||
static int felica_collect_key_versions(uint8_t flags, const uint8_t *idm,
|
||||
const uint16_t *codes_be, size_t code_count,
|
||||
@@ -919,7 +919,7 @@ static bool felica_date_is_acceptable(int year, int month, int day) {
|
||||
|
||||
int current_year = 9999;
|
||||
const time_t now = time(NULL);
|
||||
if (now != (time_t)-1) {
|
||||
if (now != (time_t) -1) {
|
||||
const struct tm *tm_now = gmtime(&now);
|
||||
if (tm_now != NULL) {
|
||||
current_year = tm_now->tm_year + 1900;
|
||||
@@ -1131,7 +1131,7 @@ static json_t *felica_get_container_issue_list(void) {
|
||||
}
|
||||
|
||||
static bool felica_container_issue_matches(const felica_get_container_issue_info_response_t *response,
|
||||
const json_t *entry) {
|
||||
const json_t *entry) {
|
||||
if (response == NULL || json_is_object(entry) == false) {
|
||||
return false;
|
||||
}
|
||||
@@ -2089,9 +2089,9 @@ static void felica_info_process_system(int level, uint8_t flags, felica_discover
|
||||
have_versions = true;
|
||||
for (size_t i = 0; i < combined_code_count; i++) {
|
||||
if (verbose) PrintAndLogEx(INFO, "[auth] card: node %04X -> DES %u AES %u%s",
|
||||
versions[i].code_be,
|
||||
versions[i].des_key_version.value, versions[i].aes_key_version.value,
|
||||
felica_node_present(&versions[i]) ? "" : " (absent)");
|
||||
versions[i].code_be,
|
||||
versions[i].des_key_version.value, versions[i].aes_key_version.value,
|
||||
felica_node_present(&versions[i]) ? "" : " (absent)");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2957,8 +2957,8 @@ static int info_felica(bool verbose, bool no_ic_optimizations) {
|
||||
felica_auth_key_store_t auth_keys = {0};
|
||||
felica_auth_key_store_load(&auth_keys, verbose);
|
||||
if (verbose) PrintAndLogEx(INFO, "[auth] loaded " _YELLOW_("%zu") " node key(s), " _YELLOW_("%zu") " group/user keyset(s)",
|
||||
json_array_size(json_object_get_ci(auth_keys.node_root, "keys")),
|
||||
json_array_size(json_object_get_ci(auth_keys.group_user_root, "keysets")));
|
||||
json_array_size(json_object_get_ci(auth_keys.node_root, "keys")),
|
||||
json_array_size(json_object_get_ci(auth_keys.group_user_root, "keysets")));
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(INFO, "--- " _CYAN_("Tag Information") " ---------------------------");
|
||||
PrintAndLogEx(INFO, "Primary IDm.... " _YELLOW_("%s"), sprint_hex_inrow(card.IDm, sizeof(card.IDm)));
|
||||
@@ -2974,7 +2974,7 @@ static int info_felica(bool verbose, bool no_ic_optimizations) {
|
||||
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 &&
|
||||
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);
|
||||
@@ -3008,10 +3008,10 @@ static int info_felica(bool verbose, bool no_ic_optimizations) {
|
||||
size_t platform_information_data_len = 0;
|
||||
if (caps.supports_request_product_information != FELICA_CAP_UNSUPPORTED &&
|
||||
send_get_platform_information(optional_flags,
|
||||
sizeof(platform_info_request), (uint8_t *)&platform_info_request,
|
||||
false, &platform_status_flags, platform_information_data,
|
||||
sizeof(platform_information_data),
|
||||
&platform_information_data_len) == PM3_SUCCESS &&
|
||||
sizeof(platform_info_request), (uint8_t *)&platform_info_request,
|
||||
false, &platform_status_flags, platform_information_data,
|
||||
sizeof(platform_information_data),
|
||||
&platform_information_data_len) == PM3_SUCCESS &&
|
||||
platform_information_data_len > 0) {
|
||||
print_platform_information(platform_information_data, platform_information_data_len);
|
||||
}
|
||||
@@ -3025,10 +3025,10 @@ static int info_felica(bool verbose, bool no_ic_optimizations) {
|
||||
felica_request_specification_version_info_t specification_version_info;
|
||||
if (caps.supports_request_specification_version != FELICA_CAP_UNSUPPORTED &&
|
||||
send_request_specification_version(optional_flags, sizeof(request_specification_version_request),
|
||||
(uint8_t *)&request_specification_version_request, false,
|
||||
false, FELICA_OPTIONAL_CMD_TIMEOUT_MS,
|
||||
felica_capability_attempts(caps.supports_request_specification_version) - 1U,
|
||||
&specification_version_info) == PM3_SUCCESS &&
|
||||
(uint8_t *)&request_specification_version_request, false,
|
||||
false, FELICA_OPTIONAL_CMD_TIMEOUT_MS,
|
||||
felica_capability_attempts(caps.supports_request_specification_version) - 1U,
|
||||
&specification_version_info) == PM3_SUCCESS &&
|
||||
specification_version_info.has_specification_version) {
|
||||
print_specification_versions(INFO, &specification_version_info, true);
|
||||
}
|
||||
@@ -3041,8 +3041,8 @@ static int info_felica(bool verbose, bool no_ic_optimizations) {
|
||||
felica_get_container_id_response_t container_id_response;
|
||||
if (caps.supports_get_container_id != FELICA_CAP_UNSUPPORTED &&
|
||||
send_get_container_id(optional_flags, sizeof(container_id_request),
|
||||
(uint8_t *)&container_id_request, false,
|
||||
&container_id_response) == PM3_SUCCESS) {
|
||||
(uint8_t *)&container_id_request, false,
|
||||
&container_id_response) == PM3_SUCCESS) {
|
||||
PrintAndLogEx(INFO, "Container IDm.. " _YELLOW_("%s"),
|
||||
sprint_hex_inrow(container_id_response.container_idm, sizeof(container_id_response.container_idm)));
|
||||
}
|
||||
@@ -3056,15 +3056,15 @@ static int info_felica(bool verbose, bool no_ic_optimizations) {
|
||||
felica_get_container_issue_info_response_t container_issue_info_response;
|
||||
if (caps.supports_get_container_issue_information != FELICA_CAP_UNSUPPORTED &&
|
||||
send_get_container_issue_information(optional_flags,
|
||||
sizeof(container_issue_info_request), (uint8_t *)&container_issue_info_request, false,
|
||||
&container_issue_info_response) == PM3_SUCCESS) {
|
||||
sizeof(container_issue_info_request), (uint8_t *)&container_issue_info_request, false,
|
||||
&container_issue_info_response) == PM3_SUCCESS) {
|
||||
char model_ascii[sizeof(container_issue_info_response.mobile_phone_model_information) + 1] = {0};
|
||||
bool model_is_ascii = decode_zero_padded_ascii(
|
||||
container_issue_info_response.mobile_phone_model_information,
|
||||
sizeof(container_issue_info_response.mobile_phone_model_information),
|
||||
model_ascii,
|
||||
sizeof(model_ascii)
|
||||
);
|
||||
);
|
||||
PrintAndLogEx(INFO, "Container issue info:");
|
||||
PrintAndLogEx(INFO, " Format/Carrier info... " _YELLOW_("%s"),
|
||||
sprint_hex_inrow(container_issue_info_response.format_version_carrier_information,
|
||||
@@ -3954,8 +3954,8 @@ static void felica_auth_collect_codes(const felica_auth_key_store_t *store, uint
|
||||
}
|
||||
|
||||
static int felica_collect_key_versions_v2(uint8_t flags, const uint8_t *idm,
|
||||
const uint16_t *codes_be, size_t code_count,
|
||||
felica_node_t *versions, uint32_t retries) {
|
||||
const uint16_t *codes_be, size_t code_count,
|
||||
felica_node_t *versions, uint32_t retries) {
|
||||
bool encryption_identifier_set = false;
|
||||
uint8_t encryption_identifier = 0;
|
||||
|
||||
@@ -3968,7 +3968,7 @@ static int felica_collect_key_versions_v2(uint8_t flags, const uint8_t *idm,
|
||||
|
||||
felica_request_service_v2_key_versions_t response;
|
||||
int result = felica_request_service_v2_key_versions(flags, idm, batch_codes_le, batch_count,
|
||||
retries, &response);
|
||||
retries, &response);
|
||||
if (result != PM3_SUCCESS || felica_encryption_identifier_get_info(response.encryption_identifier) == NULL) {
|
||||
return PM3_ERFTRANS;
|
||||
}
|
||||
@@ -3992,8 +3992,8 @@ static int felica_collect_key_versions_v2(uint8_t flags, const uint8_t *idm,
|
||||
}
|
||||
|
||||
static int felica_collect_key_versions_v1(uint8_t flags, const uint8_t *idm,
|
||||
const uint16_t *codes_be, size_t code_count,
|
||||
felica_node_t *versions) {
|
||||
const uint16_t *codes_be, size_t code_count,
|
||||
felica_node_t *versions) {
|
||||
for (size_t processed = 0; processed < code_count;) {
|
||||
const size_t batch_count = MIN(FELICA_REQUEST_SERVICE_DISCOVERY_BATCH_SIZE, code_count - processed);
|
||||
uint16_t batch_codes_le[FELICA_REQUEST_SERVICE_DISCOVERY_BATCH_SIZE] = {0};
|
||||
@@ -4004,7 +4004,7 @@ static int felica_collect_key_versions_v1(uint8_t flags, const uint8_t *idm,
|
||||
|
||||
size_t returned_nodes = 0;
|
||||
int result = felica_request_service_key_versions(flags, idm, batch_codes_le, batch_count,
|
||||
FELICA_OPTIONAL_CMD_RETRIES, key_versions, &returned_nodes);
|
||||
FELICA_OPTIONAL_CMD_RETRIES, key_versions, &returned_nodes);
|
||||
if (result != PM3_SUCCESS || returned_nodes != batch_count) {
|
||||
return PM3_ERFTRANS;
|
||||
}
|
||||
@@ -4105,9 +4105,9 @@ static int felica_auth_send_authentication1(uint8_t flags, const uint8_t idm[8],
|
||||
|
||||
PacketResponseNG packet;
|
||||
int result = send_felica_payload_with_retries(flags, (uint16_t)frame_length, frame, false,
|
||||
FELICA_AUTHENTICATION1_RES,
|
||||
FELICA_DEFAULT_TIMEOUT_MS, 2U, 0, false,
|
||||
&packet, "authentication1");
|
||||
FELICA_AUTHENTICATION1_RES,
|
||||
FELICA_DEFAULT_TIMEOUT_MS, 2U, 0, false,
|
||||
&packet, "authentication1");
|
||||
mbedtls_platform_zeroize(frame, sizeof(frame));
|
||||
if (result != PM3_SUCCESS || packet.length < sizeof(*response)) {
|
||||
return PM3_ERFTRANS;
|
||||
@@ -4131,9 +4131,9 @@ static int felica_auth_send_authentication2_once(uint8_t flags, const uint8_t id
|
||||
|
||||
PacketResponseNG packet;
|
||||
int result = send_felica_payload_with_retries(flags, sizeof(frame), frame, false,
|
||||
FELICA_AUTHENTICATION2_RES,
|
||||
FELICA_DEFAULT_TIMEOUT_MS, 2U, 0, false,
|
||||
&packet, "authentication2");
|
||||
FELICA_AUTHENTICATION2_RES,
|
||||
FELICA_DEFAULT_TIMEOUT_MS, 2U, 0, false,
|
||||
&packet, "authentication2");
|
||||
mbedtls_platform_zeroize(frame, sizeof(frame));
|
||||
const size_t ciphertext_offset = sizeof(felica_frame_response_noidm_t);
|
||||
if (result != PM3_SUCCESS || packet.length < ciphertext_offset + FELICA_AUTH2_CIPHERTEXT_LEN) {
|
||||
@@ -4188,10 +4188,10 @@ cleanup:
|
||||
}
|
||||
|
||||
static felica_auth_candidate_result_t felica_auth_try_candidate(uint8_t flags, const uint8_t idm[8],
|
||||
const uint16_t *areas_be, size_t area_count,
|
||||
const uint16_t *nodes_be, size_t node_count,
|
||||
const uint8_t group_key[8], const uint8_t user_key[8],
|
||||
uint8_t idi[8], uint8_t pmi[8], bool verbose) {
|
||||
const uint16_t *areas_be, size_t area_count,
|
||||
const uint16_t *nodes_be, size_t node_count,
|
||||
const uint8_t group_key[8], const uint8_t user_key[8],
|
||||
uint8_t idi[8], uint8_t pmi[8], bool verbose) {
|
||||
uint8_t random1[8] = {0};
|
||||
uint8_t l[8] = {0};
|
||||
uint8_t alpha[8] = {0};
|
||||
@@ -4294,9 +4294,9 @@ static void felica_auth_collect_matching_node_keys(const felica_auth_key_store_t
|
||||
}
|
||||
|
||||
static felica_auth_candidate_result_t felica_auth_try_node_pair(uint8_t flags, const uint8_t idm[8],
|
||||
const felica_auth_node_key_t *keys, size_t key_count,
|
||||
uint16_t left_code, uint16_t right_code,
|
||||
bool *attempted, uint8_t idi[8], uint8_t pmi[8], bool verbose) {
|
||||
const felica_auth_node_key_t *keys, size_t key_count,
|
||||
uint16_t left_code, uint16_t right_code,
|
||||
bool *attempted, uint8_t idi[8], uint8_t pmi[8], bool verbose) {
|
||||
const uint16_t areas[] = {left_code};
|
||||
const uint16_t nodes[] = {right_code};
|
||||
|
||||
@@ -4335,8 +4335,8 @@ static felica_auth_candidate_result_t felica_auth_try_node_pair(uint8_t flags, c
|
||||
}
|
||||
|
||||
static felica_auth_candidate_result_t felica_auth_try_node_keys(uint8_t flags, const uint8_t idm[8],
|
||||
const felica_auth_node_key_t *keys, size_t key_count,
|
||||
bool *attempted, uint8_t idi[8], uint8_t pmi[8], bool verbose) {
|
||||
const felica_auth_node_key_t *keys, size_t key_count,
|
||||
bool *attempted, uint8_t idi[8], uint8_t pmi[8], bool verbose) {
|
||||
bool has_system_key = false;
|
||||
uint16_t areas[FELICA_AUTH_MAX_NODES];
|
||||
size_t area_count = 0;
|
||||
@@ -4392,7 +4392,7 @@ static bool felica_auth_group_versions_match(const json_t *versions_json,
|
||||
if (felica_code_from_hex(code_hex, &code) == false ||
|
||||
felica_auth_parse_key_version(wanted_version_json, &wanted_version) == false) {
|
||||
if (verbose) PrintAndLogEx(INFO, "[auth] versions entry `%s` unparsable (code must be 4 hex chars, version a number)",
|
||||
code_hex ? code_hex : "(null)");
|
||||
code_hex ? code_hex : "(null)");
|
||||
return false;
|
||||
}
|
||||
const felica_node_t *card_node = felica_find_node(versions, version_count, code);
|
||||
@@ -4406,7 +4406,7 @@ static bool felica_auth_group_versions_match(const json_t *versions_json,
|
||||
}
|
||||
if (card_node->des_key_version.value != wanted_version) {
|
||||
if (verbose) PrintAndLogEx(INFO, "[auth] node %04X: version mismatch, file %u vs card %u",
|
||||
code, wanted_version, card_node->des_key_version.value);
|
||||
code, wanted_version, card_node->des_key_version.value);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -4426,11 +4426,11 @@ static bool felica_auth_json_code_array_contains(const json_t *array, uint16_t w
|
||||
}
|
||||
|
||||
static felica_auth_candidate_result_t felica_auth_try_group_user_keys(const felica_auth_key_store_t *store,
|
||||
uint8_t flags, uint16_t system_code,
|
||||
const uint8_t idm[8],
|
||||
const felica_node_t *versions,
|
||||
size_t version_count, bool *attempted,
|
||||
uint8_t idi[8], uint8_t pmi[8], bool verbose) {
|
||||
uint8_t flags, uint16_t system_code,
|
||||
const uint8_t idm[8],
|
||||
const felica_node_t *versions,
|
||||
size_t version_count, bool *attempted,
|
||||
uint8_t idi[8], uint8_t pmi[8], bool verbose) {
|
||||
json_t *keysets = json_object_get_ci(store->group_user_root, FELICA_AUTH_GROUP_USER_KEY_FILE.records_key);
|
||||
for (int root_preference = 1; root_preference >= 0; root_preference--) {
|
||||
size_t index = 0;
|
||||
@@ -4446,7 +4446,7 @@ static felica_auth_candidate_result_t felica_auth_try_group_user_keys(const feli
|
||||
continue;
|
||||
}
|
||||
if (verbose) PrintAndLogEx(INFO, "[auth] keyset #%zu (%s root): checking versions",
|
||||
index, contains_root ? "contains" : "no");
|
||||
index, contains_root ? "contains" : "no");
|
||||
json_t *versions_json = json_object_get_ci(record, "versions");
|
||||
if (felica_auth_group_versions_match(versions_json, versions, version_count, verbose) == false) {
|
||||
if (verbose) PrintAndLogEx(INFO, "[auth] keyset #%zu: version check FAILED, skipped", index);
|
||||
@@ -4470,7 +4470,7 @@ static felica_auth_candidate_result_t felica_auth_try_group_user_keys(const feli
|
||||
}
|
||||
|
||||
if (verbose) PrintAndLogEx(INFO, "[auth] keyset #%zu: ATTEMPTING auth, %zu area(s) + %zu node(s)",
|
||||
index, area_count, node_count);
|
||||
index, area_count, node_count);
|
||||
*attempted = true;
|
||||
const felica_auth_candidate_result_t result =
|
||||
felica_auth_try_candidate(flags, idm, areas, area_count, nodes, node_count,
|
||||
|
||||
+27
-9
@@ -863,15 +863,33 @@ void annotateIso7816(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize, bool
|
||||
(pcb & 0x0F) ? " error" : "");
|
||||
} else {
|
||||
switch (pcb & 0x3F) {
|
||||
case 0x00: snprintf(exp, size, "S-block RESYNCH req"); break;
|
||||
case 0x20: snprintf(exp, size, "S-block RESYNCH resp"); break;
|
||||
case 0x01: snprintf(exp, size, "S-block IFS req"); break;
|
||||
case 0x21: snprintf(exp, size, "S-block IFS resp"); break;
|
||||
case 0x02: snprintf(exp, size, "S-block ABORT req"); break;
|
||||
case 0x22: snprintf(exp, size, "S-block ABORT resp"); break;
|
||||
case 0x03: snprintf(exp, size, "S-block WTX req"); break;
|
||||
case 0x23: snprintf(exp, size, "S-block WTX resp"); break;
|
||||
default: snprintf(exp, size, "S-block"); break;
|
||||
case 0x00:
|
||||
snprintf(exp, size, "S-block RESYNCH req");
|
||||
break;
|
||||
case 0x20:
|
||||
snprintf(exp, size, "S-block RESYNCH resp");
|
||||
break;
|
||||
case 0x01:
|
||||
snprintf(exp, size, "S-block IFS req");
|
||||
break;
|
||||
case 0x21:
|
||||
snprintf(exp, size, "S-block IFS resp");
|
||||
break;
|
||||
case 0x02:
|
||||
snprintf(exp, size, "S-block ABORT req");
|
||||
break;
|
||||
case 0x22:
|
||||
snprintf(exp, size, "S-block ABORT resp");
|
||||
break;
|
||||
case 0x03:
|
||||
snprintf(exp, size, "S-block WTX req");
|
||||
break;
|
||||
case 0x23:
|
||||
snprintf(exp, size, "S-block WTX resp");
|
||||
break;
|
||||
default:
|
||||
snprintf(exp, size, "S-block");
|
||||
break;
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
||||
+105
-105
@@ -1674,131 +1674,131 @@ static int CmdHF14aDesChk(const char *Cmd) {
|
||||
app_ids_len = 3;
|
||||
}
|
||||
|
||||
{
|
||||
uint32_t deskeyCountTotal = 0;
|
||||
uint32_t aeskeyCountTotal = 0;
|
||||
uint32_t k3kkeyCountTotal = 0;
|
||||
{
|
||||
uint32_t deskeyCountTotal = 0;
|
||||
uint32_t aeskeyCountTotal = 0;
|
||||
uint32_t k3kkeyCountTotal = 0;
|
||||
|
||||
if (pattern1b) {
|
||||
deskeyCountTotal = deskeyListLen;
|
||||
aeskeyCountTotal = aeskeyListLen;
|
||||
k3kkeyCountTotal = k3kkeyListLen;
|
||||
} else if (pattern2b) {
|
||||
deskeyCountTotal = 0x10000 - startPattern;
|
||||
aeskeyCountTotal = 0x10000 - startPattern;
|
||||
k3kkeyCountTotal = 0x10000 - startPattern;
|
||||
} else if (dict_filenamelen) {
|
||||
size_t readStart = 0;
|
||||
size_t readEnd = 1;
|
||||
uint32_t n = 0;
|
||||
if (pattern1b) {
|
||||
deskeyCountTotal = deskeyListLen;
|
||||
aeskeyCountTotal = aeskeyListLen;
|
||||
k3kkeyCountTotal = k3kkeyListLen;
|
||||
} else if (pattern2b) {
|
||||
deskeyCountTotal = 0x10000 - startPattern;
|
||||
aeskeyCountTotal = 0x10000 - startPattern;
|
||||
k3kkeyCountTotal = 0x10000 - startPattern;
|
||||
} else if (dict_filenamelen) {
|
||||
size_t readStart = 0;
|
||||
size_t readEnd = 1;
|
||||
uint32_t n = 0;
|
||||
|
||||
while (readEnd != 0) {
|
||||
loadFileDICTIONARYEx((char *)dict_filename, deskeyList, sizeof(deskeyList), NULL, 8, &n, readStart, &readEnd, false);
|
||||
readStart = readEnd;
|
||||
deskeyCountTotal += n;
|
||||
}
|
||||
while (readEnd != 0) {
|
||||
loadFileDICTIONARYEx((char *)dict_filename, deskeyList, sizeof(deskeyList), NULL, 8, &n, readStart, &readEnd, false);
|
||||
readStart = readEnd;
|
||||
deskeyCountTotal += n;
|
||||
}
|
||||
|
||||
readStart = 0;
|
||||
readEnd = 1;
|
||||
while (readEnd != 0) {
|
||||
loadFileDICTIONARYEx((char *)dict_filename, aeskeyList, sizeof(aeskeyList), NULL, 16, &n, readStart, &readEnd, false);
|
||||
readStart = readEnd;
|
||||
aeskeyCountTotal += n;
|
||||
}
|
||||
readStart = 0;
|
||||
readEnd = 1;
|
||||
while (readEnd != 0) {
|
||||
loadFileDICTIONARYEx((char *)dict_filename, aeskeyList, sizeof(aeskeyList), NULL, 16, &n, readStart, &readEnd, false);
|
||||
readStart = readEnd;
|
||||
aeskeyCountTotal += n;
|
||||
}
|
||||
|
||||
readStart = 0;
|
||||
readEnd = 1;
|
||||
while (readEnd != 0) {
|
||||
loadFileDICTIONARYEx((char *)dict_filename, k3kkeyList, sizeof(k3kkeyList), NULL, 24, &n, readStart, &readEnd, false);
|
||||
readStart = readEnd;
|
||||
k3kkeyCountTotal += n;
|
||||
}
|
||||
}
|
||||
readStart = 0;
|
||||
readEnd = 1;
|
||||
while (readEnd != 0) {
|
||||
loadFileDICTIONARYEx((char *)dict_filename, k3kkeyList, sizeof(k3kkeyList), NULL, 24, &n, readStart, &readEnd, false);
|
||||
readStart = readEnd;
|
||||
k3kkeyCountTotal += n;
|
||||
}
|
||||
}
|
||||
|
||||
if (deskeyCountTotal > 0)
|
||||
PrintAndLogEx(INFO, "Loaded " _YELLOW_("%"PRIu32) " des keys", deskeyCountTotal);
|
||||
if (aeskeyCountTotal > 0)
|
||||
PrintAndLogEx(INFO, "Loaded " _YELLOW_("%"PRIu32) " aes keys", aeskeyCountTotal);
|
||||
if (k3kkeyCountTotal > 0)
|
||||
PrintAndLogEx(INFO, "Loaded " _YELLOW_("%"PRIu32) " k3kdes keys", k3kkeyCountTotal);
|
||||
if (deskeyCountTotal > 0)
|
||||
PrintAndLogEx(INFO, "Loaded " _YELLOW_("%"PRIu32) " des keys", deskeyCountTotal);
|
||||
if (aeskeyCountTotal > 0)
|
||||
PrintAndLogEx(INFO, "Loaded " _YELLOW_("%"PRIu32) " aes keys", aeskeyCountTotal);
|
||||
if (k3kkeyCountTotal > 0)
|
||||
PrintAndLogEx(INFO, "Loaded " _YELLOW_("%"PRIu32) " k3kdes keys", k3kkeyCountTotal);
|
||||
|
||||
if (deskeyCountTotal + aeskeyCountTotal + k3kkeyCountTotal == 0) {
|
||||
PrintAndLogEx(ERR, "No keys provided. Nothing to check.");
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
}
|
||||
if (deskeyCountTotal + aeskeyCountTotal + k3kkeyCountTotal == 0) {
|
||||
PrintAndLogEx(ERR, "No keys provided. Nothing to check.");
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
}
|
||||
|
||||
for (uint32_t x = 0; x < app_ids_len / 3; x++) {
|
||||
|
||||
uint32_t curaid = (app_ids[x * 3] & 0xFF) + ((app_ids[(x * 3) + 1] & 0xFF) << 8) + ((app_ids[(x * 3) + 2] & 0xFF) << 16);
|
||||
PrintAndLogEx(ERR, "Checking aid 0x%06X...", curaid);
|
||||
|
||||
bool loadedAllKeys = false;
|
||||
size_t desReadStart = 0;
|
||||
size_t desReadEnd = 1;
|
||||
size_t aesReadStart = 0;
|
||||
size_t aesReadEnd = 1;
|
||||
size_t k3kReadStart = 0;
|
||||
size_t k3kReadEnd = 1;
|
||||
uint32_t pattern2bOffset = startPattern;
|
||||
bool loadedAllKeys = false;
|
||||
size_t desReadStart = 0;
|
||||
size_t desReadEnd = 1;
|
||||
size_t aesReadStart = 0;
|
||||
size_t aesReadEnd = 1;
|
||||
size_t k3kReadStart = 0;
|
||||
size_t k3kReadEnd = 1;
|
||||
uint32_t pattern2bOffset = startPattern;
|
||||
|
||||
while (!loadedAllKeys) {
|
||||
bool foundKeyThisRound = false;
|
||||
while (!loadedAllKeys) {
|
||||
bool foundKeyThisRound = false;
|
||||
|
||||
if (pattern1b) {
|
||||
loadedAllKeys = true;
|
||||
} else if (pattern2b) {
|
||||
if (pattern2bOffset < 0x10000) {
|
||||
aeskeyListLen = 0;
|
||||
deskeyListLen = 0;
|
||||
k3kkeyListLen = 0;
|
||||
DesFill2bPattern(deskeyList, &deskeyListLen, aeskeyList, &aeskeyListLen, k3kkeyList, &k3kkeyListLen, &pattern2bOffset);
|
||||
} else {
|
||||
loadedAllKeys = true;
|
||||
}
|
||||
} else if (dict_filenamelen) {
|
||||
deskeyListLen = 0;
|
||||
if (desReadEnd != 0) {
|
||||
res = loadFileDICTIONARYEx((char *)dict_filename, deskeyList, sizeof(deskeyList), NULL, 8, &deskeyListLen, desReadStart, &desReadEnd, false);
|
||||
if (res != PM3_SUCCESS)
|
||||
desReadStart = desReadEnd;
|
||||
} else {
|
||||
// Every 16 byte or 24 byte key also gets read as a valid des key, so when desReadEnd == 0 there are absolutely no more keys of any kind left in the dictionary
|
||||
loadedAllKeys = true;
|
||||
}
|
||||
if (pattern1b) {
|
||||
loadedAllKeys = true;
|
||||
} else if (pattern2b) {
|
||||
if (pattern2bOffset < 0x10000) {
|
||||
aeskeyListLen = 0;
|
||||
deskeyListLen = 0;
|
||||
k3kkeyListLen = 0;
|
||||
DesFill2bPattern(deskeyList, &deskeyListLen, aeskeyList, &aeskeyListLen, k3kkeyList, &k3kkeyListLen, &pattern2bOffset);
|
||||
} else {
|
||||
loadedAllKeys = true;
|
||||
}
|
||||
} else if (dict_filenamelen) {
|
||||
deskeyListLen = 0;
|
||||
if (desReadEnd != 0) {
|
||||
res = loadFileDICTIONARYEx((char *)dict_filename, deskeyList, sizeof(deskeyList), NULL, 8, &deskeyListLen, desReadStart, &desReadEnd, false);
|
||||
if (res != PM3_SUCCESS)
|
||||
desReadStart = desReadEnd;
|
||||
} else {
|
||||
// Every 16 byte or 24 byte key also gets read as a valid des key, so when desReadEnd == 0 there are absolutely no more keys of any kind left in the dictionary
|
||||
loadedAllKeys = true;
|
||||
}
|
||||
|
||||
aeskeyListLen = 0;
|
||||
if (aesReadEnd != 0) {
|
||||
res = loadFileDICTIONARYEx((char *)dict_filename, aeskeyList, sizeof(aeskeyList), NULL, 16, &aeskeyListLen, aesReadStart, &aesReadEnd, false);
|
||||
if (res != PM3_SUCCESS)
|
||||
aesReadStart = aesReadEnd;
|
||||
}
|
||||
aeskeyListLen = 0;
|
||||
if (aesReadEnd != 0) {
|
||||
res = loadFileDICTIONARYEx((char *)dict_filename, aeskeyList, sizeof(aeskeyList), NULL, 16, &aeskeyListLen, aesReadStart, &aesReadEnd, false);
|
||||
if (res != PM3_SUCCESS)
|
||||
aesReadStart = aesReadEnd;
|
||||
}
|
||||
|
||||
k3kkeyListLen = 0;
|
||||
if (k3kReadEnd != 0) {
|
||||
res = loadFileDICTIONARYEx((char *)dict_filename, k3kkeyList, sizeof(k3kkeyList), NULL, 24, &k3kkeyListLen, k3kReadStart, &k3kReadEnd, false);
|
||||
if (res != PM3_SUCCESS)
|
||||
k3kReadStart = k3kReadEnd;
|
||||
}
|
||||
}
|
||||
k3kkeyListLen = 0;
|
||||
if (k3kReadEnd != 0) {
|
||||
res = loadFileDICTIONARYEx((char *)dict_filename, k3kkeyList, sizeof(k3kkeyList), NULL, 24, &k3kkeyListLen, k3kReadStart, &k3kReadEnd, false);
|
||||
if (res != PM3_SUCCESS)
|
||||
k3kReadStart = k3kReadEnd;
|
||||
}
|
||||
}
|
||||
|
||||
res = AuthCheckDesfire(&dctx, secureChannel, &app_ids[x * 3], deskeyList, deskeyListLen, aeskeyList, aeskeyListLen, k3kkeyList, k3kkeyListLen, cmdKDFAlgo, kdfInputLen, kdfInput, foundKeys, &foundKeyThisRound, verbose);
|
||||
if (res == PM3_EOPABORTED) {
|
||||
break;
|
||||
}
|
||||
res = AuthCheckDesfire(&dctx, secureChannel, &app_ids[x * 3], deskeyList, deskeyListLen, aeskeyList, aeskeyListLen, k3kkeyList, k3kkeyListLen, cmdKDFAlgo, kdfInputLen, kdfInput, foundKeys, &foundKeyThisRound, verbose);
|
||||
if (res == PM3_EOPABORTED) {
|
||||
break;
|
||||
}
|
||||
|
||||
result = result || foundKeyThisRound;
|
||||
result = result || foundKeyThisRound;
|
||||
|
||||
if (foundKeyThisRound == true && verbose == false) {
|
||||
if (pattern1b || pattern2b)
|
||||
PrintAndLogEx(NORMAL, "p" NOLF);
|
||||
else if (dict_filenamelen)
|
||||
PrintAndLogEx(NORMAL, "d" NOLF);
|
||||
}
|
||||
}
|
||||
if (foundKeyThisRound == true && verbose == false) {
|
||||
if (pattern1b || pattern2b)
|
||||
PrintAndLogEx(NORMAL, "p" NOLF);
|
||||
else if (dict_filenamelen)
|
||||
PrintAndLogEx(NORMAL, "d" NOLF);
|
||||
}
|
||||
}
|
||||
|
||||
if (!loadedAllKeys)
|
||||
break;
|
||||
if (!loadedAllKeys)
|
||||
break;
|
||||
}
|
||||
if (verbose == false) {
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
|
||||
+24
-18
@@ -1510,13 +1510,13 @@ static int CmdTearoff(const char *Cmd) {
|
||||
static int CmdBwmAutoOff(const char *Cmd) {
|
||||
CLIParserContext *ctx;
|
||||
CLIParserInit(&ctx, "hw bwmautooff",
|
||||
"Toggle automatic power-off when the PM5 is unplugged from USB (BWM only).\n"
|
||||
"Default is " _GREEN_("on") ". When on, the board powers itself down ~10s after\n"
|
||||
"USB is removed, so a BWM-equipped PM5 doesn't silently drain the battery.\n"
|
||||
"Button power-on is unaffected. Disable for standalone/BLE use on battery.\n"
|
||||
_YELLOW_("Runtime only:") " resets to on at each boot.",
|
||||
"hw bwmautooff --off --> disable auto power-off\n"
|
||||
"hw bwmautooff --on --> re-enable auto power-off");
|
||||
"Toggle automatic power-off when the PM5 is unplugged from USB (BWM only).\n"
|
||||
"Default is " _GREEN_("on") ". When on, the board powers itself down ~10s after\n"
|
||||
"USB is removed, so a BWM-equipped PM5 doesn't silently drain the battery.\n"
|
||||
"Button power-on is unaffected. Disable for standalone/BLE use on battery.\n"
|
||||
_YELLOW_("Runtime only:") " resets to on at each boot.",
|
||||
"hw bwmautooff --off --> disable auto power-off\n"
|
||||
"hw bwmautooff --on --> re-enable auto power-off");
|
||||
|
||||
void *argtable[] = {
|
||||
arg_param_begin,
|
||||
@@ -1625,9 +1625,15 @@ static int CmdBWMWifi(const char *Cmd) {
|
||||
data[n++] = BWM_WIFI_ACTION_START;
|
||||
data[n++] = (uint8_t)(port & 0xFF);
|
||||
data[n++] = (uint8_t)((port >> 8) & 0xFF);
|
||||
memcpy(&data[n], ssid, ssid_len); n += ssid_len; data[n++] = 0;
|
||||
memcpy(&data[n], pwd, pwd_len); n += pwd_len; data[n++] = 0;
|
||||
memcpy(&data[n], host, host_len); n += host_len; data[n++] = 0;
|
||||
memcpy(&data[n], ssid, ssid_len);
|
||||
n += ssid_len;
|
||||
data[n++] = 0;
|
||||
memcpy(&data[n], pwd, pwd_len);
|
||||
n += pwd_len;
|
||||
data[n++] = 0;
|
||||
memcpy(&data[n], host, host_len);
|
||||
n += host_len;
|
||||
data[n++] = 0;
|
||||
|
||||
PrintAndLogEx(INFO, "Bringing up BWM WiFi (SSID \"%s\", port %d)... this can take ~15s", ssid, port);
|
||||
|
||||
@@ -2000,7 +2006,7 @@ static int CmdPM5Ant(const char *Cmd) {
|
||||
.reg_type = rw_map ? 1 : 0,
|
||||
};
|
||||
clearCommandBuffer();
|
||||
SendCommandNG(CMD_ANT_CONTROL_READ, (uint8_t*)&payload_read, sizeof(payload_read));
|
||||
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;
|
||||
@@ -2012,7 +2018,7 @@ static int CmdPM5Ant(const char *Cmd) {
|
||||
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) {
|
||||
if (io != (uint64_t) -1) {
|
||||
struct {
|
||||
uint8_t data;
|
||||
uint8_t reg_type; // 0 is io reg, 1 is map reg.
|
||||
@@ -2021,7 +2027,7 @@ static int CmdPM5Ant(const char *Cmd) {
|
||||
.data = io & 0xFF,
|
||||
};
|
||||
clearCommandBuffer();
|
||||
SendCommandNG(CMD_ANT_CONTROL_WRITE, (uint8_t*)&payload_write, sizeof(payload_write));
|
||||
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;
|
||||
@@ -2077,14 +2083,14 @@ static int CmdDeviceFactoryData(const char *Cmd) {
|
||||
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)));
|
||||
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)));
|
||||
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)));
|
||||
sprint_hex_inrow(factory->info.aes_key, sizeof(factory->info.aes_key)));
|
||||
}
|
||||
|
||||
// If data is provided, it needs to be written
|
||||
@@ -2100,7 +2106,7 @@ static int CmdDeviceFactoryData(const char *Cmd) {
|
||||
|
||||
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);
|
||||
"of the factory data read from device (%u)."), datalen, (unsigned int)resp.length);
|
||||
free(data);
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
@@ -2550,7 +2556,7 @@ void pm3_version(bool verbose, bool oneliner) {
|
||||
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);
|
||||
char *uniqueid_hex = sprint_hex_inrow(resp.data.asBytes, resp.length);
|
||||
PrintAndLogEx(NORMAL, " --= Processor Unique ID: " _YELLOW_("0x%s"), uniqueid_hex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -910,11 +910,11 @@ static int CmdSmartReader(const char *Cmd) {
|
||||
// ISO/IEC 7816-3 tables 7 and 8, so the negotiated rate can be printed back.
|
||||
static const uint16_t pps_fi_table[16] = {
|
||||
372, 372, 558, 744, 1116, 1488, 1860, 0,
|
||||
0, 512, 768, 1024, 1536, 2048, 0, 0
|
||||
0, 512, 768, 1024, 1536, 2048, 0, 0
|
||||
};
|
||||
static const uint8_t pps_di_table[16] = {
|
||||
0, 1, 2, 4, 8, 16, 32, 64,
|
||||
12, 20, 0, 0, 0, 0, 0, 0
|
||||
0, 1, 2, 4, 8, 16, 32, 64,
|
||||
12, 20, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
static int CmdSmartPPS(const char *Cmd) {
|
||||
|
||||
@@ -2354,9 +2354,9 @@ int loadFileJSONex(const char *preferredName, void *data, size_t maxdatalen, siz
|
||||
} hdr[] = {
|
||||
{ "$.Card.uid", tag->uid, sizeof(tag->uid), true },
|
||||
{ "$.Card.dsfid", &tag->dsfid, 1, false },
|
||||
{ "$.Card.dsfidlock", (uint8_t *)&tag->dsfidLock, 1, false },
|
||||
{ "$.Card.dsfidlock", (uint8_t *) &tag->dsfidLock, 1, false },
|
||||
{ "$.Card.afi", &tag->afi, 1, false },
|
||||
{ "$.Card.afilock", (uint8_t *)&tag->afiLock, 1, false },
|
||||
{ "$.Card.afilock", (uint8_t *) &tag->afiLock, 1, false },
|
||||
{ "$.Card.bytesperpage", &tag->bytesPerPage, 1, true },
|
||||
{ "$.Card.pagescount", pagescount, is_v5 ? 2 : 1, true },
|
||||
};
|
||||
@@ -2393,7 +2393,7 @@ int loadFileJSONex(const char *preferredName, void *data, size_t maxdatalen, siz
|
||||
{ "$.Card.locks", tag->locks, tag->pagesCount },
|
||||
{ "$.Card.random", tag->random, sizeof(tag->random) },
|
||||
{ "$.Card.privacypasswd", tag->privacyPasswd, sizeof(tag->privacyPasswd) },
|
||||
{ "$.Card.state", (uint8_t *)&tag->state, 1 },
|
||||
{ "$.Card.state", (uint8_t *) &tag->state, 1 },
|
||||
};
|
||||
|
||||
for (size_t n = 0; n < ARRAYLEN(rest); n++) {
|
||||
|
||||
+2
-2
@@ -288,7 +288,7 @@ static int check_segs(flash_file_t *ctx, int can_write_bl, flash_dev_t *flash_de
|
||||
static int print_and_validate_version(flash_file_t *ctx) {
|
||||
if (!CheckValidInformationMagic(ctx->ver_info)) {
|
||||
PrintAndLogEx(ERR, _RED_("ELF file does not contain valid version information"
|
||||
"(magic = 0x%08x)"), ctx->ver_info->magic);
|
||||
"(magic = 0x%08x)"), ctx->ver_info->magic);
|
||||
return PM3_EFILE;
|
||||
}
|
||||
|
||||
@@ -733,7 +733,7 @@ int flash_start_flashing(int enable_bl_writes, char *serial_port_name, flash_dev
|
||||
PrintAndLogEx(ERR, _RED_("Bootloader does not support CMD_CHIP_TYPE, assuming AT91 platform"));
|
||||
flash_dev->chiptype = MAIN_CHIP_TYPE_AT91;
|
||||
flash_suggest_update_bootloader(bl_targeted);
|
||||
// break; -> Don't break !!! We want to execute the code for MAIN_CHIP_TYPE_AT91 as well to initialize flash_dev with correct values.
|
||||
// break; -> Don't break !!! We want to execute the code for MAIN_CHIP_TYPE_AT91 as well to initialize flash_dev with correct values.
|
||||
|
||||
case MAIN_CHIP_TYPE_AT91:
|
||||
default:
|
||||
|
||||
+112
-112
@@ -622,130 +622,130 @@ void invert_hash0(uint8_t k[8]) {
|
||||
|
||||
for (int zp_i = 0; zp_i < zP_count; zp_i++) {
|
||||
|
||||
uint64_t zP = zP_list[zp_i];
|
||||
if (g_debugMode > 0) printState("0|0|z'", zP);
|
||||
uint64_t zP = zP_list[zp_i];
|
||||
if (g_debugMode > 0) printState("0|0|z'", zP);
|
||||
|
||||
// reverse the modulo transformation in the hash0 function for the six-bit chunks
|
||||
// reverse the modulo transformation in the hash0 function for the six-bit chunks
|
||||
|
||||
uint64_t c = 0;
|
||||
uint64_t c = 0;
|
||||
|
||||
for (int n = 0; n < 4; n++) {
|
||||
uint8_t _zn = getSixBitByte(zP, n);
|
||||
uint8_t _zn4 = getSixBitByte(zP, n + 4);
|
||||
for (int n = 0; n < 4; n++) {
|
||||
uint8_t _zn = getSixBitByte(zP, n);
|
||||
uint8_t _zn4 = getSixBitByte(zP, n + 4);
|
||||
|
||||
uint8_t zn = (_zn + (63 - 2 * n)) % (63 - n);
|
||||
uint8_t zn4 = (_zn4 + (64 - 2 * n)) % (64 - n);
|
||||
|
||||
pushbackSixBitByte(&c, zn, n);
|
||||
pushbackSixBitByte(&c, zn4, n + 4);
|
||||
}
|
||||
|
||||
// The Hydra: hash0() reduces every six-bit z chunk modulo a value that
|
||||
// depends on the chunk position:
|
||||
//
|
||||
// _zn = (zn % (63 - n)) + n for n = 0..3
|
||||
// _zn4 = (zn4 % (64 - n)) + n for n = 0..3 (chunks 4..7)
|
||||
//
|
||||
// Since the modulus is smaller than 0x40 the reduction is lossy, so a
|
||||
// recovered residue r has a second pre-image at r + modulus whenever
|
||||
// that value still fits in six bits. Each such chunk forks the search.
|
||||
|
||||
// Initialize an array of pointers to uint64_t (start with one value, initialized to 0)
|
||||
uint64_t *hydra_heads = (uint64_t *)calloc(sizeof(uint64_t), 1); // Start with one uint64_t
|
||||
if (hydra_heads == NULL) {
|
||||
PrintAndLogEx(WARNING, "Failed to allocate memory");
|
||||
return;
|
||||
}
|
||||
hydra_heads[0] = 0; // Initialize first value to 0
|
||||
int heads_count = 1; // Track number of forks
|
||||
|
||||
for (int n = 0; n < 8; n++) {
|
||||
|
||||
uint8_t hydra_head = getSixBitByte(c, n);
|
||||
|
||||
// the modulus hash0() applied to this chunk, mirroring the loop there
|
||||
uint8_t modulus = (n < 4) ? (63 - n) : (64 - (n - 4));
|
||||
|
||||
// the only other value that reduces to the same residue
|
||||
uint8_t alt_head = hydra_head + modulus;
|
||||
|
||||
if (alt_head <= 0x3F) {
|
||||
|
||||
// Create new forks by duplicating existing uint64_t values
|
||||
int new_head = heads_count * 2;
|
||||
|
||||
// proper realloc pattern
|
||||
uint64_t *ptmp = (uint64_t *)realloc(hydra_heads, new_head * sizeof(uint64_t));
|
||||
if (ptmp == NULL) {
|
||||
PrintAndLogEx(WARNING, "Failed to allocate memory");
|
||||
free(hydra_heads);
|
||||
return;
|
||||
}
|
||||
hydra_heads = ptmp;
|
||||
|
||||
// keep the residue in the existing branch, the alternative in the copy
|
||||
for (int i = 0; i < heads_count; i++) {
|
||||
hydra_heads[heads_count + i] = hydra_heads[i];
|
||||
pushbackSixBitByte(&hydra_heads[i], hydra_head, n);
|
||||
pushbackSixBitByte(&hydra_heads[heads_count + i], alt_head, n);
|
||||
}
|
||||
// Update the count of total values
|
||||
heads_count = new_head;
|
||||
} else {
|
||||
// no hydra head spawns
|
||||
for (int i = 0; i < heads_count; i++) {
|
||||
pushbackSixBitByte(&hydra_heads[i], hydra_head, n);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < heads_count; i++) {
|
||||
|
||||
// restore the two most significant bytes (x and y)
|
||||
hydra_heads[i] |= ((uint64_t)x_array[img] << 56);
|
||||
hydra_heads[i] |= ((uint64_t)y << 48);
|
||||
|
||||
if (g_debugMode > 0) {
|
||||
PrintAndLogEx(DEBUG, " | x| y|z0|z1|z2|z3|z4|z5|z6|z7|");
|
||||
printState("origin_r1", hydra_heads[i]);
|
||||
}
|
||||
// reverse the swapZbalues function to get the original six-bit byte order
|
||||
uint64_t original_z = swapZvalues(hydra_heads[i]);
|
||||
|
||||
if (g_debugMode > 0) {
|
||||
PrintAndLogEx(DEBUG, " | x| y|z0|z1|z2|z3|z4|z5|z6|z7|");
|
||||
printState("origin_r2", original_z);
|
||||
PrintAndLogEx(INFO, "--------------------------");
|
||||
}
|
||||
// run pre-image through hash0
|
||||
uint8_t img_div_key[8] = {0};
|
||||
hash0(original_z, img_div_key); // commented to avoid log spam
|
||||
|
||||
// verify result, if it matches add it to the list as a valid pre-image
|
||||
bool image_match = true;
|
||||
for (int v = 0; v < 8; v++) {
|
||||
|
||||
// compare against input key k
|
||||
if (img_div_key[v] != k[v]) {
|
||||
image_match = false;
|
||||
}
|
||||
uint8_t zn = (_zn + (63 - 2 * n)) % (63 - n);
|
||||
uint8_t zn4 = (_zn4 + (64 - 2 * n)) % (64 - n);
|
||||
|
||||
pushbackSixBitByte(&c, zn, n);
|
||||
pushbackSixBitByte(&c, zn4, n + 4);
|
||||
}
|
||||
|
||||
uint8_t des_pre_image[8] = {0};
|
||||
x_num_to_bytes(original_z, sizeof(original_z), des_pre_image);
|
||||
// The Hydra: hash0() reduces every six-bit z chunk modulo a value that
|
||||
// depends on the chunk position:
|
||||
//
|
||||
// _zn = (zn % (63 - n)) + n for n = 0..3
|
||||
// _zn4 = (zn4 % (64 - n)) + n for n = 0..3 (chunks 4..7)
|
||||
//
|
||||
// Since the modulus is smaller than 0x40 the reduction is lossy, so a
|
||||
// recovered residue r has a second pre-image at r + modulus whenever
|
||||
// that value still fits in six bits. Each such chunk forks the search.
|
||||
|
||||
if (image_match) {
|
||||
PrintAndLogEx(INFO, "Pre-image......... " _YELLOW_("%s") " ( "_GREEN_("ok") " )", sprint_hex_inrow(des_pre_image, sizeof(des_pre_image)));
|
||||
} else {
|
||||
// Initialize an array of pointers to uint64_t (start with one value, initialized to 0)
|
||||
uint64_t *hydra_heads = (uint64_t *)calloc(sizeof(uint64_t), 1); // Start with one uint64_t
|
||||
if (hydra_heads == NULL) {
|
||||
PrintAndLogEx(WARNING, "Failed to allocate memory");
|
||||
return;
|
||||
}
|
||||
hydra_heads[0] = 0; // Initialize first value to 0
|
||||
int heads_count = 1; // Track number of forks
|
||||
|
||||
for (int n = 0; n < 8; n++) {
|
||||
|
||||
uint8_t hydra_head = getSixBitByte(c, n);
|
||||
|
||||
// the modulus hash0() applied to this chunk, mirroring the loop there
|
||||
uint8_t modulus = (n < 4) ? (63 - n) : (64 - (n - 4));
|
||||
|
||||
// the only other value that reduces to the same residue
|
||||
uint8_t alt_head = hydra_head + modulus;
|
||||
|
||||
if (alt_head <= 0x3F) {
|
||||
|
||||
// Create new forks by duplicating existing uint64_t values
|
||||
int new_head = heads_count * 2;
|
||||
|
||||
// proper realloc pattern
|
||||
uint64_t *ptmp = (uint64_t *)realloc(hydra_heads, new_head * sizeof(uint64_t));
|
||||
if (ptmp == NULL) {
|
||||
PrintAndLogEx(WARNING, "Failed to allocate memory");
|
||||
free(hydra_heads);
|
||||
return;
|
||||
}
|
||||
hydra_heads = ptmp;
|
||||
|
||||
// keep the residue in the existing branch, the alternative in the copy
|
||||
for (int i = 0; i < heads_count; i++) {
|
||||
hydra_heads[heads_count + i] = hydra_heads[i];
|
||||
pushbackSixBitByte(&hydra_heads[i], hydra_head, n);
|
||||
pushbackSixBitByte(&hydra_heads[heads_count + i], alt_head, n);
|
||||
}
|
||||
// Update the count of total values
|
||||
heads_count = new_head;
|
||||
} else {
|
||||
// no hydra head spawns
|
||||
for (int i = 0; i < heads_count; i++) {
|
||||
pushbackSixBitByte(&hydra_heads[i], hydra_head, n);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < heads_count; i++) {
|
||||
|
||||
// restore the two most significant bytes (x and y)
|
||||
hydra_heads[i] |= ((uint64_t)x_array[img] << 56);
|
||||
hydra_heads[i] |= ((uint64_t)y << 48);
|
||||
|
||||
if (g_debugMode > 0) {
|
||||
PrintAndLogEx(INFO, "Pre-image......... " _YELLOW_("%s") " ( "_RED_("invalid") " )", sprint_hex_inrow(des_pre_image, sizeof(des_pre_image)));
|
||||
PrintAndLogEx(DEBUG, " | x| y|z0|z1|z2|z3|z4|z5|z6|z7|");
|
||||
printState("origin_r1", hydra_heads[i]);
|
||||
}
|
||||
// reverse the swapZbalues function to get the original six-bit byte order
|
||||
uint64_t original_z = swapZvalues(hydra_heads[i]);
|
||||
|
||||
if (g_debugMode > 0) {
|
||||
PrintAndLogEx(DEBUG, " | x| y|z0|z1|z2|z3|z4|z5|z6|z7|");
|
||||
printState("origin_r2", original_z);
|
||||
PrintAndLogEx(INFO, "--------------------------");
|
||||
}
|
||||
// run pre-image through hash0
|
||||
uint8_t img_div_key[8] = {0};
|
||||
hash0(original_z, img_div_key); // commented to avoid log spam
|
||||
|
||||
// verify result, if it matches add it to the list as a valid pre-image
|
||||
bool image_match = true;
|
||||
for (int v = 0; v < 8; v++) {
|
||||
|
||||
// compare against input key k
|
||||
if (img_div_key[v] != k[v]) {
|
||||
image_match = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
uint8_t des_pre_image[8] = {0};
|
||||
x_num_to_bytes(original_z, sizeof(original_z), des_pre_image);
|
||||
|
||||
if (image_match) {
|
||||
PrintAndLogEx(INFO, "Pre-image......... " _YELLOW_("%s") " ( "_GREEN_("ok") " )", sprint_hex_inrow(des_pre_image, sizeof(des_pre_image)));
|
||||
} else {
|
||||
|
||||
if (g_debugMode > 0) {
|
||||
PrintAndLogEx(INFO, "Pre-image......... " _YELLOW_("%s") " ( "_RED_("invalid") " )", sprint_hex_inrow(des_pre_image, sizeof(des_pre_image)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Free allocated memory
|
||||
free(hydra_heads);
|
||||
// Free allocated memory
|
||||
free(hydra_heads);
|
||||
|
||||
} // for each zP candidate
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user