Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
samr7
GitHub Repository: samr7/vanitygen
Path: blob/master/pattern.h
239 views
1
/*
2
* Vanitygen, vanity bitcoin address generator
3
* Copyright (C) 2011 <[email protected]>
4
*
5
* Vanitygen is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU Affero General Public License as published by
7
* the Free Software Foundation, either version 3 of the License, or
8
* any later version.
9
*
10
* Vanitygen is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU Affero General Public License for more details.
14
*
15
* You should have received a copy of the GNU Affero General Public License
16
* along with Vanitygen. If not, see <http://www.gnu.org/licenses/>.
17
*/
18
19
#if !defined (__VG_PATTERN_H__)
20
#define __VG_PATTERN_H__
21
22
#include <openssl/bn.h>
23
#include <openssl/ec.h>
24
25
#include <pthread.h>
26
27
#ifdef _WIN32
28
#include "winglue.h"
29
#else
30
#define INLINE inline
31
#define PRSIZET "z"
32
#include <sys/time.h>
33
#include <sys/stat.h>
34
#include <errno.h>
35
#include <unistd.h>
36
#endif
37
38
#define VANITYGEN_VERSION "0.22"
39
40
typedef struct _vg_context_s vg_context_t;
41
42
struct _vg_exec_context_s;
43
typedef struct _vg_exec_context_s vg_exec_context_t;
44
45
typedef void *(*vg_exec_context_threadfunc_t)(vg_exec_context_t *);
46
47
/* Context of one pattern-matching unit within the process */
48
struct _vg_exec_context_s {
49
vg_context_t *vxc_vc;
50
BN_CTX *vxc_bnctx;
51
EC_KEY *vxc_key;
52
int vxc_delta;
53
unsigned char vxc_binres[28];
54
BIGNUM vxc_bntarg;
55
BIGNUM vxc_bnbase;
56
BIGNUM vxc_bntmp;
57
BIGNUM vxc_bntmp2;
58
59
vg_exec_context_threadfunc_t vxc_threadfunc;
60
pthread_t vxc_pthread;
61
int vxc_thread_active;
62
63
/* Thread synchronization */
64
struct _vg_exec_context_s *vxc_next;
65
int vxc_lockmode;
66
int vxc_stop;
67
};
68
69
70
typedef void (*vg_free_func_t)(vg_context_t *);
71
typedef int (*vg_add_pattern_func_t)(vg_context_t *,
72
const char ** const patterns,
73
int npatterns);
74
typedef void (*vg_clear_all_patterns_func_t)(vg_context_t *);
75
typedef int (*vg_test_func_t)(vg_exec_context_t *);
76
typedef int (*vg_hash160_sort_func_t)(vg_context_t *vcp, void *buf);
77
typedef void (*vg_output_error_func_t)(vg_context_t *vcp, const char *info);
78
typedef void (*vg_output_match_func_t)(vg_context_t *vcp, EC_KEY *pkey,
79
const char *pattern);
80
typedef void (*vg_output_timing_func_t)(vg_context_t *vcp, double count,
81
unsigned long long rate,
82
unsigned long long total);
83
84
enum vg_format {
85
VCF_PUBKEY,
86
VCF_SCRIPT,
87
};
88
89
/* Application-level context, incl. parameters and global pattern store */
90
struct _vg_context_s {
91
int vc_addrtype;
92
int vc_privtype;
93
unsigned long vc_npatterns;
94
unsigned long vc_npatterns_start;
95
unsigned long long vc_found;
96
int vc_pattern_generation;
97
double vc_chance;
98
const char *vc_result_file;
99
const char *vc_key_protect_pass;
100
int vc_remove_on_match;
101
int vc_only_one;
102
int vc_verbose;
103
enum vg_format vc_format;
104
int vc_pubkeytype;
105
EC_POINT *vc_pubkey_base;
106
int vc_halt;
107
108
vg_exec_context_t *vc_threads;
109
int vc_thread_excl;
110
111
/* Internal methods */
112
vg_free_func_t vc_free;
113
vg_add_pattern_func_t vc_add_patterns;
114
vg_clear_all_patterns_func_t vc_clear_all_patterns;
115
vg_test_func_t vc_test;
116
vg_hash160_sort_func_t vc_hash160_sort;
117
118
/* Performance related members */
119
unsigned long long vc_timing_total;
120
unsigned long long vc_timing_prevfound;
121
unsigned long long vc_timing_sincelast;
122
struct _timing_info_s *vc_timing_head;
123
124
/* External methods */
125
vg_output_error_func_t vc_output_error;
126
vg_output_match_func_t vc_output_match;
127
vg_output_timing_func_t vc_output_timing;
128
};
129
130
131
/* Base context methods */
132
extern void vg_context_free(vg_context_t *vcp);
133
extern int vg_context_add_patterns(vg_context_t *vcp,
134
const char ** const patterns, int npatterns);
135
extern void vg_context_clear_all_patterns(vg_context_t *vcp);
136
extern int vg_context_start_threads(vg_context_t *vcp);
137
extern void vg_context_stop_threads(vg_context_t *vcp);
138
extern void vg_context_wait_for_completion(vg_context_t *vcp);
139
140
/* Prefix context methods */
141
extern vg_context_t *vg_prefix_context_new(int addrtype, int privtype,
142
int caseinsensitive);
143
extern void vg_prefix_context_set_case_insensitive(vg_context_t *vcp,
144
int caseinsensitive);
145
extern double vg_prefix_get_difficulty(int addrtype, const char *pattern);
146
147
/* Regex context methods */
148
extern vg_context_t *vg_regex_context_new(int addrtype, int privtype);
149
150
/* Utility functions */
151
extern int vg_output_timing(vg_context_t *vcp, int cycle, struct timeval *last);
152
extern void vg_output_match_console(vg_context_t *vcp, EC_KEY *pkey,
153
const char *pattern);
154
extern void vg_output_timing_console(vg_context_t *vcp, double count,
155
unsigned long long rate,
156
unsigned long long total);
157
158
159
160
/* Internal vg_context methods */
161
extern int vg_context_hash160_sort(vg_context_t *vcp, void *buf);
162
extern void vg_context_thread_exit(vg_context_t *vcp);
163
164
/* Internal Init/cleanup for common execution context */
165
extern int vg_exec_context_init(vg_context_t *vcp, vg_exec_context_t *vxcp);
166
extern void vg_exec_context_del(vg_exec_context_t *vxcp);
167
extern void vg_exec_context_consolidate_key(vg_exec_context_t *vxcp);
168
extern void vg_exec_context_calc_address(vg_exec_context_t *vxcp);
169
extern EC_KEY *vg_exec_context_new_key(void);
170
171
/* Internal execution context lock handling functions */
172
extern void vg_exec_context_downgrade_lock(vg_exec_context_t *vxcp);
173
extern int vg_exec_context_upgrade_lock(vg_exec_context_t *vxcp);
174
extern void vg_exec_context_yield(vg_exec_context_t *vxcp);
175
176
177
#endif /* !defined (__VG_PATTERN_H__) */
178
179