blob: fa5482fcb7c86b980d42365cb619bc91cdd0db34 [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
34 virtual Operation* CreateOperation(keymaster_purpose_t purpose, keymaster_digest_t digest,
35 keymaster_padding_t padding, keymaster_error_t* error);
36
37 private:
38 EcdsaKey(EC_KEY* ecdsa_key, const AuthorizationSet auths, const Logger& logger)
39 : AsymmetricKey(auths, logger), ecdsa_key_(ecdsa_key) {}
40
41 static EC_GROUP* choose_group(size_t key_size_bits);
42 static keymaster_error_t get_group_size(const EC_GROUP& group, size_t* key_size_bits);
43
44 virtual int evp_key_type() { return EVP_PKEY_EC; }
45 virtual bool InternalToEvp(EVP_PKEY* pkey) const;
46 virtual bool EvpToInternal(const EVP_PKEY* pkey);
47
48 struct ECDSA_Delete {
49 void operator()(EC_KEY* p) { EC_KEY_free(p); }
50 };
51
52 struct EC_GROUP_Delete {
53 void operator()(EC_GROUP* p) { EC_GROUP_free(p); }
54 };
55
56 UniquePtr<EC_KEY, ECDSA_Delete> ecdsa_key_;
57};
58
59} // namespace keymaster
60
61#endif // SYSTEM_KEYMASTER_ECDSA_KEY_H_