123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- #include "sdk_common.h"
- #if NRF_MODULE_ENABLED(NRF_CRYPTO) && NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_NRF_SW)
- #include "nrf_sw_backend_hash.h"
- #include "sha256.h"
- #include "nrf_crypto_types.h"
- #include "nrf_crypto_error.h"
- #include "nrf_crypto_hash_shared.h"
- #include "sdk_macros.h"
- #include "nrf_log.h"
- #include "nrf_assert.h"
- #if defined(NRF_CRYPTO_BACKEND_NRF_SW_HASH_LITTLE_ENDIAN_DIGEST_ENABLED)
- #error The configuration NRF_CRYPTO_BACKEND_NRF_SW_HASH_LITTLE_ENDIAN_DIGEST_ENABLED was removed in SDK 15.1.0. Please see release notes for details on removing this error message.
- #endif
- static ret_code_t nrf_sw_backend_hash_sha256_init(void * const p_context)
- {
- ret_code_t ret_val;
-
-
- sha256_context_t * p_backend_context
- = &(((nrf_crypto_backend_hash_sha256_context_t *) p_context)->context);
- ret_val = sha256_init(p_backend_context);
- return ret_val;
- }
- static uint32_t nrf_sw_backend_hash_sha256_update(void * const p_context,
- uint8_t const * p_data,
- size_t len)
- {
- ret_code_t ret_val;
-
-
- sha256_context_t * p_backend_context
- = &(((nrf_crypto_backend_hash_sha256_context_t * ) p_context)->context);
- ret_val = sha256_update(p_backend_context, p_data, len);
- return ret_val;
- }
- static uint32_t nrf_sw_backend_hash_sha256_finalize(void * const p_context,
- uint8_t * p_digest,
- size_t * const p_digest_len)
- {
- ret_code_t ret_val;
-
-
- sha256_context_t * p_backend_context
- = &(((nrf_crypto_backend_hash_sha256_context_t * )p_context)->context);
- if (NRF_CRYPTO_HASH_SIZE_SHA256 > *p_digest_len)
- {
- return NRF_ERROR_CRYPTO_OUTPUT_LENGTH;
- }
- ret_val = sha256_final(p_backend_context, p_digest, false);
- if (ret_val != NRF_SUCCESS)
- {
- return ret_val;
- }
- *p_digest_len = NRF_CRYPTO_HASH_SIZE_SHA256;
- return NRF_SUCCESS;
- }
- const nrf_crypto_hash_info_t g_nrf_crypto_hash_sha256_info =
- {
- .init_fn = nrf_sw_backend_hash_sha256_init,
- .update_fn = nrf_sw_backend_hash_sha256_update,
- .finalize_fn = nrf_sw_backend_hash_sha256_finalize,
- .digest_size = NRF_CRYPTO_HASH_SIZE_SHA256,
- .context_size = sizeof(nrf_crypto_backend_hash_sha256_context_t),
- .hash_mode = NRF_CRYPTO_HASH_MODE_SHA256
- };
- #endif
|