42 static char salt_charset[] =
43 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./";
45 ASSERT(strlen(salt_charset) == 64);
51 #if defined(HAVE_DEV_RANDOM) || defined(HAVE_DEV_URANDOM)
54 #if defined(HAVE_DEV_RANDOM)
55 fin = fopen(
"/dev/random");
56 #elif defined(HAVE_DEV_URANDOM)
57 fin = fopen(
"/dev/urandom");
64 for (
unsigned int i = 0; i <
STRLENOF(buf); i++) {
65 buf[i] = salt_charset[buf[i] %
STRLENOF(salt_charset)];
68 for (
unsigned int i = 0; i <
STRLENOF(buf); i++) {
69 buf[i] = salt_charset[rand() %
STRLENOF(salt_charset)];
74 snprintf(salt, saltlen, salt_format, buf);
76 strncpy(salt, buf, saltlen);
#define ASSERT(expression)
char * mbdyn_make_salt(char *salt, size_t saltlen, const char *salt_format)
static doublereal buf[BUFSIZE]