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_EC_KEYMASTER0_KEY_H_ 18#define SYSTEM_KEYMASTER_EC_KEYMASTER0_KEY_H_ 19 20#include <openssl/ec_key.h> 21 22#include <keymaster/ec_key_factory.h> 23 24#include "ec_key.h" 25 26namespace keymaster { 27 28class Keymaster0Engine; 29class SoftKeymasterContext; 30 31/** 32 * An EcdsaKeyFactory which can delegate key generation, importing and loading operations to a 33 * keymaster0-backed OpenSSL engine. 34 */ 35class EcdsaKeymaster0KeyFactory : public EcKeyFactory { 36 typedef EcKeyFactory super; 37 38 public: 39 EcdsaKeymaster0KeyFactory(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& hw_enforced, 53 const AuthorizationSet& sw_enforced, 54 UniquePtr<Key>* key) const override; 55 56 private: 57 const Keymaster0Engine* engine_; 58 const SoftKeymasterContext* soft_context_; 59}; 60 61class EcKeymaster0Key : public EcKey { 62 typedef EcKey super; 63 64 public: 65 EcKeymaster0Key(EC_KEY* ec_key, const AuthorizationSet& hw_enforced, 66 const AuthorizationSet& sw_enforced, const Keymaster0Engine* engine, 67 keymaster_error_t* error); 68 69 keymaster_error_t key_material(UniquePtr<uint8_t[]>* material, size_t* size) const override; 70 71 private: 72 const Keymaster0Engine* engine_; 73}; 74 75} // namespace keymaster 76 77#endif // SYSTEM_KEYMASTER_EC_KEYMASTER0_KEY_H_ 78