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