Make variables & function names snake_case

This commit is contained in:
Matt Moran 2022-01-05 23:53:03 +13:00
commit 8ecfc4af34
6 changed files with 272 additions and 268 deletions

File diff suppressed because it is too large Load diff

View file

@ -29,7 +29,7 @@ int CmdHFGallagher(const char *Cmd);
* @param keyOut Buffer to copy the diversified key into (must be 16 bytes). * @param keyOut Buffer to copy the diversified key into (must be 16 bytes).
* @return PM3_SUCCESS if successful, PM3_EINVARG if an argument is invalid. * @return PM3_SUCCESS if successful, PM3_EINVARG if an argument is invalid.
*/ */
int GallagherDiversifyKey(uint8_t *sitekey, uint8_t *uid, uint8_t uidLen, uint8_t keyNum, uint32_t aid, uint8_t *keyOut); int hfgal_diversify_key(uint8_t *sitekey, uint8_t *uid, uint8_t uidLen, uint8_t keyNum, uint32_t aid, uint8_t *keyOut);
// Return error // Return error
#define HFGAL_RET_ERR(err, ...) { PrintAndLogEx(ERR, __VA_ARGS__); return err; } #define HFGAL_RET_ERR(err, ...) { PrintAndLogEx(ERR, __VA_ARGS__); return err; }

View file

@ -76,7 +76,7 @@ int demodGallagher(bool verbose) {
uint8_t calc_crc = CRC8Cardx(arr, ARRAYLEN(arr)); uint8_t calc_crc = CRC8Cardx(arr, ARRAYLEN(arr));
GallagherCredentials_t creds = {0}; GallagherCredentials_t creds = {0};
decodeCardholderCredentials(arr, &creds); gallagher_decode_creds(arr, &creds);
PrintAndLogEx(SUCCESS, "GALLAGHER - Region: " _GREEN_("%u") " Facility: " _GREEN_("%u") " Card No.: " _GREEN_("%u") " Issue Level: " _GREEN_("%u"), PrintAndLogEx(SUCCESS, "GALLAGHER - Region: " _GREEN_("%u") " Facility: " _GREEN_("%u") " Card No.: " _GREEN_("%u") " Issue Level: " _GREEN_("%u"),
creds.region_code, creds.facility_code, creds.card_number, creds.issue_level); creds.region_code, creds.facility_code, creds.card_number, creds.issue_level);
@ -142,7 +142,7 @@ static void setBitsInBlocks(uint32_t *blocks, uint8_t *pos, uint32_t data, uint8
static void createBlocks(uint32_t *blocks, GallagherCredentials_t *creds) { static void createBlocks(uint32_t *blocks, GallagherCredentials_t *creds) {
// put data into the correct places (Gallagher obfuscation) // put data into the correct places (Gallagher obfuscation)
uint8_t arr[8] = {0}; uint8_t arr[8] = {0};
encodeCardholderCredentials(arr, creds); gallagher_encode_creds(arr, creds);
blocks[0] = blocks[1] = blocks[2] = 0; blocks[0] = blocks[1] = blocks[2] = 0;
uint8_t pos = 0; uint8_t pos = 0;
@ -222,7 +222,7 @@ static int CmdGallagherClone(const char *Cmd) {
PrintAndLogEx(FAILED, "Can't specify both raw and rc/fc/cn/il at the same time"); PrintAndLogEx(FAILED, "Can't specify both raw and rc/fc/cn/il at the same time");
return PM3_EINVARG; return PM3_EINVARG;
} }
if (!isValidGallagherCredentials(region_code, facility_code, card_number, issue_level)) { if (!gallagher_is_valid_creds(region_code, facility_code, card_number, issue_level)) {
return PM3_EINVARG; return PM3_EINVARG;
} }
} }
@ -322,7 +322,7 @@ static int CmdGallagherSim(const char *Cmd) {
PrintAndLogEx(FAILED, "Can't specify both raw and rc/fc/cn/il at the same time"); PrintAndLogEx(FAILED, "Can't specify both raw and rc/fc/cn/il at the same time");
return PM3_EINVARG; return PM3_EINVARG;
} }
if (!isValidGallagherCredentials(region_code, facility_code, card_number, issue_level)) { if (!gallagher_is_valid_creds(region_code, facility_code, card_number, issue_level)) {
return PM3_EINVARG; return PM3_EINVARG;
} }
} }

View file

