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

CRYP driver modules. More...

Modules

 CRYP_Exported_Constants
 
 CRYP_Private_Functions
 

Data Structures

struct  CRYP_InitTypeDef
 CRYP Init structure definition. More...
 
struct  CRYP_KeyInitTypeDef
 CRYP Key(s) structure definition. More...
 
struct  CRYP_IVInitTypeDef
 CRYP Initialization Vectors (IV) structure definition. More...
 
struct  CRYP_Context
 CRYP context swapping structure definition. More...
 

Macros

#define FLAG_MASK   ((uint8_t)0x20)
 
#define MAX_TIMEOUT   ((uint16_t)0xFFFF)
 
#define AESBUSY_TIMEOUT   ((uint32_t) 0x00010000)
 
#define DESBUSY_TIMEOUT   ((uint32_t) 0x00010000)
 
#define TDESBUSY_TIMEOUT   ((uint32_t) 0x00010000)
 

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_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...
 
void CRYP_FIFOFlush (void)
 Flushes the IN and OUT FIFOs (that is read and write pointers of the FIFOs are reset) 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...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 

Detailed Description

CRYP driver modules.

Function Documentation

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.

Parameters
Mode,:encryption or decryption Mode. This parameter can be one of the following values:
  • MODE_ENCRYPT: Encryption
  • MODE_DECRYPT: Decryption
InitVectors,:Initialisation Vectors used for AES algorithm.
Key,:Key used for AES algorithm.
Keysize,:length of the Key, must be a 128, 192 or 256.
Input,:pointer to the Input buffer.
Ilength,:length of the Input buffer, must be a multiple of 16.
Output,:pointer to the returned buffer.
Return values
AnErrorStatus enumeration value:
  • SUCCESS: Operation done
  • ERROR: Operation failed
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.

Parameters
Mode,:encryption or decryption Mode. This parameter can be one of the following values:
  • MODE_ENCRYPT: Encryption
  • MODE_DECRYPT: Decryption
InitVectors,:Initialisation Vectors used for AES algorithm.
Key,:Key used for AES algorithm.
Keysize,:length of the Key, must be a 128, 192 or 256.
Input,:pointer to the Input buffer.
Ilength,:length of the Input buffer, must be a multiple of 16.
Output,:pointer to the returned buffer.
Return values
AnErrorStatus enumeration value:
  • SUCCESS: Operation done
  • ERROR: Operation failed
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.

Parameters
Mode,:encryption or decryption Mode. This parameter can be one of the following values:
  • MODE_ENCRYPT: Encryption
  • MODE_DECRYPT: Decryption
Key,:Key used for AES algorithm.
Keysize,:length of the Key, must be a 128, 192 or 256.
Input,:pointer to the Input buffer.
Ilength,:length of the Input buffer, must be a multiple of 16.
Output,:pointer to the returned buffer.
Return values
AnErrorStatus enumeration value:
  • SUCCESS: Operation done
  • ERROR: Operation failed
void CRYP_Cmd ( FunctionalState  NewState)

Enables or disables the CRYP peripheral.

Parameters
NewState,:new state of the CRYP peripheral. This parameter can be: ENABLE or DISABLE.
Return values
None
void CRYP_DataIn ( uint32_t  Data)

Writes data in the Data Input register (DIN).

Note
After the DIN register has been read once or several times, the FIFO must be flushed (using CRYP_FIFOFlush() function).
Parameters
Data,:data to write in Data Input register
Return values
None
uint32_t CRYP_DataOut ( void  )

Returns the last data entered into the output FIFO.

Parameters
None
Return values
Lastdata entered into the output FIFO.
void CRYP_DeInit ( void  )

Deinitializes the CRYP peripheral registers to their default reset values.

Parameters
None
Return values
None
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.

Parameters
Mode,:encryption or decryption Mode. This parameter can be one of the following values:
  • MODE_ENCRYPT: Encryption
  • MODE_DECRYPT: Decryption
