mirror of
https://github.com/cathugger/mkp224o.git
synced 2025-06-08 23:57:43 +00:00
tweaks and cleanups
This commit is contained in:
parent
25457c8741
commit
0208fc3fad
1 changed files with 83 additions and 62 deletions
119
main.c
119
main.c
|
@ -10,6 +10,7 @@
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <sodium/randombytes.h>
|
#include <sodium/randombytes.h>
|
||||||
|
#include <sodium/utils.h>
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "likely.h"
|
#include "likely.h"
|
||||||
|
@ -276,6 +277,8 @@ next:
|
||||||
end:
|
end:
|
||||||
free(sname);
|
free(sname);
|
||||||
POSTFILTER
|
POSTFILTER
|
||||||
|
sodium_memzero(secret,sizeof(secret));
|
||||||
|
sodium_memzero(seed,sizeof(seed));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -392,6 +395,8 @@ initseed:
|
||||||
end:
|
end:
|
||||||
free(sname);
|
free(sname);
|
||||||
POSTFILTER
|
POSTFILTER
|
||||||
|
sodium_memzero(secret,sizeof(secret));
|
||||||
|
sodium_memzero(seed,sizeof(seed));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -401,7 +406,7 @@ static void printhelp(FILE *out,const char *progname)
|
||||||
"Usage: %s filter [filter...] [options]\n"
|
"Usage: %s filter [filter...] [options]\n"
|
||||||
" %s -f filterfile [options]\n"
|
" %s -f filterfile [options]\n"
|
||||||
"Options:\n"
|
"Options:\n"
|
||||||
"\t-h - print help\n"
|
"\t-h - print help to stdout and quit\n"
|
||||||
"\t-f - instead of specifying filter(s) via commandline, specify filter file which contains filters separated by newlines\n"
|
"\t-f - instead of specifying filter(s) via commandline, specify filter file which contains filters separated by newlines\n"
|
||||||
"\t-q - do not print diagnostic output to stderr\n"
|
"\t-q - do not print diagnostic output to stderr\n"
|
||||||
"\t-x - do not print onion names\n"
|
"\t-x - do not print onion names\n"
|
||||||
|
@ -419,9 +424,31 @@ static void printhelp(FILE *out,const char *progname)
|
||||||
"\t-T - do not reset statistics counters when printing\n"
|
"\t-T - do not reset statistics counters when printing\n"
|
||||||
,progname,progname);
|
,progname,progname);
|
||||||
fflush(out);
|
fflush(out);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum {
|
||||||
|
Q_ADDITIONAL = 100,
|
||||||
|
Q_UNRECOGNISED = 101,
|
||||||
|
Q_NOSTATISTICS = 102,
|
||||||
|
Q_FAILOPENOUTPUT = 103,
|
||||||
|
Q_FAILTHREAD = 104,
|
||||||
|
Q_FAILTIME = 105,
|
||||||
|
} ;
|
||||||
|
|
||||||
|
static void e_additional()
|
||||||
|
{
|
||||||
|
fprintf(stderr,"additional argument required\n");
|
||||||
|
exit(Q_ADDITIONAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef STATISTICS
|
||||||
|
static void e_nostatistics()
|
||||||
|
{
|
||||||
|
fprintf(stderr,"statistics support not compiled in\n");
|
||||||
|
exit(Q_NOSTATISTICS);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static void setworkdir(const char *wd)
|
static void setworkdir(const char *wd)
|
||||||
{
|
{
|
||||||
free(workdir);
|
free(workdir);
|
||||||
|
@ -478,9 +505,11 @@ int main(int argc,char **argv)
|
||||||
pthread_mutex_init(&fout_mutex,0);
|
pthread_mutex_init(&fout_mutex,0);
|
||||||
|
|
||||||
const char *progname = argv[0];
|
const char *progname = argv[0];
|
||||||
if (argc <= 1)
|
if (argc <= 1) {
|
||||||
printhelp(stderr,progname);
|
printhelp(stderr,progname);
|
||||||
argc--, argv++;
|
exit(1);
|
||||||
|
}
|
||||||
|
argc--; argv++;
|
||||||
|
|
||||||
while (argc--) {
|
while (argc--) {
|
||||||
arg = *argv++;
|
arg = *argv++;
|
||||||
|
@ -492,16 +521,18 @@ int main(int argc,char **argv)
|
||||||
if (*arg == '-') {
|
if (*arg == '-') {
|
||||||
if (numargit > 1) {
|
if (numargit > 1) {
|
||||||
fprintf(stderr,"unrecognised argument: -\n");
|
fprintf(stderr,"unrecognised argument: -\n");
|
||||||
exit(1);
|
exit(Q_UNRECOGNISED);
|
||||||
}
|
}
|
||||||
++arg;
|
++arg;
|
||||||
if (!*arg)
|
if (!*arg)
|
||||||
ignoreargs = 1;
|
ignoreargs = 1;
|
||||||
else if (!strcmp(arg, "help"))
|
else if (!strcmp(arg,"help") || !strcmp(arg,"usage")) {
|
||||||
printhelp(stdout,progname);
|
printhelp(stdout,progname);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
fprintf(stderr,"unrecognised argument: --%s\n",arg);
|
fprintf(stderr,"unrecognised argument: --%s\n",arg);
|
||||||
exit(1);
|
exit(Q_UNRECOGNISED);
|
||||||
}
|
}
|
||||||
numargit = 0;
|
numargit = 0;
|
||||||
}
|
}
|
||||||
|
@ -510,15 +541,15 @@ int main(int argc,char **argv)
|
||||||
ignoreargs = 1;
|
ignoreargs = 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else if (*arg == 'h')
|
else if (*arg == 'h') {
|
||||||
printhelp(stdout,progname);
|
printhelp(stdout,progname);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
else if (*arg == 'f') {
|
else if (*arg == 'f') {
|
||||||
if (argc--)
|
if (argc--)
|
||||||
loadfilterfile(*argv++);
|
loadfilterfile(*argv++);
|
||||||
else {
|
else
|
||||||
fprintf(stderr, "additional argument required\n");
|
e_additional();
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (*arg == 'q')
|
else if (*arg == 'q')
|
||||||
++quietflag;
|
++quietflag;
|
||||||
|
@ -527,44 +558,34 @@ int main(int argc,char **argv)
|
||||||
else if (*arg == 'o') {
|
else if (*arg == 'o') {
|
||||||
if (argc--)
|
if (argc--)
|
||||||
outfile = *argv++;
|
outfile = *argv++;
|
||||||
else {
|
else
|
||||||
fprintf(stderr, "additional argument required\n");
|
e_additional();
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (*arg == 'F')
|
else if (*arg == 'F')
|
||||||
dirnameflag = 1;
|
dirnameflag = 1;
|
||||||
else if (*arg == 'd') {
|
else if (*arg == 'd') {
|
||||||
if (argc--) {
|
if (argc--)
|
||||||
setworkdir(*argv++);
|
setworkdir(*argv++);
|
||||||
}
|
else
|
||||||
else {
|
e_additional();
|
||||||
fprintf(stderr, "additional argument required\n");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (*arg == 't' || *arg == 'j') {
|
else if (*arg == 't' || *arg == 'j') {
|
||||||
if (argc--)
|
if (argc--)
|
||||||
numthreads = atoi(*argv++);
|
numthreads = atoi(*argv++);
|
||||||
else {
|
else
|
||||||
fprintf(stderr, "additional argument required\n");
|
e_additional();
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (*arg == 'n') {
|
else if (*arg == 'n') {
|
||||||
if (argc--)
|
if (argc--)
|
||||||
numneedgenerate = (size_t)atoll(*argv++);
|
numneedgenerate = (size_t)atoll(*argv++);
|
||||||
else {
|
else
|
||||||
fprintf(stderr, "additional argument required\n");
|
e_additional();
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (*arg == 'N') {
|
else if (*arg == 'N') {
|
||||||
if (argc--)
|
if (argc--)
|
||||||
numwords = atoi(*argv++);
|
numwords = atoi(*argv++);
|
||||||
else {
|
else
|
||||||
fprintf(stderr, "additional argument required\n");
|
e_additional();
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (*arg == 'Z')
|
else if (*arg == 'Z')
|
||||||
fastkeygen = 0;
|
fastkeygen = 0;
|
||||||
|
@ -574,34 +595,29 @@ int main(int argc,char **argv)
|
||||||
#ifdef STATISTICS
|
#ifdef STATISTICS
|
||||||
reportdelay = 10000000;
|
reportdelay = 10000000;
|
||||||
#else
|
#else
|
||||||
fprintf(stderr,"statistics support not compiled in\n");
|
e_nostatistics();
|
||||||
exit(1);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else if (*arg == 'S') {
|
else if (*arg == 'S') {
|
||||||
#ifdef STATISTICS
|
#ifdef STATISTICS
|
||||||
if (argc--)
|
if (argc--)
|
||||||
reportdelay = (u64)atoll(*argv++) * 1000000;
|
reportdelay = (u64)atoll(*argv++) * 1000000;
|
||||||
else {
|
else
|
||||||
fprintf(stderr, "additional argument required\n");
|
e_additional();
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
fprintf(stderr,"statistics support not compiled in\n");
|
e_nostatistics();
|
||||||
exit(1);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else if (*arg == 'T') {
|
else if (*arg == 'T') {
|
||||||
#ifdef STATISTICS
|
#ifdef STATISTICS
|
||||||
realtimestats = 0;
|
realtimestats = 0;
|
||||||
#else
|
#else
|
||||||
fprintf(stderr,"statistics support not compiled in\n");
|
e_nostatistics();
|
||||||
exit(1);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fprintf(stderr,"unrecognised argument: -%c\n",*arg);
|
fprintf(stderr,"unrecognised argument: -%c\n",*arg);
|
||||||
exit(1);
|
exit(Q_UNRECOGNISED);
|
||||||
}
|
}
|
||||||
if (numargit)
|
if (numargit)
|
||||||
goto nextarg;
|
goto nextarg;
|
||||||
|
@ -625,8 +641,13 @@ int main(int argc,char **argv)
|
||||||
fprintf(stderr,"WARNING: -N switch will produce bogus results because we can't know filter width. reconfigure with --enable-besort and recompile.\n");
|
fprintf(stderr,"WARNING: -N switch will produce bogus results because we can't know filter width. reconfigure with --enable-besort and recompile.\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (outfile)
|
if (outfile) {
|
||||||
fout = fopen(outfile,"w");
|
fout = fopen(outfile,"w");
|
||||||
|
if (!fout) {
|
||||||
|
perror("failed to open output file");
|
||||||
|
exit(Q_FAILOPENOUTPUT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (workdir)
|
if (workdir)
|
||||||
createdir(workdir,1);
|
createdir(workdir,1);
|
||||||
|
@ -672,8 +693,8 @@ int main(int argc,char **argv)
|
||||||
#endif
|
#endif
|
||||||
tret = pthread_create(&VEC_BUF(threads,i),0,fastkeygen ? dofastwork : dowork,tp);
|
tret = pthread_create(&VEC_BUF(threads,i),0,fastkeygen ? dofastwork : dowork,tp);
|
||||||
if (tret) {
|
if (tret) {
|
||||||
fprintf(stderr,"error while making " FSZ "th thread: %d\n",i,tret);
|
fprintf(stderr,"error while making " FSZ "th thread: %d (%s)\n",i,tret,strerror(tret));
|
||||||
exit(1);
|
exit(Q_FAILTHREAD);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -681,8 +702,8 @@ int main(int argc,char **argv)
|
||||||
struct timespec nowtime;
|
struct timespec nowtime;
|
||||||
u64 istarttime,inowtime,ireporttime = 0,elapsedoffset = 0;
|
u64 istarttime,inowtime,ireporttime = 0,elapsedoffset = 0;
|
||||||
if (clock_gettime(CLOCK_MONOTONIC,&nowtime) < 0) {
|
if (clock_gettime(CLOCK_MONOTONIC,&nowtime) < 0) {
|
||||||
fprintf(stderr, "failed to get time\n");
|
perror("failed to get time");
|
||||||
exit(1);
|
exit(Q_FAILTIME);
|
||||||
}
|
}
|
||||||
istarttime = (1000000 * (u64)nowtime.tv_sec) + ((u64)nowtime.tv_nsec / 1000);
|
istarttime = (1000000 * (u64)nowtime.tv_sec) + ((u64)nowtime.tv_nsec / 1000);
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue