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_H_ 16 #define __HVB_H_ 17 18 #include "hvb_ops.h" 19 #include "hvb_types.h" 20 21 #ifdef __cplusplus 22 extern "C" 23 { 24 #endif 25 26 #define HVB_MAX_NUMBER_OF_ROLLBACK_INDEX_LOCATIONS 32 27 #define HVB_MAX_NUMBER_OF_LOADED_CERTS 32 28 #define HVB_MAX_NUMBER_OF_LOADED_IMAGES 32 29 30 /* Maximum size of a rvt image - 64 KiB. */ 31 #define RVT_MAX_SIZE (64 * 1024) 32 33 /* Maximum size for hash parttion list, one is RVT and the other for null pointer. */ 34 #define REQUEST_LIST_LEN 2 35 36 enum hvb_errno { 37 HVB_OK, 38 HVB_ERROR_OOM, 39 HVB_ERROR_IO, 40 HVB_ERROR_VERIFY_SIGN, 41 HVB_ERROR_VERIFY_HASH, 42 HVB_ERROR_ROLLBACK_INDEX, 43 HVB_ERROR_PUBLIC_KEY_REJECTED, 44 HVB_ERROR_INVALID_CERT_FORMAT, 45 HVB_ERROR_INVALID_FOOTER_FORMAT, 46 HVB_ERROR_UNSUPPORTED_VERSION, 47 HVB_ERROR_INVALID_ARGUMENT, 48 }; 49 50 struct hvb_image_data { 51 char *partition_name; 52 struct hvb_buf data; 53 bool preloaded; 54 }; 55 56 struct hvb_cert_data { 57 char *partition_name; 58 struct hvb_buf data; 59 enum hvb_errno verify_result; 60 }; 61 62 struct hvb_cmdline_data { 63 char *buf; 64 uint64_t cur_pos; // the first avaliable pos in buf 65 uint64_t max_size; 66 }; 67 68 struct hvb_verified_data { 69 struct hvb_cert_data *certs; 70 uint64_t num_loaded_certs; 71 struct hvb_image_data *images; 72 uint64_t num_loaded_images; 73 struct hvb_cmdline_data cmdline; 74 uint64_t rollback_indexes[HVB_MAX_NUMBER_OF_ROLLBACK_INDEX_LOCATIONS]; 75 }; 76 77 enum hvb_errno hvb_chain_verify(struct hvb_ops *ops, const char *rvt_parttion_name, 78 const char *const *hash_ptn_list, 79 struct hvb_verified_data **out_data); 80 void hvb_chain_verify_data_free(struct hvb_verified_data *verified_data); 81 82 #ifdef __cplusplus 83 } 84 #endif 85 86 #endif 87