HSE on A53 core[Linux] to perform hashing

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

HSE on A53 core[Linux] to perform hashing

1,906 Views
ashwini2024
Contributor II

The bsp version I am using is bsp40. I have enabled hse in local.conf as below :

DISTRO_FEATURES:append = " hse "
NXP_FIRMWARE_LOCAL_DIR = "/path/to/yocto-s32/hse" # Update with your HSE firmware path

Now i am not sure how to move further i have to offload cryptographic operations to HSE.
Could you please let me know how i could do that ? Is there any specific examples or could u give me an overview where the apis are present and how i can use those HSE apis to develop an user application that is a custom application and perform hashing.

Thank you.

Tags (2)
0 Kudos
Reply
10 Replies

1,678 Views
chenyin_h
NXP Employee
NXP Employee

Hello, @ashwini2024 

I have finished some tests with libhse, the application could call the APIs of it to communicate with HSE, for details, I have replied it in your alternative thread:

https://community.nxp.com/t5/S32G/HOW-TO-INTEGRATE-AND-USE-HSE-API/td-p/1974893

Would you mind if we could continue the discussion in only one thread?

 

BR

Chenyin

0 Kudos
Reply

1,698 Views
chenyin_h
NXP Employee
NXP Employee

Hello, @ashwini2024 

Thanks for you reply.

Sorry that I may not provide correct answers on your specific request now since it is a custom development, let me summarize the status according our previous discussion:

1. The current BSP could enable communication with HSE from userspace applications according to the description in document.

2. But there seems not direct formal user space example according to your specific requirements(cryptoapi), you may have to implement it yourself based on current code(BSP, HSE FW) and document(BSP UM, etc.), such developing process is beyond our community support range in common.

3. Although we do not commonly support direct development for specific request, as I mentioned in previous post, I want to help on this issue, and wish studying it in spare time, I will try to implement an simple example for your reference,  which is just started due very limited bandwidth, I am still not sure of the schedule, but I could confirm that I will do and finish it.

Thanks for your understanding.

 

BR

Chenyin

 

0 Kudos
Reply

1,733 Views
chenyin_h
NXP Employee
NXP Employee

Hello, @ashwini2024 

Thanks for sharing the information.

Would you please help to submit a support ticket via the way I sent previously?

For such case that may involving code sharing, we may need to communicate via the regular supporting case.

Thanks for your understanding.

BR

Chenyin

0 Kudos
Reply

1,818 Views
chenyin_h
NXP Employee
NXP Employee

Hello, @ashwini2024 

Thanks for the reply.

I suggest raising a ticket, it is relatively easy to share files/patches via that channel, since it is a specific case, and some information may not be conveniently shared in public forum.

Thanks for your understanding.

 

BR

Chenyin

0 Kudos
Reply

1,722 Views
ashwini2024
Contributor II

Could you please tell me how could user space application communicate with hse on s32g3 board.
Thank you.

0 Kudos
Reply

1,774 Views
ashwini2024
Contributor II

The below is the custom application that i have implemented :

#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include "hse_interface.h"
#include "hse_gpr_status.h"
#include "hse_srv_responses.h"
#include "hse_status_and_errors.h"
#include "std_typedefs.h"
#include "hse_srv_hash.h"
#include "hse_common_types.h"
#include "hse_defs.h"
#include "hse_keymgmt_common_types.h"
#include "hse_compile_defs.h"
#include "hse_h_config.h"
#include "hse_platform.h"
#include "hse_target.h"
#include "platform_device.h"
#include "device.h"
// MU Instance base addresses - S32G2/S32G3/S32R45 platforms
#define MU_INSTANCE0 ((uint32_t)0x40210000UL) /**< @brief MU0 base address */
#define MU_INSTANCE1 ((uint32_t)0x40211000UL) /**< @brief MU1 base address */
#define MU_INSTANCE2 ((uint32_t)0x40212000UL) /**< @brief MU2 base address */
#define MU_INSTANCE3 ((uint32_t)0x40213000UL) /**< @brief MU3 base address */

#define MU_REG_READ32(address) (*(volatile uint32_t*)(address))

