forked from samr7/vanitygen
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathpattern.h
198 lines (169 loc) · 5.98 KB
/
pattern.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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/*
* Vanitygen, vanity bitcoin address generator
* Copyright (C) 2011 <[email protected]>
*
* Vanitygen is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* Vanitygen is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Vanitygen. If not, see <http://www.gnu.org/licenses/>.
*/
#if !defined(__VG_PATTERN_H__)
#define __VG_PATTERN_H__
#include <openssl/ec.h>
#include <string.h>
#if defined(_WIN32) && !defined(HAVE_STRUCT_TIMESPEC)
#define HAVE_STRUCT_TIMESPEC
#endif
#include <pthread.h>
#ifdef _WIN32
#include "winglue.h"
#else
#define INLINE inline
#define PRSIZET "z"
#ifndef _WIN32
#include <hs/hs_runtime.h>
#endif
#include <errno.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <unistd.h>
#endif
#ifndef _WIN32
#define COLOR44 "\x1B[44m"
#define COLOR36 "\x1B[36m"
#define COLOR34 "\x1B[34m"
#define COLOR33 "\x1B[33m"
#define COLOR32 "\x1B[32m"
#define COLOR0 "\x1B[0m"
#else
#define COLOR44 ""
#define COLOR36 ""
#define COLOR34 ""
#define COLOR33 ""
#define COLOR32 ""
#define COLOR0 ""
#endif
#define VANITYGEN_VERSION "0.26"
typedef struct _vg_context_s vg_context_t;
struct _vg_exec_context_s;
typedef struct _vg_exec_context_s vg_exec_context_t;
typedef void *(*vg_exec_context_threadfunc_t)(vg_exec_context_t *);
/* Context of one pattern-matching unit within the process */
struct _vg_exec_context_s {
vg_context_t *vxc_vc;
BN_CTX *vxc_bnctx;
EC_KEY *vxc_key;
int vxc_delta;
unsigned char vxc_binres[20];
BIGNUM *vxc_bntarg;
BIGNUM *vxc_bnbase;
BIGNUM *vxc_bntmp;
BIGNUM *vxc_bntmp2;
vg_exec_context_threadfunc_t vxc_threadfunc;
pthread_t vxc_pthread;
int vxc_thread_active;
#ifndef _WIN32
hs_scratch_t *vxc_scratch;
#endif
/* Thread synchronization */
struct _vg_exec_context_s *vxc_next;
int vxc_lockmode;
int vxc_stop;
int vxc_regex_sync;
};
typedef void (*vg_exec_prep_func_t)(vg_context_t *, vg_exec_context_t *);
typedef void (*vg_free_func_t)(vg_context_t *);
typedef int (*vg_add_pattern_func_t)(
vg_context_t *, const char **const patterns, int npatterns);
typedef void (*vg_clear_all_patterns_func_t)(vg_context_t *);
typedef int (*vg_test_func_t)(
vg_exec_context_t *, const int isaddresscompressed);
typedef int (*vg_hash160_sort_func_t)(vg_context_t *vcp, void *buf);
typedef void (*vg_output_error_func_t)(vg_context_t *vcp, const char *info);
typedef void (*vg_output_match_func_t)(vg_context_t *vcp, EC_KEY *pkey,
const char *pattern, int isaddresscompressed);
typedef void (*vg_output_timing_func_t)(vg_context_t *vcp, double count,
unsigned long long rate, unsigned long long total);
/* Application-level context, incl. parameters and global pattern store */
struct _vg_context_s {
int vc_addrtype;
int vc_istestnet;
int vc_privtype;
unsigned long vc_npatterns;
unsigned long vc_npatterns_start;
unsigned long long vc_found;
int vc_pattern_generation;
double vc_chance;
const char *vc_result_file;
const char *vc_result_file_csv;
int vc_remove_on_match;
int vc_only_one;
int vc_verbose;
EC_POINT *vc_pubkey_base;
char vc_privkey_prefix[32];
int vc_privkey_prefix_length;
int vc_halt;
vg_exec_context_t *vc_threads;
int vc_thread_excl;
/* Internal methods */
vg_exec_prep_func_t vc_prep;
vg_free_func_t vc_free;
vg_add_pattern_func_t vc_add_patterns;
vg_clear_all_patterns_func_t vc_clear_all_patterns;
vg_test_func_t vc_test;
vg_hash160_sort_func_t vc_hash160_sort;
/* Performance related members */
unsigned long long vc_timing_total;
unsigned long long vc_timing_prevfound;
unsigned long long vc_timing_sincelast;
struct _timing_info_s *vc_timing_head;
/* External methods */
vg_output_error_func_t vc_output_error;
vg_output_match_func_t vc_output_match;
vg_output_timing_func_t vc_output_timing;
};
/* Base context methods */
void vg_context_free(vg_context_t *vcp);
int vg_context_add_patterns(
vg_context_t *vcp, const char **const patterns, int npatterns);
void vg_context_clear_all_patterns(vg_context_t *vcp);
int vg_context_start_threads(vg_context_t *vcp);
void vg_context_stop_threads(vg_context_t *vcp);
void vg_context_wait_for_completion(vg_context_t *vcp);
/* Prefix context methods */
vg_context_t *vg_prefix_context_new(int addrtype, int privtype, int testnet);
int vg_prefix_context_add_ranges(
vg_context_t *vcp, const char *patname, const char **range, int nrange);
double vg_prefix_get_difficulty(int addrtype, const char *pattern);
/* Regex context methods */
int vg_regex_context_prep_scratch(vg_context_t *vcp);
vg_context_t *vg_regex_context_new(int addrtype, int privtype, int testnet);
/* Utility functions */
int vg_output_timing(vg_context_t *vcp, int cycle, struct timeval *last);
void vg_output_match_console(vg_context_t *vcp, EC_KEY *pkey,
const char *pattern, int isaddresscompressed);
void vg_output_timing_console(vg_context_t *vcp, double count,
unsigned long long rate, unsigned long long total);
/* Internal vg_context methods */
int vg_context_hash160_sort(vg_context_t *vcp, void *buf);
void vg_context_thread_exit(vg_context_t *vcp);
/* Internal Init/cleanup for common execution context */
int vg_exec_context_init(vg_context_t *vcp, vg_exec_context_t *vxcp);
void vg_exec_context_del(vg_exec_context_t *vxcp);
void vg_exec_context_consolidate_key(vg_exec_context_t *vxcp);
void vg_exec_context_calc_address(
vg_exec_context_t *vxcp, const int isaddresscompressed);
EC_KEY *vg_exec_context_new_key(void);
/* Internal execution context lock handling functions */
void vg_exec_context_downgrade_lock(vg_exec_context_t *vxcp);
int vg_exec_context_upgrade_lock(vg_exec_context_t *vxcp);
void vg_exec_context_yield(vg_exec_context_t *vxcp);
#endif /* !defined (__VG_PATTERN_H__) */