Skip to content

Commit a8d74d6

Browse files
committed
refactor
1 parent 13053e1 commit a8d74d6

File tree

1 file changed

+9
-20
lines changed

1 file changed

+9
-20
lines changed

client/src/cmdhffelica.c

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2251,17 +2251,6 @@ static int CmdHFFelicaDumpLite(const char *Cmd) {
22512251
return PM3_SUCCESS;
22522252
}
22532253

2254-
static void reverse_byte_array(const uint8_t* in, const int length, uint8_t* out) {
2255-
for (int i = 0; i < length; i++) {
2256-
out[i] = in[(length - 1) - i];
2257-
}
2258-
}
2259-
2260-
static void reverse_block16(const uint8_t* in, uint8_t *out) {
2261-
reverse_byte_array(in, 8, out);
2262-
reverse_byte_array(in + 8, 8, out + 8);
2263-
}
2264-
22652254
static int felica_make_block_list(uint16_t *out, const uint8_t *blk_numbers, const size_t length) {
22662255
if (length > 4) {
22672256
PrintAndLogEx(ERR, "felica_make_block_list: exceeds max size");
@@ -2345,7 +2334,7 @@ static int write_without_encryption(
23452334

23462335
uint8_t dl = (uint8_t)(datalen);
23472336

2348-
if (!check_write_req_data(&hdr, dl)) {
2337+
if (check_write_req_data(&hdr, dl) == false) {
23492338
PrintAndLogEx(FAILED, "invalid request");
23502339
return PM3_EINVARG;
23512340
}
@@ -2425,10 +2414,10 @@ static int felica_auth_context_init(
24252414
return PM3_EINVARG;
24262415
}
24272416

2428-
reverse_block16(rc, rev_rc);
2417+
SwapEndian64ex(rc, sizeof(rev_rc), 8, rev_rc);
24292418
memcpy(auth_ctx->random_challenge, rev_rc, sizeof(auth_ctx->random_challenge));
24302419

2431-
reverse_block16(key, rev_key);
2420+
SwapEndian64ex(key, sizeof(rev_key), 8, rev_key);
24322421

24332422
if (mbedtls_des3_set2key_enc(ctx, rev_key) != 0) {
24342423
ret = PM3_ECRYPTO;
@@ -2440,7 +2429,7 @@ static int felica_auth_context_init(
24402429
goto cleanup;
24412430
}
24422431

2443-
reverse_block16(encrypted_sk, rev_sk);
2432+
SwapEndian64ex(encrypted_sk, sizeof(encrypted_sk), 8, rev_sk);
24442433

24452434
memcpy(auth_ctx->session_key, rev_sk, sizeof(auth_ctx->session_key));
24462435

@@ -2475,11 +2464,11 @@ static int felica_generate_mac(
24752464
return PM3_EINVARG;
24762465
}
24772466

2478-
reverse_block16(auth_ctx->session_key, rev_sk);
2467+
SwapEndian64ex(auth_ctx->session_key, sizeof(auth_ctx->session_key), 8, rev_sk);
24792468

24802469
memcpy(iv, auth_ctx->random_challenge, sizeof(iv));
24812470

2482-
reverse_byte_array(initialize_block, sizeof(rev_block), rev_block);
2471+
SwapEndian64ex(initialize_block, sizeof(rev_block), 8, rev_block);
24832472

24842473
if (mbedtls_des3_set2key_enc(ctx, rev_sk) != 0) {
24852474
ret = PM3_ECRYPTO;
@@ -2492,10 +2481,10 @@ static int felica_generate_mac(
24922481
goto cleanup;
24932482
}
24942483
memcpy(iv, out, sizeof(iv));
2495-
reverse_byte_array(block_data + i, 8, rev_block);
2484+
SwapEndian64ex(block_data + i, 8, 8, rev_block);
24962485
}
24972486

2498-
reverse_byte_array(out, FELICA_BLK_HALF, mac);
2487+
SwapEndian64ex(out, FELICA_BLK_HALF, 8, mac);
24992488

25002489
cleanup:
25012490
mbedtls_platform_zeroize(rev_sk, sizeof(rev_sk));
@@ -2592,7 +2581,7 @@ static int CmdHFFelicaAuthenticationLite(const char *Cmd) {
25922581
if (send_wr_plain(flags, datalen, data, false, &sres) != PM3_SUCCESS) {
25932582
return PM3_ERFTRANS;
25942583
}
2595-
2584+
25962585
if (sres.status_flags.status_flag1[0] != 0x00 && sres.status_flags.status_flag2[0] != 0x00) {
25972586
PrintAndLogEx(ERR, "\nError RC Write");
25982587
return PM3_ERFTRANS;

0 commit comments

Comments
 (0)