blob: fab781615bc51a86a6b7771d92f9516c48631830 [file] [log] [blame]
Shawn Willdend67afae2014-08-19 12:36:27 -06001/*
2 * Copyright 2014 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 SYSTEM_KEYMASTER_KEY_H_
18#define SYSTEM_KEYMASTER_KEY_H_
19
Shawn Willdenb9d584d2015-01-22 16:35:00 -070020#include <hardware/keymaster_defs.h>
Shawn Willden98d9b922014-08-26 08:14:10 -060021#include <keymaster/authorization_set.h>
Shawn Willden98d9b922014-08-26 08:14:10 -060022#include <keymaster/logger.h>
Shawn Willdend67afae2014-08-19 12:36:27 -060023
24namespace keymaster {
25
26class KeyBlob;
27class Operation;
Shawn Willden72014ad2014-09-17 13:04:10 -060028class UnencryptedKeyBlob;
Shawn Willdend67afae2014-08-19 12:36:27 -060029
30class Key {
31 public:
Shawn Willden72014ad2014-09-17 13:04:10 -060032 static Key* CreateKey(const UnencryptedKeyBlob& blob, const Logger& logger,
33 keymaster_error_t* error);
Shawn Willden2f3be362014-08-25 11:31:39 -060034 static Key* GenerateKey(const AuthorizationSet& key_description, const Logger& logger,
35 keymaster_error_t* error);
Shawn Willden437fbd12014-08-20 11:59:49 -060036 static Key* ImportKey(const AuthorizationSet& key_description,
37 keymaster_key_format_t key_format, const uint8_t* key_data,
Shawn Willden2f3be362014-08-25 11:31:39 -060038 size_t key_data_length, const Logger& logger, keymaster_error_t* error);
Shawn Willdend67afae2014-08-19 12:36:27 -060039
40 virtual ~Key() {}
41 virtual Operation* CreateOperation(keymaster_purpose_t purpose, keymaster_error_t* error) = 0;
42
43 /**
44 * Return a copy of raw key material, in the key's preferred binary format.
45 */
46 virtual keymaster_error_t key_material(UniquePtr<uint8_t[]>*, size_t* size) const = 0;
47
48 /**
49 * Return a copy of raw key material, in the specified format.
50 */
Shawn Willdenf268d742014-08-19 15:36:26 -060051 virtual keymaster_error_t formatted_key_material(keymaster_key_format_t format,
52 UniquePtr<uint8_t[]>* material,
Shawn Willdend67afae2014-08-19 12:36:27 -060053 size_t* size) const = 0;
54
55 const AuthorizationSet& authorizations() const { return authorizations_; }
56
57 protected:
Shawn Willden2f3be362014-08-25 11:31:39 -060058 Key(const KeyBlob& blob, const Logger& logger);
59 Key(const AuthorizationSet& authorizations, const Logger& logger)
Shawn Willden407d4122014-08-25 16:49:13 -060060 : logger_(logger), authorizations_(authorizations) {}
Shawn Willden2f3be362014-08-25 11:31:39 -060061
62 const Logger& logger_;
Shawn Willdend67afae2014-08-19 12:36:27 -060063
64 private:
65 AuthorizationSet authorizations_;
66};
67
68} // namespace keymaster
69
70#endif // SYSTEM_KEYMASTER_KEY_H_