blob: d9ccff9dec282554ed2ad77be3f3cbc339af67a6 [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>
Ken Sumrall8f869aa2010-12-03 03:47:09 -080021
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 Crowleyb3d018a2020-02-12 11:04:05 -080029#include "KeyUtil.h"
Kenny Rootc96a5f82013-06-14 12:08:28 -070030
Ken Sumrall8f869aa2010-12-03 03:47:09 -080031#define CRYPT_FOOTER_OFFSET 0x4000
32
AnilKumar Chimata98dc8352018-05-11 00:25:09 +053033#ifdef CONFIG_HW_DISK_ENCRYPTION
34/* This flag is used to transition from L->M upgrade. L release passed
35 * a byte for every nible of user password while M release is passing
36 * ascii value of user password.
37 * Random flag value is chosen so that it does not conflict with other use cases
38 */
39#define CRYPT_ASCII_PASSWORD_UPDATED 0x1000
40#endif
Ken Sumrall8f869aa2010-12-03 03:47:09 -080041
Paul Lawrence74f29f12014-08-28 15:54:10 -070042/* Return values for cryptfs_crypto_complete */
Paul Crowley14c8c072018-09-18 13:30:21 -070043#define CRYPTO_COMPLETE_NOT_ENCRYPTED 1
44#define CRYPTO_COMPLETE_ENCRYPTED 0
45#define CRYPTO_COMPLETE_BAD_METADATA (-1)
46#define CRYPTO_COMPLETE_PARTIAL (-2)
47#define CRYPTO_COMPLETE_INCONSISTENT (-3)
48#define CRYPTO_COMPLETE_CORRUPT (-4)
Paul Lawrence74f29f12014-08-28 15:54:10 -070049
Rubin Xu85c01f92014-10-13 12:49:54 +010050/* Return values for cryptfs_getfield */
Paul Crowley14c8c072018-09-18 13:30:21 -070051#define CRYPTO_GETFIELD_OK 0
52#define CRYPTO_GETFIELD_ERROR_NO_FIELD (-1)
53#define CRYPTO_GETFIELD_ERROR_OTHER (-2)
Chih-Hung Hsiehaae79382016-06-10 14:13:59 -070054#define CRYPTO_GETFIELD_ERROR_BUF_TOO_SMALL (-3)
Rubin Xu85c01f92014-10-13 12:49:54 +010055
56/* Return values for cryptfs_setfield */
Paul Crowley14c8c072018-09-18 13:30:21 -070057#define CRYPTO_SETFIELD_OK 0
58#define CRYPTO_SETFIELD_ERROR_OTHER (-1)
Chih-Hung Hsiehaae79382016-06-10 14:13:59 -070059#define CRYPTO_SETFIELD_ERROR_FIELD_TOO_LONG (-2)
60#define CRYPTO_SETFIELD_ERROR_VALUE_TOO_LONG (-3)
Rubin Xu85c01f92014-10-13 12:49:54 +010061
62/* Return values for persist_del_key */
Paul Crowley14c8c072018-09-18 13:30:21 -070063#define PERSIST_DEL_KEY_OK 0
64#define PERSIST_DEL_KEY_ERROR_OTHER (-1)
65#define PERSIST_DEL_KEY_ERROR_NO_FIELD (-2)
Rubin Xu85c01f92014-10-13 12:49:54 +010066
Paul Crowley73be12d2020-02-03 12:22:03 -080067// Exposed for testing only
Paul Crowleyb64933a2017-10-31 08:25:55 -070068int match_multi_entry(const char* key, const char* field, unsigned index);
Paul Lawrence2f32cda2015-05-05 14:28:25 -070069
Paul Crowleyb64933a2017-10-31 08:25:55 -070070int cryptfs_crypto_complete(void);
71int cryptfs_check_passwd(const char* pw);
72int cryptfs_verify_passwd(const char* pw);
73int cryptfs_restart(void);
Paul Lawrence7ee87cf2017-12-22 10:12:06 -080074int cryptfs_enable(int type, const char* passwd, int no_ui);
Bill Peckham0db11972018-10-10 10:25:42 -070075int cryptfs_changepw(int type, const char* currentpw, const char* newpw);
Paul Lawrence7ee87cf2017-12-22 10:12:06 -080076int cryptfs_enable_default(int no_ui);
Paul Crowley3d98f5d2020-02-07 11:49:09 -080077int cryptfs_setup_ext_volume(const char* label, const char* real_blkdev,
78 const android::vold::KeyBuffer& key, std::string* out_crypto_blkdev);
Paul Crowleyb64933a2017-10-31 08:25:55 -070079int cryptfs_getfield(const char* fieldname, char* value, int len);
80int cryptfs_setfield(const char* fieldname, const char* value);
81int cryptfs_mount_default_encrypted(void);
82int cryptfs_get_password_type(void);
83const char* cryptfs_get_password(void);
84void cryptfs_clear_password(void);
85int cryptfs_isConvertibleToFBE(void);
Paul Crowleyb3d018a2020-02-12 11:04:05 -080086const android::vold::KeyGeneration cryptfs_get_keygen();
Greg Kaiser57f9af62018-02-16 13:13:58 -080087
Paul Crowleyb64933a2017-10-31 08:25:55 -070088#endif /* ANDROID_VOLD_CRYPTFS_H */