Create salt using SHA256 of site name

This commit is contained in:
Chris Oei 2012-09-02 22:08:52 -07:00
parent 87ba1c22e9
commit d8d6735872
3 changed files with 12 additions and 20 deletions

View file

@ -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]); static int getsalt(uint8_t[32], void* site);
static int static int
pickparams(uint32_t maxmem, uint32_t megaops, pickparams(uint32_t maxmem, uint32_t megaops,
@ -142,26 +142,18 @@ checkparams(uint32_t maxmem, uint32_t megaops,
} }
static int static int
getsalt(uint8_t salt[32]) getsalt(uint8_t salt[32], void* site)
{ {
uint8_t randomdata[32] = { SHA256_CTX sha256_ctx;
0x67, 0x18, 0x53, 0x16 , 0xdc, 0x1e, 0x95, 0xd2, SHA256_Init(&sha256_ctx);
0x78, 0x49, 0xc3, 0x99, 0xe6, 0x6f, 0x07, 0xc1, SHA256_Update(&sha256_ctx, site, strlen(site));
0xa7, 0x0d, 0x02, 0x07, 0x0f, 0x24, 0xbb, 0xfa, SHA256_Final(salt, &sha256_ctx);
0xf5, 0xb5, 0x42, 0x72, 0x94, 0x9b, 0x35, 0xa6
};
int i;
for (i = 0; i < 32; i++)
salt[i] = randomdata[i];
/* Success! */
return (0); return (0);
} }
int int
genpass(uint8_t dk[64], genpass(uint8_t dk[64],
const uint8_t * passwd, size_t passwdlen, const uint8_t * passwd, size_t passwdlen, void* site,
uint32_t maxmem, uint32_t megaops) uint32_t maxmem, uint32_t megaops)
{ {
uint8_t salt[32]; uint8_t salt[32];
@ -181,8 +173,8 @@ genpass(uint8_t dk[64],
return (rc); return (rc);
N = (uint64_t)(1) << logN; N = (uint64_t)(1) << logN;
/* Get some salt. */ /* Get some salt using the site. */
if ((rc = getsalt(salt)) != 0) if ((rc = getsalt(salt, site)) != 0)
return (rc); return (rc);
/* Generate the derived keys. */ /* Generate the derived keys. */

View file

@ -73,7 +73,7 @@
*/ */
int genpass(uint8_t dk[64], int genpass(uint8_t dk[64],
const uint8_t * passwd, size_t passwdlen, const uint8_t * passwd, size_t passwdlen, void* site,
uint32_t maxmem, uint32_t megaops); uint32_t maxmem, uint32_t megaops);
#endif /* !_GENPASS_H_ */ #endif /* !_GENPASS_H_ */

4
main.c
View file

@ -91,8 +91,8 @@ main(int argc, char *argv[])
exit(1); exit(1);
uint8_t dk[64]; uint8_t dk[64];
rc = genpass(dk, (uint8_t *)passwd, rc = genpass(dk, (uint8_t *)passwd, strlen(passwd), (void*) *argv,
strlen(passwd), maxmem, megaops); maxmem, megaops);
/* Zero and free the password. */ /* Zero and free the password. */
memset(passwd, 0, strlen(passwd)); memset(passwd, 0, strlen(passwd));