bigbiff | 7ba7500 | 2020-04-11 20:47:09 -0400 | [diff] [blame] | 1 | /* |
| 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) |
bigbiff | a957f07 | 2021-03-07 18:20:29 -0500 | [diff] [blame] | 28 | #define FSCRYPT_KEY_IDENTIFIER_HEX_SIZE ((2 * FSCRYPT_KEY_IDENTIFIER_SIZE) + 1) |
bigbiff | 7ba7500 | 2020-04-11 20:47:09 -0400 | [diff] [blame] | 29 | |
bigbiff | 2e344ab | 2021-05-07 10:41:55 -0400 | [diff] [blame] | 30 | #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 | |
bigbiff | 7ba7500 | 2020-04-11 20:47:09 -0400 | [diff] [blame] | 46 | /* 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 | |
bigbiff | 7ba7500 | 2020-04-11 20:47:09 -0400 | [diff] [blame] | 62 | bool fscrypt_set_mode(); |
bigbiff | a957f07 | 2021-03-07 18:20:29 -0500 | [diff] [blame] | 63 | |
| 64 | #ifdef USE_FSCRYPT_POLICY_V1 |
| 65 | bool lookup_ref_key(struct fscrypt_policy_v1 *fep, uint8_t* policy_type); |
| 66 | #else |
| 67 | bool lookup_ref_key(struct fscrypt_policy_v2 *fep, uint8_t* policy_type); |
| 68 | #endif |
| 69 | |
bigbiff | 7ba7500 | 2020-04-11 20:47:09 -0400 | [diff] [blame] | 70 | bool lookup_ref_tar(const uint8_t *policy_type, uint8_t *policy); |
bigbiff | a957f07 | 2021-03-07 18:20:29 -0500 | [diff] [blame] | 71 | |
| 72 | #ifdef USE_FSCRYPT_POLICY_V1 |
| 73 | bool fscrypt_policy_get_struct(const char *directory, struct fscrypt_policy_v1 *fep); |
| 74 | #else |
| 75 | bool fscrypt_policy_get_struct(const char *directory, struct fscrypt_policy_v2 *fep); |
| 76 | #endif |
| 77 | |
| 78 | #ifdef USE_FSCRYPT_POLICY_V1 |
| 79 | bool fscrypt_policy_set_struct(const char *directory, const struct fscrypt_policy_v1 *fep); |
| 80 | #else |
| 81 | bool fscrypt_policy_set_struct(const char *directory, const struct fscrypt_policy_v2 *fep); |
| 82 | #endif |
| 83 | |
| 84 | void bytes_to_hex(const uint8_t *bytes, size_t num_bytes, char *hex); |
bigbiff | 7ba7500 | 2020-04-11 20:47:09 -0400 | [diff] [blame] | 85 | __END_DECLS |
| 86 | |
| 87 | #endif // _FS_CRYPT_H_ |