Ken Sumrall | 8f869aa | 2010-12-03 03:47:09 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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 | |
Paul Crowley | b64933a | 2017-10-31 08:25:55 -0700 | [diff] [blame] | 17 | #ifndef ANDROID_VOLD_CRYPTFS_H |
| 18 | #define ANDROID_VOLD_CRYPTFS_H |
| 19 | |
Paul Crowley | 81796e9 | 2020-02-07 11:27:49 -0800 | [diff] [blame] | 20 | #include <string> |
| 21 | |
Logan Chien | 0267ccf | 2018-05-02 10:57:56 +0800 | [diff] [blame] | 22 | #include <linux/types.h> |
Paul Lawrence | 2f32cda | 2015-05-05 14:28:25 -0700 | [diff] [blame] | 23 | #include <stdbool.h> |
Greg Kaiser | 57f9af6 | 2018-02-16 13:13:58 -0800 | [diff] [blame] | 24 | #include <stdint.h> |
Logan Chien | 0267ccf | 2018-05-02 10:57:56 +0800 | [diff] [blame] | 25 | |
Ken Sumrall | 160b4d6 | 2013-04-22 12:15:39 -0700 | [diff] [blame] | 26 | #include <cutils/properties.h> |
| 27 | |
Ken Sumrall | 8f869aa | 2010-12-03 03:47:09 -0800 | [diff] [blame] | 28 | #define CRYPT_FOOTER_OFFSET 0x4000 |
JP Abgrall | 502dc74 | 2013-11-01 13:06:20 -0700 | [diff] [blame] | 29 | |
Paul Lawrence | 74f29f1 | 2014-08-28 15:54:10 -0700 | [diff] [blame] | 30 | /* Return values for cryptfs_crypto_complete */ |
Paul Crowley | 14c8c07 | 2018-09-18 13:30:21 -0700 | [diff] [blame] | 31 | #define CRYPTO_COMPLETE_NOT_ENCRYPTED 1 |
| 32 | #define CRYPTO_COMPLETE_ENCRYPTED 0 |
| 33 | #define CRYPTO_COMPLETE_BAD_METADATA (-1) |
| 34 | #define CRYPTO_COMPLETE_PARTIAL (-2) |
| 35 | #define CRYPTO_COMPLETE_INCONSISTENT (-3) |
| 36 | #define CRYPTO_COMPLETE_CORRUPT (-4) |
Paul Lawrence | 74f29f1 | 2014-08-28 15:54:10 -0700 | [diff] [blame] | 37 | |
Rubin Xu | 85c01f9 | 2014-10-13 12:49:54 +0100 | [diff] [blame] | 38 | /* Return values for cryptfs_getfield */ |
Paul Crowley | 14c8c07 | 2018-09-18 13:30:21 -0700 | [diff] [blame] | 39 | #define CRYPTO_GETFIELD_OK 0 |
| 40 | #define CRYPTO_GETFIELD_ERROR_NO_FIELD (-1) |
| 41 | #define CRYPTO_GETFIELD_ERROR_OTHER (-2) |
Chih-Hung Hsieh | aae7938 | 2016-06-10 14:13:59 -0700 | [diff] [blame] | 42 | #define CRYPTO_GETFIELD_ERROR_BUF_TOO_SMALL (-3) |
Rubin Xu | 85c01f9 | 2014-10-13 12:49:54 +0100 | [diff] [blame] | 43 | |
| 44 | /* Return values for cryptfs_setfield */ |
Paul Crowley | 14c8c07 | 2018-09-18 13:30:21 -0700 | [diff] [blame] | 45 | #define CRYPTO_SETFIELD_OK 0 |
| 46 | #define CRYPTO_SETFIELD_ERROR_OTHER (-1) |
Chih-Hung Hsieh | aae7938 | 2016-06-10 14:13:59 -0700 | [diff] [blame] | 47 | #define CRYPTO_SETFIELD_ERROR_FIELD_TOO_LONG (-2) |
| 48 | #define CRYPTO_SETFIELD_ERROR_VALUE_TOO_LONG (-3) |
Rubin Xu | 85c01f9 | 2014-10-13 12:49:54 +0100 | [diff] [blame] | 49 | |
| 50 | /* Return values for persist_del_key */ |
Paul Crowley | 14c8c07 | 2018-09-18 13:30:21 -0700 | [diff] [blame] | 51 | #define PERSIST_DEL_KEY_OK 0 |
| 52 | #define PERSIST_DEL_KEY_ERROR_OTHER (-1) |
| 53 | #define PERSIST_DEL_KEY_ERROR_NO_FIELD (-2) |
Rubin Xu | 85c01f9 | 2014-10-13 12:49:54 +0100 | [diff] [blame] | 54 | |
Paul Crowley | 73be12d | 2020-02-03 12:22:03 -0800 | [diff] [blame] | 55 | // Exposed for testing only |
Paul Crowley | b64933a | 2017-10-31 08:25:55 -0700 | [diff] [blame] | 56 | int match_multi_entry(const char* key, const char* field, unsigned index); |
Paul Lawrence | 2f32cda | 2015-05-05 14:28:25 -0700 | [diff] [blame] | 57 | |
Paul Crowley | b64933a | 2017-10-31 08:25:55 -0700 | [diff] [blame] | 58 | int cryptfs_crypto_complete(void); |
| 59 | int cryptfs_check_passwd(const char* pw); |
| 60 | int cryptfs_verify_passwd(const char* pw); |
| 61 | int cryptfs_restart(void); |
Paul Lawrence | 7ee87cf | 2017-12-22 10:12:06 -0800 | [diff] [blame] | 62 | int cryptfs_enable(int type, const char* passwd, int no_ui); |
Paul Crowley | b64933a | 2017-10-31 08:25:55 -0700 | [diff] [blame] | 63 | int cryptfs_changepw(int type, const char* newpw); |
Paul Lawrence | 7ee87cf | 2017-12-22 10:12:06 -0800 | [diff] [blame] | 64 | int cryptfs_enable_default(int no_ui); |
Paul Crowley | b64933a | 2017-10-31 08:25:55 -0700 | [diff] [blame] | 65 | int cryptfs_setup_ext_volume(const char* label, const char* real_blkdev, const unsigned char* key, |
Paul Crowley | 81796e9 | 2020-02-07 11:27:49 -0800 | [diff] [blame] | 66 | std::string* out_crypto_blkdev); |
Paul Crowley | b64933a | 2017-10-31 08:25:55 -0700 | [diff] [blame] | 67 | int cryptfs_revert_ext_volume(const char* label); |
| 68 | int cryptfs_getfield(const char* fieldname, char* value, int len); |
| 69 | int cryptfs_setfield(const char* fieldname, const char* value); |
| 70 | int cryptfs_mount_default_encrypted(void); |
| 71 | int cryptfs_get_password_type(void); |
| 72 | const char* cryptfs_get_password(void); |
| 73 | void cryptfs_clear_password(void); |
| 74 | int cryptfs_isConvertibleToFBE(void); |
Kenny Root | c4c70f1 | 2013-06-14 12:11:38 -0700 | [diff] [blame] | 75 | |
Greg Kaiser | 57f9af6 | 2018-02-16 13:13:58 -0800 | [diff] [blame] | 76 | uint32_t cryptfs_get_keysize(); |
| 77 | const char* cryptfs_get_crypto_name(); |
| 78 | |
Paul Crowley | b64933a | 2017-10-31 08:25:55 -0700 | [diff] [blame] | 79 | #endif /* ANDROID_VOLD_CRYPTFS_H */ |