blob: 01fc41901eff2ac1f679c3583e2ccc6e547377ba [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)
28
29/* modes not supported by upstream kernel, so not in <linux/fs.h> */
30#define FS_ENCRYPTION_MODE_AES_256_HEH 126
31#define FS_ENCRYPTION_MODE_PRIVATE 127
32
33/* new definition, not yet in Bionic's <linux/fs.h> */
34#ifndef FS_ENCRYPTION_MODE_ADIANTUM
35#define FS_ENCRYPTION_MODE_ADIANTUM 9
36#endif
37
38/* new definition, not yet in Bionic's <linux/fs.h> */
39#ifndef FS_POLICY_FLAG_DIRECT_KEY
40#define FS_POLICY_FLAG_DIRECT_KEY 0x4
41#endif
42
43#define HEX_LOOKUP "0123456789abcdef"
44
45struct fscrypt_encryption_policy {
46 uint8_t version;
47 uint8_t contents_encryption_mode;
48 uint8_t filenames_encryption_mode;
49 uint8_t flags;
50 uint8_t master_key_descriptor[FS_KEY_DESCRIPTOR_SIZE];
51} __attribute__((packed));
52
53
54bool fscrypt_set_mode();
55bool lookup_ref_key(const uint8_t *policy, uint8_t* policy_type);
56bool lookup_ref_tar(const uint8_t *policy_type, uint8_t *policy);
57void policy_to_hex(const uint8_t* policy, char* hex);
58bool fscrypt_policy_get_struct(const char *directory, struct fscrypt_encryption_policy *fep);
59bool fscrypt_policy_set_struct(const char *directory, const struct fscrypt_encryption_policy *fep);
60void fscrypt_policy_fill_default_struct(struct fscrypt_encryption_policy *fep);
61__END_DECLS
62
63#endif // _FS_CRYPT_H_