blob: f8fb634bf8d58abf8a01fbc75682bb1f85823425 [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
Paul Crowleyd5759812016-06-02 11:04:27 -070039std::string keyname(const std::string& raw_ref);
Paul Crowleyf71ace32016-06-02 11:01:19 -070040bool randomKey(std::string* key);
41bool installKey(const std::string& key, std::string* raw_ref);
42bool evictKey(const std::string& raw_ref);
43bool retrieveAndInstallKey(bool create_if_absent, const std::string& key_path,
44 const std::string& tmp_path, std::string* key_ref);
Paul Crowleyd5759812016-06-02 11:04:27 -070045bool retrieveKey(bool create_if_absent, const std::string& key_path,
46 const std::string& tmp_path, std::string* key);
Paul Crowleyf71ace32016-06-02 11:01:19 -070047
48} // namespace vold
49} // namespace android
50
51#endif