Shawn Willden | d67afae | 2014-08-19 12:36:27 -0600 | [diff] [blame] | 1 | /* |
| 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 Willden | d67afae | 2014-08-19 12:36:27 -0600 | [diff] [blame] | 20 | #include <openssl/evp.h> |
| 21 | |
| 22 | #include "key.h" |
| 23 | |
| 24 | namespace keymaster { |
| 25 | |
| 26 | class AsymmetricKey : public Key { |
| 27 | public: |
| 28 | protected: |
Shawn Willden | 2f3be36 | 2014-08-25 11:31:39 -0600 | [diff] [blame] | 29 | AsymmetricKey(const KeyBlob& blob, const Logger& logger) : Key(blob, logger) {} |
Shawn Willden | 72014ad | 2014-09-17 13:04:10 -0600 | [diff] [blame] | 30 | keymaster_error_t LoadKey(const UnencryptedKeyBlob& blob); |
Shawn Willden | d67afae | 2014-08-19 12:36:27 -0600 | [diff] [blame] | 31 | |
| 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 Willden | f268d74 | 2014-08-19 15:36:26 -0600 | [diff] [blame] | 40 | virtual keymaster_error_t formatted_key_material(keymaster_key_format_t format, |
| 41 | UniquePtr<uint8_t[]>* material, |
Shawn Willden | d67afae | 2014-08-19 12:36:27 -0600 | [diff] [blame] | 42 | size_t* size) const; |
| 43 | |
Shawn Willden | d67afae | 2014-08-19 12:36:27 -0600 | [diff] [blame] | 44 | protected: |
Shawn Willden | 2f3be36 | 2014-08-25 11:31:39 -0600 | [diff] [blame] | 45 | AsymmetricKey(const AuthorizationSet& auths, const Logger& logger) : Key(auths, logger) {} |
Shawn Willden | d67afae | 2014-08-19 12:36:27 -0600 | [diff] [blame] | 46 | |
| 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 Willden | d67afae | 2014-08-19 12:36:27 -0600 | [diff] [blame] | 51 | }; |
| 52 | |
Shawn Willden | d67afae | 2014-08-19 12:36:27 -0600 | [diff] [blame] | 53 | } // namespace keymaster |
| 54 | |
| 55 | #endif // SYSTEM_KEYMASTER_ASYMMETRIC_KEY_H |