1 /* 2 * Copyright (c) 2022-2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef __HVB_RVT_H_ 16 #define __HVB_RVT_H_ 17 18 #include "hvb_cert.h" 19 #include "hvb_ops.h" 20 21 #ifdef __cplusplus 22 extern "C" { 23 #endif 24 25 /* Magic for the rvt image header. */ 26 #define RVT_MAGIC "rot" 27 #define RVT_MAGIC_LEN 4 28 #define RVT_RELEASE_SIZE 64 29 #define MAX_NUMBER_OF_RVT_IMAGES 32 30 #define PUBKEY_LEN 1040 31 #define PARTITION_NAME_LEN 64 32 33 /* Maximum size of a rvt image - 64 KiB. */ 34 #define RVT_MAX_SIZE (64 * 1024) 35 36 struct rvt_pubk_desc { 37 /* The partition name of verity image. */ 38 char name[PARTITION_NAME_LEN]; 39 40 /* Offset into the rvt_payload of pubkey from verity image. */ 41 uint64_t pubkey_offset; 42 43 /* Length of the public key. */ 44 uint64_t pubkey_len; 45 46 /* pubkey_payload. */ 47 uint8_t pubkey_payload[PUBKEY_LEN]; 48 } HVB_ATTR_PACKED; 49 50 struct rvt_image_header { 51 /* Four bytes equal to "rot" (magic). */ 52 uint8_t magic[RVT_MAGIC_LEN]; 53 54 /* The verity_num. */ 55 uint32_t verity_num; 56 57 /* The reserved data, must be 0. */ 58 uint8_t rvt_reserved[RVT_RELEASE_SIZE]; 59 } HVB_ATTR_PACKED; 60 61 enum hvb_errno hvb_rvt_head_parser(const struct hvb_buf *rvt, struct rvt_image_header *dest, uint64_t desc_size); 62 enum hvb_errno hvb_rvt_get_pubk_desc(const struct hvb_buf *rvt, struct hvb_buf *pubk_desc); 63 enum hvb_errno hvb_rvt_pubk_desc_parser(const struct hvb_buf *pubk, struct rvt_pubk_desc *desc, uint64_t desc_size); 64 enum hvb_errno hvb_rvt_get_pubk_buf(struct hvb_buf *key_buf, const struct hvb_buf *rvt, struct rvt_pubk_desc *desc); 65 enum hvb_errno hvb_calculate_certs_digest(struct hvb_verified_data *vd, uint8_t *out_digest); 66 67 #ifdef __cplusplus 68 } 69 #endif 70 71 #endif /* HVB_RVT_H_ */ 72