2018-12-07 17:24:41 +00:00
|
|
|
/*
|
|
|
|
* PSA crypto core internal interfaces
|
|
|
|
*/
|
|
|
|
/* Copyright (C) 2018, ARM Limited, All Rights Reserved
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
* not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*
|
|
|
|
* This file is part of mbed TLS (https://tls.mbed.org)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PSA_CRYPTO_CORE_H
|
|
|
|
#define PSA_CRYPTO_CORE_H
|
|
|
|
|
|
|
|
#if !defined(MBEDTLS_CONFIG_FILE)
|
|
|
|
#include "mbedtls/config.h"
|
|
|
|
#else
|
|
|
|
#include MBEDTLS_CONFIG_FILE
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "psa/crypto.h"
|
|
|
|
|
|
|
|
#include "mbedtls/ecp.h"
|
|
|
|
#include "mbedtls/rsa.h"
|
|
|
|
|
|
|
|
/** The data structure representing a key slot, containing key material
|
|
|
|
* and metadata for one key.
|
|
|
|
*/
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
psa_key_type_t type;
|
|
|
|
psa_key_policy_t policy;
|
|
|
|
psa_key_lifetime_t lifetime;
|
Support encoding an owner in key file IDs
Differentiate between _key identifiers_, which are always `uint32_t`,
and _key file identifiers_, which are platform-dependent. Normally,
the two are the same.
In `psa/crypto_platform.h`, define `psa_app_key_id_t` (which is always
32 bits, the standard key identifier type) and
`psa_key_file_id_t` (which will be different in some service builds).
A subsequent commit will introduce a platform where the two are different.
It would make sense for the function declarations in `psa/crypto.h` to
use `psa_key_file_id_t`. However this file is currently part of the
PSA Crypto API specification, so it must stick to the standard type
`psa_key_id_t`. Hence, as long as the specification and Mbed Crypto
are not separate, use the implementation-specific file
`psa/crypto_platform.h` to define `psa_key_id_t` as `psa_key_file_id_t`.
In the library, systematically use `psa_key_file_id_t`.
perl -i -pe 's/psa_key_id_t/psa_key_file_id_t/g' library/*.[hc]
2019-02-19 12:24:37 +00:00
|
|
|
psa_key_file_id_t persistent_storage_id;
|
2018-12-07 17:24:41 +00:00
|
|
|
unsigned allocated : 1;
|
|
|
|
union
|
|
|
|
{
|
|
|
|
struct raw_data
|
|
|
|
{
|
|
|
|
uint8_t *data;
|
|
|
|
size_t bytes;
|
|
|
|
} raw;
|
|
|
|
#if defined(MBEDTLS_RSA_C)
|
|
|
|
mbedtls_rsa_context *rsa;
|
|
|
|
#endif /* MBEDTLS_RSA_C */
|
|
|
|
#if defined(MBEDTLS_ECP_C)
|
|
|
|
mbedtls_ecp_keypair *ecp;
|
|
|
|
#endif /* MBEDTLS_ECP_C */
|
|
|
|
} data;
|
|
|
|
} psa_key_slot_t;
|
|
|
|
|
2018-12-10 15:29:04 +00:00
|
|
|
/** Completely wipe a slot in memory, including its policy.
|
2018-12-10 16:00:38 +00:00
|
|
|
*
|
|
|
|
* Persistent storage is not affected.
|
|
|
|
*
|
|
|
|
* \param[in,out] slot The key slot to wipe.
|
|
|
|
*
|
|
|
|
* \retval PSA_SUCCESS
|
|
|
|
* Success. This includes the case of a key slot that was
|
|
|
|
* already fully wiped.
|
|
|
|
* \retval PSA_ERROR_TAMPERING_DETECTED
|
|
|
|
*/
|
2018-12-10 15:29:04 +00:00
|
|
|
psa_status_t psa_wipe_key_slot( psa_key_slot_t *slot );
|
|
|
|
|
2018-12-10 16:00:38 +00:00
|
|
|
/** Import key data into a slot.
|
|
|
|
*
|
|
|
|
* `slot->type` must have been set previously.
|
|
|
|
* This function assumes that the slot does not contain any key material yet.
|
|
|
|
* On failure, the slot content is unchanged.
|
|
|
|
*
|
|
|
|
* Persistent storage is not affected.
|
|
|
|
*
|
|
|
|
* \param[in,out] slot The key slot to import data into.
|
|
|
|
* Its `type` field must have previously been set to
|
|
|
|
* the desired key type.
|
|
|
|
* It must not contain any key material yet.
|
|
|
|
* \param[in] data Buffer containing the key material to parse and import.
|
|
|
|
* \param data_length Size of \p data in bytes.
|
|
|
|
*
|
|
|
|
* \retval PSA_SUCCESS
|
|
|
|
* \retval PSA_ERROR_INVALID_ARGUMENT
|
|
|
|
* \retval PSA_ERROR_NOT_SUPPORTED
|
|
|
|
* \retval PSA_ERROR_INSUFFICIENT_MEMORY
|
|
|
|
*/
|
2018-12-10 15:48:53 +00:00
|
|
|
psa_status_t psa_import_key_into_slot( psa_key_slot_t *slot,
|
|
|
|
const uint8_t *data,
|
|
|
|
size_t data_length );
|
|
|
|
|
2018-12-07 17:24:41 +00:00
|
|
|
#endif /* PSA_CRYPTO_CORE_H */
|