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.c File Reference

This file provides firmware functions to manage the following functionalities of the Cryptographic processor (CRYP) peripheral: More...

#include "stm32f4xx_cryp.h"
#include "stm32f4xx_rcc.h"

Macros

#define FLAG_MASK   ((uint8_t)0x20)
 
#define MAX_TIMEOUT   ((uint16_t)0xFFFF)
 

Functions

void CRYP_DeInit (void)
 Deinitializes the CRYP peripheral registers to their default reset values. More...
 
void CRYP_Init (CRYP_InitTypeDef *CRYP_InitStruct)
 Initializes the CRYP peripheral according to the specified parameters in the CRYP_InitStruct. More...
 
void CRYP_StructInit (CRYP_InitTypeDef *CRYP_InitStruct)
 Fills each CRYP_InitStruct member with its default value. More...
 
void CRYP_KeyInit (CRYP_KeyInitTypeDef *CRYP_KeyInitStruct)
 Initializes the CRYP Keys according to the specified parameters in the CRYP_KeyInitStruct. More...
 
void CRYP_KeyStructInit (CRYP_KeyInitTypeDef *CRYP_KeyInitStruct)
 Fills each CRYP_KeyInitStruct member with its default value. More...
 
void CRYP_IVInit (CRYP_IVInitTypeDef *CRYP_IVInitStruct)
 Initializes the CRYP Initialization Vectors(IV) according to the specified parameters in the CRYP_IVInitStruct. More...
 
void CRYP_IVStructInit (CRYP_IVInitTypeDef *CRYP_IVInitStruct)
 Fills each CRYP_IVInitStruct member with its default value. More...
 
void CRYP_FIFOFlush (void)
 Flushes the IN and OUT FIFOs (that is read and write pointers of the FIFOs are reset) More...
 
void CRYP_Cmd (FunctionalState NewState)
 Enables or disables the CRYP peripheral. More...
 
void CRYP_DataIn (uint32_t Data)
 Writes data in the Data Input register (DIN). More...
 
uint32_t CRYP_DataOut (void)
 Returns the last data entered into the output FIFO. More...
 
ErrorStatus CRYP_SaveContext (CRYP_Context *CRYP_ContextSave, CRYP_KeyInitTypeDef *CRYP_KeyInitStruct)
 Saves the CRYP peripheral Context. More...
 
void CRYP_RestoreContext (CRYP_Context *CRYP_ContextRestore)
 Restores the CRYP peripheral Context. More...
 
void CRYP_DMACmd (uint8_t CRYP_DMAReq, FunctionalState NewState)
 Enables or disables the CRYP DMA interface. More...
 
void CRYP_ITConfig (uint8_t CRYP_IT, FunctionalState NewState)
 Enables or disables the specified CRYP interrupts. More...
 
ITStatus CRYP_GetITStatus (uint8_t CRYP_IT)
 Checks whether the specified CRYP interrupt has occurred or not. More...
 
FlagStatus CRYP_GetFlagStatus (uint8_t CRYP_FLAG)
 Checks whether the specified CRYP flag is set or not. More...
 

Detailed Description

This file provides firmware functions to manage the following functionalities of the Cryptographic processor (CRYP) peripheral:

Author
MCD Application Team
Version
V1.0.2
Date
05-March-2012
  • Initialization and Configuration functions
  • Data treatment functions
  • Context swapping functions
  • DMA interface function
  • Interrupts and flags management
*                               
*          ===================================================================      
*                                 How to use this driver
*          =================================================================== 
*          1. Enable the CRYP controller clock using 
*              RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_CRYP, ENABLE); function.
*
*          2. Initialise the CRYP using CRYP_Init(), CRYP_KeyInit() and if 
*             needed CRYP_IVInit(). 
*
*          3. Flush the IN and OUT FIFOs by using CRYP_FIFOFlush() function.
*
*          4. Enable the CRYP controller using the CRYP_Cmd() function. 
*
*          5. If using DMA for Data input and output transfer, 
*             Activate the needed DMA Requests using CRYP_DMACmd() function 

