Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
cubexHal.pdf
Скачиваний:
110
Добавлен:
10.02.2016
Размер:
16.16 Mб
Скачать

UM1725

HAL CRYP Generic Driver

CRYP_TypeDef * Instance

CRYP_InitTypeDef Init

uint8_t * pCrypInBuffPtr

uint8_t * pCrypOutBuffPtr

__IO uint16_t CrypInCount

__IO uint16_t CrypOutCount

HAL_StatusTypeDef Status

HAL_PhaseTypeDef Phase

DMA_HandleTypeDef * hdmain

DMA_HandleTypeDef * hdmaout

HAL_LockTypeDef Lock

__IO HAL_CRYP_STATETypeDef State

Field Documentation

CRYP_TypeDef* CRYP_HandleTypeDef::Instance

CRYP registers base address

CRYP_InitTypeDef CRYP_HandleTypeDef::Init

CRYP required parameters

uint8_t* CRYP_HandleTypeDef::pCrypInBuffPtr

Pointer to CRYP processing (encryption, decryption,...) buffer

uint8_t* CRYP_HandleTypeDef::pCrypOutBuffPtr

Pointer to CRYP processing (encryption, decryption,...) buffer

__IO uint16_t CRYP_HandleTypeDef::CrypInCount

Counter of inputed data

__IO uint16_t CRYP_HandleTypeDef::CrypOutCount

Counter of outputted data

HAL_StatusTypeDef CRYP_HandleTypeDef::Status

CRYP peripheral status

HAL_PhaseTypeDef CRYP_HandleTypeDef::Phase

CRYP peripheral phase

DMA_HandleTypeDef* CRYP_HandleTypeDef::hdmain

CRYP In DMA handle parameters

DMA_HandleTypeDef* CRYP_HandleTypeDef::hdmaout

CRYP Out DMA handle parameters

HAL_LockTypeDef CRYP_HandleTypeDef::Lock

CRYP locking object

__IO HAL_CRYP_STATETypeDef CRYP_HandleTypeDef::State

CRYP peripheral state

10.2CRYP Firmware driver API description

10.2.1How to use this driver

The CRYP HAL driver can be used as follows:

1.Initialize the CRYP low level resources by implementing the HAL_CRYP_MspInit():

a.Enable the CRYP interface clock using __HAL_RCC_CRYP_CLK_ENABLE()

b.In case of using interrupts (e.g. HAL_CRYP_AESECB_Encrypt_IT())

Configure the CRYP interrupt priority using HAL_NVIC_SetPriority()

Enable the CRYP IRQ handler using HAL_NVIC_EnableIRQ()

In CRYP IRQ handler, call HAL_CRYP_IRQHandler()

DOCID025834 Rev 2

173/900

HAL CRYP Generic Driver

UM1725

c. In case of using DMA to control data transfer (e.g. HAL_CRYP_AESECB_Encrypt_DMA())

Enable the DMAx interface clock using __DMAx_CLK_ENABLE()

Configure and enable two DMA streams one for managing data transfer from memory to peripheral (input stream) and another stream for managing data transfer from peripheral to memory (output stream)

Associate the initialized DMA handle to the CRYP DMA handle using

__HAL_LINKDMA()

Configure the priority and enable the NVIC for the transfer complete interrupt on the two DMA Streams. The output stream should have higher priority than the input stream HAL_NVIC_SetPriority() and HAL_NVIC_EnableIRQ()

2.Initialize the CRYP HAL using HAL_CRYP_Init(). This function configures mainly:

a.The data type: 1-bit, 8-bit, 16-bit and 32-bit

b.The key size: 128, 192 and 256. This parameter is relevant only for AES

c.The encryption/decryption key. It's size depends on the algorithm used for encryption/decryption

d.The initialization vector (counter). It is not used ECB mode.

3.Three processing (encryption/decryption) functions are available:

a.Polling mode: encryption and decryption APIs are blocking functions i.e. they process the data and wait till the processing is finished, e.g. HAL_CRYP_AESCBC_Encrypt()

b.Interrupt mode: encryption and decryption APIs are not blocking functions i.e. they process the data under interrupt, e.g. HAL_CRYP_AESCBC_Encrypt_IT()

c.DMA mode: encryption and decryption APIs are not blocking functions i.e. the data transfer is ensured by DMA, e.g. HAL_CRYP_AESCBC_Encrypt_DMA()

4.When the processing function is called at first time after HAL_CRYP_Init() the CRYP peripheral is initialized and processes the buffer in input. At second call, the processing function performs an append of the already processed buffer. When a new data block is to be processed, call HAL_CRYP_Init() then the processing function.

5.Call HAL_CRYP_DeInit() to deinitialize the CRYP peripheral.

10.2.2Initialization and de-initialization functions

This section provides functions allowing to:

Initialize the CRYP according to the specified parameters in the CRYP_InitTypeDef and creates the associated handle

