Question

I've been looking for about a week to find an example of something in C that would work as the 'turn this password into properly hashed form for storage' using either the BSAFE or openssl crypto libraries, generating decent salt and doing a arguably adequate number of rounds.

Does anyone know of an example from which to crib? I'm lazy enough to prefer not to have to figure it all out myself the hard way, as this is a small (but key) part of another project.

thanks -dB

Was it helpful?

Solution

I will demo how to use openssl api to generate the hash.

#include <openssl/evp.h>

// more ITERATIONs, more secure. But you should consider the performance on your target machine
ITERATION = 512000; 

// this will be the result of PBKDF2-HMAC-SHA1  
int SHA1_LEN = 20;
unsigned char* out = (unsigned char*)calloc(SHA1_LEN, sizeof(unsigned char));

int SALT_LEN = 5;
unsigned char* salt = (unsigned char*)calloc(SALT_LEN, sizeof(unsigned char));
RAND_bytes(salt, SALT_LEN);

pwd = ""; /*your password here */
PKCS5_PBKDF2_HMAC_SHA1(pwd, strlen(pwd), salt_value, SALT_LEN, ITERATION, SHA1_LEN, out);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top