1f496120812e745a98e44d24c06d2d0aab92c300
[platform/upstream/cryptsetup.git] / lib / integrity / integrity.h
1 /*
2  * Integrity header definition
3  *
4  * Copyright (C) 2016-2021 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 #define SB_VERSION_5    5
39
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 */
45
46 struct superblock {
47         uint8_t magic[8];
48         uint8_t version;
49         int8_t log2_interleave_sectors;
50         uint16_t integrity_tag_size;
51         uint32_t journal_sections;
52         uint64_t provided_data_sectors;
53         uint32_t flags;
54         uint8_t log2_sectors_per_block;
55         uint8_t log2_blocks_per_bitmap_bit; /* V3 only */
56         uint8_t pad[2];
57         uint64_t recalc_sector; /* V2 only */
58 } __attribute__ ((packed));
59
60 int INTEGRITY_read_sb(struct crypt_device *cd,
61                       struct crypt_params_integrity *params,
62                       uint32_t *flags);
63
64 int INTEGRITY_dump(struct crypt_device *cd, struct device *device, uint64_t offset);
65
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,
73                        const char *cipher,
74                        const char *cipher_mode);
75 int INTEGRITY_hash_tag_size(const char *integrity);
76
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);
81
82 int INTEGRITY_activate(struct crypt_device *cd,
83                        const char *name,
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);
89
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);
97
98 int INTEGRITY_activate_dmd_device(struct crypt_device *cd,
99                        const char *name,
100                        const char *type,
101                        struct crypt_dm_active_device *dmd,
102                        uint32_t sb_flags);
103 #endif