赞
踩
选卡的过程和放冲突模式是硬件自动操作的,所以从第三步开始的协议解析、身份认证、数据加密,才是工作难点。
标签对读卡器的认证
- crypto1_init(&state, (uint64_t)tc[k].key); //通过密钥初始化
-
- crypto1_word(&state, tc[k].uid ^ tc[k].tag_challenge, 0);//输入UID和标签的随机数
-
- crypto1_word(&state, tc[k].reader_challenge_enc, 1);//读卡器发送的随机数
-
- rresp = prng_successor(tc[k].tag_challenge, 64);//验证标签的随机数和
-
- rresp ^= crypto1_word (&state, 0, 0);
-
- if(rresp == tc[k].reader_response)//验证读卡器的随机数是否和标签发送的数据数一样
- printf("TAG> Reader is authentic.\n");
-
- else
- printf("TAG> Reader is NOT authentic.\n");
读卡器对标签的认证
- crypto1_init(&state, tc[k].key);
- crypto1_word(&state, tc[k].uid ^ tc[k].tag_challenge, 0);
- rchal = crypto1_word(&state, tc[k].reader_challenge, 0);
- rresp = prng_successor(tc[k].tag_challenge, 64);
- rresp ^= crypto1_word (&state, 0, 0);
- tresp = prng_successor(tc[k].tag_challenge, 96);
- tresp ^= crypto1_word (&state, 0, 0);
- if(tresp == tc[k].tag_response)//读卡器验证随机数
- printf("Reader> Tag is authentic.\n");
- else
- printf("Reader> Tag is NOT authentic.\n");
ISO14443 crc校验算法
- #define CRC_A 1
- #define CRC_B 2
- #define BYTE unsigned char
-
- unsigned short UpdateCrc(unsigned char ch, unsigned short *lpwCrc)
- {
- ch = (ch^(unsigned char)((*lpwCrc) & 0x00FF));
- ch = (ch^(ch<<4));
-
- *lpwCrc = (*lpwCrc >> 8)^((unsigned short)ch << 8)^((unsigned short)ch<<3)^((unsigned short)ch>>4);
- return(*lpwCrc);
- }
-
- void ComputeCrc(int CRCType, char *Data, int Length,BYTE *TransmitFirst, BYTE *TransmitSecond)
- {
- unsigned char chBlock;
- unsigned short wCrc;
-
- switch(CRCType) {
- case CRC_A:
- wCrc = 0x6363; // ITU-V.41
- break;
- case CRC_B:
- wCrc = 0xFFFF; // ISO 3309
- break;
- default:
- return;
- }
- do {
- chBlock = *Data++;
- UpdateCrc(chBlock, &wCrc);
- } while (--Length);
- if (CRCType == CRC_B)
- wCrc = ~wCrc; // ISO 3309
- *TransmitFirst = (BYTE) (wCrc & 0xFF);
- *TransmitSecond = (BYTE) ((wCrc >> 8) & 0xFF);
- return;
- }
- BYTE BuffCRC_A[] = { 0x53,0x45,0x47,0x47,0x45,0x52,0x20,0x52};
- BYTE BuffCRC_B[] = { 0xC8,0xF0,0xD8,0x2E,0x7B};
- unsigned short Crc;
- BYTE First, Second;
-
- int crc_main(void)
- {
- printf("CRC-16 reference results 3-Jun-1999\n");
-
- printf("by Mickey Cohen - mickey@softchip.com\n\n");
- printf("Crc-16 G(x) = x^16 + x^12 + x^5 + 1\n\n");
-
- printf("CRC_A of [ ");
- printf("%02X ",BuffCRC_A[i]);
-
- ComputeCrc(CRC_A, BuffCRC_A, sizeof(BuffCRC_A), &First, &Second);
-
-
- printf("] Transmitted: %02X then %02X.\n", First, Second);
-
- return(0);
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。