Skip to content

Commit 3ba5190

Browse files
committed
Adopted separate -X and -Y options for key version numbers from user Krellan. See samr7 vanitygen pull request samr7#70.
1 parent 4a31a8e commit 3ba5190

3 files changed

Lines changed: 38 additions & 32 deletions

File tree

keyconv.c

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <stdio.h>
22
#include <string.h>
3+
#include <stdlib.h>
34
#include <math.h>
45
#include <assert.h>
56

@@ -31,6 +32,8 @@ usage(const char *progname)
3132
"-e Encrypt output key, prompt for password\n"
3233
"-E <password> Encrypt output key with <password> (UNSAFE)\n"
3334
"-c <key> Combine private key parts to make complete private key\n"
35+
"-X <version> Public key version (for altcoins)\n"
36+
"-Y <version> Private key version (-X provides public key)\n"
3437
"-v Verbose output\n",
3538
version, progname);
3639
}
@@ -47,15 +50,19 @@ main(int argc, char **argv)
4750
const char *key2_in = NULL;
4851
EC_KEY *pkey;
4952
int parameter_group = -1;
50-
int privtype, addrtype;
53+
int addrtype = 0;
54+
int privtype = 128;
55+
int addrtype_opt = addrtype;
56+
int privtype_opt = privtype;
57+
int addrtype_override = 0;
5158
int pkcs8 = 0;
5259
int pass_prompt = 0;
5360
int verbose = 0;
5461
int generate = 0;
5562
int opt;
5663
int res;
5764

58-
while ((opt = getopt(argc, argv, "8E:ec:vG")) != -1) {
65+
while ((opt = getopt(argc, argv, "8E:ec:vGX:Y:")) != -1) {
5966
switch (opt) {
6067
case '8':
6168
pkcs8 = 1;
@@ -86,20 +93,32 @@ main(int argc, char **argv)
8693
case 'G':
8794
generate = 1;
8895
break;
96+
case 'X':
97+
addrtype_opt = atoi(optarg);
98+
privtype_opt = addrtype + 128;
99+
addrtype_override = 1;
100+
break;
101+
case 'Y':
102+
privtype_opt = atoi(optarg);
103+
addrtype_override = 1;
104+
break;
89105
default:
90106
usage(argv[0]);
91107
return 1;
92108
}
93109
}
110+
if (addrtype_override)
111+
{
112+
addrtype = addrtype_opt;
113+
privtype = privtype_opt;
114+
}
94115

95116
OpenSSL_add_all_algorithms();
96117

97118
pkey = EC_KEY_new_by_curve_name(NID_secp256k1);
98119

99120
if (generate) {
100121
unsigned char *pend = (unsigned char *) pbuf;
101-
addrtype = 0;
102-
privtype = 128;
103122
EC_KEY_generate_key(pkey);
104123
res = i2o_ECPublicKey(pkey, &pend);
105124
fprintf(stderr, "Pubkey (hex): ");
@@ -181,10 +200,10 @@ main(int argc, char **argv)
181200
fprintf(stderr, "WARNING: Using weak password\n");
182201
}
183202

184-
switch (privtype) {
185-
case 128: addrtype = 0; break;
186-
case 239: addrtype = 111; break;
187-
default: addrtype = 0; break;
203+
if (addrtype_override)
204+
{
205+
addrtype = addrtype_opt;
206+
privtype = privtype_opt;
188207
}
189208

190209
if (verbose) {

oclvanitygen.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ usage(const char *name)
5959
"-1 Stop after first match\n"
6060
"-N Generate namecoin address\n"
6161
"-T Generate bitcoin testnet address\n"
62-
"-U Generate unobtanium address\n"
63-
"-u Generate unitus address\n"
6462
"-X <version> Generate address with the given version\n"
6563
"-e Encrypt private keys, prompt for password\n"
6664
"-E <password> Encrypt private keys with <password> (UNSAFE)\n"
@@ -125,7 +123,7 @@ main(int argc, char **argv)
125123
int i;
126124

127125
while ((opt = getopt(argc, argv,
128-
"vqik1NTUuX:eE:p:P:d:w:t:g:b:VSh?f:o:s:D:")) != -1) {
126+
"vqik1NTX:Y:eE:p:P:d:w:t:g:b:VSh?f:o:s:D:")) != -1) {
129127
switch (opt) {
130128
case 'v':
131129
verbose = 2;
@@ -150,18 +148,14 @@ main(int argc, char **argv)
150148
addrtype = 111;
151149
privtype = 239;
152150
break;
153-
case 'U':
154-
addrtype = 130;
155-
privtype = 224;
156-
break;
157-
case 'u':
158-
addrtype = 68;
159-
privtype = 132;
160-
break;
161151
case 'X':
162152
addrtype = atoi(optarg);
163153
privtype = 128 + addrtype;
164154
break;
155+
case 'Y':
156+
/* Overrides privtype of 'X' but leaves all else intact */
157+
privtype = atoi(optarg);
158+
break;
165159
case 'e':
166160
prompt_password = 1;
167161
break;

vanitygen.c

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,8 @@ usage(const char *name)
313313
"-1 Stop after first match\n"
314314
"-N Generate namecoin address\n"
315315
"-T Generate bitcoin testnet address\n"
316-
"-U Generate unobtanium address\n"
317-
"-u Generate unitus address\n"
318316
"-X <version> Generate address with the given version\n"
317+
"-Y <version> Specify private key version (-X provides public key)\n"
319318
"-F <format> Generate address with the given format (pubkey or script)\n"
320319
"-P <pubkey> Specify base public key for piecewise key generation\n"
321320
"-e Encrypt private keys, prompt for password\n"
@@ -363,7 +362,7 @@ main(int argc, char **argv)
363362

364363
int i;
365364

366-
while ((opt = getopt(argc, argv, "vqnrik1eE:P:NTUuX:F:t:h?f:o:s:")) != -1) {
365+
while ((opt = getopt(argc, argv, "vqnrik1eE:P:NTX:Y:F:t:h?f:o:s:")) != -1) {
367366
switch (opt) {
368367
case 'v':
369368
verbose = 2;
@@ -396,21 +395,15 @@ main(int argc, char **argv)
396395
privtype = 239;
397396
scriptaddrtype = 196;
398397
break;
399-
case 'U':
400-
addrtype = 130;
401-
privtype = 224;
402-
scriptaddrtype = 30;
403-
break;
404-
case 'u':
405-
addrtype = 68;
406-
privtype = 132;
407-
scriptaddrtype = 10;
408-
break;
409398
case 'X':
410399
addrtype = atoi(optarg);
411400
privtype = 128 + addrtype;
412401
scriptaddrtype = addrtype;
413402
break;
403+
case 'Y':
404+
/* Overrides privtype of 'X' but leaves all else intact */
405+
privtype = atoi(optarg);
406+
break;
414407
case 'F':
415408
if (!strcmp(optarg, "script"))
416409
format = VCF_SCRIPT;

0 commit comments

Comments
 (0)