Skip to content

Commit

Permalink
Combine compressed and uncompressed ec point calculations
Browse files Browse the repository at this point in the history
The EC-point batch generation is a lenghty process.
Hashing the once generated points both compressed and uncompressed
increases the overall hash-speed considerable.
  • Loading branch information
kangaderoo committed Aug 29, 2015
1 parent 145cc25 commit f997ba2
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 63 deletions.
28 changes: 19 additions & 9 deletions pattern.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* along with Vanitygen. If not, see <http://www.gnu.org/licenses/>.
*/

#include "pattern.h"
#include <stdio.h>
#include <string.h>
#include <math.h>
Expand All @@ -31,11 +32,9 @@

#include <pcre.h>

#include "pattern.h"
#include "util.h"
#include "avl.h"


/*
* Common code for execution helper
*/
Expand Down Expand Up @@ -169,6 +168,7 @@ vg_exec_context_init(vg_context_t *vcp, vg_exec_context_t *vxcp)

vxcp->vxc_next = vcp->vc_threads;
vcp->vc_threads = vxcp;
vxcp->vc_combined_compressed = vcp->vc_compressed;
__vg_exec_context_yield(vxcp);
pthread_mutex_unlock(&vg_thread_lock);
return 1;
Expand Down Expand Up @@ -256,7 +256,7 @@ vg_exec_context_calc_address(vg_exec_context_t *vxcp)
}
len = EC_POINT_point2oct(pgroup,
pubkey,
vxcp->vxc_vc->vc_compressed ? POINT_CONVERSION_COMPRESSED : POINT_CONVERSION_UNCOMPRESSED,
vxcp->vc_combined_compressed ? POINT_CONVERSION_COMPRESSED : POINT_CONVERSION_UNCOMPRESSED,
eckey_buf,
sizeof(eckey_buf),
vxcp->vxc_bnctx);
Expand Down Expand Up @@ -502,15 +502,16 @@ vg_output_timing_console(vg_context_t *vcp, double count,
}

