Contiki-NG
Loading...
Searching...
No Matches
edhoc-key-storage.c File Reference

edhoc-key-storage an implementation of a key storage to keep the ECC authentication keys to work with. More...

#include "edhoc-key-storage.h"
#include "edhoc-error.h"
#include "contiki.h"
#include "contiki-lib.h"
#include <string.h>
#include "sys/log.h"

Go to the source code of this file.

Functions

edhoc_error_t edhoc_create_key_list (void)
 Create the keys repository.
edhoc_error_t edhoc_check_key_list_identity (char *identity, uint8_t identity_size, cose_key_t **authentication_key)
 Check in the keys repository for the key with the specific identity.
edhoc_error_t edhoc_check_key_list_kid (uint8_t *key_id, uint8_t key_id_size, cose_key_t **authentication_key)
 Check in the keys repository for the key with the specific KID.
edhoc_error_t edhoc_add_key (cose_key_t *key)
 Add a DH key to the repository.
edhoc_error_t edhoc_copy_key (cose_key_t *k, cose_key_t *key)
 Copy a COSE key from one structure to another.
edhoc_error_t edhoc_remove_key_kid (uint8_t *kid, uint8_t kid_sz)
 Remove from the keys repository the key with the specific KID.
edhoc_error_t edhoc_remove_key_identity (char *identity, uint8_t identity_sz)
 Remove from the keys repository the key with the specific identity.
edhoc_error_t edhoc_remove_key (cose_key_t *auth_key)
 Remove from the keys repository the specific DH cose_key_t key.
void cose_print_key (cose_key_t *cose)
 Print a key in cose_key_t struct format for debugging.
void edhoc_print_key_info (const cose_key_t *key, const char *label)
 Print detailed key information at INFO level for user visibility.
void edhoc_print_credential (const char *label, const uint8_t *cred, size_t cred_sz)
 Print credential (CRED_I/CRED_R) values in readable format.
uint8_t edhoc_get_key_count (void)
 Get the total number of keys loaded in the key storage.
void edhoc_list_all_keys (void)
 List all keys in the key storage with basic information.
edhoc_error_t edhoc_validate_key_setup (void)
 Validate the current key setup and print diagnostic information.
edhoc_error_t edhoc_setup_key_pair (cose_key_t *own_key, cose_key_t *peer_key, const char *own_label, const char *peer_label)
 Helper function to set up a key pair (own + peer) with validation.

Detailed Description

edhoc-key-storage an implementation of a key storage to keep the ECC authentication keys to work with.

Author
Lidia Pocero pocer.nosp@m.o@is.nosp@m.i.gr, Rikard Höglund, Marco Tiloca

Definition in file edhoc-key-storage.c.

Function Documentation

◆ cose_print_key()

void cose_print_key ( cose_key_t * cose)

Print a key in cose_key_t struct format for debugging.

Parameters
coseInput cose_key_t struct

Definition at line 193 of file edhoc-key-storage.c.

Referenced by edhoc_generate_message_3().

◆ edhoc_add_key()

edhoc_error_t edhoc_add_key ( cose_key_t * key)

Add a DH key to the repository.

Parameters
keyInput key to add in cose_key_t format

Adds a new key to the repository in the form of a cose_key_t struct.

Returns
EDHOC_SUCCESS on success, error code on failure

Definition at line 108 of file edhoc-key-storage.c.

References edhoc_check_key_list_kid(), EDHOC_ERR_DUPLICATE_KEY, EDHOC_ERR_MEMORY_ALLOCATION, EDHOC_ERR_NULL_POINTER, list_add(), and memb_alloc().

Referenced by edhoc_setup_key_pair().

◆ edhoc_check_key_list_identity()

edhoc_error_t edhoc_check_key_list_identity ( char * identity,
uint8_t identity_sz,
cose_key_t ** auth_key )

Check in the keys repository for the key with the specific identity.

Parameters
identityInput key identity
identity_szInput key identity length
auth_keyOutput cose_key_t key that corresponds to the identity
Returns
EDHOC_SUCCESS if found, EDHOC_ERR_KEY_NOT_FOUND if not found, other error code on failure

This function checks the repository and returns a DH cose_key_t key that is associated with the requested identity if it exists.

Definition at line 63 of file edhoc-key-storage.c.

References EDHOC_ERR_INVALID_LENGTH, EDHOC_ERR_KEY_NOT_FOUND, EDHOC_ERR_NULL_POINTER, EDHOC_MAX_IDENTITY_LEN, list_head(), and list_item_next().

Referenced by edhoc_get_own_auth_key(), and edhoc_remove_key_identity().

◆ edhoc_check_key_list_kid()

edhoc_error_t edhoc_check_key_list_kid ( uint8_t * kid,
uint8_t kid_sz,
cose_key_t ** auth_key )

Check in the keys repository for the key with the specific KID.

Parameters
kidInput Key Identification
kid_szInput Key Identification length
auth_keyOutput cose_key_t key that corresponds to the KID
Returns
EDHOC_SUCCESS if found, EDHOC_ERR_KEY_NOT_FOUND if not found, other error code on failure

This function checks the repository and returns a DH cose_key_t key that is associated with the requested KID if it exists.

Definition at line 86 of file edhoc-key-storage.c.

