blob: c35d1157117c87a8807b339aab8682bbdb496556 [file] [log] [blame]
Ethan Yonker79f88bd2016-12-09 14:52:12 -06001/*
2 * Copyright (C) 2016 Team Win Recovery 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 __EXT4CRYPT_TAR_H
18#define __EXT4CRYPT_TAR_H
19
20#include <sys/cdefs.h>
21#include <stdbool.h>
22#include <cutils/multiuser.h>
23
Ethan Yonkerfefe5912017-09-30 22:22:13 -050024// ext4enc:TODO Include structure from somewhere sensible
25// MUST be in sync with ext4_crypto.c in kernel
26#define EXT4_KEY_DESCRIPTOR_SIZE 8
27#define EXT4_KEY_DESCRIPTOR_SIZE_HEX 17
28
29// ext4enc:TODO Get value from somewhere sensible
30#define EXT4_IOC_SET_ENCRYPTION_POLICY _IOR('f', 19, struct ext4_encryption_policy)
31#define EXT4_IOC_GET_ENCRYPTION_POLICY _IOW('f', 21, struct ext4_encryption_policy)
32
Ethan Yonker79f88bd2016-12-09 14:52:12 -060033__BEGIN_DECLS
34
Ethan Yonkerfefe5912017-09-30 22:22:13 -050035struct ext4_encryption_policy {
36 char version;
37 char contents_encryption_mode;
38 char filenames_encryption_mode;
39 char flags;
40 char master_key_descriptor[EXT4_KEY_DESCRIPTOR_SIZE];
41} __attribute__((__packed__));
42
Ethan Yonker79f88bd2016-12-09 14:52:12 -060043bool lookup_ref_key(const char* policy, char* policy_type);
44bool lookup_ref_tar(const char* policy_type, char* policy);
45
46void policy_to_hex(const char* policy, char* hex);
47bool e4crypt_policy_set(const char *directory, const char *policy,
48 size_t policy_length, int contents_encryption_mode);
49bool e4crypt_policy_get(const char *directory, char *policy,
50 size_t policy_length, int contents_encryption_mode);
Ethan Yonkerfefe5912017-09-30 22:22:13 -050051void e4crypt_policy_fill_default_struct(struct ext4_encryption_policy *eep);
52bool e4crypt_policy_set_struct(const char *directory, const struct ext4_encryption_policy *eep);
53bool e4crypt_policy_get_struct(const char *directory, struct ext4_encryption_policy *eep);
Ethan Yonker79f88bd2016-12-09 14:52:12 -060054
55bool e4crypt_set_mode();
56__END_DECLS
57
58#endif