2018-01-27 23:32:46 +01:00
|
|
|
/**
|
|
|
|
* \file psa/crypto.h
|
|
|
|
* \brief Platform Security Architecture cryptography module
|
|
|
|
*/
|
2018-07-25 14:26:13 +02: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.
|
|
|
|
*/
|
2018-01-27 23:32:46 +01:00
|
|
|
|
|
|
|
#ifndef PSA_CRYPTO_H
|
|
|
|
#define PSA_CRYPTO_H
|
|
|
|
|
|
|
|
#include "crypto_platform.h"
|
|
|
|
|
2018-01-28 13:16:24 +01:00
|
|
|
#include <stddef.h>
|
|
|
|
|
2018-02-07 21:54:47 +01:00
|
|
|
#ifdef __DOXYGEN_ONLY__
|
2018-03-07 16:40:18 +01:00
|
|
|
/* This __DOXYGEN_ONLY__ block contains mock definitions for things that
|
|
|
|
* must be defined in the crypto_platform.h header. These mock definitions
|
|
|
|
* are present in this file as a convenience to generate pretty-printed
|
|
|
|
* documentation that includes those definitions. */
|
|
|
|
|
2018-02-07 21:54:47 +01:00
|
|
|
/** \defgroup platform Implementation-specific definitions
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2018-11-30 14:39:32 +01:00
|
|
|
/** \brief Key handle.
|
2018-01-28 13:16:24 +01:00
|
|
|
*
|
2018-11-30 14:39:32 +01:00
|
|
|
* This type represents open handles to keys. It must be an unsigned integral
|
2018-02-08 09:47:44 +01:00
|
|
|
* type. The choice of type is implementation-dependent.
|
2018-11-30 14:39:32 +01:00
|
|
|
*
|
2018-12-11 15:51:32 +01:00
|
|
|
* 0 is not a valid key handle. How other handle values are assigned is
|
|
|
|
* implementation-dependent.
|
2018-01-28 13:16:24 +01:00
|
|
|
*/
|
2018-11-30 14:39:32 +01:00
|
|
|
typedef _unsigned_integral_type_ psa_key_handle_t;
|
2018-01-28 13:16:24 +01:00
|
|
|
|
2018-02-07 21:54:47 +01:00
|
|
|
/**@}*/
|
2018-03-07 16:40:18 +01:00
|
|
|
#endif /* __DOXYGEN_ONLY__ */
|
2018-02-07 21:54:47 +01:00
|
|
|
|
2018-01-27 23:32:46 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2018-12-12 13:38:31 +01:00
|
|
|
/* The file "crypto_types.h" declares types that encode errors,
|
|
|
|
* algorithms, key types, policies, etc. */
|
|
|
|
#include "crypto_types.h"
|
2018-06-18 15:20:16 +02:00
|
|
|
|
2018-12-12 13:38:31 +01:00
|
|
|
/* The file "crypto_values.h" declares macros to build and analyze values
|
|
|
|
* of integral types defined in "crypto_types.h". */
|
|
|
|
#include "crypto_values.h"
|
2018-01-27 23:32:46 +01:00
|
|
|
|
2018-12-12 13:38:31 +01:00
|
|
|
/** \defgroup initialization Library initialization
|
|
|
|
* @{
|
2018-11-30 14:08:36 +01:00
|
|
|
*/
|
|
|
|
|
2018-01-27 23:32:46 +01:00
|
|
|
/**
|
|
|
|
* \brief Library initialization.
|
|
|
|
*
|
|
|
|
* Applications must call this function before calling any other
|
|
|
|
* function in this module.
|
|
|
|
*
|
|
|
|
* Applications may call this function more than once. Once a call
|
|
|
|
* succeeds, subsequent calls are guaranteed to succeed.
|
|
|
|
*
|
2018-09-16 11:22:41 +02:00
|
|
|
* If the application calls other functions before calling psa_crypto_init(),
|
|
|
|
* the behavior is undefined. Implementations are encouraged to either perform
|
|
|
|
* the operation as if the library had been initialized or to return
|
|
|
|
* #PSA_ERROR_BAD_STATE or some other applicable error. In particular,
|
|
|
|
* implementations should not return a success status if the lack of
|
|
|
|
* initialization may have security implications, for example due to improper
|
|
|
|
* seeding of the random number generator.
|
|
|
|
*
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_SUCCESS
|
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
|
|
|
|
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
|
|
|
* \retval #PSA_ERROR_HARDWARE_FAILURE
|
|
|
|
* \retval #PSA_ERROR_TAMPERING_DETECTED
|
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_ENTROPY
|
2018-01-27 23:32:46 +01:00
|
|
|
*/
|
|
|
|
psa_status_t psa_crypto_init(void);
|
|
|
|
|
2018-01-28 13:16:24 +01:00
|
|
|
/**@}*/
|
|
|
|
|
|
|
|
/** \defgroup key_management Key management
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2018-11-30 14:39:32 +01:00
|
|
|
/** \brief Retrieve the lifetime of an open key.
|
2018-11-30 14:07:45 +01:00
|
|
|
*
|
2018-11-30 14:39:32 +01:00
|
|
|
* \param handle Handle to query.
|
2018-11-30 14:07:45 +01:00
|
|
|
* \param[out] lifetime On success, the lifetime value.
|
|
|
|
*
|
|
|
|
* \retval #PSA_SUCCESS
|
|
|
|
* Success.
|
2018-11-30 14:39:32 +01:00
|
|
|
* \retval #PSA_ERROR_INVALID_HANDLE
|
2018-11-30 14:07:45 +01:00
|
|
|
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
|
|
|
* \retval #PSA_ERROR_HARDWARE_FAILURE
|
|
|
|
* \retval #PSA_ERROR_TAMPERING_DETECTED
|
|
|
|
* \retval #PSA_ERROR_BAD_STATE
|
|
|
|
* The library has not been previously initialized by psa_crypto_init().
|
|
|
|
* It is implementation-dependent whether a failure to initialize
|
|
|
|
* results in this error code.
|
|
|
|
*/
|
2018-11-30 14:39:32 +01:00
|
|
|
psa_status_t psa_get_key_lifetime(psa_key_handle_t handle,
|
2018-11-30 14:07:45 +01:00
|
|
|
psa_key_lifetime_t *lifetime);
|
|
|
|
|
|
|
|
|
2018-11-30 14:08:36 +01:00
|
|
|
/** Allocate a key slot for a transient key, i.e. a key which is only stored
|
|
|
|
* in volatile memory.
|
|
|
|
*
|
|
|
|
* The allocated key slot and its handle remain valid until the
|
|
|
|
* application calls psa_close_key() or psa_destroy_key() or until the
|
|
|
|
* application terminates.
|
|
|
|
*
|
|
|
|
* This function takes a key type and maximum size as arguments so that
|
|
|
|
* the implementation can reserve a corresponding amount of memory.
|
|
|
|
* Implementations are not required to enforce this limit: if the application
|
|
|
|
* later tries to create a larger key or a key of a different type, it
|
|
|
|
* is implementation-defined whether this may succeed.
|
|
|
|
*
|
|
|
|
* \param type The type of key that the slot will contain.
|
|
|
|
* \param max_bits The maximum key size that the slot will contain.
|
|
|
|
* \param[out] handle On success, a handle to a volatile key slot.
|
|
|
|
*
|
|
|
|
* \retval #PSA_SUCCESS
|
|
|
|
* Success. The application can now use the value of `*handle`
|
|
|
|
* to access the newly allocated key slot.
|
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
|
|
|
|
* There was not enough memory, or the maximum number of key slots
|
|
|
|
* has been reached.
|
|
|
|
* \retval #PSA_ERROR_INVALID_ARGUMENT
|
|
|
|
* This implementation does not support this key type.
|
|
|
|
*/
|
|
|
|
|
|
|
|
psa_status_t psa_allocate_key(psa_key_type_t type,
|
|
|
|
size_t max_bits,
|
|
|
|
psa_key_handle_t *handle);
|
|
|
|
|
|
|
|
/** Open a handle to an existing persistent key.
|
|
|
|
*
|
|
|
|
* Open a handle to a key which was previously created with psa_create_key().
|
|
|
|
*
|
|
|
|
* \param lifetime The lifetime of the key. This designates a storage
|
|
|
|
* area where the key material is stored. This must not
|
|
|
|
* be #PSA_KEY_LIFETIME_VOLATILE.
|
|
|
|
* \param id The persistent identifier of the key.
|
|
|
|
* \param[out] handle On success, a handle to a key slot which contains
|
|
|
|
* the data and metadata loaded from the specified
|
|
|
|
* persistent location.
|
|
|
|
*
|
|
|
|
* \retval #PSA_SUCCESS
|
|
|
|
* Success. The application can now use the value of `*handle`
|
|
|
|
* to access the newly allocated key slot.
|
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
|
|
|
|
* \retval #PSA_ERROR_EMPTY_SLOT
|
|
|
|
* \retval #PSA_ERROR_INVALID_ARGUMENT
|
|
|
|
* \p lifetime is invalid, for example #PSA_KEY_LIFETIME_VOLATILE.
|
|
|
|
* \retval #PSA_ERROR_INVALID_ARGUMENT
|
|
|
|
* \p id is invalid for the specified lifetime.
|
|
|
|
* \retval #PSA_ERROR_NOT_SUPPORTED
|
|
|
|
* \p lifetime is not supported.
|
|
|
|
* \retval #PSA_ERROR_NOT_PERMITTED
|
|
|
|
* The specified key exists, but the application does not have the
|
|
|
|
* permission to access it. Note that this specification does not
|
|
|
|
* define any way to create such a key, but it may be possible
|
|
|
|
* through implementation-specific means.
|
|
|
|
*/
|
|
|
|
psa_status_t psa_open_key(psa_key_lifetime_t lifetime,
|
|
|
|
psa_key_id_t id,
|
|
|
|
psa_key_handle_t *handle);
|
|
|
|
|
|
|
|
/** Create a new persistent key slot.
|
|
|
|
*
|
|
|
|
* Create a new persistent key slot and return a handle to it. The handle
|
|
|
|
* remains valid until the application calls psa_close_key() or terminates.
|
|
|
|
* The application can open the key again with psa_open_key() until it
|
|
|
|
* removes the key by calling psa_destroy_key().
|
|
|
|
*
|
|
|
|
* \param lifetime The lifetime of the key. This designates a storage
|
|
|
|
* area where the key material is stored. This must not
|
|
|
|
* be #PSA_KEY_LIFETIME_VOLATILE.
|
|
|
|
* \param id The persistent identifier of the key.
|
|
|
|
* \param type The type of key that the slot will contain.
|
|
|
|
* \param max_bits The maximum key size that the slot will contain.
|
|
|
|
* \param[out] handle On success, a handle to the newly created key slot.
|
|
|
|
* When key material is later created in this key slot,
|
|
|
|
* it will be saved to the specified persistent location.
|
|
|
|
*
|
|
|
|
* \retval #PSA_SUCCESS
|
|
|
|
* Success. The application can now use the value of `*handle`
|
|
|
|
* to access the newly allocated key slot.
|
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
|
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_STORAGE
|
|
|
|
* \retval #PSA_ERROR_OCCUPIED_SLOT
|
|
|
|
* There is already a key with the identifier \p id in the storage
|
|
|
|
* area designated by \p lifetime.
|
|
|
|
* \retval #PSA_ERROR_INVALID_ARGUMENT
|
|
|
|
* \p lifetime is invalid, for example #PSA_KEY_LIFETIME_VOLATILE.
|
|
|
|
* \retval #PSA_ERROR_INVALID_ARGUMENT
|
|
|
|
* \p id is invalid for the specified lifetime.
|
|
|
|
* \retval #PSA_ERROR_NOT_SUPPORTED
|
|
|
|
* \p lifetime is not supported.
|
|
|
|
* \retval #PSA_ERROR_NOT_PERMITTED
|
|
|
|
* \p lifetime is valid, but the application does not have the
|
|
|
|
* permission to create a key there.
|
|
|
|
*/
|
|
|
|
psa_status_t psa_create_key(psa_key_lifetime_t lifetime,
|
|
|
|
psa_key_id_t id,
|
|
|
|
psa_key_type_t type,
|
|
|
|
size_t max_bits,
|
|
|
|
psa_key_handle_t *handle);
|
|
|
|
|
|
|
|
/** Close a key handle.
|
|
|
|
*
|
|
|
|
* If the handle designates a volatile key, destroy the key material and
|
|
|
|
* free all associated resources, just like psa_destroy_key().
|
|
|
|
*
|
|
|
|
* If the handle designates a persistent key, free all resources associated
|
|
|
|
* with the key in volatile memory. The key slot in persistent storage is
|
|
|
|
* not affected and can be opened again later with psa_open_key().
|
|
|
|
*
|
|
|
|
* \param handle The key handle to close.
|
|
|
|
*
|
|
|
|
* \retval #PSA_SUCCESS
|
|
|
|
* \retval #PSA_ERROR_INVALID_HANDLE
|
2018-11-30 14:39:32 +01:00
|
|
|
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
2018-11-30 14:08:36 +01:00
|
|
|
*/
|
|
|
|
psa_status_t psa_close_key(psa_key_handle_t handle);
|
|
|
|
|
2018-11-30 14:07:45 +01:00
|
|
|
/**@}*/
|
|
|
|
|
|
|
|
/** \defgroup import_export Key import and export
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2018-01-28 13:16:24 +01:00
|
|
|
/**
|
|
|
|
* \brief Import a key in binary format.
|
|
|
|
*
|
2018-03-07 16:40:18 +01:00
|
|
|
* This function supports any output from psa_export_key(). Refer to the
|
2018-10-31 14:07:52 +01:00
|
|
|
* documentation of psa_export_public_key() for the format of public keys
|
|
|
|
* and to the documentation of psa_export_key() for the format for
|
|
|
|
* other key types.
|
|
|
|
*
|
|
|
|
* This specification supports a single format for each key type.
|
|
|
|
* Implementations may support other formats as long as the standard
|
|
|
|
* format is supported. Implementations that support other formats
|
|
|
|
* should ensure that the formats are clearly unambiguous so as to
|
|
|
|
* minimize the risk that an invalid input is accidentally interpreted
|
|
|
|
* according to a different format.
|
2018-01-28 13:16:24 +01:00
|
|
|
*
|
2018-11-30 14:39:32 +01:00
|
|
|
* \param handle Handle to the slot where the key will be stored.
|
|
|
|
* This must be a valid slot for a key of the chosen
|
|
|
|
* type: it must have been obtained by calling
|
|
|
|
* psa_allocate_key() or psa_create_key() with the
|
|
|
|
* correct \p type and with a maximum size that is
|
|
|
|
* compatible with \p data.
|
2018-10-31 14:07:52 +01:00
|
|
|
* \param type Key type (a \c PSA_KEY_TYPE_XXX value). On a successful
|
|
|
|
* import, the key slot will contain a key of this type.
|
|
|
|
* \param[in] data Buffer containing the key data. The content of this
|
|
|
|
* buffer is interpreted according to \p type. It must
|
|
|
|
* contain the format described in the documentation
|
|
|
|
* of psa_export_key() or psa_export_public_key() for
|
|
|
|
* the chosen type.
|
2018-07-12 19:23:03 +02:00
|
|
|
* \param data_length Size of the \p data buffer in bytes.
|
2018-02-08 09:47:44 +01:00
|
|
|
*
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_SUCCESS
|
2018-02-08 09:47:44 +01:00
|
|
|
* Success.
|
2018-12-11 15:51:32 +01:00
|
|
|
* If the key is persistent, the key material and the key's metadata
|
|
|
|
* have been saved to persistent storage.
|
2018-11-30 14:39:32 +01:00
|
|
|
* \retval #PSA_ERROR_INVALID_HANDLE
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_ERROR_NOT_SUPPORTED
|
2018-04-19 08:28:58 +02:00
|
|
|
* The key type or key size is not supported, either by the
|
|
|
|
* implementation in general or in this particular slot.
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_ERROR_INVALID_ARGUMENT
|
2018-02-08 09:47:44 +01:00
|
|
|
* The key slot is invalid,
|
|
|
|
* or the key data is not correctly formatted.
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_ERROR_OCCUPIED_SLOT
|
2018-04-19 08:28:58 +02:00
|
|
|
* There is already a key in the specified slot.
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
|
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_STORAGE
|
|
|
|
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
2018-06-18 18:27:26 +02:00
|
|
|
* \retval #PSA_ERROR_STORAGE_FAILURE
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_ERROR_HARDWARE_FAILURE
|
|
|
|
* \retval #PSA_ERROR_TAMPERING_DETECTED
|
2018-09-12 10:44:52 +02:00
|
|
|
* \retval #PSA_ERROR_BAD_STATE
|
2018-09-16 11:22:41 +02:00
|
|
|
* The library has not been previously initialized by psa_crypto_init().
|
|
|
|
* It is implementation-dependent whether a failure to initialize
|
|
|
|
* results in this error code.
|
2018-01-28 13:16:24 +01:00
|
|
|
*/
|
2018-11-30 14:39:32 +01:00
|
|
|
psa_status_t psa_import_key(psa_key_handle_t handle,
|
2018-01-28 13:16:24 +01:00
|
|
|
psa_key_type_t type,
|
|
|
|
const uint8_t *data,
|
|
|
|
size_t data_length);
|
|
|
|
|
|
|
|
/**
|
2018-11-30 14:39:32 +01:00
|
|
|
* \brief Destroy a key.
|
2018-04-19 08:38:16 +02:00
|
|
|
*
|
|
|
|
* This function destroys the content of the key slot from both volatile
|
|
|
|
* memory and, if applicable, non-volatile storage. Implementations shall
|
|
|
|
* make a best effort to ensure that any previous content of the slot is
|
|
|
|
* unrecoverable.
|
|
|
|
*
|
2018-11-30 14:39:32 +01:00
|
|
|
* This function also erases any metadata such as policies and frees all
|
|
|
|
* resources associated with the key.
|
2018-04-19 08:38:16 +02:00
|
|
|
*
|
2018-11-30 14:39:32 +01:00
|
|
|
* \param handle Handle to the key slot to erase.
|
2018-01-28 13:16:24 +01:00
|
|
|
*
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_SUCCESS
|
2018-04-19 08:28:58 +02:00
|
|
|
* The slot's content, if any, has been erased.
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_ERROR_NOT_PERMITTED
|
2018-04-19 08:28:58 +02:00
|
|
|
* The slot holds content and cannot be erased because it is
|
|
|
|
* read-only, either due to a policy or due to physical restrictions.
|
2018-11-30 14:39:32 +01:00
|
|
|
* \retval #PSA_ERROR_INVALID_HANDLE
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
2018-04-19 08:28:58 +02:00
|
|
|
* There was an failure in communication with the cryptoprocessor.
|
|
|
|
* The key material may still be present in the cryptoprocessor.
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_ERROR_STORAGE_FAILURE
|
2018-04-19 08:28:58 +02:00
|
|
|
* The storage is corrupted. Implementations shall make a best effort
|
|
|
|
* to erase key material even in this stage, however applications
|
|
|
|
* should be aware that it may be impossible to guarantee that the
|
|
|
|
* key material is not recoverable in such cases.
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_ERROR_TAMPERING_DETECTED
|
2018-04-19 08:28:58 +02:00
|
|
|
* An unexpected condition which is not a storage corruption or
|
|
|
|
* a communication failure occurred. The cryptoprocessor may have
|
|
|
|
* been compromised.
|
2018-09-12 10:44:52 +02:00
|
|
|
* \retval #PSA_ERROR_BAD_STATE
|
2018-09-16 11:22:41 +02:00
|
|
|
* The library has not been previously initialized by psa_crypto_init().
|
|
|
|
* It is implementation-dependent whether a failure to initialize
|
|
|
|
* results in this error code.
|
2018-01-28 13:16:24 +01:00
|
|
|
*/
|
2018-11-30 14:39:32 +01:00
|
|
|
psa_status_t psa_destroy_key(psa_key_handle_t handle);
|
2018-01-28 13:16:24 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Get basic metadata about a key.
|
|
|
|
*
|
2018-11-30 14:39:32 +01:00
|
|
|
* \param handle Handle to the key slot to query.
|
2018-07-12 01:08:58 +02:00
|
|
|
* \param[out] type On success, the key type (a \c PSA_KEY_TYPE_XXX value).
|
2018-02-08 09:47:44 +01:00
|
|
|
* This may be a null pointer, in which case the key type
|
|
|
|
* is not written.
|
2018-07-12 01:08:58 +02:00
|
|
|
* \param[out] bits On success, the key size in bits.
|
2018-03-21 20:49:16 +01:00
|
|
|
* This may be a null pointer, in which case the key size
|
2018-02-08 09:47:44 +01:00
|
|
|
* is not written.
|
|
|
|
*
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_SUCCESS
|
2018-11-30 14:39:32 +01:00
|
|
|
* \retval #PSA_ERROR_INVALID_HANDLE
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_ERROR_EMPTY_SLOT
|
2018-11-30 14:39:32 +01:00
|
|
|
* The handle is to a key slot which does not contain key material yet.
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
|
|
|
* \retval #PSA_ERROR_HARDWARE_FAILURE
|
|
|
|
* \retval #PSA_ERROR_TAMPERING_DETECTED
|
2018-09-12 10:44:52 +02:00
|
|
|
* \retval #PSA_ERROR_BAD_STATE
|
2018-09-16 11:22:41 +02:00
|
|
|
* The library has not been previously initialized by psa_crypto_init().
|
|
|
|
* It is implementation-dependent whether a failure to initialize
|
|
|
|
* results in this error code.
|
2018-01-28 13:16:24 +01:00
|
|
|
*/
|
2018-11-30 14:39:32 +01:00
|
|
|
psa_status_t psa_get_key_information(psa_key_handle_t handle,
|
2018-01-28 13:16:24 +01:00
|
|
|
psa_key_type_t *type,
|
|
|
|
size_t *bits);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Export a key in binary format.
|
|
|
|
*
|
|
|
|
* The output of this function can be passed to psa_import_key() to
|
|
|
|
* create an equivalent object.
|
|
|
|
*
|
2018-10-31 14:07:52 +01:00
|
|
|
* If the implementation of psa_import_key() supports other formats
|
|
|
|
* beyond the format specified here, the output from psa_export_key()
|
|
|
|
* must use the representation specified here, not the original
|
|
|
|
* representation.
|
2018-01-28 13:16:24 +01:00
|
|
|
*
|
2018-02-08 09:47:44 +01:00
|
|
|
* For standard key types, the output format is as follows:
|
|
|
|
*
|
|
|
|
* - For symmetric keys (including MAC keys), the format is the
|
|
|
|
* raw bytes of the key.
|
|
|
|
* - For DES, the key data consists of 8 bytes. The parity bits must be
|
|
|
|
* correct.
|
|
|
|
* - For Triple-DES, the format is the concatenation of the
|
|
|
|
* two or three DES keys.
|
2018-03-03 21:29:30 +01:00
|
|
|
* - For RSA key pairs (#PSA_KEY_TYPE_RSA_KEYPAIR), the format
|
2018-08-10 18:57:40 +02:00
|
|
|
* is the non-encrypted DER encoding of the representation defined by
|
|
|
|
* PKCS\#1 (RFC 8017) as `RSAPrivateKey`, version 0.
|
|
|
|
* ```
|
|
|
|
* RSAPrivateKey ::= SEQUENCE {
|
2018-08-11 01:17:53 +02:00
|
|
|
* version INTEGER, -- must be 0
|
2018-08-10 18:57:40 +02:00
|
|
|
* modulus INTEGER, -- n
|
|
|
|
* publicExponent INTEGER, -- e
|
|
|
|
* privateExponent INTEGER, -- d
|
|
|
|
* prime1 INTEGER, -- p
|
|
|
|
* prime2 INTEGER, -- q
|
|
|
|
* exponent1 INTEGER, -- d mod (p-1)
|
|
|
|
* exponent2 INTEGER, -- d mod (q-1)
|
|
|
|
* coefficient INTEGER, -- (inverse of q) mod p
|
|
|
|
* }
|
|
|
|
* ```
|
|
|
|
* - For DSA private keys (#PSA_KEY_TYPE_DSA_KEYPAIR), the format
|
|
|
|
* is the non-encrypted DER encoding of the representation used by
|
2018-08-13 17:24:59 +02:00
|
|
|
* OpenSSL and OpenSSH, whose structure is described in ASN.1 as follows:
|
2018-08-10 18:57:40 +02:00
|
|
|
* ```
|
|
|
|
* DSAPrivateKey ::= SEQUENCE {
|
2018-08-11 01:17:53 +02:00
|
|
|
* version INTEGER, -- must be 0
|
2018-08-10 18:57:40 +02:00
|
|
|
* prime INTEGER, -- p
|
|
|
|
* subprime INTEGER, -- q
|
|
|
|
* generator INTEGER, -- g
|
|
|
|
* public INTEGER, -- y
|
|
|
|
* private INTEGER, -- x
|
|
|
|
* }
|
|
|
|
* ```
|
|
|
|
* - For elliptic curve key pairs (key types for which
|
2018-10-29 19:24:33 +01:00
|
|
|
* #PSA_KEY_TYPE_IS_ECC_KEYPAIR is true), the format is
|
2018-11-15 17:44:43 +01:00
|
|
|
* a representation of the private value as a `ceiling(m/8)`-byte string
|
|
|
|
* where `m` is the bit size associated with the curve, i.e. the bit size
|
|
|
|
* of the order of the curve's coordinate field. This byte string is
|
|
|
|
* in little-endian order for Montgomery curves (curve types
|
|
|
|
* `PSA_ECC_CURVE_CURVEXXX`), and in big-endian order for Weierstrass
|
|
|
|
* curves (curve types `PSA_ECC_CURVE_SECTXXX`, `PSA_ECC_CURVE_SECPXXX`
|
|
|
|
* and `PSA_ECC_CURVE_BRAINPOOL_PXXX`).
|
2018-10-29 19:24:33 +01:00
|
|
|
* This is the content of the `privateKey` field of the `ECPrivateKey`
|
|
|
|
* format defined by RFC 5915.
|
2018-08-10 18:57:40 +02:00
|
|
|
* - For public keys (key types for which #PSA_KEY_TYPE_IS_PUBLIC_KEY is
|
|
|
|
* true), the format is the same as for psa_export_public_key().
|
2018-02-08 09:47:44 +01:00
|
|
|
*
|
2018-11-30 14:39:32 +01:00
|
|
|
* \param handle Handle to the key to export.
|
2018-07-12 01:08:58 +02:00
|
|
|
* \param[out] data Buffer where the key data is to be written.
|
2018-07-12 19:23:03 +02:00
|
|
|
* \param data_size Size of the \p data buffer in bytes.
|
2018-07-12 01:08:58 +02:00
|
|
|
* \param[out] data_length On success, the number of bytes
|
|
|
|
* that make up the key data.
|
2018-02-08 09:47:44 +01:00
|
|
|
*
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_SUCCESS
|
2018-11-30 14:39:32 +01:00
|
|
|
* \retval #PSA_ERROR_INVALID_HANDLE
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_ERROR_EMPTY_SLOT
|
|
|
|
* \retval #PSA_ERROR_NOT_PERMITTED
|
2018-07-24 17:33:30 +02:00
|
|
|
* \retval #PSA_ERROR_NOT_SUPPORTED
|
2018-08-10 19:06:59 +02:00
|
|
|
* \retval #PSA_ERROR_BUFFER_TOO_SMALL
|
|
|
|
* The size of the \p data buffer is too small. You can determine a
|
|
|
|
* sufficient buffer size by calling
|
|
|
|
* #PSA_KEY_EXPORT_MAX_SIZE(\c type, \c bits)
|
|
|
|
* where \c type is the key type
|
|
|
|
* and \c bits is the key size in bits.
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
|
|
|
* \retval #PSA_ERROR_HARDWARE_FAILURE
|
|
|
|
* \retval #PSA_ERROR_TAMPERING_DETECTED
|
2018-09-12 10:44:52 +02:00
|
|
|
* \retval #PSA_ERROR_BAD_STATE
|
2018-09-16 11:22:41 +02:00
|
|
|
* The library has not been previously initialized by psa_crypto_init().
|
|
|
|
* It is implementation-dependent whether a failure to initialize
|
|
|
|
* results in this error code.
|
2018-01-28 13:16:24 +01:00
|
|
|
*/
|
2018-11-30 14:39:32 +01:00
|
|
|
psa_status_t psa_export_key(psa_key_handle_t handle,
|
2018-01-28 13:16:24 +01:00
|
|
|
uint8_t *data,
|
|
|
|
size_t data_size,
|
|
|
|
size_t *data_length);
|
|
|
|
|
2018-03-03 21:30:44 +01:00
|
|
|
/**
|
|
|
|
* \brief Export a public key or the public part of a key pair in binary format.
|
|
|
|
*
|
|
|
|
* The output of this function can be passed to psa_import_key() to
|
|
|
|
* create an object that is equivalent to the public key.
|
|
|
|
*
|
2019-01-11 18:15:56 +01:00
|
|
|
* This specification supports a single format for each key type.
|
|
|
|
* Implementations may support other formats as long as the standard
|
|
|
|
* format is supported. Implementations that support other formats
|
|
|
|
* should ensure that the formats are clearly unambiguous so as to
|
|
|
|
* minimize the risk that an invalid input is accidentally interpreted
|
|
|
|
* according to a different format.
|
|
|
|
*
|
2018-08-10 18:57:40 +02:00
|
|
|
* The format is the DER representation defined by RFC 5280 as
|
|
|
|
* `SubjectPublicKeyInfo`, with the `subjectPublicKey` format
|
|
|
|
* specified below.
|
|
|
|
* ```
|
|
|
|
* SubjectPublicKeyInfo ::= SEQUENCE {
|
|
|
|
* algorithm AlgorithmIdentifier,
|
|
|
|
* subjectPublicKey BIT STRING }
|
|
|
|
* AlgorithmIdentifier ::= SEQUENCE {
|
|
|
|
* algorithm OBJECT IDENTIFIER,
|
|
|
|
* parameters ANY DEFINED BY algorithm OPTIONAL }
|
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* - For RSA public keys (#PSA_KEY_TYPE_RSA_PUBLIC_KEY),
|
|
|
|
* the `subjectPublicKey` format is defined by RFC 3279 §2.3.1 as
|
|
|
|
* `RSAPublicKey`,
|
|
|
|
* with the OID `rsaEncryption`,
|
|
|
|
* and with the parameters `NULL`.
|
|
|
|
* ```
|
|
|
|
* pkcs-1 OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840)
|
|
|
|
* rsadsi(113549) pkcs(1) 1 }
|
|
|
|
* rsaEncryption OBJECT IDENTIFIER ::= { pkcs-1 1 }
|
|
|
|
*
|
|
|
|
* RSAPublicKey ::= SEQUENCE {
|
|
|
|
* modulus INTEGER, -- n
|
|
|
|
* publicExponent INTEGER } -- e
|
|
|
|
* ```
|
|
|
|
* - For DSA public keys (#PSA_KEY_TYPE_DSA_PUBLIC_KEY),
|
|
|
|
* the `subjectPublicKey` format is defined by RFC 3279 §2.3.2 as
|
|
|
|
* `DSAPublicKey`,
|
|
|
|
* with the OID `id-dsa`,
|
|
|
|
* and with the parameters `DSS-Parms`.
|
|
|
|
* ```
|
|
|
|
* id-dsa OBJECT IDENTIFIER ::= {
|
|
|
|
* iso(1) member-body(2) us(840) x9-57(10040) x9cm(4) 1 }
|
|
|
|
*
|
|
|
|
* Dss-Parms ::= SEQUENCE {
|
|
|
|
* p INTEGER,
|
|
|
|
* q INTEGER,
|
|
|
|
* g INTEGER }
|
|
|
|
* DSAPublicKey ::= INTEGER -- public key, Y
|
|
|
|
* ```
|
|
|
|
* - For elliptic curve public keys (key types for which
|
|
|
|
* #PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY is true),
|
|
|
|
* the `subjectPublicKey` format is defined by RFC 3279 §2.3.5 as
|
2018-08-11 01:17:53 +02:00
|
|
|
* `ECPoint`, which contains the uncompressed
|
2018-08-10 18:57:40 +02:00
|
|
|
* representation defined by SEC1 §2.3.3.
|
|
|
|
* The OID is `id-ecPublicKey`,
|
2018-08-11 01:17:53 +02:00
|
|
|
* and the parameters must be given as a `namedCurve` OID as specified in
|
2018-08-13 17:24:59 +02:00
|
|
|
* RFC 5480 §2.1.1.1 or other applicable standards.
|
2018-08-10 18:57:40 +02:00
|
|
|
* ```
|
|
|
|
* ansi-X9-62 OBJECT IDENTIFIER ::=
|
|
|
|
* { iso(1) member-body(2) us(840) 10045 }
|
|
|
|
* id-public-key-type OBJECT IDENTIFIER ::= { ansi-X9.62 2 }
|
|
|
|
* id-ecPublicKey OBJECT IDENTIFIER ::= { id-publicKeyType 1 }
|
|
|
|
*
|
2018-08-11 01:17:53 +02:00
|
|
|
* ECPoint ::= ...
|
|
|
|
* -- first 8 bits: 0x04;
|
2018-11-15 17:44:43 +01:00
|
|
|
* -- then x_P as a `ceiling(m/8)`-byte string, big endian;
|
|
|
|
* -- then y_P as a `ceiling(m/8)`-byte string, big endian;
|
|
|
|
* -- where `m` is the bit size associated with the curve,
|
2018-11-14 21:05:10 +01:00
|
|
|
* -- i.e. the bit size of `q` for a curve over `F_q`.
|
2018-08-10 18:57:40 +02:00
|
|
|
*
|
|
|
|
* EcpkParameters ::= CHOICE { -- other choices are not allowed
|
|
|
|
* namedCurve OBJECT IDENTIFIER }
|
|
|
|
* ```
|
2018-03-03 21:30:44 +01:00
|
|
|
*
|
2018-11-30 14:39:32 +01:00
|
|
|
* \param handle Handle to the key to export.
|
2018-07-12 01:08:58 +02:00
|
|
|
* \param[out] data Buffer where the key data is to be written.
|
2018-07-12 19:23:03 +02:00
|
|
|
* \param data_size Size of the \p data buffer in bytes.
|
2018-07-12 01:08:58 +02:00
|
|
|
* \param[out] data_length On success, the number of bytes
|
|
|
|
* that make up the key data.
|
2018-03-03 21:30:44 +01:00
|
|
|
*
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_SUCCESS
|
2018-11-30 14:39:32 +01:00
|
|
|
* \retval #PSA_ERROR_INVALID_HANDLE
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_ERROR_EMPTY_SLOT
|
|
|
|
* \retval #PSA_ERROR_INVALID_ARGUMENT
|
2018-08-10 19:06:59 +02:00
|
|
|
* The key is neither a public key nor a key pair.
|
|
|
|
* \retval #PSA_ERROR_NOT_SUPPORTED
|
|
|
|
* \retval #PSA_ERROR_BUFFER_TOO_SMALL
|
|
|
|
* The size of the \p data buffer is too small. You can determine a
|
|
|
|
* sufficient buffer size by calling
|
|
|
|
* #PSA_KEY_EXPORT_MAX_SIZE(#PSA_KEY_TYPE_PUBLIC_KEY_OF_KEYPAIR(\c type), \c bits)
|
|
|
|
* where \c type is the key type
|
|
|
|
* and \c bits is the key size in bits.
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
|
|
|
* \retval #PSA_ERROR_HARDWARE_FAILURE
|
|
|
|
* \retval #PSA_ERROR_TAMPERING_DETECTED
|
2018-09-12 10:44:52 +02:00
|
|
|
* \retval #PSA_ERROR_BAD_STATE
|
2018-09-16 11:22:41 +02:00
|
|
|
* The library has not been previously initialized by psa_crypto_init().
|
|
|
|
* It is implementation-dependent whether a failure to initialize
|
|
|
|
* results in this error code.
|
2018-03-03 21:30:44 +01:00
|
|
|
*/
|
2018-11-30 14:39:32 +01:00
|
|
|
psa_status_t psa_export_public_key(psa_key_handle_t handle,
|
2018-03-03 21:30:44 +01:00
|
|
|
uint8_t *data,
|
|
|
|
size_t data_size,
|
|
|
|
size_t *data_length);
|
|
|
|
|
|
|
|
/**@}*/
|
|
|
|
|
|
|
|
/** \defgroup policy Key policies
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** The type of the key policy data structure.
|
2019-01-04 12:47:20 +01:00
|
|
|
*
|
|
|
|
* Before calling any function on a key policy, the application must initialize
|
|
|
|
* it by any of the following means:
|
|
|
|
* - Set the structure to all-bits-zero, for example:
|
|
|
|
* \code
|
|
|
|
* psa_key_policy_t policy;
|
|
|
|
* memset(&policy, 0, sizeof(policy));
|
|
|
|
* \endcode
|
|
|
|
* - Initialize the structure to logical zero values, for example:
|
|
|
|
* \code
|
|
|
|
* psa_key_policy_t policy = {0};
|
|
|
|
* \endcode
|
|
|
|
* - Initialize the structure to the initializer #PSA_KEY_POLICY_INIT,
|
|
|
|
* for example:
|
|
|
|
* \code
|
|
|
|
* psa_key_policy_t policy = PSA_KEY_POLICY_INIT;
|
|
|
|
* \endcode
|
|
|
|
* - Assign the result of the function psa_key_policy_init()
|
|
|
|
* to the structure, for example:
|
|
|
|
* \code
|
|
|
|
* psa_key_policy_t policy;
|
|
|
|
* policy = psa_key_policy_init();
|
|
|
|
* \endcode
|
2018-03-03 21:30:44 +01:00
|
|
|
*
|
|
|
|
* This is an implementation-defined \c struct. Applications should not
|
|
|
|
* make any assumptions about the content of this structure except
|
|
|
|
* as directed by the documentation of a specific implementation. */
|
|
|
|
typedef struct psa_key_policy_s psa_key_policy_t;
|
|
|
|
|
2019-01-04 12:47:20 +01:00
|
|
|
/** \def PSA_KEY_POLICY_INIT
|
2018-07-12 19:47:19 +02:00
|
|
|
*
|
2019-01-04 12:47:20 +01:00
|
|
|
* This macro returns a suitable initializer for a key policy object of type
|
|
|
|
* #psa_key_policy_t.
|
|
|
|
*/
|
|
|
|
#ifdef __DOXYGEN_ONLY__
|
|
|
|
/* This is an example definition for documentation purposes.
|
|
|
|
* Implementations should define a suitable value in `crypto_struct.h`.
|
|
|
|
*/
|
|
|
|
#define PSA_KEY_POLICY_INIT {0}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/** Return an initial value for a key policy that forbids all usage of the key.
|
2018-07-12 19:47:19 +02:00
|
|
|
*/
|
2019-01-04 12:47:20 +01:00
|
|
|
static psa_key_policy_t psa_key_policy_init(void);
|
2018-03-03 21:30:44 +01:00
|
|
|
|
2018-03-08 07:50:30 +01:00
|
|
|
/** \brief Set the standard fields of a policy structure.
|
|
|
|
*
|
|
|
|
* Note that this function does not make any consistency check of the
|
|
|
|
* parameters. The values are only checked when applying the policy to
|
|
|
|
* a key slot with psa_set_key_policy().
|
2018-07-12 19:47:19 +02:00
|
|
|
*
|
2019-01-04 12:47:20 +01:00
|
|
|
* \param[in,out] policy The key policy to modify. It must have been
|
|
|
|
* initialized as per the documentation for
|
|
|
|
* #psa_key_policy_t.
|
|
|
|
* \param usage The permitted uses for the key.
|
|
|
|
* \param alg The algorithm that the key may be used for.
|
2018-03-08 07:50:30 +01:00
|
|
|
*/
|
2018-03-03 21:30:44 +01:00
|
|
|
void psa_key_policy_set_usage(psa_key_policy_t *policy,
|
|
|
|
psa_key_usage_t usage,
|
|
|
|
psa_algorithm_t alg);
|
|
|
|
|
2018-07-12 19:47:19 +02:00
|
|
|
/** \brief Retrieve the usage field of a policy structure.
|
|
|
|
*
|
|
|
|
* \param[in] policy The policy object to query.
|
|
|
|
*
|
|
|
|
* \return The permitted uses for a key with this policy.
|
|
|
|
*/
|
2018-07-12 00:54:56 +02:00
|
|
|
psa_key_usage_t psa_key_policy_get_usage(const psa_key_policy_t *policy);
|
2018-03-03 21:30:44 +01:00
|
|
|
|
2018-07-12 19:47:19 +02:00
|
|
|
/** \brief Retrieve the algorithm field of a policy structure.
|
|
|
|
*
|
|
|
|
* \param[in] policy The policy object to query.
|
|
|
|
*
|
|
|
|
* \return The permitted algorithm for a key with this policy.
|
|
|
|
*/
|
2018-07-12 00:54:56 +02:00
|
|
|
psa_algorithm_t psa_key_policy_get_algorithm(const psa_key_policy_t *policy);
|
2018-03-03 21:30:44 +01:00
|
|
|
|
|
|
|
/** \brief Set the usage policy on a key slot.
|
|
|
|
*
|
|
|
|
* This function must be called on an empty key slot, before importing,
|
|
|
|
* generating or creating a key in the slot. Changing the policy of an
|
|
|
|
* existing key is not permitted.
|
2018-03-08 07:50:30 +01:00
|
|
|
*
|
|
|
|
* Implementations may set restrictions on supported key policies
|
|
|
|
* depending on the key type and the key slot.
|
2018-07-12 19:47:19 +02:00
|
|
|
*
|
2018-11-30 14:39:32 +01:00
|
|
|
* \param handle Handle to the key whose policy is to be changed.
|
2018-07-12 19:47:19 +02:00
|
|
|
* \param[in] policy The policy object to query.
|
|
|
|
*
|
|
|
|
* \retval #PSA_SUCCESS
|
2018-12-11 15:51:32 +01:00
|
|
|
* Success.
|
|
|
|
* If the key is persistent, it is implementation-defined whether
|
|
|
|
* the policy has been saved to persistent storage. Implementations
|
|
|
|
* may defer saving the policy until the key material is created.
|
2018-11-30 14:39:32 +01:00
|
|
|
* \retval #PSA_ERROR_INVALID_HANDLE
|
2018-07-12 19:47:19 +02:00
|
|
|
* \retval #PSA_ERROR_OCCUPIED_SLOT
|
|
|
|
* \retval #PSA_ERROR_NOT_SUPPORTED
|
|
|
|
* \retval #PSA_ERROR_INVALID_ARGUMENT
|
|
|
|
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
|
|
|
* \retval #PSA_ERROR_HARDWARE_FAILURE
|
|
|
|
* \retval #PSA_ERROR_TAMPERING_DETECTED
|
2018-09-12 10:44:52 +02:00
|
|
|
* \retval #PSA_ERROR_BAD_STATE
|
2018-09-16 11:22:41 +02:00
|
|
|
* The library has not been previously initialized by psa_crypto_init().
|
|
|
|
* It is implementation-dependent whether a failure to initialize
|
|
|
|
* results in this error code.
|
2018-03-03 21:30:44 +01:00
|
|
|
*/
|
2018-11-30 14:39:32 +01:00
|
|
|
psa_status_t psa_set_key_policy(psa_key_handle_t handle,
|
2018-03-03 21:30:44 +01:00
|
|
|
const psa_key_policy_t *policy);
|
|
|
|
|
2018-03-08 07:50:30 +01:00
|
|
|
/** \brief Get the usage policy for a key slot.
|
2018-07-12 19:47:19 +02:00
|
|
|
*
|
2018-11-30 14:39:32 +01:00
|
|
|
* \param handle Handle to the key slot whose policy is being queried.
|
2018-07-12 19:47:19 +02:00
|
|
|
* \param[out] policy On success, the key's policy.
|
|
|
|
*
|
|
|
|
* \retval #PSA_SUCCESS
|
2018-11-30 14:39:32 +01:00
|
|
|
* \retval #PSA_ERROR_INVALID_HANDLE
|
2018-07-12 19:47:19 +02:00
|
|
|
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
|
|
|
* \retval #PSA_ERROR_HARDWARE_FAILURE
|
|
|
|
* \retval #PSA_ERROR_TAMPERING_DETECTED
|
2018-09-12 10:44:52 +02:00
|
|
|
* \retval #PSA_ERROR_BAD_STATE
|
2018-09-16 11:22:41 +02:00
|
|
|
* The library has not been previously initialized by psa_crypto_init().
|
|
|
|
* It is implementation-dependent whether a failure to initialize
|
|
|
|
* results in this error code.
|
2018-03-08 07:50:30 +01:00
|
|
|
*/
|
2018-11-30 14:39:32 +01:00
|
|
|
psa_status_t psa_get_key_policy(psa_key_handle_t handle,
|
2018-03-03 21:30:44 +01:00
|
|
|
psa_key_policy_t *policy);
|
2018-02-03 22:44:14 +01:00
|
|
|
|
|
|
|
/**@}*/
|
|
|
|
|
2018-02-07 21:05:37 +01:00
|
|
|
/** \defgroup hash Message digests
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2018-02-08 09:47:44 +01:00
|
|
|
/** The type of the state data structure for multipart hash operations.
|
2019-01-04 12:47:44 +01:00
|
|
|
*
|
|
|
|
* Before calling any function on a hash operation object, the application must
|
|
|
|
* initialize it by any of the following means:
|
|
|
|
* - Set the structure to all-bits-zero, for example:
|
|
|
|
* \code
|
|
|
|
* psa_hash_operation_t operation;
|
|
|
|
* memset(&operation, 0, sizeof(operation));
|
|
|
|
* \endcode
|
|
|
|
* - Initialize the structure to logical zero values, for example:
|
|
|
|
* \code
|
|
|
|
* psa_hash_operation_t operation = {0};
|
|
|
|
* \endcode
|
|
|
|
* - Initialize the structure to the initializer #PSA_HASH_OPERATION_INIT,
|
|
|
|
* for example:
|
|
|
|
* \code
|
|
|
|
* psa_hash_operation_t operation = PSA_HASH_OPERATION_INIT;
|
|
|
|
* \endcode
|
|
|
|
* - Assign the result of the function psa_hash_operation_init()
|
|
|
|
* to the structure, for example:
|
|
|
|
* \code
|
|
|
|
* psa_hash_operation_t operation;
|
|
|
|
* operation = psa_hash_operation_init();
|
|
|
|
* \endcode
|
2018-02-08 09:47:44 +01:00
|
|
|
*
|
2018-03-03 21:29:30 +01:00
|
|
|
* This is an implementation-defined \c struct. Applications should not
|
2018-02-08 09:47:44 +01:00
|
|
|
* make any assumptions about the content of this structure except
|
|
|
|
* as directed by the documentation of a specific implementation. */
|
2018-02-07 21:05:37 +01:00
|
|
|
typedef struct psa_hash_operation_s psa_hash_operation_t;
|
|
|
|
|
2019-01-04 12:47:44 +01:00
|
|
|
/** \def PSA_HASH_OPERATION_INIT
|
|
|
|
*
|
|
|
|
* This macro returns a suitable initializer for a hash operation object
|
|
|
|
* of type #psa_hash_operation_t.
|
|
|
|
*/
|
|
|
|
#ifdef __DOXYGEN_ONLY__
|
|
|
|
/* This is an example definition for documentation purposes.
|
|
|
|
* Implementations should define a suitable value in `crypto_struct.h`.
|
|
|
|
*/
|
|
|
|
#define PSA_HASH_OPERATION_INIT {0}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/** Return an initial value for a hash operation object.
|
|
|
|
*/
|
|
|
|
static psa_hash_operation_t psa_hash_operation_init(void);
|
|
|
|
|
2018-02-08 09:47:44 +01:00
|
|
|
/** Start a multipart hash operation.
|
|
|
|
*
|
|
|
|
* The sequence of operations to calculate a hash (message digest)
|
|
|
|
* is as follows:
|
|
|
|
* -# Allocate an operation object which will be passed to all the functions
|
|
|
|
* listed here.
|
2019-01-04 12:47:44 +01:00
|
|
|
* -# Initialize the operation object with one of the methods described in the
|
|
|
|
* documentation for #psa_hash_operation_t, e.g. PSA_HASH_OPERATION_INIT.
|
2018-07-08 19:46:38 +02:00
|
|
|
* -# Call psa_hash_setup() to specify the algorithm.
|
2018-02-16 21:24:11 +01:00
|
|
|
* -# Call psa_hash_update() zero, one or more times, passing a fragment
|
2018-02-08 09:47:44 +01:00
|
|
|
* of the message each time. The hash that is calculated is the hash
|
|
|
|
* of the concatenation of these messages in order.
|
|
|
|
* -# To calculate the hash, call psa_hash_finish().
|
|
|
|
* To compare the hash with an expected value, call psa_hash_verify().
|
|
|
|
*
|
|
|
|
* The application may call psa_hash_abort() at any time after the operation
|
2019-01-04 12:47:44 +01:00
|
|
|
* has been initialized.
|
2018-02-08 09:47:44 +01:00
|
|
|
*
|
2018-07-08 19:46:38 +02:00
|
|
|
* After a successful call to psa_hash_setup(), the application must
|
2018-03-20 17:54:15 +01:00
|
|
|
* eventually terminate the operation. The following events terminate an
|
|
|
|
* operation:
|
2018-02-08 09:47:44 +01:00
|
|
|
* - A failed call to psa_hash_update().
|
2018-03-20 17:54:53 +01:00
|
|
|
* - A call to psa_hash_finish(), psa_hash_verify() or psa_hash_abort().
|
2018-02-08 09:47:44 +01:00
|
|
|
*
|
2019-01-04 12:47:44 +01:00
|
|
|
* \param[in,out] operation The operation object to set up. It must have
|
|
|
|
* been initialized as per the documentation for
|
|
|
|
* #psa_hash_operation_t and not yet in use.
|
2018-07-12 01:08:58 +02:00
|
|
|
* \param alg The hash algorithm to compute (\c PSA_ALG_XXX value
|
|
|
|
* such that #PSA_ALG_IS_HASH(\p alg) is true).
|
2018-02-08 09:47:44 +01:00
|
|
|
*
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_SUCCESS
|
2018-02-08 09:47:44 +01:00
|
|
|
* Success.
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_ERROR_NOT_SUPPORTED
|
2018-07-12 19:23:03 +02:00
|
|
|
* \p alg is not supported or is not a hash algorithm.
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
|
|
|
|
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
|
|
|
* \retval #PSA_ERROR_HARDWARE_FAILURE
|
|
|
|
* \retval #PSA_ERROR_TAMPERING_DETECTED
|
2018-02-08 09:47:44 +01:00
|
|
|
*/
|
2018-07-08 19:46:38 +02:00
|
|
|
psa_status_t psa_hash_setup(psa_hash_operation_t *operation,
|
2018-02-07 21:05:37 +01:00
|
|
|
psa_algorithm_t alg);
|
|
|
|
|
2018-02-08 09:47:44 +01:00
|
|
|
/** Add a message fragment to a multipart hash operation.
|
|
|
|
*
|
2018-07-08 19:46:38 +02:00
|
|
|
* The application must call psa_hash_setup() before calling this function.
|
2018-02-08 09:47:44 +01:00
|
|
|
*
|
|
|
|
* If this function returns an error status, the operation becomes inactive.
|
|
|
|
*
|
2018-07-12 01:08:58 +02:00
|
|
|
* \param[in,out] operation Active hash operation.
|
|
|
|
* \param[in] input Buffer containing the message fragment to hash.
|
2018-07-12 19:23:03 +02:00
|
|
|
* \param input_length Size of the \p input buffer in bytes.
|
2018-02-08 09:47:44 +01:00
|
|
|
*
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_SUCCESS
|
2018-02-08 09:47:44 +01:00
|
|
|
* Success.
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_ERROR_BAD_STATE
|
2018-02-08 09:47:44 +01:00
|
|
|
* The operation state is not valid (not started, or already completed).
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
|
|
|
|
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
|
|
|
* \retval #PSA_ERROR_HARDWARE_FAILURE
|
|
|
|
* \retval #PSA_ERROR_TAMPERING_DETECTED
|
2018-02-08 09:47:44 +01:00
|
|
|
*/
|
2018-02-07 21:05:37 +01:00
|
|
|
psa_status_t psa_hash_update(psa_hash_operation_t *operation,
|
|
|
|
const uint8_t *input,
|
|
|
|
size_t input_length);
|
|
|
|
|
2018-02-08 09:47:44 +01:00
|
|
|
/** Finish the calculation of the hash of a message.
|
|
|
|
*
|
2018-07-08 19:46:38 +02:00
|
|
|
* The application must call psa_hash_setup() before calling this function.
|
2018-02-08 09:47:44 +01:00
|
|
|
* This function calculates the hash of the message formed by concatenating
|
|
|
|
* the inputs passed to preceding calls to psa_hash_update().
|
|
|
|
*
|
|
|
|
* When this function returns, the operation becomes inactive.
|
|
|
|
*
|
|
|
|
* \warning Applications should not call this function if they expect
|
|
|
|
* a specific value for the hash. Call psa_hash_verify() instead.
|
|
|
|
* Beware that comparing integrity or authenticity data such as
|
|
|
|
* hash values with a function such as \c memcmp is risky
|
|
|
|
* because the time taken by the comparison may leak information
|
|
|
|
* about the hashed data which could allow an attacker to guess
|
|
|
|
* a valid hash and thereby bypass security controls.
|
|
|
|
*
|
2018-07-12 01:08:58 +02:00
|
|
|
* \param[in,out] operation Active hash operation.
|
|
|
|
* \param[out] hash Buffer where the hash is to be written.
|
|
|
|
* \param hash_size Size of the \p hash buffer in bytes.
|
|
|
|
* \param[out] hash_length On success, the number of bytes
|
|
|
|
* that make up the hash value. This is always
|
2018-07-13 14:38:15 +02:00
|
|
|
* #PSA_HASH_SIZE(\c alg) where \c alg is the
|
2018-07-12 01:08:58 +02:00
|
|
|
* hash algorithm that is calculated.
|
2018-02-08 09:47:44 +01:00
|
|
|
*
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_SUCCESS
|
2018-02-08 09:47:44 +01:00
|
|
|
* Success.
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_ERROR_BAD_STATE
|
2018-02-08 09:47:44 +01:00
|
|
|
* The operation state is not valid (not started, or already completed).
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_ERROR_BUFFER_TOO_SMALL
|
2018-07-12 19:23:03 +02:00
|
|
|
* The size of the \p hash buffer is too small. You can determine a
|
2018-07-12 00:34:26 +02:00
|
|
|
* sufficient buffer size by calling #PSA_HASH_SIZE(\c alg)
|
2018-02-08 09:47:44 +01:00
|
|
|
* where \c alg is the hash algorithm that is calculated.
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
|
|
|
|
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
|
|
|
* \retval #PSA_ERROR_HARDWARE_FAILURE
|
|
|
|
* \retval #PSA_ERROR_TAMPERING_DETECTED
|
2018-02-08 09:47:44 +01:00
|
|
|
*/
|
2018-02-07 21:05:37 +01:00
|
|
|
psa_status_t psa_hash_finish(psa_hash_operation_t *operation,
|
|
|
|
uint8_t *hash,
|
|
|
|
size_t hash_size,
|
|
|
|
size_t *hash_length);
|
|
|
|
|
2018-02-08 09:47:44 +01:00
|
|
|
/** Finish the calculation of the hash of a message and compare it with
|
|
|
|
* an expected value.
|
|
|
|
*
|
2018-07-08 19:46:38 +02:00
|
|
|
* The application must call psa_hash_setup() before calling this function.
|
2018-02-08 09:47:44 +01:00
|
|
|
* This function calculates the hash of the message formed by concatenating
|
|
|
|
* the inputs passed to preceding calls to psa_hash_update(). It then
|
|
|
|
* compares the calculated hash with the expected hash passed as a
|
|
|
|
* parameter to this function.
|
|
|
|
*
|
|
|
|
* When this function returns, the operation becomes inactive.
|
|
|
|
*
|
2018-03-20 17:54:53 +01:00
|
|
|
* \note Implementations shall make the best effort to ensure that the
|
2018-02-08 09:47:44 +01:00
|
|
|
* comparison between the actual hash and the expected hash is performed
|
|
|
|
* in constant time.
|
|
|
|
*
|
2018-07-12 01:08:58 +02:00
|
|
|
* \param[in,out] operation Active hash operation.
|
|
|
|
* \param[in] hash Buffer containing the expected hash value.
|
2018-07-12 19:23:03 +02:00
|
|
|
* \param hash_length Size of the \p hash buffer in bytes.
|
2018-02-08 09:47:44 +01:00
|
|
|
*
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_SUCCESS
|
2018-02-08 09:47:44 +01:00
|
|
|
* The expected hash is identical to the actual hash of the message.
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_ERROR_INVALID_SIGNATURE
|
2018-02-08 09:47:44 +01:00
|
|
|
* The hash of the message was calculated successfully, but it
|
|
|
|
* differs from the expected hash.
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_ERROR_BAD_STATE
|
2018-02-08 09:47:44 +01:00
|
|
|
* The operation state is not valid (not started, or already completed).
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
|
|
|
|
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
|
|
|
* \retval #PSA_ERROR_HARDWARE_FAILURE
|
|
|
|
* \retval #PSA_ERROR_TAMPERING_DETECTED
|
2018-02-08 09:47:44 +01:00
|
|
|
*/
|
2018-02-07 21:05:37 +01:00
|
|
|
psa_status_t psa_hash_verify(psa_hash_operation_t *operation,
|
|
|
|
const uint8_t *hash,
|
|
|
|
size_t hash_length);
|
|
|
|
|
2018-02-08 09:47:44 +01:00
|
|
|
/** Abort a hash operation.
|
|
|
|
*
|
|
|
|
* Aborting an operation frees all associated resources except for the
|
2018-07-13 15:33:43 +02:00
|
|
|
* \p operation structure itself. Once aborted, the operation object
|
|
|
|
* can be reused for another operation by calling
|
|
|
|
* psa_hash_setup() again.
|
2018-02-08 09:47:44 +01:00
|
|
|
*
|
2018-07-13 15:33:43 +02:00
|
|
|
* You may call this function any time after the operation object has
|
|
|
|
* been initialized by any of the following methods:
|
|
|
|
* - A call to psa_hash_setup(), whether it succeeds or not.
|
|
|
|
* - Initializing the \c struct to all-bits-zero.
|
|
|
|
* - Initializing the \c struct to logical zeros, e.g.
|
|
|
|
* `psa_hash_operation_t operation = {0}`.
|
2018-02-08 09:47:44 +01:00
|
|
|
*
|
2018-07-13 15:33:43 +02:00
|
|
|
* In particular, calling psa_hash_abort() after the operation has been
|
|
|
|
* terminated by a call to psa_hash_abort(), psa_hash_finish() or
|
|
|
|
* psa_hash_verify() is safe and has no effect.
|
|
|
|
*
|
|
|
|
* \param[in,out] operation Initialized hash operation.
|
2018-02-08 09:47:44 +01:00
|
|
|
*
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_SUCCESS
|
|
|
|
* \retval #PSA_ERROR_BAD_STATE
|
2018-07-12 19:23:03 +02:00
|
|
|
* \p operation is not an active hash operation.
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
|
|
|
* \retval #PSA_ERROR_HARDWARE_FAILURE
|
|
|
|
* \retval #PSA_ERROR_TAMPERING_DETECTED
|
2018-02-08 09:47:44 +01:00
|
|
|
*/
|
|
|
|
psa_status_t psa_hash_abort(psa_hash_operation_t *operation);
|
2018-02-07 21:05:37 +01:00
|
|
|
|
|
|
|
/**@}*/
|
|
|
|
|
2018-02-08 10:02:12 +01:00
|
|
|
/** \defgroup MAC Message authentication codes
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2018-02-16 21:24:11 +01:00
|
|
|
/** The type of the state data structure for multipart MAC operations.
|
2019-01-04 12:48:03 +01:00
|
|
|
*
|
|
|
|
* Before calling any function on a MAC operation object, the application must
|
|
|
|
* initialize it by any of the following means:
|
|
|
|
* - Set the structure to all-bits-zero, for example:
|
|
|
|
* \code
|
|
|
|
* psa_mac_operation_t operation;
|
|
|
|
* memset(&operation, 0, sizeof(operation));
|
|
|
|
* \endcode
|
|
|
|
* - Initialize the structure to logical zero values, for example:
|
|
|
|
* \code
|
|
|
|
* psa_mac_operation_t operation = {0};
|
|
|
|
* \endcode
|
|
|
|
* - Initialize the structure to the initializer #PSA_MAC_OPERATION_INIT,
|
|
|
|
* for example:
|
|
|
|
* \code
|
|
|
|
* psa_mac_operation_t operation = PSA_MAC_OPERATION_INIT;
|
|
|
|
* \endcode
|
|
|
|
* - Assign the result of the function psa_mac_operation_init()
|
|
|
|
* to the structure, for example:
|
|
|
|
* \code
|
|
|
|
* psa_mac_operation_t operation;
|
|
|
|
* operation = psa_mac_operation_init();
|
|
|
|
* \endcode
|
2018-02-16 21:24:11 +01:00
|
|
|
*
|
2018-03-03 21:29:30 +01:00
|
|
|
* This is an implementation-defined \c struct. Applications should not
|
2018-02-16 21:24:11 +01:00
|
|
|
* make any assumptions about the content of this structure except
|
|
|
|
* as directed by the documentation of a specific implementation. */
|
2018-02-08 10:02:12 +01:00
|
|
|
typedef struct psa_mac_operation_s psa_mac_operation_t;
|
|
|
|
|
2019-01-04 12:48:03 +01:00
|
|
|
/** \def PSA_MAC_OPERATION_INIT
|
|
|
|
*
|
|
|
|
* This macro returns a suitable initializer for a MAC operation object of type
|
|
|
|
* #psa_mac_operation_t.
|
|
|
|
*/
|
|
|
|
#ifdef __DOXYGEN_ONLY__
|
|
|
|
/* This is an example definition for documentation purposes.
|
|
|
|
* Implementations should define a suitable value in `crypto_struct.h`.
|
|
|
|
*/
|
|
|
|
#define PSA_MAC_OPERATION_INIT {0}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/** Return an initial value for a MAC operation object.
|
|
|
|
*/
|
|
|
|
static psa_mac_operation_t psa_mac_operation_init(void);
|
|
|
|
|
2018-07-08 20:12:23 +02:00
|
|
|
/** Start a multipart MAC calculation operation.
|
2018-02-16 21:24:11 +01:00
|
|
|
*
|
2018-07-08 20:12:23 +02:00
|
|
|
* This function sets up the calculation of the MAC
|
|
|
|
* (message authentication code) of a byte string.
|
|
|
|
* To verify the MAC of a message against an
|
|
|
|
* expected value, use psa_mac_verify_setup() instead.
|
|
|
|
*
|
|
|
|
* The sequence of operations to calculate a MAC is as follows:
|
2018-02-16 21:24:11 +01:00
|
|
|
* -# Allocate an operation object which will be passed to all the functions
|
|
|
|
* listed here.
|
2019-01-04 12:48:03 +01:00
|
|
|
* -# Initialize the operation object with one of the methods described in the
|
|
|
|
* documentation for #psa_mac_operation_t, e.g. PSA_MAC_OPERATION_INIT.
|
2018-07-08 20:12:23 +02:00
|
|
|
* -# Call psa_mac_sign_setup() to specify the algorithm and key.
|
2018-02-16 21:24:11 +01:00
|
|
|
* The key remains associated with the operation even if the content
|
|
|
|
* of the key slot changes.
|
|
|
|
* -# Call psa_mac_update() zero, one or more times, passing a fragment
|
|
|
|
* of the message each time. The MAC that is calculated is the MAC
|
|
|
|
* of the concatenation of these messages in order.
|
2018-07-08 20:12:23 +02:00
|
|
|
* -# At the end of the message, call psa_mac_sign_finish() to finish
|
|
|
|
* calculating the MAC value and retrieve it.
|
2018-02-16 21:24:11 +01:00
|
|
|
*
|
|
|
|
* The application may call psa_mac_abort() at any time after the operation
|
2019-01-04 12:48:03 +01:00
|
|
|
* has been initialized.
|
2018-02-16 21:24:11 +01:00
|
|
|
*
|
2018-07-08 20:12:23 +02:00
|
|
|
* After a successful call to psa_mac_sign_setup(), the application must
|
|
|
|
* eventually terminate the operation through one of the following methods:
|
|
|
|
* - A failed call to psa_mac_update().
|
|
|
|
* - A call to psa_mac_sign_finish() or psa_mac_abort().
|
|
|
|
*
|
2019-01-04 12:48:03 +01:00
|
|
|
* \param[in,out] operation The operation object to set up. It must have
|
|
|
|
* been initialized as per the documentation for
|
|
|
|
* #psa_mac_operation_t and not yet in use.
|
2018-11-30 14:39:32 +01:00
|
|
|
* \param handle Handle to the key to use for the operation.
|
2018-07-12 01:08:58 +02:00
|
|
|
* \param alg The MAC algorithm to compute (\c PSA_ALG_XXX value
|
|
|
|
* such that #PSA_ALG_IS_MAC(alg) is true).
|
2018-07-08 20:12:23 +02:00
|
|
|
*
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_SUCCESS
|
2018-07-08 20:12:23 +02:00
|
|
|
* Success.
|
2018-11-30 14:39:32 +01:00
|
|
|
* \retval #PSA_ERROR_INVALID_HANDLE
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_ERROR_EMPTY_SLOT
|
|
|
|
* \retval #PSA_ERROR_NOT_PERMITTED
|
|
|
|
* \retval #PSA_ERROR_INVALID_ARGUMENT
|
2018-07-12 19:23:03 +02:00
|
|
|
* \p key is not compatible with \p alg.
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_ERROR_NOT_SUPPORTED
|
2018-07-12 19:23:03 +02:00
|
|
|
* \p alg is not supported or is not a MAC algorithm.
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
|
|
|
|
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
|
|
|
* \retval #PSA_ERROR_HARDWARE_FAILURE
|
|
|
|
* \retval #PSA_ERROR_TAMPERING_DETECTED
|
2018-09-12 10:44:52 +02:00
|
|
|
* \retval #PSA_ERROR_BAD_STATE
|
2018-09-16 11:22:41 +02:00
|
|
|
* The library has not been previously initialized by psa_crypto_init().
|
|
|
|
* It is implementation-dependent whether a failure to initialize
|
|
|
|
* results in this error code.
|
2018-07-08 20:12:23 +02:00
|
|
|
*/
|
|
|
|
psa_status_t psa_mac_sign_setup(psa_mac_operation_t *operation,
|
2018-11-30 14:39:32 +01:00
|
|
|
psa_key_handle_t handle,
|
2018-07-08 20:12:23 +02:00
|
|
|
psa_algorithm_t alg);
|
|
|
|
|
|
|
|
/** Start a multipart MAC verification operation.
|
|
|
|
*
|
|
|
|
* This function sets up the verification of the MAC
|
|
|
|
* (message authentication code) of a byte string against an expected value.
|
|
|
|
*
|
|
|
|
* The sequence of operations to verify a MAC is as follows:
|
|
|
|
* -# Allocate an operation object which will be passed to all the functions
|
|
|
|
* listed here.
|
2019-01-04 12:48:03 +01:00
|
|
|
* -# Initialize the operation object with one of the methods described in the
|
|
|
|
* documentation for #psa_mac_operation_t, e.g. PSA_MAC_OPERATION_INIT.
|
2018-07-08 20:12:23 +02:00
|
|
|
* -# Call psa_mac_verify_setup() to specify the algorithm and key.
|
|
|
|
* The key remains associated with the operation even if the content
|
|
|
|
* of the key slot changes.
|
|
|
|
* -# Call psa_mac_update() zero, one or more times, passing a fragment
|
|
|
|
* of the message each time. The MAC that is calculated is the MAC
|
|
|
|
* of the concatenation of these messages in order.
|
|
|
|
* -# At the end of the message, call psa_mac_verify_finish() to finish
|
|
|
|
* calculating the actual MAC of the message and verify it against
|
|
|
|
* the expected value.
|
|
|
|
*
|
|
|
|
* The application may call psa_mac_abort() at any time after the operation
|
2019-01-04 12:48:03 +01:00
|
|
|
* has been initialized.
|
2018-07-08 20:12:23 +02:00
|
|
|
*
|
|
|
|
* After a successful call to psa_mac_verify_setup(), the application must
|
|
|
|
* eventually terminate the operation through one of the following methods:
|
2018-02-16 21:24:11 +01:00
|
|
|
* - A failed call to psa_mac_update().
|
2018-07-08 20:12:23 +02:00
|
|
|
* - A call to psa_mac_verify_finish() or psa_mac_abort().
|
2018-02-16 21:24:11 +01:00
|
|
|
*
|
2019-01-04 12:48:03 +01:00
|
|
|
* \param[in,out] operation The operation object to set up. It must have
|
|
|
|
* been initialized as per the documentation for
|
|
|
|
* #psa_mac_operation_t and not yet in use.
|
2018-11-30 14:39:32 +01:00
|
|
|
* \param handle Handle to the key to use for the operation.
|
2018-07-12 01:08:58 +02:00
|
|
|
* \param alg The MAC algorithm to compute (\c PSA_ALG_XXX value
|
|
|
|
* such that #PSA_ALG_IS_MAC(\p alg) is true).
|
2018-02-16 21:24:11 +01:00
|
|
|
*
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_SUCCESS
|
2018-02-16 21:24:11 +01:00
|
|
|
* Success.
|
2018-11-30 14:39:32 +01:00
|
|
|
* \retval #PSA_ERROR_INVALID_HANDLE
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_ERROR_EMPTY_SLOT
|
|
|
|
* \retval #PSA_ERROR_NOT_PERMITTED
|
|
|
|
* \retval #PSA_ERROR_INVALID_ARGUMENT
|
2018-02-16 21:24:11 +01:00
|
|
|
* \c key is not compatible with \c alg.
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_ERROR_NOT_SUPPORTED
|
2018-02-16 21:24:11 +01:00
|
|
|
* \c alg is not supported or is not a MAC algorithm.
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
|
|
|
|
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
|
|
|
* \retval #PSA_ERROR_HARDWARE_FAILURE
|
|
|
|
* \retval #PSA_ERROR_TAMPERING_DETECTED
|
2018-09-12 10:44:52 +02:00
|
|
|
* \retval #PSA_ERROR_BAD_STATE
|
2018-09-16 11:22:41 +02:00
|
|
|
* The library has not been previously initialized by psa_crypto_init().
|
|
|
|
* It is implementation-dependent whether a failure to initialize
|
|
|
|
* results in this error code.
|
2018-02-16 21:24:11 +01:00
|
|
|
*/
|
2018-07-08 20:12:23 +02:00
|
|
|
psa_status_t psa_mac_verify_setup(psa_mac_operation_t *operation,
|
2018-11-30 14:39:32 +01:00
|
|
|
psa_key_handle_t handle,
|
2018-07-08 20:12:23 +02:00
|
|
|
psa_algorithm_t alg);
|
2018-02-08 10:02:12 +01:00
|
|
|
|
2018-07-12 00:30:52 +02:00
|
|
|
/** Add a message fragment to a multipart MAC operation.
|
|
|
|
*
|
|
|
|
* The application must call psa_mac_sign_setup() or psa_mac_verify_setup()
|
|
|
|
* before calling this function.
|
|
|
|
*
|
|
|
|
* If this function returns an error status, the operation becomes inactive.
|
|
|
|
*
|
2018-07-12 01:08:58 +02:00
|
|
|
* \param[in,out] operation Active MAC operation.
|
|
|
|
* \param[in] input Buffer containing the message fragment to add to
|
|
|
|
* the MAC calculation.
|
2018-07-12 19:23:03 +02:00
|
|
|
* \param input_length Size of the \p input buffer in bytes.
|
2018-07-12 00:30:52 +02:00
|
|
|
*
|
|
|
|
* \retval #PSA_SUCCESS
|
|
|
|
* Success.
|
|
|
|
* \retval #PSA_ERROR_BAD_STATE
|
|
|
|
* The operation state is not valid (not started, or already completed).
|
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
|
|
|
|
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
|
|
|
* \retval #PSA_ERROR_HARDWARE_FAILURE
|
|
|
|
* \retval #PSA_ERROR_TAMPERING_DETECTED
|
|
|
|
*/
|
2018-02-08 10:02:12 +01:00
|
|
|
psa_status_t psa_mac_update(psa_mac_operation_t *operation,
|
|
|
|
const uint8_t *input,
|
|
|
|
size_t input_length);
|
|
|
|
|
2018-07-12 00:30:52 +02:00
|
|
|
/** Finish the calculation of the MAC of a message.
|
|
|
|
*
|
|
|
|
* The application must call psa_mac_sign_setup() before calling this function.
|
|
|
|
* This function calculates the MAC of the message formed by concatenating
|
|
|
|
* the inputs passed to preceding calls to psa_mac_update().
|
|
|
|
*
|
|
|
|
* When this function returns, the operation becomes inactive.
|
|
|
|
*
|
|
|
|
* \warning Applications should not call this function if they expect
|
|
|
|
* a specific value for the MAC. Call psa_mac_verify_finish() instead.
|
|
|
|
* Beware that comparing integrity or authenticity data such as
|
|
|
|
* MAC values with a function such as \c memcmp is risky
|
|
|
|
* because the time taken by the comparison may leak information
|
|
|
|
* about the MAC value which could allow an attacker to guess
|
|
|
|
* a valid MAC and thereby bypass security controls.
|
|
|
|
*
|
2018-07-12 01:08:58 +02:00
|
|
|
* \param[in,out] operation Active MAC operation.
|
|
|
|
* \param[out] mac Buffer where the MAC value is to be written.
|
|
|
|
* \param mac_size Size of the \p mac buffer in bytes.
|
|
|
|
* \param[out] mac_length On success, the number of bytes
|
|
|
|
* that make up the MAC value. This is always
|
2018-07-12 19:40:46 +02:00
|
|
|
* #PSA_MAC_FINAL_SIZE(\c key_type, \c key_bits, \c alg)
|
2018-07-12 01:08:58 +02:00
|
|
|
* where \c key_type and \c key_bits are the type and
|
2018-07-12 19:40:46 +02:00
|
|
|
* bit-size respectively of the key and \c alg is the
|
2018-07-12 01:08:58 +02:00
|
|
|
* MAC algorithm that is calculated.
|
2018-07-12 00:30:52 +02:00
|
|
|
*
|
|
|
|
* \retval #PSA_SUCCESS
|
|
|
|
* Success.
|
|
|
|
* \retval #PSA_ERROR_BAD_STATE
|
|
|
|
* The operation state is not valid (not started, or already completed).
|
|
|
|
* \retval #PSA_ERROR_BUFFER_TOO_SMALL
|
2018-07-12 19:23:03 +02:00
|
|
|
* The size of the \p mac buffer is too small. You can determine a
|
2018-07-12 00:30:52 +02:00
|
|
|
* sufficient buffer size by calling PSA_MAC_FINAL_SIZE().
|
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
|
|
|
|
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
|
|
|
* \retval #PSA_ERROR_HARDWARE_FAILURE
|
|
|
|
* \retval #PSA_ERROR_TAMPERING_DETECTED
|
|
|
|
*/
|
2018-07-08 19:56:25 +02:00
|
|
|
psa_status_t psa_mac_sign_finish(psa_mac_operation_t *operation,
|
|
|
|
uint8_t *mac,
|
|
|
|
size_t mac_size,
|
|
|
|
size_t *mac_length);
|
2018-02-08 10:02:12 +01:00
|
|
|
|
2018-07-12 00:30:52 +02:00
|
|
|
/** Finish the calculation of the MAC of a message and compare it with
|
|
|
|
* an expected value.
|
|
|
|
*
|
|
|
|
* The application must call psa_mac_verify_setup() before calling this function.
|
|
|
|
* This function calculates the MAC of the message formed by concatenating
|
|
|
|
* the inputs passed to preceding calls to psa_mac_update(). It then
|
|
|
|
* compares the calculated MAC with the expected MAC passed as a
|
|
|
|
* parameter to this function.
|
|
|
|
*
|
|
|
|
* When this function returns, the operation becomes inactive.
|
|
|
|
*
|
|
|
|
* \note Implementations shall make the best effort to ensure that the
|
|
|
|
* comparison between the actual MAC and the expected MAC is performed
|
|
|
|
* in constant time.
|
|
|
|
*
|
2018-07-12 01:08:58 +02:00
|
|
|
* \param[in,out] operation Active MAC operation.
|
|
|
|
* \param[in] mac Buffer containing the expected MAC value.
|
2018-07-12 19:23:03 +02:00
|
|
|
* \param mac_length Size of the \p mac buffer in bytes.
|
2018-07-12 00:30:52 +02:00
|
|
|
*
|
|
|
|
* \retval #PSA_SUCCESS
|
|
|
|
* The expected MAC is identical to the actual MAC of the message.
|
|
|
|
* \retval #PSA_ERROR_INVALID_SIGNATURE
|
|
|
|
* The MAC of the message was calculated successfully, but it
|
|
|
|
* differs from the expected MAC.
|
|
|
|
* \retval #PSA_ERROR_BAD_STATE
|
|
|
|
* The operation state is not valid (not started, or already completed).
|
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
|
|
|
|
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
|
|
|
* \retval #PSA_ERROR_HARDWARE_FAILURE
|
|
|
|
* \retval #PSA_ERROR_TAMPERING_DETECTED
|
|
|
|
*/
|
2018-07-08 19:56:25 +02:00
|
|
|
psa_status_t psa_mac_verify_finish(psa_mac_operation_t *operation,
|
|
|
|
const uint8_t *mac,
|
|
|
|
size_t mac_length);
|
2018-02-08 10:02:12 +01:00
|
|
|
|
2018-07-12 00:30:52 +02:00
|
|
|
/** Abort a MAC operation.
|
|
|
|
*
|
|
|
|
* Aborting an operation frees all associated resources except for the
|
2018-07-13 15:33:43 +02:00
|
|
|
* \p operation structure itself. Once aborted, the operation object
|
|
|
|
* can be reused for another operation by calling
|
|
|
|
* psa_mac_sign_setup() or psa_mac_verify_setup() again.
|
2018-07-12 00:30:52 +02:00
|
|
|
*
|
2018-07-13 15:33:43 +02:00
|
|
|
* You may call this function any time after the operation object has
|
|
|
|
* been initialized by any of the following methods:
|
|
|
|
* - A call to psa_mac_sign_setup() or psa_mac_verify_setup(), whether
|
|
|
|
* it succeeds or not.
|
|
|
|
* - Initializing the \c struct to all-bits-zero.
|
|
|
|
* - Initializing the \c struct to logical zeros, e.g.
|
|
|
|
* `psa_mac_operation_t operation = {0}`.
|
2018-07-12 00:30:52 +02:00
|
|
|
*
|
2018-07-13 15:33:43 +02:00
|
|
|
* In particular, calling psa_mac_abort() after the operation has been
|
|
|
|
* terminated by a call to psa_mac_abort(), psa_mac_sign_finish() or
|
|
|
|
* psa_mac_verify_finish() is safe and has no effect.
|
|
|
|
*
|
|
|
|
* \param[in,out] operation Initialized MAC operation.
|
2018-07-12 00:30:52 +02:00
|
|
|
*
|
|
|
|
* \retval #PSA_SUCCESS
|
|
|
|
* \retval #PSA_ERROR_BAD_STATE
|
2018-07-12 19:23:03 +02:00
|
|
|
* \p operation is not an active MAC operation.
|
2018-07-12 00:30:52 +02:00
|
|
|
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
|
|
|
* \retval #PSA_ERROR_HARDWARE_FAILURE
|
|
|
|
* \retval #PSA_ERROR_TAMPERING_DETECTED
|
|
|
|
*/
|
2018-02-08 10:02:12 +01:00
|
|
|
psa_status_t psa_mac_abort(psa_mac_operation_t *operation);
|
|
|
|
|
|
|
|
/**@}*/
|
|
|
|
|
2018-03-03 21:27:18 +01:00
|
|
|
/** \defgroup cipher Symmetric ciphers
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** The type of the state data structure for multipart cipher operations.
|
2019-01-04 12:48:27 +01:00
|
|
|
*
|
|
|
|
* Before calling any function on a cipher operation object, the application
|
|
|
|
* must initialize it by any of the following means:
|
|
|
|
* - Set the structure to all-bits-zero, for example:
|
|
|
|
* \code
|
|
|
|
* psa_cipher_operation_t operation;
|
|
|
|
* memset(&operation, 0, sizeof(operation));
|
|
|
|
* \endcode
|
|
|
|
* - Initialize the structure to logical zero values, for example:
|
|
|
|
* \code
|
|
|
|
* psa_cipher_operation_t operation = {0};
|
|
|
|
* \endcode
|
|
|
|
* - Initialize the structure to the initializer #PSA_CIPHER_OPERATION_INIT,
|
|
|
|
* for example:
|
|
|
|
* \code
|
|
|
|
* psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_INIT;
|
|
|
|
* \endcode
|
|
|
|
* - Assign the result of the function psa_cipher_operation_init()
|
|
|
|
* to the structure, for example:
|
|
|
|
* \code
|
|
|
|
* psa_cipher_operation_t operation;
|
|
|
|
* operation = psa_cipher_operation_init();
|
|
|
|
* \endcode
|
2018-03-03 21:27:18 +01:00
|
|
|
*
|
|
|
|
* This is an implementation-defined \c struct. Applications should not
|
|
|
|
* make any assumptions about the content of this structure except
|
|
|
|
* as directed by the documentation of a specific implementation. */
|
|
|
|
typedef struct psa_cipher_operation_s psa_cipher_operation_t;
|
|
|
|
|
2019-01-04 12:48:27 +01:00
|
|
|
/** \def PSA_CIPHER_OPERATION_INIT
|
|
|
|
*
|
|
|
|
* This macro returns a suitable initializer for a cipher operation object of
|
|
|
|
* type #psa_cipher_operation_t.
|
|
|
|
*/
|
|
|
|
#ifdef __DOXYGEN_ONLY__
|
|
|
|
/* This is an example definition for documentation purposes.
|
|
|
|
* Implementations should define a suitable value in `crypto_struct.h`.
|
|
|
|
*/
|
|
|
|
#define PSA_CIPHER_OPERATION_INIT {0}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/** Return an initial value for a cipher operation object.
|
|
|
|
*/
|
|
|
|
static psa_cipher_operation_t psa_cipher_operation_init(void);
|
|
|
|
|
2018-03-03 21:27:18 +01:00
|
|
|
/** Set the key for a multipart symmetric encryption operation.
|
|
|
|
*
|
|
|
|
* The sequence of operations to encrypt a message with a symmetric cipher
|
|
|
|
* is as follows:
|
|
|
|
* -# Allocate an operation object which will be passed to all the functions
|
|
|
|
* listed here.
|
2019-01-04 12:48:27 +01:00
|
|
|
* -# Initialize the operation object with one of the methods described in the
|
|
|
|
* documentation for #psa_cipher_operation_t, e.g.
|
|
|
|
* PSA_CIPHER_OPERATION_INIT.
|
2018-07-08 21:39:34 +02:00
|
|
|
* -# Call psa_cipher_encrypt_setup() to specify the algorithm and key.
|
2018-03-03 21:27:18 +01:00
|
|
|
* The key remains associated with the operation even if the content
|
|
|
|
* of the key slot changes.
|
2018-08-02 13:19:33 +02:00
|
|
|
* -# Call either psa_cipher_generate_iv() or psa_cipher_set_iv() to
|
2018-03-03 21:27:18 +01:00
|
|
|
* generate or set the IV (initialization vector). You should use
|
2018-08-02 13:19:33 +02:00
|
|
|
* psa_cipher_generate_iv() unless the protocol you are implementing
|
2018-03-03 21:27:18 +01:00
|
|
|
* requires a specific IV value.
|
|
|
|
* -# Call psa_cipher_update() zero, one or more times, passing a fragment
|
|
|
|
* of the message each time.
|
|
|
|
* -# Call psa_cipher_finish().
|
|
|
|
*
|
|
|
|
* The application may call psa_cipher_abort() at any time after the operation
|
2019-01-04 12:48:27 +01:00
|
|
|
* has been initialized.
|
2018-03-03 21:27:18 +01:00
|
|
|
*
|
2018-07-08 21:39:34 +02:00
|
|
|
* After a successful call to psa_cipher_encrypt_setup(), the application must
|
2018-03-20 17:54:15 +01:00
|
|
|
* eventually terminate the operation. The following events terminate an
|
|
|
|
* operation:
|
2018-08-02 13:19:33 +02:00
|
|
|
* - A failed call to psa_cipher_generate_iv(), psa_cipher_set_iv()
|
2018-03-03 21:27:18 +01:00
|
|
|
* or psa_cipher_update().
|
2018-03-20 17:54:53 +01:00
|
|
|
* - A call to psa_cipher_finish() or psa_cipher_abort().
|
2018-03-03 21:27:18 +01:00
|
|
|
*
|
2019-01-04 12:48:27 +01:00
|
|
|
* \param[in,out] operation The operation object to set up. It must have
|
|
|
|
* been initialized as per the documentation for
|
|
|
|
* #psa_cipher_operation_t and not yet in use.
|
2018-11-30 14:39:32 +01:00
|
|
|
* \param handle Handle to the key to use for the operation.
|
2018-07-12 01:08:58 +02:00
|
|
|
* \param alg The cipher algorithm to compute
|
|
|
|
* (\c PSA_ALG_XXX value such that
|
|
|
|
* #PSA_ALG_IS_CIPHER(\p alg) is true).
|
2018-03-03 21:27:18 +01:00
|
|
|
*
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_SUCCESS
|
2018-03-03 21:27:18 +01:00
|
|
|
* Success.
|
2018-11-30 14:39:32 +01:00
|
|
|
* \retval #PSA_ERROR_INVALID_HANDLE
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_ERROR_EMPTY_SLOT
|
|
|
|
* \retval #PSA_ERROR_NOT_PERMITTED
|
|
|
|
* \retval #PSA_ERROR_INVALID_ARGUMENT
|
2018-07-12 19:23:03 +02:00
|
|
|
* \p key is not compatible with \p alg.
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_ERROR_NOT_SUPPORTED
|
2018-07-12 19:23:03 +02:00
|
|
|
* \p alg is not supported or is not a cipher algorithm.
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
|
|
|
|
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
|
|
|
* \retval #PSA_ERROR_HARDWARE_FAILURE
|
|
|
|
* \retval #PSA_ERROR_TAMPERING_DETECTED
|
2018-09-12 10:44:52 +02:00
|
|
|
* \retval #PSA_ERROR_BAD_STATE
|
2018-09-16 11:22:41 +02:00
|
|
|
* The library has not been previously initialized by psa_crypto_init().
|
|
|
|
* It is implementation-dependent whether a failure to initialize
|
|
|
|
* results in this error code.
|
2018-03-03 21:27:18 +01:00
|
|
|
*/
|
2018-07-08 21:39:34 +02:00
|
|
|
psa_status_t psa_cipher_encrypt_setup(psa_cipher_operation_t *operation,
|
2018-11-30 14:39:32 +01:00
|
|
|
psa_key_handle_t handle,
|
2018-07-08 21:39:34 +02:00
|
|
|
psa_algorithm_t alg);
|
2018-03-03 21:27:18 +01:00
|
|
|
|
|
|
|
/** Set the key for a multipart symmetric decryption operation.
|
|
|
|
*
|
|
|
|
* The sequence of operations to decrypt a message with a symmetric cipher
|
|
|
|
* is as follows:
|
|
|
|
* -# Allocate an operation object which will be passed to all the functions
|
|
|
|
* listed here.
|
2019-01-04 12:48:27 +01:00
|
|
|
* -# Initialize the operation object with one of the methods described in the
|
|
|
|
* documentation for #psa_cipher_operation_t, e.g.
|
|
|
|
* PSA_CIPHER_OPERATION_INIT.
|
2018-07-08 21:39:34 +02:00
|
|
|
* -# Call psa_cipher_decrypt_setup() to specify the algorithm and key.
|
2018-03-03 21:27:18 +01:00
|
|
|
* The key remains associated with the operation even if the content
|
|
|
|
* of the key slot changes.
|
|
|
|
* -# Call psa_cipher_update() with the IV (initialization vector) for the
|
|
|
|
* decryption. If the IV is prepended to the ciphertext, you can call
|
|
|
|
* psa_cipher_update() on a buffer containing the IV followed by the
|
|
|
|
* beginning of the message.
|
|
|
|
* -# Call psa_cipher_update() zero, one or more times, passing a fragment
|
|
|
|
* of the message each time.
|
|
|
|
* -# Call psa_cipher_finish().
|
|
|
|
*
|
|
|
|
* The application may call psa_cipher_abort() at any time after the operation
|
2019-01-04 12:48:27 +01:00
|
|
|
* has been initialized.
|
2018-03-03 21:27:18 +01:00
|
|
|
*
|
2018-07-08 21:39:34 +02:00
|
|
|
* After a successful call to psa_cipher_decrypt_setup(), the application must
|
2018-03-20 17:54:15 +01:00
|
|
|
* eventually terminate the operation. The following events terminate an
|
|
|
|
* operation:
|
2018-03-03 21:27:18 +01:00
|
|
|
* - A failed call to psa_cipher_update().
|
2018-03-20 17:54:53 +01:00
|
|
|
* - A call to psa_cipher_finish() or psa_cipher_abort().
|
2018-03-03 21:27:18 +01:00
|
|
|
*
|
2019-01-04 12:48:27 +01:00
|
|
|
* \param[in,out] operation The operation object to set up. It must have
|
|
|
|
* been initialized as per the documentation for
|
|
|
|
* #psa_cipher_operation_t and not yet in use.
|
2018-11-30 14:39:32 +01:00
|
|
|
* \param handle Handle to the key to use for the operation.
|
2018-07-12 01:08:58 +02:00
|
|
|
* \param alg The cipher algorithm to compute
|
|
|
|
* (\c PSA_ALG_XXX value such that
|
|
|
|
* #PSA_ALG_IS_CIPHER(\p alg) is true).
|
2018-03-03 21:27:18 +01:00
|
|
|
*
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_SUCCESS
|
2018-03-03 21:27:18 +01:00
|
|
|
* Success.
|
2018-11-30 14:39:32 +01:00
|
|
|
* \retval #PSA_ERROR_INVALID_HANDLE
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_ERROR_EMPTY_SLOT
|
|
|
|
* \retval #PSA_ERROR_NOT_PERMITTED
|
|
|
|
* \retval #PSA_ERROR_INVALID_ARGUMENT
|
2018-07-12 19:23:03 +02:00
|
|
|
* \p key is not compatible with \p alg.
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_ERROR_NOT_SUPPORTED
|
2018-07-12 19:23:03 +02:00
|
|
|
* \p alg is not supported or is not a cipher algorithm.
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
|
|
|
|
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
|
|
|
* \retval #PSA_ERROR_HARDWARE_FAILURE
|
|
|
|
* \retval #PSA_ERROR_TAMPERING_DETECTED
|
2018-09-12 10:44:52 +02:00
|
|
|
* \retval #PSA_ERROR_BAD_STATE
|
2018-09-16 11:22:41 +02:00
|
|
|
* The library has not been previously initialized by psa_crypto_init().
|
|
|
|
* It is implementation-dependent whether a failure to initialize
|
|
|
|
* results in this error code.
|
2018-03-03 21:27:18 +01:00
|
|
|
*/
|
2018-07-08 21:39:34 +02:00
|
|
|
psa_status_t psa_cipher_decrypt_setup(psa_cipher_operation_t *operation,
|
2018-11-30 14:39:32 +01:00
|
|
|
psa_key_handle_t handle,
|
2018-07-08 21:39:34 +02:00
|
|
|
psa_algorithm_t alg);
|
|
|
|
|
2018-07-12 00:30:52 +02:00
|
|
|
/** Generate an IV for a symmetric encryption operation.
|
|
|
|
*
|
|
|
|
* This function generates a random IV (initialization vector), nonce
|
|
|
|
* or initial counter value for the encryption operation as appropriate
|
|
|
|
* for the chosen algorithm, key type and key size.
|
|
|
|
*
|
|
|
|
* The application must call psa_cipher_encrypt_setup() before
|
|
|
|
* calling this function.
|
|
|
|
*
|
|
|
|
* If this function returns an error status, the operation becomes inactive.
|
|
|
|
*
|
2018-07-12 01:08:58 +02:00
|
|
|
* \param[in,out] operation Active cipher operation.
|
|
|
|
* \param[out] iv Buffer where the generated IV is to be written.
|
2018-07-12 19:23:03 +02:00
|
|
|
* \param iv_size Size of the \p iv buffer in bytes.
|
2018-07-12 01:08:58 +02:00
|
|
|
* \param[out] iv_length On success, the number of bytes of the
|
|
|
|
* generated IV.
|
2018-07-12 00:30:52 +02:00
|
|
|
*
|
|
|
|
* \retval #PSA_SUCCESS
|
|
|
|
* Success.
|
|
|
|
* \retval #PSA_ERROR_BAD_STATE
|
|
|
|
* The operation state is not valid (not started, or IV already set).
|
|
|
|
* \retval #PSA_ERROR_BUFFER_TOO_SMALL
|
2018-07-12 19:40:46 +02:00
|
|
|
* The size of the \p iv buffer is too small.
|
2018-07-12 00:30:52 +02:00
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
|
|
|
|
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
|
|
|
* \retval #PSA_ERROR_HARDWARE_FAILURE
|
|
|
|
* \retval #PSA_ERROR_TAMPERING_DETECTED
|
|
|
|
*/
|
2018-07-08 21:39:34 +02:00
|
|
|
psa_status_t psa_cipher_generate_iv(psa_cipher_operation_t *operation,
|
|
|
|
unsigned char *iv,
|
|
|
|
size_t iv_size,
|
|
|
|
size_t *iv_length);
|
|
|
|
|
2018-07-12 00:30:52 +02:00
|
|
|
/** Set the IV for a symmetric encryption or decryption operation.
|
|
|
|
*
|
|
|
|
* This function sets the random IV (initialization vector), nonce
|
|
|
|
* or initial counter value for the encryption or decryption operation.
|
|
|
|
*
|
|
|
|
* The application must call psa_cipher_encrypt_setup() before
|
|
|
|
* calling this function.
|
|
|
|
*
|
|
|
|
* If this function returns an error status, the operation becomes inactive.
|
|
|
|
*
|
|
|
|
* \note When encrypting, applications should use psa_cipher_generate_iv()
|
|
|
|
* instead of this function, unless implementing a protocol that requires
|
|
|
|
* a non-random IV.
|
|
|
|
*
|
2018-07-12 01:08:58 +02:00
|
|
|
* \param[in,out] operation Active cipher operation.
|
|
|
|
* \param[in] iv Buffer containing the IV to use.
|
|
|
|
* \param iv_length Size of the IV in bytes.
|
2018-07-12 00:30:52 +02:00
|
|
|
*
|
|
|
|
* \retval #PSA_SUCCESS
|
|
|
|
* Success.
|
|
|
|
* \retval #PSA_ERROR_BAD_STATE
|
|
|
|
* The operation state is not valid (not started, or IV already set).
|
|
|
|
* \retval #PSA_ERROR_INVALID_ARGUMENT
|
2018-07-12 19:23:03 +02:00
|
|
|
* The size of \p iv is not acceptable for the chosen algorithm,
|
2018-07-12 00:30:52 +02:00
|
|
|
* or the chosen algorithm does not use an IV.
|
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
|
|
|
|
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
|
|
|
* \retval #PSA_ERROR_HARDWARE_FAILURE
|
|
|
|
* \retval #PSA_ERROR_TAMPERING_DETECTED
|
|
|
|
*/
|
2018-07-08 21:39:34 +02:00
|
|
|
psa_status_t psa_cipher_set_iv(psa_cipher_operation_t *operation,
|
|
|
|
const unsigned char *iv,
|
|
|
|
size_t iv_length);
|
2018-03-03 21:27:18 +01:00
|
|
|
|
2018-07-12 00:30:52 +02:00
|
|
|
/** Encrypt or decrypt a message fragment in an active cipher operation.
|
|
|
|
*
|
2018-07-12 20:15:32 +02:00
|
|
|
* Before calling this function, you must:
|
|
|
|
* 1. Call either psa_cipher_encrypt_setup() or psa_cipher_decrypt_setup().
|
|
|
|
* The choice of setup function determines whether this function
|
|
|
|
* encrypts or decrypts its input.
|
|
|
|
* 2. If the algorithm requires an IV, call psa_cipher_generate_iv()
|
|
|
|
* (recommended when encrypting) or psa_cipher_set_iv().
|
2018-07-12 00:30:52 +02:00
|
|
|
*
|
|
|
|
* If this function returns an error status, the operation becomes inactive.
|
|
|
|
*
|
2018-07-12 01:08:58 +02:00
|
|
|
* \param[in,out] operation Active cipher operation.
|
|
|
|
* \param[in] input Buffer containing the message fragment to
|
|
|
|
* encrypt or decrypt.
|
2018-07-12 19:23:03 +02:00
|
|
|
* \param input_length Size of the \p input buffer in bytes.
|
2018-07-12 01:08:58 +02:00
|
|
|
* \param[out] output Buffer where the output is to be written.
|
2018-07-12 19:23:03 +02:00
|
|
|
* \param output_size Size of the \p output buffer in bytes.
|
2018-07-12 01:08:58 +02:00
|
|
|
* \param[out] output_length On success, the number of bytes
|
|
|
|
* that make up the returned output.
|
2018-07-12 00:30:52 +02:00
|
|
|
*
|
|
|
|
* \retval #PSA_SUCCESS
|
|
|
|
* Success.
|
|
|
|
* \retval #PSA_ERROR_BAD_STATE
|
|
|
|
* The operation state is not valid (not started, IV required but
|
|
|
|
* not set, or already completed).
|
|
|
|
* \retval #PSA_ERROR_BUFFER_TOO_SMALL
|
|
|
|
* The size of the \p output buffer is too small.
|
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
|
|
|
|
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
|
|
|
* \retval #PSA_ERROR_HARDWARE_FAILURE
|
|
|
|
* \retval #PSA_ERROR_TAMPERING_DETECTED
|
|
|
|
*/
|
2018-03-03 21:27:18 +01:00
|
|
|
psa_status_t psa_cipher_update(psa_cipher_operation_t *operation,
|
|
|
|
const uint8_t *input,
|
2018-03-12 14:59:30 +01:00
|
|
|
size_t input_length,
|
2018-06-18 15:41:12 +02:00
|
|
|
unsigned char *output,
|
|
|
|
size_t output_size,
|
2018-03-12 14:59:30 +01:00
|
|
|
size_t *output_length);
|
2018-03-03 21:27:18 +01:00
|
|
|
|
2018-07-12 00:30:52 +02:00
|
|
|
/** Finish encrypting or decrypting a message in a cipher operation.
|
|
|
|
*
|
|
|
|
* The application must call psa_cipher_encrypt_setup() or
|
|
|
|
* psa_cipher_decrypt_setup() before calling this function. The choice
|
|
|
|
* of setup function determines whether this function encrypts or
|
|
|
|
* decrypts its input.
|
|
|
|
*
|
|
|
|
* This function finishes the encryption or decryption of the message
|
|
|
|
* formed by concatenating the inputs passed to preceding calls to
|
|
|
|
* psa_cipher_update().
|
|
|
|
*
|
|
|
|
* When this function returns, the operation becomes inactive.
|
|
|
|
*
|
2018-07-12 01:08:58 +02:00
|
|
|
* \param[in,out] operation Active cipher operation.
|
|
|
|
* \param[out] output Buffer where the output is to be written.
|
2018-07-12 19:23:03 +02:00
|
|
|
* \param output_size Size of the \p output buffer in bytes.
|
2018-07-12 01:08:58 +02:00
|
|
|
* \param[out] output_length On success, the number of bytes
|
|
|
|
* that make up the returned output.
|
2018-07-12 00:30:52 +02:00
|
|
|
*
|
|
|
|
* \retval #PSA_SUCCESS
|
|
|
|
* Success.
|
|
|
|
* \retval #PSA_ERROR_BAD_STATE
|
|
|
|
* The operation state is not valid (not started, IV required but
|
|
|
|
* not set, or already completed).
|
|
|
|
* \retval #PSA_ERROR_BUFFER_TOO_SMALL
|
|
|
|
* The size of the \p output buffer is too small.
|
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
|
|
|
|
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
|
|
|
* \retval #PSA_ERROR_HARDWARE_FAILURE
|
|
|
|
* \retval #PSA_ERROR_TAMPERING_DETECTED
|
|
|
|
*/
|
2018-03-03 21:27:18 +01:00
|
|
|
psa_status_t psa_cipher_finish(psa_cipher_operation_t *operation,
|
2018-03-12 14:59:30 +01:00
|
|
|
uint8_t *output,
|
2018-04-22 19:16:58 +02:00
|
|
|
size_t output_size,
|
2018-03-12 14:59:30 +01:00
|
|
|
size_t *output_length);
|
2018-03-03 21:27:18 +01:00
|
|
|
|
2018-07-12 00:30:52 +02:00
|
|
|
/** Abort a cipher operation.
|
|
|
|
*
|
|
|
|
* Aborting an operation frees all associated resources except for the
|
2018-07-13 15:33:43 +02:00
|
|
|
* \p operation structure itself. Once aborted, the operation object
|
|
|
|
* can be reused for another operation by calling
|
|
|
|
* psa_cipher_encrypt_setup() or psa_cipher_decrypt_setup() again.
|
|
|
|
*
|
|
|
|
* You may call this function any time after the operation object has
|
|
|
|
* been initialized by any of the following methods:
|
|
|
|
* - A call to psa_cipher_encrypt_setup() or psa_cipher_decrypt_setup(),
|
|
|
|
* whether it succeeds or not.
|
|
|
|
* - Initializing the \c struct to all-bits-zero.
|
|
|
|
* - Initializing the \c struct to logical zeros, e.g.
|
|
|
|
* `psa_cipher_operation_t operation = {0}`.
|
|
|
|
*
|
|
|
|
* In particular, calling psa_cipher_abort() after the operation has been
|
|
|
|
* terminated by a call to psa_cipher_abort() or psa_cipher_finish()
|
|
|
|
* is safe and has no effect.
|
|
|
|
*
|
|
|
|
* \param[in,out] operation Initialized cipher operation.
|
2018-07-12 00:30:52 +02:00
|
|
|
*
|
|
|
|
* \retval #PSA_SUCCESS
|
|
|
|
* \retval #PSA_ERROR_BAD_STATE
|
2018-07-12 19:23:03 +02:00
|
|
|
* \p operation is not an active cipher operation.
|
2018-07-12 00:30:52 +02:00
|
|
|
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
|
|
|
* \retval #PSA_ERROR_HARDWARE_FAILURE
|
|
|
|
* \retval #PSA_ERROR_TAMPERING_DETECTED
|
|
|
|
*/
|
2018-03-03 21:27:18 +01:00
|
|
|
psa_status_t psa_cipher_abort(psa_cipher_operation_t *operation);
|
|
|
|
|
|
|
|
/**@}*/
|
|
|
|
|
2018-03-03 21:27:57 +01:00
|
|
|
/** \defgroup aead Authenticated encryption with associated data (AEAD)
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2018-06-01 16:29:38 +02:00
|
|
|
/** Process an authenticated encryption operation.
|
|
|
|
*
|
2018-11-30 14:39:32 +01:00
|
|
|
* \param handle Handle to the key to use for the operation.
|
2018-06-01 16:29:38 +02:00
|
|
|
* \param alg The AEAD algorithm to compute
|
|
|
|
* (\c PSA_ALG_XXX value such that
|
2018-07-12 00:34:26 +02:00
|
|
|
* #PSA_ALG_IS_AEAD(\p alg) is true).
|
2018-07-12 01:08:58 +02:00
|
|
|
* \param[in] nonce Nonce or IV to use.
|
2018-06-01 16:29:38 +02:00
|
|
|
* \param nonce_length Size of the \p nonce buffer in bytes.
|
2018-07-12 01:08:58 +02:00
|
|
|
* \param[in] additional_data Additional data that will be authenticated
|
2018-06-01 16:29:38 +02:00
|
|
|
* but not encrypted.
|
|
|
|
* \param additional_data_length Size of \p additional_data in bytes.
|
2018-07-12 01:08:58 +02:00
|
|
|
* \param[in] plaintext Data that will be authenticated and
|
2018-06-01 16:29:38 +02:00
|
|
|
* encrypted.
|
|
|
|
* \param plaintext_length Size of \p plaintext in bytes.
|
2018-07-12 01:08:58 +02:00
|
|
|
* \param[out] ciphertext Output buffer for the authenticated and
|
2018-06-01 16:29:38 +02:00
|
|
|
* encrypted data. The additional data is not
|
|
|
|
* part of this output. For algorithms where the
|
|
|
|
* encrypted data and the authentication tag
|
|
|
|
* are defined as separate outputs, the
|
|
|
|
* authentication tag is appended to the
|
|
|
|
* encrypted data.
|
|
|
|
* \param ciphertext_size Size of the \p ciphertext buffer in bytes.
|
|
|
|
* This must be at least
|
|
|
|
* #PSA_AEAD_ENCRYPT_OUTPUT_SIZE(\p alg,
|
|
|
|
* \p plaintext_length).
|
2018-07-12 01:08:58 +02:00
|
|
|
* \param[out] ciphertext_length On success, the size of the output
|
2018-06-01 16:29:38 +02:00
|
|
|
* in the \b ciphertext buffer.
|
2018-03-03 21:27:57 +01:00
|
|
|
*
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_SUCCESS
|
2018-03-03 21:27:57 +01:00
|
|
|
* Success.
|
2018-11-30 14:39:32 +01:00
|
|
|
* \retval #PSA_ERROR_INVALID_HANDLE
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_ERROR_EMPTY_SLOT
|
|
|
|
* \retval #PSA_ERROR_NOT_PERMITTED
|
|
|
|
* \retval #PSA_ERROR_INVALID_ARGUMENT
|
2018-07-12 19:23:03 +02:00
|
|
|
* \p key is not compatible with \p alg.
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_ERROR_NOT_SUPPORTED
|
2018-07-12 19:23:03 +02:00
|
|
|
* \p alg is not supported or is not an AEAD algorithm.
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
|
|
|
|
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
|
|
|
* \retval #PSA_ERROR_HARDWARE_FAILURE
|
|
|
|
* \retval #PSA_ERROR_TAMPERING_DETECTED
|
2018-09-12 10:44:52 +02:00
|
|
|
* \retval #PSA_ERROR_BAD_STATE
|
2018-09-16 11:22:41 +02:00
|
|
|
* The library has not been previously initialized by psa_crypto_init().
|
|
|
|
* It is implementation-dependent whether a failure to initialize
|
|
|
|
* results in this error code.
|
2018-03-03 21:27:57 +01:00
|
|
|
*/
|
2018-11-30 14:39:32 +01:00
|
|
|
psa_status_t psa_aead_encrypt(psa_key_handle_t handle,
|
2018-07-19 15:51:49 +02:00
|
|
|
psa_algorithm_t alg,
|
|
|
|
const uint8_t *nonce,
|
|
|
|
size_t nonce_length,
|
|
|
|
const uint8_t *additional_data,
|
|
|
|
size_t additional_data_length,
|
|
|
|
const uint8_t *plaintext,
|
|
|
|
size_t plaintext_length,
|
|
|
|
uint8_t *ciphertext,
|
|
|
|
size_t ciphertext_size,
|
|
|
|
size_t *ciphertext_length);
|
2018-04-25 23:51:02 +02:00
|
|
|
|
2018-06-01 16:29:38 +02:00
|
|
|
/** Process an authenticated decryption operation.
|
|
|
|
*
|
2018-11-30 14:39:32 +01:00
|
|
|
* \param handle Handle to the key to use for the operation.
|
2018-06-01 16:29:38 +02:00
|
|
|
* \param alg The AEAD algorithm to compute
|
|
|
|
* (\c PSA_ALG_XXX value such that
|
2018-07-12 00:34:26 +02:00
|
|
|
* #PSA_ALG_IS_AEAD(\p alg) is true).
|
2018-07-12 01:08:58 +02:00
|
|
|
* \param[in] nonce Nonce or IV to use.
|
2018-06-01 16:29:38 +02:00
|
|
|
* \param nonce_length Size of the \p nonce buffer in bytes.
|
2018-07-12 01:08:58 +02:00
|
|
|
* \param[in] additional_data Additional data that has been authenticated
|
2018-06-01 16:29:38 +02:00
|
|
|
* but not encrypted.
|
|
|
|
* \param additional_data_length Size of \p additional_data in bytes.
|
2018-07-12 01:08:58 +02:00
|
|
|
* \param[in] ciphertext Data that has been authenticated and
|
2018-06-01 16:29:38 +02:00
|
|
|
* encrypted. For algorithms where the
|
|
|
|
* encrypted data and the authentication tag
|
|
|
|
* are defined as separate inputs, the buffer
|
|
|
|
* must contain the encrypted data followed
|
|
|
|
* by the authentication tag.
|
|
|
|
* \param ciphertext_length Size of \p ciphertext in bytes.
|
2018-07-12 01:08:58 +02:00
|
|
|
* \param[out] plaintext Output buffer for the decrypted data.
|
2018-06-01 16:29:38 +02:00
|
|
|
* \param plaintext_size Size of the \p plaintext buffer in bytes.
|
|
|
|
* This must be at least
|
|
|
|
* #PSA_AEAD_DECRYPT_OUTPUT_SIZE(\p alg,
|
|
|
|
* \p ciphertext_length).
|
2018-07-12 01:08:58 +02:00
|
|
|
* \param[out] plaintext_length On success, the size of the output
|
2018-06-06 12:44:27 +02:00
|
|
|
* in the \b plaintext buffer.
|
2018-03-03 21:27:57 +01:00
|
|
|
*
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_SUCCESS
|
2018-03-03 21:27:57 +01:00
|
|
|
* Success.
|
2018-11-30 14:39:32 +01:00
|
|
|
* \retval #PSA_ERROR_INVALID_HANDLE
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_ERROR_EMPTY_SLOT
|
|
|
|
* \retval #PSA_ERROR_INVALID_SIGNATURE
|
2018-06-01 16:29:38 +02:00
|
|
|
* The ciphertext is not authentic.
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_ERROR_NOT_PERMITTED
|
|
|
|
* \retval #PSA_ERROR_INVALID_ARGUMENT
|
2018-07-12 19:23:03 +02:00
|
|
|
* \p key is not compatible with \p alg.
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_ERROR_NOT_SUPPORTED
|
2018-07-12 19:23:03 +02:00
|
|
|
* \p alg is not supported or is not an AEAD algorithm.
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
|
|
|
|
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
|
|
|
* \retval #PSA_ERROR_HARDWARE_FAILURE
|
|
|
|
* \retval #PSA_ERROR_TAMPERING_DETECTED
|
2018-09-12 10:44:52 +02:00
|
|
|
* \retval #PSA_ERROR_BAD_STATE
|
2018-09-16 11:22:41 +02:00
|
|
|
* The library has not been previously initialized by psa_crypto_init().
|
|
|
|
* It is implementation-dependent whether a failure to initialize
|
|
|
|
* results in this error code.
|
2018-03-03 21:27:57 +01:00
|
|
|
*/
|
2018-11-30 14:39:32 +01:00
|
|
|
psa_status_t psa_aead_decrypt(psa_key_handle_t handle,
|
2018-07-19 15:51:49 +02:00
|
|
|
psa_algorithm_t alg,
|
|
|
|
const uint8_t *nonce,
|
|
|
|
size_t nonce_length,
|
|
|
|
const uint8_t *additional_data,
|
|
|
|
size_t additional_data_length,
|
|
|
|
const uint8_t *ciphertext,
|
|
|
|
size_t ciphertext_length,
|
|
|
|
uint8_t *plaintext,
|
|
|
|
size_t plaintext_size,
|
|
|
|
size_t *plaintext_length);
|
2018-03-03 21:27:57 +01:00
|
|
|
|
|
|
|
/**@}*/
|
|
|
|
|
2018-02-03 22:44:14 +01:00
|
|
|
/** \defgroup asymmetric Asymmetric cryptography
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Sign a hash or short message with a private key.
|
|
|
|
*
|
2018-06-26 16:14:46 +02:00
|
|
|
* Note that to perform a hash-and-sign signature algorithm, you must
|
2018-07-08 19:46:38 +02:00
|
|
|
* first calculate the hash by calling psa_hash_setup(), psa_hash_update()
|
2018-06-26 16:14:46 +02:00
|
|
|
* and psa_hash_finish(). Then pass the resulting hash as the \p hash
|
|
|
|
* parameter to this function. You can use #PSA_ALG_SIGN_GET_HASH(\p alg)
|
|
|
|
* to determine the hash algorithm to use.
|
|
|
|
*
|
2018-11-30 14:39:32 +01:00
|
|
|
* \param handle Handle to the key to use for the operation.
|
|
|
|
* It must be an asymmetric key pair.
|
2018-07-12 01:08:58 +02:00
|
|
|
* \param alg A signature algorithm that is compatible with
|
2018-07-12 19:23:03 +02:00
|
|
|
* the type of \p key.
|
2018-07-12 01:08:58 +02:00
|
|
|
* \param[in] hash The hash or message to sign.
|
2018-07-12 19:23:03 +02:00
|
|
|
* \param hash_length Size of the \p hash buffer in bytes.
|
2018-07-12 01:08:58 +02:00
|
|
|
* \param[out] signature Buffer where the signature is to be written.
|
2018-07-12 19:23:03 +02:00
|
|
|
* \param signature_size Size of the \p signature buffer in bytes.
|
2018-07-12 01:08:58 +02:00
|
|
|
* \param[out] signature_length On success, the number of bytes
|
|
|
|
* that make up the returned signature value.
|
2018-02-08 09:47:44 +01:00
|
|
|
*
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_SUCCESS
|
|
|
|
* \retval #PSA_ERROR_BUFFER_TOO_SMALL
|
2018-07-12 19:23:03 +02:00
|
|
|
* The size of the \p signature buffer is too small. You can
|
2018-02-08 09:47:44 +01:00
|
|
|
* determine a sufficient buffer size by calling
|
2018-07-12 00:34:26 +02:00
|
|
|
* #PSA_ASYMMETRIC_SIGN_OUTPUT_SIZE(\c key_type, \c key_bits, \p alg)
|
2018-02-08 09:47:44 +01:00
|
|
|
* where \c key_type and \c key_bits are the type and bit-size
|
2018-07-12 19:23:03 +02:00
|
|
|
* respectively of \p key.
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_ERROR_NOT_SUPPORTED
|
|
|
|
* \retval #PSA_ERROR_INVALID_ARGUMENT
|
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
|
|
|
|
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
|
|
|
* \retval #PSA_ERROR_HARDWARE_FAILURE
|
|
|
|
* \retval #PSA_ERROR_TAMPERING_DETECTED
|
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_ENTROPY
|
2018-09-12 10:44:52 +02:00
|
|
|
* \retval #PSA_ERROR_BAD_STATE
|
2018-09-16 11:22:41 +02:00
|
|
|
* The library has not been previously initialized by psa_crypto_init().
|
|
|
|
* It is implementation-dependent whether a failure to initialize
|
|
|
|
* results in this error code.
|
2018-02-03 22:44:14 +01:00
|
|
|
*/
|
2018-11-30 14:39:32 +01:00
|
|
|
psa_status_t psa_asymmetric_sign(psa_key_handle_t handle,
|
2018-02-03 22:44:14 +01:00
|
|
|
psa_algorithm_t alg,
|
|
|
|
const uint8_t *hash,
|
|
|
|
size_t hash_length,
|
|
|
|
uint8_t *signature,
|
|
|
|
size_t signature_size,
|
|
|
|
size_t *signature_length);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Verify the signature a hash or short message using a public key.
|
|
|
|
*
|
2018-06-26 16:14:46 +02:00
|
|
|
* Note that to perform a hash-and-sign signature algorithm, you must
|
2018-07-08 19:46:38 +02:00
|
|
|
* first calculate the hash by calling psa_hash_setup(), psa_hash_update()
|
2018-06-26 16:14:46 +02:00
|
|
|
* and psa_hash_finish(). Then pass the resulting hash as the \p hash
|
|
|
|
* parameter to this function. You can use #PSA_ALG_SIGN_GET_HASH(\p alg)
|
|
|
|
* to determine the hash algorithm to use.
|
|
|
|
*
|
2018-11-30 14:39:32 +01:00
|
|
|
* \param handle Handle to the key to use for the operation.
|
|
|
|
* It must be a public key or an asymmetric key pair.
|
2018-02-08 09:47:44 +01:00
|
|
|
* \param alg A signature algorithm that is compatible with
|
2018-07-12 19:23:03 +02:00
|
|
|
* the type of \p key.
|
2018-07-12 01:08:58 +02:00
|
|
|
* \param[in] hash The hash or message whose signature is to be
|
2018-06-26 16:14:46 +02:00
|
|
|
* verified.
|
2018-07-12 19:23:03 +02:00
|
|
|
* \param hash_length Size of the \p hash buffer in bytes.
|
2018-07-12 01:08:58 +02:00
|
|
|
* \param[in] signature Buffer containing the signature to verify.
|
2018-07-12 19:23:03 +02:00
|
|
|
* \param signature_length Size of the \p signature buffer in bytes.
|
2018-02-08 09:47:44 +01:00
|
|
|
*
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_SUCCESS
|
2018-02-08 09:47:44 +01:00
|
|
|
* The signature is valid.
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_ERROR_INVALID_SIGNATURE
|
2018-02-08 09:47:44 +01:00
|
|
|
* The calculation was perfomed successfully, but the passed
|
|
|
|
* signature is not a valid signature.
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_ERROR_NOT_SUPPORTED
|
|
|
|
* \retval #PSA_ERROR_INVALID_ARGUMENT
|
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
|
|
|
|
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
|
|
|
* \retval #PSA_ERROR_HARDWARE_FAILURE
|
|
|
|
* \retval #PSA_ERROR_TAMPERING_DETECTED
|
2018-09-12 10:44:52 +02:00
|
|
|
* \retval #PSA_ERROR_BAD_STATE
|
2018-09-16 11:22:41 +02:00
|
|
|
* The library has not been previously initialized by psa_crypto_init().
|
|
|
|
* It is implementation-dependent whether a failure to initialize
|
|
|
|
* results in this error code.
|
2018-02-03 22:44:14 +01:00
|
|
|
*/
|
2018-11-30 14:39:32 +01:00
|
|
|
psa_status_t psa_asymmetric_verify(psa_key_handle_t handle,
|
2018-02-03 22:44:14 +01:00
|
|
|
psa_algorithm_t alg,
|
|
|
|
const uint8_t *hash,
|
|
|
|
size_t hash_length,
|
2018-06-27 14:58:41 +02:00
|
|
|
const uint8_t *signature,
|
2018-06-27 18:19:40 +02:00
|
|
|
size_t signature_length);
|
2018-02-03 22:44:14 +01:00
|
|
|
|
2018-03-28 14:18:39 +02:00
|
|
|
/**
|
|
|
|
* \brief Encrypt a short message with a public key.
|
|
|
|
*
|
2018-11-30 14:39:32 +01:00
|
|
|
* \param handle Handle to the key to use for the operation.
|
|
|
|
* It must be a public key or an asymmetric
|
|
|
|
* key pair.
|
2018-07-12 01:08:58 +02:00
|
|
|
* \param alg An asymmetric encryption algorithm that is
|
2018-07-12 19:23:03 +02:00
|
|
|
* compatible with the type of \p key.
|
2018-07-12 01:08:58 +02:00
|
|
|
* \param[in] input The message to encrypt.
|
2018-07-12 19:23:03 +02:00
|
|
|
* \param input_length Size of the \p input buffer in bytes.
|
2018-07-12 01:08:58 +02:00
|
|
|
* \param[in] salt A salt or label, if supported by the
|
|
|
|
* encryption algorithm.
|
|
|
|
* If the algorithm does not support a
|
|
|
|
* salt, pass \c NULL.
|
|
|
|
* If the algorithm supports an optional
|
|
|
|
* salt and you do not want to pass a salt,
|
|
|
|
* pass \c NULL.
|
|
|
|
*
|
|
|
|
* - For #PSA_ALG_RSA_PKCS1V15_CRYPT, no salt is
|
|
|
|
* supported.
|
2018-07-12 19:23:03 +02:00
|
|
|
* \param salt_length Size of the \p salt buffer in bytes.
|
|
|
|
* If \p salt is \c NULL, pass 0.
|
2018-07-12 01:08:58 +02:00
|
|
|
* \param[out] output Buffer where the encrypted message is to
|
|
|
|
* be written.
|
2018-07-12 19:23:03 +02:00
|
|
|
* \param output_size Size of the \p output buffer in bytes.
|
2018-07-12 01:08:58 +02:00
|
|
|
* \param[out] output_length On success, the number of bytes
|
|
|
|
* that make up the returned output.
|
2018-03-28 14:18:39 +02:00
|
|
|
*
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_SUCCESS
|
|
|
|
* \retval #PSA_ERROR_BUFFER_TOO_SMALL
|
2018-07-12 19:23:03 +02:00
|
|
|
* The size of the \p output buffer is too small. You can
|
2018-03-28 14:18:39 +02:00
|
|
|
* determine a sufficient buffer size by calling
|
2018-07-12 00:34:26 +02:00
|
|
|
* #PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE(\c key_type, \c key_bits, \p alg)
|
2018-03-28 14:18:39 +02:00
|
|
|
* where \c key_type and \c key_bits are the type and bit-size
|
2018-07-12 19:23:03 +02:00
|
|
|
* respectively of \p key.
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_ERROR_NOT_SUPPORTED
|
|
|
|
* \retval #PSA_ERROR_INVALID_ARGUMENT
|
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
|
|
|
|
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
|
|
|
* \retval #PSA_ERROR_HARDWARE_FAILURE
|
|
|
|
* \retval #PSA_ERROR_TAMPERING_DETECTED
|
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_ENTROPY
|
2018-09-12 10:44:52 +02:00
|
|
|
* \retval #PSA_ERROR_BAD_STATE
|
2018-09-16 11:22:41 +02:00
|
|
|
* The library has not been previously initialized by psa_crypto_init().
|
|
|
|
* It is implementation-dependent whether a failure to initialize
|
|
|
|
* results in this error code.
|
2018-03-28 14:18:39 +02:00
|
|
|
*/
|
2018-11-30 14:39:32 +01:00
|
|
|
psa_status_t psa_asymmetric_encrypt(psa_key_handle_t handle,
|
2018-03-28 14:18:39 +02:00
|
|
|
psa_algorithm_t alg,
|
|
|
|
const uint8_t *input,
|
|
|
|
size_t input_length,
|
|
|
|
const uint8_t *salt,
|
|
|
|
size_t salt_length,
|
|
|
|
uint8_t *output,
|
|
|
|
size_t output_size,
|
|
|
|
size_t *output_length);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Decrypt a short message with a private key.
|
|
|
|
*
|
2018-11-30 14:39:32 +01:00
|
|
|
* \param handle Handle to the key to use for the operation.
|
|
|
|
* It must be an asymmetric key pair.
|
2018-07-12 01:08:58 +02:00
|
|
|
* \param alg An asymmetric encryption algorithm that is
|
2018-07-12 19:23:03 +02:00
|
|
|
* compatible with the type of \p key.
|
2018-07-12 01:08:58 +02:00
|
|
|
* \param[in] input The message to decrypt.
|
2018-07-12 19:23:03 +02:00
|
|
|
* \param input_length Size of the \p input buffer in bytes.
|
2018-07-12 01:08:58 +02:00
|
|
|
* \param[in] salt A salt or label, if supported by the
|
|
|
|
* encryption algorithm.
|
|
|
|
* If the algorithm does not support a
|
|
|
|
* salt, pass \c NULL.
|
|
|
|
* If the algorithm supports an optional
|
|
|
|
* salt and you do not want to pass a salt,
|
|
|
|
* pass \c NULL.
|
|
|
|
*
|
|
|
|
* - For #PSA_ALG_RSA_PKCS1V15_CRYPT, no salt is
|
|
|
|
* supported.
|
2018-07-12 19:23:03 +02:00
|
|
|
* \param salt_length Size of the \p salt buffer in bytes.
|
|
|
|
* If \p salt is \c NULL, pass 0.
|
2018-07-12 01:08:58 +02:00
|
|
|
* \param[out] output Buffer where the decrypted message is to
|
|
|
|
* be written.
|
|
|
|
* \param output_size Size of the \c output buffer in bytes.
|
|
|
|
* \param[out] output_length On success, the number of bytes
|
|
|
|
* that make up the returned output.
|
2018-03-28 14:18:39 +02:00
|
|
|
*
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_SUCCESS
|
|
|
|
* \retval #PSA_ERROR_BUFFER_TOO_SMALL
|
2018-07-12 19:23:03 +02:00
|
|
|
* The size of the \p output buffer is too small. You can
|
2018-03-28 14:18:39 +02:00
|
|
|
* determine a sufficient buffer size by calling
|
2018-07-12 19:40:46 +02:00
|
|
|
* #PSA_ASYMMETRIC_DECRYPT_OUTPUT_SIZE(\c key_type, \c key_bits, \p alg)
|
2018-03-28 14:18:39 +02:00
|
|
|
* where \c key_type and \c key_bits are the type and bit-size
|
2018-07-12 19:23:03 +02:00
|
|
|
* respectively of \p key.
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_ERROR_NOT_SUPPORTED
|
|
|
|
* \retval #PSA_ERROR_INVALID_ARGUMENT
|
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
|
|
|
|
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
|
|
|
* \retval #PSA_ERROR_HARDWARE_FAILURE
|
|
|
|
* \retval #PSA_ERROR_TAMPERING_DETECTED
|
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_ENTROPY
|
|
|
|
* \retval #PSA_ERROR_INVALID_PADDING
|
2018-09-12 10:44:52 +02:00
|
|
|
* \retval #PSA_ERROR_BAD_STATE
|
2018-09-16 11:22:41 +02:00
|
|
|
* The library has not been previously initialized by psa_crypto_init().
|
|
|
|
* It is implementation-dependent whether a failure to initialize
|
|
|
|
* results in this error code.
|
2018-03-28 14:18:39 +02:00
|
|
|
*/
|
2018-11-30 14:39:32 +01:00
|
|
|
psa_status_t psa_asymmetric_decrypt(psa_key_handle_t handle,
|
2018-03-28 14:18:39 +02:00
|
|
|
psa_algorithm_t alg,
|
|
|
|
const uint8_t *input,
|
|
|
|
size_t input_length,
|
|
|
|
const uint8_t *salt,
|
|
|
|
size_t salt_length,
|
|
|
|
uint8_t *output,
|
|
|
|
size_t output_size,
|
|
|
|
size_t *output_length);
|
|
|
|
|
2018-01-28 13:16:24 +01:00
|
|
|
/**@}*/
|
|
|
|
|
2018-07-20 17:42:05 +02:00
|
|
|
/** \defgroup generators Generators
|
2018-07-12 17:12:33 +02:00
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** The type of the state data structure for generators.
|
|
|
|
*
|
|
|
|
* Before calling any function on a generator, the application must
|
|
|
|
* initialize it by any of the following means:
|
|
|
|
* - Set the structure to all-bits-zero, for example:
|
|
|
|
* \code
|
|
|
|
* psa_crypto_generator_t generator;
|
|
|
|
* memset(&generator, 0, sizeof(generator));
|
|
|
|
* \endcode
|
|
|
|
* - Initialize the structure to logical zero values, for example:
|
|
|
|
* \code
|
|
|
|
* psa_crypto_generator_t generator = {0};
|
|
|
|
* \endcode
|
|
|
|
* - Initialize the structure to the initializer #PSA_CRYPTO_GENERATOR_INIT,
|
|
|
|
* for example:
|
|
|
|
* \code
|
|
|
|
* psa_crypto_generator_t generator = PSA_CRYPTO_GENERATOR_INIT;
|
|
|
|
* \endcode
|
|
|
|
* - Assign the result of the function psa_crypto_generator_init()
|
|
|
|
* to the structure, for example:
|
|
|
|
* \code
|
|
|
|
* psa_crypto_generator_t generator;
|
|
|
|
* generator = psa_crypto_generator_init();
|
|
|
|
* \endcode
|
|
|
|
*
|
|
|
|
* This is an implementation-defined \c struct. Applications should not
|
|
|
|
* make any assumptions about the content of this structure except
|
|
|
|
* as directed by the documentation of a specific implementation.
|
|
|
|
*/
|
|
|
|
typedef struct psa_crypto_generator_s psa_crypto_generator_t;
|
|
|
|
|
|
|
|
/** \def PSA_CRYPTO_GENERATOR_INIT
|
|
|
|
*
|
|
|
|
* This macro returns a suitable initializer for a generator object
|
|
|
|
* of type #psa_crypto_generator_t.
|
|
|
|
*/
|
|
|
|
#ifdef __DOXYGEN_ONLY__
|
|
|
|
/* This is an example definition for documentation purposes.
|
|
|
|
* Implementations should define a suitable value in `crypto_struct.h`.
|
|
|
|
*/
|
|
|
|
#define PSA_CRYPTO_GENERATOR_INIT {0}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/** Return an initial value for a generator object.
|
|
|
|
*/
|
|
|
|
static psa_crypto_generator_t psa_crypto_generator_init(void);
|
|
|
|
|
|
|
|
/** Retrieve the current capacity of a generator.
|
|
|
|
*
|
|
|
|
* The capacity of a generator is the maximum number of bytes that it can
|
|
|
|
* return. Reading *N* bytes from a generator reduces its capacity by *N*.
|
|
|
|
*
|
|
|
|
* \param[in] generator The generator to query.
|
|
|
|
* \param[out] capacity On success, the capacity of the generator.
|
|
|
|
*
|
2018-12-11 16:47:35 +01:00
|
|
|
* \retval #PSA_SUCCESS
|
|
|
|
* \retval #PSA_ERROR_BAD_STATE
|
|
|
|
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
2018-07-12 17:12:33 +02:00
|
|
|
*/
|
|
|
|
psa_status_t psa_get_generator_capacity(const psa_crypto_generator_t *generator,
|
|
|
|
size_t *capacity);
|
|
|
|
|
|
|
|
/** Read some data from a generator.
|
|
|
|
*
|
|
|
|
* This function reads and returns a sequence of bytes from a generator.
|
|
|
|
* The data that is read is discarded from the generator. The generator's
|
|
|
|
* capacity is decreased by the number of bytes read.
|
|
|
|
*
|
|
|
|
* \param[in,out] generator The generator object to read from.
|
|
|
|
* \param[out] output Buffer where the generator output will be
|
|
|
|
* written.
|
|
|
|
* \param output_length Number of bytes to output.
|
|
|
|
*
|
2018-12-11 16:47:35 +01:00
|
|
|
* \retval #PSA_SUCCESS
|
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_CAPACITY
|
2018-07-12 17:12:33 +02:00
|
|
|
* There were fewer than \p output_length bytes
|
|
|
|
* in the generator. Note that in this case, no
|
|
|
|
* output is written to the output buffer.
|
|
|
|
* The generator's capacity is set to 0, thus
|
|
|
|
* subsequent calls to this function will not
|
|
|
|
* succeed, even with a smaller output buffer.
|
2018-12-11 16:47:35 +01:00
|
|
|
* \retval #PSA_ERROR_BAD_STATE
|
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
|
|
|
|
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
|
|
|
* \retval #PSA_ERROR_HARDWARE_FAILURE
|
|
|
|
* \retval #PSA_ERROR_TAMPERING_DETECTED
|
2018-07-12 17:12:33 +02:00
|
|
|
*/
|
|
|
|
psa_status_t psa_generator_read(psa_crypto_generator_t *generator,
|
|
|
|
uint8_t *output,
|
|
|
|
size_t output_length);
|
|
|
|
|
|
|
|
/** Create a symmetric key from data read from a generator.
|
|
|
|
*
|
|
|
|
* This function reads a sequence of bytes from a generator and imports
|
|
|
|
* these bytes as a key.
|
|
|
|
* The data that is read is discarded from the generator. The generator's
|
|
|
|
* capacity is decreased by the number of bytes read.
|
|
|
|
*
|
|
|
|
* This function is equivalent to calling #psa_generator_read and
|
|
|
|
* passing the resulting output to #psa_import_key, but
|
|
|
|
* if the implementation provides an isolation boundary then
|
|
|
|
* the key material is not exposed outside the isolation boundary.
|
|
|
|
*
|
2018-11-30 14:39:32 +01:00
|
|
|
* \param handle Handle to the slot where the key will be stored.
|
|
|
|
* This must be a valid slot for a key of the chosen
|
|
|
|
* type: it must have been obtained by calling
|
|
|
|
* psa_allocate_key() or psa_create_key() with the
|
|
|
|
* correct \p type and with a maximum size that is
|
|
|
|
* compatible with \p bits.
|
|
|
|
* It must not contain any key material yet.
|
2018-07-12 17:12:33 +02:00
|
|
|
* \param type Key type (a \c PSA_KEY_TYPE_XXX value).
|
|
|
|
* This must be a symmetric key type.
|
|
|
|
* \param bits Key size in bits.
|
|
|
|
* \param[in,out] generator The generator object to read from.
|
|
|
|
*
|
2018-12-11 16:47:35 +01:00
|
|
|
* \retval #PSA_SUCCESS
|
2018-07-12 17:12:33 +02:00
|
|
|
* Success.
|
2018-12-11 15:51:32 +01:00
|
|
|
* If the key is persistent, the key material and the key's metadata
|
|
|
|
* have been saved to persistent storage.
|
2018-12-11 16:47:35 +01:00
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_CAPACITY
|
2018-07-12 17:12:33 +02:00
|
|
|
* There were fewer than \p output_length bytes
|
|
|
|
* in the generator. Note that in this case, no
|
|
|
|
* output is written to the output buffer.
|
|
|
|
* The generator's capacity is set to 0, thus
|
|
|
|
* subsequent calls to this function will not
|
|
|
|
* succeed, even with a smaller output buffer.
|
2018-12-11 16:47:35 +01:00
|
|
|
* \retval #PSA_ERROR_NOT_SUPPORTED
|
2018-07-12 17:12:33 +02:00
|
|
|
* The key type or key size is not supported, either by the
|
|
|
|
* implementation in general or in this particular slot.
|
2018-12-11 16:47:35 +01:00
|
|
|
* \retval #PSA_ERROR_BAD_STATE
|
2018-11-30 14:39:32 +01:00
|
|
|
* \retval #PSA_ERROR_INVALID_HANDLE
|
2018-12-11 16:47:35 +01:00
|
|
|
* \retval #PSA_ERROR_OCCUPIED_SLOT
|
2018-07-12 17:12:33 +02:00
|
|
|
* There is already a key in the specified slot.
|
2018-12-11 16:47:35 +01:00
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
|
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_STORAGE
|
|
|
|
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
|
|
|
* \retval #PSA_ERROR_HARDWARE_FAILURE
|
|
|
|
* \retval #PSA_ERROR_TAMPERING_DETECTED
|
2018-09-12 10:44:52 +02:00
|
|
|
* \retval #PSA_ERROR_BAD_STATE
|
2018-09-16 11:22:41 +02:00
|
|
|
* The library has not been previously initialized by psa_crypto_init().
|
|
|
|
* It is implementation-dependent whether a failure to initialize
|
|
|
|
* results in this error code.
|
2018-07-12 17:12:33 +02:00
|
|
|
*/
|
2018-11-30 14:39:32 +01:00
|
|
|
psa_status_t psa_generator_import_key(psa_key_handle_t handle,
|
2018-07-12 17:12:33 +02:00
|
|
|
psa_key_type_t type,
|
|
|
|
size_t bits,
|
|
|
|
psa_crypto_generator_t *generator);
|
|
|
|
|
|
|
|
/** Abort a generator.
|
|
|
|
*
|
|
|
|
* Once a generator has been aborted, its capacity is zero.
|
|
|
|
* Aborting a generator frees all associated resources except for the
|
|
|
|
* \c generator structure itself.
|
|
|
|
*
|
|
|
|
* This function may be called at any time as long as the generator
|
|
|
|
* object has been initialized to #PSA_CRYPTO_GENERATOR_INIT, to
|
|
|
|
* psa_crypto_generator_init() or a zero value. In particular, it is valid
|
|
|
|
* to call psa_generator_abort() twice, or to call psa_generator_abort()
|
|
|
|
* on a generator that has not been set up.
|
|
|
|
*
|
|
|
|
* Once aborted, the generator object may be called.
|
|
|
|
*
|
|
|
|
* \param[in,out] generator The generator to abort.
|
|
|
|
*
|
2018-12-11 16:47:35 +01:00
|
|
|
* \retval #PSA_SUCCESS
|
|
|
|
* \retval #PSA_ERROR_BAD_STATE
|
|
|
|
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
|
|
|
* \retval #PSA_ERROR_HARDWARE_FAILURE
|
|
|
|
* \retval #PSA_ERROR_TAMPERING_DETECTED
|
2018-07-12 17:12:33 +02:00
|
|
|
*/
|
|
|
|
psa_status_t psa_generator_abort(psa_crypto_generator_t *generator);
|
|
|
|
|
2018-09-18 12:06:11 +02:00
|
|
|
/** Use the maximum possible capacity for a generator.
|
|
|
|
*
|
|
|
|
* Use this value as the capacity argument when setting up a generator
|
|
|
|
* to indicate that the generator should have the maximum possible capacity.
|
|
|
|
* The value of the maximum possible capacity depends on the generator
|
|
|
|
* algorithm.
|
|
|
|
*/
|
|
|
|
#define PSA_GENERATOR_UNBRIDLED_CAPACITY ((size_t)(-1))
|
|
|
|
|
2018-07-12 17:12:33 +02:00
|
|
|
/**@}*/
|
|
|
|
|
2018-07-12 17:17:20 +02:00
|
|
|
/** \defgroup derivation Key derivation
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** Set up a key derivation operation.
|
|
|
|
*
|
|
|
|
* A key derivation algorithm takes three inputs: a secret input \p key and
|
|
|
|
* two non-secret inputs \p label and p salt.
|
|
|
|
* The result of this function is a byte generator which can
|
|
|
|
* be used to produce keys and other cryptographic material.
|
|
|
|
*
|
|
|
|
* The role of \p label and \p salt is as follows:
|
2018-07-12 17:22:21 +02:00
|
|
|
* - For HKDF (#PSA_ALG_HKDF), \p salt is the salt used in the "extract" step
|
|
|
|
* and \p label is the info string used in the "expand" step.
|
2018-07-12 17:17:20 +02:00
|
|
|
*
|
2019-01-07 16:41:50 +01:00
|
|
|
* \param[in,out] generator The generator object to set up. It must have
|
|
|
|
* been initialized as per the documentation for
|
|
|
|
* #psa_crypto_generator_t and not yet in use.
|
2018-11-30 14:39:32 +01:00
|
|
|
* \param handle Handle to the secret key.
|
2018-07-12 17:17:20 +02:00
|
|
|
* \param alg The key derivation algorithm to compute
|
|
|
|
* (\c PSA_ALG_XXX value such that
|
|
|
|
* #PSA_ALG_IS_KEY_DERIVATION(\p alg) is true).
|
|
|
|
* \param[in] salt Salt to use.
|
|
|
|
* \param salt_length Size of the \p salt buffer in bytes.
|
|
|
|
* \param[in] label Label to use.
|
|
|
|
* \param label_length Size of the \p label buffer in bytes.
|
|
|
|
* \param capacity The maximum number of bytes that the
|
|
|
|
* generator will be able to provide.
|
|
|
|
*
|
|
|
|
* \retval #PSA_SUCCESS
|
|
|
|
* Success.
|
2018-11-30 14:39:32 +01:00
|
|
|
* \retval #PSA_ERROR_INVALID_HANDLE
|
2018-07-12 17:17:20 +02:00
|
|
|
* \retval #PSA_ERROR_EMPTY_SLOT
|
|
|
|
* \retval #PSA_ERROR_NOT_PERMITTED
|
|
|
|
* \retval #PSA_ERROR_INVALID_ARGUMENT
|
|
|
|
* \c key is not compatible with \c alg,
|
|
|
|
* or \p capacity is too large for the specified algorithm and key.
|
|
|
|
* \retval #PSA_ERROR_NOT_SUPPORTED
|
|
|
|
* \c alg is not supported or is not a key derivation algorithm.
|
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
|
|
|
|
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
|
|
|
* \retval #PSA_ERROR_HARDWARE_FAILURE
|
|
|
|
* \retval #PSA_ERROR_TAMPERING_DETECTED
|
2018-09-12 10:44:52 +02:00
|
|
|
* \retval #PSA_ERROR_BAD_STATE
|
2018-09-16 11:22:41 +02:00
|
|
|
* The library has not been previously initialized by psa_crypto_init().
|
|
|
|
* It is implementation-dependent whether a failure to initialize
|
|
|
|
* results in this error code.
|
2018-07-12 17:17:20 +02:00
|
|
|
*/
|
|
|
|
psa_status_t psa_key_derivation(psa_crypto_generator_t *generator,
|
2018-11-30 14:39:32 +01:00
|
|
|
psa_key_handle_t handle,
|
2018-07-12 17:17:20 +02:00
|
|
|
psa_algorithm_t alg,
|
|
|
|
const uint8_t *salt,
|
|
|
|
size_t salt_length,
|
|
|
|
const uint8_t *label,
|
|
|
|
size_t label_length,
|
|
|
|
size_t capacity);
|
|
|
|
|
2018-09-18 12:01:02 +02:00
|
|
|
/** Set up a key agreement operation.
|
|
|
|
*
|
|
|
|
* A key agreement algorithm takes two inputs: a private key \p private_key
|
|
|
|
* a public key \p peer_key.
|
|
|
|
* The result of this function is a byte generator which can
|
|
|
|
* be used to produce keys and other cryptographic material.
|
|
|
|
*
|
2018-10-25 22:22:31 +02:00
|
|
|
* The resulting generator always has the maximum capacity permitted by
|
|
|
|
* the algorithm.
|
|
|
|
*
|
2019-01-07 16:41:50 +01:00
|
|
|
* \param[in,out] generator The generator object to set up. It must have
|
|
|
|
* been initialized as per the documentation for
|
|
|
|
* #psa_crypto_generator_t and not yet in use.
|
2018-11-30 14:39:32 +01:00
|
|
|
* \param private_key Handle to the private key to use.
|
2018-11-15 17:46:21 +01:00
|
|
|
* \param[in] peer_key Public key of the peer. It must be
|
|
|
|
* in the same format that psa_import_key()
|
|
|
|
* accepts. The standard formats for public
|
|
|
|
* keys are documented in the documentation
|
|
|
|
* of psa_export_public_key().
|
2018-09-18 12:01:02 +02:00
|
|
|
* \param peer_key_length Size of \p peer_key in bytes.
|
|
|
|
* \param alg The key agreement algorithm to compute
|
|
|
|
* (\c PSA_ALG_XXX value such that
|
|
|
|
* #PSA_ALG_IS_KEY_AGREEMENT(\p alg) is true).
|
|
|
|
*
|
|
|
|
* \retval #PSA_SUCCESS
|
|
|
|
* Success.
|
2018-11-30 14:39:32 +01:00
|
|
|
* \retval #PSA_ERROR_INVALID_HANDLE
|
2018-09-18 12:01:02 +02:00
|
|
|
* \retval #PSA_ERROR_EMPTY_SLOT
|
|
|
|
* \retval #PSA_ERROR_NOT_PERMITTED
|
|
|
|
* \retval #PSA_ERROR_INVALID_ARGUMENT
|
|
|
|
* \c private_key is not compatible with \c alg,
|
|
|
|
* or \p peer_key is not valid for \c alg or not compatible with
|
|
|
|
* \c private_key.
|
|
|
|
* \retval #PSA_ERROR_NOT_SUPPORTED
|
|
|
|
* \c alg is not supported or is not a key derivation algorithm.
|
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
|
|
|
|
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
|
|
|
* \retval #PSA_ERROR_HARDWARE_FAILURE
|
|
|
|
* \retval #PSA_ERROR_TAMPERING_DETECTED
|
|
|
|
*/
|
|
|
|
psa_status_t psa_key_agreement(psa_crypto_generator_t *generator,
|
2018-11-30 14:39:32 +01:00
|
|
|
psa_key_handle_t private_key,
|
2018-09-18 12:01:02 +02:00
|
|
|
const uint8_t *peer_key,
|
|
|
|
size_t peer_key_length,
|
|
|
|
psa_algorithm_t alg);
|
|
|
|
|
2018-07-12 17:17:20 +02:00
|
|
|
/**@}*/
|
|
|
|
|
2018-07-20 17:42:05 +02:00
|
|
|
/** \defgroup random Random generation
|
2018-03-28 14:18:50 +02:00
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Generate random bytes.
|
|
|
|
*
|
|
|
|
* \warning This function **can** fail! Callers MUST check the return status
|
|
|
|
* and MUST NOT use the content of the output buffer if the return
|
|
|
|
* status is not #PSA_SUCCESS.
|
|
|
|
*
|
|
|
|
* \note To generate a key, use psa_generate_key() instead.
|
|
|
|
*
|
2018-07-12 01:08:58 +02:00
|
|
|
* \param[out] output Output buffer for the generated data.
|
2018-03-28 14:18:50 +02:00
|
|
|
* \param output_size Number of bytes to generate and output.
|
|
|
|
*
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_SUCCESS
|
|
|
|
* \retval #PSA_ERROR_NOT_SUPPORTED
|
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_ENTROPY
|
|
|
|
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
|
|
|
* \retval #PSA_ERROR_HARDWARE_FAILURE
|
|
|
|
* \retval #PSA_ERROR_TAMPERING_DETECTED
|
2018-09-06 15:24:41 +02:00
|
|
|
* \retval #PSA_ERROR_BAD_STATE
|
2018-09-16 11:22:41 +02:00
|
|
|
* The library has not been previously initialized by psa_crypto_init().
|
|
|
|
* It is implementation-dependent whether a failure to initialize
|
|
|
|
* results in this error code.
|
2018-03-28 14:18:50 +02:00
|
|
|
*/
|
|
|
|
psa_status_t psa_generate_random(uint8_t *output,
|
|
|
|
size_t output_size);
|
|
|
|
|
2018-07-12 01:24:09 +02:00
|
|
|
/** Extra parameters for RSA key generation.
|
|
|
|
*
|
2018-07-13 14:38:15 +02:00
|
|
|
* You may pass a pointer to a structure of this type as the \c extra
|
2018-07-12 01:24:09 +02:00
|
|
|
* parameter to psa_generate_key().
|
|
|
|
*/
|
|
|
|
typedef struct {
|
2018-07-20 17:42:05 +02:00
|
|
|
uint32_t e; /**< Public exponent value. Default: 65537. */
|
2018-07-12 01:24:09 +02:00
|
|
|
} psa_generate_key_extra_rsa;
|
|
|
|
|
2018-03-28 14:18:50 +02:00
|
|
|
/**
|
|
|
|
* \brief Generate a key or key pair.
|
|
|
|
*
|
2018-11-30 14:39:32 +01:00
|
|
|
* \param handle Handle to the slot where the key will be stored.
|
|
|
|
* This must be a valid slot for a key of the chosen
|
|
|
|
* type: it must have been obtained by calling
|
|
|
|
* psa_allocate_key() or psa_create_key() with the
|
|
|
|
* correct \p type and with a maximum size that is
|
|
|
|
* compatible with \p bits.
|
|
|
|
* It must not contain any key material yet.
|
2018-06-19 20:19:14 +02:00
|
|
|
* \param type Key type (a \c PSA_KEY_TYPE_XXX value).
|
|
|
|
* \param bits Key size in bits.
|
2018-07-12 01:14:59 +02:00
|
|
|
* \param[in] extra Extra parameters for key generation. The
|
2018-06-19 20:19:14 +02:00
|
|
|
* interpretation of this parameter depends on
|
2018-07-12 19:23:03 +02:00
|
|
|
* \p type. All types support \c NULL to use
|
2018-07-12 01:31:03 +02:00
|
|
|
* default parameters. Implementation that support
|
|
|
|
* the generation of vendor-specific key types
|
|
|
|
* that allow extra parameters shall document
|
|
|
|
* the format of these extra parameters and
|
|
|
|
* the default values. For standard parameters,
|
|
|
|
* the meaning of \p extra is as follows:
|
2018-07-12 19:23:03 +02:00
|
|
|
* - For a symmetric key type (a type such
|
2018-07-12 01:31:03 +02:00
|
|
|
* that #PSA_KEY_TYPE_IS_ASYMMETRIC(\p type) is
|
|
|
|
* false), \p extra must be \c NULL.
|
2018-07-12 19:23:03 +02:00
|
|
|
* - For an elliptic curve key type (a type
|
2018-07-12 01:31:03 +02:00
|
|
|
* such that #PSA_KEY_TYPE_IS_ECC(\p type) is
|
|
|
|
* false), \p extra must be \c NULL.
|
2018-07-12 19:40:46 +02:00
|
|
|
* - For an RSA key (\p type is
|
|
|
|
* #PSA_KEY_TYPE_RSA_KEYPAIR), \p extra is an
|
|
|
|
* optional #psa_generate_key_extra_rsa structure
|
2018-07-12 01:31:03 +02:00
|
|
|
* specifying the public exponent. The
|
|
|
|
* default public exponent used when \p extra
|
|
|
|
* is \c NULL is 65537.
|
2018-07-12 01:14:59 +02:00
|
|
|
* \param extra_size Size of the buffer that \p extra
|
|
|
|
* points to, in bytes. Note that if \p extra is
|
|
|
|
* \c NULL then \p extra_size must be zero.
|
2018-03-28 14:18:50 +02:00
|
|
|
*
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_SUCCESS
|
2018-12-11 15:51:32 +01:00
|
|
|
* Success.
|
|
|
|
* If the key is persistent, the key material and the key's metadata
|
|
|
|
* have been saved to persistent storage.
|
2018-11-30 14:39:32 +01:00
|
|
|
* \retval #PSA_ERROR_INVALID_HANDLE
|
|
|
|
* \retval #PSA_ERROR_OCCUPIED_SLOT
|
|
|
|
* There is already a key in the specified slot.
|
2018-07-11 17:34:00 +02:00
|
|
|
* \retval #PSA_ERROR_NOT_SUPPORTED
|
|
|
|
* \retval #PSA_ERROR_INVALID_ARGUMENT
|
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
|
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_ENTROPY
|
|
|
|
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
|
|
|
* \retval #PSA_ERROR_HARDWARE_FAILURE
|
|
|
|
* \retval #PSA_ERROR_TAMPERING_DETECTED
|
2018-09-12 10:44:52 +02:00
|
|
|
* \retval #PSA_ERROR_BAD_STATE
|
2018-09-16 11:22:41 +02:00
|
|
|
* The library has not been previously initialized by psa_crypto_init().
|
|
|
|
* It is implementation-dependent whether a failure to initialize
|
|
|
|
* results in this error code.
|
2018-03-28 14:18:50 +02:00
|
|
|
*/
|
2018-11-30 14:39:32 +01:00
|
|
|
psa_status_t psa_generate_key(psa_key_handle_t handle,
|
2018-03-28 14:18:50 +02:00
|
|
|
psa_key_type_t type,
|
|
|
|
size_t bits,
|
2018-07-12 01:14:59 +02:00
|
|
|
const void *extra,
|
|
|
|
size_t extra_size);
|
2018-03-28 14:18:50 +02:00
|
|
|
|
|
|
|
/**@}*/
|
|
|
|
|
2018-01-27 23:32:46 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-06-27 19:49:02 +02:00
|
|
|
/* The file "crypto_sizes.h" contains definitions for size calculation
|
|
|
|
* macros whose definitions are implementation-specific. */
|
|
|
|
#include "crypto_sizes.h"
|
|
|
|
|
2018-02-07 21:05:37 +01:00
|
|
|
/* The file "crypto_struct.h" contains definitions for
|
|
|
|
* implementation-specific structs that are declared above. */
|
|
|
|
#include "crypto_struct.h"
|
|
|
|
|
|
|
|
/* The file "crypto_extra.h" contains vendor-specific definitions. This
|
|
|
|
* can include vendor-defined algorithms, extra functions, etc. */
|
2018-01-27 23:32:46 +01:00
|
|
|
#include "crypto_extra.h"
|
|
|
|
|
|
|
|
#endif /* PSA_CRYPTO_H */
|