References EDHOC_ERR_INVALID_LENGTH, EDHOC_ERR_KEY_NOT_FOUND, EDHOC_ERR_NULL_POINTER, list_head(), and list_item_next().

Referenced by edhoc_add_key(), edhoc_get_auth_key_from_kid(), edhoc_get_own_auth_key(), and edhoc_remove_key_kid().

◆ edhoc_copy_key()

edhoc_error_t edhoc_copy_key ( cose_key_t * k,
cose_key_t * key )

Copy a COSE key from one structure to another.

Parameters
kThe destination where the COSE key will be copied
keyThe source COSE key to be copied

This function copies the contents of the COSE key structure from the source (key) to the destination (k). The entire structure is copied using memcpy.

Returns
EDHOC_SUCCESS on success, error code on failure

Definition at line 136 of file edhoc-key-storage.c.

References EDHOC_ERR_NULL_POINTER.

◆ edhoc_create_key_list()

edhoc_error_t edhoc_create_key_list ( void )

Create the keys repository.

Create a repository of keys in the form of a list

Returns
EDHOC_SUCCESS on success, error code on failure

Definition at line 55 of file edhoc-key-storage.c.

References list_init(), and memb_init().

◆ edhoc_get_key_count()

uint8_t edhoc_get_key_count ( void )

Get the total number of keys loaded in the key storage.

Returns
The number of keys currently stored

Definition at line 264 of file edhoc-key-storage.c.

References count, list_head(), and list_item_next().

Referenced by edhoc_validate_key_setup().

◆ edhoc_print_credential()

void edhoc_print_credential ( const char * label,
const uint8_t * cred,
size_t cred_sz )

Print credential (CRED_I/CRED_R) values in readable format.

Parameters
labelA descriptive label for the credential (e.g., "CRED_I", "CRED_R")
credThe credential bytes to print
cred_szThe size of the credential

Definition at line 244 of file edhoc-key-storage.c.

Referenced by edhoc_generate_message_2(), and edhoc_generate_message_3().

◆ edhoc_print_key_info()

void edhoc_print_key_info ( const cose_key_t * key,
const char * label )

Print detailed key information at INFO level for user visibility.

Parameters
keyThe COSE key to print
labelA descriptive label for the key (e.g., "Client", "Server")

Definition at line 212 of file edhoc-key-storage.c.

◆ edhoc_remove_key()

edhoc_error_t edhoc_remove_key ( cose_key_t * auth_key)

Remove from the keys repository the specific DH cose_key_t key.

Parameters
auth_keyInput key to remove from the repository

This function deletes from the repository the DH cose_key_t key pointed to by the auth_key parameter.

Returns
EDHOC_SUCCESS on success, error code on failure

Definition at line 181 of file edhoc-key-storage.c.

References EDHOC_ERR_NULL_POINTER, list_remove(), and memb_free().

◆ edhoc_remove_key_identity()

edhoc_error_t edhoc_remove_key_identity ( char * identity,
uint8_t identity_sz )

Remove from the keys repository the key with the specific identity.

Parameters
identityInput key identity
identity_szInput key identity length
Returns
EDHOC_SUCCESS if removed, EDHOC_ERR_KEY_NOT_FOUND if not found, other error code on failure

This function deletes from the repository the DH cose_key_t key that is associated with the identity if it exists.

Definition at line 164 of file edhoc-key-storage.c.

References edhoc_check_key_list_identity(), EDHOC_ERR_NULL_POINTER, list_remove(), and memb_free().

◆ edhoc_remove_key_kid()

edhoc_error_t edhoc_remove_key_kid ( uint8_t * kid,
uint8_t kid_sz )

Remove from the keys repository the key with the specific KID.

Parameters
kidInput Key Identification
kid_szInput Key Identification length
Returns
EDHOC_SUCCESS if removed, EDHOC_ERR_KEY_NOT_FOUND if not found, other error code on failure

This function deletes from the repository the DH cose_key_t key that is associated with the KID if it exists.

Definition at line 147 of file edhoc-key-storage.c.

References edhoc_check_key_list_kid(), EDHOC_ERR_NULL_POINTER, list_remove(), and memb_free().

◆ edhoc_setup_key_pair()

edhoc_error_t edhoc_setup_key_pair ( cose_key_t * own_key,
cose_key_t * peer_key,
const char * own_label,
const char * peer_label )

Helper function to set up a key pair (own + peer) with validation.

Parameters
own_keyThe key for own identity (with private key)
peer_keyThe key for peer identity (public only)
own_labelDescriptive label for own key
peer_labelDescriptive label for peer key
Returns
EDHOC_SUCCESS if setup successful, error code otherwise

Definition at line 342 of file edhoc-key-storage.c.

References edhoc_add_key(), EDHOC_ERR_NULL_POINTER, and edhoc_error_string().

◆ edhoc_validate_key_setup()

edhoc_error_t edhoc_validate_key_setup ( void )

Validate the current key setup and print diagnostic information.

Returns
EDHOC_SUCCESS if validation passes, error code otherwise

Definition at line 293 of file edhoc-key-storage.c.

References EDHOC_ERR_KEY_NOT_FOUND, edhoc_get_key_count(), edhoc_list_all_keys(), list_head(), and list_item_next().