SecurePasswd_MGMT 2026.03.19
A modern, cross-platform password manager and two-factor authenticator (TOTP) designed with state-of-the-art security.
Loading...
Searching...
No Matches
key_derivation.c File Reference
#include "key_derivation.h"
#include <argon2.h>
#include <sodium.h>
#include <stdio.h>
#include <string.h>
Include dependency graph for key_derivation.c:

Macros

#define MEMORY_COST   (1 << 17)
#define TIME_COST   3
#define PARALLELISM   1

Functions

int derive_key (const char *password, const uint8_t *salt, uint8_t *key)
 Derives a key from a password and salt using Argon2id.
int load_or_generate_salt (const char *path, uint8_t *salt)
 Loads the salt from the specified path, or generates a new one if it doesn't exist.
int save_salt (const char *path, const uint8_t *salt)
 Saves the salt to the specified path.

Macro Definition Documentation

◆ MEMORY_COST

#define MEMORY_COST   (1 << 17)

◆ PARALLELISM

#define PARALLELISM   1

◆ TIME_COST

#define TIME_COST   3

Function Documentation

◆ derive_key()

int derive_key ( const char * password,
const uint8_t * salt,
uint8_t * key )

Derives a key from a password and salt using Argon2id.

Parameters
passwordThe password to derive the key from.
saltThe salt to use for key derivation.
keyThe buffer to store the derived key in. Must be KEY_LEN bytes.
Returns
0 on success, -1 on error.

◆ load_or_generate_salt()

int load_or_generate_salt ( const char * path,
uint8_t * salt )

Loads the salt from the specified path, or generates a new one if it doesn't exist.

Parameters
pathThe path to the salt file.
saltThe buffer to store the loaded or generated salt in. Must be SALT_LEN bytes.
Returns
0 on success, -1 on error.

◆ save_salt()

int save_salt ( const char * path,
const uint8_t * salt )

Saves the salt to the specified path.

Parameters
pathThe path to the salt file.
saltThe salt to save. Must be SALT_LEN bytes.
Returns
0 on success, -1 on error.