*          6. If DMA is not used for data transfer, use CRYP_DataIn() and 
*             CRYP_DataOut() functions to enter data to IN FIFO and get result
*             from OUT FIFO.
*
*          7. To control CRYP events you can use one of the following 
*              two methods:
*               - Check on CRYP flags using the CRYP_GetFlagStatus() function.  
*               - Use CRYP interrupts through the function CRYP_ITConfig() at 
*                 initialization phase and CRYP_GetITStatus() function into 
*                 interrupt routines in processing phase.
*       
*          8. Save and restore Cryptographic processor context using  
*             CRYP_SaveContext() and CRYP_RestoreContext() functions.     
*
*
*          ===================================================================  
*                Procedure to perform an encryption or a decryption
*          ===================================================================  
*
*      Initialization
*      ===============  
*     1. Initialize the peripheral using CRYP_Init(), CRYP_KeyInit() and 
*        CRYP_IVInit functions:
*        - Configure the key size (128-, 192- or 256-bit, in the AES only) 
*        - Enter the symmetric key 
*        - Configure the data type
*        - In case of decryption in AES-ECB or AES-CBC, you must prepare 
*          the key: configure the key preparation mode. Then Enable the CRYP 
*          peripheral using CRYP_Cmd() function: the BUSY flag is set. 
*          Wait until BUSY flag is reset : the key is prepared for decryption
*       - Configure the algorithm and chaining (the DES/TDES in ECB/CBC, the 
*          AES in ECB/CBC/CTR) 
*       - Configure the direction (encryption/decryption).
*       - Write the initialization vectors (in CBC or CTR modes only)
*
*    2. Flush the IN and OUT FIFOs using the CRYP_FIFOFlush() function
*
*
*    Basic Processing mode (polling mode) 
*    ====================================  
*    1. Enable the cryptographic processor using CRYP_Cmd() function.
*
*    2. Write the first blocks in the input FIFO (2 to 8 words) using 
*       CRYP_DataIn() function.
*
*    3. Repeat the following sequence until the complete message has been 
*       processed:
*
*       a) Wait for flag CRYP_FLAG_OFNE occurs (using CRYP_GetFlagStatus() 
*          function), then read the OUT-FIFO using CRYP_DataOut() function
*          (1 block or until the FIFO is empty)
*
*       b) Wait for flag CRYP_FLAG_IFNF occurs, (using CRYP_GetFlagStatus() 
*          function then write the IN FIFO using CRYP_DataIn() function 
*          (1 block or until the FIFO is full)
*
*    4. At the end of the processing, CRYP_FLAG_BUSY flag will be reset and 
*        both FIFOs are empty (CRYP_FLAG_IFEM is set and CRYP_FLAG_OFNE is 
*        reset). You can disable the peripheral using CRYP_Cmd() function.
*
*    Interrupts Processing mode 
*    ===========================
*    In this mode, Processing is done when the data are transferred by the 
*    CPU during interrupts.
*
*    1. Enable the interrupts CRYP_IT_INI and CRYP_IT_OUTI using 
*       CRYP_ITConfig() function.
*
*    2. Enable the cryptographic processor using CRYP_Cmd() function.
*
*    3. In the CRYP_IT_INI interrupt handler : load the input message into the 
*       IN FIFO using CRYP_DataIn() function . You can load 2 or 4 words at a 
*       time, or load data until the IN FIFO is full. When the last word of
*       the message has been entered into the IN FIFO, disable the CRYP_IT_INI 
*       interrupt (using CRYP_ITConfig() function).
*
*    4. In the CRYP_IT_OUTI interrupt handler : read the output message from 
*       the OUT FIFO using CRYP_DataOut() function. You can read 1 block (2 or 
*       4 words) at a time or read data until the FIFO is empty.
*       When the last word has been read, INIM=0, BUSY=0 and both FIFOs are 
*       empty (CRYP_FLAG_IFEM is set and CRYP_FLAG_OFNE is reset). 
*       You can disable the CRYP_IT_OUTI interrupt (using CRYP_ITConfig() 
*       function) and you can disable the peripheral using CRYP_Cmd() function.
*
*    DMA Processing mode 
*    ====================
*    In this mode, Processing is done when the DMA is used to transfer the 
*    data from/to the memory.
*
*    1. Configure the DMA controller to transfer the input data from the 
*       memory using DMA_Init() function. 
*       The transfer length is the length of the message. 
*       As message padding is not managed by the peripheral, the message 
*       length must be an entire number of blocks. The data are transferred 
*       in burst mode. The burst length is 4 words in the AES and 2 or 4 
*       words in the DES/TDES. The DMA should be configured to set an 
*       interrupt on transfer completion of the output data to indicate that 
*       the processing is finished. 
*       Refer to DMA peripheral driver for more details.  
*
*    2. Enable the cryptographic processor using CRYP_Cmd() function. 
*       Enable the DMA requests CRYP_DMAReq_DataIN and CRYP_DMAReq_DataOUT 
*       using CRYP_DMACmd() function.
*
*    3. All the transfers and processing are managed by the DMA and the 
*       cryptographic processor. The DMA transfer complete interrupt indicates 
*       that the processing is complete. Both FIFOs are normally empty and 
*       CRYP_FLAG_BUSY flag is reset.
*
*  
Attention

© COPYRIGHT 2012 STMicroelectronics

Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); You may not use this file except in compliance with the License. You may obtain a copy of the License at:

   http://www.st.com/software_license_agreement_liberty_v2

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.