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 #pragma once 18 19 #include <openssl/evp.h> 20 #include <openssl/rsa.h> 21 22 #include <keymaster/asymmetric_key_factory.h> 23 #include <keymaster/soft_key_factory.h> 24 25 namespace keymaster { 26 27 class RsaKeyFactory : public AsymmetricKeyFactory, public SoftKeyFactoryMixin { 28 public: RsaKeyFactory(const SoftwareKeyBlobMaker & blob_maker,const KeymasterContext & context)29 explicit RsaKeyFactory(const SoftwareKeyBlobMaker& blob_maker, const KeymasterContext& context) 30 : AsymmetricKeyFactory(context), SoftKeyFactoryMixin(blob_maker) {} 31 32 keymaster_error_t GenerateKey(const AuthorizationSet& key_description, 33 UniquePtr<Key> attest_key, 34 const KeymasterBlob& issuer_subject, // 35 KeymasterKeyBlob* key_blob, 36 AuthorizationSet* hw_enforced, // 37 AuthorizationSet* sw_enforced, 38 CertificateChain* cert_chain) const override; 39 keymaster_error_t ImportKey(const AuthorizationSet& key_description, 40 keymaster_key_format_t input_key_material_format, 41 const KeymasterKeyBlob& input_key_material, 42 UniquePtr<Key> attest_key, // 43 const KeymasterBlob& issuer_subject, 44 KeymasterKeyBlob* output_key_blob, 45 AuthorizationSet* hw_enforced, // 46 AuthorizationSet* sw_enforced, 47 CertificateChain* cert_chain) const override; 48 49 keymaster_error_t CreateEmptyKey(AuthorizationSet&& hw_enforced, AuthorizationSet&& sw_enforced, 50 UniquePtr<AsymmetricKey>* key) const override; 51 52 OperationFactory* GetOperationFactory(keymaster_purpose_t purpose) const override; 53 keymaster_key_type()54 keymaster_algorithm_t keymaster_key_type() const override { return KM_ALGORITHM_RSA; } 55 56 protected: 57 keymaster_error_t UpdateImportKeyDescription(const AuthorizationSet& key_description, 58 keymaster_key_format_t import_key_format, 59 const KeymasterKeyBlob& import_key_material, 60 AuthorizationSet* updated_description, 61 uint64_t* public_exponent, 62 uint32_t* key_size) const; 63 }; 64 65 } // namespace keymaster 66