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,
|
||||
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
|
||||
pickparams(uint32_t maxmem, uint32_t megaops,
|
||||
|
@ -161,9 +161,9 @@ sha256string(uint8_t hash[32], uint8_t* s, int n)
|
|||
}
|
||||
|
||||
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];
|
||||
bintohex(buf, 32, salt);
|
||||
printf("Site hex: %s\n", buf);
|
||||
|
@ -172,7 +172,7 @@ getsalt(uint8_t salt[32], void* site)
|
|||
|
||||
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)
|
||||
{
|
||||
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 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);
|
||||
|
||||
#endif /* !_GENPASS_H_ */
|
||||
|
|
26
main.c
26
main.c
|
@ -45,20 +45,28 @@ usage(void)
|
|||
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
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
FILE * infile = NULL;
|
||||
FILE * outfile = stdout;
|
||||
int dec = 0;
|
||||
int passwdlen = 0;
|
||||
size_t passwdlen = 0;
|
||||
uint32_t maxmem = 1000;
|
||||
uint32_t megaops = 32;
|
||||
char ch;
|
||||
char * keyfile = NULL;
|
||||
char * passwd = NULL;
|
||||
uint8_t* passwd = NULL;
|
||||
int rc;
|
||||
int i;
|
||||
|
||||
#ifdef NEED_WARN_PROGNAME
|
||||
warn_progname = "scrypt-genpass";
|
||||
|
@ -68,7 +76,7 @@ main(int argc, char *argv[])
|
|||
usage();
|
||||
|
||||
/* Parse arguments. */
|
||||
while ((ch = getopt(argc, argv, "hk:m:o:p:")) != -1) {
|
||||
while ((ch = getopt(argc, argv, "htk:m:o:p:")) != -1) {
|
||||
switch (ch) {
|
||||
case 'k':
|
||||
keyfile = strdup(optarg);
|
||||
|
@ -82,6 +90,9 @@ main(int argc, char *argv[])
|
|||
case 'p':
|
||||
passwd = strdup(optarg);
|
||||
break;
|
||||
case 't':
|
||||
unit_tests();
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
|
@ -110,19 +121,16 @@ main(int argc, char *argv[])
|
|||
fseek(fp, 0, SEEK_END);
|
||||
keyfilelen = ftell(fp);
|
||||
fseek(fp, 0, SEEK_SET);
|
||||
printf("DEBUG: keyfilelen = %d\n", keyfilelen);
|
||||
uint8_t* combinedkey = malloc(passwdlen + keyfilelen + 1);
|
||||
if (combinedkey) {
|
||||
strcpy(combinedkey, passwd);
|
||||
memset(passwd, 0, passwdlen);
|
||||
free(passwd);
|
||||
int n = fread(combinedkey + passwdlen, keyfilelen, 1, fp);
|
||||
/* n == number of items read == 1 */
|
||||
size_t n = fread(combinedkey + passwdlen, keyfilelen, 1, fp);
|
||||
/* TODO: check n == number of items read == 1 */
|
||||
fclose(fp);
|
||||
printf("DEBUG: n = %d\n", n);
|
||||
passwd = combinedkey;
|
||||
passwdlen += keyfilelen;
|
||||
printf("DEBUG: combinedkey = %s\n", passwd);
|
||||
} else {
|
||||
rc = 15;
|
||||
}
|
||||
|
|
Reference in a new issue