mifare_desfire_key: fix get/set_version for AES keys

This commit is contained in:
Andreas Oberritter 2017-08-30 23:06:58 +02:00 committed by Robert Quattlebaum
parent 2514cde675
commit eea8b7b51e

View file

@ -114,6 +114,9 @@ mifare_desfire_key_get_version(MifareDESFireKey key)
{
uint8_t version = 0;
if (key->type == T_AES)
return key->aes_version;
for (int n = 0; n < 8; n++) {
version |= ((key->data[n] & 1) << (7 - n));
}
@ -124,6 +127,11 @@ mifare_desfire_key_get_version(MifareDESFireKey key)
void
mifare_desfire_key_set_version(MifareDESFireKey key, uint8_t version)
{
if (key->type == T_AES) {
key->aes_version = version;
return;
}
for (int n = 0; n < 8; n++) {
uint8_t version_bit = ((version & (1 << (7 - n))) >> (7 - n));
key->data[n] &= 0xfe;