blob: 7ffbbcefca97ff6c3d13fbdfc6c2d2a61a6e4607 [file] [log] [blame]
Shawn Willden0a4df7e2014-08-28 16:09:05 -06001/*
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_RSA_OPERATION_H_
18#define SYSTEM_KEYMASTER_RSA_OPERATION_H_
19
20#include <UniquePtr.h>
21
22#include <keymaster/key_blob.h>
23
24#include "operation.h"
25
26namespace keymaster {
27
28class RsaOperation : public Operation {
29 public:
Shawn Willden4200f212014-12-02 07:01:21 -070030 RsaOperation(keymaster_purpose_t purpose, const Logger& logger, keymaster_padding_t padding,
31 RSA* key)
32 : Operation(purpose, logger), rsa_key_(key), padding_(padding) {}
Shawn Willden0a4df7e2014-08-28 16:09:05 -060033 ~RsaOperation();
34
35 virtual keymaster_error_t Begin() { return KM_ERROR_OK; }
Shawn Willdenb7361132014-12-08 08:15:14 -070036 virtual keymaster_error_t Update(const Buffer& input, Buffer* output, size_t* input_consumed);
Shawn Willden0a4df7e2014-08-28 16:09:05 -060037 virtual keymaster_error_t Abort() { return KM_ERROR_OK; }
38
39 protected:
Shawn Willdenb7361132014-12-08 08:15:14 -070040 keymaster_error_t StoreData(const Buffer& input, size_t* input_consumed);
Shawn Willden0a4df7e2014-08-28 16:09:05 -060041
42 RSA* rsa_key_;
Shawn Willden0a4df7e2014-08-28 16:09:05 -060043 keymaster_padding_t padding_;
44 Buffer data_;
45};
46
47class RsaSignOperation : public RsaOperation {
48 public:
Shawn Willden4200f212014-12-02 07:01:21 -070049 RsaSignOperation(const Logger& logger, keymaster_digest_t digest, keymaster_padding_t padding,
50 RSA* key)
51 : RsaOperation(KM_PURPOSE_SIGN, logger, padding, key), digest_(digest) {}
Shawn Willden0a4df7e2014-08-28 16:09:05 -060052 virtual keymaster_error_t Finish(const Buffer& signature, Buffer* output);
Shawn Willden4200f212014-12-02 07:01:21 -070053
54 private:
55 keymaster_digest_t digest_;
Shawn Willden0a4df7e2014-08-28 16:09:05 -060056};
57
58class RsaVerifyOperation : public RsaOperation {
59 public:
Shawn Willden4200f212014-12-02 07:01:21 -070060 RsaVerifyOperation(const Logger& logger, keymaster_digest_t digest, keymaster_padding_t padding,
61 RSA* key)
62 : RsaOperation(KM_PURPOSE_VERIFY, logger, padding, key), digest_(digest) {}
63 virtual keymaster_error_t Finish(const Buffer& signature, Buffer* output);
64
65 private:
66 keymaster_digest_t digest_;
67};
68
69class RsaEncryptOperation : public RsaOperation {
70 public:
71 RsaEncryptOperation(const Logger& logger, keymaster_padding_t padding, RSA* key)
72 : RsaOperation(KM_PURPOSE_ENCRYPT, logger, padding, key) {}
73 virtual keymaster_error_t Finish(const Buffer& signature, Buffer* output);
74};
75
76class RsaDecryptOperation : public RsaOperation {
77 public:
78 RsaDecryptOperation(const Logger& logger, keymaster_padding_t padding, RSA* key)
79 : RsaOperation(KM_PURPOSE_DECRYPT, logger, padding, key) {}
Shawn Willden0a4df7e2014-08-28 16:09:05 -060080 virtual keymaster_error_t Finish(const Buffer& signature, Buffer* output);
81};
82
83} // namespace keymaster
84
85#endif // SYSTEM_KEYMASTER_RSA_OPERATION_H_