I'm trying to get the code below to compile. One question is how to fill in the nrf_crypto_hash_info_t structure. Another issue is that the nrf crypto includes don't compile using Crossworks gcc because malloc.h can't be found (I don't think malloc.h is a standard c include). Anyone have a working example?
void fd_sha1(fd_sha1_source_t source, uint32_t address, uint32_t length, uint8_t *hash) {
nrf_crypto_hash_context_t hash_context;
nrf_crypto_hash_info_t info = {
.init_fn = ?,
.update_fn = ?,
.finalize_fn = ?,
.digest_size = NRF_CRYPTO_HASH_SIZE_SHA1,
.context_size = sizeof(nrf_crypto_backend_hash_sha1_context_t),
.hash_mode = NRF_CRYPTO_HASH_MODE_SHA1
};
ret_code_t ret = nrf_crypto_hash_init(&hash_context, &info);
fd_log_assert(ret == NRF_SUCCESS);
sha1_byte data[FD_SHA_BLOCK_SIZE];
uint32_t remaining = length;
while (remaining > 0) {
uint32_t n = FD_SHA_BLOCK_SIZE;
if (remaining < n) {
n = remaining;
}
(*source)(address, data, n);
ret = nrf_crypto_hash_update(&hash_context, data, n);
fd_log_assert(ret == NRF_SUCCESS);
remaining -= n;
address += n;
}
ret = nrf_crypto_hash_finalize(&hash_context, hash, FD_SHA_HASH_SIZE);
fd_log_assert(ret == NRF_SUCCESS);
}