remove key_size

This commit is contained in:
merlokk 2021-07-05 14:15:39 +03:00
parent 96d18a1cd7
commit e9b8e18430
4 changed files with 8 additions and 27 deletions

View file

@ -5040,8 +5040,8 @@ static int CmdDesGetSessionParameters(CLIParserContext *ctx, DesfireContext *dct
uint8_t keydata[200] = {0};
if (CLIParamHexToBuf(arg_get_str(ctx, keyid), keydata, sizeof(keydata), &keylen))
return PM3_ESOFT;
if (keylen && keylen != key_size(algores)) {
PrintAndLogEx(ERR, "%s key must have %d bytes length instead of %d.", CLIGetOptionListStr(DesfireAlgoOpts, algores), key_size(algores), keylen);
if (keylen && keylen != desfire_get_key_length(algores)) {
PrintAndLogEx(ERR, "%s key must have %d bytes length instead of %d.", CLIGetOptionListStr(DesfireAlgoOpts, algores), desfire_get_key_length(algores), keylen);
return PM3_EINVARG;
}
if (keylen)
@ -5133,7 +5133,7 @@ static int CmdHF14ADesDefault(const char *Cmd) {
PrintAndLogEx(INFO, "Key Num : %d", defaultKeyNum);
PrintAndLogEx(INFO, "Algo : %s", CLIGetOptionListStr(DesfireAlgoOpts, defaultAlgoId));
PrintAndLogEx(INFO, "Key : %s", sprint_hex(defaultKey, key_size(defaultAlgoId)));
PrintAndLogEx(INFO, "Key : %s", sprint_hex(defaultKey, desfire_get_key_length(defaultAlgoId)));
PrintAndLogEx(INFO, "KDF algo : %s", CLIGetOptionListStr(DesfireKDFAlgoOpts, defaultKdfAlgo));
PrintAndLogEx(INFO, "KDF input : [%d] %s", defaultKdfInputLen, sprint_hex(defaultKdfInput, defaultKdfInputLen));
PrintAndLogEx(INFO, "Secure chan : %s", CLIGetOptionListStr(DesfireSecureChannelOpts, defaultSecureChannel));

View file

@ -400,24 +400,6 @@ size_t key_block_size(const desfirekey_t key) {
return desfire_get_key_block_length(key->type);
}
size_t key_size(const enum DESFIRE_CRYPTOALGO algo) {
switch (algo) {
case T_DES:
return 8;
break;
case T_3DES:
return 16;
break;
case T_3K3DES:
return 24;
break;
case T_AES:
return 16;
break;
}
return 0;
}
/*
* Size of MACing produced with the key.
*/

View file

@ -148,7 +148,6 @@ void *mifare_cryto_postprocess_data(desfiretag_t tag, void *data, size_t *nbytes
void mifare_cypher_single_block(desfirekey_t key, uint8_t *data, uint8_t *ivect, MifareCryptoDirection direction, MifareCryptoOperation operation, size_t block_size);
void mifare_cypher_blocks_chained(desfiretag_t tag, desfirekey_t key, uint8_t *ivect, uint8_t *data, size_t data_size, MifareCryptoDirection direction, MifareCryptoOperation operation);
size_t key_block_size(const desfirekey_t key);
size_t key_size(const enum DESFIRE_CRYPTOALGO algo);
size_t padded_data_length(const size_t nbytes, const size_t block_size);
size_t maced_data_length(const desfirekey_t key, const size_t nbytes);
size_t enciphered_data_length(const desfiretag_t tag, const size_t nbytes, int communication_settings);

View file

@ -234,9 +234,9 @@ void DesfirePrintContext(DesfireContext *ctx) {
PrintAndLogEx(INFO, "Key num: %d Key algo: %s Key[%d]: %s",
ctx->keyNum,
CLIGetOptionListStr(DesfireAlgoOpts, ctx->keyType),
key_size(ctx->keyType),
desfire_get_key_length(ctx->keyType),
sprint_hex(ctx->key,
key_size(ctx->keyType)));
desfire_get_key_length(ctx->keyType)));
if (ctx->kdfAlgo != MFDES_KDF_ALGO_NONE)
PrintAndLogEx(INFO, "KDF algo: %s KDF input[%d]: %s", CLIGetOptionListStr(DesfireKDFAlgoOpts, ctx->kdfAlgo), ctx->kdfInputLen, sprint_hex(ctx->kdfInput, ctx->kdfInputLen));
@ -248,9 +248,9 @@ void DesfirePrintContext(DesfireContext *ctx) {
if (DesfireIsAuthenticated(ctx)) {
PrintAndLogEx(INFO, "Session key MAC [%d]: %s ENC: %s IV [%d]: %s",
key_size(ctx->keyType),
sprint_hex(ctx->sessionKeyMAC, key_size(ctx->keyType)),
sprint_hex(ctx->sessionKeyEnc, key_size(ctx->keyType)),
desfire_get_key_length(ctx->keyType),
sprint_hex(ctx->sessionKeyMAC, desfire_get_key_length(ctx->keyType)),
sprint_hex(ctx->sessionKeyEnc, desfire_get_key_length(ctx->keyType)),
desfire_get_key_block_length(ctx->keyType),
sprint_hex(ctx->sessionKeyEnc, desfire_get_key_block_length(ctx->keyType)));