Skip to content

Buggy and useless cs computation in read_data() #151

@vinriviere

Description

@vinriviere

While debugging another issue, I stumbled upon that code in read_data():

if ((MIFARE_DESFIRE(tag)->session_key) && (cs | MDCM_MACED)) {

The (cs | MDCM_MACED) expression is obviously wrong as it is is always true.

Furthermore, there is something wrong in the main logic:

uint8_t ocs = cs;
if ((MIFARE_DESFIRE(tag)->session_key) && (cs | MDCM_MACED)) {
switch (MIFARE_DESFIRE(tag)->authentication_scheme) {
case AS_LEGACY:
break;
case AS_NEW:
cs = MDCM_PLAIN;
break;
}
}
uint8_t *p = mifare_cryto_preprocess_data(tag, cmd, &__cmd_n, 8, MDCM_PLAIN | CMAC_COMMAND);
cs = ocs;

The whole cs computation is useless, because its value is never used. Its initial value is saved into ocs at the beginning of the block, then restored afterwards. So there must be something missing (or just old unused code).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions