mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2025-12-12 04:34:43 +04:00
Merge branch 'ofw_dev' into dev
This commit is contained in:
@@ -13,41 +13,6 @@ static const uint8_t nfc_util_odd_byte_parity[256] = {
|
||||
0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
|
||||
1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1};
|
||||
|
||||
void nfc_util_num2bytes(uint64_t src, uint8_t len, uint8_t* dest) {
|
||||
furi_assert(dest);
|
||||
furi_assert(len <= 8);
|
||||
|
||||
while(len--) {
|
||||
dest[len] = (uint8_t)src;
|
||||
src >>= 8;
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t nfc_util_bytes2num(const uint8_t* src, uint8_t len) {
|
||||
furi_assert(src);
|
||||
furi_assert(len <= 8);
|
||||
|
||||
uint64_t res = 0;
|
||||
while(len--) {
|
||||
res = (res << 8) | (*src);
|
||||
src++;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
uint64_t nfc_util_bytes2num_little_endian(const uint8_t* src, uint8_t len) {
|
||||
furi_assert(src);
|
||||
furi_assert(len <= 8);
|
||||
|
||||
uint64_t res = 0;
|
||||
uint8_t shift = 0;
|
||||
while(len--) {
|
||||
res |= ((uint64_t)*src) << (8 * shift++);
|
||||
src++;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
uint8_t nfc_util_even_parity32(uint32_t data) {
|
||||
// data ^= data >> 16;
|
||||
// data ^= data >> 8;
|
||||
|
||||
@@ -6,12 +6,6 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void nfc_util_num2bytes(uint64_t src, uint8_t len, uint8_t* dest);
|
||||
|
||||
uint64_t nfc_util_bytes2num(const uint8_t* src, uint8_t len);
|
||||
|
||||
uint64_t nfc_util_bytes2num_little_endian(const uint8_t* src, uint8_t len);
|
||||
|
||||
uint8_t nfc_util_even_parity32(uint32_t data);
|
||||
|
||||
uint8_t nfc_util_odd_parity8(uint8_t data);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "crypto1.h"
|
||||
|
||||
#include <lib/nfc/helpers/nfc_util.h>
|
||||
#include <lib/bit_lib/bit_lib.h>
|
||||
#include <furi.h>
|
||||
|
||||
// Algorithm from https://github.com/RfidResearchGroup/proxmark3.git
|
||||
@@ -151,7 +152,7 @@ void crypto1_encrypt_reader_nonce(
|
||||
furi_assert(out);
|
||||
|
||||
bit_buffer_set_size_bytes(out, 8);
|
||||
uint32_t nt_num = nfc_util_bytes2num(nt, sizeof(uint32_t));
|
||||
uint32_t nt_num = bit_lib_bytes_to_num_be(nt, sizeof(uint32_t));
|
||||
|
||||
crypto1_init(crypto, key);
|
||||
if(is_nested) {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <furi/furi.h>
|
||||
#include <toolbox/hex.h>
|
||||
|
||||
#include <lib/nfc/helpers/nfc_util.h>
|
||||
#include <lib/bit_lib/bit_lib.h>
|
||||
|
||||
#define MF_CLASSIC_PROTOCOL_NAME "Mifare Classic"
|
||||
|
||||
@@ -121,7 +121,8 @@ static void mf_classic_parse_block(FuriString* block_str, MfClassicData* data, u
|
||||
// Load Key A
|
||||
// Key A mask 0b0000000000111111 = 0x003f
|
||||
if((block_unknown_bytes_mask & 0x003f) == 0) {
|
||||
uint64_t key = nfc_util_bytes2num(sec_tr_tmp->key_a.data, sizeof(MfClassicKey));
|
||||
uint64_t key =
|
||||
bit_lib_bytes_to_num_be(sec_tr_tmp->key_a.data, sizeof(MfClassicKey));
|
||||
mf_classic_set_key_found(data, sector_num, MfClassicKeyTypeA, key);
|
||||
}
|
||||
// Load Access Bits
|
||||
@@ -132,7 +133,8 @@ static void mf_classic_parse_block(FuriString* block_str, MfClassicData* data, u
|
||||
// Load Key B
|
||||
// Key B mask 0b1111110000000000 = 0xfc00
|
||||
if((block_unknown_bytes_mask & 0xfc00) == 0) {
|
||||
uint64_t key = nfc_util_bytes2num(sec_tr_tmp->key_b.data, sizeof(MfClassicKey));
|
||||
uint64_t key =
|
||||
bit_lib_bytes_to_num_be(sec_tr_tmp->key_b.data, sizeof(MfClassicKey));
|
||||
mf_classic_set_key_found(data, sector_num, MfClassicKeyTypeB, key);
|
||||
}
|
||||
} else {
|
||||
@@ -493,7 +495,7 @@ void mf_classic_set_key_found(
|
||||
uint8_t key_arr[6] = {};
|
||||
MfClassicSectorTrailer* sec_trailer =
|
||||
mf_classic_get_sector_trailer_by_sector(data, sector_num);
|
||||
nfc_util_num2bytes(key, 6, key_arr);
|
||||
bit_lib_num_to_bytes_be(key, 6, key_arr);
|
||||
if(key_type == MfClassicKeyTypeA) {
|
||||
memcpy(sec_trailer->key_a.data, key_arr, sizeof(MfClassicKey));
|
||||
FURI_BIT_SET(data->key_a_mask, sector_num);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <nfc/protocols/nfc_listener_base.h>
|
||||
|
||||
#include <nfc/helpers/iso14443_crc.h>
|
||||
#include <nfc/helpers/nfc_util.h>
|
||||
#include <bit_lib/bit_lib.h>
|
||||
|
||||
#include <furi.h>
|
||||
#include <furi_hal_random.h>
|
||||
@@ -68,14 +68,15 @@ static MfClassicListenerCommand mf_classic_listener_auth_first_part_handler(
|
||||
MfClassicSectorTrailer* sec_tr =
|
||||
mf_classic_get_sector_trailer_by_sector(instance->data, sector_num);
|
||||
MfClassicKey* key = (key_type == MfClassicKeyTypeA) ? &sec_tr->key_a : &sec_tr->key_b;
|
||||
uint64_t key_num = nfc_util_bytes2num(key->data, sizeof(MfClassicKey));
|
||||
uint64_t key_num = bit_lib_bytes_to_num_be(key->data, sizeof(MfClassicKey));
|
||||
uint32_t cuid = iso14443_3a_get_cuid(instance->data->iso14443_3a_data);
|
||||
|
||||
instance->auth_context.key_type = key_type;
|
||||
instance->auth_context.block_num = block_num;
|
||||
|
||||
furi_hal_random_fill_buf(instance->auth_context.nt.data, sizeof(MfClassicNt));
|
||||
uint32_t nt_num = nfc_util_bytes2num(instance->auth_context.nt.data, sizeof(MfClassicNt));
|
||||
uint32_t nt_num =
|
||||
bit_lib_bytes_to_num_be(instance->auth_context.nt.data, sizeof(MfClassicNt));
|
||||
|
||||
crypto1_init(instance->crypto, key_num);
|
||||
if(instance->comm_state == MfClassicListenerCommStatePlain) {
|
||||
@@ -88,7 +89,7 @@ static MfClassicListenerCommand mf_classic_listener_auth_first_part_handler(
|
||||
command = MfClassicListenerCommandProcessed;
|
||||
} else {
|
||||
uint8_t key_stream[4] = {};
|
||||
nfc_util_num2bytes(nt_num ^ cuid, sizeof(uint32_t), key_stream);
|
||||
bit_lib_num_to_bytes_be(nt_num ^ cuid, sizeof(uint32_t), key_stream);
|
||||
bit_buffer_copy_bytes(
|
||||
instance->tx_plain_buffer, instance->auth_context.nt.data, sizeof(MfClassicNt));
|
||||
crypto1_encrypt(
|
||||
@@ -147,11 +148,14 @@ static MfClassicListenerCommand
|
||||
instance->callback(instance->generic_event, instance->context);
|
||||
}
|
||||
|
||||
uint32_t nr_num = nfc_util_bytes2num(instance->auth_context.nr.data, sizeof(MfClassicNr));
|
||||
uint32_t ar_num = nfc_util_bytes2num(instance->auth_context.ar.data, sizeof(MfClassicAr));
|
||||
uint32_t nr_num =
|
||||
bit_lib_bytes_to_num_be(instance->auth_context.nr.data, sizeof(MfClassicNr));
|
||||
uint32_t ar_num =
|
||||
bit_lib_bytes_to_num_be(instance->auth_context.ar.data, sizeof(MfClassicAr));
|
||||
|
||||
crypto1_word(instance->crypto, nr_num, 1);
|
||||
uint32_t nt_num = nfc_util_bytes2num(instance->auth_context.nt.data, sizeof(MfClassicNt));
|
||||
uint32_t nt_num =
|
||||
bit_lib_bytes_to_num_be(instance->auth_context.nt.data, sizeof(MfClassicNt));
|
||||
uint32_t secret_poller = ar_num ^ crypto1_word(instance->crypto, 0, 0);
|
||||
if(secret_poller != prng_successor(nt_num, 64)) {
|
||||
FURI_LOG_T(
|
||||
@@ -161,7 +165,7 @@ static MfClassicListenerCommand
|
||||
}
|
||||
|
||||
uint32_t at_num = prng_successor(nt_num, 96);
|
||||
nfc_util_num2bytes(at_num, sizeof(uint32_t), instance->auth_context.at.data);
|
||||
bit_lib_num_to_bytes_be(at_num, sizeof(uint32_t), instance->auth_context.at.data);
|
||||
bit_buffer_copy_bytes(
|
||||
instance->tx_plain_buffer, instance->auth_context.at.data, sizeof(MfClassicAr));
|
||||
crypto1_encrypt(
|
||||
|
||||
@@ -73,7 +73,7 @@ static void mf_classic_poller_check_key_b_is_readable(
|
||||
break;
|
||||
|
||||
MfClassicSectorTrailer* sec_tr = (MfClassicSectorTrailer*)data;
|
||||
uint64_t key_b = nfc_util_bytes2num(sec_tr->key_b.data, sizeof(MfClassicKey));
|
||||
uint64_t key_b = bit_lib_bytes_to_num_be(sec_tr->key_b.data, sizeof(MfClassicKey));
|
||||
uint8_t sector_num = mf_classic_get_sector_by_block(block_num);
|
||||
mf_classic_set_key_found(instance->data, sector_num, MfClassicKeyTypeB, key_b);
|
||||
} while(false);
|
||||
@@ -456,7 +456,7 @@ NfcCommand mf_classic_poller_handler_request_read_sector_blocks(MfClassicPoller*
|
||||
MfClassicError error = MfClassicErrorNone;
|
||||
|
||||
if(!sec_read_ctx->auth_passed) {
|
||||
uint64_t key = nfc_util_bytes2num(sec_read_ctx->key.data, sizeof(MfClassicKey));
|
||||
uint64_t key = bit_lib_bytes_to_num_be(sec_read_ctx->key.data, sizeof(MfClassicKey));
|
||||
FURI_LOG_D(
|
||||
TAG,
|
||||
"Auth to block %d with key %c: %06llx",
|
||||
@@ -530,7 +530,8 @@ NfcCommand mf_classic_poller_handler_auth_a(MfClassicPoller* instance) {
|
||||
instance->state = MfClassicPollerStateAuthKeyB;
|
||||
} else {
|
||||
uint8_t block = mf_classic_get_first_block_num_of_sector(dict_attack_ctx->current_sector);
|
||||
uint64_t key = nfc_util_bytes2num(dict_attack_ctx->current_key.data, sizeof(MfClassicKey));
|
||||
uint64_t key =
|
||||
bit_lib_bytes_to_num_be(dict_attack_ctx->current_key.data, sizeof(MfClassicKey));
|
||||
FURI_LOG_D(TAG, "Auth to block %d with key A: %06llx", block, key);
|
||||
|
||||
MfClassicError error = mf_classic_poller_auth(
|
||||
@@ -568,7 +569,8 @@ NfcCommand mf_classic_poller_handler_auth_b(MfClassicPoller* instance) {
|
||||
}
|
||||
} else {
|
||||
uint8_t block = mf_classic_get_first_block_num_of_sector(dict_attack_ctx->current_sector);
|
||||
uint64_t key = nfc_util_bytes2num(dict_attack_ctx->current_key.data, sizeof(MfClassicKey));
|
||||
uint64_t key =
|
||||
bit_lib_bytes_to_num_be(dict_attack_ctx->current_key.data, sizeof(MfClassicKey));
|
||||
FURI_LOG_D(TAG, "Auth to block %d with key B: %06llx", block, key);
|
||||
|
||||
MfClassicError error = mf_classic_poller_auth(
|
||||
@@ -711,7 +713,8 @@ NfcCommand mf_classic_poller_handler_key_reuse_auth_key_a(MfClassicPoller* insta
|
||||
} else {
|
||||
uint8_t block =
|
||||
mf_classic_get_first_block_num_of_sector(dict_attack_ctx->reuse_key_sector);
|
||||
uint64_t key = nfc_util_bytes2num(dict_attack_ctx->current_key.data, sizeof(MfClassicKey));
|
||||
uint64_t key =
|
||||
bit_lib_bytes_to_num_be(dict_attack_ctx->current_key.data, sizeof(MfClassicKey));
|
||||
FURI_LOG_D(TAG, "Key attack auth to block %d with key A: %06llx", block, key);
|
||||
|
||||
MfClassicError error = mf_classic_poller_auth(
|
||||
@@ -746,7 +749,8 @@ NfcCommand mf_classic_poller_handler_key_reuse_auth_key_b(MfClassicPoller* insta
|
||||
} else {
|
||||
uint8_t block =
|
||||
mf_classic_get_first_block_num_of_sector(dict_attack_ctx->reuse_key_sector);
|
||||
uint64_t key = nfc_util_bytes2num(dict_attack_ctx->current_key.data, sizeof(MfClassicKey));
|
||||
uint64_t key =
|
||||
bit_lib_bytes_to_num_be(dict_attack_ctx->current_key.data, sizeof(MfClassicKey));
|
||||
FURI_LOG_D(TAG, "Key attack auth to block %d with key B: %06llx", block, key);
|
||||
|
||||
MfClassicError error = mf_classic_poller_auth(
|
||||
|
||||
@@ -128,7 +128,7 @@ static MfClassicError mf_classic_poller_auth_common(
|
||||
}
|
||||
|
||||
uint32_t cuid = iso14443_3a_get_cuid(instance->data->iso14443_3a_data);
|
||||
uint64_t key_num = nfc_util_bytes2num(key->data, sizeof(MfClassicKey));
|
||||
uint64_t key_num = bit_lib_bytes_to_num_be(key->data, sizeof(MfClassicKey));
|
||||
MfClassicNr nr = {};
|
||||
furi_hal_random_fill_buf(nr.data, sizeof(MfClassicNr));
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include "mf_classic_poller.h"
|
||||
#include <lib/nfc/protocols/iso14443_3a/iso14443_3a_poller_i.h>
|
||||
#include <lib/nfc/helpers/nfc_util.h>
|
||||
#include <bit_lib/bit_lib.h>
|
||||
#include "crypto1.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "mf_ultralight.h"
|
||||
|
||||
#include <nfc/helpers/nfc_util.h>
|
||||
#include <bit_lib/bit_lib.h>
|
||||
#include <furi.h>
|
||||
|
||||
#define MF_ULTRALIGHT_PROTOCOL_NAME "NTAG/Ultralight"
|
||||
@@ -603,10 +603,10 @@ bool mf_ultralight_is_all_data_read(const MfUltralightData* data) {
|
||||
} else {
|
||||
MfUltralightConfigPages* config = NULL;
|
||||
if(mf_ultralight_get_config_page(data, &config)) {
|
||||
uint32_t pass =
|
||||
nfc_util_bytes2num(config->password.data, sizeof(MfUltralightAuthPassword));
|
||||
uint32_t pass = bit_lib_bytes_to_num_be(
|
||||
config->password.data, sizeof(MfUltralightAuthPassword));
|
||||
uint16_t pack =
|
||||
nfc_util_bytes2num(config->pack.data, sizeof(MfUltralightAuthPack));
|
||||
bit_lib_bytes_to_num_be(config->pack.data, sizeof(MfUltralightAuthPack));
|
||||
all_read = ((pass != 0) || (pack != 0));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -417,7 +417,7 @@ static NfcCommand mf_ultralight_poller_handler_auth(MfUltralightPoller* instance
|
||||
command = instance->callback(instance->general_event, instance->context);
|
||||
if(!instance->mfu_event.data->auth_context.skip_auth) {
|
||||
instance->auth_context.password = instance->mfu_event.data->auth_context.password;
|
||||
uint32_t pass = nfc_util_bytes2num(
|
||||
uint32_t pass = bit_lib_bytes_to_num_be(
|
||||
instance->auth_context.password.data, sizeof(MfUltralightAuthPassword));
|
||||
FURI_LOG_D(TAG, "Trying to authenticate with password %08lX", pass);
|
||||
instance->error = mf_ultralight_poller_auth_pwd(instance, &instance->auth_context);
|
||||
@@ -497,14 +497,14 @@ static NfcCommand mf_ultralight_poller_handler_try_default_pass(MfUltralightPoll
|
||||
config->pack = instance->auth_context.pack;
|
||||
} else if(config->access.authlim == 0) {
|
||||
FURI_LOG_D(TAG, "No limits in authentication. Trying default password");
|
||||
nfc_util_num2bytes(
|
||||
bit_lib_num_to_bytes_be(
|
||||
MF_ULTRALIGHT_DEFAULT_PASSWORD,
|
||||
sizeof(MfUltralightAuthPassword),
|
||||
instance->auth_context.password.data);
|
||||
instance->error = mf_ultralight_poller_auth_pwd(instance, &instance->auth_context);
|
||||
if(instance->error == MfUltralightErrorNone) {
|
||||
FURI_LOG_D(TAG, "Default password detected");
|
||||
nfc_util_num2bytes(
|
||||
bit_lib_num_to_bytes_be(
|
||||
MF_ULTRALIGHT_DEFAULT_PASSWORD,
|
||||
sizeof(MfUltralightAuthPassword),
|
||||
config->password.data);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include "mf_ultralight_poller.h"
|
||||
#include <lib/nfc/protocols/iso14443_3a/iso14443_3a_poller_i.h>
|
||||
#include <lib/nfc/helpers/nfc_util.h>
|
||||
#include <lib/bit_lib/bit_lib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "slix_poller_i.h"
|
||||
#include <nfc/helpers/nfc_util.h>
|
||||
#include <bit_lib/bit_lib.h>
|
||||
|
||||
#include <furi.h>
|
||||
|
||||
@@ -107,7 +107,7 @@ SlixError
|
||||
uint32_t double_rand_num = (rn_h << 24) | (rn_l << 16) | (rn_h << 8) | rn_l;
|
||||
uint32_t xored_password = double_rand_num ^ password;
|
||||
uint8_t xored_password_arr[4] = {};
|
||||
nfc_util_num2bytes(xored_password, 4, xored_password_arr);
|
||||
bit_lib_num_to_bytes_be(xored_password, 4, xored_password_arr);
|
||||
bit_buffer_append_bytes(instance->tx_buffer, xored_password_arr, 4);
|
||||
|
||||
SlixError error = SlixErrorNone;
|
||||
|
||||
Reference in New Issue
Block a user