blob: c99ce2ecc8b3d9609f34d2aae91a53df728b8f36 [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
30/* modes not supported by upstream kernel, so not in <linux/fs.h> */
31#define FS_ENCRYPTION_MODE_AES_256_HEH 126
32#define FS_ENCRYPTION_MODE_PRIVATE 127
33
34/* new definition, not yet in Bionic's <linux/fs.h> */
35#ifndef FS_ENCRYPTION_MODE_ADIANTUM
36#define FS_ENCRYPTION_MODE_ADIANTUM 9
37#endif
38
39/* new definition, not yet in Bionic's <linux/fs.h> */
40#ifndef FS_POLICY_FLAG_DIRECT_KEY
41#define FS_POLICY_FLAG_DIRECT_KEY 0x4
42#endif
43
44#define HEX_LOOKUP "0123456789abcdef"
45
bigbiff7ba75002020-04-11 20:47:09 -040046bool fscrypt_set_mode();
bigbiffa957f072021-03-07 18:20:29 -050047
48#ifdef USE_FSCRYPT_POLICY_V1
49bool lookup_ref_key(struct fscrypt_policy_v1 *fep, uint8_t* policy_type);
50#else
51bool lookup_ref_key(struct fscrypt_policy_v2 *fep, uint8_t* policy_type);
52#endif
53
bigbiff7ba75002020-04-11 20:47:09 -040054bool lookup_ref_tar(const uint8_t *policy_type, uint8_t *policy);
bigbiffa957f072021-03-07 18:20:29 -050055
56#ifdef USE_FSCRYPT_POLICY_V1
57bool fscrypt_policy_get_struct(const char *directory, struct fscrypt_policy_v1 *fep);
58#else
59bool fscrypt_policy_get_struct(const char *directory, struct fscrypt_policy_v2 *fep);
60#endif
61
62#ifdef USE_FSCRYPT_POLICY_V1
63bool fscrypt_policy_set_struct(const char *directory, const struct fscrypt_policy_v1 *fep);
64#else
65bool fscrypt_policy_set_struct(const char *directory, const struct fscrypt_policy_v2 *fep);
66#endif
67
68void bytes_to_hex(const uint8_t *bytes, size_t num_bytes, char *hex);
bigbiff7ba75002020-04-11 20:47:09 -040069__END_DECLS
70
71#endif // _FS_CRYPT_H_