Key,:Key used for DES algorithm.
InitVectors,:Initialisation Vectors used for DES algorithm.
Ilength,:length of the Input buffer, must be a multiple of 8.
Input,:pointer to the Input buffer.
Output,:pointer to the returned buffer.
Return values
AnErrorStatus enumeration value:
  • SUCCESS: Operation done
  • ERROR: Operation failed
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.

Parameters
Mode,:encryption or decryption Mode. This parameter can be one of the following values:
  • MODE_ENCRYPT: Encryption
  • MODE_DECRYPT: Decryption
Key,:Key used for DES algorithm.
Ilength,:length of the Input buffer, must be a multiple of 8.
Input,:pointer to the Input buffer.
Output,:pointer to the returned buffer.
Return values
AnErrorStatus enumeration value:
  • SUCCESS: Operation done
  • ERROR: Operation failed
void CRYP_DMACmd ( uint8_t  CRYP_DMAReq,
FunctionalState  NewState 
)

Enables or disables the CRYP DMA interface.

Parameters
CRYP_DMAReq,:specifies the CRYP DMA transfer request to be enabled or disabled. This parameter can be any combination of the following values:
  • CRYP_DMAReq_DataOUT: DMA for outgoing(Tx) data transfer
  • CRYP_DMAReq_DataIN: DMA for incoming(Rx) data transfer
NewState,:new state of the selected CRYP DMA transfer request. This parameter can be: ENABLE or DISABLE.
Return values
None
void CRYP_FIFOFlush ( void  )

Flushes the IN and OUT FIFOs (that is read and write pointers of the FIFOs are reset)

Note
The FIFOs must be flushed only when BUSY flag is reset.
Parameters
None
Return values
None
FlagStatus CRYP_GetFlagStatus ( uint8_t  CRYP_FLAG)

Checks whether the specified CRYP flag is set or not.

Parameters
CRYP_FLAG,:specifies the CRYP flag to check. This parameter can be one of the following values:
  • CRYP_FLAG_IFEM: Input FIFO Empty flag.
  • CRYP_FLAG_IFNF: Input FIFO Not Full flag.
  • CRYP_FLAG_OFNE: Output FIFO Not Empty flag.
  • CRYP_FLAG_OFFU: Output FIFO Full flag.
  • CRYP_FLAG_BUSY: Busy flag.
  • CRYP_FLAG_OUTRIS: Output FIFO raw interrupt flag.
  • CRYP_FLAG_INRIS: Input FIFO raw interrupt flag.
Return values
Thenew state of CRYP_FLAG (SET or RESET).
ITStatus CRYP_GetITStatus ( uint8_t  CRYP_IT)

Checks whether the specified CRYP interrupt has occurred or not.

Note
This function checks the status of the masked interrupt (i.e the interrupt should be previously enabled).
Parameters
CRYP_IT,:specifies the CRYP (masked) interrupt source to check. This parameter can be one of the following values:
  • CRYP_IT_INI: Input FIFO interrupt
  • CRYP_IT_OUTI: Output FIFO interrupt
Return values
Thenew state of CRYP_IT (SET or RESET).
void CRYP_Init ( CRYP_InitTypeDef CRYP_InitStruct)

Initializes the CRYP peripheral according to the specified parameters in the CRYP_InitStruct.

Parameters
CRYP_InitStruct,:pointer to a CRYP_InitTypeDef structure that contains the configuration information for the CRYP peripheral.
Return values
None
void CRYP_ITConfig ( uint8_t  CRYP_IT,
FunctionalState  NewState 
)

Enables or disables the specified CRYP interrupts.

Parameters
CRYP_IT,:specifies the CRYP interrupt source to be enabled or disabled. This parameter can be any combination of the following values:
  • CRYP_IT_INI: Input FIFO interrupt
  • CRYP_IT_OUTI: Output FIFO interrupt
