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

HAL HASH Extension Driver

UM1725

28 HAL HASH Extension Driver

28.1HASHEx Firmware driver API description

28.1.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_HMACEx_SHA224_Start())

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_HMACEx_SH224_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: 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_HASHEx_SHA224_Start()

b.Interrupt mode: encryption and decryption APIs are not blocking functions i.e. they process the data under interrupt e.g. HAL_HASHEx_SHA224_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_HASHEx_SHA224_Start_DMA()

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_HASHEx_SHA224_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_HASHEx_SHA224_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_HASHEx_SHA224_Start_DMA(). After that, call the finish function in order to get the digest value e.g. HAL_HASHEx_SHA224_Finish()

376/900

DOCID025834 Rev 2

UM1725

HAL HASH Extension Driver

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

28.1.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:

SHA224

SHA256

This section contains the following APIs:

HAL_HASHEx_SHA224_Start()

HAL_HASHEx_SHA256_Start()

HAL_HASHEx_SHA224_Accumulate()

HAL_HASHEx_SHA256_Accumulate()

28.1.3HMAC processing using polling mode functions

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

SHA224

SHA256

This section contains the following APIs:

HAL_HMACEx_SHA224_Start()

HAL_HMACEx_SHA256_Start()

28.1.4HASH processing using interrupt functions

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

SHA224

SHA256

This section contains the following APIs:

HAL_HASHEx_SHA224_Start_IT()

HAL_HASHEx_SHA256_Start_IT()

HAL_HASHEx_IRQHandler()

28.1.5HASH processing using DMA functions

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

SHA224

SHA256

This section contains the following APIs:

HAL_HASHEx_SHA224_Start_DMA()

HAL_HASHEx_SHA224_Finish()

HAL_HASHEx_SHA256_Start_DMA()

HAL_HASHEx_SHA256_Finish()

DOCID025834 Rev 2

377/900

HAL HASH Extension Driver

UM1725

28.1.6HMAC processing using DMA functions

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

SHA224

SHA256

This section contains the following APIs:

HAL_HMACEx_SHA224_Start_DMA()

HAL_HMACEx_SHA256_Start_DMA()

28.1.7HAL_HASHEx_SHA224_Start

Function Name

HAL_StatusTypeDef HAL_HASHEx_SHA224_Start

 

(HASH_HandleTypeDef * hhash, uint8_t * pInBuffer, uint32_t

 

Size, uint8_t * pOutBuffer, uint32_t Timeout)

Function Description

Initializes the HASH peripheral in SHA224 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

 

 

28 bytes.

 

 

Timeout: Specify Timeout value

Return values

 

HAL status

28.1.8HAL_HASHEx_SHA256_Start

Function Name

HAL_StatusTypeDef HAL_HASHEx_SHA256_Start

 

(HASH_HandleTypeDef * hhash, uint8_t * pInBuffer, uint32_t

 

Size, uint8_t * pOutBuffer, uint32_t Timeout)

Function Description

Initializes the HASH peripheral in SHA256 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

 

 

32 bytes.

 

 

Timeout: Specify Timeout value

Return values

 

HAL status

28.1.9HAL_HASHEx_SHA224_Accumulate

Function Name

HAL_StatusTypeDef HAL_HASHEx_SHA224_Accumulate

 

(HASH_HandleTypeDef * hhash, uint8_t * pInBuffer, uint32_t

 

Size)

378/900

DOCID025834 Rev 2

UM1725

 

HAL HASH Extension Driver

Function Description

Initializes the HASH peripheral in SHA224 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.

Return values

 

HAL status

28.1.10HAL_HASHEx_SHA256_Accumulate

Function Name

HAL_StatusTypeDef HAL_HASHEx_SHA256_Accumulate

 

(HASH_HandleTypeDef * hhash, uint8_t * pInBuffer, uint32_t

 

Size)

Function Description

Initializes the HASH peripheral in SHA256 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.

Return values

 

HAL status

28.1.11HAL_HMACEx_SHA224_Start

Function Name

HAL_StatusTypeDef HAL_HMACEx_SHA224_Start

 

(HASH_HandleTypeDef * hhash, uint8_t * pInBuffer, uint32_t

 

Size, uint8_t * pOutBuffer, uint32_t Timeout)

Function Description

Initializes the HASH peripheral in HMAC SHA224 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.

 

Timeout: Timeout value

Return values

 

HAL status

28.1.12HAL_HMACEx_SHA256_Start

Function Name

HAL_StatusTypeDef HAL_HMACEx_SHA256_Start

 

 

(HASH_HandleTypeDef * hhash, uint8_t * pInBuffer, uint32_t

 

Size, uint8_t * pOutBuffer, uint32_t Timeout)

 

Function Description

Initializes the HASH peripheral in HMAC SHA256 mode then

 

processes pInBuffer.

 

Parameters

hhash: pointer to a HASH_HandleTypeDef structure that

 

contains the configuration information for HASH module

 

DOCID025834 Rev 2

379/900

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