1 /*
2 * Copyright (c) 2019-2023, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8 #include <stdint.h>
9 #include "tfm_plat_otp.h"
10
11 #ifdef BL2
12
get_rotpk_hash(enum tfm_otp_element_id_t id,uint8_t * rotpk_hash,uint32_t * rotpk_hash_size)13 static enum tfm_plat_err_t get_rotpk_hash(enum tfm_otp_element_id_t id,
14 uint8_t* rotpk_hash,
15 uint32_t* rotpk_hash_size)
16 {
17 enum tfm_plat_err_t err;
18 size_t otp_size;
19
20 err = tfm_plat_otp_read(id, *rotpk_hash_size, rotpk_hash);
21 if (err != TFM_PLAT_ERR_SUCCESS) {
22 return err;
23 }
24
25 err = tfm_plat_otp_get_size(id, &otp_size);
26 if (err != TFM_PLAT_ERR_SUCCESS) {
27 return err;
28 }
29
30 *rotpk_hash_size = otp_size;
31
32 return TFM_PLAT_ERR_SUCCESS;
33 }
34
35 enum tfm_plat_err_t
tfm_plat_get_rotpk_hash(uint8_t image_id,uint8_t * rotpk_hash,uint32_t * rotpk_hash_size)36 tfm_plat_get_rotpk_hash(uint8_t image_id,
37 uint8_t *rotpk_hash,
38 uint32_t *rotpk_hash_size)
39 {
40 /* Assumes BL2 ROTPK are contiguous */
41 if (image_id < MCUBOOT_IMAGE_NUMBER) {
42 return get_rotpk_hash(PLAT_OTP_ID_BL2_ROTPK_0 + image_id, rotpk_hash,
43 rotpk_hash_size);
44 }
45
46 return TFM_PLAT_ERR_INVALID_INPUT;
47 }
48
49 #endif /* BL2 */
50