2018-01-27 23:32:46 +01:00
|
|
|
/**
|
|
|
|
* \file psa/crypto_extra.h
|
|
|
|
*
|
|
|
|
* \brief PSA cryptography module: Mbed TLS vendor extensions
|
2018-06-28 18:02:53 +02:00
|
|
|
*
|
|
|
|
* \note This file may not be included directly. Applications must
|
|
|
|
* include psa/crypto.h.
|
|
|
|
*
|
|
|
|
* This file is reserved for vendor-specific definitions.
|
2018-01-27 23:32:46 +01:00
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* 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_EXTRA_H
|
|
|
|
#define PSA_CRYPTO_EXTRA_H
|
|
|
|
|
2019-02-25 09:51:27 +01:00
|
|
|
#include "mbedtls/platform_util.h"
|
|
|
|
|
2018-01-27 23:32:46 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2018-11-19 10:53:02 +01:00
|
|
|
/* UID for secure storage seed */
|
2018-11-21 16:31:07 +01:00
|
|
|
#define PSA_CRYPTO_ITS_RANDOM_SEED_UID 0xFFFFFF52
|
2018-11-19 10:53:02 +01:00
|
|
|
|
2019-02-21 11:41:29 +01:00
|
|
|
/*
|
|
|
|
* Deprecated PSA Crypto error code definitions
|
|
|
|
*/
|
|
|
|
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
|
|
|
#define PSA_ERROR_UNKNOWN_ERROR \
|
|
|
|
MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( PSA_ERROR_GENERIC_ERROR )
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
|
|
|
#define PSA_ERROR_OCCUPIED_SLOT \
|
|
|
|
MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( PSA_ERROR_ALREADY_EXISTS )
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
|
|
|
#define PSA_ERROR_EMPTY_SLOT \
|
|
|
|
MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( PSA_ERROR_DOES_NOT_EXIST )
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
|
|
|
#define PSA_ERROR_INSUFFICIENT_CAPACITY \
|
|
|
|
MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( PSA_ERROR_INSUFFICIENT_DATA )
|
|
|
|
#endif
|
|
|
|
|
2019-05-10 19:33:38 +02:00
|
|
|
/** \addtogroup policy
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** \brief Set the enrollment algorithm in a key policy.
|
|
|
|
*
|
|
|
|
* An operation on a key may indifferently use the algorithm set with
|
|
|
|
* psa_key_policy_set_usage() or with this function.
|
|
|
|
*
|
|
|
|
* \param[in,out] policy The key policy to modify. It must have been
|
|
|
|
* initialized as per the documentation for
|
|
|
|
* #psa_key_policy_t.
|
|
|
|
* \param alg2 A second algorithm that the key may be used for,
|
|
|
|
* in addition to the algorithm set with
|
|
|
|
* psa_key_policy_set_usage().
|
|
|
|
*
|
|
|
|
* \warning Setting an enrollment algorithm is not recommended, because
|
|
|
|
* using the same key with different algorithms can allow some
|
|
|
|
* attacks based on arithmetic relations between different
|
|
|
|
* computations made with the same key, or can escalate harmless
|
|
|
|
* side channels into exploitable ones. Use this function only
|
2019-05-22 11:45:59 +02:00
|
|
|
* if it is necessary to support a protocol for which it has been
|
2019-05-10 19:33:38 +02:00
|
|
|
* verified that the usage of the key with multiple algorithms
|
|
|
|
* is safe.
|
|
|
|
*/
|
|
|
|
void psa_key_policy_set_enrollment_algorithm(psa_key_policy_t *policy,
|
|
|
|
psa_algorithm_t alg2);
|
|
|
|
|
|
|
|
/** \brief Retrieve the enrollment algorithm field of a policy structure.
|
|
|
|
*
|
|
|
|
* \param[in] policy The policy object to query.
|
|
|
|
*
|
|
|
|
* \return The enrollment algorithm for a key with this policy.
|
|
|
|
*/
|
|
|
|
psa_algorithm_t psa_key_policy_get_enrollment_algorithm(
|
|
|
|
const psa_key_policy_t *policy);
|
|
|
|
|
|
|
|
/**@}*/
|
|
|
|
|
2018-01-27 23:32:46 +01:00
|
|
|
/**
|
|
|
|
* \brief Library deinitialization.
|
|
|
|
*
|
|
|
|
* This function clears all data associated with the PSA layer,
|
|
|
|
* including the whole key store.
|
|
|
|
*
|
|
|
|
* This is an Mbed TLS extension.
|
|
|
|
*/
|
|
|
|
void mbedtls_psa_crypto_free( void );
|
|
|
|
|
2018-11-19 10:53:02 +01:00
|
|
|
|
|
|
|
/**
|
2018-11-16 11:02:49 +01:00
|
|
|
* \brief Inject an initial entropy seed for the random generator into
|
|
|
|
* secure storage.
|
2018-11-15 18:19:27 +01:00
|
|
|
*
|
|
|
|
* This function injects data to be used as a seed for the random generator
|
|
|
|
* used by the PSA Crypto implementation. On devices that lack a trusted
|
|
|
|
* entropy source (preferably a hardware random number generator),
|
|
|
|
* the Mbed PSA Crypto implementation uses this value to seed its
|
|
|
|
* random generator.
|
|
|
|
*
|
|
|
|
* On devices without a trusted entropy source, this function must be
|
|
|
|
* called exactly once in the lifetime of the device. On devices with
|
|
|
|
* a trusted entropy source, calling this function is optional.
|
|
|
|
* In all cases, this function may only be called before calling any
|
|
|
|
* other function in the PSA Crypto API, including psa_crypto_init().
|
|
|
|
*
|
|
|
|
* When this function returns successfully, it populates a file in
|
|
|
|
* persistent storage. Once the file has been created, this function
|
|
|
|
* can no longer succeed.
|
2018-11-16 11:02:49 +01:00
|
|
|
*
|
|
|
|
* If any error occurs, this function does not change the system state.
|
|
|
|
* You can call this function again after correcting the reason for the
|
|
|
|
* error if possible.
|
2018-11-19 10:53:02 +01:00
|
|
|
*
|
|
|
|
* \warning This function **can** fail! Callers MUST check the return status.
|
|
|
|
*
|
2018-11-15 18:19:27 +01:00
|
|
|
* \warning If you use this function, you should use it as part of a
|
|
|
|
* factory provisioning process. The value of the injected seed
|
|
|
|
* is critical to the security of the device. It must be
|
|
|
|
* *secret*, *unpredictable* and (statistically) *unique per device*.
|
|
|
|
* You should be generate it randomly using a cryptographically
|
|
|
|
* secure random generator seeded from trusted entropy sources.
|
|
|
|
* You should transmit it securely to the device and ensure
|
|
|
|
* that its value is not leaked or stored anywhere beyond the
|
|
|
|
* needs of transmitting it from the point of generation to
|
|
|
|
* the call of this function, and erase all copies of the value
|
|
|
|
* once this function returns.
|
|
|
|
*
|
|
|
|
* This is an Mbed TLS extension.
|
2018-11-19 10:53:02 +01:00
|
|
|
*
|
2018-11-22 15:24:48 +01:00
|
|
|
* \note This function is only available on the following platforms:
|
2019-02-25 11:04:06 +01:00
|
|
|
* * If the compile-time option MBEDTLS_PSA_INJECT_ENTROPY is enabled.
|
|
|
|
* Note that you must provide compatible implementations of
|
|
|
|
* mbedtls_nv_seed_read and mbedtls_nv_seed_write.
|
2018-11-22 16:11:45 +01:00
|
|
|
* * In a client-server integration of PSA Cryptography, on the client side,
|
2018-11-22 15:24:48 +01:00
|
|
|
* if the server supports this feature.
|
2018-11-22 17:41:43 +01:00
|
|
|
* \param[in] seed Buffer containing the seed value to inject.
|
2018-11-22 16:11:45 +01:00
|
|
|
* \param[in] seed_size Size of the \p seed buffer.
|
2018-11-22 17:41:43 +01:00
|
|
|
* The size of the seed in bytes must be greater
|
|
|
|
* or equal to both #MBEDTLS_ENTROPY_MIN_PLATFORM
|
|
|
|
* and #MBEDTLS_ENTROPY_BLOCK_SIZE.
|
|
|
|
* It must be less or equal to
|
|
|
|
* #MBEDTLS_ENTROPY_MAX_SEED_SIZE.
|
2018-11-19 10:53:02 +01:00
|
|
|
*
|
|
|
|
* \retval #PSA_SUCCESS
|
2018-11-15 18:19:27 +01:00
|
|
|
* The seed value was injected successfully. The random generator
|
|
|
|
* of the PSA Crypto implementation is now ready for use.
|
|
|
|
* You may now call psa_crypto_init() and use the PSA Crypto
|
|
|
|
* implementation.
|
2018-11-19 10:53:02 +01:00
|
|
|
* \retval #PSA_ERROR_INVALID_ARGUMENT
|
2018-11-16 11:02:49 +01:00
|
|
|
* \p seed_size is out of range.
|
2018-11-19 10:53:02 +01:00
|
|
|
* \retval #PSA_ERROR_STORAGE_FAILURE
|
2018-11-15 18:19:27 +01:00
|
|
|
* There was a failure reading or writing from storage.
|
2018-11-19 10:53:02 +01:00
|
|
|
* \retval #PSA_ERROR_NOT_PERMITTED
|
2018-11-15 18:19:27 +01:00
|
|
|
* The library has already been initialized. It is no longer
|
|
|
|
* possible to call this function.
|
2018-11-19 10:53:02 +01:00
|
|
|
*/
|
|
|
|
psa_status_t mbedtls_psa_inject_entropy(const unsigned char *seed,
|
|
|
|
size_t seed_size);
|
|
|
|
|
|
|
|
|
2018-01-27 23:32:46 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* PSA_CRYPTO_EXTRA_H */
|