-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathluks.c
More file actions
46 lines (40 loc) · 1.29 KB
/
luks.c
File metadata and controls
46 lines (40 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// SPDX-License-Identifier: GPL-2.0
/*
* fs/partitions/luks.c
* LUKS on raw partition; this is important because a LUKS volume may detected
* as a valid Atari partition table, breaking other detection.
*
* Copyright (C) 2025 Robin H. Johnson ([email protected])
*
* Reference: https://gitlab.com/cryptsetup/LUKS2-docs/blob/master/luks2_doc_wip.pdf
* Page 5, Figure 2: LUKS2 binary header on-disk structure
* This only looks for the Magic & version; and NOT a UUID that starts at
* offset 0xA8.
*/
#include <linux/ctype.h>
#include <linux/compiler.h>
#include "check.h"
#define LUKS_MAGIC_1ST_V1 "LUKS\xba\xbe\x00\x01"
#define LUKS_MAGIC_1ST_V2 "LUKS\xba\xbe\x00\x02"
#define LUKS_MAGIC_2ND_V1 "SKUL\xba\xbe\x00\x01"
#define LUKS_MAGIC_2ND_V2 "SKUL\xba\xbe\x00\x02"
int luks_partition(struct parsed_partitions *state)
{
Sector sect;
int ret = 0;
unsigned char *data;
data = read_part_sector(state, 0, §);
if (!data)
return -1;
if (memcmp(data, LUKS_MAGIC_1ST_V1, 8) == 0
|| memcmp(data, LUKS_MAGIC_2ND_V1, 8) == 0) {
strlcat(state->pp_buf, "LUKSv1\n", PAGE_SIZE);
ret = 1;
} else if (memcmp(data, LUKS_MAGIC_1ST_V2, 8) == 0
|| memcmp(data, LUKS_MAGIC_2ND_V2, 8) == 0) {
strlcat(state->pp_buf, "LUKSv2\n", PAGE_SIZE);
ret = 1;
}
put_dev_sector(sect);
return ret;
}