Replace -t TIME param with -o mega-operations

This commit is contained in:
Chris Oei 2012-09-02 19:46:30 -07:00
parent 63fa3d2a24
commit 8ee6e37953
3 changed files with 11 additions and 18 deletions

View file

@ -47,13 +47,13 @@
#define ENCBLOCK 65536
static int pickparams(size_t, double, double,
static int pickparams(size_t, double, int,
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
pickparams(size_t maxmem, double maxmemfrac, double maxtime,
pickparams(size_t maxmem, double maxmemfrac, int megaops,
int * logN, uint32_t * r, uint32_t * p)
{
size_t memlimit;
@ -66,13 +66,7 @@ pickparams(size_t maxmem, double maxmemfrac, double maxtime,
if (memtouse(maxmem, maxmemfrac, &memlimit))
return (1);
opps = 1; /* FIXIT: don't attempt to calculate CPU speed since
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;
opslimit = 1000000 * megaops;
/* Fix r = 8 for now. */
*r = 8;
@ -199,7 +193,7 @@ err0:
int
genpass(uint8_t dk[64],
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 hbuf[32];
@ -213,7 +207,7 @@ genpass(uint8_t dk[64],
int rc;
/* Pick values for N, r, p. */
if ((rc = pickparams(maxmem, maxmemfrac, maxtime,
if ((rc = pickparams(maxmem, maxmemfrac, megaops,
&logN, &r, &p)) != 0)
return (rc);
N = (uint64_t)(1) << logN;

View file

@ -74,6 +74,6 @@
int genpass(uint8_t dk[64],
const uint8_t * passwd, size_t passwdlen,
size_t maxmem, double maxmemfrac, double maxtime);
size_t maxmem, double maxmemfrac, int megaops);
#endif /* !_GENPASS_H_ */

11
main.c
View file

@ -53,7 +53,7 @@ main(int argc, char *argv[])
int dec = 0;
size_t maxmem = 0;
double maxmemfrac = 0.5;
double maxtime = 300.0;
int megaops = 5;
char ch;
char * passwd;
int rc;
@ -67,10 +67,9 @@ main(int argc, char *argv[])
usage();
maxmem = 0;
maxmemfrac = 0.125;
maxtime = 5.0;
/* Parse arguments. */
while ((ch = getopt(argc, argv, "hm:M:t:")) != -1) {
while ((ch = getopt(argc, argv, "hm:M:o:")) != -1) {
switch (ch) {
case 'M':
maxmem = strtoumax(optarg, NULL, 0);
@ -78,8 +77,8 @@ main(int argc, char *argv[])
case 'm':
maxmemfrac = strtod(optarg, NULL);
break;
case 't':
maxtime = strtod(optarg, NULL);
case 'o':
megaops = atoi(optarg);
break;
default:
usage();
@ -99,7 +98,7 @@ main(int argc, char *argv[])
uint8_t dk[64];
rc = genpass(dk, (uint8_t *)passwd,
strlen(passwd), maxmem, maxmemfrac, maxtime);
strlen(passwd), maxmem, maxmemfrac, megaops);
/* Zero and free the password. */
memset(passwd, 0, strlen(passwd));