Greenbone Vulnerability Management Libraries: util/passwordbasedauthentication.c File Reference

Greenbone Vulnerability Management Libraries 23.7.0

Macros | Functions | Variables
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 PBASettings * | pba_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] | prefix | Controls which hash function will be used.
  [in] | count | Controls the computional cost of the hash.
  [in] | rbytes | Should point to nrbytes bytes of random data.
  [in] | nrbytes | Number of bytes in rbytes.
  [out] | output | The generated setting string is written here.
  [in] | output_size | Length 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] | buf | Destination for bytes.
  [in] | buflen | Number 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] | id | Prefix.

Returns
  1 if supported, else 0.

## ◆ pba_finalize()

void pba_finalize | ( | struct PBASettings * | settings | ) |

Cleanup PBA settings.

Parameters

  [in] | settings | PBA settings.

## ◆ pba_hash()

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

Create a password hash.

Parameters

  [in] | setting | PBA settings.
  [in] | password | Password.

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] | pepper | A static hidden addition to the randomly generated salt.
  [in] | pepper_size | The size of pepper; it must not be larger than MAX_PEPPER_SIZE.
  [in] | count | Number of rounds used to calculate the hash. 0 to use COUNT_DEFAULT.
  [in] | prefix | The 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] | setting | Setting.

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] | setting | PBA settings.
  [in] | hash | Hash.
  [in] | password | Password.

Returns
  Validity. VALID, UPDATE_RECOMMENDED, ...

## Variable Documentation

## ◆ ascii64

const char ascii64[]

Initial value:
=
"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"