2 * Integrity header definition
4 * Copyright (C) 2016-2021 Milan Broz
6 * This file is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This file is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this file; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #ifndef _CRYPTSETUP_INTEGRITY_H
22 #define _CRYPTSETUP_INTEGRITY_H
28 struct crypt_params_integrity;
30 struct crypt_dm_active_device;
32 /* dm-integrity helper */
33 #define SB_MAGIC "integrt"
34 #define SB_VERSION_1 1
35 #define SB_VERSION_2 2
36 #define SB_VERSION_3 3
37 #define SB_VERSION_4 4
38 #define SB_VERSION_5 5
40 #define SB_FLAG_HAVE_JOURNAL_MAC (1 << 0)
41 #define SB_FLAG_RECALCULATING (1 << 1) /* V2 only */
42 #define SB_FLAG_DIRTY_BITMAP (1 << 2) /* V3 only */
43 #define SB_FLAG_FIXED_PADDING (1 << 3) /* V4 only */
44 #define SB_FLAG_FIXED_HMAC (1 << 4) /* V5 only */
49 int8_t log2_interleave_sectors;
50 uint16_t integrity_tag_size;
51 uint32_t journal_sections;
52 uint64_t provided_data_sectors;
54 uint8_t log2_sectors_per_block;
55 uint8_t log2_blocks_per_bitmap_bit; /* V3 only */
57 uint64_t recalc_sector; /* V2 only */
58 } __attribute__ ((packed));
60 int INTEGRITY_read_sb(struct crypt_device *cd,
61 struct crypt_params_integrity *params,
64 int INTEGRITY_dump(struct crypt_device *cd, struct device *device, uint64_t offset);
66 int INTEGRITY_data_sectors(struct crypt_device *cd,
67 struct device *device, uint64_t offset,
68 uint64_t *data_sectors);
69 int INTEGRITY_key_size(struct crypt_device *cd,
70 const char *integrity);
71 int INTEGRITY_tag_size(struct crypt_device *cd,
72 const char *integrity,
74 const char *cipher_mode);
75 int INTEGRITY_hash_tag_size(const char *integrity);
77 int INTEGRITY_format(struct crypt_device *cd,
78 const struct crypt_params_integrity *params,
79 struct volume_key *journal_crypt_key,
80 struct volume_key *journal_mac_key);
82 int INTEGRITY_activate(struct crypt_device *cd,
84 const struct crypt_params_integrity *params,
85 struct volume_key *vk,
86 struct volume_key *journal_crypt_key,
87 struct volume_key *journal_mac_key,
88 uint32_t flags, uint32_t sb_flags);
90 int INTEGRITY_create_dmd_device(struct crypt_device *cd,
91 const struct crypt_params_integrity *params,
92 struct volume_key *vk,
93 struct volume_key *journal_crypt_key,
94 struct volume_key *journal_mac_key,
95 struct crypt_dm_active_device *dmd,
96 uint32_t flags, uint32_t sb_flags);
98 int INTEGRITY_activate_dmd_device(struct crypt_device *cd,
101 struct crypt_dm_active_device *dmd,