Sigvart Hovland | 25ec746 | 2019-03-11 15:57:21 +0100 | [diff] [blame] | 1 | /* |
Sigvart Hovland | 5962433 | 2023-02-23 09:43:42 +0100 | [diff] [blame^] | 2 | * Copyright Nordic Semiconductor ASA |
| 3 | * SPDX-License-Identifier: Apache-2.0 |
Sigvart Hovland | 25ec746 | 2019-03-11 15:57:21 +0100 | [diff] [blame] | 4 | * |
Sigvart Hovland | 5962433 | 2023-02-23 09:43:42 +0100 | [diff] [blame^] | 5 | * 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 Hovland | 25ec746 | 2019-03-11 15:57:21 +0100 | [diff] [blame] | 16 | */ |
Sigvart Hovland | 5962433 | 2023-02-23 09:43:42 +0100 | [diff] [blame^] | 17 | |
Sigvart Hovland | 25ec746 | 2019-03-11 15:57:21 +0100 | [diff] [blame] | 18 | #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 Magnusson | e96b687 | 2020-01-13 12:06:44 +0100 | [diff] [blame] | 25 | #include <devicetree.h> |
Sigvart Hovland | 25ec746 | 2019-03-11 15:57:21 +0100 | [diff] [blame] | 26 | #include <string.h> |
| 27 | |
Piotr Ciura | 71966db | 2020-07-29 08:28:53 +0200 | [diff] [blame] | 28 | /* |
| 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 Hovland | 25ec746 | 2019-03-11 15:57:21 +0100 | [diff] [blame] | 35 | typedef nrf_cc310_bl_hash_context_sha256_t bootutil_sha256_context; |
| 36 | |
| 37 | int cc310_ecdsa_verify_secp256r1(uint8_t *hash, |
| 38 | uint8_t *public_key, |
| 39 | uint8_t *signature, |
| 40 | size_t hash_len); |
| 41 | |
| 42 | |
| 43 | int cc310_init(void); |
| 44 | |
| 45 | static inline void cc310_sha256_init(nrf_cc310_bl_hash_context_sha256_t *ctx); |
| 46 | |
| 47 | void cc310_sha256_update(nrf_cc310_bl_hash_context_sha256_t *ctx, |
| 48 | const void *data, |
| 49 | uint32_t data_len); |
| 50 | |
| 51 | static inline void nrf_cc310_enable(void) |
| 52 | { |
| 53 | NRF_CRYPTOCELL->ENABLE=1; |
| 54 | } |
| 55 | |
| 56 | static inline void nrf_cc310_disable(void) |
| 57 | { |
sigvartmh | 477ff5b | 2019-11-06 21:48:46 +0100 | [diff] [blame] | 58 | NRF_CRYPTOCELL->ENABLE=0; |
Sigvart Hovland | 25ec746 | 2019-03-11 15:57:21 +0100 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | /* Enable and disable cc310 to reduce power consumption */ |
| 62 | static 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 | |
| 69 | static 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__ */ |