STM32F4 Standard Peripheral bibliotheek  1.0
ST Microelectronics bibliotheek documentatie voor de STM32F4 Standard Peripheral Library
 All Data Structures Files Functions Variables Enumerations Enumerator Groups
stm32f4xx_cryp.h
Go to the documentation of this file.
1 
29 /* Define to prevent recursive inclusion -------------------------------------*/
30 #ifndef __STM32F4xx_CRYP_H
31 #define __STM32F4xx_CRYP_H
32 
33 #ifdef __cplusplus
34  extern "C" {
35 #endif
36 
37 /* Includes ------------------------------------------------------------------*/
38 #include "stm32f4xx.h"
39 
48 /* Exported types ------------------------------------------------------------*/
49 
53 typedef struct
54 {
55  uint16_t CRYP_AlgoDir;
57  uint16_t CRYP_AlgoMode;
60  uint16_t CRYP_DataType;
62  uint16_t CRYP_KeySize;
66 
70 typedef struct
71 {
72  uint32_t CRYP_Key0Left;
73  uint32_t CRYP_Key0Right;
74  uint32_t CRYP_Key1Left;
75  uint32_t CRYP_Key1Right;
76  uint32_t CRYP_Key2Left;
77  uint32_t CRYP_Key2Right;
78  uint32_t CRYP_Key3Left;
79  uint32_t CRYP_Key3Right;
84 typedef struct
85 {
86  uint32_t CRYP_IV0Left;
87  uint32_t CRYP_IV0Right;
88  uint32_t CRYP_IV1Left;
89  uint32_t CRYP_IV1Right;
91 
95 typedef struct
96 {
98  uint32_t CR_bits9to2;
100  uint32_t CRYP_IV0LR;
101  uint32_t CRYP_IV0RR;
102  uint32_t CRYP_IV1LR;
103  uint32_t CRYP_IV1RR;
105  uint32_t CRYP_K0LR;
106  uint32_t CRYP_K0RR;
107  uint32_t CRYP_K1LR;
108  uint32_t CRYP_K1RR;
109  uint32_t CRYP_K2LR;
110  uint32_t CRYP_K2RR;
111  uint32_t CRYP_K3LR;
112  uint32_t CRYP_K3RR;
113 }CRYP_Context;
114 
115 
116 /* Exported constants --------------------------------------------------------*/
117 
125 #define CRYP_AlgoDir_Encrypt ((uint16_t)0x0000)
126 #define CRYP_AlgoDir_Decrypt ((uint16_t)0x0004)
127 #define IS_CRYP_ALGODIR(ALGODIR) (((ALGODIR) == CRYP_AlgoDir_Encrypt) || \
128  ((ALGODIR) == CRYP_AlgoDir_Decrypt))
129 
139 #define CRYP_AlgoMode_TDES_ECB ((uint16_t)0x0000)
140 #define CRYP_AlgoMode_TDES_CBC ((uint16_t)0x0008)
141 
143 #define CRYP_AlgoMode_DES_ECB ((uint16_t)0x0010)
144 #define CRYP_AlgoMode_DES_CBC ((uint16_t)0x0018)
145 
147 #define CRYP_AlgoMode_AES_ECB ((uint16_t)0x0020)
148 #define CRYP_AlgoMode_AES_CBC ((uint16_t)0x0028)
149 #define CRYP_AlgoMode_AES_CTR ((uint16_t)0x0030)
150 #define CRYP_AlgoMode_AES_Key ((uint16_t)0x0038)
151 
152 #define IS_CRYP_ALGOMODE(ALGOMODE) (((ALGOMODE) == CRYP_AlgoMode_TDES_ECB) || \
153  ((ALGOMODE) == CRYP_AlgoMode_TDES_CBC)|| \
154  ((ALGOMODE) == CRYP_AlgoMode_DES_ECB)|| \
155  ((ALGOMODE) == CRYP_AlgoMode_DES_CBC) || \
156  ((ALGOMODE) == CRYP_AlgoMode_AES_ECB) || \
157  ((ALGOMODE) == CRYP_AlgoMode_AES_CBC) || \
158  ((ALGOMODE) == CRYP_AlgoMode_AES_CTR) || \
159  ((ALGOMODE) == CRYP_AlgoMode_AES_Key))
160 
167 #define CRYP_DataType_32b ((uint16_t)0x0000)
168 #define CRYP_DataType_16b ((uint16_t)0x0040)
169 #define CRYP_DataType_8b ((uint16_t)0x0080)
170 #define CRYP_DataType_1b ((uint16_t)0x00C0)
171 #define IS_CRYP_DATATYPE(DATATYPE) (((DATATYPE) == CRYP_DataType_32b) || \
172  ((DATATYPE) == CRYP_DataType_16b)|| \
173  ((DATATYPE) == CRYP_DataType_8b)|| \
174  ((DATATYPE) == CRYP_DataType_1b))
175 
182 #define CRYP_KeySize_128b ((uint16_t)0x0000)
183 #define CRYP_KeySize_192b ((uint16_t)0x0100)
184 #define CRYP_KeySize_256b ((uint16_t)0x0200)
185 #define IS_CRYP_KEYSIZE(KEYSIZE) (((KEYSIZE) == CRYP_KeySize_128b)|| \
186  ((KEYSIZE) == CRYP_KeySize_192b)|| \
187  ((KEYSIZE) == CRYP_KeySize_256b))
188 
195 #define CRYP_FLAG_BUSY ((uint8_t)0x10)
199 #define CRYP_FLAG_IFEM ((uint8_t)0x01)
200 #define CRYP_FLAG_IFNF ((uint8_t)0x02)
201 #define CRYP_FLAG_INRIS ((uint8_t)0x22)
202 #define CRYP_FLAG_OFNE ((uint8_t)0x04)
204 #define CRYP_FLAG_OFFU ((uint8_t)0x08)
205 #define CRYP_FLAG_OUTRIS ((uint8_t)0x21)
208 #define IS_CRYP_GET_FLAG(FLAG) (((FLAG) == CRYP_FLAG_IFEM) || \
209  ((FLAG) == CRYP_FLAG_IFNF) || \
210  ((FLAG) == CRYP_FLAG_OFNE) || \
211  ((FLAG) == CRYP_FLAG_OFFU) || \
212  ((FLAG) == CRYP_FLAG_BUSY) || \
213  ((FLAG) == CRYP_FLAG_OUTRIS)|| \
214  ((FLAG) == CRYP_FLAG_INRIS))
215 
222 #define CRYP_IT_INI ((uint8_t)0x01)
223 #define CRYP_IT_OUTI ((uint8_t)0x02)
224 #define IS_CRYP_CONFIG_IT(IT) ((((IT) & (uint8_t)0xFC) == 0x00) && ((IT) != 0x00))
225 #define IS_CRYP_GET_IT(IT) (((IT) == CRYP_IT_INI) || ((IT) == CRYP_IT_OUTI))
226 
234 #define MODE_ENCRYPT ((uint8_t)0x01)
235 #define MODE_DECRYPT ((uint8_t)0x00)
236 
244 #define CRYP_DMAReq_DataIN ((uint8_t)0x01)
245 #define CRYP_DMAReq_DataOUT ((uint8_t)0x02)
246 #define IS_CRYP_DMAREQ(DMAREQ) ((((DMAREQ) & (uint8_t)0xFC) == 0x00) && ((DMAREQ) != 0x00))
247 
255 /* Exported macro ------------------------------------------------------------*/
256 /* Exported functions --------------------------------------------------------*/
257 
258 /* Function used to set the CRYP configuration to the default reset state ****/
259 void CRYP_DeInit(void);
260 
261 /* CRYP Initialization and Configuration functions ****************************/
262 void CRYP_Init(CRYP_InitTypeDef* CRYP_InitStruct);
263 void CRYP_StructInit(CRYP_InitTypeDef* CRYP_InitStruct);
264 void CRYP_KeyInit(CRYP_KeyInitTypeDef* CRYP_KeyInitStruct);
265 void CRYP_KeyStructInit(CRYP_KeyInitTypeDef* CRYP_KeyInitStruct);
266 void CRYP_IVInit(CRYP_IVInitTypeDef* CRYP_IVInitStruct);
267 void CRYP_IVStructInit(CRYP_IVInitTypeDef* CRYP_IVInitStruct);
268 void CRYP_Cmd(FunctionalState NewState);
269 
270 /* CRYP Data processing functions *********************************************/
271 void CRYP_DataIn(uint32_t Data);
272 uint32_t CRYP_DataOut(void);
273 void CRYP_FIFOFlush(void);
274 
275 /* CRYP Context swapping functions ********************************************/
276 ErrorStatus CRYP_SaveContext(CRYP_Context* CRYP_ContextSave,
277  CRYP_KeyInitTypeDef* CRYP_KeyInitStruct);
278 void CRYP_RestoreContext(CRYP_Context* CRYP_ContextRestore);
279 
280 /* CRYP's DMA interface function **********************************************/
281 void CRYP_DMACmd(uint8_t CRYP_DMAReq, FunctionalState NewState);
282 
283 /* Interrupts and flags management functions **********************************/
284 void CRYP_ITConfig(uint8_t CRYP_IT, FunctionalState NewState);
285 ITStatus CRYP_GetITStatus(uint8_t CRYP_IT);
286 FlagStatus CRYP_GetFlagStatus(uint8_t CRYP_FLAG);
287 
288 /* High Level AES functions **************************************************/
289 ErrorStatus CRYP_AES_ECB(uint8_t Mode,
290  uint8_t *Key, uint16_t Keysize,
291  uint8_t *Input, uint32_t Ilength,
292  uint8_t *Output);
293 
294 ErrorStatus CRYP_AES_CBC(uint8_t Mode,
295  uint8_t InitVectors[16],
296  uint8_t *Key, uint16_t Keysize,
297  uint8_t *Input, uint32_t Ilength,
298  uint8_t *Output);
299 
300 ErrorStatus CRYP_AES_CTR(uint8_t Mode,
301  uint8_t InitVectors[16],
302  uint8_t *Key, uint16_t Keysize,
303  uint8_t *Input, uint32_t Ilength,
304  uint8_t *Output);
305 
306 /* High Level TDES functions **************************************************/
307 ErrorStatus CRYP_TDES_ECB(uint8_t Mode,
308  uint8_t Key[24],
309  uint8_t *Input, uint32_t Ilength,
310  uint8_t *Output);
311 
312 ErrorStatus CRYP_TDES_CBC(uint8_t Mode,
313  uint8_t Key[24],
314  uint8_t InitVectors[8],
315  uint8_t *Input, uint32_t Ilength,
316  uint8_t *Output);
317 
318 /* High Level DES functions **************************************************/
319 ErrorStatus CRYP_DES_ECB(uint8_t Mode,
320  uint8_t Key[8],
321  uint8_t *Input, uint32_t Ilength,
322  uint8_t *Output);
323 
324 ErrorStatus CRYP_DES_CBC(uint8_t Mode,
325  uint8_t Key[8],
326  uint8_t InitVectors[8],
327  uint8_t *Input,uint32_t Ilength,
328  uint8_t *Output);
329 
330 #ifdef __cplusplus
331 }
332 #endif
333 
334 #endif /*__STM32F4xx_CRYP_H */
335 
344 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/