STM32 Devcoons Framework – Use the lib_crypto module (3)

S

In this post, we will add the lib_crypto module to our project. As all the module, it should be ‘automatically ‘ recognized by the STM32 Devcoons Framework, thus we will be able to use its functions directly. So, let’s start!

devcoons/stm32-lib-crypto (github.com)

Add the module by following the tutorial: 
https://devcoons.com/stm32-devcoons-framework-add-a-module-2

Enable the library features

This library contains a configuration file which allow us to enable some of its features. In this step we have to copy the .example file in the /BaseCode/Libraries/ folder, remove the .example extension and enable whatever we would like to use. Check the screenshot below:

Use the library

To use the library, let’s go to the file /AppCode/tsk_app.c and replace it with the following.

/*!
	@file   tsk_app.c
	@brief  <brief description here>
	@t.odo	-
	---------------------------------------------------------------------------
*/
/******************************************************************************
* Preprocessor Definitions & Macros
******************************************************************************/

/******************************************************************************
* Includes
******************************************************************************/

#include "tsk_app.h"

/******************************************************************************
* Enumerations, structures & Variables
******************************************************************************/

static osThreadId_t tsk_app_handle;

const osThreadAttr_t tsk_app_attrs =
{
	.name = "TskApp",
	.priority = (osPriority_t) osPriorityLow5,
	.stack_size = 2048
};

static TickType_t x_last_waketime;

///////////////////////////////////////////////////////////////////////////////

static uint8_t buffer[256];
static uint16_t res_crc16_ccitt;
static uint16_t res_crc16_ibm;
static uint8_t res_checksum8;

/******************************************************************************
* Declaration | Static Functions
******************************************************************************/

/******************************************************************************
* Definition  | Static Functions
******************************************************************************/

/******************************************************************************
* Definition  | Public Functions
******************************************************************************/

i_status tsk_app_start()
{
	tsk_app_handle = osThreadNew(tsk_app, NULL, &tsk_app_attrs);
	return I_OK;
}

/******************************************************************************
* -- Main Task
******************************************************************************/	

void tsk_app(void *argument)
{
	#ifdef HAL_IWDG_MODULE_ENABLED
	HAL_IWDG_Refresh(&hiwdg);
	#endif

	for(int i=0;i<256;i++)
		buffer[i] = (uint8_t)(i&0xFF);

	res_crc16_ccitt = crc16_ccitt(0, buffer, 256);
	res_crc16_ibm = crc16_ibm(0, buffer, 256);
	res_checksum8 = checksum_8(buffer, 256);

	while(1)
	{
		vTaskDelayUntil( &x_last_waketime, 5);
	}
}

/******************************************************************************
* EOF - NO CODE AFTER THIS LINE
******************************************************************************/

Other functions which can be used are:

void hash_sha1(uint8_t* out, const uint8_t* in, size_t in_len);
void hash_sha2_256(uint8_t* out, const uint8_t* in, size_t in_len);
void hash_sha2_512(uint8_t* out, const uint8_t* in, size_t in_len);
void hash_sha3_256(uint8_t* out, const uint8_t* in, size_t in_len);
void hash_sha3_512(uint8_t* out, const uint8_t* in, size_t in_len);
void hash_keccak_256(uint8_t* out, const uint8_t* in, size_t in_len);
void hash_keccak_512(uint8_t* out, const uint8_t* in, size_t in_len);
void hash_blake256(uint8_t* out, const uint8_t* in, size_t in_len);
void hash_ripemd160(uint8_t* out, const uint8_t* in, size_t in_len);
void hash_hmac_sha512(uint8_t* out, const uint8_t* in, size_t in_len,uint8_t* key,size_t key_len);

Run in debug and check out the results 🙂


For more information about the STM32 Devcoons Framework:
https://devcoons.com/stm32-devcoons-framework-1-how-to-use/
Disclaimer: The present content may not be used for training artificial intelligence or machine learning algorithms. All other uses, including search, entertainment, and commercial use, are permitted.

Categories

Tags