This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to use HASH?

Hi. I'm using nRF52832, SDK13.0.0.

I want tuse SHA256 abd MD5.

Could you let me know which function is for SHA256 and MD5?

Actually I've tried my code as below.

 uint8_t p_init_cmd[32];
 uint32_t init_cmd_len = 32;

 for(int i=0;i<32;i++) p_init_cmd[i]=(i%10);

 SEGGER_RTT_printf_log_Hex(0, RTT_CTRL_TEXT_CYAN"p_init_cmd     : ", p_init_cmd, 32);

 err_code = nrf_crypto_hash_compute(hash_info_sha256, p_init_cmd, init_cmd_len, &init_packet_hash);

 SEGGER_RTT_printf_log(0, "hash_info_sha256, err_code=0x%x\n", err_code);
 SEGGER_RTT_printf_log_Hex(0, "init_packet_hash     : ", init_packet_hash.p_value, 32);
 
 err_code = nrf_crypto_hash_compute(hash_info_MD5, p_init_cmd, init_cmd_len, &init_packet_md5);

 SEGGER_RTT_printf_log(0, "hash_info_MD5, err_code=0x%x\n", err_code);
 SEGGER_RTT_printf_log_Hex(0, "init_packet_hash     : ", init_packet_md5.p_value, 16);

But it doesn't work.

I need your help.

  • And init is below.

    NRF_CRYPTO_HASH_CREATE(init_packet_hash, SHA256);
    NRF_CRYPTO_HASH_CREATE(init_packet_md5, MD5);

    const nrf_crypto_hash_info_t hash_info_sha256 =
    {
        .hash_type = NRF_CRYPTO_HASH_TYPE_SHA256,
        .endian_type = NRF_CRYPTO_ENDIAN_LE
    };

    const nrf_crypto_hash_info_t hash_info_MD5 =
    {
        .hash_type = NRF_CRYPTO_HASH_TYPE_MD5,
        .endian_type = NRF_CRYPTO_ENDIAN_LE
    };

  • Hi,

    Let us continue in this thread (rather than the two duplicate ones).

    In one of the duplicate questions, you wrote that you get 0x6 returned from the call to nrf_crypto_hash_compute() when doing MD5. This is NRF_ERROR_NOT_SUPPORTED, and is expected since MD5 is only supported by the CC310 backend that is available on the nRF52840. It is not supported on the SW backend that is used for nRF52832.

    Regarding SHA-256 I don't spot the problem. Can you share a complete piece of code that I can try on my end?

    By the way, are you limited to using SDK 13 for some reason? Among many other improvements, the nrf_crypto library was reworked and greatly improved in SDK 15.

Related