Bug fixes in display code
This commit is contained in:
parent
a3b016ceed
commit
5a3a8506fc
3 changed files with 34 additions and 9 deletions
|
@ -141,13 +141,32 @@ checkparams(uint32_t maxmem, uint32_t megaops,
|
|||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
getsalt(uint8_t salt[32], void* site)
|
||||
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
|
||||
sha256string(uint8_t hash[32], char* s)
|
||||
{
|
||||
SHA256_CTX sha256_ctx;
|
||||
SHA256_Init(&sha256_ctx);
|
||||
SHA256_Update(&sha256_ctx, site, strlen(site));
|
||||
SHA256_Final(salt, &sha256_ctx);
|
||||
SHA256_Update(&sha256_ctx, (void*) s, strlen(s));
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -71,6 +71,9 @@
|
|||
* 12 error writing output 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],
|
||||
const uint8_t * passwd, size_t passwdlen, void* site,
|
||||
|
|
13
main.c
13
main.c
|
@ -94,6 +94,11 @@ main(int argc, char *argv[])
|
|||
dec ? NULL : "Please confirm passphrase", 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];
|
||||
rc = genpass(dk, (uint8_t *)passwd, strlen(passwd), (void*) *argv,
|
||||
|
@ -103,11 +108,9 @@ main(int argc, char *argv[])
|
|||
memset(passwd, 0, strlen(passwd));
|
||||
free(passwd);
|
||||
|
||||
char buf[65];
|
||||
for (i = 0; i < 64; i++) {
|
||||
sprintf(buf + i, "%x", dk[i]);
|
||||
}
|
||||
printf("Result: %s\n", buf);
|
||||
char buf[129];
|
||||
bintohex(buf, 64, dk);
|
||||
printf("Hex passkey: %s\n", buf);
|
||||
|
||||
/* If we failed, print the right error message and exit. */
|
||||
if (rc != 0) {
|
||||
|
|
Reference in a new issue