// Base addresses for each MU instance
const uint32_t u32BaseAddr[HSE_NUM_OF_MU_INSTANCES] = {
MU_INSTANCE0,
MU_INSTANCE1,
#if (HSE_NUM_OF_MU_INSTANCES > 2U)
MU_INSTANCE2,
MU_INSTANCE3,
#endif /* (HSE_NUM_OF_MU_INSTANCES > 2U) */
#if HSE_NUM_OF_MU_INSTANCES > 4
MU_INSTANCE4,
MU_INSTANCE5,
MU_INSTANCE6,
MU_INSTANCE7
#endif /* HSE_NUM_OF_MU_INSTANCES > 4 */
};

// Macro to read from the flag status register on a specific MU interface
#define MU_FSR_OFFSET ((uint32_t)0x104U) /**< @brief Flag Status Register */
#define HSE_MU_READ_FLAG_STATUS_REGISTER(u8MuIf) (MU_REG_READ32(u32BaseAddr[u8MuIf] + MU_FSR_OFFSET))
#define CHECK_HSE_STATUS(hseStatus) ((hseStatus) == ((hseStatus) & HSE_MU_GetHseStatus(0U)))

uint16_t HSE_MU_GetHseStatus(uint8_t u8MuInstance);
void HSE_Status(void);

#define HASH_SIZE 32

int main() {
/* Wait for HSE to initialize (along with RNG module) by reading the status bits in FSR */
while (!CHECK_HSE_STATUS(HSE_STATUS_INIT_OK | HSE_STATUS_RNG_INIT_OK));

HSE_Status();
/* Example of Key generation */

/* Example of Hash generation on sample data */
hseSrvDescriptor_t srvDesc;
uint32_t hashLength = HASH_SIZE;
uint8_t hashOutput[HASH_SIZE];

char *inputData = "Hello, World!";
size_t inputLength = strlen(inputData); // Use the correct length

hseHashSrv_t *hashService = &srvDesc.hseSrv.hashReq; // Correctly assign to pointer
hseSrvResponse_t srvResponse;

memset(&srvDesc, 0, sizeof(srvDesc));

// Prepare the hash service request
hashService->accessMode = HSE_ACCESS_MODE_ONE_PASS; // Set to one-pass mode
hashService->hashAlgo = HSE_HASH_ALGO_SHA2_256; // Use SHA-256
hashService->inputLength = inputLength; // Length of input data
hashService->pInput = (uintptr_t)(uintptr_t)inputData; // Pointer to input data (cast to uintptr_t)
hashService->pHash = (uintptr_t)(uintptr_t)hashOutput; // Pointer to output buffer
hashService->pHashLength = (uintptr_t)(uintptr_t)&hashLength; // Pointer to output length

// Send the request to HSE and check for the response
// Assume hse_send is a function that handles the request
// srvResponse = hse_send(&srvDesc);

// Uncomment the actual sending function when ready
if (srvResponse != HSE_SRV_RSP_OK) {
printf("HSE hash operation failed with error code: %d\n", srvResponse);
return -1;
}

// Print the resulting hash
printf("Hash of \"%s\": ", inputData);
for (int i = 0; i < HASH_SIZE; i++) {
printf("%02x", hashOutput[i]);
}
printf("\n");

return 0;
}

/*
************************************************************************************************
* Description: Returns the HSE status (16 MSB of FSR).
***********************************************************************************************
*/
uint16_t HSE_MU_GetHseStatus(uint8_t u8MuInstance) {
uint32_t u32FlagStatusReg = 0UL;

/* Get MU_FSR (MU Flag Status register) and returns HSE status (16 MSB) */
u32FlagStatusReg = HSE_MU_READ_FLAG_STATUS_REGISTER(u8MuInstance);
u32FlagStatusReg = ((u32FlagStatusReg & 0xFFFF0000UL) >> 16U);

return (uint16_t)u32FlagStatusReg;
}

