Sigvart Hovland | 25ec746 | 2019-03-11 15:57:21 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2019 Nordic Semiconductor ASA |
| 3 | * |
Dominik Kilian | 421730e | 2022-12-15 15:37:19 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause |
Sigvart Hovland | 25ec746 | 2019-03-11 15:57:21 +0100 | [diff] [blame] | 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> |
Ulf Magnusson | e96b687 | 2020-01-13 12:06:44 +0100 | [diff] [blame] | 13 | #include <devicetree.h> |
Sigvart Hovland | 25ec746 | 2019-03-11 15:57:21 +0100 | [diff] [blame] | 14 | #include <string.h> |
| 15 | |
Piotr Ciura | 71966db | 2020-07-29 08:28:53 +0200 | [diff] [blame] | 16 | /* |
| 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 Hovland | 25ec746 | 2019-03-11 15:57:21 +0100 | [diff] [blame] | 23 | typedef nrf_cc310_bl_hash_context_sha256_t bootutil_sha256_context; |
| 24 | |
| 25 | int cc310_ecdsa_verify_secp256r1(uint8_t *hash, |
| 26 | uint8_t *public_key, |
| 27 | uint8_t *signature, |
| 28 | size_t hash_len); |
| 29 | |
| 30 | |
| 31 | int cc310_init(void); |
| 32 | |
| 33 | static inline void cc310_sha256_init(nrf_cc310_bl_hash_context_sha256_t *ctx); |
| 34 | |
| 35 | void cc310_sha256_update(nrf_cc310_bl_hash_context_sha256_t *ctx, |
| 36 | const void *data, |
| 37 | uint32_t data_len); |
| 38 | |
| 39 | static inline void nrf_cc310_enable(void) |
| 40 | { |
| 41 | NRF_CRYPTOCELL->ENABLE=1; |
| 42 | } |
| 43 | |
| 44 | static inline void nrf_cc310_disable(void) |
| 45 | { |
sigvartmh | 477ff5b | 2019-11-06 21:48:46 +0100 | [diff] [blame] | 46 | NRF_CRYPTOCELL->ENABLE=0; |
Sigvart Hovland | 25ec746 | 2019-03-11 15:57:21 +0100 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | /* Enable and disable cc310 to reduce power consumption */ |
| 50 | static 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 | |
| 57 | static 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__ */ |