Greenbone Vulnerability Management Libraries 22.30.0
passwordbasedauthentication.c File Reference
#include "passwordbasedauthentication.h"
#include "authutils.c"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <crypt.h>

Go to the source code of this file.

Macros

#define __USE_GNU
#define INVALID_HASH   "1234567890$"
#define CRYPT_GENSALT_OUTPUT_SIZE   192
#define CRYPT_OUTPUT_SIZE   384

Functions

static int is_prefix_supported (const char *id)
 Check if a prefix is supported.
static int get_random (char *buf, size_t buflen)
 Try to get random bytes.
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.
struct PBASettingspba_init (const char *pepper, unsigned int pepper_size, unsigned int count, char *prefix)
 Init PBA.
void pba_finalize (struct PBASettings *settings)
 Cleanup PBA settings.
static int pba_is_phc_compliant (const char *setting)
 Check if a PBA settings is PHC compliant.
char * pba_hash (struct PBASettings *setting, const char *password)
 Create a password hash.
enum pba_rc pba_verify_hash (const struct PBASettings *setting, const char *hash, const char *password)
 Verify a password hash.

Variables

const char ascii64 []

Macro Definition Documentation

◆ __USE_GNU

#define __USE_GNU

◆ CRYPT_GENSALT_OUTPUT_SIZE

#define CRYPT_GENSALT_OUTPUT_SIZE   192

◆ CRYPT_OUTPUT_SIZE

#define CRYPT_OUTPUT_SIZE   384

◆ INVALID_HASH

#define INVALID_HASH   "1234567890$"

Function Documentation

◆ crypt_gensalt_r()

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.

If prefix is a NULL pointer, the current best default is used; if rbytes is a NULL pointer, random data will be retrieved from the operating system if possible.

Parameters
[in]prefixControls which hash function will be used.
[in]countControls the computional cost of the hash.
[in]rbytesShould point to nrbytes bytes of random data.
[in]nrbytesNumber of bytes in rbytes.
[out]outputThe generated setting string is written here.
[in]output_sizeLength of output. Must be at least CRYPT_GENSALT_OUTPUT_SIZE.
Returns
On success output, else NULL.

◆ get_random()

int get_random ( char * buf,
size_t buflen )
static

Try to get random bytes.

Parameters
[in]bufDestination for bytes.
[in]buflenNumber of bytes to get.
Returns
0 on success, else error.

◆ is_prefix_supported()

int is_prefix_supported ( const char * id)
static

Check if a prefix is supported.

Parameters
[in]idPrefix.
Returns
1 if supported, else 0.

◆ pba_finalize()

void pba_finalize ( struct PBASettings * settings)

Cleanup PBA settings.

Parameters
[in]settingsPBA settings.

◆ pba_hash()

char * pba_hash ( struct PBASettings * setting,
const char * password )

Create a password hash.

Parameters
[in]settingPBA settings.
[in]passwordPassword.
Returns
Hash. Must be freed with free().

◆ pba_init()

struct PBASettings * pba_init ( const char * pepper,
unsigned int pepper_size,
unsigned int count,
char * prefix )

Init PBA.

Parameters
[in]pepperA static hidden addition to the randomly generated salt.
[in]pepper_sizeThe size of pepper; it must not be larger than MAX_PEPPER_SIZE.
[in]countNumber of rounds used to calculate the hash. 0 to use COUNT_DEFAULT.
[in]prefixThe algorithm used, if NULL then the most secure available algorithm will be used.
Returns
Settings, or NULL on error. Free with pba_finalize.

◆ pba_is_phc_compliant()

int pba_is_phc_compliant ( const char * setting)
static

Check if a PBA settings is PHC compliant.

Parameters
[in]settingSetting.
Returns
1 if compliant, else 0.

◆ pba_verify_hash()

enum pba_rc pba_verify_hash ( const struct PBASettings * setting,
const char * hash,
const char * password )

Verify a password hash.

Parameters
[in]settingPBA settings.
[in]hashHash.
[in]passwordPassword.
Returns
Validity. VALID, UPDATE_RECOMMENDED, ...

Variable Documentation

◆ ascii64

const char ascii64[]
Initial value:
=
"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"