Replace -t TIME param with -o mega-operations
This commit is contained in:
parent
63fa3d2a24
commit
8ee6e37953
3 changed files with 11 additions and 18 deletions
|
@ -47,13 +47,13 @@
|
||||||
|
|
||||||
#define ENCBLOCK 65536
|
#define ENCBLOCK 65536
|
||||||
|
|
||||||
static int pickparams(size_t, double, double,
|
static int pickparams(size_t, double, int,
|
||||||
int *, uint32_t *, uint32_t *);
|
int *, uint32_t *, uint32_t *);
|
||||||
static int checkparams(size_t, double, double, int, uint32_t, uint32_t);
|
static int checkparams(size_t, double, double, int, uint32_t, uint32_t);
|
||||||
static int getsalt(uint8_t[32]);
|
static int getsalt(uint8_t[32]);
|
||||||
|
|
||||||
static int
|
static int
|
||||||
pickparams(size_t maxmem, double maxmemfrac, double maxtime,
|
pickparams(size_t maxmem, double maxmemfrac, int megaops,
|
||||||
int * logN, uint32_t * r, uint32_t * p)
|
int * logN, uint32_t * r, uint32_t * p)
|
||||||
{
|
{
|
||||||
size_t memlimit;
|
size_t memlimit;
|
||||||
|
@ -66,13 +66,7 @@ pickparams(size_t maxmem, double maxmemfrac, double maxtime,
|
||||||
if (memtouse(maxmem, maxmemfrac, &memlimit))
|
if (memtouse(maxmem, maxmemfrac, &memlimit))
|
||||||
return (1);
|
return (1);
|
||||||
|
|
||||||
opps = 1; /* FIXIT: don't attempt to calculate CPU speed since
|
opslimit = 1000000 * megaops;
|
||||||
we want the same result on any computer. */
|
|
||||||
opslimit = opps * maxtime;
|
|
||||||
|
|
||||||
/* Allow a minimum of 2^15 salsa20/8 cores. */
|
|
||||||
if (opslimit < 32768)
|
|
||||||
opslimit = 32768;
|
|
||||||
|
|
||||||
/* Fix r = 8 for now. */
|
/* Fix r = 8 for now. */
|
||||||
*r = 8;
|
*r = 8;
|
||||||
|
@ -199,7 +193,7 @@ err0:
|
||||||
int
|
int
|
||||||
genpass(uint8_t dk[64],
|
genpass(uint8_t dk[64],
|
||||||
const uint8_t * passwd, size_t passwdlen,
|
const uint8_t * passwd, size_t passwdlen,
|
||||||
size_t maxmem, double maxmemfrac, double maxtime)
|
size_t maxmem, double maxmemfrac, int megaops)
|
||||||
{
|
{
|
||||||
uint8_t salt[32];
|
uint8_t salt[32];
|
||||||
uint8_t hbuf[32];
|
uint8_t hbuf[32];
|
||||||
|
@ -213,7 +207,7 @@ genpass(uint8_t dk[64],
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
/* Pick values for N, r, p. */
|
/* Pick values for N, r, p. */
|
||||||
if ((rc = pickparams(maxmem, maxmemfrac, maxtime,
|
if ((rc = pickparams(maxmem, maxmemfrac, megaops,
|
||||||
&logN, &r, &p)) != 0)
|
&logN, &r, &p)) != 0)
|
||||||
return (rc);
|
return (rc);
|
||||||
N = (uint64_t)(1) << logN;
|
N = (uint64_t)(1) << logN;
|
||||||
|
|
|
@ -74,6 +74,6 @@
|
||||||
|
|
||||||
int genpass(uint8_t dk[64],
|
int genpass(uint8_t dk[64],
|
||||||
const uint8_t * passwd, size_t passwdlen,
|
const uint8_t * passwd, size_t passwdlen,
|
||||||
size_t maxmem, double maxmemfrac, double maxtime);
|
size_t maxmem, double maxmemfrac, int megaops);
|
||||||
|
|
||||||
#endif /* !_GENPASS_H_ */
|
#endif /* !_GENPASS_H_ */
|
||||||
|
|
11
main.c
11
main.c
|
@ -53,7 +53,7 @@ main(int argc, char *argv[])
|
||||||
int dec = 0;
|
int dec = 0;
|
||||||
size_t maxmem = 0;
|
size_t maxmem = 0;
|
||||||
double maxmemfrac = 0.5;
|
double maxmemfrac = 0.5;
|
||||||
double maxtime = 300.0;
|
int megaops = 5;
|
||||||
char ch;
|
char ch;
|
||||||
char * passwd;
|
char * passwd;
|
||||||
int rc;
|
int rc;
|
||||||
|
@ -67,10 +67,9 @@ main(int argc, char *argv[])
|
||||||
usage();
|
usage();
|
||||||
maxmem = 0;
|
maxmem = 0;
|
||||||
maxmemfrac = 0.125;
|
maxmemfrac = 0.125;
|
||||||
maxtime = 5.0;
|
|
||||||
|
|
||||||
/* Parse arguments. */
|
/* Parse arguments. */
|
||||||
while ((ch = getopt(argc, argv, "hm:M:t:")) != -1) {
|
while ((ch = getopt(argc, argv, "hm:M:o:")) != -1) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 'M':
|
case 'M':
|
||||||
maxmem = strtoumax(optarg, NULL, 0);
|
maxmem = strtoumax(optarg, NULL, 0);
|
||||||
|
@ -78,8 +77,8 @@ main(int argc, char *argv[])
|
||||||
case 'm':
|
case 'm':
|
||||||
maxmemfrac = strtod(optarg, NULL);
|
maxmemfrac = strtod(optarg, NULL);
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 'o':
|
||||||
maxtime = strtod(optarg, NULL);
|
megaops = atoi(optarg);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
usage();
|
usage();
|
||||||
|
@ -99,7 +98,7 @@ main(int argc, char *argv[])
|
||||||
|
|
||||||
uint8_t dk[64];
|
uint8_t dk[64];
|
||||||
rc = genpass(dk, (uint8_t *)passwd,
|
rc = genpass(dk, (uint8_t *)passwd,
|
||||||
strlen(passwd), maxmem, maxmemfrac, maxtime);
|
strlen(passwd), maxmem, maxmemfrac, megaops);
|
||||||
|
|
||||||
/* Zero and free the password. */
|
/* Zero and free the password. */
|
||||||
memset(passwd, 0, strlen(passwd));
|
memset(passwd, 0, strlen(passwd));
|
||||||
|
|
Reference in a new issue