]> cvs.zerfleddert.de Git - proxmark3-svn/blame - tools/mfkey/mfkey64.c
add: timeouts for "lf read"
[proxmark3-svn] / tools / mfkey / mfkey64.c
CommitLineData
cda056bb 1#define __STDC_FORMAT_MACROS
2#include <inttypes.h>
3#define llx PRIx64
4#define lli PRIi64
5
7847961b 6// Test-file: test2.c
7#include "crapto1.h"
8#include <stdio.h>
9
10int main (int argc, char *argv[]) {
11 struct Crypto1State *revstate;
cda056bb 12 uint64_t key; // recovered key
7847961b 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
998064f8 18 uint32_t ks2; // keystream used to encrypt reader response
19 uint32_t ks3; // keystream used to encrypt tag response
7847961b 20
cda056bb 21 printf("MIFARE Classic key recovery - based 64 bits of keystream\n");
22 printf("Recover key from only one complete authentication!\n\n");
7847961b 23
24 if (argc < 6) {
25 printf(" syntax: %s <uid> <nt> <{nr}> <{ar}> <{at}>\n\n",argv[0]);
26 return 1;
27 }
28
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);
34
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);
41
42/*
43 uint32_t uid = 0x9c599b32;
44 uint32_t tag_challenge = 0x82a4166c;
45 uint32_t nr_enc = 0xa1e458ce;
46 uint32_t reader_response = 0x6eea41e0;
47 uint32_t tag_response = 0x5cadf439;
48*/
49 // Generate lfsr succesors of the tag challenge
50 printf("\nLFSR succesors of the tag challenge:\n");
51 printf(" nt': %08x\n",prng_successor(nt, 64));
52 printf(" nt'': %08x\n",prng_successor(nt, 96));
53
54 // Extract the keystream from the messages
55 printf("\nKeystream used to generate {ar} and {at}:\n");
998064f8 56 ks2 = ar_enc ^ prng_successor(nt, 64);
7847961b 57 ks3 = at_enc ^ prng_successor(nt, 96);
58 printf(" ks2: %08x\n",ks2);
59 printf(" ks3: %08x\n",ks3);
60
61 revstate = lfsr_recovery64(ks2, ks3);
62 lfsr_rollback_word(revstate, 0, 0);
63 lfsr_rollback_word(revstate, 0, 0);
64 lfsr_rollback_word(revstate, nr_enc, 1);
65 lfsr_rollback_word(revstate, uid ^ nt, 0);
cda056bb 66 crypto1_get_lfsr(revstate, &key);
67 printf("\nFound Key: [%012"llx"]\n\n",key);
b62328cc 68 crypto1_destroy(revstate);
7847961b 69
70 return 0;
71}
Impressum, Datenschutz