]>
git.zerfleddert.de Git - proxmark3-svn/blob - tools/mfkey/mfkey64.c
1 #define __STDC_FORMAT_MACROS
10 int main (int argc
, char *argv
[]) {
11 struct Crypto1State
*revstate
;
12 uint64_t key
; // recovered key
13 uint32_t uid
; // serial number
14 uint32_t nt
; // tag challenge
15 uint32_t nr_enc
; // encrypted reader challenge
16 uint32_t ar_enc
; // encrypted reader response
17 uint32_t at_enc
; // encrypted tag response
18 uint32_t ks2
; // keystream used to encrypt reader response
19 uint32_t ks3
; // keystream used to encrypt tag response
21 printf("MIFARE Classic key recovery - based 64 bits of keystream\n");
22 printf("Recover key from only one complete authentication!\n\n");
25 printf(" syntax: %s <uid> <nt> <nr> <ar> <at>\n\n",argv
[0]);
29 sscanf(argv
[1],"%x",&uid
);
30 sscanf(argv
[2],"%x",&nt
);
31 sscanf(argv
[3],"%x",&nr_enc
);
32 sscanf(argv
[4],"%x",&ar_enc
);
33 sscanf(argv
[5],"%x",&at_enc
);
35 printf("Recovering key for:\n");
36 printf(" uid: %08x\n",uid
);
37 printf(" nt: %08x\n",nt
);
38 printf(" {nr}: %08x\n",nr_enc
);
39 printf(" {ar}: %08x\n",ar_enc
);
40 printf(" {at}: %08x\n",at_enc
);
42 // Generate lfsr succesors of the tag challenge
43 printf("\nLFSR succesors of the tag challenge:\n");
44 printf(" nt': %08x\n",prng_successor(nt
, 64));
45 printf(" nt'': %08x\n",prng_successor(nt
, 96));
49 // Extract the keystream from the messages
50 printf("\nKeystream used to generate {ar} and {at}:\n");
51 ks2
= ar_enc
^ prng_successor(nt
, 64);
52 ks3
= at_enc
^ prng_successor(nt
, 96);
53 printf(" ks2: %08x\n",ks2
);
54 printf(" ks3: %08x\n",ks3
);
56 revstate
= lfsr_recovery64(ks2
, ks3
);
57 lfsr_rollback_word(revstate
, 0, 0);
58 lfsr_rollback_word(revstate
, 0, 0);
59 lfsr_rollback_word(revstate
, nr_enc
, 1);
60 lfsr_rollback_word(revstate
, uid
^ nt
, 0);
61 crypto1_get_lfsr(revstate
, &key
);
62 printf("\nFound Key: [%012"llx
"]\n\n",key
);
63 crypto1_destroy(revstate
);
66 if ( t1
> 0 ) printf("Time : %.0f ticks \n", (float)t1
);