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 | |
| 17 | /* This structure starts 16,384 bytes before the end of a hardware |
| 18 | * partition that is encrypted. |
| 19 | * Immediately following this structure is the encrypted key. |
Ken Sumrall | e874407 | 2011-01-18 22:01:55 -0800 | [diff] [blame] | 20 | * The keysize field tells how long the key is, in bytes. |
| 21 | * Then there is 32 bytes of padding, |
| 22 | * Finally there is the salt used with the user password. |
| 23 | * The salt is fixed at 16 bytes long. |
Ken Sumrall | 8f869aa | 2010-12-03 03:47:09 -0800 | [diff] [blame] | 24 | * Obviously, the filesystem does not include the last 16 kbytes |
| 25 | * of the partition. |
| 26 | */ |
| 27 | |
| 28 | #define CRYPT_FOOTER_OFFSET 0x4000 |
| 29 | |
| 30 | #define MAX_CRYPTO_TYPE_NAME_LEN 64 |
| 31 | |
Ken Sumrall | e874407 | 2011-01-18 22:01:55 -0800 | [diff] [blame] | 32 | #define SALT_LEN 16 |
| 33 | #define KEY_TO_SALT_PADDING 32 |
| 34 | |
Ken Sumrall | 8f869aa | 2010-12-03 03:47:09 -0800 | [diff] [blame] | 35 | /* definitions of flags in the structure below */ |
| 36 | #define CRYPT_MNT_KEY_UNENCRYPTED 0x1 /* The key for the partition is not encrypted. */ |
Ken Sumrall | d33d417 | 2011-02-01 00:49:13 -0800 | [diff] [blame] | 37 | #define CRYPT_ENCRYPTION_IN_PROGRESS 0x2 /* Set when starting encryption, |
| 38 | * clear when done before rebooting */ |
Ken Sumrall | 8f869aa | 2010-12-03 03:47:09 -0800 | [diff] [blame] | 39 | |
| 40 | #define CRYPT_MNT_MAGIC 0xD0B5B1C4 |
| 41 | |
| 42 | #define __le32 unsigned int |
| 43 | #define __le16 unsigned short int |
| 44 | |
| 45 | struct crypt_mnt_ftr { |
| 46 | __le32 magic; /* See above */ |
| 47 | __le16 major_version; |
| 48 | __le16 minor_version; |
| 49 | __le32 ftr_size; /* in bytes, not including key following */ |
| 50 | __le32 flags; /* See above */ |
| 51 | __le32 keysize; /* in bytes */ |
| 52 | __le32 spare1; /* ignored */ |
| 53 | __le64 fs_size; /* Size of the encrypted fs, in 512 byte sectors */ |
| 54 | __le32 failed_decrypt_count; /* count of # of failed attempts to decrypt and |
| 55 | mount, set to 0 on successful mount */ |
| 56 | unsigned char crypto_type_name[MAX_CRYPTO_TYPE_NAME_LEN]; /* The type of encryption |
| 57 | needed to decrypt this |
| 58 | partition, null terminated */ |
| 59 | }; |
| 60 | |
Ken Sumrall | 29d8da8 | 2011-05-18 17:20:07 -0700 | [diff] [blame] | 61 | struct volume_info { |
| 62 | unsigned int size; |
| 63 | unsigned int flags; |
| 64 | struct crypt_mnt_ftr crypt_ftr; |
| 65 | char mnt_point[256]; |
| 66 | char blk_dev[256]; |
| 67 | char crypto_blkdev[256]; |
| 68 | char label[256]; |
| 69 | }; |
| 70 | #define VOL_NONREMOVABLE 0x1 |
| 71 | #define VOL_ENCRYPTABLE 0x2 |
| 72 | |
Ken Sumrall | 8f869aa | 2010-12-03 03:47:09 -0800 | [diff] [blame] | 73 | #ifdef __cplusplus |
| 74 | extern "C" { |
| 75 | #endif |
Ken Sumrall | 7f7dbaa | 2011-02-01 15:46:41 -0800 | [diff] [blame] | 76 | int cryptfs_crypto_complete(void); |
Ken Sumrall | 8f869aa | 2010-12-03 03:47:09 -0800 | [diff] [blame] | 77 | int cryptfs_check_passwd(char *pw); |
Ken Sumrall | 3ad9072 | 2011-10-04 20:38:29 -0700 | [diff] [blame] | 78 | int cryptfs_verify_passwd(char *newpw); |
Ken Sumrall | 6864b7e | 2011-01-14 15:20:02 -0800 | [diff] [blame] | 79 | int cryptfs_restart(void); |
Ken Sumrall | 8f869aa | 2010-12-03 03:47:09 -0800 | [diff] [blame] | 80 | int cryptfs_enable(char *flag, char *passwd); |
Jason parks | 70a4b3f | 2011-01-28 10:10:47 -0600 | [diff] [blame] | 81 | int cryptfs_changepw(char *newpw); |
Ken Sumrall | 29d8da8 | 2011-05-18 17:20:07 -0700 | [diff] [blame] | 82 | int cryptfs_setup_volume(const char *label, int major, int minor, |
| 83 | char *crypto_dev_path, unsigned int max_pathlen, |
| 84 | int *new_major, int *new_minor); |
Ken Sumrall | 0b8b597 | 2011-08-31 16:14:23 -0700 | [diff] [blame] | 85 | int cryptfs_revert_volume(const char *label); |
Ken Sumrall | 8f869aa | 2010-12-03 03:47:09 -0800 | [diff] [blame] | 86 | #ifdef __cplusplus |
| 87 | } |
| 88 | #endif |
| 89 | |