HSMLPF3.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023-2024, Texas Instruments Incorporated
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 HSMLPF3.h
35  *
36  * @brief Interface to for all HSM-related operations
37  *
38  * This module provides functions for use of the Hardware Security Module.
39  *
40  * The HSM initialization procedure must first enable the clock, then initialize the
41  * mailbox, and finally boot the device.
42  *
43  * APIs are provided to synchronize access to the HSM and submit command tokens,
44  * constructed by TI crypto drivers.
45  *
46  * Additional APIs to construct command tokens, interpret result token data as well as additional key/asset management
47  * operations.
48  *
49  *
50  *
51  */
52 
53 #include <stdint.h>
54 #include <stdbool.h>
55 
56 #include <ti/drivers/SHA2.h>
58 
59 #include <ti/drivers/ECDSA.h>
61 
62 #include <ti/drivers/AESGCM.h>
64 
65 #include <ti/drivers/AESECB.h>
67 
68 #include <ti/drivers/AESCTR.h>
70 
71 #include <ti/drivers/AESCBC.h>
73 
74 #include <ti/drivers/AESCMAC.h>
76 
77 #include <ti/drivers/AESCCM.h>
79 
82 #include <third_party/hsmddk/include/Kit/EIP130/TokenHelper/incl/eip130_token_common.h>
83 
90 #define HSMLPF3_STATUS_SUCCESS ((int_fast16_t)0)
91 
98 #define HSMLPF3_STATUS_ERROR ((int_fast16_t)-1)
99 
107 #define HSMLPF3_STATUS_TIMEOUT ((int_fast16_t)-2)
108 
124 typedef enum
125 {
146 
154 typedef void (*HSMLPF3_CallbackFxn)(uintptr_t arg0);
155 
163 typedef struct
164 {
165  Eip130Token_Command_t commandToken;
166  Eip130Token_Result_t resultToken;
169  uintptr_t driverHandle;
171 
172 #define AES_MODE_ENCRYPT 1U
173 #define AES_MODE_DECRYPT 0U
174 
175 #define HSMLPF3_RETVAL_MASK MASK_8_BITS
176 
189 
196 void HSMLPF3_disableClock(void);
197 
212 int_fast16_t HSMLPF3_sleep(void);
213 
229 int_fast16_t HSMLPF3_init(void);
230 
248 bool HSMLPF3_acquireLock(uint32_t timeout, uintptr_t driverHandle);
249 
258 void HSMLPF3_releaseLock(void);
259 
284 int_fast16_t HSMLPF3_submitToken(HSMLPF3_ReturnBehavior retBehavior,
285  HSMLPF3_CallbackFxn callbackFxn,
286  uintptr_t driverHandle);
287 
302 int_fast16_t HSMLPF3_waitForResult(void);
303 
313 int_fast16_t HSMLPF3_cancelOperation(void);
314 
322 
323 /*
324  * ================ APIs to handle result token data ================
325  */
326 
335 int32_t HSMLPF3_getResultCode(void);
336 
345 uint32_t HSMLPF3_getResultAssetID(void);
346 
354 void HSMLPF3_getResultDigest(uint32_t *digest, size_t digestLength);
355 
361 void HSMLPF3_getAESEncryptTag(uint8_t *mac);
362 
368 void HSMLPF3_getAESIV(uint8_t *iv);
369 
376 void HSMLPF3_getAESCMACSignMac(uint8_t *mac, uint8_t macLength);
377 
378 /*
379  * ================ APIs to construct key/asset management-related command tokens ================
380  */
381 
389 void HSMLPF3_constructCreateAssetToken(uint64_t assetPolicy, uint32_t assetLength);
390 
403 void HSMLPF3_constructLoadPlaintextAssetToken(const uint8_t *input_p, const uint32_t inputLength, uint32_t assetId);
404 
412 void HSMLPF3_constructDeleteAssetToken(uint32_t assetId);
413 
414 /*
415  * ================ APIs to construct driver-specific command tokens ================
416  */
417 
424 void HSMLPF3_constructSHA2PhysicalToken(SHA2LPF3HSM_Object *object);
425 
432 
440 void HSMLPF3_constructECDHnumLoadPhysicalToken(const uint8_t *buffer, uint8_t index, uint8_t length);
441 
447 void HSMLPF3_constructECDHnumSetPhysicalToken(uint8_t length);
448 
458  uint8_t *input,
459  uint8_t *output,
460  uint32_t inputLength);
461 
468 
475 
482 
489 
496 
503 
510 
517 
518 /*
519  * @brief Constructs an AES-CBC one-step command token
520  *
521  * @param [in] object The AESCBCLPF3 object that contains necessary data
522  */
524 
531 
537 void HSMLPF3_constructAESCMACUpdatePhysicalToken(AESCMACLPF3_Object *object, bool isInitWithDefault);
bool HSMLPF3_acquireLock(uint32_t timeout, uintptr_t driverHandle)
Acquires the HSMLPF3_accessSemaphore.
void HSMLPF3_getResultDigest(uint32_t *digest, size_t digestLength)
Copies a hash operation&#39;s digest to user space.
TI Driver for Elliptic Curve Digital Signature Algorithm.
void HSMLPF3_releaseLock(void)
Releases the lock on HSM access.
AESCBC driver header.
void HSMLPF3_constructECDHnumSetPhysicalToken(uint8_t length)
Constructs a ECDH num set command token.
The CryptoKey type is an opaque representation of a cryptographic key.
void HSMLPF3_constructAESCMACUpdatePhysicalToken(AESCMACLPF3_Object *object, bool isInitWithDefault)
Constructs an AES-CMAC update command token.
void HSMLPF3_constructAESGCMOneStepPhysicalToken(AESGCMLPF3HSM_Object *object)
Constructs an AES-GCM one-step/segmented command token.
int_fast16_t HSMLPF3_waitForResult(void)
Waits for HSM response to previously submitted token.
void HSMLPF3_constructCreateAssetToken(uint64_t assetPolicy, uint32_t assetLength)
Constructs an asset create command token.
ECDSALPF3HSM Object.
Definition: ECDSALPF3HSM.h:102
int_fast16_t HSMLPF3_init(void)
Initializes the HSM and HSMLPF3 driver for token submissions.
void HSMLPF3_constructECDSASignPhysicalToken(ECDSALPF3HSM_Object *object)
Constructs a ECDSA sign/verify command token.
void HSMLPF3_constructECDHnumLoadPhysicalToken(const uint8_t *buffer, uint8_t index, uint8_t length)
Constructs a ECDH num load command token.
AESCMACLPF3 Object.
Definition: AESCMACLPF3.h:125
AESGCM driver implementation for the Low Power F3 family.
HSMLPF3_CallbackFxn callbackFxn
Definition: HSMLPF3.h:168
void HSMLPF3_getAESEncryptTag(uint8_t *mac)
Fetches the AES tag.
void HSMLPF3_constructDeleteAssetToken(uint32_t assetId)
Constructs an asset delete command token.
void HSMLPF3_constructAESCCMSegmentedDataPhysicalToken(const AESCCMLPF3_Object *object)
Populate the command token to reflect an AES-CCM segmented or final data operation.
AESGCM driver header.
void HSMLPF3_constructAESCBCOneStepPhysicalToken(AESCBCLPF3_Object *object)
HSMLPF3_ReturnBehavior returnBehavior
Definition: HSMLPF3.h:167
void HSMLPF3_constructAESECBOneStepPhysicalToken(AESECBLPF3_Object *object)
Constructs an AES-ECB one-step command token.
int_fast16_t HSMLPF3_submitToken(HSMLPF3_ReturnBehavior retBehavior, HSMLPF3_CallbackFxn callbackFxn, uintptr_t driverHandle)
Submits a token to the HSM mailbox.
HSMLPF3_ReturnBehavior
The way in which HSMLPF3_waitForResult() function calls return after performing an calling HSMLPF3_su...
Definition: HSMLPF3.h:124
int32_t HSMLPF3_getResultCode(void)
Get operation result code.
void HSMLPF3_getAESIV(uint8_t *iv)
Fetches the AES IV.
void HSMLPF3_constructRTOSObjects(void)
Initializes the HWI and semaphores for HSMLPF3.
Semaphore module for the RTOS Porting Interface.
AESCTRLPF3 Object.
Definition: AESCTRLPF3.h:138
AESCCMLPF3 Object.
Definition: AESCCMLPF3.h:101
Definition: HSMLPF3.h:133
Eip130Token_Result_t resultToken
Definition: HSMLPF3.h:166
void HSMLPF3_constructAESCCMSegmentedAADPhysicalToken(const AESCCMLPF3_Object *object)
Populate the command token to reflect an AES-CCM segmented AAD operation.
void HSMLPF3_constructLoadPlaintextAssetToken(const uint8_t *input_p, const uint32_t inputLength, uint32_t assetId)
Constructs an asset load plaintext command token.
AESCCM driver implementation for the Low Power F3 family.
void HSMLPF3_constructAESCCMOneStepPhysicalToken(const AESCCMLPF3_Object *object)
Constructs an AES-CCM one-step/segmented command token.
void(* HSMLPF3_CallbackFxn)(uintptr_t arg0)
Pointer to crypto driver post-processing functions.
Definition: HSMLPF3.h:154
AESECB driver header.
void HSMLPF3_constructECDHPKAOperationPhysicalToken(uint8_t operation, uint8_t *input, uint8_t *output, uint32_t inputLength)
Constructs a ECDH PK command token.
AESECB driver implementation for the Low Power F3 family.
void HSMLPF3_constructAESGCMSegmentedDataPhysicalToken(AESGCMLPF3HSM_Object *object)
Populate the command token to reflect an AES-GCM segmented or final data operation.
int_fast16_t HSMLPF3_sleep(void)
Puts the HSM to sleep, lowering its power consumption.
void HSMLPF3_constructAESCTROneStepPhysicalToken(AESCTRLPF3_Object *object)
Constructs an AES-CTR one-step command token.
AESGCMLPF3HSM Object.
Definition: AESGCMLPF3HSM.h:95
AESECBLPF3 Object.
Definition: AESECBLPF3.h:110
Definition: HSMLPF3.h:139
SHA2 driver header.
ECDSA HSM IP driver implementation for the Low Power F3 family.
uintptr_t driverHandle
Definition: HSMLPF3.h:169
void HSMLPF3_disableClock(void)
Disables clock for HSM, effectively powering it off.
AESCMAC (CMAC and CBC-MAC) driver header.
Definition: HSMLPF3.h:126
AESCBC driver implementation for the Low Power F3 devices.
void HSMLPF3_getAESCMACSignMac(uint8_t *mac, uint8_t macLength)
Fetches the Final mac from result token.
Eip130Token_Command_t commandToken
Definition: HSMLPF3.h:165
AESCCM driver header.
int_fast16_t HSMLPF3_cancelOperation(void)
Cancels the operation currently in progress.
uint32_t HSMLPF3_getResultAssetID(void)
Fetches the asset ID from the HSM&#39;s result token.
bool HSMLPF3_isOperationInProgress(void)
returns the value of HSMLPF3_operationInProgress
AESCMAC (CMAC & CBC-MAC) driver implementation for the Low Power F3 family.
void HSMLPF3_constructSHA2PhysicalToken(SHA2LPF3HSM_Object *object)
Constructs a SHA2 onestep/segmented command token.
AESCBCLPF3 Object.
Definition: AESCBCLPF3.h:88
AESCTR driver implementation for the Low Power F3 family.
Struct to hold metadata for a crypto driver&#39;s operation.
Definition: HSMLPF3.h:163
void HSMLPF3_constructAESGCMSegmentedAADPhysicalToken(AESGCMLPF3HSM_Object *object)
Populate the command token to reflect an AES-GCM segmented AAD operation.
AESCTR driver header.
void HSMLPF3_constructAESCMACOneStepPhysicalToken(AESCMACLPF3_Object *object)
Constructs an AES-CMAC one-step command token.
© Copyright 1995-2024, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale