TI OAD API Documentation  9.14.00
HSMBareMetal.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2024-2025, 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 HSMBareMetal.h
35  *
36  * @brief Interface to The HSM IP in a BareMetal-based implementation.
37  *
38  * This module provides cryptographic functions for use of the Hardware Security Module.
39  *
40  * Summary and List of Features:
41  * - HSM initialization sequence.
42  * * Turn on the HSM Clock.
43  * * Initialize and link the designated HSM mailbox for token exchanges
44  * * Boot up the HSM by sending a boot operation to the HSM to initialize the HSM FW.
45  * - HSM un-init sequence.
46  * - HSM HUK provisioning.
47  * - HSM Asset-related Operations:
48  * * Dynamic Asset creation and plaintext-only load to the HSM internal AssetStore.
49  * * Support for AES and MAC keys including HMAC.
50  * * In-API key generation:
51  * (The user can request to generate key, create an asset, and load key in HSM AssetStore in one API)
52  * * Loading plaintext, returning an asset ID pair, and extracting a Key blob pair for AES operations.
53  * - Please use the HSM_KEYBLOB_SIZE() macro to determine the appropriate size of key blob buffers.
54  * * Importing a key blob pair for AES operations and returning an asset ID pair
55  * - HSM Cryptography-related Operations:
56  * * AES operations, (CCM, GCM, CTR, ECB, CBC).
57  * * MAC operations, (128-bit CMAC, 128-bit CBC-MAC, HMAC).
58  * * Hash operations, (SHA2-224, SHA2-256, SHA2-384, SHA2-512).
59  * * RNG operations, Deterministic (RECOMMENDED) and non-deterministic (Raw).
60  * * ECC operations, (ECDH, ECDSA).
61  * - HSM Support for plaintext or AssetStore formats for keys for AES operations.
62  * * (CCM, GCM, CTR, ECB, CBC):
63  * 1. For plaintext, the symmetric key material can be provided as part of the AES operation.
64  * 2. For AssetStore, the symmetric key material must be loaded as an HSM asset and the asset ID generated has
65  * to be provided as part of the AES operation.
66  * * (CMAC, CBC-MAC, and HMAC):
67  * 1. MAC-based operations that require the symmetric key to be pre-loaded in the HSM AssetStore and provide
68  * the asset ID as part of the MAC operation.
69  * - HSM Support for (CCM, GCM, CTR, ECB, CBC, CMAC, CBC-MAC) operations with the following key sizes:
70  * * 128-bit (16 Bytes).
71  * * 192-bit (24 Bytes).
72  * * 256-bit (32 Bytes).
73  * - HSM Support for HMAC Algorithms:
74  * * SHA2-224 with key sizes within range 14-64 Bytes.
75  * * SHA2-256 with key sizes within range 14-64 Bytes.
76  * * SHA2-384 with key sizes within range 24-128 Bytes.
77  * * SHA2-512 with key sizes within range 32-128 Bytes.
78  * - HSM Support for HASH Algorithms:
79  * * SHA2-224 with digest length 28 Bytes.
80  * * SHA2-256 with digest length 32 Bytes.
81  * * SHA2-384 with digest length 48 Bytes.
82  * * SHA2-512 with digest length 64 Bytes.
83  * * Multi-step hash operations are supported. To perform a multi-step hash operation, the user will need to create
84  * * a series of operations with the operation Type in the following order:
85  * - INIT_TO_CONT (once)
86  * - CONT_TO_CONT (as many times as necessary)
87  * - CONT_TO_FINAL (once)
88  * * Multi-step hash operations are supported for all digest lengths and sha2 algorithms.
89  * * Performing a CONT_TO_CONT or CONT_TO_FINAL hash operation before an INIT_TO_CONT hash operation will result
90  * * unexpected outputs.
91  * - HSM Support for RNG Operations:
92  * * Size must be 0 < x < (2^16 Bytes).
93  * * For DRBG data, size must be 32-bit aligned. (Multiple of 4 bytes).
94  * * For NRBG data, size can be anywhere between 1-256 bytes and multiple of 256 bytes if larger than 256 bytes.
95  * - HSM Support for ECC Operations:
96  * * ECDH public key generation.
97  * * ECDH shared secret generation.
98  * * ECDSA DS digest signature generation.
99  * * ECDSA DS digest signature verification.
100  * - HSM Support for ECC Curve types:
101  * * SEC_P_224_R1.
102  * * SEC_P_256_R1.
103  * * SEC_P_384_R1.
104  * * SEC_P_521_R1.
105  * * BRP_P_256_R1.
106  * * BRP_P_384_R1.
107  * * BRP_P_512_R1.
108  * * CURVE25519.
109  * - HSM limitations:
110  * * All buffer address must be word-aligned.
111  * * Input plaintext length for (CCM, GCM, CBC, CTR, ECB, CMAC, CBC-MAC, SHA2, HMAC) shall be upto 2^21 -1 Bytes
112  * and block-size aligned.
113  * * For non-final hash operations, the input data should be block-size aligned (128 bytes for SHA-2-384 and
114  * SHA-2-512 or 64 bytes for the other algorithms).
115  * * For segmented hashing, the user must maintain the intermediate digest buffer to be passed between operations.
116  * * Input for every ECC operation must be in big endian format.
117  * * Input and output buffers shall be a multiple of block length.
118  * Meaning that while the input data can be of any length, the buffers for the input and output data
119  * should be rounded up to the nearest size that is a multiple of block size.
120  * - For example, input data size of 24 Bytes must be in a buffer that is of size 32 bytes.
121  * * Additional Authenticated Data (AAD) for (CCM, GCM) length up to 2^16 - 2^8 Bytes.
122  * * The combined length of the input data and the AAD for (CCM, GCM) shall not be zero.
123  * * Nonce for (CCM) length for (7-13) Bytes.
124  * * Initialization Vector (IV) for (CCM, CBC, CTR) length IS EXACTLY 16 Bytes.
125  * * Tag length for AES-CCM shall be a multiple of 2 Bytes, [4, 6, 8, 10, 12, 14, 16].
126  * * Tag for AES-GCM length should be the following [4, 8, 12, 13, 14, 15, 16] Bytes.
127  * * MAC length (128-bit CMAC, 128-bit CBC-MAC) should be the following [2, 4, 6, 8, 10, 12, 14, 16] Bytes.
128  * * For ECC operations:
129  * - ECDSA sign and verify operations do not support curve type: CURVE25519.
130  * - All input keys must be supplied in plaintext.
131  * - ECC operations takes in a digest (not the input buffer).
132  * Therefore, the input buffer must be hashed using #HSMBareMetal_HASHOperation() API and supplying the
133  * digest in the ECC operation.
134  * - Digest length must match curve length. Ex. for SEC_P_384_R1 and BRP_P_384_R1 curve types, the digest must
135  * be generated using SHA2-384. For BRP_P_512_R1 and SEC_P_521_R1 curve types, the digest must be generated using
136  * SHA2-512.
137  *
138  * NOTE: The above features do not support segmented operations. All operations are performed as a 'one-shot'
139  * operation. NOTE: the above features and their APIs are synchonous and conduct their operations in a polling return
140  * behavior-like fashion.
141  *
142  * # Usage #
143  *
144  * ## Before starting a BareMetal operation #
145  *
146  * Before starting a BareMetal operation
147  * - Call HSMBareMetal_init() to initialize the HSM IP and the SW architecture.
148  *
149  * - Call HSMBareMetal_provisionHUK() to use any asset-related operations and specifically key blob-related
150  * operations.
151  *
152  * ## Starting a BareMetal operation #
153  *
154  * The HSMBareMetal implementation provides a simplified approach to leverage the Hardware Security Module (HSM)
155  * functional capability while also bypassing the complex SW architecture of the HSM and the RTOS while offering a
156  * centralized suit of APIs to conduct all major cryptographic operations.
157  *
158  * This implementation delivers multiple features in a switch-like approach. For example, it allows multiple
159  * modes of an Advanced Encryption Standard (AES) operations in one API by simply choosing from an Enum for
160  * all AEAD operations such as (CCM, GCM, CBC, CTR, ECB, CMAC, CBC-MAC), (ENC, DEC).
161  *
162  * @anchor ti_sccm_HSMBareMetal_Synopsis
163  * ## Examples
164  * @code
165  *
166  * // Import the HSMBareMetal defintions
167  * #include <ti/drivers/cryptoutils/hsm/HSMBareMetal.h>
168  *
169  * int_fast16_t status;
170  * HSMBareMetal_AssetOperationStruct assetOperationStruct;
171  * HSMBareMetal_AESOperationStruct AESOperationStruct;
172  * HSMBareMetal_AESOperationMode aesOperationMode = HSMBareMetal_AES_MODE_CCM;
173  * HSMBareMetal_KeyInput keyInput = HSMBareMetal_KEY_INPUT_ASSETSTORE;
174  *
175  * uint32_t encKeyAssetId = 0U;
176  * uint32_t decKeyAssetId = 0U;
177  * HSMBareMetal_AssetPairStruct assetPair;
178  * assetPair.encGenKeyAssetID = &encKeyAssetId;
179  * assetPair.decVrfyKeyAssetID = &decKeyAssetId;
180  * uint8_t nonce[] = "Thisisanonce";
181  * uint8_t aad[] = "This string will be authenticated but not encrypted.";
182  * uint8_t plaintext[] = "This string will be encrypted and authenticated.";
183  * uint8_t mac[16];
184  * uint8_t ciphertext[sizeof(plaintext)];
185  * uint8_t keyingMaterial[32] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
186  * 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
187  * 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
188  * 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F};
189  *
190  * status = HSMBareMetal_init();
191  *
192  * if (status != HSMBAREMETAL_STATUS_SUCCESS)
193  * {
194  * // handle error
195  * }
196  *
197  * if (keyInput == HSMBareMetal_KEY_INPUT_ASSETSTORE)
198  * {
199  * HSMBareMetal_AssetOperation_init(&assetOperationStruct);
200  *
201  * assetOperationStruct.keyAssetIDs = assetPair;
202  * assetOperationStruct.isKeyGenerated = true;
203  * assetOperationStruct.key = &keyingMaterial[0];
204  * assetOperationStruct.keyLength = sizeof(keyingMaterial);
205  * assetOperationStruct.algorithm = HSMBareMetal_OPERATION_ALGO_AES;
206  * assetOperationStruct.aesOperationMode = aesOperationMode;
207  *
208  * status = HSMBareMetal_AssetOperation(&assetOperationStruct);
209  *
210  * if (status != HSMBAREMETAL_STATUS_SUCCESS)
211  * {
212  * // handle error
213  * }
214  * }
215  *
216  * HSMBareMetal_AESOperation_init(&AESOperationStruct);
217  *
218  * if (keyInput == HSMBareMetal_KEY_INPUT_ASSETSTORE)
219  * {
220  * AESOperationStruct.keyAssetID = encKeyAssetId;
221  * }
222  * else
223  * {
224  * AESOperationStruct.key = (uint8_t *)keyingMaterial;
225  * }
226  *
227  * AESOperationStruct.keyLength = sizeof(keyingMaterial);
228  * AESOperationStruct.isKeyInAssetStore = keyInput;
229  * AESOperationStruct.input = plaintext;
230  * AESOperationStruct.inputLength = sizeof(plaintext);
231  * AESOperationStruct.aad = aad;
232  * AESOperationStruct.aadLength = sizeof(aad);
233  * AESOperationStruct.mac = mac;
234  * AESOperationStruct.macLength = sizeof(mac);
235  * AESOperationStruct.nonce = nonce;
236  * AESOperationStruct.nonceLength = sizeof(nonce);
237  * AESOperationStruct.output = ciphertext;
238  * AESOperationStruct.operationMode = aesOperationMode;
239  * AESOperationStruct.operationDirection = HSMBareMetal_OPERATION_DIR_ENC_GEN;
240  *
241  * status = HSMBareMetal_AESOperation(&AESOperationStruct);
242  *
243  * if (status != HSMBAREMETAL_STATUS_SUCCESS)
244  * {
245  * // handle error
246  * }
247  *
248  * if (keyInput == HSMBareMetal_KEY_INPUT_ASSETSTORE)
249  * {
250  * status = HSMBareMetal_freeAssetPair(assetPair);
251  * }
252  *
253  * HSMBareMetal_deInit();
254  *
255  * @endcode
256  *
257  */
258 
259 #ifndef HSMBAREMETAL_H
260 #define HSMBAREMETAL_H
261 
262 #ifdef __cplusplus
263 extern "C" {
264 #endif
265 
266 #include <stdint.h>
267 #include <stdbool.h>
268 #include <string.h>
269 
276 #define HSMBAREMETAL_STATUS_SUCCESS ((int_fast16_t)0)
277 
284 #define HSMBAREMETAL_STATUS_ERROR ((int_fast16_t)-1)
285 
290 #define HSMBAREMETAL_STATUS_HSM_NOT_INITIALIZED ((int_fast16_t)-2)
291 
297 #define HSMBAREMETAL_STATUS_HW_ERROR ((int_fast16_t)-3)
298 
302 #define HSMBAREMETAL_STATUS_HSM_ALREADY_INITIALIZED ((int_fast16_t)-4)
303 
312 #define HSMBAREMETAL_STATUS_INVALID_MAC ((int_fast16_t)-5)
313 
317 #define HSMBAREMETAL_STATUS_INVALID_INPUT_PARAMETERS ((int_fast16_t)-6)
318 
322 #define HSMBAREMETAL_STATUS_NRBG_ALREADY_IN_MODE ((int_fast16_t)-7)
323 
327 #define HSMBAREMETAL_STATUS_INVALID_PRIVATE_KEY_SIZE ((int_fast16_t)-8)
328 
332 #define HSMBAREMETAL_STATUS_INVALID_PUBLIC_KEY_SIZE ((int_fast16_t)-9)
333 
337 #define HSMBAREMETAL_STATUS_INVALID_PUBLIC_KEY_OCTET_VALUE ((int_fast16_t)-10)
338 
342 #define HSMBAREMETAL_STATUS_INVALID_SHARED_SECRET_KEY_SIZE ((int_fast16_t)-11)
343 
347 #define HSMBAREMETAL_STATUS_HUK_ALREADY_PROVISIONED ((int_fast16_t)-12)
348 
352 #define HSMBAREMETAL_STATUS_FEATURE_NOT_SUPPORTED ((int_fast16_t)-13)
353 
357 #define HSMBAREMETAL_STATUS_INVALID_INPUT_DATA_LENGTH ((int_fast16_t)-14)
358 
362 #define HSMBAREMETAL_STATUS_INVALID_MAC_LENGTH ((int_fast16_t)-15)
363 
367 #define HSMBareMetal_WAIT_FOREVER ~(0)
368 
372 #define HSMBAREMETAL_HUK_ASSET_NUMBER 0x61
373 
377 #define HSMBAREMETAL_AES_BLOCK_SIZE 16
378 
384 #define HSM_KEYBLOB_SIZE(keyLength) (HSMBAREMETAL_AES_BLOCK_SIZE + keyLength)
385 
391 typedef enum
392 {
393  ENTROPY_TYPE_DRBG = 0x0000,
394  ENTROPY_TYPE_CRNG = 0x7264,
395  ENTROPY_TYPE_TRNG = 0x5244,
397 
403 typedef enum
404 {
405  NRBG_TYPE_CRNG = 1,
406  NRBG_TYPE_TRNG = 0,
408 
414 typedef enum
415 {
416  HSMBareMetal_OPERATION_ALGO_AES = 1,
417  HSMBareMetal_OPERATION_ALGO_MAC = 2,
418  HSMBareMetal_OPERATION_ALGO_HASH = 3,
419  HSMBareMetal_OPERATION_ALGO_ECC = 4,
421 
427 typedef enum
428 {
429  HSMBareMetal_OPERATION_DIR_ENC_GEN = 1,
430  HSMBareMetal_OPERATION_DIR_DEC_VRFY = 2,
432 
436 typedef enum
437 {
438  HSMBareMetal_AES_MODE_ECB = 0,
439  HSMBareMetal_AES_MODE_CBC = 1,
440  HSMBareMetal_AES_MODE_CTR = 2,
441  HSMBareMetal_AES_MODE_CCM = 5,
442  HSMBareMetal_AES_MODE_GCM = 7,
444 
448 typedef enum
449 {
450  HSMBareMetal_MAC_MODE_HMAC_224 = 2,
451  HSMBareMetal_MAC_MODE_HMAC_256 = 3,
452  HSMBareMetal_MAC_MODE_HMAC_384 = 4,
453  HSMBareMetal_MAC_MODE_HMAC_512 = 5,
454  HSMBareMetal_MAC_MODE_CMAC = 8,
455  HSMBareMetal_MAC_MODE_CBC_MAC = 9,
457 
461 typedef enum
462 {
463  HSMBareMetal_HASH_MODE_SHA2_224 = 2,
464  HSMBareMetal_HASH_MODE_SHA2_256 = 3,
465  HSMBareMetal_HASH_MODE_SHA2_384 = 4,
466  HSMBareMetal_HASH_MODE_SHA2_512 = 5,
468 
472 typedef enum
473 {
474  HSMBareMetal_HASH_TYPE_INIT_TO_FINAL = 0,
475  HSMBareMetal_HASH_TYPE_CONT_TO_FINAL = 1,
476  HSMBareMetal_HASH_TYPE_INIT_TO_CONT = 2,
477  HSMBareMetal_HASH_TYPE_CONT_TO_CONT = 3,
479 
483 typedef enum
484 {
485  HSMBareMetal_PK_CURVE_TYPE_SEC_P_224_R1 = 1,
486  HSMBareMetal_PK_CURVE_TYPE_SEC_P_256_R1 = 2,
487  HSMBareMetal_PK_CURVE_TYPE_SEC_P_384_R1 = 3,
488  HSMBareMetal_PK_CURVE_TYPE_SEC_P_521_R1 = 4,
489  HSMBareMetal_PK_CURVE_TYPE_BRP_P_256_R1 = 5,
490  HSMBareMetal_PK_CURVE_TYPE_BRP_P_384_R1 = 6,
491  HSMBareMetal_PK_CURVE_TYPE_BRP_P_512_R1 = 7,
492  HSMBareMetal_PK_CURVE_TYPE_25519 = 8, /* Only applicable for ECDH generate public key and compute shared secret
493  operations. */
495 
499 typedef enum
500 {
501  HSMBareMetal_PK_CURVE_LENGTH_224 = 224,
502  HSMBareMetal_PK_CURVE_LENGTH_255 = 255,
503  HSMBareMetal_PK_CURVE_LENGTH_256 = 256,
504  HSMBareMetal_PK_CURVE_LENGTH_384 = 384,
505  HSMBareMetal_PK_CURVE_LENGTH_512 = 512,
506  HSMBareMetal_PK_CURVE_LENGTH_521 = 521,
508 
512 typedef enum
513 {
514  HSMBareMetal_PK_DIGEST_LENGTH_224 = 224,
515  HSMBareMetal_PK_DIGEST_LENGTH_256 = 256,
516  HSMBareMetal_PK_DIGEST_LENGTH_384 = 384,
517  HSMBareMetal_PK_DIGEST_LENGTH_512 = 512,
519 
523 typedef enum
524 {
525  HSMBareMetal_PK_MODE_ECDH_GEN_PUB_KEY = 1,
526  HSMBareMetal_PK_MODE_ECDH_GEN_SHRD_SCRT = 2,
527  HSMBareMetal_PK_MODE_ECDSA_SIGN = 3,
528  HSMBareMetal_PK_MODE_ECDSA_VERIFY = 4,
530 
534 typedef enum
535 {
536  HSMBareMetal_KEY_INPUT_PLAINTEXT = 0,
537  HSMBareMetal_KEY_INPUT_ASSETSTORE = 1,
539 
543 typedef enum
544 {
545  HSMBareMetal_ASSET_OPERATION_TYPE_LOAD_PLAINTEXT = 0,
546  HSMBareMetal_ASSET_OPERATION_TYPE_LOAD_IMPORT_KEY_BLOB = 1,
547  HSMBareMetal_ASSET_OPERATION_TYPE_LOAD_EXPORT_KEY_BLOB = 2,
549 
550 /* Operation Structures */
551 
555 typedef struct
556 {
557  uint8_t patch;
558  uint8_t minor;
559  uint8_t major;
561 
565 typedef struct
566 {
567  uint8_t *key;
568  uint8_t keyLength;
569  uint8_t *aad;
573  uint8_t *input;
578  uint8_t *output;
584  uint8_t *nonce;
587  uint8_t *iv;
590  uint8_t *mac;
596  size_t aadLength;
599  size_t inputLength;
603  uint8_t nonceLength;
606  uint8_t ivLength;
609  uint8_t macLength;
614  uint32_t keyAssetID; /* Asset ID for a previously-allocated asset. */
615  HSMBareMetal_KeyInput isKeyInAssetStore;
616  HSMBareMetal_operationDirection operationDirection;
617  HSMBareMetal_AESOperationMode operationMode;
619 
623 typedef struct
624 {
625  uint32_t keyAssetID;
626  uint8_t keyLength;
627  uint8_t *input;
632  uint8_t *mac;
638  size_t inputLength;
643  size_t macLength;
648  HSMBareMetal_MACOperationMode operationMode;
649  HSMBareMetal_operationDirection operationDirection;
651 
657 typedef struct
658 {
659  uint32_t *encGenKeyAssetID; /* Asset ID for encryption/generation */
660  uint32_t *decVrfyKeyAssetID; /* Asset ID for decryption/Verification */
662 
668 typedef struct
669 {
670  uint8_t *encGenKeyBlob; /* Key blob data for encryption/generation operations. */
671  uint8_t *decVrfyKeyBlob; /* Key blob data for decryption/Verification operations. */
673 
677 typedef struct
678 {
679  uint32_t *privateKeyAssetID; /* Asset ID for the private key. */
680  uint32_t *publicKeyAssetID; /* Asset ID for the public key. */
682 
686 typedef struct
687 {
688  uint8_t *key; /* Plaintext key buffer. */
689  uint8_t keyLength; /* Key length. */
690  bool isKeyGenerated; /* When set, HSMBareMetal will leverage the #HSMBareMetal_RNGOperation to generate a DRBG key
691  internally and return the AssetIDPair only. */
692  HSMBareMetal_AssetPairKeyBlobStruct keyBlobs; /* Contains a pair of pointers to the encrypt and decrypt key blob
693  data. This field is used as an input and an ouput depending on the
694  operationType. */
695  HSMBareMetal_AssetPairStruct keyAssetIDs; /* In a symmetric operation, for every key there exists two key Asset IDs.
696  One for ENC/GEN and the other for DEC/VRFY. */
697  HSMBareMetal_operationAlgorithm algorithm; /* AES or MAC. */
698  HSMBareMetal_AssetOperationType operationType; /* Load plaintext, load plaintext and export key blobs, or import key
699  blobs. */
700  HSMBareMetal_AESOperationMode aesOperationMode;
701  HSMBareMetal_MACOperationMode macOperationMode;
703 
707 typedef struct
708 {
709  uint8_t *input;
710  size_t inputLength;
711  uint8_t *digest;
712  HSMBareMetal_HASHOperationMode operationMode;
713  HSMBareMetal_HASHOperationType operationType;
714  size_t totalInputLength;
716 
720 typedef struct
721 {
722  uint8_t *random;
723  size_t randomLength;
724  HSMBareMetal_entropyType entropyType;
726 
730 typedef struct
731 {
732  uint8_t *keyMaterial;
733  uint32_t keyLength;
735 
739 typedef struct
740 {
741  uint32_t assetId;
742  uint32_t keyLength;
744 
748 typedef struct
749 {
750  HSMBareMetal_KeyInput keyInputType;
751  union
752  {
755  } u;
757 
761 typedef struct
762 {
763  HSMBareMetal_CryptoKeyStruct *privateKey;
764  HSMBareMetal_CryptoKeyStruct *publicKey;
765  HSMBareMetal_CryptoKeyStruct *sharedSecret; /* Only applicable for ECDH generate public key or compute shared secret
766  operations */
767  uint8_t *hashDigest; /* Only applicable for ECDSA sign and verify operations */
768  uint8_t *signatureR; /* Only applicable for ECDSA sign and verify operations */
769  uint8_t *signatureS; /* Only applicable for ECDSA sign and verify operations */
770  HSMBareMetal_ECCOperationMode operationMode;
771  HSMBareMetal_ECCOperationCurveType operationCurveType;
773 
786 int_fast16_t HSMBareMetal_init(void);
787 
793 int_fast16_t HSMBareMetal_deInit(void);
794 
802 int_fast16_t HSMBareMetal_checkHSMStatus(void);
803 
817 int_fast16_t HSMBareMetal_provisionHUK(void);
818 
833 int_fast16_t HSMBareMetal_searchStaticAsset(uint32_t assetNumber, uint32_t *assetId);
834 
847 
859 void HSMBareMetal_CryptoKeyPlaintext_initKey(HSMBareMetal_CryptoKeyStruct *cryptoKey, uint8_t *key, size_t keyLength);
860 
865 
870 
875 
880 
885 
890 
916 int_fast16_t HSMBareMetal_RNGOperation(HSMBareMetal_RNGOperationStruct *operationStruct);
917 
933 
957 
974 
988 int_fast16_t HSMBareMetal_freeKeyAsset(uint32_t *keyAssetID);
989 
1004 int_fast16_t HSMBareMetal_AESOperation(HSMBareMetal_AESOperationStruct *operationStruct);
1005 
1020 int_fast16_t HSMBareMetal_MACOperation(HSMBareMetal_MACOperationStruct *operationStruct);
1021 
1036 int_fast16_t HSMBareMetal_HASHOperation(HSMBareMetal_HASHOperationStruct *operationStruct);
1037 
1063 int_fast16_t HSMBareMetal_ECCOperation(HSMBareMetal_ECCOperationStruct *operationStruct);
1064 
1065 #ifdef __cplusplus
1066 }
1067 #endif
1068 
1069 #endif /* HSMBAREMETAL_H */
Struct to store HSM system versions.
Definition: HSMBareMetal.h:555
size_t inputLength
Definition: HSMBareMetal.h:599
HSMBareMetal_HASHOperationMode
Enum for Hash operation modes (algorithms).
Definition: HSMBareMetal.h:461
HSMBareMetal_MACOperationMode
Enum for the MAC operation mode.
Definition: HSMBareMetal.h:448
Struct containing the parameters required for MAC operations.
Definition: HSMBareMetal.h:623
HSMBareMetal_ECCOperationMode
Enum for ECC operation modes.
Definition: HSMBareMetal.h:523
uint8_t * input
Definition: HSMBareMetal.h:627
void HSMBareMetal_AESOperation_init(HSMBareMetal_AESOperationStruct *operationStruct)
Function to initialize an HSMBareMetal_AESOperation struct to its default (all zeroes) ...
uint8_t * output
Definition: HSMBareMetal.h:578
Struct containing the parameters required for AES operations.
Definition: HSMBareMetal.h:748
Struct containing the parameters required for Hash operations.
Definition: HSMBareMetal.h:707
HSMBareMetal_NRBGMode
Enum for the current NRBG IP for the HSM to pull entropy from.
Definition: HSMBareMetal.h:403
HSMBareMetal_operationAlgorithm
Enum for operation algorithm.
Definition: HSMBareMetal.h:414
void HSMBareMetal_MACOperation_init(HSMBareMetal_MACOperationStruct *operationStruct)
Function to initialize an HSMBareMetal_MACOperation struct to its default (all zeroes) ...
Struct containing the parameters required for asset create and plaintext key load operations...
Definition: HSMBareMetal.h:686
uint8_t * aad
Definition: HSMBareMetal.h:569
HSMBareMetal_operationDirection
Enum for the direction of an AES operation.
Definition: HSMBareMetal.h:427
int_fast16_t HSMBareMetal_deInit(void)
Close the HSMBareMetal Module.
int_fast16_t HSMBareMetal_RNGOperation(HSMBareMetal_RNGOperationStruct *operationStruct)
Perform a Bare Metal Random Number Generation Operation.
HSMBareMetal_AESOperationMode
Enum for AES operation modes.
Definition: HSMBareMetal.h:436
uint8_t macLength
Definition: HSMBareMetal.h:609
int_fast16_t HSMBareMetal_checkHSMStatus(void)
Check HSM HW status.
size_t macLength
Definition: HSMBareMetal.h:643
uint8_t * nonce
Definition: HSMBareMetal.h:584
HSMBareMetal_AssetOperationType
Enum for the Asset operation type.
Definition: HSMBareMetal.h:543
void HSMBareMetal_RNGOperation_init(HSMBareMetal_RNGOperationStruct *operationStruct)
Function to initialize an HSMBareMetal_RNGOperation struct to its default (all zeroes) ...
HSMBareMetal_entropyType
Enum for entropy type.
Definition: HSMBareMetal.h:391
Struct containing the two buffers for symmetric key blob data.
Definition: HSMBareMetal.h:668
int_fast16_t HSMBareMetal_init(void)
Initialize HSMBareMetal Module.
uint32_t keyAssetID
Definition: HSMBareMetal.h:625
uint8_t ivLength
Definition: HSMBareMetal.h:606
Struct containing the two asset IDs returned for usage in a symmetric operation.
Definition: HSMBareMetal.h:657
uint8_t * iv
Definition: HSMBareMetal.h:587
int_fast16_t HSMBareMetal_MACOperation(HSMBareMetal_MACOperationStruct *operationStruct)
Perform a Bare Metal MAC Operation.
HSMBareMetal_HASHOperationType
Enum for Hash operation types (hash mode).
Definition: HSMBareMetal.h:472
HSMBareMetal_ECCOperationCurveType
Enum for ECC operation curve types.
Definition: HSMBareMetal.h:483
Struct containing the parameters required for AES operations.
Definition: HSMBareMetal.h:565
uint8_t * mac
Definition: HSMBareMetal.h:632
void HSMBareMetal_CryptoKeyPlaintext_initKey(HSMBareMetal_CryptoKeyStruct *cryptoKey, uint8_t *key, size_t keyLength)
Initializes a CryptoKey with plaintext encoding.
void HSMBareMetal_HASHOperation_init(HSMBareMetal_HASHOperationStruct *operationStruct)
Function to initialize an HSMBareMetal_HASHOperation struct to its default (all zeroes) ...
size_t aadLength
Definition: HSMBareMetal.h:596
Struct containing the AssetStore-based crypto key data.
Definition: HSMBareMetal.h:739
int_fast16_t HSMBareMetal_RNGSwitchNRBGMode(HSMBareMetal_NRBGMode NRBGMode)
Switch the current NRBG engine: CRNG -> TRNG or vice-versa.
uint8_t * input
Definition: HSMBareMetal.h:573
int_fast16_t HSMBareMetal_AssetOperation(HSMBareMetal_AssetOperationStruct *operationStruct)
Perform a Bare Metal Asset Create and Load Operations.
int_fast16_t HSMBareMetal_provisionHUK(void)
Provision the Hardware Unique Key (HUK) for this device.
int_fast16_t HSMBareMetal_searchStaticAsset(uint32_t assetNumber, uint32_t *assetId)
Perform an HSM OTP search for static asset.
int_fast16_t HSMBareMetal_AESOperation(HSMBareMetal_AESOperationStruct *operationStruct)
Perform a Bare Metal AES Operation.
HSMBareMetal_ECCOperationDigestLength
Enum for ECC operation digest lengths.
Definition: HSMBareMetal.h:512
int_fast16_t HSMBareMetal_getHSMFirmwareVersion(HSMBareMetal_systemInfoVersionStruct *firmwareVersionStruct)
Returns the HSM FW image version number (major, minor, and patch)
int_fast16_t HSMBareMetal_ECCOperation(HSMBareMetal_ECCOperationStruct *operationStruct)
Perform a Bare Metal Public Key Operation.
void HSMBareMetal_ECCOperation_init(HSMBareMetal_ECCOperationStruct *operationStruct)
Function to initialize an HSMBareMetal_ECCOperation struct to its default (all zeroes) ...
void HSMBareMetal_AssetOperation_init(HSMBareMetal_AssetOperationStruct *operationStruct)
Function to initialize an HSMBareMetal_AssetOperation struct to its default (all zeroes) ...
Struct containing the parameters required for ECC operations.
Definition: HSMBareMetal.h:761
int_fast16_t HSMBareMetal_freeKeyAsset(uint32_t *keyAssetID)
Perform a Bare Metal Asset Delete Operation.
Struct containing the two asset IDs returned for ECC operations.
Definition: HSMBareMetal.h:677
int_fast16_t HSMBareMetal_HASHOperation(HSMBareMetal_HASHOperationStruct *operationStruct)
Perform a Bare Metal Hash Operation.
HSMBareMetal_ECCOperationCurveLength
Enum for ECC operation curve lengths.
Definition: HSMBareMetal.h:499
Struct containing the parameters required for RNG operations.
Definition: HSMBareMetal.h:720
size_t inputLength
Definition: HSMBareMetal.h:638
uint8_t nonceLength
Definition: HSMBareMetal.h:603
uint8_t * mac
Definition: HSMBareMetal.h:590
HSMBareMetal_KeyInput
Enum for the AES operation mode.
Definition: HSMBareMetal.h:534
Struct containing the Plaintext-based crypto key data.
Definition: HSMBareMetal.h:730
int_fast16_t HSMBareMetal_freeAssetPair(HSMBareMetal_AssetPairStruct keyAssetPair)
Perform a Bare Metal Asset Delete Operations.