38c4c5eee73f43e1eca558a752b302dd9034f582
[platform/upstream/cryptsetup.git] / lib / integrity / integrity.h
1 /*
2  * Integrity header definition
3  *
4  * Copyright (C) 2016-2020 Milan Broz
5  *
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.
10  *
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.
15  *
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.
19  */
20
21 #ifndef _CRYPTSETUP_INTEGRITY_H
22 #define _CRYPTSETUP_INTEGRITY_H
23
24 #include <stdint.h>
25
26 struct crypt_device;
27 struct device;
28 struct crypt_params_integrity;
29 struct volume_key;
30 struct crypt_dm_active_device;
31
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
39 #define SB_FLAG_HAVE_JOURNAL_MAC        (1 << 0)
40 #define SB_FLAG_RECALCULATING           (1 << 1) /* V2 only */
41 #define SB_FLAG_DIRTY_BITMAP            (1 << 2) /* V3 only */
42 #define SB_FLAG_FIXED_PADDING           (1 << 3) /* V4 only */
43
44 struct superblock {
45         uint8_t magic[8];
46         uint8_t version;
47         int8_t log2_interleave_sectors;
48         uint16_t integrity_tag_size;
49         uint32_t journal_sections;
50         uint64_t provided_data_sectors;
51         uint32_t flags;
52         uint8_t log2_sectors_per_block;
53         uint8_t log2_blocks_per_bitmap_bit; /* V3 only */
54         uint8_t pad[2];
55         uint64_t recalc_sector; /* V2 only */
56 } __attribute__ ((packed));
57
58 int INTEGRITY_read_sb(struct crypt_device *cd,
59                       struct crypt_params_integrity *params,
60                       uint32_t *flags);
61
62 int INTEGRITY_dump(struct crypt_device *cd, struct device *device, uint64_t offset);
63
64 int INTEGRITY_data_sectors(struct crypt_device *cd,
65                            struct device *device, uint64_t offset,
66                            uint64_t *data_sectors);
67 int INTEGRITY_key_size(struct crypt_device *cd,
68                        const char *integrity);
69 int INTEGRITY_tag_size(struct crypt_device *cd,
70                        const char *integrity,
71                        const char *cipher,
72                        const char *cipher_mode);
73 int INTEGRITY_hash_tag_size(const char *integrity);
74
75 int INTEGRITY_format(struct crypt_device *cd,
76                      const struct crypt_params_integrity *params,
77                      struct volume_key *journal_crypt_key,
78                      struct volume_key *journal_mac_key);
79
80 int INTEGRITY_activate(struct crypt_device *cd,
81                        const char *name,
82                        const struct crypt_params_integrity *params,
83                        struct volume_key *vk,
84                        struct volume_key *journal_crypt_key,
85                        struct volume_key *journal_mac_key,
86                        uint32_t flags, uint32_t sb_flags);
87
88 int INTEGRITY_create_dmd_device(struct crypt_device *cd,
89                        const struct crypt_params_integrity *params,
90                        struct volume_key *vk,
91                        struct volume_key *journal_crypt_key,
92                        struct volume_key *journal_mac_key,
93                        struct crypt_dm_active_device *dmd,
94                        uint32_t flags, uint32_t sb_flags);
95
96 int INTEGRITY_activate_dmd_device(struct crypt_device *cd,
97                        const char *name,
98                        const char *type,
99                        struct crypt_dm_active_device *dmd,
100                        uint32_t sb_flags);
101 #endif