1/*
2 * Copyright 2015 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_EC_KEYMASTER0_KEY_H_
18#define SYSTEM_KEYMASTER_EC_KEYMASTER0_KEY_H_
19
20#include <openssl/ec_key.h>
21
22#include <keymaster/ec_key_factory.h>
23
24#include "ec_key.h"
25
26namespace keymaster {
27
28class Keymaster0Engine;
29class SoftKeymasterContext;
30
31/**
32 * An EcdsaKeyFactory which can delegate key generation, importing and loading operations to a
33 * keymaster0-backed OpenSSL engine.
34 */
35class EcdsaKeymaster0KeyFactory : public EcKeyFactory {
36    typedef EcKeyFactory super;
37
38  public:
39    EcdsaKeymaster0KeyFactory(const SoftKeymasterContext* context, const Keymaster0Engine* engine);
40
41    keymaster_error_t GenerateKey(const AuthorizationSet& key_description,
42                                  KeymasterKeyBlob* key_blob, AuthorizationSet* hw_enforced,
43                                  AuthorizationSet* sw_enforced) const override;
44
45    keymaster_error_t ImportKey(const AuthorizationSet& key_description,
46                                keymaster_key_format_t input_key_material_format,
47                                const KeymasterKeyBlob& input_key_material,
48                                KeymasterKeyBlob* output_key_blob, AuthorizationSet* hw_enforced,
49                                AuthorizationSet* sw_enforced) const override;
50
51    keymaster_error_t LoadKey(const KeymasterKeyBlob& key_material,
52                              const AuthorizationSet& additional_params,
53                              const AuthorizationSet& hw_enforced,
54                              const AuthorizationSet& sw_enforced,
55                              UniquePtr<Key>* key) const override;
56
57  private:
58    const Keymaster0Engine* engine_;
59};
60
61class EcKeymaster0Key : public EcKey {
62  public:
63    EcKeymaster0Key(EC_KEY* ec_key, const AuthorizationSet& hw_enforced,
64                    const AuthorizationSet& sw_enforced, keymaster_error_t* error)
65        : EcKey(ec_key, hw_enforced, sw_enforced, error) {}
66};
67
68}  // namespace keymaster
69
70#endif  // SYSTEM_KEYMASTER_EC_KEYMASTER0_KEY_H_
71