Imported Upstream version 2.3.7
[platform/upstream/cryptsetup.git] / lib / bitlk / bitlk.h
1 /*
2  * BITLK (BitLocker-compatible) header definition
3  *
4  * Copyright (C) 2019-2021 Red Hat, Inc. All rights reserved.
5  * Copyright (C) 2019-2021 Milan Broz
6  * Copyright (C) 2019-2021 Vojtech Trefny
7  *
8  * This file is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This file is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this file; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23 #ifndef _CRYPTSETUP_BITLK_H
24 #define _CRYPTSETUP_BITLK_H
25
26 #include <stddef.h>
27 #include <stdint.h>
28 #include <stdbool.h>
29
30 struct crypt_device;
31 struct device;
32
33 #define BITLK_NONCE_SIZE 12
34 #define BITLK_SALT_SIZE 16
35 #define BITLK_VMK_MAC_TAG_SIZE 16
36
37 #define BITLK_STATE_NORMAL 0x0004
38
39 typedef enum {
40         BITLK_ENCRYPTION_TYPE_NORMAL = 0,
41         BITLK_ENCRYPTION_TYPE_EOW,
42         BITLK_ENCRYPTION_TYPE_UNKNOWN,
43 } BITLKEncryptionType;
44
45 typedef enum {
46         BITLK_PROTECTION_CLEAR_KEY = 0,
47         BITLK_PROTECTION_TPM,
48         BITLK_PROTECTION_STARTUP_KEY,
49         BITLK_PROTECTION_TPM_PIN,
50         BITLK_PROTECTION_RECOVERY_PASSPHRASE,
51         BITLK_PROTECTION_PASSPHRASE,
52         BITLK_PROTECTION_SMART_CARD,
53         BITLK_PROTECTION_UNKNOWN,
54 } BITLKVMKProtection;
55
56 typedef enum {
57         BITLK_ENTRY_TYPE_PROPERTY = 0x0000,
58         BITLK_ENTRY_TYPE_VMK = 0x0002,
59         BITLK_ENTRY_TYPE_FVEK = 0x0003,
60         BITLK_ENTRY_TYPE_STARTUP_KEY = 0x0006,
61         BITLK_ENTRY_TYPE_DESCRIPTION = 0x0007,
62         BITLK_ENTRY_TYPE_VOLUME_HEADER = 0x000f,
63 } BITLKFVEEntryType;
64
65 typedef enum {
66         BITLK_ENTRY_VALUE_ERASED = 0x0000,
67         BITLK_ENTRY_VALUE_KEY = 0x0001,
68         BITLK_ENTRY_VALUE_STRING = 0x0002,
69         BITLK_ENTRY_VALUE_STRETCH_KEY = 0x0003,
70         BITLK_ENTRY_VALUE_USE_KEY = 0x0004,
71         BITLK_ENTRY_VALUE_ENCRYPTED_KEY = 0x0005,
72         BITLK_ENTRY_VALUE_TPM_KEY = 0x0006,
73         BITLK_ENTRY_VALUE_VALIDATION = 0x0007,
74         BITLK_ENTRY_VALUE_VMK = 0x0008,
75         BITLK_ENTRY_VALUE_EXTERNAL_KEY = 0x0009,
76         BITLK_ENTRY_VALUE_OFFSET_SIZE = 0x000f,
77         BITLK_ENTRY_VALUE_RECOVERY_TIME = 0x015,
78 } BITLKFVEEntryValue;
79
80 struct bitlk_vmk {
81         char *guid;
82         char *name;
83         BITLKVMKProtection protection;
84         uint8_t salt[BITLK_SALT_SIZE];
85         uint8_t mac_tag[BITLK_VMK_MAC_TAG_SIZE];
86         uint8_t nonce[BITLK_NONCE_SIZE];
87         struct volume_key *vk;
88         struct bitlk_vmk *next;
89 };
90
91 struct bitlk_fvek {
92         uint8_t mac_tag[BITLK_VMK_MAC_TAG_SIZE];
93         uint8_t nonce[BITLK_NONCE_SIZE];
94         struct volume_key *vk;
95 };
96
97 struct bitlk_metadata {
98         uint16_t sector_size;
99         bool togo;
100         bool state;
101         BITLKEncryptionType type;
102         const char *cipher;
103         const char *cipher_mode;
104         uint16_t key_size;
105         char *guid;
106         uint64_t creation_time;
107         char *description;
108         uint64_t metadata_offset[3];
109         uint32_t metadata_version;
110         uint64_t volume_header_offset;
111         uint64_t volume_header_size;
112         struct bitlk_vmk *vmks;
113         struct bitlk_fvek *fvek;
114 };
115
116 int BITLK_read_sb(struct crypt_device *cd, struct bitlk_metadata *params);
117
118 int BITLK_dump(struct crypt_device *cd, struct device *device, struct bitlk_metadata *params);
119
120 int BITLK_activate(struct crypt_device *cd,
121                    const char *name,
122                    const char *password,
123                    size_t passwordLen,
124                    const struct bitlk_metadata *params,
125                    uint32_t flags);
126
127 void BITLK_bitlk_fvek_free(struct bitlk_fvek *fvek);
128 void BITLK_bitlk_vmk_free(struct bitlk_vmk *vmk);
129 void BITLK_bitlk_metadata_free(struct bitlk_metadata *params);
130
131 #endif