NewState,:new state of the specified CRYP interrupt. This parameter can be: ENABLE or DISABLE.
Return values
None
void CRYP_IVInit ( CRYP_IVInitTypeDef CRYP_IVInitStruct)

Initializes the CRYP Initialization Vectors(IV) according to the specified parameters in the CRYP_IVInitStruct.

Parameters
CRYP_IVInitStruct,:pointer to a CRYP_IVInitTypeDef structure that contains the configuration information for the CRYP Initialization Vectors(IV).
Return values
None
void CRYP_IVStructInit ( CRYP_IVInitTypeDef CRYP_IVInitStruct)

Fills each CRYP_IVInitStruct member with its default value.

Parameters
CRYP_IVInitStruct,:pointer to a CRYP_IVInitTypeDef Initialization Vectors(IV) structure which will be initialized.
Return values
None
void CRYP_KeyInit ( CRYP_KeyInitTypeDef CRYP_KeyInitStruct)

Initializes the CRYP Keys according to the specified parameters in the CRYP_KeyInitStruct.

Parameters
CRYP_KeyInitStruct,:pointer to a CRYP_KeyInitTypeDef structure that contains the configuration information for the CRYP Keys.
Return values
None
void CRYP_KeyStructInit ( CRYP_KeyInitTypeDef CRYP_KeyInitStruct)

Fills each CRYP_KeyInitStruct member with its default value.

Parameters
CRYP_KeyInitStruct,:pointer to a CRYP_KeyInitTypeDef structure which will be initialized.
Return values
None
void CRYP_RestoreContext ( CRYP_Context CRYP_ContextRestore)

Restores the CRYP peripheral Context.

Note
Since teh DMA transfer is stopped in CRYP_SaveContext() function, after restoring the context, you have to enable the DMA again (if the DMA was previously used).
Parameters
CRYP_ContextRestore,:pointer to a CRYP_Context structure that contains the repository for saved context.
Note
The data that were saved during context saving must be rewrited into the IN FIFO.
Return values
None
ErrorStatus CRYP_SaveContext ( CRYP_Context CRYP_ContextSave,
CRYP_KeyInitTypeDef CRYP_KeyInitStruct 
)

Saves the CRYP peripheral Context.

Note
This function stops DMA transfer before to save the context. After restoring the context, you have to enable the DMA again (if the DMA was previously used).
Parameters
CRYP_ContextSave,:pointer to a CRYP_Context structure that contains the repository for current context.
CRYP_KeyInitStruct,:pointer to a CRYP_KeyInitTypeDef structure that contains the configuration information for the CRYP Keys.
Return values
None
void CRYP_StructInit ( CRYP_InitTypeDef CRYP_InitStruct)

Fills each CRYP_InitStruct member with its default value.

Parameters
CRYP_InitStruct,:pointer to a CRYP_InitTypeDef structure which will be initialized.
Return values
None
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.

Parameters
Mode,:encryption or decryption Mode. This parameter can be one of the following values:
  • MODE_ENCRYPT: Encryption
  • MODE_DECRYPT: Decryption
Key,:Key used for TDES algorithm.
InitVectors,:Initialisation Vectors used for TDES algorithm.
Input,:pointer to the Input buffer.
Ilength,:length of the Input buffer, must be a multiple of 8.
Output,:pointer to the returned buffer.
Return values
AnErrorStatus enumeration value:
  • SUCCESS: Operation done
  • ERROR: Operation failed
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.

Parameters
Mode,:encryption or decryption Mode. This parameter can be one of the following values:
  • MODE_ENCRYPT: Encryption
  • MODE_DECRYPT: Decryption
Key,:Key used for TDES algorithm.
Ilength,:length of the Input buffer, must be a multiple of 8.
Input,:pointer to the Input buffer.
Output,:pointer to the returned buffer.
Return values
AnErrorStatus enumeration value:
  • SUCCESS: Operation done
  • ERROR: Operation failed