]> git.zerfleddert.de Git - proxmark3-svn/blame - client/cmdanalyse.c
BUG: forgot to remove
[proxmark3-svn] / client / cmdanalyse.c
CommitLineData
812513bf 1//-----------------------------------------------------------------------------
2// Copyright (C) 2016 iceman
3//
4// This code is licensed to you under the terms of the GNU GPL, version 2 or,
5// at your option, any later version. See the LICENSE.txt file for the text of
6// the license.
7//-----------------------------------------------------------------------------
8// Analyse bytes commands
9//-----------------------------------------------------------------------------
10#include "cmdanalyse.h"
b403c300 11#include "nonce2key/nonce2key.h"
812513bf 12
13static int CmdHelp(const char *Cmd);
14
15int usage_analyse_lcr(void) {
16 PrintAndLog("Specifying the bytes of a UID with a known LRC will find the last byte value");
17 PrintAndLog("needed to generate that LRC with a rolling XOR. All bytes should be specified in HEX.");
18 PrintAndLog("");
19 PrintAndLog("Usage: analyse lcr [h] <bytes>");
20 PrintAndLog("Options:");
21 PrintAndLog(" h This help");
22 PrintAndLog(" <bytes> bytes to calc missing XOR in a LCR");
23 PrintAndLog("");
24 PrintAndLog("Samples:");
25 PrintAndLog(" analyse lcr 04008064BA");
26 PrintAndLog("expected output: Target (BA) requires final LRC XOR byte value: 5A");
27 return 0;
28}
53b3c3e8 29int usage_analyse_checksum(void) {
30 PrintAndLog("The bytes will be added with eachother and than limited with the applied mask");
31 PrintAndLog("Finally compute ones' complement of the least significant bytes");
32 PrintAndLog("");
33 PrintAndLog("Usage: analyse chksum [h] b <bytes> m <mask>");
34 PrintAndLog("Options:");
35 PrintAndLog(" h This help");
36 PrintAndLog(" b <bytes> bytes to calc missing XOR in a LCR");
37 PrintAndLog(" m <mask> bit mask to limit the outpuyt");
38 PrintAndLog("");
39 PrintAndLog("Samples:");
40 PrintAndLog(" analyse chksum b 137AF00A0A0D m FF");
41 PrintAndLog("expected output: 0x61");
42 return 0;
43}
53b3c3e8 44int usage_analyse_crc(void){
45 PrintAndLog("A stub method to test different crc implementations inside the PM3 sourcecode. Just because you figured out the poly, doesn't mean you get the desired output");
46 PrintAndLog("");
47 PrintAndLog("Usage: analyse crc [h] <bytes>");
48 PrintAndLog("Options:");
49 PrintAndLog(" h This help");
50 PrintAndLog(" <bytes> bytes to calc crc");
51 PrintAndLog("");
52 PrintAndLog("Samples:");
53 PrintAndLog(" analyse crc 137AF00A0A0D");
54 return 0;
55}
09bb01c7 56int usage_analyse_hid(void){
57 PrintAndLog("Permute function from 'heart of darkness' paper.");
58 PrintAndLog("");
59 PrintAndLog("Usage: analyse hid [h] <r|f> <bytes>");
60 PrintAndLog("Options:");
61 PrintAndLog(" h This help");
62 PrintAndLog(" r reverse permuted key");
63 PrintAndLog(" f permute key");
64 PrintAndLog(" <bytes> input bytes");
65 PrintAndLog("");
66 PrintAndLog("Samples:");
67 PrintAndLog(" analyse hid r 0123456789abcdef");
68 return 0;
69}
53b3c3e8 70
812513bf 71static uint8_t calculateLRC( uint8_t* bytes, uint8_t len) {
72 uint8_t LRC = 0;
73 for (uint8_t i = 0; i < len; i++)
74 LRC ^= bytes[i];
75 return LRC;
76}
53b3c3e8 77
62dc7d4a 78static uint16_t calcSumCrumbAdd( uint8_t* bytes, uint8_t len, uint32_t mask) {
53b3c3e8 79 uint8_t sum = 0;
80 for (uint8_t i = 0; i < len; i++) {
81 sum += CRUMB(bytes[i], 0);
82 sum += CRUMB(bytes[i], 2);
83 sum += CRUMB(bytes[i], 4);
84 sum += CRUMB(bytes[i], 6);
85 }
6c283951 86 sum &= mask;
53b3c3e8 87 return sum;
88}
62dc7d4a 89static uint16_t calcSumCrumbAddOnes( uint8_t* bytes, uint8_t len, uint32_t mask) {
f054036a 90 return (~calcSumCrumbAdd(bytes, len, mask) & mask);
53b3c3e8 91}
62dc7d4a 92static uint16_t calcSumNibbleAdd( uint8_t* bytes, uint8_t len, uint32_t mask) {
53b3c3e8 93 uint8_t sum = 0;
94 for (uint8_t i = 0; i < len; i++) {
95 sum += NIBBLE_LOW(bytes[i]);
96 sum += NIBBLE_HIGH(bytes[i]);
97 }
6c283951 98 sum &= mask;
53b3c3e8 99 return sum;
100}
62dc7d4a 101static uint16_t calcSumNibbleAddOnes( uint8_t* bytes, uint8_t len, uint32_t mask){
f054036a 102 return (~calcSumNibbleAdd(bytes, len, mask) & mask);
53b3c3e8 103}
62dc7d4a 104static uint16_t calcSumCrumbXor( uint8_t* bytes, uint8_t len, uint32_t mask) {
2c601080 105 uint8_t sum = 0;
106 for (uint8_t i = 0; i < len; i++) {
107 sum ^= CRUMB(bytes[i], 0);
108 sum ^= CRUMB(bytes[i], 2);
109 sum ^= CRUMB(bytes[i], 4);
110 sum ^= CRUMB(bytes[i], 6);
111 }
112 sum &= mask;
113 return sum;
114}
62dc7d4a 115static uint16_t calcSumNibbleXor( uint8_t* bytes, uint8_t len, uint32_t mask) {
32da0a46 116 uint8_t sum = 0;
117 for (uint8_t i = 0; i < len; i++) {
118 sum ^= NIBBLE_LOW(bytes[i]);
119 sum ^= NIBBLE_HIGH(bytes[i]);
120 }
2c601080 121 sum &= mask;
32da0a46 122 return sum;
123}
62dc7d4a 124static uint16_t calcSumByteXor( uint8_t* bytes, uint8_t len, uint32_t mask) {
32da0a46 125 uint8_t sum = 0;
126 for (uint8_t i = 0; i < len; i++)
127 sum ^= bytes[i];
128 sum &= mask;
129 return sum;
130}
62dc7d4a 131static uint16_t calcSumByteAdd( uint8_t* bytes, uint8_t len, uint32_t mask) {
53b3c3e8 132 uint8_t sum = 0;
133 for (uint8_t i = 0; i < len; i++)
134 sum += bytes[i];
6c283951 135 sum &= mask;
53b3c3e8 136 return sum;
137}
138// Ones complement
62dc7d4a 139static uint16_t calcSumByteAddOnes( uint8_t* bytes, uint8_t len, uint32_t mask) {
f054036a 140 return (~calcSumByteAdd(bytes, len, mask) & mask);
53b3c3e8 141}
142
62dc7d4a 143static uint16_t calcSumByteSub( uint8_t* bytes, uint8_t len, uint32_t mask) {
53b3c3e8 144 uint8_t sum = 0;
145 for (uint8_t i = 0; i < len; i++)
146 sum -= bytes[i];
6c283951 147 sum &= mask;
53b3c3e8 148 return sum;
149}
62dc7d4a 150static uint16_t calcSumByteSubOnes( uint8_t* bytes, uint8_t len, uint32_t mask){
f054036a 151 return (~calcSumByteSub(bytes, len, mask) & mask);
53b3c3e8 152}
62dc7d4a 153static uint16_t calcSumNibbleSub( uint8_t* bytes, uint8_t len, uint32_t mask) {
53b3c3e8 154 uint8_t sum = 0;
155 for (uint8_t i = 0; i < len; i++) {
156 sum -= NIBBLE_LOW(bytes[i]);
157 sum -= NIBBLE_HIGH(bytes[i]);
158 }
6c283951 159 sum &= mask;
53b3c3e8 160 return sum;
161}
62dc7d4a 162static uint16_t calcSumNibbleSubOnes( uint8_t* bytes, uint8_t len, uint32_t mask) {
f054036a 163 return (~calcSumNibbleSub(bytes, len, mask) & mask);
53b3c3e8 164}
165
62dc7d4a 166// BSD shift checksum 8bit version
167static uint16_t calcBSDchecksum8( uint8_t* bytes, uint8_t len, uint32_t mask){
168 uint16_t sum = 0;
169 for(uint8_t i = 0; i < len; i++){
170 sum = ((sum & 0xFF) >> 1) | ((sum & 0x1) << 7); // rotate accumulator
171 sum += bytes[i]; // add next byte
172 sum &= 0xFF; //
173 }
174 sum &= mask;
175 return sum;
176}
177// BSD shift checksum 4bit version
178static uint16_t calcBSDchecksum4( uint8_t* bytes, uint8_t len, uint32_t mask){
179 uint16_t sum = 0;
180 for(uint8_t i = 0; i < len; i++){
181 sum = ((sum & 0xF) >> 1) | ((sum & 0x1) << 3); // rotate accumulator
182 sum += NIBBLE_HIGH(bytes[i]); // add high nibble
183 sum &= 0xF; //
184 sum = ((sum & 0xF) >> 1) | ((sum & 0x1) << 3); // rotate accumulator
185 sum += NIBBLE_LOW(bytes[i]); // add low nibble
186 sum &= 0xF; //
187 }
188 sum &= mask;
189 return sum;
190}
191
b403c300 192// measuring LFSR maximum length
193int CmdAnalyseLfsr(const char *Cmd){
194
195 uint16_t start_state = 0; /* Any nonzero start state will work. */
196 uint16_t lfsr = start_state;
197 //uint32_t period = 0;
198
199 uint8_t iv = param_get8ex(Cmd, 0, 0, 16);
200 uint8_t find = param_get8ex(Cmd, 1, 0, 16);
201
202 printf("LEGIC LFSR IV 0x%02X: \n", iv);
203 printf(" bit# | lfsr | ^0x40 | 0x%02X ^ lfsr \n",find);
204
205 for (uint8_t i = 0x01; i < 0x30; i += 1) {
206 //period = 0;
207 legic_prng_init(iv);
208 legic_prng_forward(i);
209 lfsr = legic_prng_get_bits(12);
210
211 printf(" %02X | %03X | %03X | %03X \n",i, lfsr, 0x40 ^ lfsr, find ^ lfsr);
212 }
213 return 0;
214}
812513bf 215int CmdAnalyseLCR(const char *Cmd) {
216 uint8_t data[50];
217 char cmdp = param_getchar(Cmd, 0);
218 if (strlen(Cmd) == 0|| cmdp == 'h' || cmdp == 'H') return usage_analyse_lcr();
219
220 int len = 0;
221 param_gethex_ex(Cmd, 0, data, &len);
222 if ( len%2 ) return usage_analyse_lcr();
223 len >>= 1;
224 uint8_t finalXor = calculateLRC(data, len);
225 PrintAndLog("Target [%02X] requires final LRC XOR byte value: 0x%02X",data[len-1] ,finalXor);
226 return 0;
227}
53b3c3e8 228int CmdAnalyseCRC(const char *Cmd) {
229
230 char cmdp = param_getchar(Cmd, 0);
231 if (strlen(Cmd) == 0 || cmdp == 'h' || cmdp == 'H') return usage_analyse_crc();
232
233 int len = strlen(Cmd);
234 if ( len & 1 ) return usage_analyse_crc();
235
236 // add 1 for null terminator.
237 uint8_t *data = malloc(len+1);
238 if ( data == NULL ) return 1;
239
240 if ( param_gethex(Cmd, 0, data, len)) {
241 free(data);
242 return usage_analyse_crc();
243 }
244 len >>= 1;
245
6c283951 246 //PrintAndLog("\nTests with '%s' hex bytes", sprint_hex(data, len));
53b3c3e8 247
248 PrintAndLog("\nTests of reflection. Two current methods in source code");
249 PrintAndLog(" reflect(0x3e23L,3) is %04X == 0x3e26", reflect(0x3e23L,3) );
250 PrintAndLog(" SwapBits(0x3e23L,3) is %04X == 0x3e26", SwapBits(0x3e23L,3) );
251 PrintAndLog(" 0xB400 == %04X", reflect( (1 << 16 | 0xb400),16) );
252
253 //
254 // Test of CRC16, '123456789' string.
255 //
256 PrintAndLog("\nTests with '123456789' string");
257 uint8_t dataStr[] = { 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39 };
258 uint8_t legic8 = CRC8Legic(dataStr, sizeof(dataStr));
259
53b3c3e8 260 PrintAndLog("LEGIC: CRC16: %X", CRC16Legic(dataStr, sizeof(dataStr), legic8));
261
262 //these below has been tested OK.
263 PrintAndLog("Confirmed CRC Implementations");
264 PrintAndLog("LEGIC: CRC8 : %X (0xC6 expected)", legic8);
265 PrintAndLog("MAXIM: CRC8 : %X (0xA1 expected)", CRC8Maxim(dataStr, sizeof(dataStr)));
266 PrintAndLog("DNP : CRC16: %X (0x82EA expected)", CRC16_DNP(dataStr, sizeof(dataStr)));
df007486 267 PrintAndLog("CCITT: CRC16: %X (0xE5CC expected)", CRC16_CCITT(dataStr, sizeof(dataStr)));
268
269 PrintAndLog("ICLASS org: CRC16: %X (0x expected)",iclass_crc16( (char*)dataStr, sizeof(dataStr)));
270 PrintAndLog("ICLASS ice: CRC16: %X (0x expected)",CRC16_ICLASS(dataStr, sizeof(dataStr)));
271
272
273
274 uint8_t dataStr1234[] = { 0x1,0x2,0x3,0x4};
275 PrintAndLog("ISO15693 org: : CRC16: %X (0xF0B8 expected)", Iso15693Crc(dataStr1234, sizeof(dataStr1234)));
276 PrintAndLog("ISO15693 ice: : CRC16: %X (0xF0B8 expected)", CRC16_Iso15693(dataStr1234, sizeof(dataStr1234)));
53b3c3e8 277
278 free(data);
279 return 0;
280}
281int CmdAnalyseCHKSUM(const char *Cmd){
282
283 uint8_t data[50];
284 uint8_t cmdp = 0;
2c601080 285 uint32_t mask = 0xFFFF;
53b3c3e8 286 bool errors = false;
62dc7d4a 287 bool useHeader = false;
53b3c3e8 288 int len = 0;
5f7e30f8 289 memset(data, 0x0, sizeof(data));
53b3c3e8 290
291 while(param_getchar(Cmd, cmdp) != 0x00) {
292 switch(param_getchar(Cmd, cmdp)) {
293 case 'b':
294 case 'B':
295 param_gethex_ex(Cmd, cmdp+1, data, &len);
296 if ( len%2 ) errors = true;
297 len >>= 1;
298 cmdp += 2;
299 break;
300 case 'm':
301 case 'M':
302 mask = param_get32ex(Cmd, cmdp+1, 0, 16);
303 cmdp += 2;
304 break;
62dc7d4a 305 case 'v':
306 case 'V':
307 useHeader = true;
308 cmdp++;
309 break;
53b3c3e8 310 case 'h':
311 case 'H':
312 return usage_analyse_checksum();
313 default:
314 PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));
315 errors = true;
316 break;
317 }
318 if(errors) break;
319 }
320 //Validations
321 if(errors) return usage_analyse_checksum();
322
62dc7d4a 323 if (useHeader) {
324 PrintAndLog(" add | sub | add 1's compl | sub 1's compl | xor");
f054036a 325 PrintAndLog("byte nibble crumb | byte nibble | byte nibble cumb | byte nibble | byte nibble cumb | BSD |");
62dc7d4a 326 PrintAndLog("------------------+-------------+------------------+-----------------+--------------------");
327 }
f054036a 328 PrintAndLog("0x%X 0x%X 0x%X | 0x%X 0x%X | 0x%X 0x%X 0x%X | 0x%X 0x%X | 0x%X 0x%X 0x%X | 0x%X 0x%X |\n",
2c601080 329 calcSumByteAdd(data, len, mask)
330 , calcSumNibbleAdd(data, len, mask)
331 , calcSumCrumbAdd(data, len, mask)
332 , calcSumByteSub(data, len, mask)
333 , calcSumNibbleSub(data, len, mask)
334 , calcSumByteAddOnes(data, len, mask)
335 , calcSumNibbleAddOnes(data, len, mask)
336 , calcSumCrumbAddOnes(data, len, mask)
337 , calcSumByteSubOnes(data, len, mask)
338 , calcSumNibbleSubOnes(data, len, mask)
339 , calcSumByteXor(data, len, mask)
340 , calcSumNibbleXor(data, len, mask)
341 , calcSumCrumbXor(data, len, mask)
62dc7d4a 342 , calcBSDchecksum8(data, len, mask)
f054036a 343 , calcBSDchecksum4(data, len, mask)
2c601080 344 );
53b3c3e8 345 return 0;
346}
812513bf 347
5558d935 348int CmdAnalyseDates(const char *Cmd){
349 // look for datestamps in a given array of bytes
53b3c3e8 350 PrintAndLog("To be implemented. Feel free to contribute!");
5558d935 351 return 0;
352}
16658b1f 353int CmdAnalyseTEASelfTest(const char *Cmd){
354
355 uint8_t v[8], v_le[8];
356 memset(v, 0x00, sizeof(v));
357 memset(v_le, 0x00, sizeof(v_le));
358 uint8_t* v_ptr = v_le;
359
360 uint8_t cmdlen = strlen(Cmd);
361 cmdlen = ( sizeof(v)<<2 < cmdlen ) ? sizeof(v)<<2 : cmdlen;
362
363 if ( param_gethex(Cmd, 0, v, cmdlen) > 0 ){
364 PrintAndLog("can't read hex chars, uneven? :: %u", cmdlen);
365 return 1;
366 }
367
368 SwapEndian64ex(v , 8, 4, v_ptr);
369
370 // ENCRYPTION KEY:
371 uint8_t key[16] = {0x55,0xFE,0xF6,0x30,0x62,0xBF,0x0B,0xC1,0xC9,0xB3,0x7C,0x34,0x97,0x3E,0x29,0xFB };
372 uint8_t keyle[16];
373 uint8_t* key_ptr = keyle;
374 SwapEndian64ex(key , sizeof(key), 4, key_ptr);
375
376 PrintAndLog("TEST LE enc| %s", sprint_hex(v_ptr, 8));
377
378 tea_decrypt(v_ptr, key_ptr);
379 PrintAndLog("TEST LE dec | %s", sprint_hex_ascii(v_ptr, 8));
380
381 tea_encrypt(v_ptr, key_ptr);
382 tea_encrypt(v_ptr, key_ptr);
383 PrintAndLog("TEST enc2 | %s", sprint_hex_ascii(v_ptr, 8));
384
385 return 0;
386}
5558d935 387
b403c300 388int CmdAnalyseA(const char *Cmd){
09bb01c7 389/*
390piwi
391// uid(2e086b1a) nt(230736f6) ks(0b0008000804000e) nr(000000000)
392// uid(2e086b1a) nt(230736f6) ks(0e0b0e0b090c0d02) nr(000000001)
393// uid(2e086b1a) nt(230736f6) ks(0e05060e01080b08) nr(000000002)
394uint64_t d1[] = {0x2e086b1a, 0x230736f6, 0x0000001, 0x0e0b0e0b090c0d02};
395uint64_t d2[] = {0x2e086b1a, 0x230736f6, 0x0000002, 0x0e05060e01080b08};
b403c300 396
09bb01c7 397// uid(17758822) nt(c0c69e59) ks(080105020705040e) nr(00000001)
398// uid(17758822) nt(c0c69e59) ks(01070a05050c0705) nr(00000002)
399uint64_t d1[] = {0x17758822, 0xc0c69e59, 0x0000001, 0x080105020705040e};
400uint64_t d2[] = {0x17758822, 0xc0c69e59, 0x0000002, 0x01070a05050c0705};
401
402// uid(6e442129) nt(8f699195) ks(090d0b0305020f02) nr(00000001)
403// uid(6e442129) nt(8f699195) ks(03030508030b0c0e) nr(00000002)
404// uid(6e442129) nt(8f699195) ks(02010f030c0d050d) nr(00000003)
405// uid(6e442129) nt(8f699195) ks(00040f0f0305030e) nr(00000004)
406uint64_t d1[] = {0x6e442129, 0x8f699195, 0x0000001, 0x090d0b0305020f02};
407uint64_t d2[] = {0x6e442129, 0x8f699195, 0x0000004, 0x00040f0f0305030e};
408
409uid(3e172b29) nt(039b7bd2) ks(0c0e0f0505080800) nr(00000001)
410uid(3e172b29) nt(039b7bd2) ks(0e06090d03000b0f) nr(00000002)
411*/
412 uint64_t key = 0;
413 uint64_t d1[] = {0x3e172b29, 0x039b7bd2, 0x0000001, 0x0c0e0f0505080800};
414 uint64_t d2[] = {0x3e172b29, 0x039b7bd2, 0x0000002, 0x0e06090d03000b0f};
415
416 nonce2key_ex(0, 0 , d1[0], d1[1], d1[2], d1[3], &key);
417 nonce2key_ex(0, 0 , d2[0], d2[1], d2[2], d2[3], &key);
418 return 0;
419}
b403c300 420
09bb01c7 421static void permute(uint8_t *data, uint8_t len, uint8_t *output){
422#define KEY_SIZE 8
b403c300 423
09bb01c7 424 if ( len > KEY_SIZE ) {
425 for(uint8_t m = 0; m < len; m += KEY_SIZE){
426 permute(data+m, KEY_SIZE, output+m);
427 }
428 return;
429 }
430 if ( len != KEY_SIZE ) {
431 printf("wrong key size\n");
432 return;
433 }
434 uint8_t i,j,p, mask;
435 for( i=0; i < KEY_SIZE; ++i){
436 p = 0;
437 mask = 0x80 >> i;
438 for( j=0; j < KEY_SIZE; ++j){
439 p >>= 1;
440 if (data[j] & mask)
441 p |= 0x80;
442 }
443 output[i] = p;
444 }
445}
446static void permute_rev(uint8_t *data, uint8_t len, uint8_t *output){
447 permute(data, len, output);
448 permute(output, len, data);
449 permute(data, len, output);
450}
451static void simple_crc(uint8_t *data, uint8_t len, uint8_t *output){
452 uint8_t crc = 0;
453 for( uint8_t i=0; i < len; ++i){
454 // seventh byte contains the crc.
455 if ( (i & 0x7) == 0x7 ) {
456 output[i] = crc ^ 0xFF;
457 crc = 0;
458 } else {
459 output[i] = data[i];
460 crc ^= data[i];
461 }
462 }
463}
464// DES doesn't use the MSB.
465static void shave(uint8_t *data, uint8_t len){
466 for (uint8_t i=0; i<len; ++i)
467 data[i] &= 0xFE;
468}
469static void generate_rev(uint8_t *data, uint8_t len) {
470 uint8_t *key = calloc(len,1);
471 printf("input permuted key | %s \n", sprint_hex(data, len));
472 permute_rev(data, len, key);
473 printf(" unpermuted key | %s \n", sprint_hex(key, len));
474 shave(key, len);
475 printf(" key | %s \n", sprint_hex(key, len));
476 free(key);
477}
478static void generate(uint8_t *data, uint8_t len) {
479 uint8_t *key = calloc(len,1);
480 uint8_t *pkey = calloc(len,1);
481 printf(" input key | %s \n", sprint_hex(data, len));
482 permute(data, len, pkey);
483 printf(" permuted key | %s \n", sprint_hex(pkey, len));
484 simple_crc(pkey, len, key );
485 printf(" CRC'ed key | %s \n", sprint_hex(key, len));
486 free(key);
487 free(pkey);
488}
489int CmdAnalyseHid(const char *Cmd){
b403c300 490
ea1c1ca6 491 uint8_t key[8] = {0};
492 uint8_t key_std_format[8] = {0};
493 uint8_t key_iclass_format[8] = {0};
09bb01c7 494 uint8_t data[16] = {0};
495 bool isReverse = FALSE;
496 int len = 0;
497 char cmdp = param_getchar(Cmd, 0);
498 if (strlen(Cmd) == 0|| cmdp == 'h' || cmdp == 'H') return usage_analyse_hid();
499
500 if ( cmdp == 'r' || cmdp == 'R' )
501 isReverse = TRUE;
502
503 param_gethex_ex(Cmd, 1, data, &len);
504 if ( len%2 ) return usage_analyse_hid();
505
ea1c1ca6 506 len >>= 1;
507
508 memcpy(key, data, 8);
509
510 if ( isReverse ) {
09bb01c7 511 generate_rev(data, len);
ea1c1ca6 512 permutekey_rev(key, key_std_format);
513 printf(" holiman iclass key | %s \n", sprint_hex(key_std_format, 8));
514 }
515 else {
09bb01c7 516 generate(data, len);
ea1c1ca6 517 permutekey(key, key_iclass_format);
518 printf(" holiman std key | %s \n", sprint_hex(key_iclass_format, 8));
519 }
b403c300 520 return 0;
521}
522
812513bf 523static command_t CommandTable[] = {
5558d935 524 {"help", CmdHelp, 1, "This help"},
53b3c3e8 525 {"lcr", CmdAnalyseLCR, 1, "Generate final byte for XOR LRC"},
526 {"crc", CmdAnalyseCRC, 1, "Stub method for CRC evaluations"},
527 {"chksum", CmdAnalyseCHKSUM, 1, "Checksum with adding, masking and one's complement"},
528 {"dates", CmdAnalyseDates, 1, "Look for datestamps in a given array of bytes"},
16658b1f 529 {"tea", CmdAnalyseTEASelfTest, 1, "Crypto TEA test"},
b403c300 530 {"lfsr", CmdAnalyseLfsr, 1, "LFSR tests"},
531 {"a", CmdAnalyseA, 1, "num bits test"},
09bb01c7 532 {"hid", CmdAnalyseHid, 1, "Permute function from 'heart of darkness' paper"},
812513bf 533 {NULL, NULL, 0, NULL}
534};
535
536int CmdAnalyse(const char *Cmd) {
537 clearCommandBuffer();
538 CmdsParse(CommandTable, Cmd);
539 return 0;
540}
541
542int CmdHelp(const char *Cmd) {
543 CmdsHelp(CommandTable);
544 return 0;
545}
Impressum, Datenschutz