Hi. I'm using nRF52832, SDK13.0.0.
I should use SHA256 and MD5.
I made my code as 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
};
...
...
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, "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);
The result log is
p_init_cmd : 0001020304050607080900010203040506070809000102030405060708090001
hash_info_sha256, err_code=0x0
init_packet_hash : E8352A8521130C3C6564D205FA78C236F9E2AE133FC191D0CA70E35D4AACB1DC
hash_info_MD5, err_code=0x6
init_packet_hash : 00000000000000000000000000000000
I think MD5 has a problem because it only support SHA256.
But I should use MD5. Is there any way to use MD5?
And SHA256 also has a problem.
input data is "0001020304050607080900010203040506070809000102030405060708090001"
output data is "E8352A8521130C3C6564D205FA78C236F9E2AE133FC191D0CA70E35D4AACB1DC"
But SHA-256 calculator says output data is "94d785502c800d13c5ee22d0f4e5e6d754c29f7ef4a8ff540aa56bfd5da468b5"
I refered to http://www.xorbin.com/tools/sha256-hash-calculator
I don't know why output data is not good.
I need your help.