Shawn Willden | 2c8dd3e | 2014-09-18 15:16:31 -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_RSA_KEY_H_ |
| 18 | #define SYSTEM_KEYMASTER_RSA_KEY_H_ |
| 19 | |
| 20 | #include <openssl/rsa.h> |
| 21 | |
| 22 | #include "asymmetric_key.h" |
| 23 | |
| 24 | namespace keymaster { |
| 25 | |
| 26 | class RsaKey : public AsymmetricKey { |
Shawn Willden | 0cb6942 | 2015-05-26 08:31:37 -0600 | [diff] [blame] | 27 | public: |
| 28 | RsaKey(const AuthorizationSet& hw_enforced, const AuthorizationSet& sw_enforced, |
| 29 | keymaster_error_t* error) |
| 30 | : AsymmetricKey(hw_enforced, sw_enforced, error) {} |
Shawn Willden | a278f61 | 2014-12-23 11:22:21 -0700 | [diff] [blame] | 31 | |
Shawn Willden | 125e486 | 2015-05-11 06:53:34 -0600 | [diff] [blame] | 32 | bool InternalToEvp(EVP_PKEY* pkey) const override; |
| 33 | bool EvpToInternal(const EVP_PKEY* pkey) override; |
Shawn Willden | 2c8dd3e | 2014-09-18 15:16:31 -0600 | [diff] [blame] | 34 | |
Shawn Willden | 4200f21 | 2014-12-02 07:01:21 -0700 | [diff] [blame] | 35 | bool SupportedMode(keymaster_purpose_t purpose, keymaster_padding_t padding); |
| 36 | bool SupportedMode(keymaster_purpose_t purpose, keymaster_digest_t digest); |
| 37 | |
Shawn Willden | 2c8dd3e | 2014-09-18 15:16:31 -0600 | [diff] [blame] | 38 | struct RSA_Delete { |
| 39 | void operator()(RSA* p) { RSA_free(p); } |
| 40 | }; |
| 41 | |
Shawn Willden | 0cb6942 | 2015-05-26 08:31:37 -0600 | [diff] [blame] | 42 | RSA* key() const { return rsa_key_.get(); } |
Shawn Willden | 63ac043 | 2014-12-29 14:07:08 -0700 | [diff] [blame] | 43 | |
Shawn Willden | 2beb628 | 2015-05-20 16:36:24 -0600 | [diff] [blame] | 44 | protected: |
| 45 | RsaKey(RSA* rsa, const AuthorizationSet& hw_enforced, const AuthorizationSet& sw_enforced, |
| 46 | keymaster_error_t* error) |
| 47 | : AsymmetricKey(hw_enforced, sw_enforced, error), rsa_key_(rsa) {} |
| 48 | |
Shawn Willden | 0cb6942 | 2015-05-26 08:31:37 -0600 | [diff] [blame] | 49 | private: |
| 50 | UniquePtr<RSA, RSA_Delete> rsa_key_; |
Shawn Willden | 2c8dd3e | 2014-09-18 15:16:31 -0600 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | } // namespace keymaster |
| 54 | |
| 55 | #endif // SYSTEM_KEYMASTER_RSA_KEY_H_ |