blob: 16548ee96037a8fe0a3c19f8211c87e45d7e7f1c [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
Shawn Willden111edb32015-02-05 22:44:24 -070035 virtual keymaster_error_t Begin(const AuthorizationSet& /* input_params */,
36 AuthorizationSet* /* output_params */) {
37 return KM_ERROR_OK;
38 }
Shawn Willdenb7361132014-12-08 08:15:14 -070039 virtual keymaster_error_t Update(const Buffer& input, Buffer* output, size_t* input_consumed);
Shawn Willden0a4df7e2014-08-28 16:09:05 -060040 virtual keymaster_error_t Abort() { return KM_ERROR_OK; }
41
42 protected:
Shawn Willdenb7361132014-12-08 08:15:14 -070043 keymaster_error_t StoreData(const Buffer& input, size_t* input_consumed);
Shawn Willden0a4df7e2014-08-28 16:09:05 -060044
45 RSA* rsa_key_;
Shawn Willden0a4df7e2014-08-28 16:09:05 -060046 keymaster_padding_t padding_;
47 Buffer data_;
48};
49
50class RsaSignOperation : public RsaOperation {
51 public:
Shawn Willden4200f212014-12-02 07:01:21 -070052 RsaSignOperation(const Logger& logger, keymaster_digest_t digest, keymaster_padding_t padding,
53 RSA* key)
54 : RsaOperation(KM_PURPOSE_SIGN, logger, padding, key), digest_(digest) {}
Shawn Willden0a4df7e2014-08-28 16:09:05 -060055 virtual keymaster_error_t Finish(const Buffer& signature, Buffer* output);
Shawn Willden4200f212014-12-02 07:01:21 -070056
57 private:
58 keymaster_digest_t digest_;
Shawn Willden0a4df7e2014-08-28 16:09:05 -060059};
60
61class RsaVerifyOperation : public RsaOperation {
62 public:
Shawn Willden4200f212014-12-02 07:01:21 -070063 RsaVerifyOperation(const Logger& logger, keymaster_digest_t digest, keymaster_padding_t padding,
64 RSA* key)
65 : RsaOperation(KM_PURPOSE_VERIFY, logger, padding, key), digest_(digest) {}
66 virtual keymaster_error_t Finish(const Buffer& signature, Buffer* output);
67
68 private:
69 keymaster_digest_t digest_;
70};
71
72class RsaEncryptOperation : public RsaOperation {
73 public:
74 RsaEncryptOperation(const Logger& logger, keymaster_padding_t padding, RSA* key)
75 : RsaOperation(KM_PURPOSE_ENCRYPT, logger, padding, key) {}
76 virtual keymaster_error_t Finish(const Buffer& signature, Buffer* output);
77};
78
79class RsaDecryptOperation : public RsaOperation {
80 public:
81 RsaDecryptOperation(const Logger& logger, keymaster_padding_t padding, RSA* key)
82 : RsaOperation(KM_PURPOSE_DECRYPT, logger, padding, key) {}
Shawn Willden0a4df7e2014-08-28 16:09:05 -060083 virtual keymaster_error_t Finish(const Buffer& signature, Buffer* output);
84};
85
86} // namespace keymaster
87
88#endif // SYSTEM_KEYMASTER_RSA_OPERATION_H_