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_DSA_OPERATION_H_ 18 #define SYSTEM_KEYMASTER_DSA_OPERATION_H_ 19 20 #include <openssl/dsa.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 DsaOperation : public Operation { 31 public: DsaOperation(keymaster_purpose_t purpose,const Logger & logger,keymaster_digest_t digest,keymaster_padding_t padding,DSA * key)32 DsaOperation(keymaster_purpose_t purpose, const Logger& logger, keymaster_digest_t digest, 33 keymaster_padding_t padding, DSA* key) 34 : Operation(purpose, logger), dsa_key_(key), digest_(digest), padding_(padding) {} 35 ~DsaOperation(); 36 Begin()37 virtual keymaster_error_t Begin() { return KM_ERROR_OK; } 38 virtual keymaster_error_t Update(const Buffer& input, Buffer* output); Abort()39 virtual keymaster_error_t Abort() { return KM_ERROR_OK; } 40 41 protected: 42 keymaster_error_t StoreData(const Buffer& input); 43 44 DSA* dsa_key_; 45 keymaster_digest_t digest_; 46 keymaster_padding_t padding_; 47 Buffer data_; 48 }; 49 50 class DsaSignOperation : public DsaOperation { 51 public: DsaSignOperation(keymaster_purpose_t purpose,const Logger & logger,keymaster_digest_t digest,keymaster_padding_t padding,DSA * key)52 DsaSignOperation(keymaster_purpose_t purpose, const Logger& logger, keymaster_digest_t digest, 53 keymaster_padding_t padding, DSA* key) 54 : DsaOperation(purpose, logger, digest, padding, key) {} 55 virtual keymaster_error_t Finish(const Buffer& signature, Buffer* output); 56 }; 57 58 class DsaVerifyOperation : public DsaOperation { 59 public: DsaVerifyOperation(keymaster_purpose_t purpose,const Logger & logger,keymaster_digest_t digest,keymaster_padding_t padding,DSA * key)60 DsaVerifyOperation(keymaster_purpose_t purpose, const Logger& logger, keymaster_digest_t digest, 61 keymaster_padding_t padding, DSA* key) 62 : DsaOperation(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_DSA_OPERATION_H_ 69