-
- uint32_t ar = bytes_to_num(receivedCmd, 4);
- uint32_t nr = bytes_to_num(&receivedCmd[4], 4);
-
- //Collect AR/NR
- //if(ar_nr_collected < 2 && cardAUTHSC == 2){
- if(ar_nr_collected < 2) {
- if(ar_nr_responses[2] != ar) {
- // Avoid duplicates... probably not necessary, ar should vary.
- //ar_nr_responses[ar_nr_collected*5] = 0;
- //ar_nr_responses[ar_nr_collected*5+1] = 0;
- ar_nr_responses[ar_nr_collected*5+2] = nonce;
- ar_nr_responses[ar_nr_collected*5+3] = nr;
- ar_nr_responses[ar_nr_collected*5+4] = ar;
- ar_nr_collected++;
- }
- // Interactive mode flag, means we need to send ACK
- if(flags & FLAG_INTERACTIVE && ar_nr_collected == 2)
- finished = true;
- }
-
- // --- crypto
- //crypto1_word(pcs, ar , 1);
- //cardRr = nr ^ crypto1_word(pcs, 0, 0);
-
- //test if auth OK
- //if (cardRr != prng_successor(nonce, 64)){
-
- //if (MF_DBGLEVEL >= 4) Dbprintf("AUTH FAILED for sector %d with key %c. cardRr=%08x, succ=%08x",
- // cardAUTHSC, cardAUTHKEY == 0 ? 'A' : 'B',
- // cardRr, prng_successor(nonce, 64));
- // Shouldn't we respond anything here?
- // Right now, we don't nack or anything, which causes the
- // reader to do a WUPA after a while. /Martin
- // -- which is the correct response. /piwi
- //cardSTATE_TO_IDLE();
- //LogTrace(Uart.output, Uart.len, Uart.startTime*16 - DELAY_AIR2ARM_AS_TAG, Uart.endTime*16 - DELAY_AIR2ARM_AS_TAG, Uart.parity, TRUE);
- //break;
- //}
-
- ans = prng_successor(nonce, 96) ^ crypto1_word(pcs, 0, 0);
-
- num_to_bytes(ans, 4, rAUTH_AT);
- // --- crypto
- EmSendCmd(rAUTH_AT, sizeof(rAUTH_AT));
- LED_C_ON();
- cardSTATE = MFEMUL_WORK;
- if (MF_DBGLEVEL >= 4) {
- Dbprintf("AUTH COMPLETED for sector %d with key %c. time=%d",
- cardAUTHSC,
- cardAUTHKEY == 0 ? 'A' : 'B',
- GetTickCount() - authTimer
- );