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 <utility> 21 22 #include <openssl/rsa.h> 23 24 #include <keymaster/km_openssl/openssl_utils.h> 25 26 #include "asymmetric_key.h" 27 28 namespace keymaster { 29 30 class RsaKey : public AsymmetricKey { 31 public: RsaKey(AuthorizationSet hw_enforced,AuthorizationSet sw_enforced,const KeyFactory * factory)32 RsaKey(AuthorizationSet hw_enforced, AuthorizationSet sw_enforced, const KeyFactory* factory) 33 : AsymmetricKey(std::move(hw_enforced), std::move(sw_enforced), factory) {} RsaKey(AuthorizationSet hw_enforced,AuthorizationSet sw_enforced,const KeyFactory * factory,RSA_Ptr rsa_key)34 RsaKey(AuthorizationSet hw_enforced, AuthorizationSet sw_enforced, const KeyFactory* factory, 35 RSA_Ptr rsa_key) 36 : AsymmetricKey(std::move(hw_enforced), std::move(sw_enforced), factory), 37 rsa_key_(std::move(rsa_key)) {} 38 evp_key_type()39 int evp_key_type() const override { return EVP_PKEY_RSA; } 40 41 EVP_PKEY_Ptr InternalToEvp() const override; 42 bool EvpToInternal(const EVP_PKEY* pkey) override; 43 44 bool SupportedMode(keymaster_purpose_t purpose, keymaster_padding_t padding); 45 bool SupportedMode(keymaster_purpose_t purpose, keymaster_digest_t digest); 46 key()47 RSA* key() const { return rsa_key_.get(); } 48 49 protected: RsaKey(RSA * rsa,AuthorizationSet hw_enforced,AuthorizationSet sw_enforced,const KeyFactory * key_factory)50 RsaKey(RSA* rsa, AuthorizationSet hw_enforced, AuthorizationSet sw_enforced, 51 const KeyFactory* key_factory) 52 : AsymmetricKey(std::move(hw_enforced), std::move(sw_enforced), key_factory), rsa_key_(rsa) 53 {} 54 55 private: 56 RSA_Ptr rsa_key_; 57 }; 58 59 } // namespace keymaster 60 61 #endif // SYSTEM_KEYMASTER_RSA_KEY_H_ 62