1 /*
2 * Copyright (c) 2024, Arm Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7 #ifndef DEFAULT_PSA_CRYPTO_BACKEND_H
8 #define DEFAULT_PSA_CRYPTO_BACKEND_H
9
10 #include <stdint.h>
11
12 /**
13 * Provides the common crypto backend interface, based on the psa crypto
14 * API. To accommodate backend specific overrides to API types, a
15 * backend may provide its own API definitions.
16 */
17 #include <psa/crypto.h>
18
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22
23 /**
24 * Crypto frontends that support some kind of key id namespacing, should
25 * use this type for key ids. Namespacing allows for partitioning of
26 * the key id namespace. The nature of the partitioning is up to a
27 * crypto frontend. Note that a backend may override this typedef to
28 * suite the backend's handling of namespaces.
29 */
30 typedef psa_key_id_t namespaced_key_id_t;
31 #define NAMESPACED_KEY_ID_INIT PSA_KEY_ID_NULL
32
33 /**
34 * An overridable type for a key id namespace.
35 */
36 typedef int32_t key_id_namespace_t;
37 #define KEY_ID_NAMESPACE_INIT 0
38
39 /**
40 * \brief Initialize a namespaced key id
41 *
42 * This default implementation just discards the namespace.
43 *
44 * \param namespaced_key_id The object to initialize
45 * \param key_namespace The namespace
46 * \param key_id The key id
47 */
namespaced_key_id_init(namespaced_key_id_t * namespaced_key_id,key_id_namespace_t key_namespace,psa_key_id_t key_id)48 static inline void namespaced_key_id_init(namespaced_key_id_t *namespaced_key_id,
49 key_id_namespace_t key_namespace,
50 psa_key_id_t key_id)
51 {
52 (void)key_namespace;
53 *namespaced_key_id = key_id;
54 }
55
56 /**
57 * \brief Get the key id from a namespaced_key_id_t
58 *
59 * \param namespaced_key_id Namespaced key id
60 * \return Key id without namespace
61 */
namespaced_key_id_get_key_id(namespaced_key_id_t namespaced_key_id)62 static inline psa_key_id_t namespaced_key_id_get_key_id(namespaced_key_id_t namespaced_key_id)
63 {
64 return namespaced_key_id;
65 }
66
67 /**
68 * \brief Set the key id namespace associated with a key attributes object
69 *
70 * The default implementation discards the namespace
71 *
72 * \param attributes Key attributes object
73 * \param key_namespace Key id namespace
74 */
namespaced_key_id_set_namespace(psa_key_attributes_t * attributes,key_id_namespace_t key_namespace)75 static inline void namespaced_key_id_set_namespace(psa_key_attributes_t *attributes,
76 key_id_namespace_t key_namespace)
77 {
78 (void)attributes;
79 (void)key_namespace;
80 }
81
82 #ifdef __cplusplus
83 } /* extern "C" */
84 #endif
85
86 #endif /* DEFAULT_PSA_CRYPTO_BACKEND_H */
87