1 /* 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 26 typedef struct keymaster0_device keymaster0_device_t; 27 typedef struct keymaster1_device keymaster1_device_t; 28 typedef struct keymaster2_device keymaster2_device_t; 29 30 namespace keymaster { 31 class AndroidKeymaster; 32 class KeymasterContext; 33 34 namespace ng { 35 36 using ::android::hardware::keymaster::V3_0::ErrorCode; 37 using ::android::hardware::keymaster::V3_0::IKeymasterDevice; 38 using ::android::hardware::keymaster::V3_0::KeyCharacteristics; 39 using ::android::hardware::keymaster::V3_0::KeyFormat; 40 using ::android::hardware::keymaster::V3_0::KeyParameter; 41 using ::android::hardware::keymaster::V3_0::KeyPurpose; 42 using ::android::hardware::Return; 43 using ::android::hardware::Void; 44 using ::android::hardware::hidl_vec; 45 using ::android::hardware::hidl_string; 46 using ::android::sp; 47 48 enum class KeymasterHardwareProfile : uint32_t { 49 SW, 50 KM0, 51 KM1, 52 KM2, 53 }; 54 55 class 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 98 IKeymasterDevice* CreateKeymasterDevice(); 99 100 IKeymasterDevice* CreateKeymasterDevice(keymaster2_device_t* km2_device); 101 IKeymasterDevice* CreateKeymasterDevice(keymaster1_device_t* km1_device); 102 IKeymasterDevice* CreateKeymasterDevice(keymaster0_device_t* km0_device); 103 104 } // namespace ng 105 } // namespace keymaster 106 107 #endif // HIDL_android_hardware_keymaster_V3_0_AndroidKeymaster3Device_H_ 108