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  uint32_t CRYP_AlgoDir;
57  uint32_t CRYP_AlgoMode;
60  uint32_t CRYP_DataType;
62  uint32_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_CurrentConfig;
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  uint32_t CRYP_CSGCMCCMR[8];
114  uint32_t CRYP_CSGCMR[8];
115 }CRYP_Context;
116 
117 
118 /* Exported constants --------------------------------------------------------*/
119 
127 #define CRYP_AlgoDir_Encrypt ((uint16_t)0x0000)
128 #define CRYP_AlgoDir_Decrypt ((uint16_t)0x0004)
129 #define IS_CRYP_ALGODIR(ALGODIR) (((ALGODIR) == CRYP_AlgoDir_Encrypt) || \
130  ((ALGODIR) == CRYP_AlgoDir_Decrypt))
131 
141 #define CRYP_AlgoMode_TDES_ECB ((uint32_t)0x00000000)
142 #define CRYP_AlgoMode_TDES_CBC ((uint32_t)0x00000008)
143 
145 #define CRYP_AlgoMode_DES_ECB ((uint32_t)0x00000010)
146 #define CRYP_AlgoMode_DES_CBC ((uint32_t)0x00000018)
147 
149 #define CRYP_AlgoMode_AES_ECB ((uint32_t)0x00000020)
150 #define CRYP_AlgoMode_AES_CBC ((uint32_t)0x00000028)
151 #define CRYP_AlgoMode_AES_CTR ((uint32_t)0x00000030)
152 #define CRYP_AlgoMode_AES_Key ((uint32_t)0x00000038)
153 #define CRYP_AlgoMode_AES_GCM ((uint32_t)0x00080000)
154 #define CRYP_AlgoMode_AES_CCM ((uint32_t)0x00080008)
155 
156 #define IS_CRYP_ALGOMODE(ALGOMODE) (((ALGOMODE) == CRYP_AlgoMode_TDES_ECB) || \
157  ((ALGOMODE) == CRYP_AlgoMode_TDES_CBC)|| \
158  ((ALGOMODE) == CRYP_AlgoMode_DES_ECB) || \
159  ((ALGOMODE) == CRYP_AlgoMode_DES_CBC) || \
160  ((ALGOMODE) == CRYP_AlgoMode_AES_ECB) || \
161  ((ALGOMODE) == CRYP_AlgoMode_AES_CBC) || \
162  ((ALGOMODE) == CRYP_AlgoMode_AES_CTR) || \
163  ((ALGOMODE) == CRYP_AlgoMode_AES_Key) || \
164  ((ALGOMODE) == CRYP_AlgoMode_AES_GCM) || \
165  ((ALGOMODE) == CRYP_AlgoMode_AES_CCM))
166 
175 #define CRYP_Phase_Init ((uint32_t)0x00000000)
176 #define CRYP_Phase_Header CRYP_CR_GCM_CCMPH_0
177 #define CRYP_Phase_Payload CRYP_CR_GCM_CCMPH_1
178 #define CRYP_Phase_Final CRYP_CR_GCM_CCMPH
179 
180 #define IS_CRYP_PHASE(PHASE) (((PHASE) == CRYP_Phase_Init) || \
181  ((PHASE) == CRYP_Phase_Header) || \
182  ((PHASE) == CRYP_Phase_Payload) || \
183  ((PHASE) == CRYP_Phase_Final))
184 
192 #define CRYP_DataType_32b ((uint16_t)0x0000)
193 #define CRYP_DataType_16b ((uint16_t)0x0040)
194 #define CRYP_DataType_8b ((uint16_t)0x0080)
195 #define CRYP_DataType_1b ((uint16_t)0x00C0)
196 #define IS_CRYP_DATATYPE(DATATYPE) (((DATATYPE) == CRYP_DataType_32b) || \
197  ((DATATYPE) == CRYP_DataType_16b)|| \
198  ((DATATYPE) == CRYP_DataType_8b)|| \
199  ((DATATYPE) == CRYP_DataType_1b))
200 
207 #define CRYP_KeySize_128b ((uint16_t)0x0000)
208 #define CRYP_KeySize_192b ((uint16_t)0x0100)
209 #define CRYP_KeySize_256b ((uint16_t)0x0200)
210 #define IS_CRYP_KEYSIZE(KEYSIZE) (((KEYSIZE) == CRYP_KeySize_128b)|| \
211  ((KEYSIZE) == CRYP_KeySize_192b)|| \
212  ((KEYSIZE) == CRYP_KeySize_256b))
213 
220 #define CRYP_FLAG_BUSY ((uint8_t)0x10)
224 #define CRYP_FLAG_IFEM ((uint8_t)0x01)
225 #define CRYP_FLAG_IFNF ((uint8_t)0x02)
226 #define CRYP_FLAG_INRIS ((uint8_t)0x22)
227 #define CRYP_FLAG_OFNE ((uint8_t)0x04)
229 #define CRYP_FLAG_OFFU ((uint8_t)0x08)
230 #define CRYP_FLAG_OUTRIS ((uint8_t)0x21)
233 #define IS_CRYP_GET_FLAG(FLAG) (((FLAG) == CRYP_FLAG_IFEM) || \
234  ((FLAG) == CRYP_FLAG_IFNF) || \
235  ((FLAG) == CRYP_FLAG_OFNE) || \
236  ((FLAG) == CRYP_FLAG_OFFU) || \
237  ((FLAG) == CRYP_FLAG_BUSY) || \
238  ((FLAG) == CRYP_FLAG_OUTRIS)|| \
239  ((FLAG) == CRYP_FLAG_INRIS))
240 
247 #define CRYP_IT_INI ((uint8_t)0x01)
248 #define CRYP_IT_OUTI ((uint8_t)0x02)
249 #define IS_CRYP_CONFIG_IT(IT) ((((IT) & (uint8_t)0xFC) == 0x00) && ((IT) != 0x00))
250 #define IS_CRYP_GET_IT(IT) (((IT) == CRYP_IT_INI) || ((IT) == CRYP_IT_OUTI))
251 
259 #define MODE_ENCRYPT ((uint8_t)0x01)
260 #define MODE_DECRYPT ((uint8_t)0x00)
261 
269 #define CRYP_DMAReq_DataIN ((uint8_t)0x01)
270 #define CRYP_DMAReq_DataOUT ((uint8_t)0x02)
271 #define IS_CRYP_DMAREQ(DMAREQ) ((((DMAREQ) & (uint8_t)0xFC) == 0x00) && ((DMAREQ) != 0x00))
272 
280 /* Exported macro ------------------------------------------------------------*/
281 /* Exported functions --------------------------------------------------------*/
282 
283 /* Function used to set the CRYP configuration to the default reset state ****/
284 void CRYP_DeInit(void);
285 
286 /* CRYP Initialization and Configuration functions ****************************/
287 void CRYP_Init(CRYP_InitTypeDef* CRYP_InitStruct);
288 void CRYP_StructInit(CRYP_InitTypeDef* CRYP_InitStruct);
289 void CRYP_KeyInit(CRYP_KeyInitTypeDef* CRYP_KeyInitStruct);
290 void CRYP_KeyStructInit(CRYP_KeyInitTypeDef* CRYP_KeyInitStruct);
291 void CRYP_IVInit(CRYP_IVInitTypeDef* CRYP_IVInitStruct);
292 void CRYP_IVStructInit(CRYP_IVInitTypeDef* CRYP_IVInitStruct);
293 void CRYP_Cmd(FunctionalState NewState);
294 void CRYP_PhaseConfig(uint32_t CRYP_Phase);
295 void CRYP_FIFOFlush(void);
296 /* CRYP Data processing functions *********************************************/
297 void CRYP_DataIn(uint32_t Data);
298 uint32_t CRYP_DataOut(void);
299 
300 /* CRYP Context swapping functions ********************************************/
301 ErrorStatus CRYP_SaveContext(CRYP_Context* CRYP_ContextSave,
302  CRYP_KeyInitTypeDef* CRYP_KeyInitStruct);
303 void CRYP_RestoreContext(CRYP_Context* CRYP_ContextRestore);
304 
305 /* CRYP DMA interface function ************************************************/
306 void CRYP_DMACmd(uint8_t CRYP_DMAReq, FunctionalState NewState);
307 
308 /* Interrupts and flags management functions **********************************/
309 void CRYP_ITConfig(uint8_t CRYP_IT, FunctionalState NewState);
310 ITStatus CRYP_GetITStatus(uint8_t CRYP_IT);
312 FlagStatus CRYP_GetFlagStatus(uint8_t CRYP_FLAG);
313 
314 /* High Level AES functions **************************************************/
315 ErrorStatus CRYP_AES_ECB(uint8_t Mode,
316  uint8_t *Key, uint16_t Keysize,
317  uint8_t *Input, uint32_t Ilength,
318  uint8_t *Output);
319 
320 ErrorStatus CRYP_AES_CBC(uint8_t Mode,
321  uint8_t InitVectors[16],
322  uint8_t *Key, uint16_t Keysize,
323  uint8_t *Input, uint32_t Ilength,
324  uint8_t *Output);
325 
326 ErrorStatus CRYP_AES_CTR(uint8_t Mode,
327  uint8_t InitVectors[16],
328  uint8_t *Key, uint16_t Keysize,
329  uint8_t *Input, uint32_t Ilength,
330  uint8_t *Output);
331 
332 ErrorStatus CRYP_AES_GCM(uint8_t Mode, uint8_t InitVectors[16],
333  uint8_t *Key, uint16_t Keysize,
334  uint8_t *Input, uint32_t ILength,
335  uint8_t *Header, uint32_t HLength,
336  uint8_t *Output, uint8_t *AuthTAG);
337 
338 ErrorStatus CRYP_AES_CCM(uint8_t Mode,
339  uint8_t* Nonce, uint32_t NonceSize,
340  uint8_t* Key, uint16_t Keysize,
341  uint8_t* Input, uint32_t ILength,
342  uint8_t* Header, uint32_t HLength, uint8_t *HBuffer,
343  uint8_t* Output,
344  uint8_t* AuthTAG, uint32_t TAGSize);
345 
346 /* High Level TDES functions **************************************************/
347 ErrorStatus CRYP_TDES_ECB(uint8_t Mode,
348  uint8_t Key[24],
349  uint8_t *Input, uint32_t Ilength,
350  uint8_t *Output);
351 
352 ErrorStatus CRYP_TDES_CBC(uint8_t Mode,
353  uint8_t Key[24],
354  uint8_t InitVectors[8],
355  uint8_t *Input, uint32_t Ilength,
356  uint8_t *Output);
357 
358 /* High Level DES functions **************************************************/
359 ErrorStatus CRYP_DES_ECB(uint8_t Mode,
360  uint8_t Key[8],
361  uint8_t *Input, uint32_t Ilength,
362  uint8_t *Output);
363 
364 ErrorStatus CRYP_DES_CBC(uint8_t Mode,
365  uint8_t Key[8],
366  uint8_t InitVectors[8],
367  uint8_t *Input,uint32_t Ilength,
368  uint8_t *Output);
369 
370 #ifdef __cplusplus
371 }
372 #endif
373 
374 #endif /*__STM32F4xx_CRYP_H */
375 
384 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
FlagStatus
Definition: stm32f4xx.h:706
ITStatus CRYP_GetITStatus(uint8_t CRYP_IT)
Checks whether the specified CRYP interrupt has occurred or not.
FunctionalState
Definition: stm32f4xx.h:708
ErrorStatus CRYP_DES_ECB(uint8_t Mode, uint8_t Key[8], uint8_t *Input, uint32_t Ilength, uint8_t *Output)
Encrypt and decrypt using DES in ECB Mode.
void CRYP_DMACmd(uint8_t CRYP_DMAReq, FunctionalState NewState)
Enables or disables the CRYP DMA interface.
void CRYP_ITConfig(uint8_t CRYP_IT, FunctionalState NewState)
Enables or disables the specified CRYP interrupts.
uint32_t CR_CurrentConfig
void CRYP_Init(CRYP_InitTypeDef *CRYP_InitStruct)
Initializes the CRYP peripheral according to the specified parameters in the CRYP_InitStruct.
uint32_t CRYP_AlgoMode
ErrorStatus CRYP_AES_CBC(uint8_t Mode, uint8_t InitVectors[16], uint8_t *Key, uint16_t Keysize, uint8_t *Input, uint32_t Ilength, uint8_t *Output)
Encrypt and decrypt using AES in CBC Mode.
void CRYP_StructInit(CRYP_InitTypeDef *CRYP_InitStruct)
Fills each CRYP_InitStruct member with its default value.
uint32_t CRYP_IV0LR
CMSIS Cortex-M4 Device Peripheral Access Layer Header File. This file contains all the peripheral reg...
CRYP context swapping structure definition.
void CRYP_FIFOFlush(void)
Flushes the IN and OUT FIFOs (that is read and write pointers of the FIFOs are reset) ...
void CRYP_PhaseConfig(uint32_t CRYP_Phase)
Configures the AES-CCM and AES-GCM phases.
uint32_t CRYP_DataOut(void)
Returns the last data entered into the output FIFO.
uint32_t CRYP_K1LR
uint32_t CRYP_IV1LR
ErrorStatus CRYP_TDES_CBC(uint8_t Mode, uint8_t Key[24], uint8_t InitVectors[8], uint8_t *Input, uint32_t Ilength, uint8_t *Output)
Encrypt and decrypt using TDES in CBC Mode.
uint32_t CRYP_DataType
enum FlagStatus ITStatus
ErrorStatus CRYP_TDES_ECB(uint8_t Mode, uint8_t Key[24], uint8_t *Input, uint32_t Ilength, uint8_t *Output)
Encrypt and decrypt using TDES in ECB Mode.
uint32_t CRYP_K2LR
uint32_t CRYP_K1RR
uint32_t CRYP_IV0RR
FlagStatus CRYP_GetFlagStatus(uint8_t CRYP_FLAG)
Checks whether the specified CRYP flag is set or not.
void CRYP_DataIn(uint32_t Data)
Writes data in the Data Input register (DIN).
uint32_t CRYP_KeySize
uint32_t CRYP_K0LR
FunctionalState CRYP_GetCmdStatus(void)
Returns whether CRYP peripheral is enabled or disabled.
ErrorStatus CRYP_AES_GCM(uint8_t Mode, uint8_t InitVectors[16], uint8_t *Key, uint16_t Keysize, uint8_t *Input, uint32_t ILength, uint8_t *Header, uint32_t HLength, uint8_t *Output, uint8_t *AuthTAG)
Encrypt and decrypt using AES in GCM Mode. The GCM and CCM modes are available only on STM32F437x Dev...
ErrorStatus CRYP_AES_CTR(uint8_t Mode, uint8_t InitVectors[16], uint8_t *Key, uint16_t Keysize, uint8_t *Input, uint32_t Ilength, uint8_t *Output)
Encrypt and decrypt using AES in CTR Mode.
void CRYP_RestoreContext(CRYP_Context *CRYP_ContextRestore)
Restores the CRYP peripheral Context.
ErrorStatus
Definition: stm32f4xx.h:711
uint32_t CRYP_K3LR
ErrorStatus CRYP_DES_CBC(uint8_t Mode, uint8_t Key[8], uint8_t InitVectors[8], uint8_t *Input, uint32_t Ilength, uint8_t *Output)
Encrypt and decrypt using DES in CBC Mode.
void CRYP_IVStructInit(CRYP_IVInitTypeDef *CRYP_IVInitStruct)
Fills each CRYP_IVInitStruct member with its default value.
CRYP Key(s) structure definition.
void CRYP_Cmd(FunctionalState NewState)
Enables or disables the CRYP peripheral.
void CRYP_KeyInit(CRYP_KeyInitTypeDef *CRYP_KeyInitStruct)
Initializes the CRYP Keys according to the specified parameters in the CRYP_KeyInitStruct.
ErrorStatus CRYP_AES_ECB(uint8_t Mode, uint8_t *Key, uint16_t Keysize, uint8_t *Input, uint32_t Ilength, uint8_t *Output)
Encrypt and decrypt using AES in ECB Mode.
uint32_t CRYP_IV1RR
ErrorStatus CRYP_AES_CCM(uint8_t Mode, uint8_t *Nonce, uint32_t NonceSize, uint8_t *Key, uint16_t Keysize, uint8_t *Input, uint32_t ILength, uint8_t *Header, uint32_t HLength, uint8_t *HBuffer, uint8_t *Output, uint8_t *AuthTAG, uint32_t TAGSize)
Encrypt and decrypt using AES in CCM Mode. The GCM and CCM modes are available only on STM32F437x Dev...
ErrorStatus CRYP_SaveContext(CRYP_Context *CRYP_ContextSave, CRYP_KeyInitTypeDef *CRYP_KeyInitStruct)
Saves the CRYP peripheral Context.
CRYP Initialization Vectors (IV) structure definition.
uint32_t CRYP_K2RR
uint32_t CRYP_AlgoDir
uint32_t CRYP_K3RR
void CRYP_KeyStructInit(CRYP_KeyInitTypeDef *CRYP_KeyInitStruct)
Fills each CRYP_KeyInitStruct member with its default value.
void CRYP_IVInit(CRYP_IVInitTypeDef *CRYP_IVInitStruct)
Initializes the CRYP Initialization Vectors(IV) according to the specified parameters in the CRYP_IVI...
uint32_t CRYP_K0RR
void CRYP_DeInit(void)
Deinitializes the CRYP peripheral registers to their default reset values.
CRYP Init structure definition.


rosflight_firmware
Author(s): Daniel Koch , James Jackson
autogenerated on Wed Jul 3 2019 19:59:26