forked from openwall/john
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMD5_std.h
178 lines (153 loc) · 3.57 KB
/
MD5_std.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*
* This file is part of John the Ripper password cracker,
* Copyright (c) 1996-2000,2003,2011 by Solar Designer
*
* ...with changes in the jumbo patch, by bartavelle and magnum
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted.
*
* There's ABSOLUTELY NO WARRANTY, express or implied.
*/
/*
* FreeBSD-style MD5-based password hash implementation.
*/
#ifndef _JOHN_MD5_STD_H
#define _JOHN_MD5_STD_H
#include <stdint.h>
#include "arch.h"
typedef uint32_t MD5_word;
/*
* Binary ciphertext type.
*/
typedef MD5_word MD5_binary[4];
/*
* Various structures for internal use.
*/
typedef union {
double dummy;
MD5_word w[15];
char b[60];
} MD5_block;
typedef struct {
int length;
MD5_block *even, *odd;
} MD5_pattern;
typedef struct {
char s[8];
struct {
int p, s, ps, pp, psp;
} l;
struct {
MD5_block p, sp, pp, spp;
} e;
struct {
MD5_block p, ps, pp, psp;
} o;
} MD5_pool;
#if !MD5_IMM
typedef struct {
MD5_word AC[64];
MD5_word IV[4];
MD5_word masks[2];
} MD5_data;
#endif
#ifdef SIMD_PARA_MD5
#ifndef SIMD_COEF_32
#define SIMD_COEF_32 4
#endif
#define MD5_N (SIMD_PARA_MD5*SIMD_COEF_32)
#else
#undef MD5_ALGORITHM_NAME
#if MD5_X2
#define MD5_N 2
#define MD5_ALGORITHM_NAME "32/" ARCH_BITS_STR " X2"
#else
#define MD5_N 1
#define MD5_ALGORITHM_NAME "32/" ARCH_BITS_STR
#endif
#endif
typedef struct {
#if !MD5_IMM
MD5_data data;
#endif
MD5_binary out[MD5_N];
MD5_block _block[MD5_N];
MD5_pattern _order[21][MD5_N];
MD5_pool _pool[MD5_N];
char *prefix;
int prelen;
} MD5_std_combined;
#if defined(_OPENMP) && !MD5_ASM
#define MD5_std_mt 1
#define MD5_std_cpt 128
#define MD5_std_mt_max (MD5_std_cpt * 576)
extern MD5_std_combined *MD5_std_all_p;
extern int MD5_std_min_kpc, MD5_std_max_kpc;
extern int MD5_std_nt;
#define MD5_std_all_align 64
#define MD5_std_all_size \
((sizeof(MD5_std_combined) + (MD5_std_all_align - 1)) & \
~(MD5_std_all_align - 1))
#ifdef __GNUC__
#define MD5_std_all \
(*(MD5_std_combined *)((char *)MD5_std_all_p + t))
#define for_each_t(n) \
for (t = 0; t < (n) * MD5_std_all_size; t += MD5_std_all_size)
#define init_t() \
int t = (unsigned int)index / MD5_N * MD5_std_all_size; \
index = (unsigned int)index % MD5_N;
#else
/*
* For compilers that complain about the above e.g. with "iteration expression
* of omp for loop does not have a canonical shape".
*/
#define MD5_std_all \
(*(MD5_std_combined *)((char *)MD5_std_all_p + t * MD5_std_all_size))
#define for_each_t(n) \
for (t = 0; t < (n); t++)
#define init_t() \
int t = (unsigned int)index / MD5_N; \
index = (unsigned int)index % MD5_N;
#endif
#else
#define MD5_std_mt 0
extern MD5_std_combined MD5_std_all;
#define for_each_t(n)
#define init_t()
#endif
/*
* MD5_std_crypt() output buffer.
*/
#define MD5_out MD5_std_all.out
// these 2 are still used by the 'para' function
#define MD5_TYPE_APACHE 1
#define MD5_TYPE_STD 2
#define MD5_TYPE_AIX 3
/*
* Initializes the internal structures.
*/
struct fmt_main;
extern void MD5_std_init(struct fmt_main *self);
/*
* Sets a salt for MD5_std_crypt().
*/
extern void MD5_std_set_salt(char *salt);
/*
* Sets a key for MD5_std_crypt().
* Currently only supports keys up to 15 characters long.
*/
extern void MD5_std_set_key(char *key, int index);
/*
* Main hashing routine, sets MD5_out.
*/
extern void MD5_std_crypt(int count);
/*
* Returns the salt for MD5_std_set_salt().
*/
extern char *MD5_std_get_salt(char *ciphertext);
/*
* Converts an ASCII ciphertext to binary.
*/
extern MD5_word *MD5_std_get_binary(char *ciphertext);
#endif