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