DeInitialize the CRYP peripheral

Initialize the CRYP MSP

DeInitialize CRYP MSP

This section contains the following APIs:

HAL_CRYP_Init()

HAL_CRYP_DeInit()

HAL_CRYP_MspInit()

HAL_CRYP_MspDeInit()

10.2.3AES processing functions

This section provides functions allowing to:

Encrypt plaintext using AES-128/192/256 using chaining modes

Decrypt cyphertext using AES-128/192/256 using chaining modes

Three processing functions are available:

174/900

DOCID025834 Rev 2

UM1725

HAL CRYP Generic Driver

 

Polling mode

 

Interrupt mode

 

DMA mode

This section contains the following APIs:

HAL_CRYP_AESECB_Encrypt()

HAL_CRYP_AESCBC_Encrypt()

HAL_CRYP_AESCTR_Encrypt()

HAL_CRYP_AESECB_Decrypt()

HAL_CRYP_AESCBC_Decrypt()

HAL_CRYP_AESCTR_Decrypt()

HAL_CRYP_AESECB_Encrypt_IT()

HAL_CRYP_AESCBC_Encrypt_IT()

HAL_CRYP_AESCTR_Encrypt_IT()

HAL_CRYP_AESECB_Decrypt_IT()

HAL_CRYP_AESCBC_Decrypt_IT()

HAL_CRYP_AESCTR_Decrypt_IT()

HAL_CRYP_AESECB_Encrypt_DMA()

HAL_CRYP_AESCBC_Encrypt_DMA()

HAL_CRYP_AESCTR_Encrypt_DMA()

HAL_CRYP_AESECB_Decrypt_DMA()

HAL_CRYP_AESCBC_Decrypt_DMA()

HAL_CRYP_AESCTR_Decrypt_DMA()

10.2.4DES processing functions

This section provides functions allowing to:

Encrypt plaintext using DES using ECB or CBC chaining modes

Decrypt cyphertext using ECB or CBC chaining modes

Three processing functions are available:

Polling mode

Interrupt mode

DMA mode

This section contains the following APIs:

HAL_CRYP_DESECB_Encrypt()

HAL_CRYP_DESECB_Decrypt()

HAL_CRYP_DESCBC_Encrypt()

HAL_CRYP_DESCBC_Decrypt()

HAL_CRYP_DESECB_Encrypt_IT()

HAL_CRYP_DESCBC_Encrypt_IT()

HAL_CRYP_DESECB_Decrypt_IT()

HAL_CRYP_DESCBC_Decrypt_IT()

HAL_CRYP_DESECB_Encrypt_DMA()

HAL_CRYP_DESCBC_Encrypt_DMA()

HAL_CRYP_DESECB_Decrypt_DMA()

HAL_CRYP_DESCBC_Decrypt_DMA()

10.2.5TDES processing functions

This section provides functions allowing to:

Encrypt plaintext using TDES based on ECB or CBC chaining modes

DOCID025834 Rev 2

175/900

HAL CRYP Generic Driver

UM1725

Decrypt cyphertext using TDES based on ECB or CBC chaining modes

 

Three processing functions are available:

 

 

Polling mode

 

 

Interrupt mode

 

 

DMA mode

 

This section contains the following APIs:

HAL_CRYP_TDESECB_Encrypt()

HAL_CRYP_TDESECB_Decrypt()

HAL_CRYP_TDESCBC_Encrypt()

HAL_CRYP_TDESCBC_Decrypt()

HAL_CRYP_TDESECB_Encrypt_IT()

HAL_CRYP_TDESCBC_Encrypt_IT()

HAL_CRYP_TDESECB_Decrypt_IT()

HAL_CRYP_TDESCBC_Decrypt_IT()

HAL_CRYP_TDESECB_Encrypt_DMA()

HAL_CRYP_TDESCBC_Encrypt_DMA()

HAL_CRYP_TDESECB_Decrypt_DMA()

HAL_CRYP_TDESCBC_Decrypt_DMA()

10.2.6DMA callback functions

This section provides DMA callback functions:

DMA Input data transfer complete

DMA Output data transfer complete

DMA error

This section contains the following APIs:

HAL_CRYP_InCpltCallback()

HAL_CRYP_OutCpltCallback()

HAL_CRYP_ErrorCallback()

10.2.7CRYP IRQ handler management

This section provides CRYP IRQ handler function.

This section contains the following APIs:

HAL_CRYP_IRQHandler()

10.2.8Peripheral State functions

This subsection permits to get in run-time the status of the peripheral.

This section contains the following APIs:

HAL_CRYP_GetState()

10.2.9HAL_CRYP_Init

Function Name

HAL_StatusTypeDef HAL_CRYP_Init (CRYP_HandleTypeDef *

 

hcryp)

Function Description

Initializes the CRYP according to the specified parameters in the

 

CRYP_InitTypeDef and creates the associated handle.

176/900

DOCID025834 Rev 2

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]