@ -62,7 +62,7 @@ static void descramble(uint8_t *arr, uint8_t len) {
} }
} }
void decodeCardholderCredentials(uint8_t *eight_bytes, GallagherCredentials_t *creds) { void gallagher_decode_creds(uint8_t *eight_bytes, GallagherCredentials_t *creds) {
uint8_t *arr = eight_bytes; uint8_t *arr = eight_bytes;
descramble(arr, 8); descramble(arr, 8);
@ -80,7 +80,7 @@ void decodeCardholderCredentials(uint8_t *eight_bytes, GallagherCredentials_t *c
creds->issue_level = arr[7] & 0x0F; creds->issue_level = arr[7] & 0x0F;
} }
void encodeCardholderCredentials(uint8_t *eight_bytes, GallagherCredentials_t *creds) { void gallagher_encode_creds(uint8_t *eight_bytes, GallagherCredentials_t *creds) {
uint8_t rc = creds->region_code; uint8_t rc = creds->region_code;
uint16_t fc = creds->facility_code; uint16_t fc = creds->facility_code;
uint32_t cn = creds->card_number; uint32_t cn = creds->card_number;
@ -100,25 +100,25 @@ void encodeCardholderCredentials(uint8_t *eight_bytes, GallagherCredentials_t *c
scramble(eight_bytes, 8); scramble(eight_bytes, 8);
} }
bool isValidGallagherCredentials(uint64_t region_code, uint64_t facility_code, uint64_t card_number, uint64_t issue_level) { bool gallagher_is_valid_creds(uint64_t region_code, uint64_t facility_code, uint64_t card_number, uint64_t issue_level) {
bool isValid = true; bool is_valid = true;
// validate input // validate input
if (region_code > 0x0f) { if (region_code > 0x0f) {
PrintAndLogEx(ERR, "Region code must be 0 <= rc <= 15 (4 bits), received: %d", region_code); PrintAndLogEx(ERR, "Region code must be 0 <= rc <= 15 (4 bits), received: %d", region_code);
isValid = false; is_valid = false;
} }
if (facility_code > 0xffff) { if (facility_code > 0xffff) {
PrintAndLogEx(ERR, "Facility code must be 0 <= fc <= 65535 (2 bytes), received: %d", facility_code); PrintAndLogEx(ERR, "Facility code must be 0 <= fc <= 65535 (2 bytes), received: %d", facility_code);
isValid = false; is_valid = false;
} }
if (card_number > 0xffffff) { if (card_number > 0xffffff) {
PrintAndLogEx(ERR, "Card number must be 0 <= cn <= 16777215 (3 bytes), received: %d", card_number); PrintAndLogEx(ERR, "Card number must be 0 <= cn <= 16777215 (3 bytes), received: %d", card_number);
isValid = false; is_valid = false;
} }
if (issue_level > 0x0f) { if (issue_level > 0x0f) {
PrintAndLogEx(ERR, "Issue level must be 0 <= il <= 15 (4 bits), received: %d", issue_level); PrintAndLogEx(ERR, "Issue level must be 0 <= il <= 15 (4 bits), received: %d", issue_level);
isValid = false; is_valid = false;
} }
return isValid; return is_valid;
} }

View file

@ -21,10 +21,10 @@ typedef struct {
uint8_t issue_level; uint8_t issue_level;
} GallagherCredentials_t; } GallagherCredentials_t;
void encodeCardholderCredentials(uint8_t *eight_bytes, GallagherCredentials_t *creds); void gallagher_encode_creds(uint8_t *eight_bytes, GallagherCredentials_t *creds);
void decodeCardholderCredentials(uint8_t *eight_bytes, GallagherCredentials_t *creds); void gallagher_decode_creds(uint8_t *eight_bytes, GallagherCredentials_t *creds);
bool isValidGallagherCredentials(uint64_t region_code, uint64_t facility_code, uint64_t card_number, uint64_t issue_level); bool gallagher_is_valid_creds(uint64_t region_code, uint64_t facility_code, uint64_t card_number, uint64_t issue_level);
#endif #endif

View file

@ -324,9 +324,9 @@ Check column "offline" for their availability.
|command |offline |description |command |offline |description
|------- |------- |----------- |------- |------- |-----------
|`hf gallagher help `|Y |`This help` |`hf gallagher help `|Y |`This help`
|`hf gallagher reader `|N |`Attempt to read and extract tag data` |`hf gallagher reader `|N |`Read & decode all Gallagher credentials on the DESFire card`
|`hf gallagher clone `|N |`Add Gallagher credentials to a DESFire card` |`hf gallagher clone `|N |`Add Gallagher credentials to a DESFire card`
|`hf gallagher delete `|N |`Delete Gallagher application from a DESFire card` |`hf gallagher delete `|N |`Delete Gallagher credentials from a DESFire card`
### hf ksx6924 ### hf ksx6924