blob: 872806e59a505c8292e45bb58c548faf706344e2 [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"
Paul Crowley4eac2642020-02-12 11:04:05 -080029#include "KeyUtil.h"
Paul Crowley3d98f5d2020-02-07 11:49:09 -080030
Ken Sumrall8f869aa2010-12-03 03:47:09 -080031#define CRYPT_FOOTER_OFFSET 0x4000
JP Abgrall502dc742013-11-01 13:06:20 -070032
Paul Lawrence74f29f12014-08-28 15:54:10 -070033/* Return values for cryptfs_crypto_complete */
Paul Crowley14c8c072018-09-18 13:30:21 -070034#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)
Paul Lawrence74f29f12014-08-28 15:54:10 -070040
Rubin Xu85c01f92014-10-13 12:49:54 +010041/* Return values for cryptfs_getfield */
Paul Crowley14c8c072018-09-18 13:30:21 -070042#define CRYPTO_GETFIELD_OK 0
43#define CRYPTO_GETFIELD_ERROR_NO_FIELD (-1)
44#define CRYPTO_GETFIELD_ERROR_OTHER (-2)
Chih-Hung Hsiehaae79382016-06-10 14:13:59 -070045#define CRYPTO_GETFIELD_ERROR_BUF_TOO_SMALL (-3)
Rubin Xu85c01f92014-10-13 12:49:54 +010046
47/* Return values for cryptfs_setfield */
Paul Crowley14c8c072018-09-18 13:30:21 -070048#define CRYPTO_SETFIELD_OK 0
49#define CRYPTO_SETFIELD_ERROR_OTHER (-1)
Chih-Hung Hsiehaae79382016-06-10 14:13:59 -070050#define CRYPTO_SETFIELD_ERROR_FIELD_TOO_LONG (-2)
51#define CRYPTO_SETFIELD_ERROR_VALUE_TOO_LONG (-3)
Rubin Xu85c01f92014-10-13 12:49:54 +010052
53/* Return values for persist_del_key */
Paul Crowley14c8c072018-09-18 13:30:21 -070054#define PERSIST_DEL_KEY_OK 0
55#define PERSIST_DEL_KEY_ERROR_OTHER (-1)
56#define PERSIST_DEL_KEY_ERROR_NO_FIELD (-2)
Rubin Xu85c01f92014-10-13 12:49:54 +010057
Paul Crowley73be12d2020-02-03 12:22:03 -080058// Exposed for testing only
Paul Crowleyb64933a2017-10-31 08:25:55 -070059int match_multi_entry(const char* key, const char* field, unsigned index);
Paul Lawrence2f32cda2015-05-05 14:28:25 -070060
Paul Crowleyb64933a2017-10-31 08:25:55 -070061int cryptfs_crypto_complete(void);
62int cryptfs_check_passwd(const char* pw);
63int cryptfs_verify_passwd(const char* pw);
64int cryptfs_restart(void);
Paul Lawrence7ee87cf2017-12-22 10:12:06 -080065int cryptfs_enable(int type, const char* passwd, int no_ui);
Paul Crowleyb64933a2017-10-31 08:25:55 -070066int cryptfs_changepw(int type, const char* newpw);
Paul Lawrence7ee87cf2017-12-22 10:12:06 -080067int cryptfs_enable_default(int no_ui);
Paul Crowley3d98f5d2020-02-07 11:49:09 -080068int cryptfs_setup_ext_volume(const char* label, const char* real_blkdev,
69 const android::vold::KeyBuffer& key, std::string* out_crypto_blkdev);
Paul Crowleyb64933a2017-10-31 08:25:55 -070070int 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);
Paul Crowley4eac2642020-02-12 11:04:05 -080077const android::vold::KeyGeneration cryptfs_get_keygen();
Greg Kaiser57f9af62018-02-16 13:13:58 -080078
Paul Crowleyb64933a2017-10-31 08:25:55 -070079#endif /* ANDROID_VOLD_CRYPTFS_H */