chg: hf iclass / hf mfu - free some 3des contexts

This commit is contained in:
Iceman 2019-09-06 09:00:01 +02:00
parent ffe849fb93
commit f1eceab385
2 changed files with 17 additions and 13 deletions

View file

@ -870,11 +870,11 @@ static int CmdHFiClassDecrypt(const char *Cmd) {
mbedtls_des3_set2key_dec(&ctx, key); mbedtls_des3_set2key_dec(&ctx, key);
uint8_t dec_data[8] = {0}; uint8_t dec_data[8] = {0};
if ( have_data ) { if ( have_data ) {
mbedtls_des3_crypt_ecb(&ctx, enc_data, dec_data); mbedtls_des3_crypt_ecb(&ctx, enc_data, dec_data);
PrintAndLogEx(SUCCESS, "Data: %s", sprint_hex(dec_data, sizeof(dec_data))); PrintAndLogEx(SUCCESS, "Data: %s", sprint_hex(dec_data, sizeof(dec_data)));
} }
if ( have_file ) { if ( have_file ) {
picopass_hdr *hdr = (picopass_hdr *)decrypted; picopass_hdr *hdr = (picopass_hdr *)decrypted;
@ -913,6 +913,8 @@ static int CmdHFiClassDecrypt(const char *Cmd) {
free(decrypted); free(decrypted);
free(fptr); free(fptr);
} }
mbedtls_des3_free(&ctx);
return PM3_SUCCESS; return PM3_SUCCESS;
} }
@ -923,6 +925,7 @@ static void iClassEncryptBlkData(uint8_t *blk_data, uint8_t *key) {
mbedtls_des3_set2key_enc(&ctx, key); mbedtls_des3_set2key_enc(&ctx, key);
mbedtls_des3_crypt_ecb(&ctx, blk_data, encrypted); mbedtls_des3_crypt_ecb(&ctx, blk_data, encrypted);
memcpy(blk_data, encrypted, 8); memcpy(blk_data, encrypted, 8);
mbedtls_des3_free(&ctx);
} }
static int CmdHFiClassEncryptBlk(const char *Cmd) { static int CmdHFiClassEncryptBlk(const char *Cmd) {

View file

@ -2519,7 +2519,7 @@ static int CmdHF14AMfUCSetUid(const char *Cmd) {
if (param_gethex(Cmd, 0, uid, 14)) { if (param_gethex(Cmd, 0, uid, 14)) {
PrintAndLogEx(WARNING, "UID must include 14 HEX symbols"); PrintAndLogEx(WARNING, "UID must include 14 HEX symbols");
return 1; return PM3_EINVARG;
} }
// read block2. // read block2.
@ -2527,7 +2527,7 @@ static int CmdHF14AMfUCSetUid(const char *Cmd) {
SendCommandMIX(CMD_HF_MIFAREU_READBL, 2, 0, 0, NULL, 0); SendCommandMIX(CMD_HF_MIFAREU_READBL, 2, 0, 0, NULL, 0);
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) { if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
PrintAndLogEx(WARNING, "Command execute timeout"); PrintAndLogEx(WARNING, "Command execute timeout");
return 2; return PM3_ETIMEOUT;
} }
// save old block2. // save old block2.
@ -2544,7 +2544,7 @@ static int CmdHF14AMfUCSetUid(const char *Cmd) {
SendCommandOLD(CMD_HF_MIFAREU_WRITEBL, 0, 0, 0, data, sizeof(data)); SendCommandOLD(CMD_HF_MIFAREU_WRITEBL, 0, 0, 0, data, sizeof(data));
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) { if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
PrintAndLogEx(WARNING, "Command execute timeout"); PrintAndLogEx(WARNING, "Command execute timeout");
return 3; return PM3_ETIMEOUT;
} }
// block 1. // block 1.
@ -2556,7 +2556,7 @@ static int CmdHF14AMfUCSetUid(const char *Cmd) {
SendCommandOLD(CMD_HF_MIFAREU_WRITEBL, 1, 0, 0, data, sizeof(data)); SendCommandOLD(CMD_HF_MIFAREU_WRITEBL, 1, 0, 0, data, sizeof(data));
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) { if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
PrintAndLogEx(WARNING, "Command execute timeout"); PrintAndLogEx(WARNING, "Command execute timeout");
return 4; return PM3_ETIMEOUT;
} }
// block 2. // block 2.
@ -2568,9 +2568,9 @@ static int CmdHF14AMfUCSetUid(const char *Cmd) {
SendCommandOLD(CMD_HF_MIFAREU_WRITEBL, 2, 0, 0, data, sizeof(data)); SendCommandOLD(CMD_HF_MIFAREU_WRITEBL, 2, 0, 0, data, sizeof(data));
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) { if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
PrintAndLogEx(WARNING, "Command execute timeout"); PrintAndLogEx(WARNING, "Command execute timeout");
return 5; return PM3_ETIMEOUT;
} }
return 0; return PM3_SUCCESS;
} }
static int CmdHF14AMfUGenDiverseKeys(const char *Cmd) { static int CmdHF14AMfUGenDiverseKeys(const char *Cmd) {
@ -2681,8 +2681,9 @@ static int CmdHF14AMfUGenDiverseKeys(const char *Cmd) {
PrintAndLogEx(NORMAL, "Mifare ABA :\t %s", sprint_hex(dmkey, sizeof(dmkey))); PrintAndLogEx(NORMAL, "Mifare ABA :\t %s", sprint_hex(dmkey, sizeof(dmkey)));
PrintAndLogEx(NORMAL, "Mifare Pwd :\t %s", sprint_hex(newpwd, sizeof(newpwd))); PrintAndLogEx(NORMAL, "Mifare Pwd :\t %s", sprint_hex(newpwd, sizeof(newpwd)));
mbedtls_des3_free(&ctx);
// next. from the diversify_key method. // next. from the diversify_key method.
return 0; return PM3_SUCCESS;
} }
static int CmdHF14AMfUPwdGen(const char *Cmd) { static int CmdHF14AMfUPwdGen(const char *Cmd) {
@ -2709,11 +2710,11 @@ static int CmdHF14AMfUPwdGen(const char *Cmd) {
// 3: proprietary Anticollision // 3: proprietary Anticollision
if (select_status == 0) { if (select_status == 0) {
PrintAndLogEx(WARNING, "iso14443a card select failed"); PrintAndLogEx(WARNING, "iso14443a card select failed");
return 1; return PM3_ESOFT;
} }
if (card.uidlen != 7) { if (card.uidlen != 7) {
PrintAndLogEx(WARNING, "Wrong sized UID, expected 7bytes got %d", card.uidlen); PrintAndLogEx(WARNING, "Wrong sized UID, expected 7bytes got %d", card.uidlen);
return 1; return PM3_ESOFT;
} }
memcpy(uid, card.uid, sizeof(uid)); memcpy(uid, card.uid, sizeof(uid));
} else { } else {
@ -2732,7 +2733,7 @@ static int CmdHF14AMfUPwdGen(const char *Cmd) {
PrintAndLogEx(NORMAL, "------+----------+-----"); PrintAndLogEx(NORMAL, "------+----------+-----");
PrintAndLogEx(NORMAL, " Vingcard algo"); PrintAndLogEx(NORMAL, " Vingcard algo");
PrintAndLogEx(NORMAL, "--------------------"); PrintAndLogEx(NORMAL, "--------------------");
return 0; return PM3_SUCCESS;
} }
//------------------------------------ //------------------------------------
// Menu Stuff // Menu Stuff
@ -2757,7 +2758,7 @@ static command_t CommandTable[] = {
static int CmdHelp(const char *Cmd) { static int CmdHelp(const char *Cmd) {
(void)Cmd; // Cmd is not used so far (void)Cmd; // Cmd is not used so far
CmdsHelp(CommandTable); CmdsHelp(CommandTable);
return 0; return PM3_SUCCESS;
} }
int CmdHFMFUltra(const char *Cmd) { int CmdHFMFUltra(const char *Cmd) {