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 #ifndef SYSTEM_KEYMASTER_EC_KEY_H_ 18 #define SYSTEM_KEYMASTER_EC_KEY_H_ 19 20 #include <openssl/ec.h> 21 22 #include <keymaster/km_openssl/asymmetric_key.h> 23 #include <keymaster/km_openssl/openssl_utils.h> 24 25 namespace keymaster { 26 27 class EcdsaOperationFactory; 28 29 class EcKey : public AsymmetricKey { 30 public: EcKey(AuthorizationSet && hw_enforced,AuthorizationSet && sw_enforced,const KeyFactory * key_factory)31 EcKey(AuthorizationSet&& hw_enforced, AuthorizationSet&& sw_enforced, 32 const KeyFactory* key_factory) 33 : AsymmetricKey(move(hw_enforced), move(sw_enforced), key_factory) {} ~EcKey()34 virtual ~EcKey() {} 35 36 bool InternalToEvp(EVP_PKEY* pkey) const override; 37 bool EvpToInternal(const EVP_PKEY* pkey) override; 38 key()39 EC_KEY* key() const { return ec_key_.get(); } 40 41 protected: EcKey(EC_KEY * ec_key,AuthorizationSet && hw_enforced,AuthorizationSet && sw_enforced,const KeyFactory * key_factory)42 EcKey(EC_KEY* ec_key, AuthorizationSet&& hw_enforced, AuthorizationSet&& sw_enforced, 43 const KeyFactory* key_factory) 44 : AsymmetricKey(move(hw_enforced), move(sw_enforced), key_factory), ec_key_(ec_key) {} 45 46 private: 47 EC_KEY_Ptr ec_key_; 48 }; 49 50 } // namespace keymaster 51 52 #endif // SYSTEM_KEYMASTER_EC_KEY_H_ 53