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

HAL HASH Generic Driver

UM1725

__IO uint32_t HASH_HandleTypeDef::HashBuffSize

Size of buffer to be processed

__IO uint32_t HASH_HandleTypeDef::HashInCount

Counter of inputed data

__IO uint32_t HASH_HandleTypeDef::HashITCounter

Counter of issued interrupts

HAL_StatusTypeDef HASH_HandleTypeDef::Status

HASH peripheral status

HAL_HASHPhaseTypeDef HASH_HandleTypeDef::Phase

HASH peripheral phase

DMA_HandleTypeDef* HASH_HandleTypeDef::hdmain

HASH In DMA handle parameters

HAL_LockTypeDef HASH_HandleTypeDef::Lock

HASH locking object

__IO HAL_HASH_STATETypeDef HASH_HandleTypeDef::State

HASH peripheral state

27.2HASH Firmware driver API description

27.2.1How to use this driver

The HASH HAL driver can be used as follows:

1.Initialize the HASH low level resources by implementing the HAL_HASH_MspInit():

a.Enable the HASH interface clock using __HAL_RCC_HASH_CLK_ENABLE()

b.In case of using processing APIs based on interrupts (e.g.

HAL_HMAC_SHA1_Start_IT())

Configure the HASH interrupt priority using HAL_NVIC_SetPriority()

Enable the HASH IRQ handler using HAL_NVIC_EnableIRQ()

In HASH IRQ handler, call HAL_HASH_IRQHandler() c. In case of using DMA to control data transfer (e.g.

HAL_HMAC_SHA1_Start_DMA())

Enable the DMAx interface clock using __DMAx_CLK_ENABLE()

Configure and enable one DMA stream one for managing data transfer from memory to peripheral (input stream). Managing data transfer from peripheral to memory can be performed only using CPU

Associate the initialized DMA handle to the HASH DMA handle using

__HAL_LINKDMA()

Configure the priority and enable the NVIC for the transfer complete interrupt on the DMA Stream using HAL_NVIC_SetPriority() and HAL_NVIC_EnableIRQ()

2.Initialize the HASH HAL using HAL_HASH_Init(). This function configures mainly:

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

b.For HMAC, the encryption key.

c.For HMAC, the key size used for encryption.

3.Three processing functions are available:

a.Polling mode: processing APIs are blocking functions i.e. they process the data and wait till the digest computation is finished e.g. HAL_HASH_SHA1_Start()

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

c.DMA mode: processing APIs are not blocking functions and the CPU is not used for data transfer i.e. the data transfer is ensured by DMA e.g. HAL_HASH_SHA1_Start_DMA()

360/900

DOCID025834 Rev 2

UM1725

HAL HASH Generic Driver

4.When the processing function is called at first time after HAL_HASH_Init() the HASH peripheral is initialized and processes the buffer in input. After that, the digest computation is started. When processing multi-buffer use the accumulate function to write the data in the peripheral without starting the digest computation. In last buffer use the start function to input the last buffer ans start the digest computation.

a.e.g. HAL_HASH_SHA1_Accumulate() : write 1st data buffer in the peripheral without starting the digest computation

b.write (n-1)th data buffer in the peripheral without starting the digest computation

c.HAL_HASH_SHA1_Start() : write (n)th data buffer in the peripheral and start the digest computation

5.In HMAC mode, there is no Accumulate API. Only Start API is available.

6.In case of using DMA, call the DMA start processing e.g. HAL_HASH_SHA1_Start_DMA(). After that, call the finish function in order to get the digest value e.g. HAL_HASH_SHA1_Finish()

7.Call HAL_HASH_DeInit() to deinitialize the HASH peripheral.

27.2.2HASH processing using polling mode functions

This section provides functions allowing to calculate in polling mode the hash value using one of the following algorithms:

MD5

SHA1

This section contains the following APIs:

HAL_HASH_MD5_Start()

HAL_HASH_MD5_Accumulate()

HAL_HASH_SHA1_Start()

HAL_HASH_SHA1_Accumulate()

27.2.3HASH processing using interrupt mode functions

This section provides functions allowing to calculate in interrupt mode the hash value using one of the following algorithms:

MD5

SHA1

This section contains the following APIs:

HAL_HASH_MD5_Start_IT()

HAL_HASH_SHA1_Start_IT()

HAL_HASH_IRQHandler()

HAL_HMAC_SHA1_Start()

HAL_HMAC_MD5_Start()

27.2.4HASH processing using DMA mode functions

This section provides functions allowing to calculate in DMA mode the hash value using one of the following algorithms:

MD5

SHA1

This section contains the following APIs:

HAL_HASH_MD5_Start_DMA()

