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