17310c0d0Sopenharmony_ci/* 27310c0d0Sopenharmony_ci * Copyright (c) 2022-2023 Huawei Device Co., Ltd. 37310c0d0Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 47310c0d0Sopenharmony_ci * you may not use this file except in compliance with the License. 57310c0d0Sopenharmony_ci * You may obtain a copy of the License at 67310c0d0Sopenharmony_ci * 77310c0d0Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 87310c0d0Sopenharmony_ci * 97310c0d0Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 107310c0d0Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 117310c0d0Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 127310c0d0Sopenharmony_ci * See the License for the specific language governing permissions and 137310c0d0Sopenharmony_ci * limitations under the License. 147310c0d0Sopenharmony_ci */ 157310c0d0Sopenharmony_ci#ifndef __HVB_RVT_H_ 167310c0d0Sopenharmony_ci#define __HVB_RVT_H_ 177310c0d0Sopenharmony_ci 187310c0d0Sopenharmony_ci#include "hvb_cert.h" 197310c0d0Sopenharmony_ci#include "hvb_ops.h" 207310c0d0Sopenharmony_ci 217310c0d0Sopenharmony_ci#ifdef __cplusplus 227310c0d0Sopenharmony_ciextern "C" { 237310c0d0Sopenharmony_ci#endif 247310c0d0Sopenharmony_ci 257310c0d0Sopenharmony_ci/* Magic for the rvt image header. */ 267310c0d0Sopenharmony_ci#define RVT_MAGIC "rot" 277310c0d0Sopenharmony_ci#define RVT_MAGIC_LEN 4 287310c0d0Sopenharmony_ci#define RVT_RELEASE_SIZE 64 297310c0d0Sopenharmony_ci#define MAX_NUMBER_OF_RVT_IMAGES 32 307310c0d0Sopenharmony_ci#define PUBKEY_LEN 1040 317310c0d0Sopenharmony_ci#define PARTITION_NAME_LEN 64 327310c0d0Sopenharmony_ci 337310c0d0Sopenharmony_ci/* Maximum size of a rvt image - 64 KiB. */ 347310c0d0Sopenharmony_ci#define RVT_MAX_SIZE (64 * 1024) 357310c0d0Sopenharmony_ci 367310c0d0Sopenharmony_cistruct rvt_pubk_desc { 377310c0d0Sopenharmony_ci /* The partition name of verity image. */ 387310c0d0Sopenharmony_ci char name[PARTITION_NAME_LEN]; 397310c0d0Sopenharmony_ci 407310c0d0Sopenharmony_ci /* Offset into the rvt_payload of pubkey from verity image. */ 417310c0d0Sopenharmony_ci uint64_t pubkey_offset; 427310c0d0Sopenharmony_ci 437310c0d0Sopenharmony_ci /* Length of the public key. */ 447310c0d0Sopenharmony_ci uint64_t pubkey_len; 457310c0d0Sopenharmony_ci 467310c0d0Sopenharmony_ci /* pubkey_payload. */ 477310c0d0Sopenharmony_ci uint8_t pubkey_payload[PUBKEY_LEN]; 487310c0d0Sopenharmony_ci} HVB_ATTR_PACKED; 497310c0d0Sopenharmony_ci 507310c0d0Sopenharmony_cistruct rvt_image_header { 517310c0d0Sopenharmony_ci /* Four bytes equal to "rot" (magic). */ 527310c0d0Sopenharmony_ci uint8_t magic[RVT_MAGIC_LEN]; 537310c0d0Sopenharmony_ci 547310c0d0Sopenharmony_ci /* The verity_num. */ 557310c0d0Sopenharmony_ci uint32_t verity_num; 567310c0d0Sopenharmony_ci 577310c0d0Sopenharmony_ci /* The reserved data, must be 0. */ 587310c0d0Sopenharmony_ci uint8_t rvt_reserved[RVT_RELEASE_SIZE]; 597310c0d0Sopenharmony_ci} HVB_ATTR_PACKED; 607310c0d0Sopenharmony_ci 617310c0d0Sopenharmony_cienum hvb_errno hvb_rvt_head_parser(const struct hvb_buf *rvt, struct rvt_image_header *dest, uint64_t desc_size); 627310c0d0Sopenharmony_cienum hvb_errno hvb_rvt_get_pubk_desc(const struct hvb_buf *rvt, struct hvb_buf *pubk_desc); 637310c0d0Sopenharmony_cienum hvb_errno hvb_rvt_pubk_desc_parser(const struct hvb_buf *pubk, struct rvt_pubk_desc *desc, uint64_t desc_size); 647310c0d0Sopenharmony_cienum hvb_errno hvb_rvt_get_pubk_buf(struct hvb_buf *key_buf, const struct hvb_buf *rvt, struct rvt_pubk_desc *desc); 657310c0d0Sopenharmony_cienum hvb_errno hvb_calculate_certs_digest(struct hvb_verified_data *vd, uint8_t *out_digest); 667310c0d0Sopenharmony_ci 677310c0d0Sopenharmony_ci#ifdef __cplusplus 687310c0d0Sopenharmony_ci} 697310c0d0Sopenharmony_ci#endif 707310c0d0Sopenharmony_ci 717310c0d0Sopenharmony_ci#endif /* HVB_RVT_H_ */ 72