blob: 700fd1c07fbaf5bf5336b3e2a75d3630374113ec [file] [log] [blame]
Janis Danisevskisa68669b2017-02-06 11:46:54 +00001/*
2 **
3 ** Copyright 2016, The Android Open Source Project
4 **
5 ** Licensed under the Apache License, Version 2.0 (the "License");
6 ** you may not use this file except in compliance with the License.
7 ** You may obtain a copy of the License at
8 **
9 ** http://www.apache.org/licenses/LICENSE-2.0
10 **
11 ** Unless required by applicable law or agreed to in writing, software
12 ** distributed under the License is distributed on an "AS IS" BASIS,
13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 ** See the License for the specific language governing permissions and
15 ** limitations under the License.
16 */
17
18#ifndef HIDL_android_hardware_keymaster_V3_0_AndroidKeymaster3Device_H_
19#define HIDL_android_hardware_keymaster_V3_0_AndroidKeymaster3Device_H_
20
21#include <android/hardware/keymaster/3.0/IKeymasterDevice.h>
22
23#include <hidl/MQDescriptor.h>
24#include <hidl/Status.h>
25
Janis Danisevskis2fea2352017-07-26 16:52:33 -070026typedef struct keymaster0_device keymaster0_device_t;
Janis Danisevskisa68669b2017-02-06 11:46:54 +000027typedef struct keymaster1_device keymaster1_device_t;
28typedef struct keymaster2_device keymaster2_device_t;
29
30namespace keymaster {
31class AndroidKeymaster;
32class KeymasterContext;
33
34namespace ng {
35
36using ::android::hardware::keymaster::V3_0::ErrorCode;
37using ::android::hardware::keymaster::V3_0::IKeymasterDevice;
38using ::android::hardware::keymaster::V3_0::KeyCharacteristics;
39using ::android::hardware::keymaster::V3_0::KeyFormat;
40using ::android::hardware::keymaster::V3_0::KeyParameter;
41using ::android::hardware::keymaster::V3_0::KeyPurpose;
42using ::android::hardware::Return;
43using ::android::hardware::Void;
44using ::android::hardware::hidl_vec;
45using ::android::hardware::hidl_string;
46using ::android::sp;
47
48enum class KeymasterHardwareProfile : uint32_t {
49 SW,
50 KM0,
51 KM1,
52 KM2,
53};
54
55class AndroidKeymaster3Device : public IKeymasterDevice {
56 public:
57 AndroidKeymaster3Device();
58 AndroidKeymaster3Device(KeymasterContext* context, KeymasterHardwareProfile profile);
59 virtual ~AndroidKeymaster3Device();
60
61 // Methods from ::android::hardware::keymaster::V3_0::IKeymasterDevice follow.
62 Return<void> getHardwareFeatures(getHardwareFeatures_cb _hidl_cb);
63 Return<ErrorCode> addRngEntropy(const hidl_vec<uint8_t>& data) override;
64 Return<void> generateKey(const hidl_vec<KeyParameter>& keyParams,
65 generateKey_cb _hidl_cb) override;
66 Return<void> getKeyCharacteristics(const hidl_vec<uint8_t>& keyBlob,
67 const hidl_vec<uint8_t>& clientId,
68 const hidl_vec<uint8_t>& appData,
69 getKeyCharacteristics_cb _hidl_cb) override;
70 Return<void> importKey(const hidl_vec<KeyParameter>& params, KeyFormat keyFormat,
71 const hidl_vec<uint8_t>& keyData, importKey_cb _hidl_cb) override;
72 Return<void> exportKey(KeyFormat exportFormat, const hidl_vec<uint8_t>& keyBlob,
73 const hidl_vec<uint8_t>& clientId, const hidl_vec<uint8_t>& appData,
74 exportKey_cb _hidl_cb) override;
75 Return<void> attestKey(const hidl_vec<uint8_t>& keyToAttest,
76 const hidl_vec<KeyParameter>& attestParams,
77 attestKey_cb _hidl_cb) override;
78 Return<void> upgradeKey(const hidl_vec<uint8_t>& keyBlobToUpgrade,
79 const hidl_vec<KeyParameter>& upgradeParams,
80 upgradeKey_cb _hidl_cb) override;
81 Return<ErrorCode> deleteKey(const hidl_vec<uint8_t>& keyBlob) override;
82 Return<ErrorCode> deleteAllKeys() override;
83 Return<ErrorCode> destroyAttestationIds() override;
84 Return<void> begin(KeyPurpose purpose, const hidl_vec<uint8_t>& key,
85 const hidl_vec<KeyParameter>& inParams, begin_cb _hidl_cb) override;
86 Return<void> update(uint64_t operationHandle, const hidl_vec<KeyParameter>& inParams,
87 const hidl_vec<uint8_t>& input, update_cb _hidl_cb) override;
88 Return<void> finish(uint64_t operationHandle, const hidl_vec<KeyParameter>& inParams,
89 const hidl_vec<uint8_t>& input, const hidl_vec<uint8_t>& signature,
90 finish_cb _hidl_cb) override;
91 Return<ErrorCode> abort(uint64_t operationHandle) override;
92
93 private:
94 std::unique_ptr<::keymaster::AndroidKeymaster> impl_;
95 KeymasterHardwareProfile profile_;
96};
97
98IKeymasterDevice* CreateKeymasterDevice();
99
Janis Danisevskis2fea2352017-07-26 16:52:33 -0700100IKeymasterDevice* CreateKeymasterDevice(keymaster2_device_t* km2_device);
101IKeymasterDevice* CreateKeymasterDevice(keymaster1_device_t* km1_device);
102IKeymasterDevice* CreateKeymasterDevice(keymaster0_device_t* km0_device);
103
Janis Danisevskisa68669b2017-02-06 11:46:54 +0000104} // namespace ng
105} // namespace keymaster
106
107#endif // HIDL_android_hardware_keymaster_V3_0_AndroidKeymaster3Device_H_