blob: b158f51897926fccdb51106a1d2232dff08ae471 [file] [log] [blame]
Antonio de Angelis8908f472018-08-31 15:44:25 +01001/*
2 * Copyright (c) 2018, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8#ifndef __TFM_CRYPTO_VENEERS_H__
9#define __TFM_CRYPTO_VENEERS_H__
10
11#ifdef __cplusplus
12extern "C" {
13#endif
14
15#include "tfm_crypto_defs.h"
16
17#include "psa_crypto.h"
18
19#include "crypto_psa_wrappers.h"
20
21/**
22 * \brief Import the key data on the provided key slot (veneer function)
23 *
24 * \param[in] key Key slot
25 * \param[in] type Key type
26 * \param[in] data Key data to import
27 * \param[in] data_length Length in bytes of the data field
28 *
29 * \return Return values as described in \ref tfm_crypto_err_t
30 */
31enum tfm_crypto_err_t tfm_crypto_veneer_import_key(psa_key_slot_t key,
32 psa_key_type_t type,
33 const uint8_t *data,
34 size_t data_length);
35/**
36 * \brief Destroy the key in the provided key slot (veneer function)
37 *
38 * \param[in] key Key slot
39 *
40 * \return Return values as described in \ref tfm_crypto_err_t
41 */
42enum tfm_crypto_err_t tfm_crypto_veneer_destroy_key(psa_key_slot_t key);
43
44/**
45 * \brief Retrieve key information for the provided key slot (veneer function)
46 *
47 * \param[in] key Key slot
48 * \param[out] type Key type associated to the key slot requested
49 * \param[out] bits Length in bits of the key in the requested slot
50 *
51 * \return Return values as described in \ref tfm_crypto_err_t
52 */
53enum tfm_crypto_err_t tfm_crypto_veneer_get_key_information(
54 psa_key_slot_t key,
55 psa_key_type_t *type,
56 size_t *bits);
57/**
58 * \brief Export the key contained in the provided key slot (veneer function)
59 *
60 * \param[in] key Key slot
61 * \param[out] data Buffer to hold the exported key
62 * \param[in] data_size Length of the buffer pointed to by data
63 * \param[out] data_length Length of the exported key
64 *
65 * \return Return values as described in \ref tfm_crypto_err_t
66 */
67enum tfm_crypto_err_t tfm_crypto_veneer_export_key(psa_key_slot_t key,
68 uint8_t *data,
69 size_t data_size,
70 size_t *data_length);
71/**
72 * \brief Set the initialisation vector on the provided cipher operation (veneer
73 * function)
74 *
75 * \param[in] operation Cipher operation context
76 * \param[in] iv Buffer that contains the IV
77 * \param[in] iv_length Length of the provided IV
78 *
79 * \return Return values as described in \ref tfm_crypto_err_t
80 */
81enum tfm_crypto_err_t tfm_crypto_veneer_encrypt_set_iv(
82 psa_cipher_operation_t *operation,
83 const unsigned char *iv,
84 size_t iv_length);
85/**
86 * \brief Set the cipher operation using the provided algorithm and key slot,
87 * for encryption context (veneer function)
88 *
89 * \param[in] operation Cipher operation context
90 * \param[in] key Key slot to bind to the cipher context
91 * \param[in] alg Algorithm to use for the cipher operation
92 *
93 * \return Return values as described in \ref tfm_crypto_err_t
94 */
95enum tfm_crypto_err_t tfm_crypto_veneer_encrypt_setup(
96 psa_cipher_operation_t *operation,
97 psa_key_slot_t key,
98 psa_algorithm_t alg);
99/**
100 * \brief Set the cipher operation using the provided algorithm and key slot,
101 * for decryption context (veneer function)
102 *
103 * \param[in] operation Cipher operation context
104 * \param[in] key Key slot to bind to the cipher context
105 * \param[in] alg Algorithm to use for the cipher operation
106 *
107 * \return Return values as described in \ref tfm_crypto_err_t
108 */
109enum tfm_crypto_err_t tfm_crypto_veneer_decrypt_setup(
110 psa_cipher_operation_t *operation,
111 psa_key_slot_t key,
112 psa_algorithm_t alg);
113/**
114 * \brief Update the cipher context with a chunk of input data to create a
115 * chunk of encrypted output data (for encryption contexts), or to
116 * decrypt a chunk of encrypted input data to obtain decrypted data
117 * (for decryption contexts) (veneer function)
118 *
119 * \param[in] operation Cipher operation context
120 * \param[in] input_s Pointer to the struct containing input parameters
121 * \param[out] output_s Pointer to the struct containing output parameters
122 *
123 * \return Return values as described in \ref tfm_crypto_err_t
124 */
125enum tfm_crypto_err_t tfm_crypto_veneer_cipher_update(
126 psa_cipher_operation_t *operation,
127 struct psa_cipher_update_input *input_s,
128 struct psa_cipher_update_output *output_s);
129/**
130 * \brief Abort a cipher operation, clears the operation context provided
131 * (veneer function)
132 *
133 * \param[in] operation Cipher operation context
134 *
135 * \return Return values as described in \ref tfm_crypto_err_t
136 */
137enum tfm_crypto_err_t tfm_crypto_veneer_cipher_abort(
138 psa_cipher_operation_t *operation);
139
140/**
141 * \brief Finalise a cipher context flushing out any remaining block of
142 * output data (veneer function)
143 *
144 * \param[in] operation Cipher operation context
145 * \param[out] output Buffer containing output data
146 * \param[in] output_size Size of the output buffer
147 * \param[out] output_length Size of the produced output
148 *
149 * \return Return values as described in \ref tfm_crypto_err_t
150 */
151enum tfm_crypto_err_t tfm_crypto_veneer_cipher_finish(
152 psa_cipher_operation_t *operation,
153 uint8_t *output,
154 size_t output_size,
155 size_t *output_length);
156#ifdef __cplusplus
157}
158#endif
159
160#endif /* __TFM_CRYPTO_VENEERS_H__ */