R&Y: Added DAY RTA Tapp Card and Additional BKK BEM Stored Value Card AIDs to `aid_de...
[RRG-proxmark3.git] / common / bruteforce.h
blobcab98c8c7351cb2c0cb999935edf686ebcf59360
1 //-----------------------------------------------------------------------------
2 // Copyright (C) Proxmark3 contributors. See AUTHORS.md for details.
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // See LICENSE.txt for the text of the license.
15 //-----------------------------------------------------------------------------
16 // functions for bruteforcing card keys - key generators
17 //-----------------------------------------------------------------------------
19 #ifndef BRUTEFORCE_H__
20 #define BRUTEFORCE_H__
22 #include "common.h"
24 #define BF_KEY_SIZE_32 4
25 #define BF_KEY_SIZE_48 6
27 // bruteforcing all keys sequentially between X and Y
28 #define BF_MODE_RANGE 1
30 // try keys based on limited charset/passphrases
31 // some payment systems use user-provided passphrase as system key
32 #define BF_MODE_CHARSET 2
34 // "smart" mode - try some predictable patterns
35 #define BF_MODE_SMART 3
38 // bit flags - can be used together using logical OR
39 #define BF_CHARSET_DIGITS 1
40 #define BF_CHARSET_UPPERCASE 2
42 #define BF_GENERATOR_END 0
43 #define BF_GENERATOR_NEXT 1
44 #define BF_GENERATOR_ERROR 2
46 #define BF_CHARSET_DIGITS_SIZE 10
47 #define BF_CHARSET_UPPERCASE_SIZE 25
49 extern uint8_t charset_digits[];
50 extern uint8_t charset_uppercase[];
52 typedef uint8_t bruteforce_charset_t;
53 typedef uint8_t bruteforce_mode_t;
55 // structure to hold key generator temporary data
56 typedef struct {
57 // position of each of bytes in charset mode - used to iterate over alphabets
58 // add more bytes to support larger keys
59 // pos[0] is most significant byte - all maths avoid relying on little/big endian memory layout
60 uint8_t pos[6]; // max supported key is now 48 bit
62 uint8_t key_length; // bytes
63 uint64_t current_key; // Use 64 bit and truncate when needed.
64 uint8_t mode;
65 uint8_t charset[
66 BF_CHARSET_DIGITS_SIZE
67 + BF_CHARSET_UPPERCASE_SIZE
69 uint8_t charset_length;
71 uint32_t range_low;
72 uint32_t range_high;
73 uint16_t smart_mode_stage;
74 // flags to use internally by generators as they wish
75 bool flag1, flag2, flag3;
76 // counters to use internally by generators as they wish
77 uint32_t counter1, counter2;
79 } generator_context_t;
82 void bf_generator_init(generator_context_t *ctx, uint8_t mode, uint8_t key_length);
83 void bf_generator_clear(generator_context_t *ctx); // clear flags and counters used by generators
84 int bf_generator_set_charset(generator_context_t *ctx, uint8_t charsets);
85 int bf_generate(generator_context_t *ctx);
86 int _bf_generate_mode_range(generator_context_t *ctx);
87 int _bf_generate_mode_charset(generator_context_t *ctx);
88 int _bf_generate_mode_smart(generator_context_t *ctx);
89 int bf_array_increment(uint8_t *data, uint8_t data_len, uint8_t modulo);
90 uint32_t bf_get_key32(const generator_context_t *ctx);
91 uint64_t bf_get_key48(const generator_context_t *ctx);
93 // smart mode
94 typedef int (smart_generator_t)(generator_context_t *ctx);
96 int bf_generate_mode_smart(generator_context_t *ctx);
98 int smart_generator_byte_repeat(generator_context_t *ctx);
99 int smart_generator_msb_byte_only(generator_context_t *ctx);
100 int smart_generator_nibble_sequence(generator_context_t *ctx);
102 extern smart_generator_t *smart_generators[]; // array of smart cracking functions
104 #endif // BRUTEFORCE_H__