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