Darryl Green | db2b8db | 2018-06-15 13:06:04 +0100 | [diff] [blame] | 1 | /** |
| 2 | * \file psa_crypto_storage_backend.h |
| 3 | * |
| 4 | * \brief PSA cryptography module: Mbed TLS key storage backend |
| 5 | */ |
| 6 | /* |
| 7 | * Copyright (C) 2018, ARM Limited, All Rights Reserved |
| 8 | * SPDX-License-Identifier: Apache-2.0 |
| 9 | * |
| 10 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 11 | * not use this file except in compliance with the License. |
| 12 | * You may obtain a copy of the License at |
| 13 | * |
| 14 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 15 | * |
| 16 | * Unless required by applicable law or agreed to in writing, software |
| 17 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 18 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 19 | * See the License for the specific language governing permissions and |
| 20 | * limitations under the License. |
| 21 | * |
| 22 | * This file is part of mbed TLS (https://tls.mbed.org) |
| 23 | */ |
| 24 | |
| 25 | #ifndef PSA_CRYPTO_STORAGE_BACKEND_H |
| 26 | #define PSA_CRYPTO_STORAGE_BACKEND_H |
| 27 | |
| 28 | #ifdef __cplusplus |
| 29 | extern "C" { |
| 30 | #endif |
| 31 | |
| 32 | /* Include the Mbed TLS configuration file, the way Mbed TLS does it |
| 33 | * in each of its header files. */ |
| 34 | #if defined(MBEDTLS_CONFIG_FILE) |
| 35 | #include MBEDTLS_CONFIG_FILE |
| 36 | #else |
| 37 | #include "mbedtls/config.h" |
| 38 | #endif |
| 39 | |
| 40 | #include "psa/crypto.h" |
| 41 | #include "psa_crypto_storage.h" |
| 42 | #include <stdint.h> |
| 43 | |
| 44 | /** |
| 45 | * \brief Load persistent data for the given key slot number. |
| 46 | * |
| 47 | * This function reads data from a storage backend and returns the data in a |
| 48 | * buffer. |
| 49 | * |
Gilles Peskine | 8d4919b | 2018-12-03 16:48:09 +0100 | [diff] [blame] | 50 | * \param key Persistent identifier of the key to be loaded. This |
| 51 | * should be an occupied storage location. |
| 52 | * \param[out] data Buffer where the data is to be written. |
| 53 | * \param data_size Size of the \c data buffer in bytes. |
Darryl Green | db2b8db | 2018-06-15 13:06:04 +0100 | [diff] [blame] | 54 | * |
| 55 | * \retval PSA_SUCCESS |
| 56 | * \retval PSA_ERROR_STORAGE_FAILURE |
Gilles Peskine | 8d4919b | 2018-12-03 16:48:09 +0100 | [diff] [blame] | 57 | * \retval PSA_ERROR_EMPTY_SLOT |
Darryl Green | db2b8db | 2018-06-15 13:06:04 +0100 | [diff] [blame] | 58 | */ |
Gilles Peskine | 8d4919b | 2018-12-03 16:48:09 +0100 | [diff] [blame] | 59 | psa_status_t psa_crypto_storage_load( const psa_key_id_t key, uint8_t *data, |
Darryl Green | db2b8db | 2018-06-15 13:06:04 +0100 | [diff] [blame] | 60 | size_t data_size ); |
| 61 | |
| 62 | /** |
| 63 | * \brief Store persistent data for the given key slot number. |
| 64 | * |
| 65 | * This function stores the given data buffer to a persistent storage. |
| 66 | * |
Gilles Peskine | 8d4919b | 2018-12-03 16:48:09 +0100 | [diff] [blame] | 67 | * \param key Persistent identifier of the key to be stored. This |
| 68 | * should be an unoccupied storage location. |
Darryl Green | db2b8db | 2018-06-15 13:06:04 +0100 | [diff] [blame] | 69 | * \param[in] data Buffer containing the data to be stored. |
| 70 | * \param data_length The number of bytes |
| 71 | * that make up the data. |
| 72 | * |
| 73 | * \retval PSA_SUCCESS |
| 74 | * \retval PSA_ERROR_INSUFFICIENT_STORAGE |
| 75 | * \retval PSA_ERROR_STORAGE_FAILURE |
Gilles Peskine | 8d4919b | 2018-12-03 16:48:09 +0100 | [diff] [blame] | 76 | * \retval PSA_ERROR_OCCUPIED_SLOT |
Darryl Green | db2b8db | 2018-06-15 13:06:04 +0100 | [diff] [blame] | 77 | */ |
Gilles Peskine | 8d4919b | 2018-12-03 16:48:09 +0100 | [diff] [blame] | 78 | psa_status_t psa_crypto_storage_store( const psa_key_id_t key, |
Darryl Green | db2b8db | 2018-06-15 13:06:04 +0100 | [diff] [blame] | 79 | const uint8_t *data, |
| 80 | size_t data_length ); |
| 81 | |
| 82 | /** |
| 83 | * \brief Checks if persistent data is stored for the given key slot number |
| 84 | * |
| 85 | * This function checks if any key data or metadata exists for the key slot in |
| 86 | * the persistent storage. |
| 87 | * |
Gilles Peskine | 8d4919b | 2018-12-03 16:48:09 +0100 | [diff] [blame] | 88 | * \param key Persistent identifier to check. |
Darryl Green | db2b8db | 2018-06-15 13:06:04 +0100 | [diff] [blame] | 89 | * |
| 90 | * \retval 0 |
| 91 | * No persistent data present for slot number |
| 92 | * \retval 1 |
| 93 | * Persistent data present for slot number |
| 94 | */ |
Gilles Peskine | 8d4919b | 2018-12-03 16:48:09 +0100 | [diff] [blame] | 95 | int psa_is_key_present_in_storage( const psa_key_id_t key ); |
Darryl Green | db2b8db | 2018-06-15 13:06:04 +0100 | [diff] [blame] | 96 | |
| 97 | /** |
| 98 | * \brief Get data length for given key slot number. |
| 99 | * |
Gilles Peskine | 8d4919b | 2018-12-03 16:48:09 +0100 | [diff] [blame] | 100 | * \param key Persistent identifier whose stored data length |
| 101 | * is to be obtained. |
| 102 | * \param[out] data_length The number of bytes that make up the data. |
Darryl Green | db2b8db | 2018-06-15 13:06:04 +0100 | [diff] [blame] | 103 | * |
| 104 | * \retval PSA_SUCCESS |
| 105 | * \retval PSA_ERROR_STORAGE_FAILURE |
| 106 | */ |
Gilles Peskine | 8d4919b | 2018-12-03 16:48:09 +0100 | [diff] [blame] | 107 | psa_status_t psa_crypto_storage_get_data_length( const psa_key_id_t key, |
Darryl Green | db2b8db | 2018-06-15 13:06:04 +0100 | [diff] [blame] | 108 | size_t *data_length ); |
| 109 | |
| 110 | |
| 111 | #ifdef __cplusplus |
| 112 | } |
| 113 | #endif |
| 114 | |
| 115 | #endif /* PSA_CRYPTO_STORAGE_H */ |