blob: 5714790148fb858ffcb4adf9b85be26484a9cb44 [file] [log] [blame]
bigbiff7ba75002020-04-11 20:47:09 -04001/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _FS_CRYPT_H_
18#define _FS_CRYPT_H_
19
20#include <sys/cdefs.h>
21#include <stdbool.h>
22#include <cutils/multiuser.h>
23#include <linux/fs.h>
24
25__BEGIN_DECLS
26
27#define FS_KEY_DESCRIPTOR_SIZE_HEX (2 * FS_KEY_DESCRIPTOR_SIZE + 1)
bigbiffa957f072021-03-07 18:20:29 -050028#define FSCRYPT_KEY_IDENTIFIER_HEX_SIZE ((2 * FSCRYPT_KEY_IDENTIFIER_SIZE) + 1)
bigbiff7ba75002020-04-11 20:47:09 -040029
bigbiff2e344ab2021-05-07 10:41:55 -040030#ifdef USE_FSCRYPT_POLICY_V1
31#define USER_CE_FSCRYPT_POLICY "0CE"
32#define USER_DE_FSCRYPT_POLICY "0DE"
33#define SYSTEM_DE_FSCRYPT_POLICY "0DK"
34#else
35#define USER_CE_FSCRYPT_POLICY "2CE"
36#define USER_DE_FSCRYPT_POLICY "2DE"
37#define SYSTEM_DE_FSCRYPT_POLICY "2DK"
38#endif
39
40#define FSCRYPT_V1 "0"
41#define FSCRYPT_V2 "2"
42#define SYSTEM_DE_KEY "DK"
43#define USER_CE_KEY "C"
44#define USER_DE_KEY "D"
45
bigbiff7ba75002020-04-11 20:47:09 -040046/* modes not supported by upstream kernel, so not in <linux/fs.h> */
47#define FS_ENCRYPTION_MODE_AES_256_HEH 126
48#define FS_ENCRYPTION_MODE_PRIVATE 127
49
50/* new definition, not yet in Bionic's <linux/fs.h> */
51#ifndef FS_ENCRYPTION_MODE_ADIANTUM
52#define FS_ENCRYPTION_MODE_ADIANTUM 9
53#endif
54
55/* new definition, not yet in Bionic's <linux/fs.h> */
56#ifndef FS_POLICY_FLAG_DIRECT_KEY
57#define FS_POLICY_FLAG_DIRECT_KEY 0x4
58#endif
59
60#define HEX_LOOKUP "0123456789abcdef"
61
bigbiff7ba75002020-04-11 20:47:09 -040062bool fscrypt_set_mode();
bigbiffa957f072021-03-07 18:20:29 -050063
64#ifdef USE_FSCRYPT_POLICY_V1
65bool lookup_ref_key(struct fscrypt_policy_v1 *fep, uint8_t* policy_type);
66#else
67bool lookup_ref_key(struct fscrypt_policy_v2 *fep, uint8_t* policy_type);
68#endif
69
bigbiff7ba75002020-04-11 20:47:09 -040070bool lookup_ref_tar(const uint8_t *policy_type, uint8_t *policy);
bigbiffa957f072021-03-07 18:20:29 -050071
72#ifdef USE_FSCRYPT_POLICY_V1
73bool fscrypt_policy_get_struct(const char *directory, struct fscrypt_policy_v1 *fep);
74#else
75bool fscrypt_policy_get_struct(const char *directory, struct fscrypt_policy_v2 *fep);
76#endif
77
78#ifdef USE_FSCRYPT_POLICY_V1
79bool fscrypt_policy_set_struct(const char *directory, const struct fscrypt_policy_v1 *fep);
80#else
81bool fscrypt_policy_set_struct(const char *directory, const struct fscrypt_policy_v2 *fep);
82#endif
83
84void bytes_to_hex(const uint8_t *bytes, size_t num_bytes, char *hex);
bigbiff7ba75002020-04-11 20:47:09 -040085__END_DECLS
86
87#endif // _FS_CRYPT_H_