]> git.zerfleddert.de Git - proxmark3-svn/blame - client/mifarehost.c
next update from en4rab on data samples
[proxmark3-svn] / client / mifarehost.c
CommitLineData
b62a5a84 1// Merlok, 2011, 2012\r
f397b5cc
M
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
55acbb2a 8// mifare commands\r
f397b5cc
M
9//-----------------------------------------------------------------------------\r
10\r
11#include <stdio.h>\r
873014de 12#include <stdlib.h> \r
31b6e9af 13#include <string.h>\r
f397b5cc 14#include "mifarehost.h"\r
902cb3c0 15#include "proxmark3.h"\r
f397b5cc 16\r
55acbb2a 17// MIFARE\r
f397b5cc
M
18int compar_int(const void * a, const void * b) {\r
19 return (*(uint64_t*)b - *(uint64_t*)a);\r
20}\r
21\r
22// Compare countKeys structure\r
23int compar_special_int(const void * a, const void * b) {\r
24 return (((countKeys *)b)->count - ((countKeys *)a)->count);\r
25}\r
26\r
27countKeys * uniqsort(uint64_t * possibleKeys, uint32_t size) {\r
28 int i, j = 0;\r
29 int count = 0;\r
30 countKeys *our_counts;\r
31 \r
32 qsort(possibleKeys, size, sizeof (uint64_t), compar_int);\r
33 \r
34 our_counts = calloc(size, sizeof(countKeys));\r
35 if (our_counts == NULL) {\r
36 PrintAndLog("Memory allocation error for our_counts");\r
37 return NULL;\r
38 }\r
39 \r
40 for (i = 0; i < size; i++) {\r
41 if (possibleKeys[i+1] == possibleKeys[i]) { \r
42 count++;\r
43 } else {\r
44 our_counts[j].key = possibleKeys[i];\r
45 our_counts[j].count = count;\r
46 j++;\r
47 count=0;\r
48 }\r
49 }\r
50 qsort(our_counts, j, sizeof(countKeys), compar_special_int);\r
51 return (our_counts);\r
52}\r
53\r
54int mfnested(uint8_t blockNo, uint8_t keyType, uint8_t * key, uint8_t trgBlockNo, uint8_t trgKeyType, uint8_t * resultKeys) \r
55{\r
56 int i, m, len;\r
57 uint8_t isEOF;\r
58 uint32_t uid;\r
59 fnVector * vector = NULL;\r
60 countKeys *ck;\r
61 int lenVector = 0;\r
902cb3c0 62 UsbCommand resp;\r
f397b5cc
M
63 \r
64 memset(resultKeys, 0x00, 16 * 6);\r
65\r
66 // flush queue\r
7dd1908b 67 WaitForResponseTimeout(CMD_ACK,NULL,100);\r
f397b5cc
M
68 \r
69 UsbCommand c = {CMD_MIFARE_NESTED, {blockNo, keyType, trgBlockNo + trgKeyType * 0x100}};\r
70 memcpy(c.d.asBytes, key, 6);\r
71 SendCommand(&c);\r
72\r
73 PrintAndLog("\n");\r
74\r
75 // wait cycle\r
76 while (true) {\r
77 printf(".");\r
78 if (ukbhit()) {\r
79 getchar();\r
80 printf("\naborted via keyboard!\n");\r
81 break;\r
82 }\r
83\r
902cb3c0 84 if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {\r
85 isEOF = resp.arg[0] & 0xff;\r
f397b5cc
M
86\r
87 if (isEOF) break;\r
88 \r
902cb3c0 89 len = resp.arg[1] & 0xff;\r
f397b5cc
M
90 if (len == 0) continue;\r
91 \r
902cb3c0 92 memcpy(&uid, resp.d.asBytes, 4);\r
93 PrintAndLog("uid:%08x len=%d trgbl=%d trgkey=%x", uid, len, resp.arg[2] & 0xff, (resp.arg[2] >> 8) & 0xff);\r
f397b5cc
M
94 vector = (fnVector *) realloc((void *)vector, (lenVector + len) * sizeof(fnVector) + 200);\r
95 if (vector == NULL) {\r
96 PrintAndLog("Memory allocation error for fnVector. len: %d bytes: %d", lenVector + len, (lenVector + len) * sizeof(fnVector)); \r
97 break;\r
98 }\r
99 \r
100 for (i = 0; i < len; i++) {\r
902cb3c0 101 vector[lenVector + i].blockNo = resp.arg[2] & 0xff;\r
102 vector[lenVector + i].keyType = (resp.arg[2] >> 8) & 0xff;\r
f397b5cc
M
103 vector[lenVector + i].uid = uid;\r
104\r
902cb3c0 105 memcpy(&vector[lenVector + i].nt, (void *)(resp.d.asBytes + 8 + i * 8 + 0), 4);\r
106 memcpy(&vector[lenVector + i].ks1, (void *)(resp.d.asBytes + 8 + i * 8 + 4), 4);\r
f397b5cc
M
107 }\r
108\r
109 lenVector += len;\r
110 }\r
111 }\r
112 \r
113 if (!lenVector) {\r
114 PrintAndLog("Got 0 keys from proxmark."); \r
115 return 1;\r
116 }\r
117 printf("------------------------------------------------------------------\n");\r
118 \r
119 // calc keys\r
120 struct Crypto1State* revstate = NULL;\r
121 struct Crypto1State* revstate_start = NULL;\r
122 uint64_t lfsr;\r
123 int kcount = 0;\r
124 pKeys *pk;\r
125 \r
126 if ((pk = (void *) malloc(sizeof(pKeys))) == NULL) return 1;\r
127 memset(pk, 0x00, sizeof(pKeys));\r
128 \r
129 for (m = 0; m < lenVector; m++) {\r
130 // And finally recover the first 32 bits of the key\r
131 revstate = lfsr_recovery32(vector[m].ks1, vector[m].nt ^ vector[m].uid);\r
132 if (revstate_start == NULL) revstate_start = revstate;\r
133 \r
134 while ((revstate->odd != 0x0) || (revstate->even != 0x0)) {\r
135 lfsr_rollback_word(revstate, vector[m].nt ^ vector[m].uid, 0);\r
136 crypto1_get_lfsr(revstate, &lfsr);\r
137\r
138 // Allocate a new space for keys\r
139 if (((kcount % MEM_CHUNK) == 0) || (kcount >= pk->size)) {\r
140 pk->size += MEM_CHUNK;\r
141//fprintf(stdout, "New chunk by %d, sizeof %d\n", kcount, pk->size * sizeof(uint64_t));\r
142 pk->possibleKeys = (uint64_t *) realloc((void *)pk->possibleKeys, pk->size * sizeof(uint64_t));\r
143 if (pk->possibleKeys == NULL) {\r
144 PrintAndLog("Memory allocation error for pk->possibleKeys"); \r
145 return 1;\r
146 }\r
147 }\r
148 pk->possibleKeys[kcount] = lfsr;\r
149 kcount++;\r
150 revstate++;\r
151 }\r
152 free(revstate_start);\r
153 revstate_start = NULL;\r
154\r
155 }\r
156 \r
157 // Truncate\r
158 if (kcount != 0) {\r
159 pk->size = --kcount;\r
160 if ((pk->possibleKeys = (uint64_t *) realloc((void *)pk->possibleKeys, pk->size * sizeof(uint64_t))) == NULL) {\r
161 PrintAndLog("Memory allocation error for pk->possibleKeys"); \r
162 return 1;\r
163 } \r
164 }\r
165\r
166 PrintAndLog("Total keys count:%d", kcount);\r
167 ck = uniqsort(pk->possibleKeys, pk->size);\r
168\r
169 // fill key array\r
170 for (i = 0; i < 16 ; i++) {\r
171 num_to_bytes(ck[i].key, 6, (uint8_t*)(resultKeys + i * 6));\r
172 }\r
173\r
174 // finalize\r
175 free(pk->possibleKeys);\r
176 free(pk);\r
177 free(ck);\r
178 free(vector);\r
179\r
180 return 0;\r
181}\r
182\r
183int mfCheckKeys (uint8_t blockNo, uint8_t keyType, uint8_t keycnt, uint8_t * keyBlock, uint64_t * key){\r
184 *key = 0;\r
185\r
186 UsbCommand c = {CMD_MIFARE_CHKKEYS, {blockNo, keyType, keycnt}};\r
187 memcpy(c.d.asBytes, keyBlock, 6 * keycnt);\r
f397b5cc
M
188 SendCommand(&c);\r
189\r
902cb3c0 190 UsbCommand resp;\r
191 if (!WaitForResponseTimeout(CMD_ACK,&resp,3000)) return 1;\r
192 if ((resp.arg[0] & 0xff) != 0x01) return 2;\r
193 *key = bytes_to_num(resp.d.asBytes, 6);\r
f397b5cc
M
194 return 0;\r
195}\r
8556b852 196\r
55acbb2a
M
197// EMULATOR\r
198\r
8556b852 199int mfEmlGetMem(uint8_t *data, int blockNum, int blocksCount) {\r
545a1f38 200 UsbCommand c = {CMD_MIFARE_EML_MEMGET, {blockNum, blocksCount, 0}};\r
902cb3c0 201 SendCommand(&c);\r
8556b852 202\r
902cb3c0 203 UsbCommand resp;\r
204 if (!WaitForResponseTimeout(CMD_ACK,&resp,1500)) return 1;\r
205 memcpy(data, resp.d.asBytes, blocksCount * 16);\r
8556b852
M
206 return 0;\r
207}\r
208\r
209int mfEmlSetMem(uint8_t *data, int blockNum, int blocksCount) {\r
545a1f38 210 UsbCommand c = {CMD_MIFARE_EML_MEMSET, {blockNum, blocksCount, 0}};\r
8556b852 211 memcpy(c.d.asBytes, data, blocksCount * 16); \r
545a1f38 212 SendCommand(&c);\r
8556b852
M
213 return 0;\r
214}\r
215\r
55acbb2a
M
216// "MAGIC" CARD\r
217\r
0675f200 218int mfCSetUID(uint8_t *uid, uint8_t *oldUID, int wantWipe) {\r
0675f200
M
219 uint8_t block0[16];\r
220 memset(block0, 0, 16);\r
221 memcpy(block0, uid, 4); \r
222 block0[4] = block0[0]^block0[1]^block0[2]^block0[3]; // Mifare UID BCC\r
8784cd1a
M
223 // mifare classic SAK(byte 5) and ATQA(byte 6 and 7)\r
224 block0[5] = 0x88;\r
225 block0[6] = 0x04;\r
226 block0[7] = 0x00;\r
f774db95 227 \r
208a0166 228 return mfCSetBlock(0, block0, oldUID, wantWipe, CSETBLOCK_SINGLE_OPER);\r
f774db95
M
229}\r
230\r
208a0166 231int mfCSetBlock(uint8_t blockNo, uint8_t *data, uint8_t *uid, int wantWipe, uint8_t params) {\r
f774db95 232 uint8_t isOK = 0;\r
0675f200 233\r
545a1f38 234 UsbCommand c = {CMD_MIFARE_EML_CSETBLOCK, {wantWipe, params & (0xFE | (uid == NULL ? 0:1)), blockNo}};\r
f774db95 235 memcpy(c.d.asBytes, data, 16); \r
545a1f38 236 SendCommand(&c);\r
0675f200 237\r
902cb3c0 238 UsbCommand resp;\r
239 if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {\r
240 isOK = resp.arg[0] & 0xff;\r
241 if (uid != NULL) memcpy(uid, resp.d.asBytes, 4);\r
0675f200
M
242 if (!isOK) return 2;\r
243 } else {\r
244 PrintAndLog("Command execute timeout");\r
245 return 1;\r
246 }\r
247 return 0;\r
248}\r
545a1f38
M
249\r
250int mfCGetBlock(uint8_t blockNo, uint8_t *data, uint8_t params) {\r
251 uint8_t isOK = 0;\r
252\r
253 UsbCommand c = {CMD_MIFARE_EML_CGETBLOCK, {params, 0, blockNo}};\r
254 SendCommand(&c);\r
255\r
902cb3c0 256 UsbCommand resp;\r
257 if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {\r
258 isOK = resp.arg[0] & 0xff;\r
259 memcpy(data, resp.d.asBytes, 16);\r
545a1f38
M
260 if (!isOK) return 2;\r
261 } else {\r
262 PrintAndLog("Command execute timeout");\r
263 return 1;\r
264 }\r
265 return 0;\r
266}\r
55acbb2a
M
267\r
268// SNIFFER\r
269\r
e0c635d1
M
270// constants\r
271static uint8_t trailerAccessBytes[4] = {0x08, 0x77, 0x8F, 0x00};\r
272\r
55acbb2a
M
273// variables\r
274char logHexFileName[200] = {0x00};\r
e0c635d1
M
275static uint8_t traceCard[4096] = {0x00};\r
276static char traceFileName[20];\r
55acbb2a
M
277static int traceState = TRACE_IDLE;\r
278static uint8_t traceCurBlock = 0;\r
279static uint8_t traceCurKey = 0;\r
280\r
281struct Crypto1State *traceCrypto1 = NULL;\r
282\r
283struct Crypto1State *revstate;\r
284uint64_t lfsr;\r
285uint32_t ks2;\r
286uint32_t ks3;\r
287\r
288uint32_t uid; // serial number\r
289uint32_t nt; // tag challenge\r
71d90e54 290uint32_t nt_par; \r
55acbb2a
M
291uint32_t nr_enc; // encrypted reader challenge\r
292uint32_t ar_enc; // encrypted reader response\r
71d90e54 293uint32_t nr_ar_par; \r
55acbb2a 294uint32_t at_enc; // encrypted tag response\r
71d90e54 295uint32_t at_par; \r
55acbb2a 296\r
e0c635d1
M
297int isTraceCardEmpty(void) {\r
298 return ((traceCard[0] == 0) && (traceCard[1] == 0) && (traceCard[2] == 0) && (traceCard[3] == 0));\r
299}\r
55acbb2a 300\r
e0c635d1
M
301int isBlockEmpty(int blockN) {\r
302 for (int i = 0; i < 16; i++) \r
303 if (traceCard[blockN * 16 + i] != 0) return 0;\r
55acbb2a 304\r
e0c635d1
M
305 return 1;\r
306}\r
307\r
308int isBlockTrailer(int blockN) {\r
309 return ((blockN & 0x03) == 0x03);\r
310}\r
311\r
312int loadTraceCard(uint8_t *tuid) {\r
313 FILE * f;\r
314 char buf[64];\r
315 uint8_t buf8[64];\r
316 int i, blockNum;\r
317 \r
318 if (!isTraceCardEmpty()) saveTraceCard();\r
55acbb2a
M
319 memset(traceCard, 0x00, 4096);\r
320 memcpy(traceCard, tuid + 3, 4);\r
e0c635d1
M
321 FillFileNameByUID(traceFileName, tuid, ".eml", 7);\r
322\r
323 f = fopen(traceFileName, "r");\r
324 if (!f) return 1;\r
325 \r
326 blockNum = 0;\r
327 while(!feof(f)){\r
328 memset(buf, 0, sizeof(buf));\r
759c16b3 329 if (fgets(buf, sizeof(buf), f) == NULL) {\r
330 PrintAndLog("File reading error.");\r
331 return 2;\r
332 }\r
e0c635d1
M
333\r
334 if (strlen(buf) < 32){\r
335 if (feof(f)) break;\r
336 PrintAndLog("File content error. Block data must include 32 HEX symbols");\r
337 return 2;\r
338 }\r
339 for (i = 0; i < 32; i += 2)\r
340 sscanf(&buf[i], "%02x", (unsigned int *)&buf8[i / 2]);\r
341\r
342 memcpy(traceCard + blockNum * 16, buf8, 16);\r
343\r
344 blockNum++;\r
345 }\r
346 fclose(f);\r
347\r
348 return 0;\r
349}\r
350\r
351int saveTraceCard(void) {\r
352 FILE * f;\r
353 \r
354 if ((!strlen(traceFileName)) || (isTraceCardEmpty())) return 0;\r
355 \r
356 f = fopen(traceFileName, "w+");\r
357 for (int i = 0; i < 64; i++) { // blocks\r
358 for (int j = 0; j < 16; j++) // bytes\r
359 fprintf(f, "%02x", *(traceCard + i * 16 + j)); \r
360 fprintf(f,"\n");\r
361 }\r
362 fclose(f);\r
363\r
364 return 0;\r
365}\r
366\r
367int mfTraceInit(uint8_t *tuid, uint8_t *atqa, uint8_t sak, bool wantSaveToEmlFile) {\r
368\r
369 if (traceCrypto1) crypto1_destroy(traceCrypto1);\r
370 traceCrypto1 = NULL;\r
371\r
372 if (wantSaveToEmlFile) loadTraceCard(tuid);\r
55acbb2a
M
373 traceCard[4] = traceCard[0] ^ traceCard[1] ^ traceCard[2] ^ traceCard[3];\r
374 traceCard[5] = sak;\r
375 memcpy(&traceCard[6], atqa, 2);\r
376 traceCurBlock = 0;\r
377 uid = bytes_to_num(tuid + 3, 4);\r
378 \r
379 traceState = TRACE_IDLE;\r
380\r
381 return 0;\r
382}\r
383\r
384void mf_crypto1_decrypt(struct Crypto1State *pcs, uint8_t *data, int len, bool isEncrypted){\r
385 uint8_t bt = 0;\r
386 int i;\r
387 \r
388 if (len != 1) {\r
389 for (i = 0; i < len; i++)\r
390 data[i] = crypto1_byte(pcs, 0x00, isEncrypted) ^ data[i];\r
391 } else {\r
392 bt = 0;\r
393 for (i = 0; i < 4; i++)\r
394 bt |= (crypto1_bit(pcs, 0, isEncrypted) ^ BIT(data[0], i)) << i;\r
395 \r
396 data[0] = bt;\r
397 }\r
398 return;\r
399}\r
400\r
401\r
71d90e54 402int mfTraceDecode(uint8_t *data_src, int len, uint32_t parity, bool wantSaveToEmlFile) {\r
55acbb2a
M
403 uint8_t data[64];\r
404\r
405 if (traceState == TRACE_ERROR) return 1;\r
406 if (len > 64) {\r
407 traceState = TRACE_ERROR;\r
408 return 1;\r
409 }\r
410 \r
411 memcpy(data, data_src, len);\r
412 if ((traceCrypto1) && ((traceState == TRACE_IDLE) || (traceState > TRACE_AUTH_OK))) {\r
413 mf_crypto1_decrypt(traceCrypto1, data, len, 0);\r
414 PrintAndLog("dec> %s", sprint_hex(data, len));\r
415 AddLogHex(logHexFileName, "dec> ", data, len); \r
416 }\r
417 \r
418 switch (traceState) {\r
419 case TRACE_IDLE: \r
8b6a93df
M
420 // check packet crc16!\r
421 if ((len >= 4) && (!CheckCrc14443(CRC_14443_A, data, len))) {\r
422 PrintAndLog("dec> CRC ERROR!!!");\r
423 AddLogLine(logHexFileName, "dec> ", "CRC ERROR!!!"); \r
424 traceState = TRACE_ERROR; // do not decrypt the next commands\r
425 return 1;\r
426 }\r
55acbb2a
M
427 \r
428 // AUTHENTICATION\r
429 if ((len ==4) && ((data[0] == 0x60) || (data[0] == 0x61))) {\r
430 traceState = TRACE_AUTH1;\r
431 traceCurBlock = data[1];\r
432 traceCurKey = data[0] == 60 ? 1:0;\r
433 return 0;\r
434 }\r
435\r
436 // READ\r
437 if ((len ==4) && ((data[0] == 0x30))) {\r
438 traceState = TRACE_READ_DATA;\r
439 traceCurBlock = data[1];\r
440 return 0;\r
441 }\r
442\r
443 // WRITE\r
444 if ((len ==4) && ((data[0] == 0xA0))) {\r
445 traceState = TRACE_WRITE_OK;\r
446 traceCurBlock = data[1];\r
447 return 0;\r
448 }\r
449\r
450 // HALT\r
451 if ((len ==4) && ((data[0] == 0x50) && (data[1] == 0x00))) {\r
452 traceState = TRACE_ERROR; // do not decrypt the next commands\r
453 return 0;\r
454 }\r
455 \r
456 return 0;\r
457 break;\r
458 \r
459 case TRACE_READ_DATA: \r
460 if (len == 18) {\r
461 traceState = TRACE_IDLE;\r
462\r
e0c635d1
M
463 if (isBlockTrailer(traceCurBlock)) {\r
464 memcpy(traceCard + traceCurBlock * 16 + 6, data + 6, 4);\r
465 } else {\r
466 memcpy(traceCard + traceCurBlock * 16, data, 16);\r
467 }\r
468 if (wantSaveToEmlFile) saveTraceCard();\r
55acbb2a
M
469 return 0;\r
470 } else {\r
471 traceState = TRACE_ERROR;\r
472 return 1;\r
473 }\r
474 break;\r
475\r
476 case TRACE_WRITE_OK: \r
477 if ((len == 1) && (data[0] = 0x0a)) {\r
478 traceState = TRACE_WRITE_DATA;\r
479\r
480 return 0;\r
481 } else {\r
482 traceState = TRACE_ERROR;\r
483 return 1;\r
484 }\r
485 break;\r
486\r
487 case TRACE_WRITE_DATA: \r
488 if (len == 18) {\r
489 traceState = TRACE_IDLE;\r
490\r
491 memcpy(traceCard + traceCurBlock * 16, data, 16);\r
e0c635d1 492 if (wantSaveToEmlFile) saveTraceCard();\r
55acbb2a
M
493 return 0;\r
494 } else {\r
495 traceState = TRACE_ERROR;\r
496 return 1;\r
497 }\r
498 break;\r
499\r
500 case TRACE_AUTH1: \r
501 if (len == 4) {\r
502 traceState = TRACE_AUTH2;\r
503\r
504 nt = bytes_to_num(data, 4);\r
71d90e54 505 nt_par = parity;\r
55acbb2a
M
506 return 0;\r
507 } else {\r
508 traceState = TRACE_ERROR;\r
509 return 1;\r
510 }\r
511 break;\r
512\r
513 case TRACE_AUTH2: \r
514 if (len == 8) {\r
515 traceState = TRACE_AUTH_OK;\r
516\r
517 nr_enc = bytes_to_num(data, 4);\r
518 ar_enc = bytes_to_num(data + 4, 4);\r
71d90e54 519 nr_ar_par = parity;\r
55acbb2a
M
520 return 0;\r
521 } else {\r
522 traceState = TRACE_ERROR;\r
523 return 1;\r
524 }\r
525 break;\r
526\r
527 case TRACE_AUTH_OK: \r
528 if (len ==4) {\r
529 traceState = TRACE_IDLE;\r
530\r
531 at_enc = bytes_to_num(data, 4);\r
71d90e54 532 at_par = parity;\r
55acbb2a
M
533 \r
534 // decode key here)\r
535 if (!traceCrypto1) {\r
536 ks2 = ar_enc ^ prng_successor(nt, 64);\r
537 ks3 = at_enc ^ prng_successor(nt, 96);\r
538 revstate = lfsr_recovery64(ks2, ks3);\r
539 lfsr_rollback_word(revstate, 0, 0);\r
540 lfsr_rollback_word(revstate, 0, 0);\r
541 lfsr_rollback_word(revstate, nr_enc, 1);\r
542 lfsr_rollback_word(revstate, uid ^ nt, 0);\r
543 }else{\r
544 ks2 = ar_enc ^ prng_successor(nt, 64);\r
545 ks3 = at_enc ^ prng_successor(nt, 96);\r
546 revstate = lfsr_recovery64(ks2, ks3);\r
547 lfsr_rollback_word(revstate, 0, 0);\r
548 lfsr_rollback_word(revstate, 0, 0);\r
549 lfsr_rollback_word(revstate, nr_enc, 1);\r
550 lfsr_rollback_word(revstate, uid ^ nt, 0);\r
551 }\r
552 crypto1_get_lfsr(revstate, &lfsr);\r
553 printf("key> %x%x\n", (unsigned int)((lfsr & 0xFFFFFFFF00000000) >> 32), (unsigned int)(lfsr & 0xFFFFFFFF));\r
554 AddLogUint64(logHexFileName, "key> ", lfsr); \r
555 \r
e0c635d1
M
556 int blockShift = ((traceCurBlock & 0xFC) + 3) * 16;\r
557 if (isBlockEmpty((traceCurBlock & 0xFC) + 3)) memcpy(traceCard + blockShift + 6, trailerAccessBytes, 4);\r
558 \r
55acbb2a 559 if (traceCurKey) {\r
e0c635d1 560 num_to_bytes(lfsr, 6, traceCard + blockShift + 10);\r
55acbb2a 561 } else {\r
e0c635d1 562 num_to_bytes(lfsr, 6, traceCard + blockShift);\r
55acbb2a 563 }\r
e0c635d1 564 if (wantSaveToEmlFile) saveTraceCard();\r
55acbb2a
M
565\r
566 if (traceCrypto1) {\r
567 crypto1_destroy(traceCrypto1);\r
568 }\r
569 \r
570 // set cryptosystem state\r
571 traceCrypto1 = lfsr_recovery64(ks2, ks3);\r
572 \r
573// nt = crypto1_word(traceCrypto1, nt ^ uid, 1) ^ nt;\r
574\r
575 /* traceCrypto1 = crypto1_create(lfsr); // key in lfsr\r
576 crypto1_word(traceCrypto1, nt ^ uid, 0);\r
577 crypto1_word(traceCrypto1, ar, 1);\r
578 crypto1_word(traceCrypto1, 0, 0);\r
579 crypto1_word(traceCrypto1, 0, 0);*/\r
580 \r
581 return 0;\r
582 } else {\r
583 traceState = TRACE_ERROR;\r
584 return 1;\r
585 }\r
586 break;\r
587\r
588 default: \r
589 traceState = TRACE_ERROR;\r
590 return 1;\r
591 }\r
592\r
593 return 0;\r
594}\r
Impressum, Datenschutz