From e2bd1444fbc05bb9ed1d933cac21b52f2933dc89 Mon Sep 17 00:00:00 2001 From: "Aaron Tulino (Aaronjamt)" Date: Tue, 23 Dec 2025 14:43:14 -0700 Subject: [PATCH] Further optimization Make SHA256 output directly into the final output buffer and make the first SHA1 do the same. The second SHA1 needs an intermediate buffer as it outputs 20 bytes but we only need the first 12. --- client/src/cmdhfseos.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/client/src/cmdhfseos.c b/client/src/cmdhfseos.c index 26118d972..59d9d0380 100644 --- a/client/src/cmdhfseos.c +++ b/client/src/cmdhfseos.c @@ -512,7 +512,6 @@ static void create_mutual_auth_key(uint8_t *KEYIFD, uint8_t *KEYICC, uint8_t *RN // PrintAndLogEx(SUCCESS, "hash Input....................... " _YELLOW_("%s"), sprint_hex_inrow(hash_in,ARRAYLEN(hash_in))); uint8_t output[32]; // Buffer to store the two 16-byte keys - uint8_t hashedOutput[32]; uint32_t counter = 1; // Generate the first key @@ -520,17 +519,16 @@ static void create_mutual_auth_key(uint8_t *KEYIFD, uint8_t *KEYICC, uint8_t *RN // PrintAndLogEx(SUCCESS, "key_out_temp..................... " _YELLOW_("%s"), sprint_hex_inrow(hash_in,ARRAYLEN(hash_in))); if (HashingAlgorithm == 0x06) { - sha1hash(hash_in, sizeof(hash_in), hashedOutput); + sha1hash(hash_in, sizeof(hash_in), output); //PrintAndLogEx(SUCCESS, "key_out_temp..................... " _YELLOW_("%s"), sprint_hex_inrow(hash_in,ARRAYLEN(hash_in))); - memcpy(output, hashedOutput, 20); counter++; set_counter_big_endian(hash_in, counter); + uint8_t hashedOutput[20]; sha1hash(hash_in, sizeof(hash_in), hashedOutput); memcpy(output + 20, hashedOutput, 12); //PrintAndLogEx(SUCCESS, "key_out_temp..................... " _YELLOW_("%s"), sprint_hex_inrow(hash_in,ARRAYLEN(hash_in))); } else if (HashingAlgorithm == 0x07) { - sha256hash(hash_in, sizeof(hash_in), hashedOutput); - memcpy(output, hashedOutput, 32); + sha256hash(hash_in, sizeof(hash_in), output); } else { // Yes they generate their encryption keys and mac keys in a weird way for no fucking reason, the 2nd cycle isn't required. PrintAndLogEx(ERR, _RED_("Unknown Hashing Algorithm"));