void
vg_output_match_console(vg_context_t *vcp, EC_KEY *pkey, const char *pattern)
//vg_output_match_console(vg_context_t *vcp, EC_KEY *pkey, const char *pattern)
vg_output_match_console(vg_context_t *vcp, vg_exec_context_t *vxcp, const char *pattern)
{
unsigned char key_buf[512], *pend;
char addr_buf[64], addr2_buf[64];
char privkey_buf[VG_PROTKEY_MAX_B58];
const char *keytype = "Privkey";
int len;
int isscript = (vcp->vc_format == VCF_SCRIPT);

EC_KEY *pkey = vxcp->vxc_key;
EC_POINT *ppnt;
int free_ppnt = 0;
if (vcp->vc_pubkey_base) {
Expand All @@ -528,7 +529,8 @@ vg_output_match_console(vg_context_t *vcp, EC_KEY *pkey, const char *pattern)
}

assert(EC_KEY_check_key(pkey));
if (vcp->vc_compressed)
// if (vcp->vc_combined_compressed)
if (vxcp->vc_combined_compressed)
vg_encode_address_compressed(ppnt,
EC_KEY_get0_group(pkey),
vcp->vc_pubkeytype, addr_buf);
Expand All @@ -555,7 +557,8 @@ vg_output_match_console(vg_context_t *vcp, EC_KEY *pkey, const char *pattern)
}
}
if (!vcp->vc_key_protect_pass) {
if (vcp->vc_compressed)
// if (vcp->vc_combined_compressed)
if (vxcp->vc_combined_compressed)
vg_encode_privkey_compressed(pkey, vcp->vc_privtype, privkey_buf);
else
vg_encode_privkey(pkey, vcp->vc_privtype, privkey_buf);
Expand Down Expand Up @@ -1009,8 +1012,10 @@ vg_prefix_avl_insert(avl_root_t *rootp, vg_prefix_t *vpnew)
vg_prefix_t *vp;
avl_item_t *itemp = NULL;
avl_item_t **ptrp = &rootp->ar_root;

while (*ptrp) {
itemp = *ptrp;
// ptrp = &itemp->ai_left;
vp = avl_item_entry(itemp, vg_prefix_t, vp_item);
if (BN_cmp(vp->vp_low, vpnew->vp_high) > 0) {
ptrp = &itemp->ai_left;
Expand All @@ -1021,6 +1026,7 @@ vg_prefix_avl_insert(avl_root_t *rootp, vg_prefix_t *vpnew)
return vp;
}
}

vpnew->vp_item.ai_up = itemp;
itemp = &vpnew->vp_item;
*ptrp = itemp;
Expand Down Expand Up @@ -1492,7 +1498,9 @@ vg_prefix_test(vg_exec_context_t *vxcp)
goto research;

vg_exec_context_consolidate_key(vxcp);
vcpp->base.vc_output_match(&vcpp->base, vxcp->vxc_key,
// vcpp->base.vc_output_match(&vcpp->base, vxcp->vxc_key,
// vp->vp_pattern, &combined_compressed);
vcpp->base.vc_output_match(&vcpp->base, vxcp,
vp->vp_pattern);

vcpp->base.vc_found++;
Expand Down Expand Up @@ -1792,7 +1800,9 @@ vg_regex_test(vg_exec_context_t *vxcp)
goto restart_loop;

vg_exec_context_consolidate_key(vxcp);
vcrp->base.vc_output_match(&vcrp->base, vxcp->vxc_key,
// vcrp->base.vc_output_match(&vcrp->base, vxcp->vxc_key,
// vcrp->vcr_regex_pat[i], combined_compressed);
vcrp->base.vc_output_match(&vcrp->base, vxcp,
vcrp->vcr_regex_pat[i]);
vcrp->base.vc_found++;

Expand Down
23 changes: 19 additions & 4 deletions pattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,20 @@
#if !defined (__VG_PATTERN_H__)
#define __VG_PATTERN_H__

#if defined(_WIN32)
#include "winglue.h"
#ifndef PCRE_STATIC
#define PCRE_STATIC
#endif
#endif


#include <openssl/bn.h>
#include <openssl/ec.h>

#include <pthread.h>

#ifdef _WIN32
#if defined(_WIN32)
#include "winglue.h"
#else
#define INLINE inline
Expand All @@ -50,6 +58,7 @@ struct _vg_exec_context_s {
BN_CTX *vxc_bnctx;
EC_KEY *vxc_key;
int vxc_delta;
int vc_combined_compressed;
unsigned char vxc_binres[28];
BIGNUM vxc_bntarg;
BIGNUM vxc_bnbase;
Expand All @@ -75,7 +84,9 @@ typedef void (*vg_clear_all_patterns_func_t)(vg_context_t *);
typedef int (*vg_test_func_t)(vg_exec_context_t *);
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,
//typedef void (*vg_output_match_func_t)(vg_context_t *vcp, EC_KEY *pkey,
// const char *pattern);
typedef void (*vg_output_match_func_t)(vg_context_t *vcp, vg_exec_context_t *vxcp,
const char *pattern);
typedef void (*vg_output_timing_func_t)(vg_context_t *vcp, double count,
unsigned long long rate,
Expand Down Expand Up @@ -150,8 +161,12 @@ extern vg_context_t *vg_regex_context_new(int addrtype, int privtype);

/* Utility functions */
extern int vg_output_timing(vg_context_t *vcp, int cycle, struct timeval *last);
extern void vg_output_match_console(vg_context_t *vcp, EC_KEY *pkey,
const char *pattern);
extern void vg_output_match_console(vg_context_t *vcp, vg_exec_context_t *vxcp,
const char *pattern);

//extern void vg_output_match_console(vg_context_t *vcp, EC_KEY *pkey,
// const char *pattern, int compressed);

extern void vg_output_timing_console(vg_context_t *vcp, double count,
unsigned long long rate,
unsigned long long total);
Expand Down
Loading

0 comments on commit f997ba2

Please sign in to comment.