psa_hash_compute with 8k message got error -141 built with nrf54l15dk_nrf54l15_cpuapp_ns target

I am implementing sha256 with hash message bigger than or equal to 8KB. I tried with nrf54l15dk_nrf54l15_cpuapp target, and it's working fine but if I try with nrf54l15dk_nrf54l15_cpuapp_ns I got an error -141(PSA_ERROR_INSUFFICIENT_MEMORY). Likewise, I tried on sample code and got the same error: C:\ncs\v2.9.1\nrf\samples\crypto\sha256

Device: nRF54L15-DK

NCS: V2.9.1

int hash_singlepart_sha256(void)
{
    uint32_t olen;
    psa_status_t status;

    uint8_t* ptrs = malloc(1024 * 8);
    if(ptrs == NULL) {
        LOG_INF("Malloc Error %d...", 1024 * 8);
    }

    memset(ptrs, 1, 8 * 1024);


    LOG_INF("Hashing using SHA256...");

    /* Calculate the SHA256 hash */
    status = psa_hash_compute(
        PSA_ALG_SHA_256, ptrs, 1024 * 8, m_hash, sizeof(m_hash), &olen);
    if (status != PSA_SUCCESS) {
        LOG_INF("psa_hash_compute failed! (Error: %d)", status);
        return APP_ERROR;
    }

    LOG_INF("Hashing successful!");
    PRINT_HEX("SHA256 hash", m_hash, sizeof(m_hash));

    return APP_SUCCESS;
}
Could you please help and advise?
Thanks,
Sophak
Parents
  • Hi,

     

    Looks like the TFM image needs to be adjusted to handle such a large buffer.

    Try to adjust CONFIG_TFM_CRYPTO_IOVEC_BUFFER_SIZE to a higher size, and see if this works.

     

    Kind regards,

    Håkon

  • Thank you so much for your help.

    I have tested by set CONFIG_TFM_CRYPTO_IOVEC_BUFFER_SIZE to 16KB and able to compute hash with message 8KB.

    Best regards,

    Sophak

  • Hi Sophak,

     

    I am glad to hear that this worked. Hope you have a wonderful day!

     

    Kind regards,

    Håkon

  • Hello Håkon,

    I have another problem when build project with nrf54l15dk_nrf54l15_cpuapp_ns target.

    #1 - I set enable mbedtls, but on the log it always set false.

    CONFIG_MBEDTLS_USE_PSA_CRYPTO=y
    CONFIG_MBEDTLS_PSA_CRYPTO_C=y

    #2 - I want to use low level driver on cracen library to handle my custom cryptography logic such as: 

    #include <cracen/mem_helpers.h>
    #include <cracen/statuscodes.h>
    #include <sicrypto/drbghash.h>
    #include <sicrypto/ecdsa.h>
    #include <sicrypto/ed25519.h>
    #include <sicrypto/ik.h>
    #include <sicrypto/internal.h>
    #include <sicrypto/rsapss.h>
    #include <sicrypto/rsassa_pkcs1v15.h>
    #include <sicrypto/sicrypto.h>
    #include <silexpk/blinding.h>
    #include <silexpk/ec_curves.h>
    #include <silexpk/ed25519.h>
    #include <silexpk/ik.h>
    #include <silexpk/sxbuf/sxbufop.h>
    #include <silexpk/sxops/eccweierstrass.h>
    #include <sxsymcrypt/sha1.h>
    #include <sxsymcrypt/sha2.h>
    #include <sxsymcrypt/trng.h>

    I am able to use all this API from when I build with nrf54l15dk_nrf54l15_cpuapp but when I build with nrf54l15dk_nrf54l15_cpuapp_ns, I got no such file or directory during build time.

    Could you please help to check and advise for all this issue?

     

    Thanks and Best Regards,

    Sophak

Reply
  • Hello Håkon,

    I have another problem when build project with nrf54l15dk_nrf54l15_cpuapp_ns target.

    #1 - I set enable mbedtls, but on the log it always set false.

    CONFIG_MBEDTLS_USE_PSA_CRYPTO=y
    CONFIG_MBEDTLS_PSA_CRYPTO_C=y

    #2 - I want to use low level driver on cracen library to handle my custom cryptography logic such as: 

    #include <cracen/mem_helpers.h>
    #include <cracen/statuscodes.h>
    #include <sicrypto/drbghash.h>
    #include <sicrypto/ecdsa.h>
    #include <sicrypto/ed25519.h>
    #include <sicrypto/ik.h>
    #include <sicrypto/internal.h>
    #include <sicrypto/rsapss.h>
    #include <sicrypto/rsassa_pkcs1v15.h>
    #include <sicrypto/sicrypto.h>
    #include <silexpk/blinding.h>
    #include <silexpk/ec_curves.h>
    #include <silexpk/ed25519.h>
    #include <silexpk/ik.h>
    #include <silexpk/sxbuf/sxbufop.h>
    #include <silexpk/sxops/eccweierstrass.h>
    #include <sxsymcrypt/sha1.h>
    #include <sxsymcrypt/sha2.h>
    #include <sxsymcrypt/trng.h>

    I am able to use all this API from when I build with nrf54l15dk_nrf54l15_cpuapp but when I build with nrf54l15dk_nrf54l15_cpuapp_ns, I got no such file or directory during build time.

    Could you please help to check and advise for all this issue?

     

    Thanks and Best Regards,

    Sophak

Children
Related