mirror of
https://github.com/cathugger/mkp224o.git
synced 2025-01-09 19:17:19 -03:00
remove slow/fast workers
This commit is contained in:
parent
d612b74842
commit
2b417046b6
7 changed files with 10 additions and 343 deletions
|
@ -542,7 +542,7 @@ worker.c.o: ed25519/ed25519-donna/ed25519-donna-64bit-x86-32bit.h
|
||||||
worker.c.o: ed25519/ed25519-donna/ed25519-donna-32bit-sse2.h
|
worker.c.o: ed25519/ed25519-donna/ed25519-donna-32bit-sse2.h
|
||||||
worker.c.o: ed25519/ed25519-donna/ed25519-donna-64bit-sse2.h
|
worker.c.o: ed25519/ed25519-donna/ed25519-donna-64bit-sse2.h
|
||||||
worker.c.o: ed25519/ed25519-donna/ed25519-donna-impl-sse2.h
|
worker.c.o: ed25519/ed25519-donna/ed25519-donna-impl-sse2.h
|
||||||
worker.c.o: ed25519/ed25519-donna/ed25519-donna-impl-base.h worker_slow.inc.h
|
worker.c.o: ed25519/ed25519-donna/ed25519-donna-impl-base.h
|
||||||
worker.c.o: worker_fast.inc.h worker_fast_pass.inc.h worker_batch.inc.h
|
worker.c.o: worker_batch.inc.h worker_batch_pass.inc.h
|
||||||
worker.c.o: worker_batch_pass.inc.h ed25519/ed25519_impl_post.h
|
worker.c.o: ed25519/ed25519_impl_post.h
|
||||||
yaml.c.o: types.h yaml.h ioutil.h base32.h base64.h common.h
|
yaml.c.o: types.h yaml.h ioutil.h base32.h base64.h common.h
|
||||||
|
|
24
main.c
24
main.c
|
@ -110,10 +110,9 @@ static void printhelp(FILE *out,const char *progname)
|
||||||
" -j NUMTHREADS same as -t\n"
|
" -j NUMTHREADS same as -t\n"
|
||||||
" -n NUMKEYS specify number of keys (default - 0 - unlimited)\n"
|
" -n NUMKEYS specify number of keys (default - 0 - unlimited)\n"
|
||||||
" -N NUMWORDS specify number of words per key (default - 1)\n"
|
" -N NUMWORDS specify number of words per key (default - 1)\n"
|
||||||
" -Z use \"slower\" key generation method (initial default)\n"
|
" -Z deprecated, does nothing\n"
|
||||||
" -z use \"faster\" key generation method (later default)\n"
|
" -z deprecated, does nothing\n"
|
||||||
" -B use batching key generation method\n"
|
" -B use batching key generation method (current default)\n"
|
||||||
" (>10x faster than -z, current default)\n"
|
|
||||||
" -s print statistics each 10 seconds\n"
|
" -s print statistics each 10 seconds\n"
|
||||||
" -S SECONDS print statistics every specified amount of seconds\n"
|
" -S SECONDS print statistics every specified amount of seconds\n"
|
||||||
" -T do not reset statistics counters when printing\n"
|
" -T do not reset statistics counters when printing\n"
|
||||||
|
@ -257,8 +256,6 @@ VEC_STRUCT(threadvec,pthread_t);
|
||||||
#include "filters_main.inc.h"
|
#include "filters_main.inc.h"
|
||||||
|
|
||||||
enum worker_type {
|
enum worker_type {
|
||||||
WT_SLOW,
|
|
||||||
WT_FAST,
|
|
||||||
WT_BATCH,
|
WT_BATCH,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -417,9 +414,9 @@ int main(int argc,char **argv)
|
||||||
e_additional();
|
e_additional();
|
||||||
}
|
}
|
||||||
else if (*arg == 'Z')
|
else if (*arg == 'Z')
|
||||||
wt = WT_SLOW;
|
/* ignored */ ;
|
||||||
else if (*arg == 'z')
|
else if (*arg == 'z')
|
||||||
wt = WT_FAST;
|
/* ignored */ ;
|
||||||
else if (*arg == 'B')
|
else if (*arg == 'B')
|
||||||
wt = WT_BATCH;
|
wt = WT_BATCH;
|
||||||
else if (*arg == 's') {
|
else if (*arg == 's') {
|
||||||
|
@ -665,17 +662,10 @@ int main(int argc,char **argv)
|
||||||
tattrp,
|
tattrp,
|
||||||
#ifdef PASSPHRASE
|
#ifdef PASSPHRASE
|
||||||
deterministic
|
deterministic
|
||||||
? (wt == WT_BATCH
|
? CRYPTO_NAMESPACE(worker_batch_pass)
|
||||||
? CRYPTO_NAMESPACE(worker_batch_pass)
|
|
||||||
: CRYPTO_NAMESPACE(worker_fast_pass))
|
|
||||||
:
|
:
|
||||||
#endif
|
#endif
|
||||||
wt == WT_BATCH
|
CRYPTO_NAMESPACE(worker_batch),
|
||||||
? CRYPTO_NAMESPACE(worker_batch)
|
|
||||||
:
|
|
||||||
wt == WT_FAST
|
|
||||||
? CRYPTO_NAMESPACE(worker_fast)
|
|
||||||
: CRYPTO_NAMESPACE(worker_slow),
|
|
||||||
tp
|
tp
|
||||||
);
|
);
|
||||||
if (tret) {
|
if (tret) {
|
||||||
|
|
3
worker.h
3
worker.h
|
@ -40,10 +40,7 @@ extern void worker_init(void);
|
||||||
extern char *makesname(void);
|
extern char *makesname(void);
|
||||||
extern size_t worker_batch_memuse(void);
|
extern size_t worker_batch_memuse(void);
|
||||||
|
|
||||||
extern void *CRYPTO_NAMESPACE(worker_slow)(void *task);
|
|
||||||
extern void *CRYPTO_NAMESPACE(worker_fast)(void *task);
|
|
||||||
extern void *CRYPTO_NAMESPACE(worker_batch)(void *task);
|
extern void *CRYPTO_NAMESPACE(worker_batch)(void *task);
|
||||||
#ifdef PASSPHRASE
|
#ifdef PASSPHRASE
|
||||||
extern void *CRYPTO_NAMESPACE(worker_fast_pass)(void *task);
|
|
||||||
extern void *CRYPTO_NAMESPACE(worker_batch_pass)(void *task);
|
extern void *CRYPTO_NAMESPACE(worker_batch_pass)(void *task);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,107 +0,0 @@
|
||||||
|
|
||||||
void *CRYPTO_NAMESPACE(worker_fast)(void *task)
|
|
||||||
{
|
|
||||||
union pubonionunion pubonion;
|
|
||||||
u8 * const pk = &pubonion.raw[PKPREFIX_SIZE];
|
|
||||||
u8 secret[SKPREFIX_SIZE + SECRET_LEN];
|
|
||||||
u8 * const sk = &secret[SKPREFIX_SIZE];
|
|
||||||
u8 seed[SEED_LEN];
|
|
||||||
u8 hashsrc[checksumstrlen + PUBLIC_LEN + 1];
|
|
||||||
u8 wpk[PUBLIC_LEN + 1];
|
|
||||||
ge_p3 ALIGN(16) ge_public;
|
|
||||||
char *sname;
|
|
||||||
|
|
||||||
size_t counter;
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
#ifdef STATISTICS
|
|
||||||
struct statstruct *st = (struct statstruct *)task;
|
|
||||||
#else
|
|
||||||
(void) task;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
PREFILTER
|
|
||||||
|
|
||||||
memcpy(secret,skprefix,SKPREFIX_SIZE);
|
|
||||||
wpk[PUBLIC_LEN] = 0;
|
|
||||||
memset(&pubonion,0,sizeof(pubonion));
|
|
||||||
memcpy(pubonion.raw,pkprefix,PKPREFIX_SIZE);
|
|
||||||
// write version later as it will be overwritten by hash
|
|
||||||
memcpy(hashsrc,checksumstr,checksumstrlen);
|
|
||||||
hashsrc[checksumstrlen + PUBLIC_LEN] = 0x03; // version
|
|
||||||
|
|
||||||
sname = makesname();
|
|
||||||
|
|
||||||
initseed:
|
|
||||||
|
|
||||||
#ifdef STATISTICS
|
|
||||||
++st->numrestart.v;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
randombytes(seed,sizeof(seed));
|
|
||||||
|
|
||||||
ed25519_seckey_expand(sk,seed);
|
|
||||||
|
|
||||||
ge_scalarmult_base(&ge_public,sk);
|
|
||||||
ge_p3_tobytes(pk,&ge_public);
|
|
||||||
|
|
||||||
for (counter = 0;counter < SIZE_MAX-8;counter += 8) {
|
|
||||||
ge_p1p1 ALIGN(16) sum;
|
|
||||||
|
|
||||||
if (unlikely(endwork))
|
|
||||||
goto end;
|
|
||||||
|
|
||||||
DOFILTER(i,pk,{
|
|
||||||
if (numwords > 1) {
|
|
||||||
shiftpk(wpk,pk,filter_len(i));
|
|
||||||
size_t j;
|
|
||||||
for (int w = 1;;) {
|
|
||||||
DOFILTER(j,wpk,goto secondfind);
|
|
||||||
goto next;
|
|
||||||
secondfind:
|
|
||||||
if (++w >= numwords)
|
|
||||||
break;
|
|
||||||
shiftpk(wpk,wpk,filter_len(j));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// found!
|
|
||||||
// update secret key with counter
|
|
||||||
addsztoscalar32(sk,counter);
|
|
||||||
// sanity check
|
|
||||||
if ((sk[0] & 248) != sk[0] || ((sk[31] & 63) | 64) != sk[31])
|
|
||||||
goto initseed;
|
|
||||||
|
|
||||||
ADDNUMSUCCESS;
|
|
||||||
|
|
||||||
// calc checksum
|
|
||||||
memcpy(&hashsrc[checksumstrlen],pk,PUBLIC_LEN);
|
|
||||||
FIPS202_SHA3_256(hashsrc,sizeof(hashsrc),&pk[PUBLIC_LEN]);
|
|
||||||
// version byte
|
|
||||||
pk[PUBLIC_LEN + 2] = 0x03;
|
|
||||||
// full name
|
|
||||||
strcpy(base32_to(&sname[direndpos],pk,PUBONION_LEN),".onion");
|
|
||||||
onionready(sname,secret,pubonion.raw);
|
|
||||||
pk[PUBLIC_LEN] = 0; // what is this for?
|
|
||||||
// don't reuse same seed
|
|
||||||
goto initseed;
|
|
||||||
});
|
|
||||||
next:
|
|
||||||
ge_add(&sum,&ge_public,&ge_eightpoint);
|
|
||||||
ge_p1p1_to_p3(&ge_public,&sum);
|
|
||||||
ge_p3_tobytes(pk,&ge_public);
|
|
||||||
#ifdef STATISTICS
|
|
||||||
++st->numcalc.v;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
goto initseed;
|
|
||||||
|
|
||||||
end:
|
|
||||||
free(sname);
|
|
||||||
|
|
||||||
POSTFILTER
|
|
||||||
|
|
||||||
sodium_memzero(secret,sizeof(secret));
|
|
||||||
sodium_memzero(seed,sizeof(seed));
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
|
@ -1,116 +0,0 @@
|
||||||
|
|
||||||
#ifdef PASSPHRASE
|
|
||||||
void *CRYPTO_NAMESPACE(worker_fast_pass)(void *task)
|
|
||||||
{
|
|
||||||
union pubonionunion pubonion;
|
|
||||||
u8 * const pk = &pubonion.raw[PKPREFIX_SIZE];
|
|
||||||
u8 secret[SKPREFIX_SIZE + SECRET_LEN];
|
|
||||||
u8 * const sk = &secret[SKPREFIX_SIZE];
|
|
||||||
u8 seed[SEED_LEN];
|
|
||||||
u8 hashsrc[checksumstrlen + PUBLIC_LEN + 1];
|
|
||||||
u8 wpk[PUBLIC_LEN + 1];
|
|
||||||
ge_p3 ALIGN(16) ge_public;
|
|
||||||
char *sname;
|
|
||||||
|
|
||||||
size_t counter,oldcounter;
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
#ifdef STATISTICS
|
|
||||||
struct statstruct *st = (struct statstruct *)task;
|
|
||||||
#else
|
|
||||||
(void) task;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
PREFILTER
|
|
||||||
|
|
||||||
memcpy(secret,skprefix,SKPREFIX_SIZE);
|
|
||||||
wpk[PUBLIC_LEN] = 0;
|
|
||||||
memset(&pubonion,0,sizeof(pubonion));
|
|
||||||
memcpy(pubonion.raw,pkprefix,PKPREFIX_SIZE);
|
|
||||||
// write version later as it will be overwritten by hash
|
|
||||||
memcpy(hashsrc,checksumstr,checksumstrlen);
|
|
||||||
hashsrc[checksumstrlen + PUBLIC_LEN] = 0x03; // version
|
|
||||||
|
|
||||||
sname = makesname();
|
|
||||||
|
|
||||||
initseed:
|
|
||||||
|
|
||||||
#ifdef STATISTICS
|
|
||||||
++st->numrestart.v;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
pthread_mutex_lock(&determseed_mutex);
|
|
||||||
for (int i = 0; i < SEED_LEN; i++)
|
|
||||||
if (++determseed[i])
|
|
||||||
break;
|
|
||||||
memcpy(seed, determseed, SEED_LEN);
|
|
||||||
pthread_mutex_unlock(&determseed_mutex);
|
|
||||||
|
|
||||||
ed25519_seckey_expand(sk,seed);
|
|
||||||
|
|
||||||
ge_scalarmult_base(&ge_public,sk);
|
|
||||||
ge_p3_tobytes(pk,&ge_public);
|
|
||||||
|
|
||||||
for (counter = oldcounter = 0;counter < DETERMINISTIC_LOOP_COUNT;counter += 8) {
|
|
||||||
ge_p1p1 ALIGN(16) sum;
|
|
||||||
|
|
||||||
if (unlikely(endwork))
|
|
||||||
goto end;
|
|
||||||
|
|
||||||
DOFILTER(i,pk,{
|
|
||||||
if (numwords > 1) {
|
|
||||||
shiftpk(wpk,pk,filter_len(i));
|
|
||||||
size_t j;
|
|
||||||
for (int w = 1;;) {
|
|
||||||
DOFILTER(j,wpk,goto secondfind);
|
|
||||||
goto next;
|
|
||||||
secondfind:
|
|
||||||
if (++w >= numwords)
|
|
||||||
break;
|
|
||||||
shiftpk(wpk,wpk,filter_len(j));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// found!
|
|
||||||
// update secret key with delta since last hit (if any)
|
|
||||||
addsztoscalar32(sk,counter-oldcounter);
|
|
||||||
oldcounter = counter;
|
|
||||||
// sanity check
|
|
||||||
if ((sk[0] & 248) != sk[0] || ((sk[31] & 63) | 64) != sk[31])
|
|
||||||
goto initseed;
|
|
||||||
|
|
||||||
// reseed right half of key to avoid reuse, it won't change public key anyway
|
|
||||||
reseedright(sk);
|
|
||||||
|
|
||||||
ADDNUMSUCCESS;
|
|
||||||
|
|
||||||
// calc checksum
|
|
||||||
memcpy(&hashsrc[checksumstrlen],pk,PUBLIC_LEN);
|
|
||||||
FIPS202_SHA3_256(hashsrc,sizeof(hashsrc),&pk[PUBLIC_LEN]);
|
|
||||||
// version byte
|
|
||||||
pk[PUBLIC_LEN + 2] = 0x03;
|
|
||||||
// full name
|
|
||||||
strcpy(base32_to(&sname[direndpos],pk,PUBONION_LEN),".onion");
|
|
||||||
onionready(sname,secret,pubonion.raw);
|
|
||||||
pk[PUBLIC_LEN] = 0; // what is this for?
|
|
||||||
});
|
|
||||||
next:
|
|
||||||
ge_add(&sum, &ge_public,&ge_eightpoint);
|
|
||||||
ge_p1p1_to_p3(&ge_public,&sum);
|
|
||||||
ge_p3_tobytes(pk,&ge_public);
|
|
||||||
#ifdef STATISTICS
|
|
||||||
++st->numcalc.v;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
goto initseed;
|
|
||||||
|
|
||||||
end:
|
|
||||||
free(sname);
|
|
||||||
|
|
||||||
POSTFILTER
|
|
||||||
|
|
||||||
sodium_memzero(secret,sizeof(secret));
|
|
||||||
sodium_memzero(seed,sizeof(seed));
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#endif // PASSPHRASE
|
|
|
@ -6,9 +6,6 @@ static size_t CRYPTO_NAMESPACE(worker_batch_memuse)(void)
|
||||||
return (sizeof(ge_p3) + sizeof(fe) + sizeof(bytes32)) * BATCHNUM;
|
return (sizeof(ge_p3) + sizeof(fe) + sizeof(bytes32)) * BATCHNUM;
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "worker_slow.inc.h"
|
|
||||||
#include "worker_fast.inc.h"
|
|
||||||
#include "worker_fast_pass.inc.h"
|
|
||||||
#include "worker_batch.inc.h"
|
#include "worker_batch.inc.h"
|
||||||
#include "worker_batch_pass.inc.h"
|
#include "worker_batch_pass.inc.h"
|
||||||
|
|
||||||
|
|
|
@ -1,94 +0,0 @@
|
||||||
|
|
||||||
void *CRYPTO_NAMESPACE(worker_slow)(void *task)
|
|
||||||
{
|
|
||||||
union pubonionunion pubonion;
|
|
||||||
u8 * const pk = &pubonion.raw[PKPREFIX_SIZE];
|
|
||||||
u8 secret[SKPREFIX_SIZE + SECRET_LEN];
|
|
||||||
u8 * const sk = &secret[SKPREFIX_SIZE];
|
|
||||||
u8 seed[SEED_LEN];
|
|
||||||
u8 hashsrc[checksumstrlen + PUBLIC_LEN + 1];
|
|
||||||
u8 wpk[PUBLIC_LEN + 1];
|
|
||||||
char *sname;
|
|
||||||
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
#ifdef STATISTICS
|
|
||||||
struct statstruct *st = (struct statstruct *)task;
|
|
||||||
#else
|
|
||||||
(void) task;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
PREFILTER
|
|
||||||
|
|
||||||
memcpy(secret,skprefix,SKPREFIX_SIZE);
|
|
||||||
wpk[PUBLIC_LEN] = 0;
|
|
||||||
memset(&pubonion,0,sizeof(pubonion));
|
|
||||||
memcpy(pubonion.raw,pkprefix,PKPREFIX_SIZE);
|
|
||||||
// write version later as it will be overwritten by hash
|
|
||||||
memcpy(hashsrc,checksumstr,checksumstrlen);
|
|
||||||
hashsrc[checksumstrlen + PUBLIC_LEN] = 0x03; // version
|
|
||||||
|
|
||||||
sname = makesname();
|
|
||||||
|
|
||||||
initseed:
|
|
||||||
randombytes(seed,sizeof(seed));
|
|
||||||
ed25519_seckey_expand(sk,seed);
|
|
||||||
|
|
||||||
#ifdef STATISTICS
|
|
||||||
++st->numrestart.v;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
again:
|
|
||||||
if (unlikely(endwork))
|
|
||||||
goto end;
|
|
||||||
|
|
||||||
ed25519_pubkey(pk,sk);
|
|
||||||
|
|
||||||
#ifdef STATISTICS
|
|
||||||
++st->numcalc.v;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
DOFILTER(i,pk,{
|
|
||||||
if (numwords > 1) {
|
|
||||||
shiftpk(wpk,pk,filter_len(i));
|
|
||||||
size_t j;
|
|
||||||
for (int w = 1;;) {
|
|
||||||
DOFILTER(j,wpk,goto secondfind);
|
|
||||||
goto next;
|
|
||||||
secondfind:
|
|
||||||
if (++w >= numwords)
|
|
||||||
break;
|
|
||||||
shiftpk(wpk,wpk,filter_len(j));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// sanity check
|
|
||||||
if ((sk[0] & 248) != sk[0] || ((sk[31] & 63) | 64) != sk[31])
|
|
||||||
goto initseed;
|
|
||||||
|
|
||||||
ADDNUMSUCCESS;
|
|
||||||
|
|
||||||
// calc checksum
|
|
||||||
memcpy(&hashsrc[checksumstrlen],pk,PUBLIC_LEN);
|
|
||||||
FIPS202_SHA3_256(hashsrc,sizeof(hashsrc),&pk[PUBLIC_LEN]);
|
|
||||||
// version byte
|
|
||||||
pk[PUBLIC_LEN + 2] = 0x03;
|
|
||||||
// base32
|
|
||||||
strcpy(base32_to(&sname[direndpos],pk,PUBONION_LEN),".onion");
|
|
||||||
onionready(sname,secret,pubonion.raw);
|
|
||||||
pk[PUBLIC_LEN] = 0; // what is this for?
|
|
||||||
goto initseed;
|
|
||||||
});
|
|
||||||
next:
|
|
||||||
addsk32(sk);
|
|
||||||
goto again;
|
|
||||||
|
|
||||||
end:
|
|
||||||
free(sname);
|
|
||||||
|
|
||||||
POSTFILTER
|
|
||||||
|
|
||||||
sodium_memzero(secret,sizeof(secret));
|
|
||||||
sodium_memzero(seed,sizeof(seed));
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
Loading…
Reference in a new issue