]> git.zerfleddert.de Git - proxmark3-svn/blame_incremental - client/mifarehost.c
CHG: rename of methods to follow naming convention
[proxmark3-svn] / client / mifarehost.c
... / ...
CommitLineData
1// Merlok, 2011, 2012\r
2// people from mifare@nethemba.com, 2010\r
3//\r
4// This code is licensed to you under the terms of the GNU GPL, version 2 or,\r
5// at your option, any later version. See the LICENSE.txt file for the text of\r
6// the license.\r
7//-----------------------------------------------------------------------------\r
8// mifare commands\r
9//-----------------------------------------------------------------------------\r
10\r
11#include <stdio.h>\r
12#include <stdlib.h> \r
13#include <string.h>\r
14#include <pthread.h>\r
15#include "mifarehost.h"\r
16#include "proxmark3.h"\r
17\r
18// MIFARE\r
19int compar_int(const void * a, const void * b) {\r
20 // didn't work: (the result is truncated to 32 bits)\r
21 //return (*(uint64_t*)b - *(uint64_t*)a);\r
22\r
23 // better:\r
24 if (*(uint64_t*)b == *(uint64_t*)a) return 0;\r
25 else if (*(uint64_t*)b > *(uint64_t*)a) return 1;\r
26 else return -1;\r
27}\r
28\r
29// Compare 16 Bits out of cryptostate\r
30int Compare16Bits(const void * a, const void * b) {\r
31 if ((*(uint64_t*)b & 0x00ff000000ff0000) == (*(uint64_t*)a & 0x00ff000000ff0000)) return 0;\r
32 else if ((*(uint64_t*)b & 0x00ff000000ff0000) > (*(uint64_t*)a & 0x00ff000000ff0000)) return 1;\r
33 else return -1;\r
34}\r
35\r
36typedef \r
37 struct {\r
38 union {\r
39 struct Crypto1State *slhead;\r
40 uint64_t *keyhead;\r
41 } head;\r
42 union {\r
43 struct Crypto1State *sltail;\r
44 uint64_t *keytail;\r
45 } tail;\r
46 uint32_t len;\r
47 uint32_t uid;\r
48 uint32_t blockNo;\r
49 uint32_t keyType;\r
50 uint32_t nt;\r
51 uint32_t ks1;\r
52 } StateList_t;\r
53\r
54\r
55// wrapper function for multi-threaded lfsr_recovery32\r
56void* nested_worker_thread(void *arg)\r
57{\r
58 struct Crypto1State *p1;\r
59 StateList_t *statelist = arg;\r
60\r
61 statelist->head.slhead = lfsr_recovery32(statelist->ks1, statelist->nt ^ statelist->uid);\r
62 for (p1 = statelist->head.slhead; *(uint64_t *)p1 != 0; p1++);\r
63 statelist->len = p1 - statelist->head.slhead;\r
64 statelist->tail.sltail = --p1;\r
65 qsort(statelist->head.slhead, statelist->len, sizeof(uint64_t), Compare16Bits);\r
66 \r
67 return statelist->head.slhead;\r
68}\r
69\r
70int mfnested(uint8_t blockNo, uint8_t keyType, uint8_t * key, uint8_t trgBlockNo, uint8_t trgKeyType, uint8_t * resultKey, bool calibrate) \r
71{\r
72 uint16_t i, len;\r
73 uint32_t uid;\r
74 UsbCommand resp;\r
75 StateList_t statelists[2];\r
76 struct Crypto1State *p1, *p2, *p3, *p4;\r
77 \r
78 // flush queue\r
79 WaitForResponseTimeout(CMD_ACK,NULL,100);\r
80 \r
81 UsbCommand c = {CMD_MIFARE_NESTED, {blockNo + keyType * 0x100, trgBlockNo + trgKeyType * 0x100, calibrate}};\r
82 memcpy(c.d.asBytes, key, 6);\r
83 SendCommand(&c);\r
84\r
85 if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {\r
86 len = resp.arg[1];\r
87 if (len == 2) { \r
88 memcpy(&uid, resp.d.asBytes, 4);\r
89 PrintAndLog("uid:%08x len=%d trgbl=%d trgkey=%x", uid, len, (uint16_t)resp.arg[2] & 0xff, (uint16_t)resp.arg[2] >> 8);\r
90 \r
91 for (i = 0; i < 2; i++) {\r
92 statelists[i].blockNo = resp.arg[2] & 0xff;\r
93 statelists[i].keyType = (resp.arg[2] >> 8) & 0xff;\r
94 statelists[i].uid = uid;\r
95\r
96 memcpy(&statelists[i].nt, (void *)(resp.d.asBytes + 4 + i * 8 + 0), 4);\r
97 memcpy(&statelists[i].ks1, (void *)(resp.d.asBytes + 4 + i * 8 + 4), 4);\r
98 }\r
99 }\r
100 else {\r
101 PrintAndLog("Got 0 keys from proxmark."); \r
102 return 1;\r
103 }\r
104 }\r
105 \r
106 // calc keys\r
107 \r
108 pthread_t thread_id[2];\r
109 \r
110 // create and run worker threads\r
111 for (i = 0; i < 2; i++) {\r
112 pthread_create(thread_id + i, NULL, nested_worker_thread, &statelists[i]);\r
113 }\r
114 \r
115 // wait for threads to terminate:\r
116 for (i = 0; i < 2; i++) {\r
117 pthread_join(thread_id[i], (void*)&statelists[i].head.slhead);\r
118 }\r
119\r
120\r
121 // the first 16 Bits of the cryptostate already contain part of our key.\r
122 // Create the intersection of the two lists based on these 16 Bits and\r
123 // roll back the cryptostate\r
124 p1 = p3 = statelists[0].head.slhead; \r
125 p2 = p4 = statelists[1].head.slhead;\r
126 while (p1 <= statelists[0].tail.sltail && p2 <= statelists[1].tail.sltail) {\r
127 if (Compare16Bits(p1, p2) == 0) {\r
128 struct Crypto1State savestate, *savep = &savestate;\r
129 savestate = *p1;\r
130 while(Compare16Bits(p1, savep) == 0 && p1 <= statelists[0].tail.sltail) {\r
131 *p3 = *p1;\r
132 lfsr_rollback_word(p3, statelists[0].nt ^ statelists[0].uid, 0);\r
133 p3++;\r
134 p1++;\r
135 }\r
136 savestate = *p2;\r
137 while(Compare16Bits(p2, savep) == 0 && p2 <= statelists[1].tail.sltail) {\r
138 *p4 = *p2;\r
139 lfsr_rollback_word(p4, statelists[1].nt ^ statelists[1].uid, 0);\r
140 p4++;\r
141 p2++;\r
142 }\r
143 }\r
144 else {\r
145 while (Compare16Bits(p1, p2) == -1) p1++;\r
146 while (Compare16Bits(p1, p2) == 1) p2++;\r
147 }\r
148 }\r
149 p3->even = 0; p3->odd = 0;\r
150 p4->even = 0; p4->odd = 0;\r
151 statelists[0].len = p3 - statelists[0].head.slhead;\r
152 statelists[1].len = p4 - statelists[1].head.slhead;\r
153 statelists[0].tail.sltail=--p3;\r
154 statelists[1].tail.sltail=--p4;\r
155\r
156 // the statelists now contain possible keys. The key we are searching for must be in the\r
157 // intersection of both lists. Create the intersection:\r
158 qsort(statelists[0].head.keyhead, statelists[0].len, sizeof(uint64_t), compar_int);\r
159 qsort(statelists[1].head.keyhead, statelists[1].len, sizeof(uint64_t), compar_int);\r
160\r
161 uint64_t *p5, *p6, *p7;\r
162 p5 = p7 = statelists[0].head.keyhead; \r
163 p6 = statelists[1].head.keyhead;\r
164 while (p5 <= statelists[0].tail.keytail && p6 <= statelists[1].tail.keytail) {\r
165 if (compar_int(p5, p6) == 0) {\r
166 *p7++ = *p5++;\r
167 p6++;\r
168 }\r
169 else {\r
170 while (compar_int(p5, p6) == -1) p5++;\r
171 while (compar_int(p5, p6) == 1) p6++;\r
172 }\r
173 }\r
174 statelists[0].len = p7 - statelists[0].head.keyhead;\r
175 statelists[0].tail.keytail=--p7;\r
176\r
177 memset(resultKey, 0, 6);\r
178 // The list may still contain several key candidates. Test each of them with mfCheckKeys\r
179 for (i = 0; i < statelists[0].len; i++) {\r
180 uint8_t keyBlock[6];\r
181 uint64_t key64;\r
182 crypto1_get_lfsr(statelists[0].head.slhead + i, &key64);\r
183 num_to_bytes(key64, 6, keyBlock);\r
184 key64 = 0;\r
185 if (!mfCheckKeys(statelists[0].blockNo, statelists[0].keyType, 1, keyBlock, &key64)) {\r
186 num_to_bytes(key64, 6, resultKey);\r
187 break;\r
188 }\r
189 }\r
190 \r
191 free(statelists[0].head.slhead);\r
192 free(statelists[1].head.slhead);\r
193 \r
194 return 0;\r
195}\r
196\r
197int mfCheckKeys (uint8_t blockNo, uint8_t keyType, uint8_t keycnt, uint8_t * keyBlock, uint64_t * key){\r
198\r
199 *key = 0;\r
200\r
201 UsbCommand c = {CMD_MIFARE_CHKKEYS, {blockNo, keyType, keycnt}};\r
202 memcpy(c.d.asBytes, keyBlock, 6 * keycnt);\r
203 SendCommand(&c);\r
204\r
205 UsbCommand resp;\r
206 if (!WaitForResponseTimeout(CMD_ACK,&resp,3000)) return 1;\r
207 if ((resp.arg[0] & 0xff) != 0x01) return 2;\r
208 *key = bytes_to_num(resp.d.asBytes, 6);\r
209 return 0;\r
210}\r
211\r
212// EMULATOR\r
213\r
214int mfEmlGetMem(uint8_t *data, int blockNum, int blocksCount) {\r
215 UsbCommand c = {CMD_MIFARE_EML_MEMGET, {blockNum, blocksCount, 0}};\r
216 SendCommand(&c);\r
217\r
218 UsbCommand resp;\r
219 if (!WaitForResponseTimeout(CMD_ACK,&resp,1500)) return 1;\r
220 memcpy(data, resp.d.asBytes, blocksCount * 16);\r
221 return 0;\r
222}\r
223\r
224int mfEmlSetMem(uint8_t *data, int blockNum, int blocksCount) {\r
225 UsbCommand c = {CMD_MIFARE_EML_MEMSET, {blockNum, blocksCount, 0}};\r
226 memcpy(c.d.asBytes, data, blocksCount * 16); \r
227 SendCommand(&c);\r
228 return 0;\r
229}\r
230\r
231// "MAGIC" CARD\r
232\r
233int mfCSetUID(uint8_t *uid, uint8_t *atqa, uint8_t *sak, uint8_t *oldUID, bool wantWipe) {\r
234 uint8_t oldblock0[16] = {0x00};\r
235 uint8_t block0[16] = {0x00};\r
236\r
237 int old = mfCGetBlock(0, oldblock0, CSETBLOCK_SINGLE_OPER);\r
238 if (old == 0) {\r
239 memcpy(block0, oldblock0, 16);\r
240 PrintAndLog("old block 0: %s", sprint_hex(block0,16));\r
241 } else {\r
242 PrintAndLog("Couldn't get old data. Will write over the last bytes of Block 0.");\r
243 }\r
244\r
245 // fill in the new values\r
246 // UID\r
247 memcpy(block0, uid, 4); \r
248 // Mifare UID BCC\r
249 block0[4] = block0[0]^block0[1]^block0[2]^block0[3];\r
250 // mifare classic SAK(byte 5) and ATQA(byte 6 and 7, reversed)\r
251 if (sak!=NULL)\r
252 block0[5]=sak[0];\r
253 if (atqa!=NULL) {\r
254 block0[6]=atqa[1];\r
255 block0[7]=atqa[0];\r
256 }\r
257 PrintAndLog("new block 0: %s", sprint_hex(block0,16));\r
258 return mfCSetBlock(0, block0, oldUID, wantWipe, CSETBLOCK_SINGLE_OPER);\r
259}\r
260\r
261int mfCSetBlock(uint8_t blockNo, uint8_t *data, uint8_t *uid, bool wantWipe, uint8_t params) {\r
262\r
263 uint8_t isOK = 0;\r
264 UsbCommand c = {CMD_MIFARE_CSETBLOCK, {wantWipe, params & (0xFE | (uid == NULL ? 0:1)), blockNo}};\r
265 memcpy(c.d.asBytes, data, 16); \r
266 SendCommand(&c);\r
267\r
268 UsbCommand resp;\r
269 if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {\r
270 isOK = resp.arg[0] & 0xff;\r
271 if (uid != NULL) \r
272 memcpy(uid, resp.d.asBytes, 4);\r
273 if (!isOK) \r
274 return 2;\r
275 } else {\r
276 PrintAndLog("Command execute timeout");\r
277 return 1;\r
278 }\r
279 return 0;\r
280}\r
281\r
282int mfCGetBlock(uint8_t blockNo, uint8_t *data, uint8_t params) {\r
283 uint8_t isOK = 0;\r
284\r
285 UsbCommand c = {CMD_MIFARE_CGETBLOCK, {params, 0, blockNo}};\r
286 SendCommand(&c);\r
287\r
288 UsbCommand resp;\r
289 if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {\r
290 isOK = resp.arg[0] & 0xff;\r
291 memcpy(data, resp.d.asBytes, 16);\r
292 if (!isOK) return 2;\r
293 } else {\r
294 PrintAndLog("Command execute timeout");\r
295 return 1;\r
296 }\r
297 return 0;\r
298}\r
299\r
300// SNIFFER\r
301\r
302// constants\r
303static uint8_t trailerAccessBytes[4] = {0x08, 0x77, 0x8F, 0x00};\r
304\r
305// variables\r
306char logHexFileName[FILE_PATH_SIZE] = {0x00};\r
307static uint8_t traceCard[4096] = {0x00};\r
308static char traceFileName[FILE_PATH_SIZE] = {0x00};\r
309static int traceState = TRACE_IDLE;\r
310static uint8_t traceCurBlock = 0;\r
311static uint8_t traceCurKey = 0;\r
312\r
313struct Crypto1State *traceCrypto1 = NULL;\r
314\r
315struct Crypto1State *revstate;\r
316uint64_t lfsr;\r
317uint32_t ks2;\r
318uint32_t ks3;\r
319\r
320uint32_t uid; // serial number\r
321uint32_t nt; // tag challenge\r
322uint32_t nr_enc; // encrypted reader challenge\r
323uint32_t ar_enc; // encrypted reader response\r
324uint32_t at_enc; // encrypted tag response\r
325\r
326int isTraceCardEmpty(void) {\r
327 return ((traceCard[0] == 0) && (traceCard[1] == 0) && (traceCard[2] == 0) && (traceCard[3] == 0));\r
328}\r
329\r
330int isBlockEmpty(int blockN) {\r
331 for (int i = 0; i < 16; i++) \r
332 if (traceCard[blockN * 16 + i] != 0) return 0;\r
333\r
334 return 1;\r
335}\r
336\r
337int isBlockTrailer(int blockN) {\r
338 return ((blockN & 0x03) == 0x03);\r
339}\r
340\r
341int loadTraceCard(uint8_t *tuid) {\r
342 FILE * f;\r
343 char buf[64] = {0x00};\r
344 uint8_t buf8[64] = {0x00};\r
345 int i, blockNum;\r
346 \r
347 if (!isTraceCardEmpty()) \r
348 saveTraceCard();\r
349 \r
350 memset(traceCard, 0x00, 4096);\r
351 memcpy(traceCard, tuid + 3, 4);\r
352\r
353 FillFileNameByUID(traceFileName, tuid, ".eml", 7);\r
354\r
355 f = fopen(traceFileName, "r");\r
356 if (!f) {\r
357 fclose(f);\r
358 return 1;\r
359 }\r
360 \r
361 blockNum = 0;\r
362 \r
363 while(!feof(f)){\r
364 \r
365 memset(buf, 0, sizeof(buf));\r
366 if (fgets(buf, sizeof(buf), f) == NULL) {\r
367 PrintAndLog("File reading error.");\r
368 fclose(f);\r
369 return 2;\r
370 }\r
371\r
372 if (strlen(buf) < 32){\r
373 if (feof(f)) break;\r
374 PrintAndLog("File content error. Block data must include 32 HEX symbols");\r
375 fclose(f);\r
376 return 2;\r
377 }\r
378 for (i = 0; i < 32; i += 2)\r
379 sscanf(&buf[i], "%02x", (unsigned int *)&buf8[i / 2]);\r
380\r
381 memcpy(traceCard + blockNum * 16, buf8, 16);\r
382\r
383 blockNum++;\r
384 }\r
385 fclose(f);\r
386\r
387 return 0;\r
388}\r
389\r
390int saveTraceCard(void) {\r
391 FILE * f;\r
392 \r
393 if ((!strlen(traceFileName)) || (isTraceCardEmpty())) return 0;\r
394 \r
395 f = fopen(traceFileName, "w+");\r
396 if ( !f ) {\r
397 fclose(f);\r
398 return 1;\r
399 }\r
400 \r
401 for (int i = 0; i < 64; i++) { // blocks\r
402 for (int j = 0; j < 16; j++) // bytes\r
403 fprintf(f, "%02x", *(traceCard + i * 16 + j)); \r
404 fprintf(f,"\n");\r
405 }\r
406 fclose(f);\r
407 return 0;\r
408}\r
409\r
410int mfTraceInit(uint8_t *tuid, uint8_t *atqa, uint8_t sak, bool wantSaveToEmlFile) {\r
411\r
412 if (traceCrypto1) \r
413 crypto1_destroy(traceCrypto1);\r
414\r
415 traceCrypto1 = NULL;\r
416\r
417 if (wantSaveToEmlFile) \r
418 loadTraceCard(tuid);\r
419 \r
420 traceCard[4] = traceCard[0] ^ traceCard[1] ^ traceCard[2] ^ traceCard[3];\r
421 traceCard[5] = sak;\r
422 memcpy(&traceCard[6], atqa, 2);\r
423 traceCurBlock = 0;\r
424 uid = bytes_to_num(tuid + 3, 4);\r
425 \r
426 traceState = TRACE_IDLE;\r
427\r
428 return 0;\r
429}\r
430\r
431void mf_crypto1_decrypt(struct Crypto1State *pcs, uint8_t *data, int len, bool isEncrypted){\r
432 uint8_t bt = 0;\r
433 int i;\r
434 \r
435 if (len != 1) {\r
436 for (i = 0; i < len; i++)\r
437 data[i] = crypto1_byte(pcs, 0x00, isEncrypted) ^ data[i];\r
438 } else {\r
439 bt = 0;\r
440 for (i = 0; i < 4; i++)\r
441 bt |= (crypto1_bit(pcs, 0, isEncrypted) ^ BIT(data[0], i)) << i;\r
442 \r
443 data[0] = bt;\r
444 }\r
445 return;\r
446}\r
447\r
448\r
449int mfTraceDecode(uint8_t *data_src, int len, bool wantSaveToEmlFile) {\r
450 uint8_t data[64];\r
451\r
452 if (traceState == TRACE_ERROR) return 1;\r
453 if (len > 64) {\r
454 traceState = TRACE_ERROR;\r
455 return 1;\r
456 }\r
457 \r
458 memcpy(data, data_src, len);\r
459 if ((traceCrypto1) && ((traceState == TRACE_IDLE) || (traceState > TRACE_AUTH_OK))) {\r
460 mf_crypto1_decrypt(traceCrypto1, data, len, 0);\r
461 PrintAndLog("dec> %s", sprint_hex(data, len));\r
462 AddLogHex(logHexFileName, "dec> ", data, len); \r
463 }\r
464 \r
465 switch (traceState) {\r
466 case TRACE_IDLE: \r
467 // check packet crc16!\r
468 if ((len >= 4) && (!CheckCrc14443(CRC_14443_A, data, len))) {\r
469 PrintAndLog("dec> CRC ERROR!!!");\r
470 AddLogLine(logHexFileName, "dec> ", "CRC ERROR!!!"); \r
471 traceState = TRACE_ERROR; // do not decrypt the next commands\r
472 return 1;\r
473 }\r
474 \r
475 // AUTHENTICATION\r
476 if ((len == 4) && ((data[0] == 0x60) || (data[0] == 0x61))) {\r
477 traceState = TRACE_AUTH1;\r
478 traceCurBlock = data[1];\r
479 traceCurKey = data[0] == 60 ? 1:0;\r
480 return 0;\r
481 }\r
482\r
483 // READ\r
484 if ((len ==4) && ((data[0] == 0x30))) {\r
485 traceState = TRACE_READ_DATA;\r
486 traceCurBlock = data[1];\r
487 return 0;\r
488 }\r
489\r
490 // WRITE\r
491 if ((len ==4) && ((data[0] == 0xA0))) {\r
492 traceState = TRACE_WRITE_OK;\r
493 traceCurBlock = data[1];\r
494 return 0;\r
495 }\r
496\r
497 // HALT\r
498 if ((len ==4) && ((data[0] == 0x50) && (data[1] == 0x00))) {\r
499 traceState = TRACE_ERROR; // do not decrypt the next commands\r
500 return 0;\r
501 }\r
502 \r
503 return 0;\r
504 break;\r
505 \r
506 case TRACE_READ_DATA: \r
507 if (len == 18) {\r
508 traceState = TRACE_IDLE;\r
509\r
510 if (isBlockTrailer(traceCurBlock)) {\r
511 memcpy(traceCard + traceCurBlock * 16 + 6, data + 6, 4);\r
512 } else {\r
513 memcpy(traceCard + traceCurBlock * 16, data, 16);\r
514 }\r
515 if (wantSaveToEmlFile) saveTraceCard();\r
516 return 0;\r
517 } else {\r
518 traceState = TRACE_ERROR;\r
519 return 1;\r
520 }\r
521 break;\r
522\r
523 case TRACE_WRITE_OK: \r
524 if ((len == 1) && (data[0] == 0x0a)) {\r
525 traceState = TRACE_WRITE_DATA;\r
526\r
527 return 0;\r
528 } else {\r
529 traceState = TRACE_ERROR;\r
530 return 1;\r
531 }\r
532 break;\r
533\r
534 case TRACE_WRITE_DATA: \r
535 if (len == 18) {\r
536 traceState = TRACE_IDLE;\r
537\r
538 memcpy(traceCard + traceCurBlock * 16, data, 16);\r
539 if (wantSaveToEmlFile) saveTraceCard();\r
540 return 0;\r
541 } else {\r
542 traceState = TRACE_ERROR;\r
543 return 1;\r
544 }\r
545 break;\r
546\r
547 case TRACE_AUTH1: \r
548 if (len == 4) {\r
549 traceState = TRACE_AUTH2;\r
550 nt = bytes_to_num(data, 4);\r
551 return 0;\r
552 } else {\r
553 traceState = TRACE_ERROR;\r
554 return 1;\r
555 }\r
556 break;\r
557\r
558 case TRACE_AUTH2: \r
559 if (len == 8) {\r
560 traceState = TRACE_AUTH_OK;\r
561\r
562 nr_enc = bytes_to_num(data, 4);\r
563 ar_enc = bytes_to_num(data + 4, 4);\r
564 return 0;\r
565 } else {\r
566 traceState = TRACE_ERROR;\r
567 return 1;\r
568 }\r
569 break;\r
570\r
571 case TRACE_AUTH_OK: \r
572 if (len ==4) {\r
573 traceState = TRACE_IDLE;\r
574\r
575 at_enc = bytes_to_num(data, 4);\r
576 \r
577 // decode key here)\r
578 ks2 = ar_enc ^ prng_successor(nt, 64);\r
579 ks3 = at_enc ^ prng_successor(nt, 96);\r
580 revstate = lfsr_recovery64(ks2, ks3);\r
581 lfsr_rollback_word(revstate, 0, 0);\r
582 lfsr_rollback_word(revstate, 0, 0);\r
583 lfsr_rollback_word(revstate, nr_enc, 1);\r
584 lfsr_rollback_word(revstate, uid ^ nt, 0);\r
585\r
586 crypto1_get_lfsr(revstate, &lfsr);\r
587 printf("key> %x%x\n", (unsigned int)((lfsr & 0xFFFFFFFF00000000) >> 32), (unsigned int)(lfsr & 0xFFFFFFFF));\r
588 AddLogUint64(logHexFileName, "key> ", lfsr); \r
589 \r
590 int blockShift = ((traceCurBlock & 0xFC) + 3) * 16;\r
591 if (isBlockEmpty((traceCurBlock & 0xFC) + 3)) memcpy(traceCard + blockShift + 6, trailerAccessBytes, 4);\r
592 \r
593 if (traceCurKey) {\r
594 num_to_bytes(lfsr, 6, traceCard + blockShift + 10);\r
595 } else {\r
596 num_to_bytes(lfsr, 6, traceCard + blockShift);\r
597 }\r
598 if (wantSaveToEmlFile) saveTraceCard();\r
599\r
600 if (traceCrypto1) {\r
601 crypto1_destroy(traceCrypto1);\r
602 }\r
603 \r
604 // set cryptosystem state\r
605 traceCrypto1 = lfsr_recovery64(ks2, ks3);\r
606 \r
607// nt = crypto1_word(traceCrypto1, nt ^ uid, 1) ^ nt;\r
608\r
609 /* traceCrypto1 = crypto1_create(lfsr); // key in lfsr\r
610 crypto1_word(traceCrypto1, nt ^ uid, 0);\r
611 crypto1_word(traceCrypto1, ar, 1);\r
612 crypto1_word(traceCrypto1, 0, 0);\r
613 crypto1_word(traceCrypto1, 0, 0);*/\r
614 \r
615 return 0;\r
616 } else {\r
617 traceState = TRACE_ERROR;\r
618 return 1;\r
619 }\r
620 break;\r
621\r
622 default: \r
623 traceState = TRACE_ERROR;\r
624 return 1;\r
625 }\r
626\r
627 return 0;\r
628}\r
Impressum, Datenschutz