blob: 56cb1892d05d1a0120e5249dbd8805f1b59cedee [file] [log] [blame]
Paul Crowleyf71ace32016-06-02 11:01:19 -07001/*
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
22namespace android {
23namespace vold {
24
25// ext4enc:TODO get this const from somewhere good
26const 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
30constexpr int EXT4_ENCRYPTION_MODE_AES_256_XTS = 1;
31constexpr int EXT4_AES_256_XTS_KEY_SIZE = 64;
32constexpr int EXT4_MAX_KEY_SIZE = 64;
33struct ext4_encryption_key {
34 uint32_t mode;
35 char raw[EXT4_MAX_KEY_SIZE];
36 uint32_t size;
37};
38
39bool randomKey(std::string* key);
40bool installKey(const std::string& key, std::string* raw_ref);
41bool evictKey(const std::string& raw_ref);
42bool retrieveAndInstallKey(bool create_if_absent, const std::string& key_path,
43 const std::string& tmp_path, std::string* key_ref);
44
45} // namespace vold
46} // namespace android
47
48#endif