1 /* 2 * Copyright 2014 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 <utility> 20 21 #include <openssl/ec.h> 22 23 #include <keymaster/km_openssl/asymmetric_key.h> 24 #include <keymaster/km_openssl/openssl_utils.h> 25 26 namespace keymaster { 27 28 class EcdsaOperationFactory; 29 30 class EcKey : public AsymmetricKey { 31 public: EcKey(AuthorizationSet hw_enforced,AuthorizationSet sw_enforced,const KeyFactory * factory)32 EcKey(AuthorizationSet hw_enforced, AuthorizationSet sw_enforced, const KeyFactory* factory) 33 : AsymmetricKey(std::move(hw_enforced), std::move(sw_enforced), factory) {} EcKey(AuthorizationSet hw_enforced,AuthorizationSet sw_enforced,const KeyFactory * factory,EC_KEY_Ptr ec_key)34 EcKey(AuthorizationSet hw_enforced, AuthorizationSet sw_enforced, const KeyFactory* factory, 35 EC_KEY_Ptr ec_key) 36 : AsymmetricKey(std::move(hw_enforced), std::move(sw_enforced), factory), 37 ec_key_(std::move(ec_key)) {} 38 evp_key_type()39 int evp_key_type() const override { return EVP_PKEY_EC; } 40 41 EVP_PKEY_Ptr InternalToEvp() const override; 42 bool EvpToInternal(const EVP_PKEY* pkey) override; 43 key()44 EC_KEY* key() const { return ec_key_.get(); } 45 46 protected: EcKey(EC_KEY * ec_key,AuthorizationSet hw_enforced,AuthorizationSet sw_enforced,const KeyFactory * key_factory)47 EcKey(EC_KEY* ec_key, AuthorizationSet hw_enforced, AuthorizationSet sw_enforced, 48 const KeyFactory* key_factory) 49 : AsymmetricKey(std::move(hw_enforced), std::move(sw_enforced), key_factory), 50 ec_key_(ec_key) {} 51 52 private: 53 EC_KEY_Ptr ec_key_; 54 }; 55 56 } // namespace keymaster 57