mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2024-11-26 10:26:09 +03:00
Fix valid_nonce
This commit is contained in:
parent
3acba77070
commit
6332ec7478
@ -207,16 +207,11 @@ uint32_t lfsr_rollback_word(Crypto1* crypto1, uint32_t in, int fb) {
|
||||
}
|
||||
|
||||
// Return true if the nonce is invalid else return false
|
||||
bool valid_nonce(uint32_t Nt, uint32_t NtEnc, uint32_t Ks1, uint8_t parity) {
|
||||
return ((nfc_util_odd_parity8((Nt >> 24) & 0xFF) ==
|
||||
(((parity >> 3) & 1) ^ nfc_util_odd_parity8((NtEnc >> 24) & 0xFF) ^
|
||||
FURI_BIT(Ks1, 16))) &&
|
||||
(nfc_util_odd_parity8((Nt >> 16) & 0xFF) ==
|
||||
(((parity >> 2) & 1) ^ nfc_util_odd_parity8((NtEnc >> 16) & 0xFF) ^
|
||||
FURI_BIT(Ks1, 8))) &&
|
||||
(nfc_util_odd_parity8((Nt >> 8) & 0xFF) ==
|
||||
(((parity >> 1) & 1) ^ nfc_util_odd_parity8((NtEnc >> 8) & 0xFF) ^
|
||||
FURI_BIT(Ks1, 0)))) ?
|
||||
true :
|
||||
false;
|
||||
bool valid_nonce(uint32_t nt, uint32_t ks, uint8_t nt_par_enc) {
|
||||
return (nfc_util_even_parity8((nt >> 24) & 0xFF) ==
|
||||
(((nt_par_enc >> 3) & 1) ^ FURI_BIT(ks, 16))) &&
|
||||
(nfc_util_even_parity8((nt >> 16) & 0xFF) ==
|
||||
(((nt_par_enc >> 2) & 1) ^ FURI_BIT(ks, 8))) &&
|
||||
(nfc_util_even_parity8((nt >> 8) & 0xFF) ==
|
||||
(((nt_par_enc >> 1) & 1) ^ FURI_BIT(ks, 0)));
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ void crypto1_encrypt_reader_nonce(
|
||||
|
||||
uint32_t lfsr_rollback_word(Crypto1* crypto1, uint32_t in, int fb);
|
||||
|
||||
bool valid_nonce(uint32_t Nt, uint32_t NtEnc, uint32_t Ks1, uint8_t parity);
|
||||
bool valid_nonce(uint32_t nt, uint32_t ks, uint8_t nt_par_enc);
|
||||
|
||||
uint32_t prng_successor(uint32_t x, uint32_t n);
|
||||
|
||||
|
@ -13,6 +13,10 @@ 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};
|
||||
|
||||
uint8_t nfc_util_even_parity8(uint8_t data) {
|
||||
return !nfc_util_odd_byte_parity[data];
|
||||
}
|
||||
|
||||
uint8_t nfc_util_even_parity32(uint32_t data) {
|
||||
// data ^= data >> 16;
|
||||
// data ^= data >> 8;
|
||||
|
@ -6,6 +6,8 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
uint8_t nfc_util_even_parity8(uint8_t data);
|
||||
|
||||
uint8_t nfc_util_even_parity32(uint32_t data);
|
||||
|
||||
uint8_t nfc_util_odd_parity8(uint8_t data);
|
||||
|
@ -1250,8 +1250,7 @@ NfcCommand mf_classic_poller_handler_nested_collect_nt_enc(MfClassicPoller* inst
|
||||
((dict_attack_ctx->d_median + current_dist) != UINT16_MAX)) {
|
||||
uint32_t nth_successor_positive =
|
||||
prng_successor(decrypted_nt_prev, dict_attack_ctx->d_median + current_dist);
|
||||
if(valid_nonce(
|
||||
nth_successor_positive, nt_enc, nth_successor_positive ^ nt_enc, parity)) {
|
||||
if(valid_nonce(nth_successor_positive, nth_successor_positive ^ nt_enc, parity)) {
|
||||
found_matching_nt = true;
|
||||
found_nt = nth_successor_positive;
|
||||
break;
|
||||
@ -1259,8 +1258,7 @@ NfcCommand mf_classic_poller_handler_nested_collect_nt_enc(MfClassicPoller* inst
|
||||
if(current_dist > 0) {
|
||||
uint32_t nth_successor_negative =
|
||||
prng_successor(decrypted_nt_prev, dict_attack_ctx->d_median - current_dist);
|
||||
if(valid_nonce(
|
||||
nth_successor_negative, nt_enc, nth_successor_negative ^ nt_enc, parity)) {
|
||||
if(valid_nonce(nth_successor_negative, nth_successor_negative ^ nt_enc, parity)) {
|
||||
found_matching_nt = true;
|
||||
found_nt = nth_successor_negative;
|
||||
break;
|
||||
|
@ -2805,6 +2805,7 @@ Function,+,nfc_set_mask_receive_time_fc,void,"Nfc*, uint32_t"
|
||||
Function,+,nfc_start,void,"Nfc*, NfcEventCallback, void*"
|
||||
Function,+,nfc_stop,void,Nfc*
|
||||
Function,+,nfc_util_even_parity32,uint8_t,uint32_t
|
||||
Function,+,nfc_util_even_parity8,uint8_t,uint8_t
|
||||
Function,+,nfc_util_odd_parity,void,"const uint8_t*, uint8_t*, uint8_t"
|
||||
Function,+,nfc_util_odd_parity8,uint8_t,uint8_t
|
||||
Function,+,notification_internal_message,void,"NotificationApp*, const NotificationSequence*"
|
||||
@ -3526,7 +3527,7 @@ Function,-,ungetc,int,"int, FILE*"
|
||||
Function,-,unsetenv,int,const char*
|
||||
Function,-,usbd_poll,void,usbd_device*
|
||||
Function,-,utoa,char*,"unsigned, char*, int"
|
||||
Function,+,valid_nonce,_Bool,"uint32_t, uint32_t, uint32_t, uint8_t"
|
||||
Function,+,valid_nonce,_Bool,"uint32_t, uint32_t, uint8_t"
|
||||
Function,+,validator_is_file_alloc_init,ValidatorIsFile*,"const char*, const char*, const char*"
|
||||
Function,+,validator_is_file_callback,_Bool,"const char*, FuriString*, void*"
|
||||
Function,+,validator_is_file_free,void,ValidatorIsFile*
|
||||
|
|
Loading…
Reference in New Issue
Block a user