void HSE_Status(void) {
uint8_t i;
char status[][40] = {
"",
"HSE_SHE_STATUS_SECURE_BOOT",
"HSE_SHE_STATUS_SECURE_BOOT_INIT",
"HSE_SHE_STATUS_SECURE_BOOT_FINISHED",
"HSE_SHE_STATUS_SECURE_BOOT_OK",
"HSE_STATUS_RNG_INIT_OK",
"HSE_STATUS_HOST_DEBUGGER_ACTIVE",
"HSE_STATUS_HSE_DEBUGGER_ACTIVE",
"HSE_STATUS_INIT_OK",
"HSE_STATUS_INSTALL_OK",
"HSE_STATUS_BOOT_OK",
"HSE_STATUS_CUST_SUPER_USER",
"HSE_STATUS_OEM_SUPER_USER",
"HSE_STATUS_PUBLISH_SYS_IMAGE",
"HSE_STATUS_PRIMARY_SYS_IMAGE",
"HSE_STATUS_BACKUP_SYS_IMAGE",
};

printf("HSE FW up and running! Status:\n");
for (i = 0U; i < 16U; ++i) {
if (CHECK_HSE_STATUS((1UL << i))) {
printf("\t%s\n", status[i]);
}
}
}


But the platform.h and device.h file is not getting added it throws many errors . Could you please help me resolve those errors and could u tell me if the c code i mentioned needs any modifications ?

The device.h and platform.h files are present in the yocto package in kernel-source/include/linux folder .

0 Kudos
Reply

1,862 Views
chenyin_h
NXP Employee
NXP Employee

Hello, @ashwini2024 

Thanks a lot for your kindly understanding.

We always would like supporting our customer more on their issues, although such kind of topic is somewhat beyond our supporting range via this channel.

I will try creating a user space sample based on current BSP APIs, it may not fully fulfill the needs from your side, but could be used as a reference, you may modify it according to your specific needs.

In order for better tracking the case, would you mind creating a private case with the following way?

(you may add @chenyin in the description to avoid assigning to my other colleagues)

1. go to SUPPORTHOME, click on "Submit a Ticket" in the middle of this page.
2.Login, Or Register with your business email
3. After logging in, please click "Creat New Cases" on the upper right side of the page to submit a question according to the steps
 
BR
Chenyin
0 Kudos
Reply

1,839 Views
ashwini2024
Contributor II

Thank you, @chenyin_h, for the detailed instructions. If it’s feasible to discuss this topic further here, I’d be very grateful, as it would help streamline our communication. However, if submitting a ticket is essential, please let me know, and I’ll proceed as needed.
Thank you for your continued support!

0 Kudos
Reply

1,876 Views
chenyin_h
NXP Employee
NXP Employee

Hello, @ashwini2024 

Thanks for your post.

As what I have suggested in another thread created by you , there are not out-of-box examples which could help you directly from BSP perspective.

The HSE kernel driver is already included in the BSP release, for such requirement,  the customer may have to develop the application themselves based on current drivers.

Whatever, since this topic has been mentioned several times, I plan to create an example(linux user space) to do the digest operation taking use the HSE instead of CPU, it would be based on the BSP41 or 42 HSE driver from my plan.

But as you may know, we commonly have to deal with several different posts from different customers per day, there are very limited bandwidth for developing additional example code/applications, it may take multiple days or even several weeks for finishing the example,  I apologize for the late schedule.

 

BR

Chenyin

0 Kudos
Reply

1,868 Views
ashwini2024
Contributor II

Thank you for the update and for your transparency about the timelines. I completely understand the high volume of work and the limited resources you have to work with. I appreciate the effort you're putting into supporting us amidst your other commitments. Please take the time you need; I know these things can take longer, and I’m grateful for any assistance you can provide when possible.

Thank you again

0 Kudos
Reply
An error has occurred when reading existing sub-variable "Language_PG_Configuration"; see cause exception! The type of the containing value was: extended_hash+string (lithium.coreapi.webui.template.models.NamedValueByNameTemplateModel wrapped into f.e.b.StringModel) ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign redirect_lingo_page_url = web... [in template "language_macro_header.ftl" at line 173, column 1] - Reached through: #include "language_macro_header.ftl" [in template "Language_translator_Dashboard" at line 3, column 1] ----