![]() |
Contiki-NG
|
EDHOC key storage - Implementation of key storage for managing DH-static authentication key pairs. More...
#include "contiki.h"#include "contiki-lib.h"#include "ecc-common.h"#include "edhoc-error.h"#include "edhoc-config.h"#include <stdio.h>Go to the source code of this file.
Data Structures | |
| struct | cose_key |
| KEY length in bytes. More... | |
Typedefs | |
| typedef struct cose_key | cose_key_t |
| KEY length in bytes. | |
Functions | |
| edhoc_error_t | edhoc_create_key_list (void) |
| Create the keys repository. | |
| edhoc_error_t | edhoc_add_key (cose_key_t *key) |
| Add a DH key to the repository. | |
| 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. | |
| 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. | |
| 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. | |
| edhoc_error_t | edhoc_copy_key (cose_key_t *k, cose_key_t *key) |
| Copy a COSE key from one structure to another. | |
| 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. | |
EDHOC key storage - Implementation of key storage for managing DH-static authentication key pairs.
Can also be used to store the DH-static authentication public keys of other EDHOC peers.
Definition in file edhoc-key-storage.h.
| void cose_print_key | ( | cose_key_t * | cose | ) |
Print a key in cose_key_t struct format for debugging.
| cose | Input cose_key_t struct |
Definition at line 193 of file edhoc-key-storage.c.
Referenced by edhoc_generate_message_3().
| edhoc_error_t edhoc_add_key | ( | cose_key_t * | key | ) |
Add a DH key to the repository.
| key | Input key to add in cose_key_t format |
Adds a new key to the repository in the form of a cose_key_t struct.
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_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.
| identity | Input key identity |
| identity_sz | Input key identity length |
| auth_key | Output cose_key_t key that corresponds to the identity |
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_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.
| kid | Input Key Identification |
| kid_sz | Input Key Identification length |
| auth_key | Output cose_key_t key that corresponds to the KID |
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_error_t edhoc_copy_key | ( | cose_key_t * | k, |
| cose_key_t * | key ) |
Copy a COSE key from one structure to another.
| k | The destination where the COSE key will be copied |
| key | The 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.
Definition at line 136 of file edhoc-key-storage.c.
References EDHOC_ERR_NULL_POINTER.
| edhoc_error_t edhoc_create_key_list | ( | void | ) |
Create the keys repository.
Create a repository of keys in the form of a list
Definition at line 55 of file edhoc-key-storage.c.
References list_init(), and memb_init().
| uint8_t edhoc_get_key_count | ( | void | ) |
Get the total number of keys loaded in the key storage.
Definition at line 264 of file edhoc-key-storage.c.
References count, list_head(), and list_item_next().
Referenced by edhoc_validate_key_setup().
| 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.
| label | A descriptive label for the credential (e.g., "CRED_I", "CRED_R") |
| cred | The credential bytes to print |
| cred_sz | The 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().
| void edhoc_print_key_info | ( | const cose_key_t * | key, |
| const char * | label ) |
Print detailed key information at INFO level for user visibility.
| key | The COSE key to print |
| label | A descriptive label for the key (e.g., "Client", "Server") |
Definition at line 212 of file edhoc-key-storage.c.
| edhoc_error_t edhoc_remove_key | ( | cose_key_t * | auth_key | ) |
Remove from the keys repository the specific DH cose_key_t key.
| auth_key | Input 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.
Definition at line 181 of file edhoc-key-storage.c.
References EDHOC_ERR_NULL_POINTER, list_remove(), and memb_free().
| edhoc_error_t edhoc_remove_key_identity | ( | char * | identity, |
| uint8_t | identity_sz ) |
Remove from the keys repository the key with the specific identity.
| identity | Input key identity |
| identity_sz | Input key identity length |
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_error_t edhoc_remove_key_kid | ( | uint8_t * | kid, |
| uint8_t | kid_sz ) |
Remove from the keys repository the key with the specific KID.
| kid | Input Key Identification |
| kid_sz | Input Key Identification length |
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_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.
| own_key | The key for own identity (with private key) |
| peer_key | The key for peer identity (public only) |
| own_label | Descriptive label for own key |
| peer_label | Descriptive label for peer key |
Definition at line 342 of file edhoc-key-storage.c.
References edhoc_add_key(), EDHOC_ERR_NULL_POINTER, and edhoc_error_string().
| edhoc_error_t edhoc_validate_key_setup | ( | void | ) |
Validate the current key setup and print diagnostic information.
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().