22#define INVALID_HASH "1234567890$"
23#ifndef CRYPT_GENSALT_OUTPUT_SIZE
24#define CRYPT_GENSALT_OUTPUT_SIZE 192
27#ifndef CRYPT_OUTPUT_SIZE
28#define CRYPT_OUTPUT_SIZE 384
48#ifndef EXTERNAL_CRYPT_GENSALT_R
52 "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
65 FILE *fp = fopen (
"/dev/urandom",
"r");
72 size_t nread = fread (buf, 1, buflen, fp);
101crypt_gensalt_r (
const char *prefix,
unsigned long count,
const char *rbytes,
102 int nrbytes,
char *output,
int output_size);
105 int nrbytes,
char *output,
int output_size)
107 char *internal_rbytes = NULL;
108 unsigned int written = 0, used = 0;
109 unsigned long value = 0;
110 if ((rbytes != NULL && nrbytes < 3) || output_size < 16
118 internal_rbytes = malloc (16);
125 rbytes = internal_rbytes;
127 written = snprintf (output, output_size,
"%srounds=%lu$",
129 while (written + 5 < (
unsigned int) output_size
130 && used + 3 < (
unsigned int) nrbytes && (used * 4 / 3) < 16)
132 value = ((
unsigned long) rbytes[used + 0] << 0)
133 | ((
unsigned long) rbytes[used + 1] << 8)
134 | ((
unsigned long) rbytes[used + 2] << 16);
135 output[written] =
ascii64[value & 0x3f];
136 output[written + 1] =
ascii64[(value >> 6) & 0x3f];
137 output[written + 2] =
ascii64[(value >> 12) & 0x3f];
138 output[written + 3] =
ascii64[(value >> 18) & 0x3f];
142 output[written] =
'\0';
144 if (internal_rbytes != NULL)
145 free (internal_rbytes);
146 return output[0] ==
'*' ? 0 : output;
208 return strlen (setting) > 1 && setting[0] ==
'$';
222 char *result = NULL, *settings = NULL, *tmp, *rslt;
224 struct crypt_data *data = NULL;
226 if (!setting || !password)
235 tmp = settings + strlen (settings) - 1;
238 if (setting->
pepper[i] != 0)
239 tmp[0] = setting->
pepper[i];
243 data = calloc (1,
sizeof (
struct crypt_data));
244 rslt = crypt_r (password, settings, data);
251 tmp = result + (tmp - settings);
255 if (setting->
pepper[i] != 0)
261 if (settings != NULL)
277 const char *password)
279 char *cmp, *tmp = NULL;
280 struct crypt_data *data = NULL;
295 hash_size = hash ? strlen (hash) : strlen (invalid_hash);
297 data = calloc (1,
sizeof (
struct crypt_data));
302 memcpy (tmp, hash ? hash : invalid_hash,
305 cmp = strrchr (tmp,
'$');
309 if (setting->
pepper[i] != 0)
310 cmp[0] = setting->
pepper[i];
315 cmp = crypt_r (password ? password :
"", tmp, data);
316 if (strcmp (tmp, cmp) == 0)
Authentication mechanism(s).
int gvm_authenticate_classic(const gchar *username, const gchar *password, const gchar *hash_arg)
Authenticate a credential pair against user file contents.
Definition authutils.c:274
int gvm_auth_init(void)
Initializes Gcrypt.
Definition authutils.c:109
static gboolean initialized
Flag whether the config file was read.
Definition authutils.c:33
static int pba_is_phc_compliant(const char *setting)
Check if a PBA settings is PHC compliant.
Definition passwordbasedauthentication.c:202
static int get_random(char *buf, size_t buflen)
Try to get random bytes.
Definition passwordbasedauthentication.c:63
#define INVALID_HASH
Definition passwordbasedauthentication.c:22
const char ascii64[]
Definition passwordbasedauthentication.c:51
char * crypt_gensalt_r(const char *prefix, unsigned long count, const char *rbytes, int nrbytes, char *output, int output_size)
Generate string suitable for use as setting when hashing a passphrase.
Definition passwordbasedauthentication.c:104
void pba_finalize(struct PBASettings *settings)
Cleanup PBA settings.
Definition passwordbasedauthentication.c:189
#define CRYPT_OUTPUT_SIZE
Definition passwordbasedauthentication.c:28
char * pba_hash(struct PBASettings *setting, const char *password)
Create a password hash.
Definition passwordbasedauthentication.c:220
struct PBASettings * pba_init(const char *pepper, unsigned int pepper_size, unsigned int count, char *prefix)
Init PBA.
Definition passwordbasedauthentication.c:165
enum pba_rc pba_verify_hash(const struct PBASettings *setting, const char *hash, const char *password)
Verify a password hash.
Definition passwordbasedauthentication.c:276
#define CRYPT_GENSALT_OUTPUT_SIZE
Definition passwordbasedauthentication.c:24
static int is_prefix_supported(const char *id)
Check if a prefix is supported.
Definition passwordbasedauthentication.c:39
#define COUNT_DEFAULT
Definition passwordbasedauthentication.h:12
pba_rc
Definition passwordbasedauthentication.h:46
@ ERR
Definition passwordbasedauthentication.h:50
@ VALID
Definition passwordbasedauthentication.h:47
@ UPDATE_RECOMMENDED
Definition passwordbasedauthentication.h:48
@ INVALID
Definition passwordbasedauthentication.h:49
#define MAX_PEPPER_SIZE
Definition passwordbasedauthentication.h:10
#define PREFIX_DEFAULT
Definition passwordbasedauthentication.h:14
Definition passwordbasedauthentication.h:23
char pepper[MAX_PEPPER_SIZE]
Definition passwordbasedauthentication.h:24
char * prefix
Definition passwordbasedauthentication.h:26
unsigned int count
Definition passwordbasedauthentication.h:25