Re: Ковыряем RFID Mifare и MFRC522
Добавлено: Пт июл 21, 2017 14:02:23
Вот еще из той же оперы, но есть немного комментариев...
Здесь можно немножко помяукать :)
https://radiokot.ru/forum/
Код взят из самой популярной библиотеки для mfrc. Мне подобный подход к построению логики кажется странным.// Wait for the CRC calculation to complete. Each iteration of the while-loop takes 17.73us.
for (uint16_t i = 5000; i > 0; i--) {
// DivIrqReg[7..0] bits are: Set2 reserved reserved MfinActIRq reserved CRCIRq reserved reserved
byte n = PCD_ReadRegister(DivIrqReg);
if (n & 0x04) { // CRCIRq bit set - calculation done
PCD_WriteRegister(CommandReg, PCD_Idle); // Stop calculating CRC for new content in the FIFO.
// Transfer the result from the registers to the result buffer
result[0] = PCD_ReadRegister(CRCResultRegL);
result[1] = PCD_ReadRegister(CRCResultRegH);
return STATUS_OK;
}
}
В принципе зачем то описывается процесс генерации NT со стороны карты. Продолжение следует.The challenge nT has a length of 32bits, but as mentioned before the LFSR is only 16 bits.This means that the 16 bits that are not accounted for are enerated by theLFSR from the initial seed and .The value of the LFSR updates with every clock tick (every 9.44Μs) and value depends on thetime the tag powers p nd when communication is invoked. Therefore, the challenge nonce,nT, since LFSR of the tag isdeterministic, can be replicated at anytime by controlling start up nd when communications begins. Initially, the state of theLFSR is only the input bit 1 and the rest of the register are 0 s.With each clock tick, the feedback bits are omputed using thespecified taps and XOR - ing them to generate a new input bit. This bit is fed back into the register onto the right and the registeris shifted to he eft. The operation can be defined as

Привожу полный лог0960090009FF09FF09FF09FF09FF09FF099009F6090B09C5
Ну во всяком случае FIFO опустел-> 010F [Reset]
-> B7 [Version]
<- 92
-> 010F113D2D302C002A8D2B3E148326701540 [Init]
-> 0952010C0D87 [Send REQA]
-> 8989 [Read REQA]
<- 0400
-> 09930920010C0D80 [Anticol]
-> 8989898989 [Read UID]
<- 90F60BC5A8
-> 09930970099009F6090B09C509A801030100 [Calculate CRC]
-> A2A1 [GET CRC]
<- CE6F
-> 09930970099009F6090B09C509A809CE096F010C0D80 [Select]
-> 898989 [Read SAK]
<- 08B6DD
-> 0960090009FF09FF09FF09FF09FF09FF099009F6090B09C5 [Auth string]
-> 010E [Authenticate]
<- 01
-> 89 [In FIFO?]
<- 00
Я если честно со структурой карты Classic 1k в настоящее время на вы так сказать-> 010F [Reset]
-> B7 [Version]
<- 92
-> 010F113D2D302C002A8D2B3E148326701540 [Init]
-> 0952010C0D87 [Send REQA]
-> 8989 [Read REQA]
<- 0400
-> 09930920010C0D80 [Anticol]
-> 8989898989 [Read UID]
<- 90F60BC5A8
-> 09930970099009F6090B09C509A801030100 [Calculate CRC]
-> A2A1 [GET CRC]
<- CE6F
-> 09930970099009F6090B09C509A809CE096F010C0D80 [Select]
-> 898989 [Read SAK]
<- 08B6DD
-> 0960090009FF09FF09FF09FF09FF09FF099009F6090B09C5 [Auth string]
-> 010E [Authenticate]
-> 88 [Status2Reg]
<- 08
-> 0930090001030100 [Calculate CRC]
-> A2A1 [GET CRC]
<- 02A8
-> 09300900090209A8010C0D80 [Send Read block 00 to Card]
-> 89898989898989 [Read]
<- 90F60BC5A88804
000000000000 - KEYB (угу, по всей видимости все зеркалируется)000000000000FF078069FFFFFFFFFFFF
Первый блок прочитан, два других - нет.-> 0960090309FF09FF09FF09FF09FF09FF099009F6090B09C5 [Auth string]
-> 010E [Authenticate]
-> 88 [Status2Reg]
<- 08
-> 0930090001030100 [Calculate CRC]
-> A2A1 [GET CRC]
<- 02A8
-> 09300900090209A8010C0D80 [Send Read block 00 to Card]
-> 89898989898989898989898989898989 [Read]
<- 90F60BC5A88804008500B42EF0BB6AA8
-> 0930090101030100 [Calculate CRC]
-> A2A1 [GET CRC]
<- 60AA
-> 09300901096009AA010C0D80 [Send Read block 00 to Card]
-> 89898989898989898989898989898989 [Read]
<- 05FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
-> 0930090201030100 [Calculate CRC]
-> A2A1 [GET CRC]
<- 108B
-> 093009020910098B010C0D80 [Send Read block 00 to Card]
-> 89898989898989898989898989898989 [Read]
<- 90909090909090909090909090909090
Работает. Перед каждой итерацией производим полную очистку буффера, видимо там что то есть. Странно конечно, после операции чтения 89 каждый прочитанный байт должен удаляться.-> 0960090309FF09FF09FF09FF09FF09FF099009F6090B09C5 [Auth string]
-> 010E [Authenticate]
-> 88 [Status2Reg]
<- 08
-> 0930090001030100 [Calculate CRC]
-> A2A1 [GET CRC]
<- 02A8
-> 09300900090209A8010C0D80 [Send Read block 00 to Card]
-> 89898989898989898989898989898989 [Read]
<- 90F60BC5A88804008500B42EF0BB6AA8
-> 0A80 [Clear FIFO]
-> 0930090101030100 [Calculate CRC]
-> A2A1 [GET CRC]
<- 8BB9
-> 09300901098B09B9010C0D80 [Send Read block 00 to Card]
-> 89898989898989898989898989898989 [Read]
<- 00000000000000000000000000000000
-> 0A80 [Clear FIFO]
-> 0930090201030100 [Calculate CRC]
-> A2A1 [GET CRC]
<- 108B
-> 093009020910098B010C0D80 [Send Read block 00 to Card]
-> 89898989898989898989898989898989 [Read]
<- 00000000000000000000000000000000
-> 0A80 [Clear FIFO]
-> 0930090301030100 [Calculate CRC]
-> A2A1 [GET CRC]
<- 999A
-> 093009030999099A010C0D80 [Send Read block 00 to Card]
-> 89898989898989898989898989898989 [Read]
<- 000000000000FF078069FFFFFFFFFFFF
