blob: 463db7f987a28b53c44bef1f4b4a9bab80f76193 [file] [log] [blame]
Ken Sumrall8f869aa2010-12-03 03:47:09 -08001/*
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 Crowleyb64933a2017-10-31 08:25:55 -070017#ifndef ANDROID_VOLD_CRYPTFS_H
18#define ANDROID_VOLD_CRYPTFS_H
19
Paul Crowley81796e92020-02-07 11:27:49 -080020#include <string>
21
Logan Chien0267ccf2018-05-02 10:57:56 +080022#include <linux/types.h>
Paul Lawrence2f32cda2015-05-05 14:28:25 -070023#include <stdbool.h>
Greg Kaiser57f9af62018-02-16 13:13:58 -080024#include <stdint.h>
Logan Chien0267ccf2018-05-02 10:57:56 +080025
Ken Sumrall160b4d62013-04-22 12:15:39 -070026#include <cutils/properties.h>
27
Paul Crowley3d98f5d2020-02-07 11:49:09 -080028#include "KeyBuffer.h"
29
Ken Sumrall8f869aa2010-12-03 03:47:09 -080030#define CRYPT_FOOTER_OFFSET 0x4000
JP Abgrall502dc742013-11-01 13:06:20 -070031
Paul Lawrence74f29f12014-08-28 15:54:10 -070032/* Return values for cryptfs_crypto_complete */
Paul Crowley14c8c072018-09-18 13:30:21 -070033#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 Lawrence74f29f12014-08-28 15:54:10 -070039
Rubin Xu85c01f92014-10-13 12:49:54 +010040/* Return values for cryptfs_getfield */
Paul Crowley14c8c072018-09-18 13:30:21 -070041#define CRYPTO_GETFIELD_OK 0
42#define CRYPTO_GETFIELD_ERROR_NO_FIELD (-1)
43#define CRYPTO_GETFIELD_ERROR_OTHER (-2)
Chih-Hung Hsiehaae79382016-06-10 14:13:59 -070044#define CRYPTO_GETFIELD_ERROR_BUF_TOO_SMALL (-3)
Rubin Xu85c01f92014-10-13 12:49:54 +010045
46/* Return values for cryptfs_setfield */
Paul Crowley14c8c072018-09-18 13:30:21 -070047#define CRYPTO_SETFIELD_OK 0
48#define CRYPTO_SETFIELD_ERROR_OTHER (-1)
Chih-Hung Hsiehaae79382016-06-10 14:13:59 -070049#define CRYPTO_SETFIELD_ERROR_FIELD_TOO_LONG (-2)
50#define CRYPTO_SETFIELD_ERROR_VALUE_TOO_LONG (-3)
Rubin Xu85c01f92014-10-13 12:49:54 +010051
52/* Return values for persist_del_key */
Paul Crowley14c8c072018-09-18 13:30:21 -070053#define PERSIST_DEL_KEY_OK 0
54#define PERSIST_DEL_KEY_ERROR_OTHER (-1)
55#define PERSIST_DEL_KEY_ERROR_NO_FIELD (-2)
Rubin Xu85c01f92014-10-13 12:49:54 +010056
Paul Crowley73be12d2020-02-03 12:22:03 -080057// Exposed for testing only
Paul Crowleyb64933a2017-10-31 08:25:55 -070058int match_multi_entry(const char* key, const char* field, unsigned index);
Paul Lawrence2f32cda2015-05-05 14:28:25 -070059
Paul Crowleyb64933a2017-10-31 08:25:55 -070060int cryptfs_crypto_complete(void);
61int cryptfs_check_passwd(const char* pw);
62int cryptfs_verify_passwd(const char* pw);
63int cryptfs_restart(void);
Paul Lawrence7ee87cf2017-12-22 10:12:06 -080064int cryptfs_enable(int type, const char* passwd, int no_ui);
Paul Crowleyb64933a2017-10-31 08:25:55 -070065int cryptfs_changepw(int type, const char* newpw);
Paul Lawrence7ee87cf2017-12-22 10:12:06 -080066int cryptfs_enable_default(int no_ui);
Paul Crowley3d98f5d2020-02-07 11:49:09 -080067int cryptfs_setup_ext_volume(const char* label, const char* real_blkdev,
68 const android::vold::KeyBuffer& key, std::string* out_crypto_blkdev);
Paul Crowleyb64933a2017-10-31 08:25:55 -070069int cryptfs_revert_ext_volume(const char* label);
70int cryptfs_getfield(const char* fieldname, char* value, int len);
71int cryptfs_setfield(const char* fieldname, const char* value);
72int cryptfs_mount_default_encrypted(void);
73int cryptfs_get_password_type(void);
74const char* cryptfs_get_password(void);
75void cryptfs_clear_password(void);
76int cryptfs_isConvertibleToFBE(void);
Kenny Rootc4c70f12013-06-14 12:11:38 -070077
Greg Kaiser57f9af62018-02-16 13:13:58 -080078uint32_t cryptfs_get_keysize();
79const char* cryptfs_get_crypto_name();
80
Paul Crowleyb64933a2017-10-31 08:25:55 -070081#endif /* ANDROID_VOLD_CRYPTFS_H */