1 /**
2  * Author......: See docs/credits.txt
3  * License.....: MIT
4  */
5 
6 #ifndef _COMMON_H
7 #define _COMMON_H
8 
9 #define PROGNAME "hashcat"
10 
11 #if defined (__unix__) || defined (__APPLE__)
12 #define _POSIX
13 #elif defined (_WIN32)
14 #define _WIN 1
15 #else
16 #error Your Operating System is not supported or detected
17 #endif
18 
19 #if defined (__BYTE_ORDER__) && defined (__ORDER_BIG_ENDIAN__)
20 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
21 #error "compiling for big-endian architecture not supported"
22 #endif
23 #endif
24 
25 #ifndef _GNU_SOURCE
26 #define _GNU_SOURCE
27 #endif
28 
29 // needed for *time_r functions under MinGW
30 #ifndef _POSIX_THREAD_SAFE_FUNCTIONS
31 #define _POSIX_THREAD_SAFE_FUNCTIONS 200809L
32 #endif
33 
34 // needed for 64-bit off_t on 32-bit OSes
35 #ifndef _FILE_OFFSET_BITS
36 #define _FILE_OFFSET_BITS 64
37 #endif
38 
39 // _FORTIFY_SOURCE needs string.h
40 #include <string.h>
41 
42 #ifndef _FORTIFY_SOURCE
43 #define _FORTIFY_SOURCE 2
44 #endif
45 
46 #define NOMINMAX 1
47 
48 #define MIN(a,b) (((a) < (b)) ? (a) : (b))
49 #define MAX(a,b) (((a) > (b)) ? (a) : (b))
50 
51 #define CEIL(a) ((a - (int) (a)) > 0 ? a + 1 : a)
52 #define CEILDIV(a,b) (((a) + (b) - 1) / (b))
53 
54 #if defined (__APPLE__)
55 #define __stdcall
56 #endif
57 
58 #if defined (__MSC_VER)
59 #define HC_API_CALL __cdecl
60 #elif defined (_WIN32) || defined (__WIN32__)
61 #define HC_API_CALL __stdcall
62 #else
63 #define HC_API_CALL
64 #endif
65 
66 #if defined (__GNUC__)
67 #define HC_ALIGN(x) __attribute__((aligned(x)))
68 #elif defined (_MSC_VER)
69 #define HC_ALIGN(x) __declspec(align(x))
70 #else
71 #define HC_ALIGN(x)
72 #endif
73 
74 #if defined (_WIN)
75 #define WIN32_LEAN_AND_MEAN
76 #endif
77 
78 /* The C++ standard denies redefinition of keywords,
79 but this is nededed for VS compiler which doesn't have inline keyword but has __inline
80 */
81 #ifndef __cplusplus
82 #if defined (_MSC_VER)
83 #define inline __inline
84 #endif
85 #endif
86 
87 #define MAYBE_UNUSED __attribute__((unused))
88 
89 /*
90  * Check if the system uses nanoseconds for file timestamps.
91  * In case the system uses nanoseconds we set some custom macros here,
92  * e.g. the (nanosecond) access time macros for dictstat
93  */
94 
95 #if defined (__linux__)
96 #include <linux/version.h>
97 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,48)
98 #define STAT_NANOSECONDS_ACCESS_TIME st_atim.tv_nsec
99 #endif
100 #endif
101 
102 #if defined (__APPLE__)
103 #define STAT_NANOSECONDS_ACCESS_TIME st_atimespec.tv_nsec
104 #endif
105 
106 /**
107  * Disable this picky gcc-8 compiler warning
108  * We're in good company:
109  * https://github.com/curl/curl/blob/fc3743c31bb3c84e31a2eff99e958337571eb5f0/lib/md5.c#L487-L490
110  * https://github.com/kivadiu/thread/blob/ee607c86d4acd1d7733304526eb25d742b533071/src/win32/thread_primitives.cpp#L105-L113
111  */
112 
113 #if defined (__GNUC__) && (__GNUC__ >= 8)
114 #pragma GCC diagnostic ignored "-Wcast-function-type"
115 #endif
116 
117 // config section
118 // do not try to simply change this, it will not work
119 
120 #define PW_MIN              0
121 #define PW_MAX              256
122 #define PW_MAX_OLD          55
123 
124 #define SALT_MIN            0
125 #define SALT_MAX            256
126 #define SALT_MAX_OLD        51
127 
128 #define HCBUFSIZ_TINY       0x1000
129 #define HCBUFSIZ_SMALL      0x2000
130 #define HCBUFSIZ_LARGE      0x1000000
131 
132 #define CPT_CACHE           0x20000
133 #define PARAMCNT            64
134 #define DEVICES_MAX         128
135 #define EXEC_CACHE          128
136 #define SPEED_CACHE         4096
137 #define SPEED_MAXAGE        4096
138 #define EXPECTED_ITERATIONS 10000
139 
140 #if defined (_WIN)
141 #define EOL "\r\n"
142 #else
143 #define EOL "\n"
144 #endif
145 
146 #endif // _COMMON_H
147 
148