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 
17 #ifndef ANDROID_VOLD_CRYPTFS_H
18 #define ANDROID_VOLD_CRYPTFS_H
19 
20 #include <string>
21 
22 #include <linux/types.h>
23 #include <stdbool.h>
24 #include <stdint.h>
25 
26 #include <cutils/properties.h>
27 
28 #include "KeyBuffer.h"
29 #include "KeyUtil.h"
30 
31 #define CRYPT_FOOTER_OFFSET 0x4000
32 
33 /* Return values for cryptfs_crypto_complete */
34 #define CRYPTO_COMPLETE_NOT_ENCRYPTED 1
35 #define CRYPTO_COMPLETE_ENCRYPTED 0
36 #define CRYPTO_COMPLETE_BAD_METADATA (-1)
37 #define CRYPTO_COMPLETE_PARTIAL (-2)
38 #define CRYPTO_COMPLETE_INCONSISTENT (-3)
39 #define CRYPTO_COMPLETE_CORRUPT (-4)
40 
41 /* Return values for cryptfs_getfield */
42 #define CRYPTO_GETFIELD_OK 0
43 #define CRYPTO_GETFIELD_ERROR_NO_FIELD (-1)
44 #define CRYPTO_GETFIELD_ERROR_OTHER (-2)
45 #define CRYPTO_GETFIELD_ERROR_BUF_TOO_SMALL (-3)
46 
47 /* Return values for cryptfs_setfield */
48 #define CRYPTO_SETFIELD_OK 0
49 #define CRYPTO_SETFIELD_ERROR_OTHER (-1)
50 #define CRYPTO_SETFIELD_ERROR_FIELD_TOO_LONG (-2)
51 #define CRYPTO_SETFIELD_ERROR_VALUE_TOO_LONG (-3)
52 
53 /* Return values for persist_del_key */
54 #define PERSIST_DEL_KEY_OK 0
55 #define PERSIST_DEL_KEY_ERROR_OTHER (-1)
56 #define PERSIST_DEL_KEY_ERROR_NO_FIELD (-2)
57 
58 // Exposed for testing only
59 int match_multi_entry(const char* key, const char* field, unsigned index);
60 
61 int cryptfs_crypto_complete(void);
62 int cryptfs_check_passwd(const char* pw);
63 int cryptfs_verify_passwd(const char* pw);
64 int cryptfs_restart(void);
65 int cryptfs_enable(int type, const char* passwd, int no_ui);
66 int cryptfs_changepw(int type, const char* newpw);
67 int cryptfs_enable_default(int no_ui);
68 int cryptfs_setup_ext_volume(const char* label, const char* real_blkdev,
69                              const android::vold::KeyBuffer& key, std::string* out_crypto_blkdev);
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);
77 const android::vold::KeyGeneration cryptfs_get_keygen();
78 
79 #endif /* ANDROID_VOLD_CRYPTFS_H */
80