Paul Crowley | f71ace3 | 2016-06-02 11:01:19 -0700 | [diff] [blame] | 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 | |
Paul Crowley | d575981 | 2016-06-02 11:04:27 -0700 | [diff] [blame^] | 39 | std::string keyname(const std::string& raw_ref); |
Paul Crowley | f71ace3 | 2016-06-02 11:01:19 -0700 | [diff] [blame] | 40 | bool randomKey(std::string* key); |
| 41 | bool installKey(const std::string& key, std::string* raw_ref); |
| 42 | bool evictKey(const std::string& raw_ref); |
| 43 | bool retrieveAndInstallKey(bool create_if_absent, const std::string& key_path, |
| 44 | const std::string& tmp_path, std::string* key_ref); |
Paul Crowley | d575981 | 2016-06-02 11:04:27 -0700 | [diff] [blame^] | 45 | bool retrieveKey(bool create_if_absent, const std::string& key_path, |
| 46 | const std::string& tmp_path, std::string* key); |
Paul Crowley | f71ace3 | 2016-06-02 11:01:19 -0700 | [diff] [blame] | 47 | |
| 48 | } // namespace vold |
| 49 | } // namespace android |
| 50 | |
| 51 | #endif |