ADuCM302x Device Drivers API Reference Manual  Release 3.1.2.0
adi_crypto_def.h
1 
44 #ifndef ADI_CRYPTO_DEF_H
45 #define ADI_CRYPTO_DEF_H
46 
49 #include <drivers/dma/adi_dma.h>
50 #include <adi_crypto_config.h>
51 
52 /* pick up compiler-specific alignment directives */
53 #include <drivers/general/adi_drivers_general.h>
54 #define ALIGN4 ALIGNED_PRAGMA(4)
55 
56 /* Support Check MACROS */
57 #define CRYPTO_SUPPORT_KEY_REQUIRED ( \
58  (ADI_CRYPTO_ENABLE_ECB_SUPPORT == 1) \
59  || (ADI_CRYPTO_ENABLE_CTR_SUPPORT == 1) \
60  || (ADI_CRYPTO_ENABLE_CBC_SUPPORT == 1) \
61  || (ADI_CRYPTO_ENABLE_CCM_SUPPORT == 1) \
62  || (ADI_CRYPTO_ENABLE_CMAC_SUPPORT == 1) \
63  )
64 
65 #define CRYPTO_SUPPORT_MODE_CCM_ONLY ( \
66  (ADI_CRYPTO_ENABLE_ECB_SUPPORT != 1) \
67  && (ADI_CRYPTO_ENABLE_CTR_SUPPORT != 1) \
68  && (ADI_CRYPTO_ENABLE_CBC_SUPPORT != 1) \
69  && (ADI_CRYPTO_ENABLE_CCM_SUPPORT == 1) \
70  && (ADI_CRYPTO_ENABLE_CMAC_SUPPORT != 1) \
71  && (ADI_CRYPTO_ENABLE_SHA_SUPPORT != 1) \
72  )
73 
74 #define CRYPTO_SUPPORT_MODE_ANY_NON_CCM ( \
75  (ADI_CRYPTO_ENABLE_ECB_SUPPORT == 1) \
76  || (ADI_CRYPTO_ENABLE_CTR_SUPPORT == 1) \
77  || (ADI_CRYPTO_ENABLE_CBC_SUPPORT == 1) \
78  || (ADI_CRYPTO_ENABLE_CMAC_SUPPORT == 1) \
79  || (ADI_CRYPTO_ENABLE_SHA_SUPPORT == 1) \
80  )
81 
82 #define CRYPTO_SUPPORT_MODE_ANY_NON_SHA ( \
83  (ADI_CRYPTO_ENABLE_ECB_SUPPORT == 1) \
84  || (ADI_CRYPTO_ENABLE_CTR_SUPPORT == 1) \
85  || (ADI_CRYPTO_ENABLE_CBC_SUPPORT == 1) \
86  || (ADI_CRYPTO_ENABLE_CMAC_SUPPORT == 1) \
87  || (ADI_CRYPTO_ENABLE_CCM_SUPPORT == 1) \
88  )
89 
90 
91 /* PKSTOR config bits */
92 #if (defined (__ADUCM4x50__) && (1 == ADI_CRYPTO_ENABLE_PKSTOR_SUPPORT))
93 #define PK_CONFIG_BITS (BITM_CRYPT_CFG_PRKSTOREN | BITM_CRYPT_CFG_BLKEN )
94 #define NUM_PKSTOR_VAL_STRING_WORDS (2)
95 #endif
96 
97 
98 /* define local MIN/MAX macros, if not already... */
99 #ifndef MIN
100 #define MIN(a,b) (((a)<(b))?(a):(b))
101 #endif
102 #ifndef MAX
103 #define MAX(a,b) (((a)>(b))?(a):(b))
104 #endif
105 
106 /* various size macros */
107 #define MAX_CRYPTO_DMA_BYTES (DMA_TRANSFER_LIMIT * sizeof(uint32_t))
108 
109 /* SHA hardware max chunk size attributes */
110 #define SHA_CHUNK_MAX_BYTES (64u)
111 #define SHA_CHUNK_MAX_BITS (SHA_CHUNK_MAX_BYTES * 8U)
112 #define SHA_CHUNK_MAX_WORDS (16u)
113 
114 /* HMAC hardware max chunk size attributes */
115 #define HMAC_CHUNK_MAX_BYTES (64u)
116 #define HMAC_CHUNK_MAX_BITS (HMAC_CHUNK_MAX_BYTES * 8U)
117 #define HMAC_CHUNK_MAX_WORDS (16u)
118 
119 #define FIFO_WIDTH_IN_BITS (32u)
120 #define FIFO_WIDTH_IN_BYTES (FIFO_WIDTH_IN_BITS/8u)
121 #define FIFO_DEPTH (4u)
122 
123 #define CRYPTO_INPUT_SIZE_IN_BITS (128u)
124 #define CRYPTO_INPUT_SIZE_IN_BYTES (CRYPTO_INPUT_SIZE_IN_BITS/8u)
125 
126 #define SHA_OUTPUT_SIZE_IN_BITS (256u)
127 #define SHA_OUTPUT_SIZE_IN_BYTES (SHA_OUTPUT_SIZE_IN_BITS/8u)
128 
129 
130 /* MAKE SURE THIS STRUCT REMAINS *******PERFECTLY ALIGNED******* WITH USER
131  ADI_CRYPTO_TRANSACTION BECAUSE WE USE BCOPY TO INITIALIZE EACH NEW SUBMIT!
132 
133  Internal compute structure reflecting mostly, user ADI_CRYPTO_TRANSACTION,
134  except for moving data pointers and remaining counts. Contents initialized
135  directly from from ADI_CRYPTO_TRANSACTION during buffer submit.
136 */
137 typedef struct _CRYPTO_COMPUTE {
138  ADI_CRYPTO_CIPHER_MODE eCipherMode;
139  ADI_CRYPTO_CODING_MODE eCodingMode;
140 #if defined (__ADUCM4x50__)
141  ADI_CRYPTO_KEY_BYTE_SWAP eKeyByteSwap;
142  ADI_CRYPTO_SHA_BYTE_SWAP eShaByteSwap;
143 #endif /*__ADUCM4x50__*/
144  ADI_CRYPTO_AES_BYTE_SWAP eAesByteSwap;
146  uint8_t *pAesKey;
147  ADI_CRYPTO_AES_KEY_LEN eAesKeyLen;
149  uint8_t *pHmacKey;
151  uint32_t *pNextAuthInput; /* CCM mode: pointer to user prefix buffer */
152  uint32_t numAuthBytesRemaining; /* Length of the prefix buffer in bytes (should be a multiple of 16 bytes) */
153 
154  uint32_t *pNextInput; /* Pointer to next user 32-bit input location */
155  uint32_t numInputBytesRemaining; /* Number of input bytes remaining */
156 
157  uint32_t *pNextOutput; /* Pointer to next user 32-bit output location */
158  uint32_t numOutputBytesRemaining; /* Number of output bytes remaining */
159 
160  uint8_t *pNonceIV;
170  uint32_t CounterInit;
171  uint32_t numValidBytes;
172  uint32_t numShaBitsRemaining;
174 #if (defined (__ADUCM4x50__) && (1 == ADI_CRYPTO_ENABLE_PKSTOR_SUPPORT))
175  /* PKSTOR extensions used only in context of overriding above key info with protected keys stored in flash. */
176  /* Assumes previously wrapped keys have already been stored using adi_crypto_pk_Xxx APIs. */
177  bool bUsePKSTOR; /* flag controlling use of PKSTOR key overrides */
178  ADI_CRYPTO_PK_KUW_LEN pkKuwLen; /* overriding key size */
179  uint8_t pkIndex; /* PKSTOR flash index for key to use */
180 #endif
181 } CRYPTO_COMPUTE;
182 
183 
184 /* Crypto device attributes */
185 typedef struct _CRYPTO_INFO {
186  ADI_CRYPT_TypeDef *pDev; /* Pointer to physical Crypto controller */
187  ADI_CRYPTO_HANDLE hDevice; /* Device Handle */
188 #if (ADI_CRYPTO_ENABLE_DMA_SUPPORT == 1)
189  IRQn_Type dmaInputIrqNum;
190  IRQn_Type dmaOutputIrqNum;
191  DMA_CHANn_TypeDef dmaInputChanNum;
192  DMA_CHANn_TypeDef dmaOutputChanNum;
193  volatile ADI_CRYPTO_RESULT dmaError; /* DMA error collector. */
194 #endif
195 } CRYPTO_INFO;
196 
197 
198 #ifdef __ICCARM__
199 /*
200 * Pm123 (RULE 8.5) there shall be no definition of objects or functions in a header file.
201 * Exception is to allow the Crypto device data type and instance to be declared simultaniously.
202 */
203 #pragma diag_suppress=Pm123
204 #endif /* __ICCARM__ */
205 
206 /* Crypto driver internal data */
207 struct __ADI_CRYPTO_DEV_DATA_TYPE {
208  bool bDeviceEnabled; /* Boolean flag to signify whether the device is enable/disabled */
209  bool bDmaEnabled; /* Boolean flag to signify whether the DMA is enable/disabled */
210  bool bCompletion; /* Boolean flag to signify whether a transaction is complete */
211 
212  ADI_CRYPT_TypeDef *pDev; /* Pointer to physical Crypto controller */
213 
214  CRYPTO_INFO *pDevInfo; /* access to device info */
215 
216  CRYPTO_COMPUTE Computation; /* Active computation structure */
217 
218  ADI_CRYPTO_TRANSACTION *pUserBuffer; /* saved user buffer pointer from submit */
219  ADI_CALLBACK pfCallback; /* User defined callback function */
220  void *pCBParam; /* User defined callback param */
221  ADI_CRYPTO_RESULT dmaErrorCode; /* saved DMA error code to return via user API */
222 
223 
224  SEM_VAR_DECLR /* Blocking object abstraction: "Semaphore" for rtos, "bLowPowerExitFlag" for non-rtos, etc. */
225 } ADI_CRYPTO_DEV_DATA_TYPE;
226 
227 #ifdef __ICCARM__
228 #pragma diag_default=Pm123
229 #endif /* __ICCARM__ */
230 
233 #endif /* ADI_CRYPTO_DEF_H */
ADI_CRYPTO_AES_KEY_LEN
Definition: adi_crypto.h:159
ADI_CRYPTO_CIPHER_MODE
Definition: adi_crypto.h:194
ADI_CRYPTO_RESULT
Definition: adi_crypto.h:69
ADI_CRYPTO_CODING_MODE
Definition: adi_crypto.h:152
ADI_CRYPTO_AES_BYTE_SWAP
Definition: adi_crypto.h:184
struct __ADI_CRYPTO_DEV_DATA_TYPE * ADI_CRYPTO_HANDLE
Definition: adi_crypto.h:140