blob: 7e583505794dd7556f088eb408f0e48ee16837d6 [file] [log] [blame]
Sigvart Hovland25ec7462019-03-11 15:57:21 +01001/*
2 * Copyright (c) 2019 Nordic Semiconductor ASA
3 *
Dominik Kilian421730e2022-12-15 15:37:19 +01004 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
Sigvart Hovland25ec7462019-03-11 15:57:21 +01005 */
6#ifndef NRF_CC310_GLUE_H__
7#define NRF_CC310_GLUE_H__
8
9#include <nrf.h>
10#include <nrf_cc310_bl_init.h>
11#include <nrf_cc310_bl_hash_sha256.h>
12#include <nrf_cc310_bl_ecdsa_verify_secp256r1.h>
Ulf Magnussone96b6872020-01-13 12:06:44 +010013#include <devicetree.h>
Sigvart Hovland25ec7462019-03-11 15:57:21 +010014#include <string.h>
15
Piotr Ciura71966db2020-07-29 08:28:53 +020016/*
17 * Name translation for peripherals with only one type of access available.
18 */
19#if !defined(NRF_TRUSTZONE_NONSECURE) && defined(CONFIG_ARM_TRUSTZONE_M)
20#define NRF_CRYPTOCELL NRF_CRYPTOCELL_S
21#endif
22
Sigvart Hovland25ec7462019-03-11 15:57:21 +010023typedef nrf_cc310_bl_hash_context_sha256_t bootutil_sha256_context;
24
25int cc310_ecdsa_verify_secp256r1(uint8_t *hash,
26 uint8_t *public_key,
27 uint8_t *signature,
28 size_t hash_len);
29
30
31int cc310_init(void);
32
33static inline void cc310_sha256_init(nrf_cc310_bl_hash_context_sha256_t *ctx);
34
35void cc310_sha256_update(nrf_cc310_bl_hash_context_sha256_t *ctx,
36 const void *data,
37 uint32_t data_len);
38
39static inline void nrf_cc310_enable(void)
40{
41 NRF_CRYPTOCELL->ENABLE=1;
42}
43
44static inline void nrf_cc310_disable(void)
45{
sigvartmh477ff5b2019-11-06 21:48:46 +010046 NRF_CRYPTOCELL->ENABLE=0;
Sigvart Hovland25ec7462019-03-11 15:57:21 +010047}
48
49/* Enable and disable cc310 to reduce power consumption */
50static inline void cc310_sha256_init(nrf_cc310_bl_hash_context_sha256_t * ctx)
51{
52 cc310_init();
53 nrf_cc310_enable();
54 nrf_cc310_bl_hash_sha256_init(ctx);
55}
56
57static inline void cc310_sha256_finalize(bootutil_sha256_context *ctx,
58 uint8_t *output)
59{
60 nrf_cc310_bl_hash_sha256_finalize(ctx,
61 (nrf_cc310_bl_hash_digest_sha256_t *)output);
62 nrf_cc310_disable();
63}
64
65#endif /* NRF_CC310_GLUE_H__ */