HAL_HASH_MD5_Finish()

HAL_HASH_SHA1_Start_DMA()

DOCID025834 Rev 2

361/900

HAL HASH Generic Driver

UM1725

HAL_HASH_SHA1_Finish()

HAL_HASH_SHA1_Start_IT()

HAL_HASH_MD5_Start_IT()

27.2.5HMAC processing using polling mode functions

This section provides functions allowing to calculate in polling mode the HMAC value using one of the following algorithms:

MD5

SHA1

This section contains the following APIs:

HAL_HMAC_MD5_Start()

HAL_HMAC_SHA1_Start()

HAL_HASH_SHA1_Start_DMA()

HAL_HASH_SHA1_Finish()

HAL_HASH_MD5_Start_DMA()

HAL_HASH_MD5_Finish()

27.2.6HMAC processing using DMA mode functions

This section provides functions allowing to calculate in DMA mode the HMAC value using one of the following algorithms:

MD5

SHA1

This section contains the following APIs:

HAL_HMAC_MD5_Start_DMA()

HAL_HMAC_SHA1_Start_DMA()

27.2.7Peripheral State functions

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

This section contains the following APIs:

HAL_HASH_GetState()

HAL_HASH_IRQHandler()

27.2.8Initialization and de-initialization functions

This section provides functions allowing to:

Initialize the HASH according to the specified parameters in the HASH_InitTypeDef and creates the associated handle.

DeInitialize the HASH peripheral.

Initialize the HASH MSP.

DeInitialize HASH MSP.

This section contains the following APIs:

HAL_HASH_Init()

HAL_HASH_DeInit()

HAL_HASH_MspInit()

HAL_HASH_MspDeInit()

HAL_HASH_InCpltCallback()

HAL_HASH_ErrorCallback()

362/900

DOCID025834 Rev 2

UM1725

HAL HASH Generic Driver

HAL_HASH_DgstCpltCallback()

27.2.9HAL_HASH_MD5_Start

Function Name

HAL_StatusTypeDef HAL_HASH_MD5_Start

 

(HASH_HandleTypeDef * hhash, uint8_t * pInBuffer, uint32_t

 

Size, uint8_t * pOutBuffer, uint32_t Timeout)

Function Description

Initializes the HASH peripheral in MD5 mode then processes

 

pInBuffer.

Parameters

 

hhash: pointer to a HASH_HandleTypeDef structure that

 

 

contains the configuration information for HASH module

 

 

pInBuffer: Pointer to the input buffer (buffer to be hashed).

 

 

Size: Length of the input buffer in bytes. If the Size is multiple

 

 

of 64 bytes, appending the input buffer is possible. If the Size

 

 

is not multiple of 64 bytes, the padding is managed by

 

 

hardware and appending the input buffer is no more possible.

 

pOutBuffer: Pointer to the computed digest. Its size must be

 

 

16 bytes.

 

 

Timeout: Timeout value

Return values

 

HAL status

27.2.10HAL_HASH_MD5_Accumulate

Function Name

HAL_StatusTypeDef HAL_HASH_MD5_Accumulate

 

(HASH_HandleTypeDef * hhash, uint8_t * pInBuffer, uint32_t

 

Size)

Function Description

Initializes the HASH peripheral in MD5 mode then writes the

 

pInBuffer.

Parameters

 

hhash: pointer to a HASH_HandleTypeDef structure that

 

 

contains the configuration information for HASH module

 

 

pInBuffer: Pointer to the input buffer (buffer to be hashed).

 

 

Size: Length of the input buffer in bytes. If the Size is multiple

 

 

of 64 bytes, appending the input buffer is possible. If the Size

 

 

is not multiple of 64 bytes, the padding is managed by

 

 

hardware and appending the input buffer is no more possible.

Return values

 

HAL status

27.2.11HAL_HASH_SHA1_Start

Function Name

HAL_StatusTypeDef HAL_HASH_SHA1_Start

 

 

(HASH_HandleTypeDef * hhash, uint8_t * pInBuffer, uint32_t

 

Size, uint8_t * pOutBuffer, uint32_t Timeout)

 

Function Description

Initializes the HASH peripheral in SHA1 mode then processes

 

pInBuffer.

 

Parameters

hhash: pointer to a HASH_HandleTypeDef structure that

 

contains the configuration information for HASH module

 

pInBuffer: Pointer to the input buffer (buffer to be hashed).

 

Size: Length of the input buffer in bytes. If the Size is not

 

multiple of 64 bytes, the padding is managed by hardware.

 

pOutBuffer: Pointer to the computed digest. Its size must be

 

20 bytes.

 

 

DOCID025834 Rev 2

363/900

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