blob: c42fad5a5bc45d077eeb4e0a44978e8b003ff3e8 [file] [log] [blame]
Sigvart Hovland25ec7462019-03-11 15:57:21 +01001/*
Sigvart Hovland59624332023-02-23 09:43:42 +01002 * Copyright Nordic Semiconductor ASA
3 * SPDX-License-Identifier: Apache-2.0
Sigvart Hovland25ec7462019-03-11 15:57:21 +01004 *
Sigvart Hovland59624332023-02-23 09:43:42 +01005 * Licensed under the Apache License, Version 2.0 (the "License"); you may
6 * not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
Sigvart Hovland25ec7462019-03-11 15:57:21 +010016 */
Sigvart Hovland59624332023-02-23 09:43:42 +010017
Sigvart Hovland25ec7462019-03-11 15:57:21 +010018#ifndef NRF_CC310_GLUE_H__
19#define NRF_CC310_GLUE_H__
20
21#include <nrf.h>
22#include <nrf_cc310_bl_init.h>
23#include <nrf_cc310_bl_hash_sha256.h>
24#include <nrf_cc310_bl_ecdsa_verify_secp256r1.h>
Ulf Magnussone96b6872020-01-13 12:06:44 +010025#include <devicetree.h>
Sigvart Hovland25ec7462019-03-11 15:57:21 +010026#include <string.h>
27
Piotr Ciura71966db2020-07-29 08:28:53 +020028/*
29 * Name translation for peripherals with only one type of access available.
30 */
31#if !defined(NRF_TRUSTZONE_NONSECURE) && defined(CONFIG_ARM_TRUSTZONE_M)
32#define NRF_CRYPTOCELL NRF_CRYPTOCELL_S
33#endif
34
Sigvart Hovland25ec7462019-03-11 15:57:21 +010035typedef nrf_cc310_bl_hash_context_sha256_t bootutil_sha256_context;
36
37int cc310_ecdsa_verify_secp256r1(uint8_t *hash,
38 uint8_t *public_key,
39 uint8_t *signature,
40 size_t hash_len);
41
42
43int cc310_init(void);
44
45static inline void cc310_sha256_init(nrf_cc310_bl_hash_context_sha256_t *ctx);
46
47void cc310_sha256_update(nrf_cc310_bl_hash_context_sha256_t *ctx,
48 const void *data,
49 uint32_t data_len);
50
51static inline void nrf_cc310_enable(void)
52{
53 NRF_CRYPTOCELL->ENABLE=1;
54}
55
56static inline void nrf_cc310_disable(void)
57{
sigvartmh477ff5b2019-11-06 21:48:46 +010058 NRF_CRYPTOCELL->ENABLE=0;
Sigvart Hovland25ec7462019-03-11 15:57:21 +010059}
60
61/* Enable and disable cc310 to reduce power consumption */
62static inline void cc310_sha256_init(nrf_cc310_bl_hash_context_sha256_t * ctx)
63{
64 cc310_init();
65 nrf_cc310_enable();
66 nrf_cc310_bl_hash_sha256_init(ctx);
67}
68
69static inline void cc310_sha256_finalize(bootutil_sha256_context *ctx,
70 uint8_t *output)
71{
72 nrf_cc310_bl_hash_sha256_finalize(ctx,
73 (nrf_cc310_bl_hash_digest_sha256_t *)output);
74 nrf_cc310_disable();
75}
76
77#endif /* NRF_CC310_GLUE_H__ */