blob: b657a65320b710723dfbf477ebfd050e8ef00b14 [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_EDCSA_KEY_H_
18#define SYSTEM_KEYMASTER_EDCSA_KEY_H_
19
20#include <openssl/ecdsa.h>
21
22#include "asymmetric_key.h"
23
24namespace keymaster {
25
26class EcdsaKey : public AsymmetricKey {
27 public:
28 static EcdsaKey* GenerateKey(const AuthorizationSet& key_description, const Logger& logger,
29 keymaster_error_t* error);
30 static EcdsaKey* ImportKey(const AuthorizationSet& key_description, EVP_PKEY* pkey,
31 const Logger& logger, keymaster_error_t* error);
32 EcdsaKey(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 EcdsaKey(EC_KEY* ecdsa_key, const AuthorizationSet auths, const Logger& logger)
38 : AsymmetricKey(auths, logger), ecdsa_key_(ecdsa_key) {}
39
40 static EC_GROUP* choose_group(size_t key_size_bits);
41 static keymaster_error_t get_group_size(const EC_GROUP& group, size_t* key_size_bits);
42
43 virtual int evp_key_type() { return EVP_PKEY_EC; }
44 virtual bool InternalToEvp(EVP_PKEY* pkey) const;
45 virtual bool EvpToInternal(const EVP_PKEY* pkey);
46
47 struct ECDSA_Delete {
48 void operator()(EC_KEY* p) { EC_KEY_free(p); }
49 };
50
51 struct EC_GROUP_Delete {
52 void operator()(EC_GROUP* p) { EC_GROUP_free(p); }
53 };
54
55 UniquePtr<EC_KEY, ECDSA_Delete> ecdsa_key_;
56};
57
58} // namespace keymaster
59
60#endif // SYSTEM_KEYMASTER_ECDSA_KEY_H_