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_KEY_FACTORY_H_ 18#define SYSTEM_KEYMASTER_KEY_FACTORY_H_ 19 20#include <hardware/keymaster_defs.h> 21#include <keymaster/authorization_set.h> 22 23namespace keymaster { 24 25class Key; 26class KeymasterContext; 27class OperationFactory; 28struct KeymasterKeyBlob; 29 30/** 31 * KeyFactory is a abstraction that encapsulats the knowledge of how to build and parse a specifiec 32 * subclass of Key. 33 */ 34class KeyFactory { 35 public: 36 explicit KeyFactory(const KeymasterContext* context) : context_(context) {} 37 virtual ~KeyFactory() {} 38 39 // Factory methods. 40 virtual keymaster_error_t GenerateKey(const AuthorizationSet& key_description, 41 KeymasterKeyBlob* key_blob, AuthorizationSet* hw_enforced, 42 AuthorizationSet* sw_enforced) const = 0; 43 44 virtual 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, 48 AuthorizationSet* hw_enforced, 49 AuthorizationSet* sw_enforced) const = 0; 50 51 virtual 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 = 0; 56 57 virtual OperationFactory* GetOperationFactory(keymaster_purpose_t purpose) const = 0; 58 59 // Informational methods. 60 virtual const keymaster_key_format_t* SupportedImportFormats(size_t* format_count) const = 0; 61 virtual const keymaster_key_format_t* SupportedExportFormats(size_t* format_count) const = 0; 62 63 protected: 64 const KeymasterContext* context_; 65}; 66 67} // namespace keymaster 68 69#endif // SYSTEM_KEYMASTER_KEY_FACTORY_H_ 70