Convert tabs to spaces
This commit is contained in:
parent
80506f18fe
commit
74d492b50d
7 changed files with 462 additions and 462 deletions
|
@ -55,119 +55,119 @@ static int
|
|||
pickparams(uint32_t maxmem, uint32_t megaops,
|
||||
int * logN, uint32_t * r, uint32_t * p)
|
||||
{
|
||||
size_t memlimit;
|
||||
double opps;
|
||||
double opslimit;
|
||||
double maxN, maxrp;
|
||||
int rc;
|
||||
size_t memlimit;
|
||||
double opps;
|
||||
double opslimit;
|
||||
double maxN, maxrp;
|
||||
int rc;
|
||||
|
||||
/* Figure out how much memory to use. */
|
||||
memlimit = MEGA * maxmem;
|
||||
opslimit = MEGA * megaops;
|
||||
/* Figure out how much memory to use. */
|
||||
memlimit = MEGA * maxmem;
|
||||
opslimit = MEGA * megaops;
|
||||
|
||||
/* Fix r = 8 for now. */
|
||||
*r = 8;
|
||||
/* Fix r = 8 for now. */
|
||||
*r = 8;
|
||||
|
||||
/*
|
||||
* The memory limit requires that 128Nr <= memlimit, while the CPU
|
||||
* limit requires that 4Nrp <= opslimit. If opslimit < memlimit/32,
|
||||
* opslimit imposes the stronger limit on N.
|
||||
*/
|
||||
/*
|
||||
* The memory limit requires that 128Nr <= memlimit, while the CPU
|
||||
* limit requires that 4Nrp <= opslimit. If opslimit < memlimit/32,
|
||||
* opslimit imposes the stronger limit on N.
|
||||
*/
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Requiring 128Nr <= %zu, 4Nrp <= %f\n",
|
||||
memlimit, opslimit);
|
||||
fprintf(stderr, "Requiring 128Nr <= %zu, 4Nrp <= %f\n",
|
||||
memlimit, opslimit);
|
||||
#endif
|
||||
if (opslimit < memlimit/32) {
|
||||
/* Set p = 1 and choose N based on the CPU limit. */
|
||||
*p = 1;
|
||||
maxN = opslimit / (*r * 4);
|
||||
for (*logN = 1; *logN < 63; *logN += 1) {
|
||||
if ((uint64_t)(1) << *logN > maxN / 2)
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
/* Set N based on the memory limit. */
|
||||
maxN = memlimit / (*r * 128);
|
||||
for (*logN = 1; *logN < 63; *logN += 1) {
|
||||
if ((uint64_t)(1) << *logN > maxN / 2)
|
||||
break;
|
||||
}
|
||||
if (opslimit < memlimit/32) {
|
||||
/* Set p = 1 and choose N based on the CPU limit. */
|
||||
*p = 1;
|
||||
maxN = opslimit / (*r * 4);
|
||||
for (*logN = 1; *logN < 63; *logN += 1) {
|
||||
if ((uint64_t)(1) << *logN > maxN / 2)
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
/* Set N based on the memory limit. */
|
||||
maxN = memlimit / (*r * 128);
|
||||
for (*logN = 1; *logN < 63; *logN += 1) {
|
||||
if ((uint64_t)(1) << *logN > maxN / 2)
|
||||
break;
|
||||
}
|
||||
|
||||
/* Choose p based on the CPU limit. */
|
||||
maxrp = (opslimit / 4) / ((uint64_t)(1) << *logN);
|
||||
if (maxrp > 0x3fffffff)
|
||||
maxrp = 0x3fffffff;
|
||||
*p = (uint32_t)(maxrp) / *r;
|
||||
}
|
||||
/* Choose p based on the CPU limit. */
|
||||
maxrp = (opslimit / 4) / ((uint64_t)(1) << *logN);
|
||||
if (maxrp > 0x3fffffff)
|
||||
maxrp = 0x3fffffff;
|
||||
*p = (uint32_t)(maxrp) / *r;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "N = %zu r = %d p = %d\n",
|
||||
(size_t)(1) << *logN, (int)(*r), (int)(*p));
|
||||
fprintf(stderr, "N = %zu r = %d p = %d\n",
|
||||
(size_t)(1) << *logN, (int)(*r), (int)(*p));
|
||||
#endif
|
||||
|
||||
/* Success! */
|
||||
return (0);
|
||||
/* Success! */
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
checkparams(uint32_t maxmem, uint32_t megaops,
|
||||
int logN, uint32_t r, uint32_t p)
|
||||
{
|
||||
size_t memlimit;
|
||||
double opps;
|
||||
double opslimit;
|
||||
uint64_t N;
|
||||
int rc;
|
||||
size_t memlimit;
|
||||
double opps;
|
||||
double opslimit;
|
||||
uint64_t N;
|
||||
int rc;
|
||||
|
||||
/* Figure out the maximum amount of memory we can use. */
|
||||
memlimit = 1000000 * maxmem;
|
||||
/* Figure out the maximum amount of memory we can use. */
|
||||
memlimit = 1000000 * maxmem;
|
||||
|
||||
opslimit = 1000000 * megaops;
|
||||
opslimit = 1000000 * megaops;
|
||||
|
||||
/* Sanity-check values. */
|
||||
if ((logN < 1) || (logN > 63))
|
||||
return (7);
|
||||
if ((uint64_t)(r) * (uint64_t)(p) >= 0x40000000)
|
||||
return (7);
|
||||
/* Sanity-check values. */
|
||||
if ((logN < 1) || (logN > 63))
|
||||
return (7);
|
||||
if ((uint64_t)(r) * (uint64_t)(p) >= 0x40000000)
|
||||
return (7);
|
||||
|
||||
/* Check limits. */
|
||||
N = (uint64_t)(1) << logN;
|
||||
if ((memlimit / N) / r < 128)
|
||||
return (9);
|
||||
if ((opslimit / N) / (r * p) < 4)
|
||||
return (10);
|
||||
/* Check limits. */
|
||||
N = (uint64_t)(1) << logN;
|
||||
if ((memlimit / N) / r < 128)
|
||||
return (9);
|
||||
if ((opslimit / N) / (r * p) < 4)
|
||||
return (10);
|
||||
|
||||
/* Success! */
|
||||
return (0);
|
||||
/* Success! */
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
bintohex(char* outstring, size_t nbytes, uint8_t* data)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < nbytes; i++)
|
||||
sprintf(outstring + 2 * i, "%02x", data[i]);
|
||||
outstring[2 * nbytes] = '\0';
|
||||
return 0;
|
||||
int i;
|
||||
for (i = 0; i < nbytes; i++)
|
||||
sprintf(outstring + 2 * i, "%02x", data[i]);
|
||||
outstring[2 * nbytes] = '\0';
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
sha256string(uint8_t hash[32], uint8_t* s, int n)
|
||||
{
|
||||
SHA256_CTX sha256_ctx;
|
||||
SHA256_Init(&sha256_ctx);
|
||||
SHA256_Update(&sha256_ctx, (void*) s, n);
|
||||
SHA256_Final(hash, &sha256_ctx);
|
||||
SHA256_CTX sha256_ctx;
|
||||
SHA256_Init(&sha256_ctx);
|
||||
SHA256_Update(&sha256_ctx, (void*) s, n);
|
||||
SHA256_Final(hash, &sha256_ctx);
|
||||
}
|
||||
|
||||
static int
|
||||
getsalt(uint8_t salt[32], char* site)
|
||||
{
|
||||
sha256string(salt, (uint8_t*) site, strlen(site));
|
||||
char buf[65];
|
||||
bintohex(buf, 32, salt);
|
||||
printf("Site hex: %s\n", buf);
|
||||
return (0);
|
||||
sha256string(salt, (uint8_t*) site, strlen(site));
|
||||
char buf[65];
|
||||
bintohex(buf, 32, salt);
|
||||
printf("Site hex: %s\n", buf);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -175,31 +175,31 @@ genpass(uint8_t dk[64],
|
|||
const uint8_t * passwd, size_t passwdlen, char* site,
|
||||
uint32_t maxmem, uint32_t megaops)
|
||||
{
|
||||
uint8_t salt[32];
|
||||
uint8_t hbuf[32];
|
||||
int logN;
|
||||
uint64_t N;
|
||||
uint32_t r;
|
||||
uint32_t p;
|
||||
SHA256_CTX ctx;
|
||||
uint8_t * key_hmac = &dk[32];
|
||||
HMAC_SHA256_CTX hctx;
|
||||
int rc;
|
||||
uint8_t salt[32];
|
||||
uint8_t hbuf[32];
|
||||
int logN;
|
||||
uint64_t N;
|
||||
uint32_t r;
|
||||
uint32_t p;
|
||||
SHA256_CTX ctx;
|
||||
uint8_t * key_hmac = &dk[32];
|
||||
HMAC_SHA256_CTX hctx;
|
||||
int rc;
|
||||
|
||||
/* Pick values for N, r, p. */
|
||||
if ((rc = pickparams(maxmem, megaops,
|
||||
&logN, &r, &p)) != 0)
|
||||
return (rc);
|
||||
N = (uint64_t)(1) << logN;
|
||||
/* Pick values for N, r, p. */
|
||||
if ((rc = pickparams(maxmem, megaops,
|
||||
&logN, &r, &p)) != 0)
|
||||
return (rc);
|
||||
N = (uint64_t)(1) << logN;
|
||||
|
||||
/* Get some salt using the site. */
|
||||
if ((rc = getsalt(salt, site)) != 0)
|
||||
return (rc);
|
||||
/* Get some salt using the site. */
|
||||
if ((rc = getsalt(salt, site)) != 0)
|
||||
return (rc);
|
||||
|
||||
/* Generate the derived keys. */
|
||||
if (crypto_scrypt(passwd, passwdlen, salt, 32, N, r, p, dk, 64))
|
||||
return (3);
|
||||
/* Generate the derived keys. */
|
||||
if (crypto_scrypt(passwd, passwdlen, salt, 32, N, r, p, dk, 64))
|
||||
return (3);
|
||||
|
||||
/* Success! */
|
||||
return (0);
|
||||
/* Success! */
|
||||
return (0);
|
||||
}
|
||||
|
|
|
@ -56,20 +56,20 @@
|
|||
*/
|
||||
/**
|
||||
* Return codes from scrypt(enc|dec)_(buf|file):
|
||||
* 0 success
|
||||
* 1 getrlimit or sysctl(hw.usermem) failed
|
||||
* 2 clock_getres or clock_gettime failed
|
||||
* 3 error computing derived key
|
||||
* 4 could not read salt from /dev/urandom
|
||||
* 5 error in OpenSSL
|
||||
* 6 malloc failed
|
||||
* 7 data is not a valid scrypt-encrypted block
|
||||
* 8 unrecognized scrypt format
|
||||
* 9 decrypting file would take too much memory
|
||||
* 10 decrypting file would take too long
|
||||
* 11 password is incorrect
|
||||
* 12 error writing output file
|
||||
* 13 error reading input file
|
||||
* 0 success
|
||||
* 1 getrlimit or sysctl(hw.usermem) failed
|
||||
* 2 clock_getres or clock_gettime failed
|
||||
* 3 error computing derived key
|
||||
* 4 could not read salt from /dev/urandom
|
||||
* 5 error in OpenSSL
|
||||
* 6 malloc failed
|
||||
* 7 data is not a valid scrypt-encrypted block
|
||||
* 8 unrecognized scrypt format
|
||||
* 9 decrypting file would take too much memory
|
||||
* 10 decrypting file would take too long
|
||||
* 11 password is incorrect
|
||||
* 12 error writing output file
|
||||
* 13 error reading input file
|
||||
*/
|
||||
int bintohex(char* outstring, size_t nbytes, uint8_t* data);
|
||||
|
||||
|
@ -80,15 +80,15 @@ int genpass(uint8_t dk[64],
|
|||
uint32_t maxmem, uint32_t megaops);
|
||||
|
||||
typedef struct {
|
||||
char* keyfile;
|
||||
uint32_t maxmem;
|
||||
uint32_t megaops;
|
||||
int numbers_only;
|
||||
size_t outputlength;
|
||||
uint8_t* passwd;
|
||||
size_t passwdlen;
|
||||
char* site;
|
||||
int verbose;
|
||||
char* keyfile;
|
||||
uint32_t maxmem;
|
||||
uint32_t megaops;
|
||||
int numbers_only;
|
||||
size_t outputlength;
|
||||
uint8_t* passwd;
|
||||
size_t passwdlen;
|
||||
char* site;
|
||||
int verbose;
|
||||
} sg_parms_t, *sg_parms_ptr;
|
||||
|
||||
#endif /* !_GENPASS_H_ */
|
||||
|
|
Reference in a new issue