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_ECDSA_OPERATION_H_ 18 #define SYSTEM_KEYMASTER_ECDSA_OPERATION_H_ 19 20 #include <openssl/ec.h> 21 22 #include <UniquePtr.h> 23 24 #include <keymaster/key_blob.h> 25 26 #include "operation.h" 27 28 namespace keymaster { 29 30 class EcdsaOperation : public Operation { 31 public: 32 EcdsaOperation(keymaster_purpose_t purpose, const Logger& logger, keymaster_digest_t digest, 33 keymaster_padding_t padding, EC_KEY* key) 34 : Operation(purpose, logger), ecdsa_key_(key), digest_(digest), padding_(padding) {} 35 ~EcdsaOperation(); 36 37 virtual keymaster_error_t Begin() { return KM_ERROR_OK; } 38 virtual keymaster_error_t Update(const Buffer& input, Buffer* output); 39 virtual keymaster_error_t Abort() { return KM_ERROR_OK; } 40 41 protected: 42 keymaster_error_t StoreData(const Buffer& input); 43 44 EC_KEY* ecdsa_key_; 45 keymaster_digest_t digest_; 46 keymaster_padding_t padding_; 47 Buffer data_; 48 }; 49 50 class EcdsaSignOperation : public EcdsaOperation { 51 public: 52 EcdsaSignOperation(keymaster_purpose_t purpose, const Logger& logger, keymaster_digest_t digest, 53 keymaster_padding_t padding, EC_KEY* key) 54 : EcdsaOperation(purpose, logger, digest, padding, key) {} 55 virtual keymaster_error_t Finish(const Buffer& signature, Buffer* output); 56 }; 57 58 class EcdsaVerifyOperation : public EcdsaOperation { 59 public: 60 EcdsaVerifyOperation(keymaster_purpose_t purpose, const Logger& logger, 61 keymaster_digest_t digest, keymaster_padding_t padding, EC_KEY* key) 62 : EcdsaOperation(purpose, logger, digest, padding, key) {} 63 virtual keymaster_error_t Finish(const Buffer& signature, Buffer* output); 64 }; 65 66 } // namespace keymaster 67 68 #endif // SYSTEM_KEYMASTER_ECDSA_OPERATION_H_ 69