blob: 14a66c11d7ed01c9f3d0a33b484972468f7ba11b [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 Willden6bfbff02015-02-06 19:48:24 -070039 virtual keymaster_error_t Update(const AuthorizationSet& additional_params, const Buffer& input,
40 Buffer* output, size_t* input_consumed);
Shawn Willden0a4df7e2014-08-28 16:09:05 -060041 virtual keymaster_error_t Abort() { return KM_ERROR_OK; }
42
43 protected:
Shawn Willdenb7361132014-12-08 08:15:14 -070044 keymaster_error_t StoreData(const Buffer& input, size_t* input_consumed);
Shawn Willden0a4df7e2014-08-28 16:09:05 -060045
46 RSA* rsa_key_;
Shawn Willden0a4df7e2014-08-28 16:09:05 -060047 keymaster_padding_t padding_;
48 Buffer data_;
49};
50
51class RsaSignOperation : public RsaOperation {
52 public:
Shawn Willden4200f212014-12-02 07:01:21 -070053 RsaSignOperation(const Logger& logger, keymaster_digest_t digest, keymaster_padding_t padding,
54 RSA* key)
55 : RsaOperation(KM_PURPOSE_SIGN, logger, padding, key), digest_(digest) {}
Shawn Willden6bfbff02015-02-06 19:48:24 -070056 virtual keymaster_error_t Finish(const AuthorizationSet& additional_params,
57 const Buffer& signature, Buffer* output);
Shawn Willden4200f212014-12-02 07:01:21 -070058
59 private:
60 keymaster_digest_t digest_;
Shawn Willden0a4df7e2014-08-28 16:09:05 -060061};
62
63class RsaVerifyOperation : public RsaOperation {
64 public:
Shawn Willden4200f212014-12-02 07:01:21 -070065 RsaVerifyOperation(const Logger& logger, keymaster_digest_t digest, keymaster_padding_t padding,
66 RSA* key)
67 : RsaOperation(KM_PURPOSE_VERIFY, logger, padding, key), digest_(digest) {}
Shawn Willden6bfbff02015-02-06 19:48:24 -070068 virtual keymaster_error_t Finish(const AuthorizationSet& additional_params,
69 const Buffer& signature, Buffer* output);
Shawn Willden4200f212014-12-02 07:01:21 -070070
71 private:
72 keymaster_digest_t digest_;
73};
74
75class RsaEncryptOperation : public RsaOperation {
76 public:
77 RsaEncryptOperation(const Logger& logger, keymaster_padding_t padding, RSA* key)
78 : RsaOperation(KM_PURPOSE_ENCRYPT, logger, padding, key) {}
Shawn Willden6bfbff02015-02-06 19:48:24 -070079 virtual keymaster_error_t Finish(const AuthorizationSet& additional_params,
80 const Buffer& signature, Buffer* output);
Shawn Willden4200f212014-12-02 07:01:21 -070081};
82
83class RsaDecryptOperation : public RsaOperation {
84 public:
85 RsaDecryptOperation(const Logger& logger, keymaster_padding_t padding, RSA* key)
86 : RsaOperation(KM_PURPOSE_DECRYPT, logger, padding, key) {}
Shawn Willden6bfbff02015-02-06 19:48:24 -070087 virtual keymaster_error_t Finish(const AuthorizationSet& additional_params,
88 const Buffer& signature, Buffer* output);
Shawn Willden0a4df7e2014-08-28 16:09:05 -060089};
90
91} // namespace keymaster
92
93#endif // SYSTEM_KEYMASTER_RSA_OPERATION_H_