OSDN Git Service

Merge "Add noatime to vfat and exfat" into oc-mr1-dev
[android-x86/system-vold.git] / KeyUtil.h
1 /*
2  * Copyright (C) 2016 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_KEYUTIL_H
18 #define ANDROID_VOLD_KEYUTIL_H
19
20 #include <string>
21
22 namespace android {
23 namespace vold {
24
25 // ext4enc:TODO get this const from somewhere good
26 const int EXT4_KEY_DESCRIPTOR_SIZE = 8;
27
28 // ext4enc:TODO Include structure from somewhere sensible
29 // MUST be in sync with ext4_crypto.c in kernel
30 constexpr int EXT4_ENCRYPTION_MODE_AES_256_XTS = 1;
31 constexpr int EXT4_AES_256_XTS_KEY_SIZE = 64;
32 constexpr int EXT4_MAX_KEY_SIZE = 64;
33 struct ext4_encryption_key {
34     uint32_t mode;
35     char raw[EXT4_MAX_KEY_SIZE];
36     uint32_t size;
37 };
38
39 bool randomKey(std::string* key);
40 bool installKey(const std::string& key, std::string* raw_ref);
41 bool evictKey(const std::string& raw_ref);
42 bool retrieveAndInstallKey(bool create_if_absent, const std::string& key_path,
43                            const std::string& tmp_path, std::string* key_ref);
44 bool retrieveKey(bool create_if_absent, const std::string& key_path,
45                  const std::string& tmp_path, std::string* key);
46
47 }  // namespace vold
48 }  // namespace android
49
50 #endif