Make types more robust
This commit is contained in:
parent
466c5a69e5
commit
205ca9df63
3 changed files with 22 additions and 14 deletions
|
@ -49,7 +49,7 @@
|
||||||
static int pickparams(uint32_t, uint32_t,
|
static int pickparams(uint32_t, uint32_t,
|
||||||
int *, uint32_t *, uint32_t *);
|
int *, uint32_t *, uint32_t *);
|
||||||
static int checkparams(uint32_t, uint32_t, int, uint32_t, uint32_t);
|
static int checkparams(uint32_t, uint32_t, int, uint32_t, uint32_t);
|
||||||
static int getsalt(uint8_t[32], void* site);
|
static int getsalt(uint8_t[32], char* site);
|
||||||
|
|
||||||
static int
|
static int
|
||||||
pickparams(uint32_t maxmem, uint32_t megaops,
|
pickparams(uint32_t maxmem, uint32_t megaops,
|
||||||
|
@ -161,9 +161,9 @@ sha256string(uint8_t hash[32], uint8_t* s, int n)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
getsalt(uint8_t salt[32], void* site)
|
getsalt(uint8_t salt[32], char* site)
|
||||||
{
|
{
|
||||||
sha256string(salt, site, strlen(site));
|
sha256string(salt, (uint8_t*) site, strlen(site));
|
||||||
char buf[65];
|
char buf[65];
|
||||||
bintohex(buf, 32, salt);
|
bintohex(buf, 32, salt);
|
||||||
printf("Site hex: %s\n", buf);
|
printf("Site hex: %s\n", buf);
|
||||||
|
@ -172,7 +172,7 @@ getsalt(uint8_t salt[32], void* site)
|
||||||
|
|
||||||
int
|
int
|
||||||
genpass(uint8_t dk[64],
|
genpass(uint8_t dk[64],
|
||||||
const uint8_t * passwd, size_t passwdlen, void* site,
|
const uint8_t * passwd, size_t passwdlen, char* site,
|
||||||
uint32_t maxmem, uint32_t megaops)
|
uint32_t maxmem, uint32_t megaops)
|
||||||
{
|
{
|
||||||
uint8_t salt[32];
|
uint8_t salt[32];
|
||||||
|
|
|
@ -76,7 +76,7 @@ int bintohex(char* outstring, size_t nbytes, uint8_t* data);
|
||||||
int sha256string(uint8_t* hash, uint8_t* s, int n);
|
int sha256string(uint8_t* hash, uint8_t* s, int n);
|
||||||
|
|
||||||
int genpass(uint8_t dk[64],
|
int genpass(uint8_t dk[64],
|
||||||
const uint8_t * passwd, size_t passwdlen, void* site,
|
const uint8_t * passwd, size_t passwdlen, char* site,
|
||||||
uint32_t maxmem, uint32_t megaops);
|
uint32_t maxmem, uint32_t megaops);
|
||||||
|
|
||||||
#endif /* !_GENPASS_H_ */
|
#endif /* !_GENPASS_H_ */
|
||||||
|
|
26
main.c
26
main.c
|
@ -45,20 +45,28 @@ usage(void)
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void unit_tests()
|
||||||
|
{
|
||||||
|
printf("sizeof(void*) = %lu\n", sizeof(void*));
|
||||||
|
printf("sizeof(char*) = %lu\n", sizeof(char*));
|
||||||
|
printf("sizeof(uint8_t*) = %lu\n", sizeof(uint8_t*));
|
||||||
|
|
||||||
|
printf("sizeof(char) = %lu\n", sizeof(char));
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
FILE * infile = NULL;
|
FILE * infile = NULL;
|
||||||
FILE * outfile = stdout;
|
FILE * outfile = stdout;
|
||||||
int dec = 0;
|
int dec = 0;
|
||||||
int passwdlen = 0;
|
size_t passwdlen = 0;
|
||||||
uint32_t maxmem = 1000;
|
uint32_t maxmem = 1000;
|
||||||
uint32_t megaops = 32;
|
uint32_t megaops = 32;
|
||||||
char ch;
|
char ch;
|
||||||
char * keyfile = NULL;
|
char * keyfile = NULL;
|
||||||
char * passwd = NULL;
|
uint8_t* passwd = NULL;
|
||||||
int rc;
|
int rc;
|
||||||
int i;
|
|
||||||
|
|
||||||
#ifdef NEED_WARN_PROGNAME
|
#ifdef NEED_WARN_PROGNAME
|
||||||
warn_progname = "scrypt-genpass";
|
warn_progname = "scrypt-genpass";
|
||||||
|
@ -68,7 +76,7 @@ main(int argc, char *argv[])
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
/* Parse arguments. */
|
/* Parse arguments. */
|
||||||
while ((ch = getopt(argc, argv, "hk:m:o:p:")) != -1) {
|
while ((ch = getopt(argc, argv, "htk:m:o:p:")) != -1) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 'k':
|
case 'k':
|
||||||
keyfile = strdup(optarg);
|
keyfile = strdup(optarg);
|
||||||
|
@ -82,6 +90,9 @@ main(int argc, char *argv[])
|
||||||
case 'p':
|
case 'p':
|
||||||
passwd = strdup(optarg);
|
passwd = strdup(optarg);
|
||||||
break;
|
break;
|
||||||
|
case 't':
|
||||||
|
unit_tests();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
|
@ -110,19 +121,16 @@ main(int argc, char *argv[])
|
||||||
fseek(fp, 0, SEEK_END);
|
fseek(fp, 0, SEEK_END);
|
||||||
keyfilelen = ftell(fp);
|
keyfilelen = ftell(fp);
|
||||||
fseek(fp, 0, SEEK_SET);
|
fseek(fp, 0, SEEK_SET);
|
||||||
printf("DEBUG: keyfilelen = %d\n", keyfilelen);
|
|
||||||
uint8_t* combinedkey = malloc(passwdlen + keyfilelen + 1);
|
uint8_t* combinedkey = malloc(passwdlen + keyfilelen + 1);
|
||||||
if (combinedkey) {
|
if (combinedkey) {
|
||||||
strcpy(combinedkey, passwd);
|
strcpy(combinedkey, passwd);
|
||||||
memset(passwd, 0, passwdlen);
|
memset(passwd, 0, passwdlen);
|
||||||
free(passwd);
|
free(passwd);
|
||||||
int n = fread(combinedkey + passwdlen, keyfilelen, 1, fp);
|
size_t n = fread(combinedkey + passwdlen, keyfilelen, 1, fp);
|
||||||
/* n == number of items read == 1 */
|
/* TODO: check n == number of items read == 1 */
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
printf("DEBUG: n = %d\n", n);
|
|
||||||
passwd = combinedkey;
|
passwd = combinedkey;
|
||||||
passwdlen += keyfilelen;
|
passwdlen += keyfilelen;
|
||||||
printf("DEBUG: combinedkey = %s\n", passwd);
|
|
||||||
} else {
|
} else {
|
||||||
rc = 15;
|
rc = 15;
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue