psa_import_key, error -134 and bus fault

I am creating a sas token to azure iot hub on the nrf9160dk, and I have my access key provided by azure and I have base64 decoded it and using it as key and I want to store it using psa_import_key. But everytime I run psa_import_key(), I get error -134 and bus fault. I used the zephyr hash library sample But there was no example on how to use psa_import_key.


[00:00:22.361,755] <err> os: ***** BUS FAULT *****
[00:00:22.367,248] <err> os:   Precise data bus error
[00:00:22.372,985] <err> os:   BFAR Address: 0x0
[00:00:22.378,326] <err> os: r0/a1:  0x200125e5  r1/a2:  0x20040000  r2/a3:  0x20020ec7
[00:00:22.387,054] <err> os: r3/a4:  0x2003171c r12/ip:  0x00000000 r14/lr:  0x0003c7fb
[00:00:22.395,782] <err> os:  xpsr:  0x21000000
[00:00:22.401,000] <err> os: Faulting instruction address (r15/pc): 0x0003ffdc
[00:00:22.408,996] <err> os: >>> ZEPHYR FATAL ERROR 25: Unknown error on CPU 0
[00:00:22.416,931] <err> os: Current thread: 0x2000f4c8 (unknown)
[00:00:22.423,706] <err> os: Halting system



Here is my code, and I run 

psa_crypto_init(); before I call the import key function. 


int import_key(uint8_t *hmac_key, size_t hmac_key_len)
{
    psa_status_t status;
    psa_key_attributes_t key_attributes = PSA_KEY_ATTRIBUTES_INIT;
    printk("Importing key, length: %d", hmac_key_len);

    /* Configure key attributes */
    psa_set_key_usage_flags(&key_attributes,
        PSA_KEY_USAGE_VERIFY_HASH | PSA_KEY_USAGE_SIGN_HASH);
    psa_set_key_lifetime(&key_attributes, PSA_KEY_LIFETIME_VOLATILE);
    psa_set_key_algorithm(&key_attributes, PSA_ALG_HMAC(PSA_ALG_SHA_256));
    psa_set_key_type(&key_attributes, PSA_KEY_TYPE_HMAC);
    psa_set_key_bits(&key_attributes, 256);
    
    /* Import the key into PSA */
    status = psa_import_key(&key_attributes, hmac_key, hmac_key_len, &key_id);
    if (status != PSA_SUCCESS) {
        LOG_INF("psa_import_key failed! (Error: %d)", status);
        return HMAC_ERROR;
    }

    /* Reset attributes after importing */
    psa_reset_key_attributes(&key_attributes);

    LOG_INF("Key imported successfully!");
    return HMAC_SUCCESS;
}


And here is my configs

CONFIG_NRF_SECURITY=y
CONFIG_MBEDTLS_PSA_CRYPTO_C=y
CONFIG_PSA_WANT_ALG_HMAC=y
CONFIG_PSA_WANT_ALG_SHA_256=y
CONFIG_PSA_WANT_KEY_TYPE_HMAC=y

CONFIG_MBEDTLS_PSA_CRYPTO_STORAGE_C=y
CONFIG_MBEDTLS_ENABLE_HEAP=y
CONFIG_MBEDTLS_HEAP_SIZE=8192

CONFIG_TFM_PROFILE_TYPE_NOT_SET=y

CONFIG_TFM_PROFILE_TYPE_MINIMAL=y


I have tried different configurations, like using

psa_set_key_lifetime(&key_attributes,
PSA_KEY_LIFETIME_VOLATILE
); instead of PERSISTANT

And I also tried to generate a testkey that looks like this, and still got same error so I do not think the error is in the key itself.
static const uint8_t test_key[32] __aligned(4) = {
    0x00, 0x01, 0x02, 0x03,
    0x04, 0x05, 0x06, 0x07,
    0x08, 0x09, 0x0A, 0x0B,
    0x0C, 0x0D, 0x0E, 0x0F,
    0x10, 0x11, 0x12, 0x13,
    0x14, 0x15, 0x16, 0x17,
    0x18, 0x19, 0x1A, 0x1B,
    0x1C, 0x1D, 0x1E, 0x1F
};


I think it has something to do with the configs in some way, or the attributes but I do not know.

Would you please help me to find out the solution?

IIf there's any information missing in my post, please let me know, and I'll gladly provide it.
 
Related