Badhri Jagan Sridharan | 8bb45a5 | 2015-12-14 20:09:39 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 Google, Inc. |
| 3 | * |
| 4 | * This software is licensed under the terms of the GNU General Public |
| 5 | * License version 2, as published by the Free Software Foundation, and |
| 6 | * may be copied, distributed, and modified under those terms. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | */ |
| 14 | |
| 15 | #ifndef DM_ANDROID_VERITY_H |
| 16 | #define DM_ANDROID_VERITY_H |
| 17 | |
| 18 | #include <crypto/sha.h> |
| 19 | |
| 20 | #define RSANUMBYTES 256 |
| 21 | #define VERITY_METADATA_MAGIC_NUMBER 0xb001b001 |
| 22 | #define VERITY_METADATA_MAGIC_DISABLE 0x46464f56 |
| 23 | #define VERITY_METADATA_VERSION 0 |
| 24 | #define VERITY_STATE_DISABLE 1 |
| 25 | #define DATA_BLOCK_SIZE (4 * 1024) |
| 26 | #define VERITY_METADATA_SIZE (8 * DATA_BLOCK_SIZE) |
| 27 | #define VERITY_TABLE_ARGS 10 |
| 28 | #define VERITY_COMMANDLINE_PARAM_LENGTH 20 |
| 29 | |
| 30 | #define FEC_MAGIC 0xFECFECFE |
| 31 | #define FEC_BLOCK_SIZE (4 * 1024) |
| 32 | #define FEC_VERSION 0 |
| 33 | #define FEC_RSM 255 |
| 34 | #define FEC_ARG_LENGTH 300 |
| 35 | |
| 36 | #define VERITY_TABLE_OPT_RESTART "restart_on_corruption" |
| 37 | #define VERITY_TABLE_OPT_LOGGING "ignore_corruption" |
| 38 | #define VERITY_TABLE_OPT_IGNZERO "ignore_zero_blocks" |
| 39 | |
| 40 | #define VERITY_TABLE_OPT_FEC_FORMAT \ |
| 41 | "use_fec_from_device %s fec_start %llu fec_blocks %llu fec_roots %u ignore_zero_blocks" |
| 42 | #define VERITY_TABLE_OPT_FEC_ARGS 9 |
| 43 | |
| 44 | #define VERITY_DEBUG 0 |
| 45 | |
| 46 | #define DM_MSG_PREFIX "android-verity" |
Badhri Jagan Sridharan | d0706bc | 2016-03-21 10:55:23 -0700 | [diff] [blame] | 47 | |
| 48 | #define DM_LINEAR_ARGS 2 |
Badhri Jagan Sridharan | 7e70218 | 2016-03-28 14:41:21 -0700 | [diff] [blame] | 49 | #define DM_LINEAR_TARGET_OFFSET "0" |
| 50 | |
Badhri Jagan Sridharan | 8bb45a5 | 2015-12-14 20:09:39 -0800 | [diff] [blame] | 51 | /* |
| 52 | * There can be two formats. |
| 53 | * if fec is present |
| 54 | * <data_blocks> <verity_tree> <verity_metdata_32K><fec_data><fec_data_4K> |
| 55 | * if fec is not present |
| 56 | * <data_blocks> <verity_tree> <verity_metdata_32K> |
| 57 | */ |
| 58 | /* TODO: rearrange structure to reduce memory holes |
| 59 | * depends on userspace change. |
| 60 | */ |
| 61 | struct fec_header { |
| 62 | __le32 magic; |
| 63 | __le32 version; |
| 64 | __le32 size; |
| 65 | __le32 roots; |
| 66 | __le32 fec_size; |
| 67 | __le64 inp_size; |
| 68 | u8 hash[SHA256_DIGEST_SIZE]; |
| 69 | }; |
| 70 | |
| 71 | struct android_metadata_header { |
| 72 | __le32 magic_number; |
| 73 | __le32 protocol_version; |
| 74 | char signature[RSANUMBYTES]; |
| 75 | __le32 table_length; |
| 76 | }; |
| 77 | |
| 78 | struct android_metadata { |
| 79 | struct android_metadata_header *header; |
| 80 | char *verity_table; |
| 81 | }; |
| 82 | |
| 83 | struct fec_ecc_metadata { |
| 84 | bool valid; |
| 85 | u32 roots; |
| 86 | u64 blocks; |
| 87 | u64 rounds; |
| 88 | u64 start; |
| 89 | }; |
| 90 | |
| 91 | struct bio_read { |
| 92 | struct page **page_io; |
| 93 | int number_of_pages; |
| 94 | }; |
| 95 | |
Badhri Jagan Sridharan | d0706bc | 2016-03-21 10:55:23 -0700 | [diff] [blame] | 96 | extern struct target_type linear_target; |
Badhri Jagan Sridharan | 67584ff | 2016-04-05 11:18:16 -0700 | [diff] [blame^] | 97 | |
| 98 | extern void dm_linear_dtr(struct dm_target *ti); |
| 99 | extern int dm_linear_map(struct dm_target *ti, struct bio *bio); |
| 100 | extern void dm_linear_status(struct dm_target *ti, status_type_t type, |
| 101 | unsigned status_flags, char *result, unsigned maxlen); |
| 102 | extern int dm_linear_ioctl(struct dm_target *ti, unsigned int cmd, |
| 103 | unsigned long arg); |
| 104 | extern int dm_linear_merge(struct dm_target *ti, struct bvec_merge_data *bvm, |
| 105 | struct bio_vec *biovec, int max_size); |
| 106 | extern int dm_linear_iterate_devices(struct dm_target *ti, |
| 107 | iterate_devices_callout_fn fn, void *data); |
| 108 | extern int dm_linear_ctr(struct dm_target *ti, unsigned int argc, char **argv); |
Badhri Jagan Sridharan | 8bb45a5 | 2015-12-14 20:09:39 -0800 | [diff] [blame] | 109 | #endif /* DM_ANDROID_VERITY_H */ |