blob: db34c341f90b007684303c3d92859f1591a04d7c [file] [log] [blame]
Sigvart Hovland25ec7462019-03-11 15:57:21 +01001/*
2 * Copyright (c) 2019 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
5 */
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>
13#include <generated_dts_board.h>
14#include <string.h>
15
16typedef nrf_cc310_bl_hash_context_sha256_t bootutil_sha256_context;
17
18int cc310_ecdsa_verify_secp256r1(uint8_t *hash,
19 uint8_t *public_key,
20 uint8_t *signature,
21 size_t hash_len);
22
23
24int cc310_init(void);
25
26static inline void cc310_sha256_init(nrf_cc310_bl_hash_context_sha256_t *ctx);
27
28void cc310_sha256_update(nrf_cc310_bl_hash_context_sha256_t *ctx,
29 const void *data,
30 uint32_t data_len);
31
32static inline void nrf_cc310_enable(void)
33{
34 NRF_CRYPTOCELL->ENABLE=1;
35}
36
37static inline void nrf_cc310_disable(void)
38{
39 NRF_CRYPTOCELL->ENABLE=1;
40}
41
42/* Enable and disable cc310 to reduce power consumption */
43static inline void cc310_sha256_init(nrf_cc310_bl_hash_context_sha256_t * ctx)
44{
45 cc310_init();
46 nrf_cc310_enable();
47 nrf_cc310_bl_hash_sha256_init(ctx);
48}
49
50static inline void cc310_sha256_finalize(bootutil_sha256_context *ctx,
51 uint8_t *output)
52{
53 nrf_cc310_bl_hash_sha256_finalize(ctx,
54 (nrf_cc310_bl_hash_digest_sha256_t *)output);
55 nrf_cc310_disable();
56}
57
58#endif /* NRF_CC310_GLUE_H__ */