]> git.zerfleddert.de Git - proxmark3-svn/blame - tools/nonce2key/nonce2key.c
chg: cleaning out timing.
[proxmark3-svn] / tools / nonce2key / nonce2key.c
CommitLineData
93f57590 1#include "crapto1.h"
125a98a1 2#define __STDC_FORMAT_MACROS
93f57590 3#include <inttypes.h>
4#include <stdio.h>
93f57590 5
6int main(const int argc, const char* argv[]) {
838c15a6 7 struct Crypto1State *state;
14d6c4fc 8 uint32_t pos, uid, nt, nr, rr, nr_diff;
9 uint8_t bt, i, ks3x[8], par[8][8];
10 uint64_t key_recovered;
838c15a6 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 }
9c624f67 19 sscanf(argv[1],"%08x", &uid);
20 sscanf(argv[2],"%08x", &nt);
21 sscanf(argv[3],"%016" SCNx64 ,&par_info);
22 sscanf(argv[4],"%016" SCNx64 ,&ks_info);
93f57590 23
838c15a6 24 // Reset the last three significant bits of the reader nonce
25 nr &= 0xffffff1f;
26
9c624f67 27 printf("\nuid(%08x) nt(%08x) par(%016" PRIx64 ") ks(%016" PRIx64 ")\n\n", uid, nt, par_info, ks_info);
838c15a6 28
29 for ( pos = 0; pos < 8; pos++ ) {
30 ks3x[7-pos] = (ks_info >> (pos*8)) & 0x0f;
31 bt = (par_info >> (pos*8)) & 0xff;
32
33 for ( i = 0; i < 8; i++) {
34 par[7-pos][i] = (bt >> i) & 0x01;
35 }
36 }
37
38 printf("|diff|{nr} |ks3|ks3^5|parity |\n");
39 printf("+----+--------+---+-----+---------------+\n");
40
41 for ( i = 0; i < 8; i++) {
42 nr_diff = nr | i << 5;
43 printf("| %02x |%08x| %01x | %01x |", i << 5, nr_diff, ks3x[i], ks3x[i]^5);
44
45 for ( pos = 0; pos < 7; pos++)
46 printf("%01x,", par[i][pos]);
47 printf("%01x|\n", par[i][7]);
48 }
49 printf("+----+--------+---+-----+---------------+\n");
14d6c4fc 50
838c15a6 51 state = lfsr_common_prefix(nr,rr,ks3x,par);
52 lfsr_rollback_word(state,uid^nt,0);
53 crypto1_get_lfsr(state,&key_recovered);
9c624f67 54 printf("\nkey recovered: %012" PRIx64 "\n\n", key_recovered);
838c15a6 55 crypto1_destroy(state);
838c15a6 56 return 0;
93f57590 57}
Impressum, Datenschutz