library/src/network/httpd/BP-HTTPdUsers.cc
// Attempts to generate a salted hash buffer provided a given password.  Result
// must be free'd.
Attempts to generate a salted hash buffer provided a given password.  Result
must be free'd.
Attempts to generate a salted hash buffer provided a given password . Result must be free ' d .
char * BP_HTTPdUserCreateSaltedHash
(
		BP_HTTPD_USER_PASSWORD_HASH_TYPE hash_type,
		char * salt,
		char * pass
)
{
	if(!hash_type)
		return NULL;
	if(!salt)
		return NULL;
	if(!pass)
		return NULL;
	size_t salted_password_buff_len = bpstrlen(salt)+bpstrlen(pass)+10;
	char *salted_password_buff = (char *) bpcalloc(salted_password_buff_len, 1);
	snprintf(salted_password_buff, bpstrlen(salt) + bpstrlen(pass) + 8, "%s%s", salt, pass);
	char * ret_hash = (char *) NULL;
	switch(hash_type)
	{
		case BP_HTTPD_USER_PASSWORD_HASH_TYPE_MD5:
			ret_hash = BP_GenMD5(salted_password_buff, bpstrlen(salted_password_buff));
			break;
		case BP_HTTPD_USER_PASSWORD_HASH_TYPE_SHA1:
			ret_hash = BP_GenSHA1(salted_password_buff, bpstrlen(salted_password_buff));
			break;
		case BP_HTTPD_USER_PASSWORD_HASH_TYPE_SHA256:
			ret_hash = BP_GenSHA256(salted_password_buff, bpstrlen(salted_password_buff));
			break;
		default:
			break;
	}
	memset(salted_password_buff, 0x00, salted_password_buff_len-1);
	bpfree(salted_password_buff);
	return ret_hash;
}
char * BP_HTTPdUserCreateSaltedHash ( BP_HTTPD_USER_PASSWORD_HASH_TYPE hash_type , char * salt , char * pass ) { if ( ! hash_type ) return NULL ; if ( ! salt ) return NULL ; if ( ! pass ) return NULL ; size_t salted_password_buff_len = bpstrlen ( salt ) + bpstrlen ( pass ) + 10 ; char * salted_password_buff = ( char * ) bpcalloc ( salted_password_buff_len , 1 ) ; snprintf ( salted_password_buff , bpstrlen ( salt ) + bpstrlen ( pass ) + 8 , " " , salt , pass ) ; char * ret_hash = ( char * ) NULL ; switch ( hash_type ) { case BP_HTTPD_USER_PASSWORD_HASH_TYPE_MD5 : ret_hash = BP_GenMD5 ( salted_password_buff , bpstrlen ( salted_password_buff ) ) ; break ; case BP_HTTPD_USER_PASSWORD_HASH_TYPE_SHA1 : ret_hash = BP_GenSHA1 ( salted_password_buff , bpstrlen ( salted_password_buff ) ) ; break ; case BP_HTTPD_USER_PASSWORD_HASH_TYPE_SHA256 : ret_hash = BP_GenSHA256 ( salted_password_buff , bpstrlen ( salted_password_buff ) ) ; break ; default : break ; } memset ( salted_password_buff , 0x00 , salted_password_buff_len - 1 ) ; bpfree ( salted_password_buff ) ; return ret_hash ; }
Attempts to generate a salted hash buffer provided a given password.
Attempts to generate a salted hash buffer provided a given password .
// set the salted password buff length // allocate space for the salted buffer // generate the password buff (with some extra buffer) // the heap allocated hash to return // set password based on hash type // zero out the salted password buffer (prevents it from sitting in memory) // destroy the salted buffer after the hash is calculated // return the buffer