[FL-2933] Mf Classic initial write, update, detect reader (#1941)
* nfc: introduce nfc write * nfc: add write logic * nfc worker: add write state * nfc: add mfc update logic * nfc: add update success logic * nfc: add custom card for detect reader * nfc: update write logic * nfc: add halt command, add notifications * nfc: add write fail scene * nfc: fixes and clean up * nfc: fix navigation ad notifications * nfc: fix detect reader nfc data setter Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
@@ -73,3 +73,55 @@ uint32_t prng_successor(uint32_t x, uint32_t n) {
|
||||
|
||||
return SWAPENDIAN(x);
|
||||
}
|
||||
|
||||
void crypto1_decrypt(
|
||||
Crypto1* crypto,
|
||||
uint8_t* encrypted_data,
|
||||
uint16_t encrypted_data_bits,
|
||||
uint8_t* decrypted_data) {
|
||||
furi_assert(crypto);
|
||||
furi_assert(encrypted_data);
|
||||
furi_assert(decrypted_data);
|
||||
|
||||
if(encrypted_data_bits < 8) {
|
||||
uint8_t decrypted_byte = 0;
|
||||
decrypted_byte |= (crypto1_bit(crypto, 0, 0) ^ FURI_BIT(encrypted_data[0], 0)) << 0;
|
||||
decrypted_byte |= (crypto1_bit(crypto, 0, 0) ^ FURI_BIT(encrypted_data[0], 1)) << 1;
|
||||
decrypted_byte |= (crypto1_bit(crypto, 0, 0) ^ FURI_BIT(encrypted_data[0], 2)) << 2;
|
||||
decrypted_byte |= (crypto1_bit(crypto, 0, 0) ^ FURI_BIT(encrypted_data[0], 3)) << 3;
|
||||
decrypted_data[0] = decrypted_byte;
|
||||
} else {
|
||||
for(size_t i = 0; i < encrypted_data_bits / 8; i++) {
|
||||
decrypted_data[i] = crypto1_byte(crypto, 0, 0) ^ encrypted_data[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void crypto1_encrypt(
|
||||
Crypto1* crypto,
|
||||
uint8_t* keystream,
|
||||
uint8_t* plain_data,
|
||||
uint16_t plain_data_bits,
|
||||
uint8_t* encrypted_data,
|
||||
uint8_t* encrypted_parity) {
|
||||
furi_assert(crypto);
|
||||
furi_assert(plain_data);
|
||||
furi_assert(encrypted_data);
|
||||
furi_assert(encrypted_parity);
|
||||
|
||||
if(plain_data_bits < 8) {
|
||||
encrypted_data[0] = 0;
|
||||
for(size_t i = 0; i < plain_data_bits; i++) {
|
||||
encrypted_data[0] |= (crypto1_bit(crypto, 0, 0) ^ FURI_BIT(plain_data[0], i)) << i;
|
||||
}
|
||||
} 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(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)
|
||||
<< (7 - (i & 0x0007)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user