1 /* 2 * Copyright 2021 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_ECDH_OPERATION_H_ 18 #define SYSTEM_KEYMASTER_ECDH_OPERATION_H_ 19 20 #include <openssl/ec.h> 21 #include <openssl/evp.h> 22 23 #include <keymaster/UniquePtr.h> 24 25 #include <keymaster/key.h> 26 #include <keymaster/km_openssl/openssl_utils.h> 27 #include <keymaster/operation.h> 28 29 namespace keymaster { 30 31 class EcdhOperation : public Operation { 32 public: EcdhOperation(AuthorizationSet && hw_enforced,AuthorizationSet && sw_enforced,EVP_PKEY * key)33 EcdhOperation(AuthorizationSet&& hw_enforced, AuthorizationSet&& sw_enforced, EVP_PKEY* key) 34 : Operation(KM_PURPOSE_AGREE_KEY, move(hw_enforced), move(sw_enforced)), ecdh_key_(key) {} 35 Abort()36 keymaster_error_t Abort() override { return KM_ERROR_OK; } 37 38 keymaster_error_t Begin(const AuthorizationSet& input_params, 39 AuthorizationSet* output_params) override; 40 keymaster_error_t Update(const AuthorizationSet& additional_params, const Buffer& input, 41 AuthorizationSet* output_params, Buffer* output, 42 size_t* input_consumed) override; 43 keymaster_error_t Finish(const AuthorizationSet& additional_params, const Buffer& input, 44 const Buffer& signature, AuthorizationSet* output_params, 45 Buffer* output) override; 46 47 protected: 48 EVP_PKEY_Ptr ecdh_key_; 49 }; 50 51 class EcdhOperationFactory : public OperationFactory { 52 private: registry_key()53 KeyType registry_key() const override { return KeyType(KM_ALGORITHM_EC, KM_PURPOSE_AGREE_KEY); } 54 OperationPtr CreateOperation(Key&& key, const AuthorizationSet& begin_params, 55 keymaster_error_t* error) override; 56 }; 57 58 } // namespace keymaster 59 60 #endif // SYSTEM_KEYMASTER_ECDH_OPERATION_H_ 61