blob: cb341e280b4231f047676380837c2544ed1e7ba1 [file] [log] [blame]
Shawn Willden2c8dd3e2014-09-18 15:16:31 -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_KEY_H_
18#define SYSTEM_KEYMASTER_RSA_KEY_H_
19
20#include <openssl/rsa.h>
21
22#include "asymmetric_key.h"
23
24namespace keymaster {
25
26class RsaKey : public AsymmetricKey {
27 public:
28 static RsaKey* GenerateKey(const AuthorizationSet& key_description, const Logger& logger,
29 keymaster_error_t* error);
30 static RsaKey* ImportKey(const AuthorizationSet& key_description, EVP_PKEY* pkey,
31 const Logger& logger, keymaster_error_t* error);
32 RsaKey(const UnencryptedKeyBlob& blob, const Logger& logger, keymaster_error_t* error);
33
Shawn Willden96599212014-09-26 12:07:44 -060034 virtual Operation* CreateOperation(keymaster_purpose_t purpose, keymaster_error_t* error);
Shawn Willden2c8dd3e2014-09-18 15:16:31 -060035
36 private:
37 RsaKey(RSA* rsa_key, const AuthorizationSet& auths, const Logger& logger)
38 : AsymmetricKey(auths, logger), rsa_key_(rsa_key) {}
39
40 virtual int evp_key_type() { return EVP_PKEY_RSA; }
41 virtual bool InternalToEvp(EVP_PKEY* pkey) const;
42 virtual bool EvpToInternal(const EVP_PKEY* pkey);
43
Shawn Willden46a420d2014-12-02 07:01:21 -070044 bool SupportedMode(keymaster_purpose_t purpose, keymaster_padding_t padding);
45 bool SupportedMode(keymaster_purpose_t purpose, keymaster_digest_t digest);
46
Shawn Willden2c8dd3e2014-09-18 15:16:31 -060047 struct RSA_Delete {
48 void operator()(RSA* p) { RSA_free(p); }
49 };
50
51 UniquePtr<RSA, RSA_Delete> rsa_key_;
52};
53
54} // namespace keymaster
55
56#endif // SYSTEM_KEYMASTER_RSA_KEY_H_