Thank you for the prompt reply.
https://github.com/nxp-auto-linux/pkcs11-hse/blob/release/bsp42.0/examples/hse-encrypt/hse-encrypt.c
I have used the above code as a reference modified the code by applying the patch to it as per my requirements to compute the hash.
It has generated the binary.
The below is the logic i have implemented :
Could you please let me know if the implemented logic is right and if there is any error .And if it will generate the hash correctly using hse .
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <errno.h>
#include "libhse.h"
#include "hse_interface.h"
#define HASH_SIZE 32 // Size for SHA-256 hash output
int main()
{
DECLARE_SET_ZERO(hseSrvDescriptor_t, srvDesc);
uint32_t hashLength = HASH_SIZE;
uint8_t hashOutput[HASH_SIZE];
int err;
char *inputData = "Hello, World!";
size_t inputLength = strlen(inputData); // Length of input data
// Open HSE device
err = hse_dev_open();
if (err) {
printf("DEMO: failed to open HSE device: error %d\n", err);
return err;
}
// Fill in hashing service descriptor
hseHashSrv_t *hashService = &srvDesc.hseSrv.hashReq; // Correctly assign to pointer
memset(&srvDesc, 0, sizeof(srvDesc)); // Zero out the service descriptor
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
// Issue hash service request
err = hse_srv_req_sync(HSE_CHANNEL_ANY, &srvDesc, sizeof(srvDesc));
if (err) {
printf("DEMO: hash request failed: error %d\n", err);
hse_dev_close();
return err;
}
// Print the resulting hash
printf("DEMO: hash operation successful\n");
printf("Hash (SHA-256): ");
for (uint32_t i = 0; i < hashLength; i++) {
printf("%02x", hashOutput[i]);
}
printf("\n");
// Close HSE device
hse_dev_close();
return 0;
}