CryptoKeyKeyStore_PSA_s.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2022-2023, Texas Instruments Incorporated - https://www.ti.com
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 /*!*****************************************************************************
34  * @file CryptoKeyKeyStore_PSA_s.h
35  * @brief Secure Crypto Service
36  *
37  * @anchor ti_drivers_cryptoutils_cryptokey_CryptoKeyKeyStore_PSA_s_Overview
38  * # Overview
39  * The Secure KeyStore driver is used to access all KeyStore functions
40  * when using the TF-M.
41  *
42  *******************************************************************************
43  */
44 #ifndef ti_drivers_cryptoutils_cryptokey_CryptoKeyKeyStore_PSA_s__include
45 #define ti_drivers_cryptoutils_cryptokey_CryptoKeyKeyStore_PSA_s__include
46 
47 #include <stdint.h>
48 
51 
52 #include <third_party/tfm/interface/include/psa/crypto.h>
53 #include <third_party/tfm/interface/include/psa/service.h>
54 
55 /* For client side key attribute structure */
56 #include <third_party/tfm/interface/include/psa/crypto_client_struct.h>
57 
58 /*
59  * Crypto Key Store secure message types
60  */
61 #define KEYSTORE_PSA_S_MSG_TYPE_GET_KEY KEYSTORE_PSA_S_MSG_TYPE(0U)
62 #define KEYSTORE_PSA_S_MSG_TYPE_GENERATE_KEY KEYSTORE_PSA_S_MSG_TYPE(1U)
63 #define KEYSTORE_PSA_S_MSG_TYPE_EXPORT_CERTIFICATE KEYSTORE_PSA_S_MSG_TYPE(2U)
64 #define KEYSTORE_PSA_S_MSG_TYPE_EXPORT_PUBLIC_KEY KEYSTORE_PSA_S_MSG_TYPE(3U)
65 #define KEYSTORE_PSA_S_MSG_TYPE_EXPORT_KEY KEYSTORE_PSA_S_MSG_TYPE(4U)
66 #define KEYSTORE_PSA_S_MSG_TYPE_DESTROY_CERTIFICATE KEYSTORE_PSA_S_MSG_TYPE(5U)
67 #define KEYSTORE_PSA_S_MSG_TYPE_DESTROY_KEY KEYSTORE_PSA_S_MSG_TYPE(6U)
68 #define KEYSTORE_PSA_S_MSG_TYPE_IMPORT_CERTIFICATE KEYSTORE_PSA_S_MSG_TYPE(7U)
69 #define KEYSTORE_PSA_S_MSG_TYPE_IMPORT_KEY KEYSTORE_PSA_S_MSG_TYPE(8U)
70 #define KEYSTORE_PSA_S_MSG_TYPE_PURGE_KEY KEYSTORE_PSA_S_MSG_TYPE(9U)
71 #define KEYSTORE_PSA_S_MSG_TYPE_GET_KEY_ATTRIBUTES KEYSTORE_PSA_S_MSG_TYPE(10U)
72 #define KEYSTORE_PSA_S_MSG_TYPE_RESET_KEY_ATTRIBUTES KEYSTORE_PSA_S_MSG_TYPE(11U)
73 
74 /*
75  * ============ KeyStore driver Secure Message Structs =========
76  * These secure message structs correspond to the secure message types defined
77  * above. Together, they are used by non-secure client to make PSA calls to the
78  * KeyStore secure service. There is a single input vector for the PSA call
79  * which is a pointer to secure message struct. If the underlying function
80  * has a return value, there is a single output vector which is a pointer to
81  * storage for the return value.
82  */
83 typedef struct
84 {
85  uint32_t key;
86  uint8_t *data;
87  size_t dataSize;
88  size_t *dataLength;
92 
93 typedef struct
94 {
95  struct psa_client_key_attributes_s *attributes;
98 
99 /* Msg for KeyStore_PSA_exportKey(), KeyStore_PSA_exportCertificate(), and KeyStore_PSA_exportPublicKey() */
100 typedef struct
101 {
102  uint32_t key;
103  uint8_t *data;
104  size_t dataSize;
105  size_t *dataLength;
107 
108 typedef struct
109 {
110  struct psa_client_key_attributes_s *attributes;
111  uint32_t *key;
112  uint8_t *data;
113  size_t dataLength;
115 
116 typedef struct
117 {
118  struct psa_client_key_attributes_s *attributes;
119  uint8_t *data;
120  size_t dataLength;
121  uint32_t *key;
123 
124 /* Msg for KeyStore_PSA_destroyKey(), KeyStore_PSA_destroyCertificate(), and KeyStore_PSA_purgeKey() */
125 typedef struct
126 {
127  uint32_t key;
129 
130 typedef struct
131 {
132  uint32_t key;
133  struct psa_client_key_attributes_s *attributes;
135 
136 typedef struct
137 {
138  struct psa_client_key_attributes_s *attributes;
140 
151 psa_status_t KeyStore_s_handlePsaMsg(psa_msg_t *msg);
152 
158 void KeyStore_s_init(void);
159 
171 psa_status_t KeyStore_s_copyKeyAttributesFromClient(struct psa_client_key_attributes_s *clientKeyAttr,
172  int32_t clientId,
173  psa_key_attributes_t *keyAttributes);
174 
183 void KeyStore_s_copyKeyIDFromClient(KeyStore_PSA_KeyFileId *keyID, int32_t clientId, uint32_t *clientKeyID);
184 #endif /* ti_drivers_cryptoutils_cryptokey_CryptoKeyKeyStore_PSA_s__include */
Definition: CryptoKeyKeyStore_PSA_s.h:116
size_t dataSize
Definition: CryptoKeyKeyStore_PSA_s.h:104
psa_key_usage_t KeyStore_PSA_KeyUsage
Encoding of permitted usage on a key.
Definition: CryptoKeyKeyStore_PSA.h:125
uint32_t key
Definition: CryptoKeyKeyStore_PSA_s.h:85
uint32_t * key
Definition: CryptoKeyKeyStore_PSA_s.h:121
KeyStore_PSA_Algorithm alg
Definition: CryptoKeyKeyStore_PSA_s.h:89
uint32_t key
Definition: CryptoKeyKeyStore_PSA_s.h:132
uint32_t key
Definition: CryptoKeyKeyStore_PSA_s.h:127
CryptoKeyKeyStore_PSA driver header.
Definition: CryptoKeyKeyStore_PSA_s.h:125
psa_status_t KeyStore_s_handlePsaMsg(psa_msg_t *msg)
Handles PSA messages for KeyStore secure driver.
KeyStore_PSA_KeyUsage usage
Definition: CryptoKeyKeyStore_PSA_s.h:90
mbedtls_svc_key_id_t KeyStore_PSA_KeyFileId
Definition: CryptoKeyKeyStore_PSA.h:932
struct psa_client_key_attributes_s * attributes
Definition: CryptoKeyKeyStore_PSA_s.h:133
Secure Crypto Service.
Definition: CryptoKeyKeyStore_PSA_s.h:83
uint8_t * data
Definition: CryptoKeyKeyStore_PSA_s.h:103
uint32_t key
Definition: CryptoKeyKeyStore_PSA_s.h:102
uint8_t * data
Definition: CryptoKeyKeyStore_PSA_s.h:119
Definition: CryptoKeyKeyStore_PSA_s.h:93
uint32_t * key
Definition: CryptoKeyKeyStore_PSA_s.h:111
uint8_t * data
Definition: CryptoKeyKeyStore_PSA_s.h:112
size_t * dataLength
Definition: CryptoKeyKeyStore_PSA_s.h:88
KeyStore_PSA_KeyFileId * key
Definition: CryptoKeyKeyStore_PSA_s.h:96
struct psa_client_key_attributes_s * attributes
Definition: CryptoKeyKeyStore_PSA_s.h:110
void KeyStore_s_copyKeyIDFromClient(KeyStore_PSA_KeyFileId *keyID, int32_t clientId, uint32_t *clientKeyID)
Copies client key ID from non-secure side to secure side.
Definition: CryptoKeyKeyStore_PSA_s.h:100
size_t dataLength
Definition: CryptoKeyKeyStore_PSA_s.h:113
size_t dataLength
Definition: CryptoKeyKeyStore_PSA_s.h:120
psa_algorithm_t KeyStore_PSA_Algorithm
Encoding of a cryptographic algorithm.
Definition: CryptoKeyKeyStore_PSA.h:463
psa_status_t KeyStore_s_copyKeyAttributesFromClient(struct psa_client_key_attributes_s *clientKeyAttr, int32_t clientId, psa_key_attributes_t *keyAttributes)
Gets key attributes from client key attributes. Follows tfm_crypto_key_attributes_from_client() ...
struct psa_client_key_attributes_s * attributes
Definition: CryptoKeyKeyStore_PSA_s.h:138
Definition: CryptoKeyKeyStore_PSA_s.h:130
Definition: CryptoKeyKeyStore_PSA_s.h:108
size_t dataSize
Definition: CryptoKeyKeyStore_PSA_s.h:87
struct psa_client_key_attributes_s * attributes
Definition: CryptoKeyKeyStore_PSA_s.h:118
Definition: CryptoKeyKeyStore_PSA_s.h:136
struct psa_client_key_attributes_s * attributes
Definition: CryptoKeyKeyStore_PSA_s.h:95
size_t * dataLength
Definition: CryptoKeyKeyStore_PSA_s.h:105
uint8_t * data
Definition: CryptoKeyKeyStore_PSA_s.h:86
void KeyStore_s_init(void)
Initializes the KeyStore secure driver.
© Copyright 1995-2023, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale