MSPM0GX51X Driver Library  2.05.01.00
dl_keystorectl.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023, 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  * @file dl_keystorectl.h
34  * @brief KEYSTORECTL (Keystore Controller) Driver Library
35  * @defgroup KEYSTORECTL Keystore Controller (KEYSTORECTL)
36  *
37  * @anchor ti_dl_dl_keystorectl_Overview
38  * # Overview
39  *
40  * The Keystore Controller (KEYSTORECTL) DriverLib allows full configuration
41  * of the MSPM0 KEYSTORECTL Module.
42  *
43  * <hr>
44  ******************************************************************************/
48 #ifndef ti_dl_dl_keystorectl__include
49 #define ti_dl_dl_keystorectl__include
50 
51 #include <stdbool.h>
52 #include <stdint.h>
53 
54 #include <ti/devices/msp/msp.h>
55 #include <ti/driverlib/dl_common.h>
56 
57 #ifdef __MSPM0_HAS_KEYSTORE_CTL__
58 
59 #ifdef __cplusplus
60 extern "C" {
61 #endif
62 
63 /* clang-format off */
64 
70 #define DL_KEYSTORECTL_KEY_SLOT_0 (KEYSTORECTL_KEYWR_KEYSLOTSEL_SLOT0)
71 
73 #define DL_KEYSTORECTL_KEY_SLOT_1 (KEYSTORECTL_KEYWR_KEYSLOTSEL_SLOT1)
74 
76 #define DL_KEYSTORECTL_KEY_SLOT_2 (KEYSTORECTL_KEYWR_KEYSLOTSEL_SLOT2)
77 
79 #define DL_KEYSTORECTL_KEY_SLOT_3 (KEYSTORECTL_KEYWR_KEYSLOTSEL_SLOT3)
80 
82 #define DL_KEYSTORECTL_KEY_SLOT_4 (KEYSTORECTL_KEYWR_KEYSLOTSEL_SLOT4)
83 
85 #define DL_KEYSTORECTL_KEY_SLOT_5 (KEYSTORECTL_KEYWR_KEYSLOTSEL_SLOT5)
86 
88 #define DL_KEYSTORECTL_KEY_SLOT_6 (KEYSTORECTL_KEYWR_KEYSLOTSEL_SLOT6)
89 
91 #define DL_KEYSTORECTL_KEY_SLOT_7 (KEYSTORECTL_KEYWR_KEYSLOTSEL_SLOT7)
92 
93 
95 #define DL_KEYSTORECTL_KEY_SLOT_0_AND_1 ((KEYSTORECTL_KEYWR_KEYSLOTSEL_SLOT0) | \
96  (KEYSTORECTL_KEYWR_KEYSLOTSEL_SLOT1))
97 
99 #define DL_KEYSTORECTL_KEY_SLOT_2_AND_3 ((KEYSTORECTL_KEYWR_KEYSLOTSEL_SLOT2) | \
100  (KEYSTORECTL_KEYWR_KEYSLOTSEL_SLOT3))
101 
103 #define DL_KEYSTORECTL_KEY_SLOT_4_AND_5 ((KEYSTORECTL_KEYWR_KEYSLOTSEL_SLOT4) | \
104  (KEYSTORECTL_KEYWR_KEYSLOTSEL_SLOT5))
105 
107 #define DL_KEYSTORECTL_KEY_SLOT_6_AND_7 ((KEYSTORECTL_KEYWR_KEYSLOTSEL_SLOT6) | \
108  (KEYSTORECTL_KEYWR_KEYSLOTSEL_SLOT7))
109 
112 /* clang-format on */
113 
115 typedef enum {
117  DL_KEYSTORECTL_NUM_256_KEYS_ZERO = KEYSTORECTL_CFG_NK256_ZERO,
119  DL_KEYSTORECTL_NUM_256_KEYS_ONE = KEYSTORECTL_CFG_NK256_ONE,
121  DL_KEYSTORECTL_NUM_256_KEYS_TWO = KEYSTORECTL_CFG_NK256_TWO,
123  DL_KEYSTORECTL_NUM_256_KEYS_THREE = KEYSTORECTL_CFG_NK256_THREE,
125  DL_KEYSTORECTL_NUM_256_KEYS_FOUR = KEYSTORECTL_CFG_NK256_FOUR,
127 
129 typedef enum {
131  DL_KEYSTORECTL_KEY_SIZE_128_BITS = KEYSTORECTL_KEYWR_KEYSZSEL_K128,
133  DL_KEYSTORECTL_KEY_SIZE_256_BITS = KEYSTORECTL_KEYWR_KEYSZSEL_K256,
135 
137 typedef enum {
139  DL_KEYSTORECTL_NUM_SLOTS_TWO = KEYSTORECTL_STATUS_NKEYSLOTS_TWO,
141  DL_KEYSTORECTL_NUM_SLOTS_THREE = KEYSTORECTL_STATUS_NKEYSLOTS_THREE,
143  DL_KEYSTORECTL_NUM_SLOTS_FOUR = KEYSTORECTL_STATUS_NKEYSLOTS_FOUR,
145 
147 typedef enum {
149  DL_KEYSTORECTL_CRYPTO_SEL_AES = KEYSTORECTL_KEYRD_CRYPTOSEL_AES,
151 
153 typedef enum {
155  DL_KEYSTORECTL_STATUS_VALID = KEYSTORECTL_STATUS_STAT_VALID,
158  DL_KEYSTORECTL_STATUS_NO_CONFIG = KEYSTORECTL_STATUS_STAT_NO_CFG,
161  KEYSTORECTL_STATUS_STAT_INVALID_NK256,
163  DL_KEYSTORECTL_STATUS_BUSY_RX = KEYSTORECTL_STATUS_STAT_BUSY_RECEIVE,
165  DL_KEYSTORECTL_STATUS_BUSY_TX = KEYSTORECTL_STATUS_STAT_BUSY_TRANSMIT,
171  KEYSTORECTL_STATUS_STAT_INVALID_KEYSLOTSELW,
177  KEYSTORECTL_STATUS_STAT_INVALID_KEYSLOTSELR,
182 
186 typedef struct {
189  uint32_t keySlot;
192  DL_KEYSTORECTL_KEY_SIZE keySize;
194  uint32_t *key;
196 
200 typedef struct {
203  uint32_t keySlot;
206  DL_KEYSTORECTL_KEY_SIZE keySize;
208  DL_KEYSTORECTL_CRYPTO_SEL cryptoSel;
210 
229  KEYSTORECTL_Regs *keystorectl, DL_KEYSTORECTL_NUM_256_KEYS numKeys)
230 {
232  &keystorectl->CFG, (uint32_t) numKeys, KEYSTORECTL_CFG_NK256_MASK);
233 }
234 
244 __STATIC_INLINE DL_KEYSTORECTL_NUM_256_KEYS DL_KEYSTORECTL_getNumberOf256Keys(
245  const KEYSTORECTL_Regs *keystorectl)
246 {
247  uint32_t numKeys = (keystorectl->CFG & KEYSTORECTL_CFG_NK256_MASK);
248 
249  return (DL_KEYSTORECTL_NUM_256_KEYS)(numKeys);
250 }
251 
273  KEYSTORECTL_Regs *keystorectl, uint32_t keySlot)
274 {
276  &keystorectl->KEYWR, keySlot, KEYSTORECTL_KEYWR_KEYSLOTSEL_MASK);
277 }
278 
294 __STATIC_INLINE uint32_t DL_KEYSTORECTL_getDestinationKeySlot(
295  const KEYSTORECTL_Regs *keystorectl)
296 {
297  return (keystorectl->KEYWR & KEYSTORECTL_KEYWR_KEYSLOTSEL_MASK);
298 }
299 
319  KEYSTORECTL_Regs *keystorectl, DL_KEYSTORECTL_KEY_SIZE keySize)
320 {
321  DL_Common_updateReg(&keystorectl->KEYWR, (uint32_t) keySize,
322  KEYSTORECTL_KEYWR_KEYSZSEL_MASK);
323 }
324 
337 __STATIC_INLINE DL_KEYSTORECTL_KEY_SIZE DL_KEYSTORECTL_getDestinationKeySize(
338  const KEYSTORECTL_Regs *keystorectl)
339 {
340  uint32_t keySize = (keystorectl->KEYWR & KEYSTORECTL_KEYWR_KEYSZSEL_MASK);
341 
342  return (DL_KEYSTORECTL_KEY_SIZE)(keySize);
343 }
344 
362 void DL_KEYSTORECTL_loadKey(KEYSTORECTL_Regs *keystorectl, uint32_t *key);
363 
381 __STATIC_INLINE void DL_KEYSTORECTL_setSourceKeySlot(
382  KEYSTORECTL_Regs *keystorectl, uint32_t keySlot)
383 {
385  &keystorectl->KEYRD, keySlot, KEYSTORECTL_KEYRD_KEYSLOTSEL_MASK);
386 }
387 
400 __STATIC_INLINE uint32_t DL_KEYSTORECTL_getSourceKeySlot(
401  const KEYSTORECTL_Regs *keystorectl)
402 {
403  return (keystorectl->KEYRD & KEYSTORECTL_KEYRD_KEYSLOTSEL_MASK);
404 }
405 
421 __STATIC_INLINE void DL_KEYSTORECTL_setSourceKeySize(
422  KEYSTORECTL_Regs *keystorectl, DL_KEYSTORECTL_KEY_SIZE keySize)
423 {
424  DL_Common_updateReg(&keystorectl->KEYRD, (uint32_t) keySize,
425  KEYSTORECTL_KEYRD_KEYSZSEL_MASK);
426 }
427 
437 __STATIC_INLINE DL_KEYSTORECTL_KEY_SIZE DL_KEYSTORECTL_getSourceKeySize(
438  const KEYSTORECTL_Regs *keystorectl)
439 {
440  uint32_t keySize = (keystorectl->KEYRD & KEYSTORECTL_KEYRD_KEYSZSEL_MASK);
441 
442  return (DL_KEYSTORECTL_KEY_SIZE)(keySize);
443 }
444 
453  const KEYSTORECTL_Regs *keystorectl)
454 {
455  uint32_t status = (keystorectl->STATUS & KEYSTORECTL_STATUS_STAT_MASK);
456 
457  return (DL_KEYSTORECTL_STATUS)(status);
458 }
459 
472 __STATIC_INLINE uint32_t DL_KEYSTORECTL_getValidKeySlots(
473  const KEYSTORECTL_Regs *keystorectl)
474 {
475  return (keystorectl->STATUS & KEYSTORECTL_STATUS_VALID_MASK);
476 }
477 
491 __STATIC_INLINE DL_KEYSTORECTL_NUM_SLOTS DL_KEYSTORECTL_getNumSlots(
492  const KEYSTORECTL_Regs *keystorectl)
493 {
494  uint32_t numSlots =
495  (keystorectl->STATUS & KEYSTORECTL_STATUS_NKEYSLOTS_MASK);
496 
497  return (DL_KEYSTORECTL_NUM_SLOTS)(numSlots);
498 }
499 
531  KEYSTORECTL_Regs *keystorectl, DL_KEYSTORECTL_KeyWrConfig *keyWrConfig);
532 
554  KEYSTORECTL_Regs *keystorectl, const DL_KEYSTORECTL_Config *config);
555 
556 #ifdef __cplusplus
557 }
558 #endif
559 
560 #endif /* __MSPM0_HAS_KEYSTORE_CTL__ */
561 
562 #endif /* ti_dl_dl_KEYSTORECTL__include */
563 
__STATIC_INLINE void DL_Common_updateReg(volatile uint32_t *reg, uint32_t val, uint32_t mask)
Writes value to specified register - retaining bits unaffected by mask.
Definition: dl_common.h:63
Definition: dl_keystorectl.h:143
Definition: dl_keystorectl.h:131
DL_KEYSTORECTL_KEY_SIZE
Definition: dl_keystorectl.h:129
Definition: dl_keystorectl.h:170
Definition: dl_keystorectl.h:149
Definition: dl_keystorectl.h:123
Definition: dl_keystorectl.h:163
Definition: dl_keystorectl.h:165
DL_KEYSTORECTL_STATUS
Definition: dl_keystorectl.h:153
DL_KEYSTORECTL_CRYPTO_SEL
Definition: dl_keystorectl.h:147
DL_KEYSTORECTL_CRYPTO_SEL cryptoSel
Definition: dl_keystorectl.h:208
__STATIC_INLINE DL_KEYSTORECTL_STATUS DL_KEYSTORECTL_getStatus(const KEYSTORECTL_Regs *keystorectl)
Gets the current status of the KEYSTORECTL module.
Definition: dl_keystorectl.h:452
uint32_t * key
Definition: dl_keystorectl.h:194
DL_KEYSTORECTL_STATUS DL_KEYSTORECTL_writeKey(KEYSTORECTL_Regs *keystorectl, DL_KEYSTORECTL_KeyWrConfig *keyWrConfig)
Writes a key into the KEYSTORE.
Definition: dl_keystorectl.h:158
DL_KEYSTORECTL_KEY_SIZE keySize
Definition: dl_keystorectl.h:206
DriverLib Common APIs.
Definition: dl_keystorectl.h:121
Definition: dl_keystorectl.h:176
Definition: dl_keystorectl.h:125
Configuration struct for DL_KEYSTORECTL_transferKey.
Definition: dl_keystorectl.h:200
Definition: dl_keystorectl.h:141
__STATIC_INLINE DL_KEYSTORECTL_NUM_256_KEYS DL_KEYSTORECTL_getNumberOf256Keys(const KEYSTORECTL_Regs *keystorectl)
Returns the current number of combined 256 key slots.
Definition: dl_keystorectl.h:244
Definition: dl_keystorectl.h:155
DL_KEYSTORECTL_NUM_256_KEYS
Definition: dl_keystorectl.h:115
Definition: dl_keystorectl.h:133
uint32_t keySlot
Definition: dl_keystorectl.h:203
__STATIC_INLINE void DL_KEYSTORECTL_setDestinationKeySize(KEYSTORECTL_Regs *keystorectl, DL_KEYSTORECTL_KEY_SIZE keySize)
Sets the intended destination key slot size for next write.
Definition: dl_keystorectl.h:318
__STATIC_INLINE uint32_t DL_KEYSTORECTL_getDestinationKeySlot(const KEYSTORECTL_Regs *keystorectl)
Returns the intended destination key slot for the next write.
Definition: dl_keystorectl.h:294
DL_KEYSTORECTL_KEY_SIZE keySize
Definition: dl_keystorectl.h:192
__STATIC_INLINE void DL_KEYSTORECTL_setSourceKeySize(KEYSTORECTL_Regs *keystorectl, DL_KEYSTORECTL_KEY_SIZE keySize)
Gets the intended source key slot size for next transfer.
Definition: dl_keystorectl.h:421
Definition: dl_keystorectl.h:117
Definition: dl_keystorectl.h:160
Configuration struct for DL_KEYSTORECTL_writeKey.
Definition: dl_keystorectl.h:186
uint32_t keySlot
Definition: dl_keystorectl.h:189
DL_KEYSTORECTL_STATUS DL_KEYSTORECTL_transferKey(KEYSTORECTL_Regs *keystorectl, const DL_KEYSTORECTL_Config *config)
Transfers key loaded in KEYSTORE into intended crypto.
__STATIC_INLINE void DL_KEYSTORECTL_setDestinationKeySlot(KEYSTORECTL_Regs *keystorectl, uint32_t keySlot)
Sets the intended destination key slot for the next write.
Definition: dl_keystorectl.h:272
__STATIC_INLINE DL_KEYSTORECTL_NUM_SLOTS DL_KEYSTORECTL_getNumSlots(const KEYSTORECTL_Regs *keystorectl)
Gets the total number of 128-bit key slots in HW on the device.
Definition: dl_keystorectl.h:491
void DL_KEYSTORECTL_loadKey(KEYSTORECTL_Regs *keystorectl, uint32_t *key)
Sets the intended destination key slot size for next write.
Definition: dl_keystorectl.h:180
__STATIC_INLINE uint32_t DL_KEYSTORECTL_getSourceKeySlot(const KEYSTORECTL_Regs *keystorectl)
Gets the intended source key slot for the next transfer.
Definition: dl_keystorectl.h:400
DL_KEYSTORECTL_NUM_SLOTS
Definition: dl_keystorectl.h:137
Definition: dl_keystorectl.h:139
__STATIC_INLINE DL_KEYSTORECTL_KEY_SIZE DL_KEYSTORECTL_getDestinationKeySize(const KEYSTORECTL_Regs *keystorectl)
Returns the intended destination key size for the next write.
Definition: dl_keystorectl.h:337
Definition: dl_keystorectl.h:119
__STATIC_INLINE uint32_t DL_KEYSTORECTL_getValidKeySlots(const KEYSTORECTL_Regs *keystorectl)
Gets currently written key slots.
Definition: dl_keystorectl.h:472
__STATIC_INLINE void DL_KEYSTORECTL_setNumberOf256Keys(KEYSTORECTL_Regs *keystorectl, DL_KEYSTORECTL_NUM_256_KEYS numKeys)
Sets the number of combined 256 key slots.
Definition: dl_keystorectl.h:228
__STATIC_INLINE DL_KEYSTORECTL_KEY_SIZE DL_KEYSTORECTL_getSourceKeySize(const KEYSTORECTL_Regs *keystorectl)
Gets the intended source key size for the next transfer.
Definition: dl_keystorectl.h:437
__STATIC_INLINE void DL_KEYSTORECTL_setSourceKeySlot(KEYSTORECTL_Regs *keystorectl, uint32_t keySlot)
Gets the intended source key slot for the next transfer.
Definition: dl_keystorectl.h:381
© Copyright 1995-2025, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale