Skip to content

Commit

Permalink
Simpilify valid_nonce()
Browse files Browse the repository at this point in the history
  • Loading branch information
ikspress committed Jul 11, 2024
1 parent 2a2d056 commit 94f288a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/mfoc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1241,9 +1241,9 @@ countKeys *uniqsort(uint64_t *possibleKeys, uint32_t size)
// Return 1 if the nonce is invalid else return 0
int valid_nonce(uint32_t Nt, uint32_t NtEnc, uint32_t Ks1, uint8_t *parity)
{
return ((odd_parity((Nt >> 24) & 0xFF) == ((parity[0]) ^ odd_parity((NtEnc >> 24) & 0xFF) ^ BIT(Ks1, 16))) & \
(odd_parity((Nt >> 16) & 0xFF) == ((parity[1]) ^ odd_parity((NtEnc >> 16) & 0xFF) ^ BIT(Ks1, 8))) & \
(odd_parity((Nt >> 8) & 0xFF) == ((parity[2]) ^ odd_parity((NtEnc >> 8) & 0xFF) ^ BIT(Ks1, 0)))) ? 1 : 0;
return ((oddparity((Nt >> 24) & 0xFF) == ((parity[0]) ^ oddparity((NtEnc >> 24) & 0xFF) ^ BIT(Ks1, 16))) &&
(oddparity((Nt >> 16) & 0xFF) == ((parity[1]) ^ oddparity((NtEnc >> 16) & 0xFF) ^ BIT(Ks1, 8))) &&
(oddparity((Nt >> 8) & 0xFF) == ((parity[2]) ^ oddparity((NtEnc >> 8) & 0xFF) ^ BIT(Ks1, 0)))) ? 1 : 0;
}

void num_to_bytes(uint64_t n, uint32_t len, uint8_t *dest)
Expand Down
2 changes: 0 additions & 2 deletions src/mfoc.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
// Number of sets with 32b keys
#define DEFAULT_SETS_NR 5

#define odd_parity(i) (( (i) ^ (i)>>1 ^ (i)>>2 ^ (i)>>3 ^ (i)>>4 ^ (i)>>5 ^ (i)>>6 ^ (i)>>7 ^ 1) & 0x01)

typedef struct {
uint8_t KeyA[6];
uint8_t KeyB[6];
Expand Down

0 comments on commit 94f288a

Please sign in to comment.