| 1 | /* |
| 2 | * EIF (Enclave Image Format) related helpers |
| 3 | * |
| 4 | * Copyright (c) 2024 Dorjoy Chowdhury <dorjoychy111@gmail.com> |
| 5 | * |
| 6 | * This work is licensed under the terms of the GNU GPL, version 2 or |
| 7 | * (at your option) any later version. See the COPYING file in the |
| 8 | * top-level directory. |
| 9 | */ |
| 10 | |
| 11 | #ifndef HW_CORE_EIF_H |
| 12 | #define HW_CORE_EIF_H |
| 13 | |
| 14 | #define MAX_SECTIONS 32 |
| 15 | #define EIF_HDR_ARCH_ARM64 0x1 |
| 16 | |
| 17 | /* members are ordered according to field order in .eif file */ |
| 18 | typedef struct EifHeader { |
| 19 | uint8_t magic[4]; /* must be .eif in ascii i.e., [46, 101, 105, 102] */ |
| 20 | uint16_t version; |
| 21 | uint16_t flags; |
| 22 | uint64_t default_memory; |
| 23 | uint64_t default_cpus; |
| 24 | uint16_t reserved; |
| 25 | uint16_t section_cnt; |
| 26 | uint64_t section_offsets[MAX_SECTIONS]; |
| 27 | uint64_t section_sizes[MAX_SECTIONS]; |
| 28 | uint32_t unused; |
| 29 | uint32_t eif_crc32; |
| 30 | } QEMU_PACKED EifHeader; |
| 31 | |
| 32 | /* members are ordered according to field order in .eif file */ |
| 33 | typedef struct EifSectionHeader { |
| 34 | /* |
| 35 | * 0 = invalid, 1 = kernel, 2 = cmdline, 3 = ramdisk, 4 = signature, |
| 36 | * 5 = metadata |
| 37 | */ |
| 38 | uint16_t section_type; |
| 39 | uint16_t flags; |
| 40 | uint64_t section_size; |
| 41 | } QEMU_PACKED EifSectionHeader; |
| 42 | |
| 43 | enum EifSectionTypes { |
| 44 | EIF_SECTION_INVALID = 0, |
| 45 | EIF_SECTION_KERNEL = 1, |
| 46 | EIF_SECTION_CMDLINE = 2, |
| 47 | EIF_SECTION_RAMDISK = 3, |
| 48 | EIF_SECTION_SIGNATURE = 4, |
| 49 | EIF_SECTION_METADATA = 5, |
| 50 | EIF_SECTION_MAX = 6, |
| 51 | }; |
| 52 | |
| 53 | #define EIF_MAGIC { '.', 'e', 'i', 'f' } |
| 54 | |
| 55 | bool read_eif_file(const char *eif_path, const char *machine_initrd, |
| 56 | char **kernel_path, char **initrd_path, |
| 57 | char **kernel_cmdline, uint8_t *image_sha384, |
| 58 | uint8_t *bootstrap_sha384, uint8_t *app_sha384, |
| 59 | uint8_t *fingerprint_sha384, bool *signature_found, |
| 60 | Error **errp); |
| 61 | |
| 62 | #endif |
| 63 |