EDGESEC  0.1.0-alpha.0+sha.ca29a8277b72f80785649ea9ef9cd7edf642d939
Secure router - reference implementation
Functions
crypt_service.c File Reference

File containing the implementation of crypt service configuration utilities. More...

#include "crypt_service.h"
#include "crypt_config.h"
#include "generic_hsm_driver.h"
#include "sqlite_crypt_writer.h"
#include "../utils/allocs.h"
#include "../utils/base64.h"
#include "../utils/cryptou.h"
#include "../utils/log.h"
#include "../utils/os.h"
Include dependency graph for crypt_service.c:

Functions

void free_crypt_service (struct crypt_context *ctx)
 Frees the crypt context. More...
 
int generate_user_key (const uint8_t *user_secret, int user_secret_size, uint8_t *user_key, int user_key_size, const uint8_t *user_key_salt, int user_key_salt_size)
 Generates a the key for a user. More...
 
struct secrets_rowprepare_secret_entry (const char *key_id, const uint8_t *key, int key_size, const uint8_t *salt, int salt_size, const uint8_t *iv, int iv_size)
 
int extract_secret_entry (const struct secrets_row *row, uint8_t *key, int *key_size, uint8_t *salt, int *salt_size, uint8_t *iv, int *iv_size)
 Extracts the secret key, salt, and IV from a secret entry. More...
 
int extract_user_crypto_key_entry (struct secrets_row *row_secret, uint8_t *user_secret, int user_secret_size, uint8_t *crypto_key)
 
struct secrets_rowgenerate_user_crypto_key_entry (const char *key_id, const uint8_t *user_secret, int user_secret_size, uint8_t *crypto_key)
 
struct crypt_contextload_crypt_service (const char *crypt_db_path, const char *key_id, uint8_t *user_secret, int user_secret_size)
 Load the crypt service. More...
 
void free_crypt_pair (struct crypt_pair *pair)
 Frees the crypt pair. More...
 
struct crypt_pairget_crypt_pair (struct crypt_context *ctx, const char *key)
 Retrieves a key/value pair from the crypt. More...
 
int put_crypt_pair (struct crypt_context *ctx, struct crypt_pair *pair)
 Inserts a key/value pair into the crypt. More...
 

Detailed Description

File containing the implementation of crypt service configuration utilities.

Author
Alexandru Mereacre
Date
2021

Function Documentation

◆ extract_secret_entry()

int extract_secret_entry ( const struct secrets_row row,
uint8_t *  key,
int *  key_size,
uint8_t *  salt,
int *  salt_size,
uint8_t *  iv,
int *  iv_size 
)

Extracts the secret key, salt, and IV from a secret entry.

Parameters
rowThe row to extract the data from.
[out]keyThe output secret key buffer.
key_sizeThe size of key.
[out]saltThe output secret salt buffer.
salt_sizeThe size of salt.
[out]ivThe output IV buffer.
iv_sizeThe size of iv.
Return values
0On success.
-1On error.

◆ extract_user_crypto_key_entry()

int extract_user_crypto_key_entry ( struct secrets_row row_secret,
uint8_t *  user_secret,
int  user_secret_size,
uint8_t *  crypto_key 
)

◆ free_crypt_pair()

void free_crypt_pair ( struct crypt_pair pair)

Frees the crypt pair.

Parameters
pairThe crypt pair

◆ free_crypt_service()

void free_crypt_service ( struct crypt_context ctx)

Frees the crypt context.

Parameters
ctxThe crypt context

◆ generate_user_crypto_key_entry()

struct secrets_row* generate_user_crypto_key_entry ( const char *  key_id,
const uint8_t *  user_secret,
int  user_secret_size,
uint8_t *  crypto_key 
)

◆ generate_user_key()

int generate_user_key ( const uint8_t *  user_secret,
int  user_secret_size,
uint8_t *  user_key,
int  user_key_size,
const uint8_t *  user_key_salt,
int  user_key_salt_size 
)

Generates a the key for a user.

Parameters
user_secretSecret bytes.
user_secret_sizeSize of user_secret.
[out]user_keyOutput buffer for the generated key.
user_key_sizeSize of user_key
user_key_saltSalt bytes.
user_key_salt_sizeSize of user_key_salt_size
Return values
0On success.
-1On error.

◆ get_crypt_pair()

struct crypt_pair* get_crypt_pair ( struct crypt_context ctx,
const char *  key 
)

Retrieves a key/value pair from the crypt.

Parameters
ctxThe crypt context
keyThe key string
Returns
struct crypt_pair* The returned pair, NULL on failure

◆ load_crypt_service()

struct crypt_context* load_crypt_service ( const char *  crypt_db_path,
const char *  key_id,
uint8_t *  user_secret,
int  user_secret_size 
)

Load the crypt service.

Parameters
crypt_db_pathThe crypt db path
key_idThe crypt secrets key id
[in,out]user_secretThe user secret. If creating a new key, the user secret will be loaded from this variable. If loading an existing key, the existing key will be writen to the buffer.
user_secret_sizeThe user secret size, if zero use the hardware secure element
Returns
The crypt contex, NULL on failure. Use free_crypt_service() to deallocate.

◆ prepare_secret_entry()

struct secrets_row* prepare_secret_entry ( const char *  key_id,
const uint8_t *  key,
int  key_size,
const uint8_t *  salt,
int  salt_size,
const uint8_t *  iv,
int  iv_size 
)

◆ put_crypt_pair()

int put_crypt_pair ( struct crypt_context ctx,
struct crypt_pair pair 
)

Inserts a key/value pair into the crypt.

Parameters
ctxThe crypt context
pairThe key/value pair
Returns
0 on success, -1 on failure