Andres Morales | 3b48ae5 | 2015-01-29 10:53:19 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 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 ANDROID_HARDWARE_KEYGUARD_H |
| 18 | #define ANDROID_HARDWARE_KEYGUARD_H |
| 19 | |
| 20 | #include <sys/cdefs.h> |
| 21 | #include <sys/types.h> |
| 22 | #include <hardware/hardware.h> |
| 23 | |
| 24 | __BEGIN_DECLS |
| 25 | |
| 26 | #define KEYGUARD_HARDWARE_MODULE_ID "keyguard" |
| 27 | |
| 28 | #define KEYGUARD_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1) |
| 29 | |
| 30 | #define HARDWARE_KEYGUARD "keyguard" |
| 31 | |
| 32 | struct keyguard_module { |
| 33 | /** |
| 34 | * Comon methods of the keyguard module. This *must* be the first member of |
| 35 | * keyguard_module as users of this structure will cast a hw_module_t to |
| 36 | * a keyguard_module pointer in the appropriate context. |
| 37 | */ |
| 38 | hw_module_t common; |
| 39 | }; |
| 40 | |
| 41 | struct keyguard_device { |
| 42 | /** |
| 43 | * Common methods of the keyguard device. As above, this must be the first |
| 44 | * member of keymaster_device. |
| 45 | */ |
| 46 | hw_device_t common; |
| 47 | |
| 48 | /** |
| 49 | * Enrolls password_payload, which should be derived from a user selected pin or password, |
| 50 | * with the authentication factor private key used only for enrolling authentication |
| 51 | * factor data. |
| 52 | * |
| 53 | * Returns: 0 on success or an error code less than 0 on error. |
| 54 | * On error, enrolled_password_handle will not be allocated. |
| 55 | */ |
| 56 | int (*enroll)(const struct keyguard_device *dev, const uint8_t *password_payload, |
| 57 | const uint8_t password_payload_length, uint8_t **enrolled_password_handle, |
| 58 | uint8_t *enrolled_password_handle_length); |
| 59 | |
| 60 | /** |
| 61 | * Verifies provided_password matches enrolled_password_handle. |
| 62 | * |
| 63 | * Implementations of this module may retain the result of this call |
| 64 | * to attest to the recency of authentication. |
| 65 | * |
| 66 | * On success, writes the address of a verification token to verification_token, |
| 67 | * usable to attest password verification to other trusted services. Clients |
| 68 | * may pass NULL for this value. |
| 69 | * |
| 70 | * Returns: 0 on success or an error code less than 0 on error |
| 71 | * On error, verification token will not be allocated |
| 72 | */ |
| 73 | int (*verify)(const struct keyguard_device *dev, const uint8_t *enrolled_password_handle, |
| 74 | const uint8_t enrolled_password_handle_length, const uint8_t *provided_password, |
| 75 | const uint8_t provided_password_length, uint8_t **verification_token); |
| 76 | |
| 77 | }; |
| 78 | typedef struct keyguard_device keyguard_device_t; |
| 79 | |
| 80 | static inline int keyguard_open(const struct hw_module_t *module, |
| 81 | keyguard_device_t **device) { |
| 82 | return module->methods->open(module, HARDWARE_KEYGUARD, |
| 83 | (struct hw_device_t **) device); |
| 84 | } |
| 85 | |
| 86 | static inline int keyguard_close(keyguard_device_t *device) { |
| 87 | return device->common.close(&device->common); |
| 88 | } |
| 89 | |
| 90 | __END_DECLS |
| 91 | |
| 92 | #endif // ANDROID_HARDWARE_KEYGUARD_H |