]> git.zerfleddert.de Git - proxmark3-svn/blame_incremental - tools/nonce2key/nonce2key.c
marcan's patch until he gets commit access. Remove C library's includes from the...
[proxmark3-svn] / tools / nonce2key / nonce2key.c
... / ...
CommitLineData
1#include "crapto1.h"
2#include <inttypes.h>
3#include <stdio.h>
4typedef unsigned char byte_t;
5
6int main(const int argc, const char* argv[]) {
7 struct Crypto1State *state;
8 uint32_t pos, uid, nt, nr, rr, nr_diff, ks1, ks2;
9 byte_t bt, i, ks3x[8], par[8][8];
10 uint64_t key, key_recovered;
11 uint64_t par_info;
12 uint64_t ks_info;
13 nr = rr = 0;
14
15 if (argc < 5) {
16 printf("\nsyntax: %s <uid> <nt> <par> <ks>\n\n",argv[0]);
17 return 1;
18 }
19 sscanf(argv[1],"%08x",&uid);
20 sscanf(argv[2],"%08x",&nt);
21 sscanf(argv[3],"%016llx",&par_info);
22 sscanf(argv[4],"%016llx",&ks_info);
23
24 // Reset the last three significant bits of the reader nonce
25 nr &= 0xffffff1f;
26
27 printf("\nuid(%08x) nt(%08x) par(%016llx) ks(%016llx)\n\n",uid,nt,par_info,ks_info);
28
29 for (pos=0; pos<8; pos++)
30 {
31 ks3x[7-pos] = (ks_info >> (pos*8)) & 0x0f;
32 bt = (par_info >> (pos*8)) & 0xff;
33 for (i=0; i<8; i++)
34 {
35 par[7-pos][i] = (bt >> i) & 0x01;
36 }
37 }
38
39 printf("|diff|{nr} |ks3|ks3^5|parity |\n");
40 printf("+----+--------+---+-----+---------------+\n");
41 for (i=0; i<8; i++)
42 {
43 nr_diff = nr | i << 5;
44 printf("| %02x |%08x|",i << 5, nr_diff);
45 printf(" %01x | %01x |",ks3x[i], ks3x[i]^5);
46 for (pos=0; pos<7; pos++) printf("%01x,",par[i][pos]);
47 printf("%01x|\n",par[i][7]);
48 }
49
50 state = lfsr_common_prefix(nr,rr,ks3x,par);
51 lfsr_rollback_word(state,uid^nt,0);
52 crypto1_get_lfsr(state,&key_recovered);
53 printf("\nkey recovered: %012llx\n\n",key_recovered);
54 crypto1_destroy(state);
55
56 return 0;
57}
Impressum, Datenschutz