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 | * |
| 50 | * \param key Slot number whose content is to be loaded. This must |
| 51 | * be a key slot whose lifetime is set to persistent. |
| 52 | * \param[out] data Buffer where the data is to be written. |
| 53 | * \param data_size Size of the \c data buffer in bytes. |
| 54 | * |
| 55 | * \retval PSA_SUCCESS |
| 56 | * \retval PSA_ERROR_STORAGE_FAILURE |
| 57 | */ |
| 58 | psa_status_t psa_crypto_storage_load( const psa_key_slot_t key, uint8_t *data, |
| 59 | size_t data_size ); |
| 60 | |
| 61 | /** |
| 62 | * \brief Store persistent data for the given key slot number. |
| 63 | * |
| 64 | * This function stores the given data buffer to a persistent storage. |
| 65 | * |
| 66 | * \param key Slot number whose content is to be stored. |
| 67 | * \param[in] data Buffer containing the data to be stored. |
| 68 | * \param data_length The number of bytes |
| 69 | * that make up the data. |
| 70 | * |
| 71 | * \retval PSA_SUCCESS |
| 72 | * \retval PSA_ERROR_INSUFFICIENT_STORAGE |
| 73 | * \retval PSA_ERROR_STORAGE_FAILURE |
| 74 | */ |
| 75 | psa_status_t psa_crypto_storage_store( const psa_key_slot_t key, |
| 76 | const uint8_t *data, |
| 77 | size_t data_length ); |
| 78 | |
| 79 | /** |
| 80 | * \brief Checks if persistent data is stored for the given key slot number |
| 81 | * |
| 82 | * This function checks if any key data or metadata exists for the key slot in |
| 83 | * the persistent storage. |
| 84 | * |
| 85 | * \param key Slot number whose content is to be checked. |
| 86 | * |
| 87 | * \retval 0 |
| 88 | * No persistent data present for slot number |
| 89 | * \retval 1 |
| 90 | * Persistent data present for slot number |
| 91 | */ |
| 92 | int psa_is_key_present_in_storage( const psa_key_slot_t key ); |
| 93 | |
| 94 | /** |
| 95 | * \brief Get data length for given key slot number. |
| 96 | * |
| 97 | * \param key Slot number whose stored data length is to be obtained. |
| 98 | * \param[out] data_length The number of bytes |
| 99 | * that make up the data. |
| 100 | * |
| 101 | * \retval PSA_SUCCESS |
| 102 | * \retval PSA_ERROR_STORAGE_FAILURE |
| 103 | */ |
| 104 | psa_status_t psa_crypto_storage_get_data_length( const psa_key_slot_t key, |
| 105 | size_t *data_length ); |
| 106 | |
| 107 | |
| 108 | #ifdef __cplusplus |
| 109 | } |
| 110 | #endif |
| 111 | |
| 112 | #endif /* PSA_CRYPTO_STORAGE_H */ |