Bug fixes in display code

This commit is contained in:
Chris Oei 2012-09-03 00:57:10 -07:00
parent a3b016ceed
commit 5a3a8506fc
3 changed files with 34 additions and 9 deletions

View file

@ -141,13 +141,32 @@ checkparams(uint32_t maxmem, uint32_t megaops,
return (0); return (0);
} }
static int int
getsalt(uint8_t salt[32], void* site) 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
sha256string(uint8_t hash[32], char* s)
{ {
SHA256_CTX sha256_ctx; SHA256_CTX sha256_ctx;
SHA256_Init(&sha256_ctx); SHA256_Init(&sha256_ctx);
SHA256_Update(&sha256_ctx, site, strlen(site)); SHA256_Update(&sha256_ctx, (void*) s, strlen(s));
SHA256_Final(salt, &sha256_ctx); SHA256_Final(hash, &sha256_ctx);
}
static int
getsalt(uint8_t salt[32], void* site)
{
sha256string(salt, site);
char buf[65];
bintohex(buf, 32, salt);
printf("Site hex: %s\n", buf);
return (0); return (0);
} }

View file

@ -71,6 +71,9 @@
* 12 error writing output file * 12 error writing output file
* 13 error reading input file * 13 error reading input file
*/ */
int bintohex(char* outstring, size_t nbytes, uint8_t* data);
int sha256string(uint8_t* hash, char* s);
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, void* site,

13
main.c
View file

@ -94,6 +94,11 @@ main(int argc, char *argv[])
dec ? NULL : "Please confirm passphrase", 1)) dec ? NULL : "Please confirm passphrase", 1))
exit(1); exit(1);
} }
uint8_t passhash[32];
sha256string(passhash, passwd);
char buf1[65];
bintohex(buf1, 32, passhash);
printf("Master hex: %s\n", buf1);
uint8_t dk[64]; uint8_t dk[64];
rc = genpass(dk, (uint8_t *)passwd, strlen(passwd), (void*) *argv, rc = genpass(dk, (uint8_t *)passwd, strlen(passwd), (void*) *argv,
@ -103,11 +108,9 @@ main(int argc, char *argv[])
memset(passwd, 0, strlen(passwd)); memset(passwd, 0, strlen(passwd));
free(passwd); free(passwd);
char buf[65]; char buf[129];
for (i = 0; i < 64; i++) { bintohex(buf, 64, dk);
sprintf(buf + i, "%x", dk[i]); printf("Hex passkey: %s\n", buf);
}
printf("Result: %s\n", buf);
/* If we failed, print the right error message and exit. */ /* If we failed, print the right error message and exit. */
if (rc != 0) { if (rc != 0) {