-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sys/psa_crypto: implement persistent key storage
- Loading branch information
1 parent
e51dc09
commit 3392b68
Showing
15 changed files
with
1,231 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
/* | ||
* Copyright (C) 2023 HAW Hamburg | ||
* | ||
* This file is subject to the terms and conditions of the GNU Lesser | ||
* General Public License v2.1. See the file LICENSE in the top level | ||
* directory for more details. | ||
*/ | ||
|
||
/** | ||
* @ingroup sys_psa_crypto | ||
* @defgroup sys_psa_crypto_cbor_encoder Module for encoding PSA keys in CBOR | ||
* @{ | ||
* | ||
* @file psa_crypto_cbor_encoder.h | ||
* @brief | ||
* | ||
* @author Lena Boeckmann <lena.boeckmann@haw-hamburg.de> | ||
* | ||
*/ | ||
|
||
#ifndef PSA_CRYPTO_CBOR_ENCODER_H | ||
#define PSA_CRYPTO_CBOR_ENCODER_H | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#include "psa_crypto_slot_management.h" | ||
|
||
/** | ||
* @brief Encodes a basic key slot in CBOR | ||
* | ||
* Single Key Format: | ||
* - Key Slot Array: | ||
* - Attributes Array[5]: | ||
* - ID (First bytes are always ID for quick lookup) | ||
* - Type | ||
* - Bits | ||
* - Lifetime | ||
* - Policy Array[2]: | ||
* - Usage | ||
* - Algorithm | ||
* - Key Array[2] | ||
* - Key Length | ||
* - Key Data Array[slot->key.data_len] | ||
* - Key Data | ||
* | ||
* Asymmetric Key Pair Format: | ||
* - Key Slot Array: | ||
* - Attributes Array[5]: | ||
* - ID (First bytes are always ID for quick lookup) | ||
* - Type | ||
* - Bits | ||
* - Lifetime | ||
* - Policy Array[2]: | ||
* - Usage | ||
* - Algorithm | ||
* - Key Pair Array[2]: | ||
* - Private Key Array[2] | ||
* - Private Key Data Length | ||
* - Private Key Data Array[slot->key.data_len] | ||
* - Private Key Data | ||
* - Public Key Array[2] | ||
* - Public Key Length | ||
* - Public Key Array[pubkey_data_len] | ||
* - Public Key Data | ||
* | ||
* Protected Key Format: | ||
* - Key Slot Array: | ||
* - ID (First bytes are always ID for quick lookup) | ||
* - Type | ||
* - Bits | ||
* - Lifetime | ||
* - Policy Array[2]: | ||
* - Usage | ||
* - Algorithm | ||
* - Prot Key Array[1-2] | ||
* - Key Slot Number | ||
* *optional:* | ||
* - Public Key Array[2] | ||
* - Public Key Len | ||
* - Public Key Array[pubkey_data_len] | ||
* - Public Key Data | ||
* | ||
* @param slot Pointer to slot containing the key to encode | ||
* @param output Buffer to write the encoded key to | ||
* @param output_len Length of output buffer | ||
* @param output_size Pointer to write actual length of encoding | ||
* | ||
* @return psa_status_t | ||
*/ | ||
psa_status_t psa_encode_key_slot(psa_key_slot_t *slot, uint8_t *output, | ||
size_t output_len, size_t *output_size); | ||
|
||
/** | ||
* @brief Decode CBOR encoded key data and write to PSA key slot. Only decodes the key and should | ||
* be called in combination with psa_decode_key_attributes. | ||
* | ||
* @param slot Pointer to key slot to write decoded key to | ||
* @param cbor_buf Buffer containing CBOR encoded data | ||
* @param cbor_buf_size Size of @p cbor_buf | ||
* @return psa_status_t | ||
*/ | ||
psa_status_t psa_decode_key_slot_data(psa_key_slot_t *slot, uint8_t *cbor_buf, | ||
size_t cbor_buf_size); | ||
|
||
/** | ||
* @brief Decode CBOR PSA key attributes. Only decodes key attributes and not the actual key. | ||
* Key can be decoded with psa_decode_key_slot_data. | ||
* | ||
* @param attr Key attribute struct to store decoded attributes | ||
* @param cbor_buf Buffer containing CBOR encoded data | ||
* @param cbor_buf_size Size of @p cbor_buf | ||
* @return psa_status_t | ||
*/ | ||
psa_status_t psa_decode_key_attributes(psa_key_attributes_t *attr, uint8_t *cbor_buf, | ||
size_t cbor_buf_size); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* PSA_CRYPTO_CBOR_ENCODER_H */ | ||
/** @} */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright (C) 2023 HAW Hamburg | ||
* | ||
* This file is subject to the terms and conditions of the GNU Lesser | ||
* General Public License v2.1. See the file LICENSE in the top level | ||
* directory for more details. | ||
*/ | ||
|
||
/** | ||
* @ingroup sys_psa_crypto | ||
* @defgroup sys_psa_crypto_pers_stor PSA Crypto Persistent Storage API | ||
* @{ | ||
* | ||
* @file psa_crypto_persistent_storage.h | ||
* @brief | ||
* | ||
* @author Lena Boeckmann <lena.boeckmann@haw-hamburg.de> | ||
* | ||
*/ | ||
|
||
#ifndef PSA_CRYPTO_PERSISTENT_STORAGE_H | ||
#define PSA_CRYPTO_PERSISTENT_STORAGE_H | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#include "psa/crypto.h" | ||
|
||
/** | ||
* @brief Writes a CBOR encoded key slot to a file | ||
* | ||
* @param id ID of slot, used as filename | ||
* @param cbor_buf Pointer to CBOR encoded data | ||
* @param cbor_buf_len Length of CBOR encoded data | ||
* @return psa_status_t | ||
*/ | ||
psa_status_t psa_write_cbor_encoded_key_slot_to_file(psa_key_id_t id, | ||
uint8_t* cbor_buf, | ||
size_t cbor_buf_len); | ||
|
||
/** | ||
* @brief Reads a CBOR encoded key slot from a file | ||
* | ||
* @param id ID of the desired key | ||
* @param cbor_buf Output buffer to write CBOR data to | ||
* @param cbor_buf_size Size of output buffer | ||
* @param cbor_data_len Actual length of CBOR encoded data | ||
* @return psa_status_t | ||
*/ | ||
psa_status_t psa_get_cbor_encoded_key_slot_from_file(psa_key_id_t id, | ||
uint8_t *cbor_buf, | ||
size_t cbor_buf_size, | ||
size_t *cbor_data_len); | ||
|
||
/** | ||
* @brief Destroy a key in persistent storage | ||
* | ||
* @param key_id ID of the key to be destroyed | ||
* @return psa_status_t | ||
*/ | ||
psa_status_t psa_destroy_persistent_key(psa_key_id_t key_id); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* PSA_CRYPTO_PERSISTENT_STORAGE_H */ | ||
/** @} */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.