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 60 29 #define MAX_NUMBER_OF_RVT_IMAGES 32 30 #define MAX_PUBKEY_LEN 1040 31 #define PUBKEY_LEN_4096 1040 32 #define PUBKEY_LEN_2048 528 33 #define PUBKEY_LEN_SM 64 34 #define PARTITION_NAME_LEN 64 35 #define RVT_MAX_VALID_KEY_NUM 2 36 37 /* Maximum size of a rvt image - 64 KiB. */ 38 #define RVT_MAX_SIZE (64 * 1024) 39 40 struct rvt_pubk_desc { 41 /* The partition name of verity image. */ 42 char name[PARTITION_NAME_LEN]; 43 44 /* Offset into the rvt_payload of pubkey from verity image. */ 45 uint64_t pubkey_offset; 46 47 /* Length of the public key. */ 48 uint64_t pubkey_len; 49 50 /* pubkey payload stored dynamically */ 51 struct hvb_buf pubkey_payload; 52 53 /* second pubkey payload when pubkey_num_per_ptn is 2 */ 54 struct hvb_buf pubkey_payload_backup; 55 }; 56 57 struct rvt_image_header { 58 /* Four bytes equal to "rot" (magic). */ 59 uint8_t magic[RVT_MAGIC_LEN]; 60 61 /* The verity_num. */ 62 uint32_t verity_num; 63 64 /* pubkey num for each ptn, can be 1 or 2 and 0 as old version. */ 65 uint32_t pubkey_num_per_ptn; 66 67 /* The reserved data, must be 0. */ 68 uint8_t rvt_reserved[RVT_RELEASE_SIZE]; 69 } HVB_ATTR_PACKED; 70 71 enum hvb_errno hvb_rvt_head_parser(const struct hvb_buf *rvt, struct rvt_image_header *header); 72 enum hvb_errno hvb_rvt_get_pubk_desc(const struct hvb_buf *rvt, struct hvb_buf *pubk_desc); 73 enum hvb_errno hvb_rvt_pubk_desc_parser(const struct hvb_buf *pubk, struct rvt_pubk_desc *desc); 74 enum hvb_errno hvb_rvt_get_pubk_buf(struct hvb_buf *key_buf, const struct hvb_buf *rvt, 75 uint32_t pubkey_offset, uint32_t pubkey_len); 76 enum hvb_errno hvb_calculate_certs_digest(struct hvb_verified_data *vd, uint8_t *out_digest); 77 78 #ifdef __cplusplus 79 } 80 #endif 81 82 #endif /* HVB_RVT_H_ */ 83