Shawn Willden | 0a4df7e | 2014-08-28 16:09:05 -0600 | [diff] [blame] | 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: |
Shawn Willden | f6ca3a3 | 2014-09-11 15:11:32 -0600 | [diff] [blame] | 32 | DsaOperation(keymaster_purpose_t purpose, const Logger& logger, keymaster_digest_t digest, |
Shawn Willden | 0a4df7e | 2014-08-28 16:09:05 -0600 | [diff] [blame] | 33 | keymaster_padding_t padding, DSA* key) |
Shawn Willden | f6ca3a3 | 2014-09-11 15:11:32 -0600 | [diff] [blame] | 34 | : Operation(purpose, logger), dsa_key_(key), digest_(digest), padding_(padding) {} |
Shawn Willden | 0a4df7e | 2014-08-28 16:09:05 -0600 | [diff] [blame] | 35 | ~DsaOperation(); |
| 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 | 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: |
Shawn Willden | f6ca3a3 | 2014-09-11 15:11:32 -0600 | [diff] [blame] | 52 | DsaSignOperation(keymaster_purpose_t purpose, const Logger& logger, keymaster_digest_t digest, |
Shawn Willden | 0a4df7e | 2014-08-28 16:09:05 -0600 | [diff] [blame] | 53 | keymaster_padding_t padding, DSA* key) |
Shawn Willden | f6ca3a3 | 2014-09-11 15:11:32 -0600 | [diff] [blame] | 54 | : DsaOperation(purpose, logger, digest, padding, key) {} |
Shawn Willden | 0a4df7e | 2014-08-28 16:09:05 -0600 | [diff] [blame] | 55 | virtual keymaster_error_t Finish(const Buffer& signature, Buffer* output); |
| 56 | }; |
| 57 | |
| 58 | class DsaVerifyOperation : public DsaOperation { |
| 59 | public: |
Shawn Willden | f6ca3a3 | 2014-09-11 15:11:32 -0600 | [diff] [blame] | 60 | DsaVerifyOperation(keymaster_purpose_t purpose, const Logger& logger, keymaster_digest_t digest, |
Shawn Willden | 0a4df7e | 2014-08-28 16:09:05 -0600 | [diff] [blame] | 61 | keymaster_padding_t padding, DSA* key) |
Shawn Willden | f6ca3a3 | 2014-09-11 15:11:32 -0600 | [diff] [blame] | 62 | : DsaOperation(purpose, logger, digest, padding, key) {} |
Shawn Willden | 0a4df7e | 2014-08-28 16:09:05 -0600 | [diff] [blame] | 63 | virtual keymaster_error_t Finish(const Buffer& signature, Buffer* output); |
| 64 | }; |
| 65 | |
| 66 | } // namespace keymaster |
| 67 | |
| 68 | #endif // SYSTEM_KEYMASTER_DSA_OPERATION_H_ |