CryptoCC26X4_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  * @file CryptoCC26X4_s.h
34  * @brief Secure Crypto Service
35  *
36  * @anchor ti_drivers_crypto_CryptoCC26X4_s_Overview
37  * # Overview
38  * The Secure Crypto Service is used to access all cryptographic functions
39  * when using the TF-M.
40  *
41  *******************************************************************************
42  */
43 #ifndef ti_drivers_crypto_CryptoCC26X4_s__include
44 #define ti_drivers_crypto_CryptoCC26X4_s__include
45 
46 #include <stdint.h>
47 
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51 
52 /* Index values for secure msg types for various crypto drivers */
53 #define CRYPTO_S_MSG_TYPE_INDEX_AESCBC ((int32_t)0x11)
54 #define CRYPTO_S_MSG_TYPE_INDEX_AESCCM ((int32_t)0x22)
55 #define CRYPTO_S_MSG_TYPE_INDEX_AESCMAC ((int32_t)0x33)
56 #define CRYPTO_S_MSG_TYPE_INDEX_AESCTR ((int32_t)0x44)
57 #define CRYPTO_S_MSG_TYPE_INDEX_AESECB ((int32_t)0x55)
58 #define CRYPTO_S_MSG_TYPE_INDEX_AESGCM ((int32_t)0x66)
59 #define CRYPTO_S_MSG_TYPE_INDEX_AESCTRDRBG ((int32_t)0x77)
60 #define CRYPTO_S_MSG_TYPE_INDEX_ECDH ((int32_t)0x88)
61 #define CRYPTO_S_MSG_TYPE_INDEX_ECDSA ((int32_t)0x99)
62 #define CRYPTO_S_MSG_TYPE_INDEX_ECJPAKE ((int32_t)0xAA)
63 #define CRYPTO_S_MSG_TYPE_INDEX_EDDSA ((int32_t)0xBB)
64 #define CRYPTO_S_MSG_TYPE_INDEX_SHA2 ((int32_t)0xCC)
65 #define CRYPTO_S_MSG_TYPE_INDEX_TRNG ((int32_t)0xDD)
66 #define CRYPTO_S_MSG_TYPE_INDEX_KEYSTORE ((int32_t)0xEE)
67 #define CRYPTO_S_MSG_TYPE_INDEX_PSA ((int32_t)0xFF)
68 
69 #define CRYPTO_S_MSG_TYPE_FUNCNUM_BITS 4U
70 #define CRYPTO_S_MSG_TYPE_FUNCNUM_SHIFT 8U
71 #define CRYPTO_S_MSG_TYPE_INDEX_MASK 0xFF
72 #define GET_CRYPTO_S_MSG_TYPE_INDEX(type) ((type) & (int32_t)CRYPTO_S_MSG_TYPE_INDEX_MASK)
73 
74 /* TF-M PSA NS interface internally limits the type to int16_t */
75 #define TFM_PSA_TYPE_MASK 0x00007FFF
76 
77 /*
78  * Macros used to generate PSA message type values for various crypto driver
79  * functions. It duplicates the funcNum in the highest nibble when possible
80  * for bit flip resistance. The funcNum value is limited to 15.
81  */
82 #define CRYPTO_S_MSG_TYPE(index, funcNum) \
83  (((index) | ((int32_t)(funcNum) << CRYPTO_S_MSG_TYPE_FUNCNUM_SHIFT) | \
84  ((int32_t)(funcNum) << (CRYPTO_S_MSG_TYPE_FUNCNUM_SHIFT + CRYPTO_S_MSG_TYPE_FUNCNUM_BITS))) & \
85  TFM_PSA_TYPE_MASK)
86 
87 #define AESCBC_S_MSG_TYPE(funcNum) CRYPTO_S_MSG_TYPE(CRYPTO_S_MSG_TYPE_INDEX_AESCBC, funcNum)
88 #define AESCCM_S_MSG_TYPE(funcNum) CRYPTO_S_MSG_TYPE(CRYPTO_S_MSG_TYPE_INDEX_AESCCM, funcNum)
89 #define AESCMAC_S_MSG_TYPE(funcNum) CRYPTO_S_MSG_TYPE(CRYPTO_S_MSG_TYPE_INDEX_AESCMAC, funcNum)
90 #define AESCTR_S_MSG_TYPE(funcNum) CRYPTO_S_MSG_TYPE(CRYPTO_S_MSG_TYPE_INDEX_AESCTR, funcNum)
91 #define AESCTRDRBG_S_MSG_TYPE(funcNum) CRYPTO_S_MSG_TYPE(CRYPTO_S_MSG_TYPE_INDEX_AESCTRDRBG, funcNum)
92 #define AESECB_S_MSG_TYPE(funcNum) CRYPTO_S_MSG_TYPE(CRYPTO_S_MSG_TYPE_INDEX_AESECB, funcNum)
93 #define AESGCM_S_MSG_TYPE(funcNum) CRYPTO_S_MSG_TYPE(CRYPTO_S_MSG_TYPE_INDEX_AESGCM, funcNum)
94 #define ECDH_S_MSG_TYPE(funcNum) CRYPTO_S_MSG_TYPE(CRYPTO_S_MSG_TYPE_INDEX_ECDH, funcNum)
95 #define ECDSA_S_MSG_TYPE(funcNum) CRYPTO_S_MSG_TYPE(CRYPTO_S_MSG_TYPE_INDEX_ECDSA, funcNum)
96 #define ECJPAKE_S_MSG_TYPE(funcNum) CRYPTO_S_MSG_TYPE(CRYPTO_S_MSG_TYPE_INDEX_ECJPAKE, funcNum)
97 #define SHA2_S_MSG_TYPE(funcNum) CRYPTO_S_MSG_TYPE(CRYPTO_S_MSG_TYPE_INDEX_SHA2, funcNum)
98 #define TRNG_S_MSG_TYPE(funcNum) CRYPTO_S_MSG_TYPE(CRYPTO_S_MSG_TYPE_INDEX_TRNG, funcNum)
99 #define KEYSTORE_PSA_S_MSG_TYPE(funcNum) CRYPTO_S_MSG_TYPE(CRYPTO_S_MSG_TYPE_INDEX_KEYSTORE, funcNum)
100 #define PSA_S_MSG_TYPE(funcNum) CRYPTO_S_MSG_TYPE(CRYPTO_S_MSG_TYPE_INDEX_PSA, funcNum)
101 
102 /*
103  * Secure handle ID values which correspond to unmapped memory ranges are used
104  * to avoid confusion with non-secure driver handles which point to valid
105  * memory locations.
106  */
107 enum
108 {
116  CRYPTO_S_HANDLE_ID_ECDH = 0xABCD8000U,
120  CRYPTO_S_HANDLE_ID_SHA2 = 0xABCDC000U,
121  CRYPTO_S_HANDLE_ID_TRNG = 0xABCDD000U,
122 };
123 
124 #define CRYPTO_S_HANDLE_ID_MASK 0xFFFFF000U
125 #define CRYPTO_S_HANDLE_INDEX_MASK 0x00000FFFU
126 
127 #define GET_CRYPTO_S_HANDLE_ID(handle) ((uintptr_t)(handle)&CRYPTO_S_HANDLE_ID_MASK)
128 #define GET_CRYPTO_S_HANDLE_INDEX(handle) ((uintptr_t)(handle)&CRYPTO_S_HANDLE_INDEX_MASK)
129 
130 #ifdef __cplusplus
131 }
132 #endif
133 
134 #endif /* ti_drivers_crypto_CryptoCC26X4_s__include */
Definition: CryptoCC26X4_s.h:115
Definition: CryptoCC26X4_s.h:118
Definition: CryptoCC26X4_s.h:117
Definition: CryptoCC26X4_s.h:109
Definition: CryptoCC26X4_s.h:121
Definition: CryptoCC26X4_s.h:120
Definition: CryptoCC26X4_s.h:116
Definition: CryptoCC26X4_s.h:113
Definition: CryptoCC26X4_s.h:112
Definition: CryptoCC26X4_s.h:119
Definition: CryptoCC26X4_s.h:114
Definition: CryptoCC26X4_s.h:111
Definition: CryptoCC26X4_s.h:110
© Copyright 1995-2023, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale