diff options
-rw-r--r-- | usb-i2c-sl018/tuer-rfid.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/usb-i2c-sl018/tuer-rfid.c b/usb-i2c-sl018/tuer-rfid.c index e51e361..e991302 100644 --- a/usb-i2c-sl018/tuer-rfid.c +++ b/usb-i2c-sl018/tuer-rfid.c @@ -306,11 +306,11 @@ uint8_t generate_csum(uint8_t* data) return sum2<<4 | sum1;
}
-bool compare_keyslots(const keyslot_t* a, const keyslot_t* b) // constant time compare
+uint8_t compare_keyslots(const keyslot_t* a, const keyslot_t* b) // constant time compare
{
uint8_t tmp=0, i;
for(i=0; i<sizeof(keyslot_t); ++i)
- tmp |= (a->byte[i] ^ a->byte[i]);
+ tmp |= a->byte[i] ^ b->byte[i];
return tmp;
}
@@ -323,12 +323,12 @@ bool check_card(const uint8_t * uid, uint8_t uid_len) uid_len = uid_len > sizeof(keyslot_t) ? sizeof(keyslot_t) : uid_len;
for (uint8_t pos=0; pos<uid_len; pos++)
card.byte[pos]=uid[uid_len-pos-1];
- card.byte[sizeof(keyslot_t) - 1]=generate_csum(&card.byte[0]);
+ card.byte[sizeof(keyslot_t) - 1]=generate_csum(card.byte);
keyslot_t * ks=keyslots;
bool valid=0;
for(uint8_t ks_num=0;ks_num<(EEPROM_SIZE/sizeof(card));ks_num++) {
eeprom_read_block(&eeprom_ks,&ks[ks_num],sizeof(eeprom_ks));
- if(card.uint64==eeprom_ks.uint64) {
+ if(!compare_keyslots(&card, &eeprom_ks)) {
valid=1;
// break; // this would break security (not const time)
}
@@ -353,9 +353,11 @@ void handle_card(void) if (0<type && type < 7) {
if(check_card(recv_twi_msg->data,uid_len)) {
sl018_cmd(SL018CMD_ComRedLedOn);
- fprintf(stdio,"open/close\n\r"); // TODO: open/close door!
+ fprintf(stdio,"Card allowed - opening/closing door\n\r"); // TODO: open/close door!
_delay_ms(255);
sl018_cmd(SL018CMD_ComRedLedOff);
+ } else {
+ fprintf(stdio,"Card not found in Database\n\r");
}
} else {
fprintf(stdio,"Unknown Card Type %02x\n\r",type);
|