1 /* 2 * Copyright 2015 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_KEYMASTER0_KEY_H_ 18 #define SYSTEM_KEYMASTER_RSA_KEYMASTER0_KEY_H_ 19 20 #include <openssl/rsa.h> 21 22 #include <keymaster/km_openssl/rsa_key.h> 23 #include <keymaster/km_openssl/rsa_key_factory.h> 24 25 namespace keymaster { 26 27 class Keymaster0Engine; 28 29 /** 30 * An RsaKeyFactory which can delegate key generation, importing and loading operations to a 31 * keymaster0-backed OpenSSL engine. 32 */ 33 class RsaKeymaster0KeyFactory : public RsaKeyFactory { 34 typedef RsaKeyFactory super; 35 36 public: 37 RsaKeymaster0KeyFactory(const SoftwareKeyBlobMaker* blob_maker, 38 const Keymaster0Engine* engine); 39 40 keymaster_error_t GenerateKey(const AuthorizationSet& key_description, 41 KeymasterKeyBlob* key_blob, AuthorizationSet* hw_enforced, 42 AuthorizationSet* sw_enforced) const override; 43 44 keymaster_error_t ImportKey(const AuthorizationSet& key_description, 45 keymaster_key_format_t input_key_material_format, 46 const KeymasterKeyBlob& input_key_material, 47 KeymasterKeyBlob* output_key_blob, AuthorizationSet* hw_enforced, 48 AuthorizationSet* sw_enforced) const override; 49 50 keymaster_error_t LoadKey(KeymasterKeyBlob&& key_material, 51 const AuthorizationSet& additional_params, 52 AuthorizationSet&& hw_enforced, 53 AuthorizationSet&& sw_enforced, 54 UniquePtr<Key>* key) const override; 55 56 private: 57 const Keymaster0Engine* engine_; 58 }; 59 60 class RsaKeymaster0Key : public RsaKey { 61 public: RsaKeymaster0Key(RSA * rsa_key,AuthorizationSet && hw_enforced,AuthorizationSet && sw_enforced,const KeyFactory * key_factory)62 RsaKeymaster0Key(RSA* rsa_key, AuthorizationSet&& hw_enforced, 63 AuthorizationSet&& sw_enforced, 64 const KeyFactory* key_factory) 65 : RsaKey(rsa_key, move(hw_enforced), move(sw_enforced), key_factory) {} 66 }; 67 68 } // namespace keymaster 69 70 #endif // SYSTEM_KEYMASTER_RSA_KEYMASTER0_KEY_H_ 71