Mistake on this page?
Report an issue in GitHub or email us
TARGET_TFM/TARGET_TFM_V1_0/include/psa/crypto_types.h
1 /*
2  * Copyright (c) 2018-2020, Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 /**
8  * \file psa/crypto_types.h
9  *
10  * \brief PSA cryptography module: type aliases.
11  *
12  * \note This file may not be included directly. Applications must
13  * include psa/crypto.h. Drivers must include the appropriate driver
14  * header file.
15  *
16  * This file contains portable definitions of integral types for properties
17  * of cryptographic keys, designations of cryptographic algorithms, and
18  * error codes returned by the library.
19  *
20  * This header file does not declare any function.
21  */
22 
23 #ifndef PSA_CRYPTO_TYPES_H
24 #define PSA_CRYPTO_TYPES_H
25 
26 #include <stdint.h>
27 
28 /** \defgroup error Error codes
29  * @{
30  */
31 
32 /**
33  * \brief Function return status.
34  *
35  * This is either #PSA_SUCCESS (which is zero), indicating success,
36  * or a small negative value indicating that an error occurred. Errors are
37  * encoded as one of the \c PSA_ERROR_xxx values defined here. */
38 /* If #PSA_SUCCESS is already defined, it means that #psa_status_t
39  * is also defined in an external header, so prevent its multiple
40  * definition.
41  */
42 #ifndef PSA_SUCCESS
43 typedef int32_t psa_status_t;
44 #endif
45 
46 /**@}*/
47 
48 /** \defgroup crypto_types Key and algorithm types
49  * @{
50  */
51 
52 /** \brief Encoding of a key type.
53  */
54 typedef uint32_t psa_key_type_t;
55 
56 /** The type of PSA elliptic curve identifiers.
57  *
58  * The curve identifier is required to create an ECC key using the
59  * PSA_KEY_TYPE_ECC_KEY_PAIR() or PSA_KEY_TYPE_ECC_PUBLIC_KEY()
60  * macros.
61  *
62  * The encoding of curve identifiers is taken from the
63  * TLS Supported Groups Registry (formerly known as the
64  * TLS EC Named Curve Registry)
65  * https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-8
66  *
67  * This specification defines identifiers for some of the curves in the IANA
68  * registry. Implementations that support other curves that are in the IANA
69  * registry should use the IANA value and a implementation-specific identifier.
70  * Implemenations that support non-IANA curves should use one of the following
71  * approaches for allocating a key type:
72  *
73  * 1. Select a ::psa_ecc_curve_t value in the range #PSA_ECC_CURVE_VENDOR_MIN to
74  * #PSA_ECC_CURVE_VENDOR_MAX, which is a subset of the IANA private use
75  * range.
76  * 2. Use a ::psa_key_type_t value that is vendor-defined.
77  *
78  * The first option is recommended.
79  */
80 typedef uint16_t psa_ecc_curve_t;
81 
82 /** The type of PSA Diffie-Hellman group identifiers.
83  *
84  * The group identifier is required to create an Diffie-Hellman key using the
85  * PSA_KEY_TYPE_DH_KEY_PAIR() or PSA_KEY_TYPE_DH_PUBLIC_KEY()
86  * macros.
87  *
88  * The encoding of group identifiers is taken from the
89  * TLS Supported Groups Registry (formerly known as the
90  * TLS EC Named Curve Registry)
91  * https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-8
92  *
93  * This specification defines identifiers for some of the groups in the IANA
94  * registry. Implementations that support other groups that are in the IANA
95  * registry should use the IANA value and a implementation-specific identifier.
96  * Implemenations that support non-IANA groups should use one of the following
97  * approaches for allocating a key type:
98  *
99  * 1. Select a ::psa_dh_group_t value in the range #PSA_DH_GROUP_VENDOR_MIN to
100  * #PSA_DH_GROUP_VENDOR_MAX, which is a subset of the IANA private use
101  * range.
102  * 2. Select a ::psa_dh_group_t value from the named groups allocated for
103  * GREASE in the IETF draft specification. The GREASE specification and
104  * values are listed below.
105  * 3. Use a ::psa_key_type_t value that is vendor-defined.
106  *
107  * Option 1 or 2 are recommended.
108  *
109  * The current draft of the GREASE specification is
110  * https://datatracker.ietf.org/doc/draft-ietf-tls-grease
111  *
112  * The following GREASE values are allocated for named groups:
113  * \code
114  * 0x0A0A
115  * 0x1A1A
116  * 0x2A2A
117  * 0x3A3A
118  * 0x4A4A
119  * 0x5A5A
120  * 0x6A6A
121  * 0x7A7A
122  * 0x8A8A
123  * 0x9A9A
124  * 0xAAAA
125  * 0xBABA
126  * 0xCACA
127  * 0xDADA
128  * 0xEAEA
129  * 0xFAFA
130  * \endcode
131  */
132 typedef uint16_t psa_dh_group_t;
133 
134 /** \brief Encoding of a cryptographic algorithm.
135  *
136  * For algorithms that can be applied to multiple key types, this type
137  * does not encode the key type. For example, for symmetric ciphers
138  * based on a block cipher, #psa_algorithm_t encodes the block cipher
139  * mode and the padding mode while the block cipher itself is encoded
140  * via #psa_key_type_t.
141  */
142 typedef uint32_t psa_algorithm_t;
143 
144 /**@}*/
145 
146 /** \defgroup key_lifetimes Key lifetimes
147  * @{
148  */
149 
150 /** Encoding of key lifetimes.
151  *
152  * The lifetime of a key indicates where it is stored and what system actions
153  * may create and destroy it.
154  *
155  * Keys with the lifetime #PSA_KEY_LIFETIME_VOLATILE are automatically
156  * destroyed when the application terminates or on a power reset.
157  *
158  * Keys with a lifetime other than #PSA_KEY_LIFETIME_VOLATILE are said
159  * to be _persistent_.
160  * Persistent keys are preserved if the application or the system restarts.
161  * Persistent keys have a key identifier of type #psa_key_id_t.
162  * The application can call psa_open_key() to open a persistent key that
163  * it created previously.
164  */
165 typedef uint32_t psa_key_lifetime_t;
166 
167 /** Encoding of identifiers of persistent keys.
168  *
169  * - Applications may freely choose key identifiers in the range
170  * #PSA_KEY_ID_USER_MIN to #PSA_KEY_ID_USER_MAX.
171  * - Implementations may define additional key identifiers in the range
172  * #PSA_KEY_ID_VENDOR_MIN to #PSA_KEY_ID_VENDOR_MAX.
173  * - 0 is reserved as an invalid key identifier.
174  * - Key identifiers outside these ranges are reserved for future use.
175  */
176 typedef uint32_t psa_key_id_t;
177 #define PSA_KEY_ID_INIT 0
178 
179 /**@}*/
180 
181 /** \defgroup policy Key policies
182  * @{
183  */
184 
185 /** \brief Encoding of permitted usage on a key. */
186 typedef uint32_t psa_key_usage_t;
187 
188 /**@}*/
189 
190 /** \defgroup attributes Key attributes
191  * @{
192  */
193 
194 /** The type of a structure containing key attributes.
195  *
196  * This is an opaque structure that can represent the metadata of a key
197  * object. Metadata that can be stored in attributes includes:
198  * - The location of the key in storage, indicated by its key identifier
199  * and its lifetime.
200  * - The key's policy, comprising usage flags and a specification of
201  * the permitted algorithm(s).
202  * - Information about the key itself: the key type and its size.
203  * - Implementations may define additional attributes.
204  *
205  * The actual key material is not considered an attribute of a key.
206  * Key attributes do not contain information that is generally considered
207  * highly confidential.
208  *
209  * An attribute structure can be a simple data structure where each function
210  * `psa_set_key_xxx` sets a field and the corresponding function
211  * `psa_get_key_xxx` retrieves the value of the corresponding field.
212  * However, implementations may report values that are equivalent to the
213  * original one, but have a different encoding. For example, an
214  * implementation may use a more compact representation for types where
215  * many bit-patterns are invalid or not supported, and store all values
216  * that it does not support as a special marker value. In such an
217  * implementation, after setting an invalid value, the corresponding
218  * get function returns an invalid value which may not be the one that
219  * was originally stored.
220  *
221  * An attribute structure may contain references to auxiliary resources,
222  * for example pointers to allocated memory or indirect references to
223  * pre-calculated values. In order to free such resources, the application
224  * must call psa_reset_key_attributes(). As an exception, calling
225  * psa_reset_key_attributes() on an attribute structure is optional if
226  * the structure has only been modified by the following functions
227  * since it was initialized or last reset with psa_reset_key_attributes():
228  * - psa_set_key_id()
229  * - psa_set_key_lifetime()
230  * - psa_set_key_type()
231  * - psa_set_key_bits()
232  * - psa_set_key_usage_flags()
233  * - psa_set_key_algorithm()
234  *
235  * Before calling any function on a key attribute structure, the application
236  * must initialize it by any of the following means:
237  * - Set the structure to all-bits-zero, for example:
238  * \code
239  * psa_key_attributes_t attributes;
240  * memset(&attributes, 0, sizeof(attributes));
241  * \endcode
242  * - Initialize the structure to logical zero values, for example:
243  * \code
244  * psa_key_attributes_t attributes = {0};
245  * \endcode
246  * - Initialize the structure to the initializer #PSA_KEY_ATTRIBUTES_INIT,
247  * for example:
248  * \code
249  * psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
250  * \endcode
251  * - Assign the result of the function psa_key_attributes_init()
252  * to the structure, for example:
253  * \code
254  * psa_key_attributes_t attributes;
255  * attributes = psa_key_attributes_init();
256  * \endcode
257  *
258  * A freshly initialized attribute structure contains the following
259  * values:
260  *
261  * - lifetime: #PSA_KEY_LIFETIME_VOLATILE.
262  * - key identifier: 0 (which is not a valid key identifier).
263  * - type: \c 0 (meaning that the type is unspecified).
264  * - key size: \c 0 (meaning that the size is unspecified).
265  * - usage flags: \c 0 (which allows no usage except exporting a public key).
266  * - algorithm: \c 0 (which allows no cryptographic usage, but allows
267  * exporting).
268  *
269  * A typical sequence to create a key is as follows:
270  * -# Create and initialize an attribute structure.
271  * -# If the key is persistent, call psa_set_key_id().
272  * Also call psa_set_key_lifetime() to place the key in a non-default
273  * location.
274  * -# Set the key policy with psa_set_key_usage_flags() and
275  * psa_set_key_algorithm().
276  * -# Set the key type with psa_set_key_type().
277  * Skip this step if copying an existing key with psa_copy_key().
278  * -# When generating a random key with psa_generate_key() or deriving a key
279  * with psa_key_derivation_output_key(), set the desired key size with
280  * psa_set_key_bits().
281  * -# Call a key creation function: psa_import_key(), psa_generate_key(),
282  * psa_key_derivation_output_key() or psa_copy_key(). This function reads
283  * the attribute structure, creates a key with these attributes, and
284  * outputs a handle to the newly created key.
285  * -# The attribute structure is now no longer necessary.
286  * You may call psa_reset_key_attributes(), although this is optional
287  * with the workflow presented here because the attributes currently
288  * defined in this specification do not require any additional resources
289  * beyond the structure itself.
290  *
291  * A typical sequence to query a key's attributes is as follows:
292  * -# Call psa_get_key_attributes().
293  * -# Call `psa_get_key_xxx` functions to retrieve the attribute(s) that
294  * you are interested in.
295  * -# Call psa_reset_key_attributes() to free any resources that may be
296  * used by the attribute structure.
297  *
298  * Once a key has been created, it is impossible to change its attributes.
299  */
301 
302 /**@}*/
303 
304 /** \defgroup derivation Key derivation
305  * @{
306  */
307 
308 /** \brief Encoding of the step of a key derivation. */
309 typedef uint16_t psa_key_derivation_step_t;
310 
311 /**@}*/
312 
313 #endif /* PSA_CRYPTO_TYPES_H */
uint16_t psa_ecc_curve_t
The type of PSA elliptic curve identifiers.
uint16_t psa_key_derivation_step_t
Encoding of the step of a key derivation.
uint32_t psa_key_id_t
Encoding of identifiers of persistent keys.
uint16_t psa_dh_group_t
The type of PSA Diffie-Hellman group identifiers.
uint32_t psa_algorithm_t
Encoding of a cryptographic algorithm.
uint32_t psa_key_usage_t
Encoding of permitted usage on a key.
uint32_t psa_key_type_t
Encoding of a key type.
uint32_t psa_key_lifetime_t
Encoding of key lifetimes.
int32_t psa_status_t
Function return status.
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.