1) Nothing will create the data array using crypt_gensalt
. Why? crypt_gensalt
returns a pointer to the setting
string that is passed to the crypt
function itself. If you want to store the value returned by crypt_gensalt
, you must copy the string pointed to by the return to data manually. There is a separate function however, crypt_gensalt_rn
that will fill a character array for you. See man 3 crypt_gensalt
for details. The declaration from the man page is:
char *crypt_gensalt_rn (const char *prefix, unsigned long count,
const char *input, int size, char *output,
int output_size);
which allowed providing your character array as 'output'
to be filled by the function as opposed to returning a pointer to it alone.
You should not include 10
in your prefix
, "$2a$"
is proper (but see note for "$2y$"
below). The count is added by crypt_gensalt
and is part of the setting
string it returns. Your input
string should match the format:
const char *input = "\$2[axy]\$[0-9]{2}\$[./A-Za-z0-9]{53}";
note: you should use "$2y$"
as the prefix, instead of "$2a$"
as of version 1.2 of the library. e.g. "Version 1.2 adds support for the $2y$
prefix (denoting correctly computed hashes) and a countermeasure to avoid one-correct to many-buggy hash collisions with the $2a$
prefix" See: Openwall Site - Modern password hashing
2) The count in the prefix is the additional number of times the salt generation algorithm is run beyond the default. (if set to 0
, the default is used).
3) The purpose is that crypt_gensalt
returns a pointer to a null-terminated string formatted to be used as setting
in the crypt
function call:
char *crypt(const char *key, const char *setting);