Kenny Root | 60d0e5f | 2012-02-15 10:54:24 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2011 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_KEYMASTER_H |
| 18 | #define ANDROID_HARDWARE_KEYMASTER_H |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | #include <sys/cdefs.h> |
| 22 | #include <sys/types.h> |
| 23 | |
| 24 | #include <hardware/hardware.h> |
| 25 | |
| 26 | __BEGIN_DECLS |
| 27 | |
| 28 | /** |
| 29 | * The id of this module |
| 30 | */ |
| 31 | #define KEYSTORE_HARDWARE_MODULE_ID "keystore" |
| 32 | |
| 33 | #define KEYSTORE_KEYMASTER "keymaster" |
| 34 | |
| 35 | struct keystore_module { |
| 36 | struct hw_module_t common; |
| 37 | }; |
| 38 | |
| 39 | /** |
| 40 | * Key algorithm for imported keypairs. |
| 41 | */ |
| 42 | typedef enum { |
| 43 | ALGORITHM_RSA, |
| 44 | } keymaster_keypair_algorithm_t; |
| 45 | |
| 46 | /** |
| 47 | * The parameters that can be set for a given keymaster implementation. |
| 48 | */ |
| 49 | struct keymaster_device { |
| 50 | struct hw_device_t common; |
| 51 | |
| 52 | void* context; |
| 53 | |
| 54 | /** |
| 55 | * Generates a public and private key. The key-blob returned is opaque |
| 56 | * and will subsequently provided for signing and verification. |
| 57 | * |
| 58 | * Returns: 0 on success or an error code less than 0. |
| 59 | */ |
| 60 | int (*generate_rsa_keypair)(const struct keymaster_device* dev, |
| 61 | int modulus_size, unsigned long public_exponent, |
| 62 | uint8_t** keyBlob, size_t* keyBlobLength); |
| 63 | |
| 64 | /** |
| 65 | * Imports a public and private key pair. The imported keys should be in |
| 66 | * DER format. The key-blob returned is opaque and can be subsequently |
| 67 | * provided for signing and verification. |
| 68 | * |
| 69 | * Returns: 0 on success or an error code less than 0. |
| 70 | */ |
| 71 | int (*import_keypair)(const struct keymaster_device* dev, |
| 72 | keymaster_keypair_algorithm_t algorithm, |
| 73 | uint8_t* privateKey, size_t* privateKeyLength, |
| 74 | uint8_t* publicKey, size_t* publicKeyLength, |
| 75 | uint8_t** keyBlob, size_t* keyBlobLength); |
| 76 | |
| 77 | /** |
| 78 | * Signs data using a key-blob generated before. |
| 79 | * |
| 80 | * Returns: 0 on success or an error code less than 0. |
| 81 | */ |
| 82 | int (*sign_data)(const struct keymaster_device* dev, |
| 83 | const uint8_t* keyBlob, const size_t keyBlobLength, |
| 84 | const uint8_t* data, const size_t dataLength, |
| 85 | uint8_t** signedData, size_t* signedDataLength); |
| 86 | |
| 87 | /** |
| 88 | * Verifies data signed with a key-blob. |
| 89 | * |
| 90 | * Returns: 0 on successful verification or an error code less than 0. |
| 91 | */ |
| 92 | int (*verify_data)(const struct keymaster_device* dev, |
| 93 | const uint8_t* keyBlob, const size_t keyBlobLength, |
| 94 | const uint8_t* signedData, const size_t signedDataLength, |
| 95 | const uint8_t* signature, const size_t signatureLength); |
| 96 | }; |
| 97 | typedef struct keymaster_device keymaster_device_t; |
| 98 | |
| 99 | __END_DECLS |
| 100 | |
| 101 | #endif // ANDROID_HARDWARE_KEYMASTER_H |
| 102 | |