mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-07-26 01:48:10 -07:00
further mergability updates
This commit is contained in:
@@ -46,14 +46,23 @@ typedef struct {
|
||||
|
||||
|
||||
DigitalSignal* digital_signal_alloc(uint32_t max_edges_cnt);
|
||||
|
||||
void digital_signal_free(DigitalSignal* signal);
|
||||
|
||||
void digital_signal_add(DigitalSignal* signal, uint32_t ticks);
|
||||
|
||||
void digital_signal_add_pulse(DigitalSignal* signal, uint32_t ticks, bool level);
|
||||
|
||||
bool digital_signal_append(DigitalSignal* signal_a, DigitalSignal* signal_b);
|
||||
|
||||
void digital_signal_prepare(DigitalSignal* signal);
|
||||
|
||||
bool digital_signal_get_start_level(DigitalSignal* signal);
|
||||
|
||||
uint32_t digital_signal_get_edges_cnt(DigitalSignal* signal);
|
||||
|
||||
uint32_t digital_signal_get_edge(DigitalSignal* signal, uint32_t edge_num);
|
||||
|
||||
void digital_signal_send(DigitalSignal* signal, const GpioPin* gpio);
|
||||
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ uint32_t crypto1_filter(uint32_t in) {
|
||||
return FURI_BIT(0xEC57E80A, out);
|
||||
}
|
||||
|
||||
static inline uint8_t crypto1_bit(Crypto1* crypto1, uint8_t in, int is_encrypted) {
|
||||
uint8_t crypto1_bit(Crypto1* crypto1, uint8_t in, int is_encrypted) {
|
||||
furi_assert(crypto1);
|
||||
uint8_t out = crypto1_filter(crypto1->odd);
|
||||
uint32_t feed = out & (!!is_encrypted);
|
||||
@@ -58,15 +58,6 @@ uint8_t crypto1_byte(Crypto1* crypto1, uint8_t in, int is_encrypted) {
|
||||
return out;
|
||||
}
|
||||
|
||||
static inline uint8_t crypto1_byte_inline(Crypto1* crypto1, uint8_t in, int is_encrypted) {
|
||||
furi_assert(crypto1);
|
||||
uint8_t out = 0;
|
||||
for(uint8_t i = 0; i < 8; i++) {
|
||||
out |= crypto1_bit(crypto1, FURI_BIT(in, i), is_encrypted) << i;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
uint32_t crypto1_word(Crypto1* crypto1, uint32_t in, int is_encrypted) {
|
||||
furi_assert(crypto1);
|
||||
uint32_t out = 0;
|
||||
@@ -101,7 +92,7 @@ void crypto1_decrypt(
|
||||
decrypted_data[0] = decrypted_byte;
|
||||
} else {
|
||||
for(size_t i = 0; i < encrypted_data_bits / 8; i++) {
|
||||
decrypted_data[i] = crypto1_byte_inline(crypto, 0, 0) ^ encrypted_data[i];
|
||||
decrypted_data[i] = crypto1_byte(crypto, 0, 0) ^ encrypted_data[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -126,7 +117,7 @@ void crypto1_encrypt(
|
||||
} else {
|
||||
memset(encrypted_parity, 0, plain_data_bits / 8 + 1);
|
||||
for(uint8_t i = 0; i < plain_data_bits / 8; i++) {
|
||||
encrypted_data[i] = crypto1_byte_inline(crypto, keystream ? keystream[i] : 0, 0) ^
|
||||
encrypted_data[i] = crypto1_byte(crypto, keystream ? keystream[i] : 0, 0) ^
|
||||
plain_data[i];
|
||||
encrypted_parity[i / 8] |=
|
||||
(((crypto1_filter(crypto->odd) ^ nfc_util_odd_parity8(plain_data[i])) & 0x01)
|
||||
|
||||
@@ -12,7 +12,7 @@ void crypto1_reset(Crypto1* crypto1);
|
||||
|
||||
void crypto1_init(Crypto1* crypto1, uint64_t key);
|
||||
|
||||
//uint8_t crypto1_bit(Crypto1* crypto1, uint8_t in, int is_encrypted);
|
||||
uint8_t crypto1_bit(Crypto1* crypto1, uint8_t in, int is_encrypted);
|
||||
|
||||
uint8_t crypto1_byte(Crypto1* crypto1, uint8_t in, int is_encrypted);
|
||||
|
||||
|
||||
@@ -763,39 +763,26 @@ bool mf_classic_emulator(MfClassicEmulator* emulator, FuriHalNfcTxRxContext* tx_
|
||||
uint8_t plain_data[MF_CLASSIC_MAX_DATA_SIZE];
|
||||
MfClassicKey access_key = MfClassicKeyA;
|
||||
|
||||
tx_rx->tx_rx_type = FuriHalNfcTxRxFullyTransparent;
|
||||
|
||||
FURI_LOG_D(TAG, "Starting mf_classic_emulator");
|
||||
|
||||
// Read command
|
||||
while(!command_processed) {
|
||||
if(!is_encrypted) {
|
||||
crypto1_reset(&emulator->crypto);
|
||||
memcpy(plain_data, tx_rx->rx_data, tx_rx->rx_bits / 8);
|
||||
} else {
|
||||
tx_rx->rx_bits = 0;
|
||||
if(!furi_hal_nfc_tx_rx(tx_rx, 300)) {
|
||||
FURI_LOG_D(
|
||||
TAG,
|
||||
"Error in tx rx. Tx :%d bits, Rx: %d bits. Received:",
|
||||
"Error in tx rx. Tx :%d bits, Rx: %d bits",
|
||||
tx_rx->tx_bits,
|
||||
tx_rx->rx_bits);
|
||||
|
||||
FURI_LOG_D(TAG,"Sent:");
|
||||
for(int pos = 0; pos < tx_rx->tx_bits/8; pos++) {
|
||||
FURI_LOG_D(TAG," %02X", tx_rx->tx_data[pos]);
|
||||
}
|
||||
FURI_LOG_D(TAG,"Received:");
|
||||
for(int pos = 0; pos < tx_rx->rx_bits/8; pos++) {
|
||||
FURI_LOG_D(TAG," %02X", tx_rx->rx_data[pos]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
crypto1_decrypt(&emulator->crypto, tx_rx->rx_data, tx_rx->rx_bits, plain_data);
|
||||
}
|
||||
|
||||
if(plain_data[0] == 0x50 && plain_data[1] == 0x00) {
|
||||
//furi_hal_nfc_listen_sleep();
|
||||
FURI_LOG_T(TAG, "Halt received");
|
||||
furi_hal_nfc_listen_sleep();
|
||||
command_processed = true;
|
||||
break;
|
||||
} else if(plain_data[0] == 0x60 || plain_data[0] == 0x61) {
|
||||
@@ -812,7 +799,7 @@ bool mf_classic_emulator(MfClassicEmulator* emulator, FuriHalNfcTxRxContext* tx_
|
||||
access_key = MfClassicKeyB;
|
||||
}
|
||||
|
||||
uint32_t nonce = prng_successor(DWT->CYCCNT, 2) ^ 0xAA;
|
||||
uint32_t nonce = prng_successor(DWT->CYCCNT, 32) ^ 0xAA;
|
||||
uint8_t nt[4];
|
||||
uint8_t nt_keystream[4];
|
||||
nfc_util_num2bytes(nonce, 4, nt);
|
||||
@@ -820,15 +807,13 @@ bool mf_classic_emulator(MfClassicEmulator* emulator, FuriHalNfcTxRxContext* tx_
|
||||
crypto1_init(&emulator->crypto, key);
|
||||
if(!is_encrypted) {
|
||||
crypto1_word(&emulator->crypto, emulator->cuid ^ nonce, 0);
|
||||
for(size_t pos = 0; pos < sizeof(nt); pos++) {
|
||||
tx_rx->tx_data[pos] = nt[pos];
|
||||
}
|
||||
memcpy(tx_rx->tx_data, nt, sizeof(nt));
|
||||
tx_rx->tx_parity[0] = 0;
|
||||
for(size_t i = 0; i < sizeof(nt); i++) {
|
||||
tx_rx->tx_parity[0] |= nfc_util_odd_parity8(nt[i]) << (7 - i);
|
||||
}
|
||||
tx_rx->tx_bits = sizeof(nt) * 8;
|
||||
tx_rx->tx_rx_type = FuriHalNfcTxRxFullyTransparent;
|
||||
tx_rx->tx_rx_type = FuriHalNfcTxRxTransparent;
|
||||
} else {
|
||||
crypto1_encrypt(
|
||||
&emulator->crypto,
|
||||
@@ -838,10 +823,10 @@ bool mf_classic_emulator(MfClassicEmulator* emulator, FuriHalNfcTxRxContext* tx_
|
||||
tx_rx->tx_data,
|
||||
tx_rx->tx_parity);
|
||||
tx_rx->tx_bits = sizeof(nt) * 8;
|
||||
tx_rx->tx_rx_type = FuriHalNfcTxRxFullyTransparent;
|
||||
tx_rx->tx_rx_type = FuriHalNfcTxRxTransparent;
|
||||
}
|
||||
if(!furi_hal_nfc_tx_rx(tx_rx, 500)) {
|
||||
FURI_LOG_E(TAG, "Error in NT exchange?");
|
||||
FURI_LOG_E(TAG, "Error in NT exchange");
|
||||
command_processed = true;
|
||||
break;
|
||||
}
|
||||
@@ -854,7 +839,7 @@ bool mf_classic_emulator(MfClassicEmulator* emulator, FuriHalNfcTxRxContext* tx_
|
||||
|
||||
uint32_t nr = nfc_util_bytes2num(tx_rx->rx_data, 4);
|
||||
uint32_t ar = nfc_util_bytes2num(&tx_rx->rx_data[4], 4);
|
||||
/*
|
||||
|
||||
FURI_LOG_D(
|
||||
TAG,
|
||||
"%08lx key%c block %d nt/nr/ar: %08lx %08lx %08lx",
|
||||
@@ -864,7 +849,7 @@ bool mf_classic_emulator(MfClassicEmulator* emulator, FuriHalNfcTxRxContext* tx_
|
||||
nonce,
|
||||
nr,
|
||||
ar);
|
||||
*/
|
||||
|
||||
crypto1_word(&emulator->crypto, nr, 1);
|
||||
uint32_t cardRr = ar ^ crypto1_word(&emulator->crypto, 0, 0);
|
||||
if(cardRr != prng_successor(nonce, 64)) {
|
||||
@@ -885,7 +870,7 @@ bool mf_classic_emulator(MfClassicEmulator* emulator, FuriHalNfcTxRxContext* tx_
|
||||
tx_rx->tx_data,
|
||||
tx_rx->tx_parity);
|
||||
tx_rx->tx_bits = sizeof(responce) * 8;
|
||||
tx_rx->tx_rx_type = FuriHalNfcTxRxFullyTransparent;
|
||||
tx_rx->tx_rx_type = FuriHalNfcTxRxTransparent;
|
||||
|
||||
is_encrypted = true;
|
||||
} else if(is_encrypted && plain_data[0] == 0x30) {
|
||||
@@ -916,7 +901,7 @@ bool mf_classic_emulator(MfClassicEmulator* emulator, FuriHalNfcTxRxContext* tx_
|
||||
} else {
|
||||
tx_rx->tx_data[0] = nack;
|
||||
}
|
||||
tx_rx->tx_rx_type = FuriHalNfcTxRxFullyTransparent;
|
||||
tx_rx->tx_rx_type = FuriHalNfcTxRxTransparent;
|
||||
tx_rx->tx_bits = 4;
|
||||
furi_hal_nfc_tx_rx(tx_rx, 300);
|
||||
break;
|
||||
@@ -932,7 +917,7 @@ bool mf_classic_emulator(MfClassicEmulator* emulator, FuriHalNfcTxRxContext* tx_
|
||||
tx_rx->tx_data,
|
||||
tx_rx->tx_parity);
|
||||
tx_rx->tx_bits = 18 * 8;
|
||||
tx_rx->tx_rx_type = FuriHalNfcTxRxFullyTransparent;
|
||||
tx_rx->tx_rx_type = FuriHalNfcTxRxTransparent;
|
||||
} else if(is_encrypted && plain_data[0] == 0xA0) {
|
||||
uint8_t block = plain_data[1];
|
||||
if(block > mf_classic_get_total_block_num(emulator->data.type)) {
|
||||
@@ -941,7 +926,7 @@ bool mf_classic_emulator(MfClassicEmulator* emulator, FuriHalNfcTxRxContext* tx_
|
||||
// Send ACK
|
||||
uint8_t ack = 0x0A;
|
||||
crypto1_encrypt(&emulator->crypto, NULL, &ack, 4, tx_rx->tx_data, tx_rx->tx_parity);
|
||||
tx_rx->tx_rx_type = FuriHalNfcTxRxFullyTransparent;
|
||||
tx_rx->tx_rx_type = FuriHalNfcTxRxTransparent;
|
||||
tx_rx->tx_bits = 4;
|
||||
|
||||
if(!furi_hal_nfc_tx_rx(tx_rx, 300)) break;
|
||||
@@ -976,10 +961,9 @@ bool mf_classic_emulator(MfClassicEmulator* emulator, FuriHalNfcTxRxContext* tx_
|
||||
// Send ACK
|
||||
ack = 0x0A;
|
||||
crypto1_encrypt(&emulator->crypto, NULL, &ack, 4, tx_rx->tx_data, tx_rx->tx_parity);
|
||||
tx_rx->tx_rx_type = FuriHalNfcTxRxFullyTransparent;
|
||||
tx_rx->tx_rx_type = FuriHalNfcTxRxTransparent;
|
||||
tx_rx->tx_bits = 4;
|
||||
} else {
|
||||
FURI_LOG_T(TAG, "%02X unknown received", plain_data[0]);
|
||||
// Unknown command
|
||||
break;
|
||||
}
|
||||
@@ -993,7 +977,7 @@ bool mf_classic_emulator(MfClassicEmulator* emulator, FuriHalNfcTxRxContext* tx_
|
||||
} else {
|
||||
tx_rx->tx_data[0] = nack;
|
||||
}
|
||||
tx_rx->tx_rx_type = FuriHalNfcTxRxFullyTransparent;
|
||||
tx_rx->tx_rx_type = FuriHalNfcTxRxTransparent;
|
||||
tx_rx->tx_bits = 4;
|
||||
furi_hal_nfc_tx_rx(tx_rx, 300);
|
||||
}
|
||||
|
||||
@@ -27,4 +27,3 @@ NfcaSignal* nfca_signal_alloc();
|
||||
void nfca_signal_free(NfcaSignal* nfca_signal);
|
||||
|
||||
void nfca_signal_encode(NfcaSignal* nfca_signal, uint8_t* data, uint16_t bits, uint8_t* parity);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user