123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- #include "sdk_common.h"
- #if NRF_MODULE_ENABLED(NRF_CRYPTO) && NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_OBERON)
- #include "nrf_log.h"
- #include "nrf_crypto_error.h"
- #include "nrf_crypto_types.h"
- #include "oberon_backend_hmac.h"
- #if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_OBERON_HMAC_SHA256)
- #define HMAC_SHA256_BLOCK_SIZE 64
- static ret_code_t oberon_backend_hmac_init_sha256(void * const p_context,
- uint8_t const * p_key,
- size_t key_size)
- {
- nrf_crypto_backend_oberon_hmac_sha256_context_t * p_ctx =
- (nrf_crypto_backend_oberon_hmac_sha256_context_t *)p_context;
- ocrypto_hmac_sha256_init(&p_ctx->oberon_ctx, p_key, key_size);
- return NRF_SUCCESS;
- }
- static ret_code_t oberon_backend_hmac_update_sha256(void * const p_context,
- uint8_t const * p_data,
- size_t size)
- {
- nrf_crypto_backend_oberon_hmac_sha256_context_t * p_ctx =
- (nrf_crypto_backend_oberon_hmac_sha256_context_t *)p_context;
- ocrypto_hmac_sha256_update(&p_ctx->oberon_ctx, p_data, size);
- return NRF_SUCCESS;
- }
- static ret_code_t oberon_backend_hmac_finalize_sha256(void * const p_context,
- uint8_t * p_digest,
- size_t * const p_size)
- {
- nrf_crypto_backend_oberon_hmac_sha256_context_t * const p_ctx =
- (nrf_crypto_backend_oberon_hmac_sha256_context_t *)p_context;
- ocrypto_hmac_sha256_final(&p_ctx->oberon_ctx, p_digest);
-
- *p_size = p_ctx->header.p_info->digest_size;
- return NRF_SUCCESS;
- }
- const nrf_crypto_hmac_info_t g_nrf_crypto_hmac_sha256_info =
- {
- .init_fn = oberon_backend_hmac_init_sha256,
- .update_fn = oberon_backend_hmac_update_sha256,
- .finalize_fn = oberon_backend_hmac_finalize_sha256,
- .digest_size = NRF_CRYPTO_HASH_SIZE_SHA256,
- .context_size = sizeof(nrf_crypto_backend_oberon_hmac_sha256_context_t),
- .type = NRF_CRYPTO_HMAC_SHA256_TYPE
- };
- #endif
- #if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_OBERON_HMAC_SHA512)
- #define HMAC_SHA512_BLOCK_SIZE 128
- static ret_code_t oberon_backend_hmac_init_sha512(void * const p_context,
- uint8_t const * p_key,
- size_t key_size)
- {
- nrf_crypto_backend_oberon_hmac_sha512_context_t * p_ctx =
- (nrf_crypto_backend_oberon_hmac_sha512_context_t *)p_context;
- ocrypto_hmac_sha512_init(&p_ctx->oberon_ctx, p_key, key_size);
- return NRF_SUCCESS;
- }
- static ret_code_t oberon_backend_hmac_update_sha512(void * const p_context,
- uint8_t const * p_data,
- size_t size)
- {
- nrf_crypto_backend_oberon_hmac_sha512_context_t * p_ctx =
- (nrf_crypto_backend_oberon_hmac_sha512_context_t *)p_context;
- ocrypto_hmac_sha512_update(&p_ctx->oberon_ctx, p_data, size);
- return NRF_SUCCESS;
- }
- static ret_code_t oberon_backend_hmac_finalize_sha512(void * const p_context,
- uint8_t * p_digest,
- size_t * const p_size)
- {
- nrf_crypto_backend_oberon_hmac_sha512_context_t * const p_ctx =
- (nrf_crypto_backend_oberon_hmac_sha512_context_t *)p_context;
- ocrypto_hmac_sha512_final(&p_ctx->oberon_ctx, p_digest);
-
- *p_size = p_ctx->header.p_info->digest_size;
- return NRF_SUCCESS;
- }
- const nrf_crypto_hmac_info_t g_nrf_crypto_hmac_sha512_info =
- {
- .init_fn = oberon_backend_hmac_init_sha512,
- .update_fn = oberon_backend_hmac_update_sha512,
- .finalize_fn = oberon_backend_hmac_finalize_sha512,
- .digest_size = NRF_CRYPTO_HASH_SIZE_SHA512,
- .context_size = sizeof(nrf_crypto_backend_oberon_hmac_sha512_context_t),
- .type = NRF_CRYPTO_HMAC_SHA512_TYPE
- };
- #endif
- #endif
|