AM273x MCU+ SDK  09.02.00
hsmclient.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2022-24 Texas Instruments Incorporated
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the
14  * 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
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #ifndef HSM_CLIENT_H_
34 #define HSM_CLIENT_H_
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 /* Header file for HSM client driver */
41 #include <stdint.h>
42 #include <drivers/sipc_notify.h>
45 #include <kernel/dpl/SemaphoreP.h>
46 
55 #define LABEL_AND_CONTEXT_LEN_MAX 48U
56 
62 typedef union HsmVer_t_
63 {
64  uint64_t HsmrtVer ;
65  struct
66  {
67  uint8_t PatchVer ;
68  uint8_t MinorVer ;
69  uint8_t MajorVer;
70  uint8_t ApiVer ;
71  uint8_t SocType ;
72  uint8_t BinType ;
73  uint8_t HsmType ;
74  uint8_t DevType ;
77 #if defined(_TMS320C6X)
78 }__attribute__((packed)) HsmVer_t_;
79 #else
80 }__attribute__((packed)) HsmVer_t;
81 #endif
82 
83 
89 typedef struct HsmClient_t_
90 {
93  HsmMsg_t ReqMsg ;
94  HsmMsg_t RespMsg ;
95  uint8_t RespFlag ;
96  uint8_t ClientId ;
98 } HsmClient_t ;
99 
105 typedef struct EfuseRead_t_
106 {
107  uint32_t rowData ;
108  uint8_t rowIdx ;
109  uint8_t rsvd[3];
110 } EfuseRead_t;
111 
117 typedef struct EfuseRowWrite_t_
118 {
119  uint32_t rowData ;
120  uint32_t rowBitMask ;
121  uint8_t rowIdx ;
122  uint8_t rsvd[3];
124 
130 typedef struct EfuseRowCount_t_
131 {
132  uint32_t rowCount ;
133  uint8_t rowSize ;
134  uint8_t rsvd[3];
136 
143 typedef struct EfuseRowProt_t_
144 {
145  uint8_t rowidx ;
146  uint8_t readProt ;
147  uint8_t writeProt ;
148  uint8_t rsvd[1];
149 } EfuseRowProt_t ;
150 
156 typedef struct keywriter_cert_header_t_
157 {
158  uint8_t* certAddress; /*For holding cerificate address*/
159  uint32_t certSize; /*Cerificate size*/
160  uint32_t debugResponse; /*Debug response*/
161  uint32_t reserved; /*reserved for future use*/
163 
169 typedef struct FirewallRegionReq_t_
170 {
171  uint16_t firewallId ;
172  uint16_t region ;
174  uint32_t startAddress;
175  uint32_t endAddress;
177 
183 typedef struct FirewallReq_t_
184 {
185  uint16_t regionCount;
186  uint16_t crcArr;
189 }FirewallReq_t ;
190 
197 typedef struct FirewallIntrReq_t_
198 {
199  uint16_t firewallId ;
200  uint8_t interruptEnable;
203  uint8_t faultClear;
205 
215 typedef struct SWRev_t_
216 {
217  uint32_t revValue;
218  uint8_t revId;
219  uint8_t rsvd[3];
220 } SWRev_t;
221 
232 typedef struct DKEK_t_
233 {
234  uint8_t label_length;
235  uint8_t context_length;
236  uint8_t label_and_context[LABEL_AND_CONTEXT_LEN_MAX];
237  uint32_t dkek[8];
238 } DKEK_t;
239 
251 typedef struct RNGReq_t_
252 {
253  uint8_t* resultPtr;
254  uint32_t* resultLengthPtr;
255  uint8_t DRBGMode;
256  uint32_t* seedValue;
258  uint8_t reserved;
259 } RNGReq_t;
260 
271 int32_t HsmClient_init(SIPC_Params* params);
272 
278 void HsmClient_deInit(void);
279 
295 int32_t HsmClient_getVersion(HsmClient_t *HsmClient ,
296  HsmVer_t* verId,uint32_t timeToWaitInTick);
297 
313 int32_t HsmClient_getUID(HsmClient_t* HsmClient,
314  uint8_t* uid, uint32_t timeout);
315 
332 int32_t HsmClient_openDbgFirewall(HsmClient_t* HsmClient,
333  uint8_t* cert,
334  uint32_t cert_size,
335  uint32_t timeout);
336 
353 int32_t HsmClient_importKeyring(HsmClient_t* HsmClient,
354  uint8_t* cert,
355  uint32_t cert_size,
356  uint32_t timeout);
357 
370 int32_t HsmClient_readOTPRow(HsmClient_t* HsmClient,
371  EfuseRead_t* readRow);
372 
385 int32_t HsmClient_writeOTPRow(HsmClient_t* HsmClient,
386  EfuseRowWrite_t* writeRow);
387 
400 int32_t HsmClient_lockOTPRow(HsmClient_t* HsmClient,
401  EfuseRowProt_t* rowProt);
402 
415 int32_t HsmClient_getOTPRowCount(HsmClient_t* HsmClient,
416  EfuseRowCount_t* rowCount);
417 
430 int32_t HsmClient_getOTPRowProtection(HsmClient_t* HsmClient,
431  EfuseRowProt_t* rowProt);
432 
449 int32_t HsmClient_procAuthBoot(HsmClient_t* HsmClient,
450  uint8_t* cert,
451  uint32_t cert_size,
452  uint32_t timeout);
453 
469 int32_t HsmClient_setFirewall(HsmClient_t* HsmClient,
470  FirewallReq_t* FirewallReqObj,
471  uint32_t timeout);
487 int32_t HsmClient_FirewallIntr(HsmClient_t* HsmClient,
488  FirewallIntrReq_t* FirewallIntrReqObj,
489  uint32_t timeout);
490 
503 int32_t HsmClient_keyWriter(HsmClient_t* HsmClient,
504  KeyWriterCertHeader_t* certHeader,
505  uint32_t timeout);
506 
519 int32_t HsmClient_readSWRev(HsmClient_t* HsmClient,
520  SWRev_t* readSWRev);
521 
534 int32_t HsmClient_writeSWRev(HsmClient_t* HsmClient,
535  SWRev_t* writeSWRev);
536 
553 int32_t HsmClient_getDKEK(HsmClient_t* HsmClient,
554  DKEK_t* getDKEK,
555  uint32_t timeout);
567 int32_t HsmClient_register(HsmClient_t* HsmClient, uint8_t clientId);
568 
577 void HsmClient_unregister(HsmClient_t* HsmClient,uint8_t clientId);
578 
592 int32_t HsmClient_waitForBootNotify(HsmClient_t* HsmClient,uint32_t timeToWaitInTicks);
593 
604 int32_t Hsmclient_loadHSMRtFirmware(HsmClient_t *gHSMClient, const uint8_t *pHSMRt_firmware);
605 
617 int32_t HsmClient_getRandomNum(HsmClient_t* HsmClient,
618  RNGReq_t* getRandomNum);
621 #ifdef __cplusplus
622 }
623 #endif
624 
625 #endif /* HSM_CLIENT_H_ */
SIPC_Params
Parameters used by SIPC_init.
Definition: sipc_notify.h:84
KeyWriterCertHeader_t::certSize
uint32_t certSize
Definition: hsmclient.h:159
EfuseRead_t::rowData
uint32_t rowData
Definition: hsmclient.h:107
HsmVer_t_
type for reading HSMRt version.
Definition: hsmclient.h:63
LABEL_AND_CONTEXT_LEN_MAX
#define LABEL_AND_CONTEXT_LEN_MAX
Definition: hsmclient.h:55
HsmClient_setFirewall
int32_t HsmClient_setFirewall(HsmClient_t *HsmClient, FirewallReq_t *FirewallReqObj, uint32_t timeout)
The service issued to HSM Server sets the firewall for the given firewall id and region.
Definition: hsmclient.c:916
HsmClient_writeSWRev
int32_t HsmClient_writeSWRev(HsmClient_t *HsmClient, SWRev_t *writeSWRev)
The service issued to HSM Server writes the SWRevision value based on identifier as param.
Definition: hsmclient.c:1290
HsmVer_t_::PatchVer
uint8_t PatchVer
Definition: hsmclient.h:67
EfuseRowProt_t
This is a EfuseRowProt type which holds the information of eFuse row index and protection status corr...
Definition: hsmclient.h:144
EfuseRowCount_t::rowCount
uint32_t rowCount
Definition: hsmclient.h:132
FirewallRegionReq_t::region
uint16_t region
Definition: hsmclient.h:172
HsmClient_t::RespFlag
uint8_t RespFlag
Definition: hsmclient.h:95
EfuseRowWrite_t::rowBitMask
uint32_t rowBitMask
Definition: hsmclient.h:120
EfuseRowProt_t::rowidx
uint8_t rowidx
Definition: hsmclient.h:145
DKEK_t
This is DKEK type which holds the label and context for derivation. This also holds the 256 derived K...
Definition: hsmclient.h:233
EfuseRowWrite_t
This is a EfuseRowWrite type which holds the information regarding programming eFuse row.
Definition: hsmclient.h:118
HsmClient_readSWRev
int32_t HsmClient_readSWRev(HsmClient_t *HsmClient, SWRev_t *readSWRev)
The service issued to HSM Server retrieves the SWRevision value based on identifier as param.
Definition: hsmclient.c:1222
HsmClient_importKeyring
int32_t HsmClient_importKeyring(HsmClient_t *HsmClient, uint8_t *cert, uint32_t cert_size, uint32_t timeout)
The service issued to HSM Server verifies the certificate and imports the keys from the certificate.
Definition: hsmclient.c:436
EfuseRead_t::rowIdx
uint8_t rowIdx
Definition: hsmclient.h:108
HsmVer_t_::HsmType
uint8_t HsmType
Definition: hsmclient.h:73
RNGReq_t::seedValue
uint32_t * seedValue
Definition: hsmclient.h:256
HsmVer_t_::MajorVer
uint8_t MajorVer
Definition: hsmclient.h:69
FirewallIntrReq_t::firewallId
uint16_t firewallId
Definition: hsmclient.h:199
FirewallReq_t::FirewallRegionArr
FirewallRegionReq_t * FirewallRegionArr
Definition: hsmclient.h:187
FirewallRegionReq_t
This is a FirewallRegionReq type which holds the information of Firewall region configuration.
Definition: hsmclient.h:170
RNGReq_t::resultPtr
uint8_t * resultPtr
Definition: hsmclient.h:253
HsmClient_t
This is a HSMClient type which holds the information needed by hsm client to communicate with HSM .
Definition: hsmclient.h:90
HsmVer_t_::SocType
uint8_t SocType
Definition: hsmclient.h:71
HsmVer_t_::ApiVer
uint8_t ApiVer
Definition: hsmclient.h:70
SemaphoreP.h
HsmVer_t_::HsmrtVer
uint64_t HsmrtVer
Definition: hsmclient.h:64
sipc_notify.h
HsmVer_t_::DevType
uint8_t DevType
Definition: hsmclient.h:74
RNGReq_t::seedSizeInDWords
uint8_t seedSizeInDWords
Definition: hsmclient.h:257
HsmClient_t::RespMsg
HsmMsg_t RespMsg
Definition: hsmclient.h:94
FirewallRegionReq_t::endAddress
uint32_t endAddress
Definition: hsmclient.h:175
HsmClient_openDbgFirewall
int32_t HsmClient_openDbgFirewall(HsmClient_t *HsmClient, uint8_t *cert, uint32_t cert_size, uint32_t timeout)
The service issued to HSM Server verifies the certificate and by default the hsm flag is set to HSM_F...
Definition: hsmclient.c:364
SWRev_t::revValue
uint32_t revValue
Definition: hsmclient.h:217
HsmClient_register
int32_t HsmClient_register(HsmClient_t *HsmClient, uint8_t clientId)
register a client to a particular ClientId
Definition: hsmclient.c:171
FirewallIntrReq_t
This is a FirewallIntrReq type which holds the information of MPU Firewall request for interrupt enab...
Definition: hsmclient.h:198
EfuseRowCount_t
This is a EfuseRowCount type which holds the information regarding eFuse row count and size of each r...
Definition: hsmclient.h:131
HsmClient_getOTPRowCount
int32_t HsmClient_getOTPRowCount(HsmClient_t *HsmClient, EfuseRowCount_t *rowCount)
The service issued to HSM Server retrieves the count of extended OTP rows.
Definition: hsmclient.c:710
FirewallReq_t
This is a FirewallReq_t type which holds the information of Firewall configuration.
Definition: hsmclient.h:184
EfuseRowProt_t::readProt
uint8_t readProt
Definition: hsmclient.h:146
FirewallIntrReq_t::interruptEnableClear
uint8_t interruptEnableClear
Definition: hsmclient.h:201
FirewallRegionReq_t::permissionAttributes
uint32_t permissionAttributes
Definition: hsmclient.h:173
HsmClient_init
int32_t HsmClient_init(SIPC_Params *params)
Initialize the HSM client for current core.
Definition: hsmclient.c:200
HsmClient_FirewallIntr
int32_t HsmClient_FirewallIntr(HsmClient_t *HsmClient, FirewallIntrReq_t *FirewallIntrReqObj, uint32_t timeout)
The service issued to HSM Server sets the firewall interrupt request for the given firewall id.
Definition: hsmclient.c:988
SWRev_t
This is SWRev type which holds the information regarding Revision identifier and value corresponding ...
Definition: hsmclient.h:216
HsmClient_getOTPRowProtection
int32_t HsmClient_getOTPRowProtection(HsmClient_t *HsmClient, EfuseRowProt_t *rowProt)
The service issued to HSM Server retrieves the extended otp efuse row protection status.
Definition: hsmclient.c:777
HsmVer_t_::BinType
uint8_t BinType
Definition: hsmclient.h:72
FirewallRegionReq_t::startAddress
uint32_t startAddress
Definition: hsmclient.h:174
HsmVer_t_::VerStruct
struct HsmVer_t_::@0 VerStruct
FirewallReq_t::statusFirewallRegionArr
uint16_t statusFirewallRegionArr
Definition: hsmclient.h:188
FirewallReq_t::regionCount
uint16_t regionCount
Definition: hsmclient.h:185
DKEK_t::context_length
uint8_t context_length
Definition: hsmclient.h:235
SWRev_t::revId
uint8_t revId
Definition: hsmclient.h:218
HsmClient_unregister
void HsmClient_unregister(HsmClient_t *HsmClient, uint8_t clientId)
unregister a client to a particular ClientId
Definition: hsmclient.c:221
FirewallIntrReq_t::faultClear
uint8_t faultClear
Definition: hsmclient.h:203
hsmclient_msg.h
HsmClient_writeOTPRow
int32_t HsmClient_writeOTPRow(HsmClient_t *HsmClient, EfuseRowWrite_t *writeRow)
The service issued to HSM Server writes the data to extended OTP efuse row based on row index provide...
Definition: hsmclient.c:576
FirewallIntrReq_t::interruptEnable
uint8_t interruptEnable
Definition: hsmclient.h:200
KeyWriterCertHeader_t::certAddress
uint8_t * certAddress
Definition: hsmclient.h:158
Hsmclient_loadHSMRtFirmware
int32_t Hsmclient_loadHSMRtFirmware(HsmClient_t *gHSMClient, const uint8_t *pHSMRt_firmware)
Loads the HSMRt firmware. This is typically called by SBL.
Definition: hsmclient_loadhsmrt.c:254
HsmClient_readOTPRow
int32_t HsmClient_readOTPRow(HsmClient_t *HsmClient, EfuseRead_t *readRow)
The service issued to HSM Server retrieves the data of GP OTP row based on row index provided as para...
Definition: hsmclient.c:508
HsmClient_waitForBootNotify
int32_t HsmClient_waitForBootNotify(HsmClient_t *HsmClient, uint32_t timeToWaitInTicks)
Current core will wait for bootnotify message from HSM core.
Definition: hsmclient.c:1121
EfuseRowWrite_t::rowData
uint32_t rowData
Definition: hsmclient.h:119
HsmClient_t::Semaphore
SemaphoreP_Object Semaphore
Definition: hsmclient.h:91
HsmVer_t_::MinorVer
uint8_t MinorVer
Definition: hsmclient.h:68
EfuseRowProt_t::writeProt
uint8_t writeProt
Definition: hsmclient.h:147
EfuseRead_t
This is a EfuseRead type which holds the information of eFuse row index and row data corresponding to...
Definition: hsmclient.h:106
FirewallRegionReq_t::firewallId
uint16_t firewallId
Definition: hsmclient.h:171
RNGReq_t::resultLengthPtr
uint32_t * resultLengthPtr
Definition: hsmclient.h:254
HsmClient_getUID
int32_t HsmClient_getUID(HsmClient_t *HsmClient, uint8_t *uid, uint32_t timeout)
The service issued to HSM Server populates the Device UID by default the hsm flag is set to HSM_FLAG_...
Definition: hsmclient.c:296
HsmClient_keyWriter
int32_t HsmClient_keyWriter(HsmClient_t *HsmClient, KeyWriterCertHeader_t *certHeader, uint32_t timeout)
The service issued to HSM Server verifies the certificate and process the keywriter operations,...
Definition: hsmclient.c:1151
EfuseRowWrite_t::rowIdx
uint8_t rowIdx
Definition: hsmclient.h:121
HsmClient_t::ClientId
uint8_t ClientId
Definition: hsmclient.h:96
SemaphoreP_Object
Opaque semaphore object used with the semaphore APIs.
Definition: SemaphoreP.h:59
HsmClient_getRandomNum
int32_t HsmClient_getRandomNum(HsmClient_t *HsmClient, RNGReq_t *getRandomNum)
Returns the Random Number Generated.
Definition: hsmclient.c:1358
KeyWriterCertHeader_t::debugResponse
uint32_t debugResponse
Definition: hsmclient.h:160
HsmClient_getDKEK
int32_t HsmClient_getDKEK(HsmClient_t *HsmClient, DKEK_t *getDKEK, uint32_t timeout)
The service issued to HSM Server retrieves the derived KEK based on identifier as param.
Definition: hsmclient.c:1054
RNGReq_t::reserved
uint8_t reserved
Definition: hsmclient.h:258
EfuseRowCount_t::rowSize
uint8_t rowSize
Definition: hsmclient.h:133
KeyWriterCertHeader_t::reserved
uint32_t reserved
Definition: hsmclient.h:161
DKEK_t::label_length
uint8_t label_length
Definition: hsmclient.h:234
__attribute__
union HsmVer_t_ __attribute__((packed)) HsmVer_t
type for reading HSMRt version.
KeyWriterCertHeader_t
This is a keywriter_cert_header type which holds the information of customer key certificate and debu...
Definition: hsmclient.h:157
FirewallIntrReq_t::interruptEnableStatusClear
uint8_t interruptEnableStatusClear
Definition: hsmclient.h:202
FirewallReq_t::crcArr
uint16_t crcArr
Definition: hsmclient.h:186
RNGReq_t
This is RNG type which holds the resultPtr for derivation which is returned by TIFS....
Definition: hsmclient.h:252
HsmClient_procAuthBoot
int32_t HsmClient_procAuthBoot(HsmClient_t *HsmClient, uint8_t *cert, uint32_t cert_size, uint32_t timeout)
The service issued to HSM Server helps with extended secure boot for applications.
Definition: hsmclient.c:844
HsmClient_getVersion
int32_t HsmClient_getVersion(HsmClient_t *HsmClient, HsmVer_t *verId, uint32_t timeToWaitInTick)
populates the current HSMRT version Id by default the hsm flag is set to HSM_FLAG_AOP for this servic...
Definition: hsmclient.c:227
RNGReq_t::DRBGMode
uint8_t DRBGMode
Definition: hsmclient.h:255
HsmClient_lockOTPRow
int32_t HsmClient_lockOTPRow(HsmClient_t *HsmClient, EfuseRowProt_t *rowProt)
The service issued to HSM Server sets the protection status bit of the specified row to 1.
Definition: hsmclient.c:643
hsmclient_utils.h
HsmClient_t::ReqMsg
HsmMsg_t ReqMsg
Definition: hsmclient.h:93
HsmClient_deInit
void HsmClient_deInit(void)
De initialize the HSM client for current core.