blob: ead81897383d4e1f04be04150cbb141f4ffd8191 [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_ASYMMETRIC_KEY_H
18#define SYSTEM_KEYMASTER_ASYMMETRIC_KEY_H
19
Shawn Willdend67afae2014-08-19 12:36:27 -060020#include <openssl/evp.h>
21
22#include "key.h"
23
24namespace keymaster {
25
26class AsymmetricKey : public Key {
27 public:
28 protected:
Shawn Willden2f3be362014-08-25 11:31:39 -060029 AsymmetricKey(const KeyBlob& blob, const Logger& logger) : Key(blob, logger) {}
Shawn Willden72014ad2014-09-17 13:04:10 -060030 keymaster_error_t LoadKey(const UnencryptedKeyBlob& blob);
Shawn Willdend67afae2014-08-19 12:36:27 -060031
32 /**
33 * Return a copy of raw key material, in the key's preferred binary format.
34 */
35 virtual keymaster_error_t key_material(UniquePtr<uint8_t[]>* material, size_t* size) const;
36
37 /**
38 * Return a copy of raw key material, in the specified format.
39 */
Shawn Willdenf268d742014-08-19 15:36:26 -060040 virtual keymaster_error_t formatted_key_material(keymaster_key_format_t format,
41 UniquePtr<uint8_t[]>* material,
Shawn Willdend67afae2014-08-19 12:36:27 -060042 size_t* size) const;
43
Shawn Willdend67afae2014-08-19 12:36:27 -060044 protected:
Shawn Willden2f3be362014-08-25 11:31:39 -060045 AsymmetricKey(const AuthorizationSet& auths, const Logger& logger) : Key(auths, logger) {}
Shawn Willdend67afae2014-08-19 12:36:27 -060046
47 private:
48 virtual int evp_key_type() = 0;
49 virtual bool InternalToEvp(EVP_PKEY* pkey) const = 0;
50 virtual bool EvpToInternal(const EVP_PKEY* pkey) = 0;
Shawn Willdend67afae2014-08-19 12:36:27 -060051};
52
Shawn Willdend67afae2014-08-19 12:36:27 -060053} // namespace keymaster
54
55#endif // SYSTEM_KEYMASTER_ASYMMETRIC_KEY_H