2 * Copyright (C) 2016 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef ANDROID_VOLD_KEYUTIL_H
18 #define ANDROID_VOLD_KEYUTIL_H
25 // ext4enc:TODO get this const from somewhere good
26 const int EXT4_KEY_DESCRIPTOR_SIZE = 8;
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 {
35 char raw[EXT4_MAX_KEY_SIZE];
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);
48 } // namespace android