blob: 4f9de17642b516a35f9e867b02f22263aa66fd84 [file] [log] [blame]
Shawn Willden9d645a02014-06-12 13:48:46 -06001/*
2 * Copyright (C) 2014 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_DEFS_H
18#define ANDROID_HARDWARE_KEYMASTER_DEFS_H
19
20#include <stdint.h>
21#include <stdlib.h>
22#include <string.h>
23
24#if defined(__cplusplus)
25extern "C" {
26#endif // defined(__cplusplus)
27
28/*!
29 * \deprecated Flags for keymaster_device::flags
30 *
31 * keymaster_device::flags is deprecated and will be removed in the
32 * next version of the API in favor of the more detailed information
33 * available from TODO:
34 */
35enum {
36 /*
37 * Indicates this keymaster implementation does not have hardware that
38 * keeps private keys out of user space.
39 *
40 * This should not be implemented on anything other than the default
41 * implementation.
42 */
43 KEYMASTER_SOFTWARE_ONLY = 1 << 0,
44
45 /*
46 * This indicates that the key blobs returned via all the primitives
47 * are sufficient to operate on their own without the trusted OS
48 * querying userspace to retrieve some other data. Key blobs of
49 * this type are normally returned encrypted with a
50 * Key Encryption Key (KEK).
51 *
52 * This is currently used by "vold" to know whether the whole disk
53 * encryption secret can be unwrapped without having some external
54 * service started up beforehand since the "/data" partition will
55 * be unavailable at that point.
56 */
57 KEYMASTER_BLOBS_ARE_STANDALONE = 1 << 1,
58
59 /*
60 * Indicates that the keymaster module supports DSA keys.
61 */
62 KEYMASTER_SUPPORTS_DSA = 1 << 2,
63
64 /*
65 * Indicates that the keymaster module supports EC keys.
66 */
67 KEYMASTER_SUPPORTS_EC = 1 << 3,
68};
69
70/**
71 * \deprecated Asymmetric key pair types.
72 */
73typedef enum {
74 TYPE_RSA = 1,
75 TYPE_DSA = 2,
76 TYPE_EC = 3,
77} keymaster_keypair_t;
78
79/**
80 * Authorization tags each have an associated type. This enumeration facilitates tagging each with
81 * a type, by using the high four bits (of an implied 32-bit unsigned enum value) to specify up to
82 * 16 data types. These values are ORed with tag IDs to generate the final tag ID values.
83 */
84typedef enum {
85 KM_INVALID = 0 << 28, /* Invalid type, used to designate a tag as uninitialized */
86 KM_ENUM = 1 << 28,
87 KM_ENUM_REP = 2 << 28, /* Repeatable enumeration value. */
88 KM_INT = 3 << 28,
89 KM_INT_REP = 4 << 28, /* Repeatable integer value */
90 KM_LONG = 5 << 28,
91 KM_DATE = 6 << 28,
92 KM_BOOL = 7 << 28,
93 KM_BIGNUM = 8 << 28,
94 KM_BYTES = 9 << 28,
95} keymaster_tag_type_t;
96
97typedef enum {
98 KM_TAG_INVALID = KM_INVALID | 0,
99
100 /*
101 * Tags that must be semantically enforced by hardware and software implementations.
102 */
103
104 /* Crypto parameters */
Shawn Willden41e91e92015-01-30 06:23:26 -0700105 KM_TAG_PURPOSE = KM_ENUM_REP | 1, /* keymaster_purpose_t. */
106 KM_TAG_ALGORITHM = KM_ENUM | 2, /* keymaster_algorithm_t. */
107 KM_TAG_KEY_SIZE = KM_INT | 3, /* Key size in bits. */
108 KM_TAG_BLOCK_MODE = KM_ENUM | 4, /* keymaster_block_mode_t. */
109 KM_TAG_DIGEST = KM_ENUM | 5, /* keymaster_digest_t. */
110 KM_TAG_MAC_LENGTH = KM_INT | 6, /* MAC length in bits. */
111 KM_TAG_PADDING = KM_ENUM | 7, /* keymaster_padding_t. */
112 KM_TAG_CHUNK_LENGTH = KM_INT | 8, /* AEAD mode minimum decryption chunk size, in bytes. */
113 KM_TAG_CALLER_NONCE = KM_BOOL | 9, /* Allow caller to specify nonce or IV. */
Shawn Willden9d645a02014-06-12 13:48:46 -0600114
115 /* Other hardware-enforced. */
116 KM_TAG_RESCOPING_ADD = KM_ENUM_REP | 101, /* Tags authorized for addition via rescoping. */
117 KM_TAG_RESCOPING_DEL = KM_ENUM_REP | 102, /* Tags authorized for removal via rescoping. */
118 KM_TAG_BLOB_USAGE_REQUIREMENTS = KM_ENUM | 705, /* keymaster_key_blob_usage_requirements_t */
119
120 /* Algorithm-specific. */
121 KM_TAG_RSA_PUBLIC_EXPONENT = KM_LONG | 200, /* Defaults to 2^16+1 */
122 KM_TAG_DSA_GENERATOR = KM_BIGNUM | 201,
123 KM_TAG_DSA_P = KM_BIGNUM | 202,
124 KM_TAG_DSA_Q = KM_BIGNUM | 203,
125 /* Note there are no EC-specific params. Field size is defined by KM_TAG_KEY_SIZE, and the
126 curve is chosen from NIST recommendations for field size */
127
128 /*
129 * Tags that should be semantically enforced by hardware if possible and will otherwise be
130 * enforced by software (keystore).
131 */
132
133 /* Key validity period */
134 KM_TAG_ACTIVE_DATETIME = KM_DATE | 400, /* Start of validity */
135 KM_TAG_ORIGINATION_EXPIRE_DATETIME = KM_DATE | 401, /* Date when new "messages" should no
136 longer be created. */
137 KM_TAG_USAGE_EXPIRE_DATETIME = KM_DATE | 402, /* Date when existing "messages" should no
138 longer be trusted. */
139 KM_TAG_MIN_SECONDS_BETWEEN_OPS = KM_INT | 403, /* Minimum elapsed time between
140 cryptographic operations with the key. */
Shawn Willdendc0007b2015-01-23 01:01:21 -0700141 KM_TAG_MAX_USES_PER_BOOT = KM_INT | 404, /* Number of times the key can be used per
142 boot. */
Shawn Willden9d645a02014-06-12 13:48:46 -0600143
144 /* User authentication */
Shawn Willden41e91e92015-01-30 06:23:26 -0700145 KM_TAG_ALL_USERS = KM_BOOL | 500, /* If key is usable by all users. */
146 KM_TAG_USER_ID = KM_INT | 501, /* ID of authorized user. Disallowed if
147 KM_TAG_ALL_USERS is present. */
148 KM_TAG_NO_AUTH_REQUIRED = KM_BOOL | 502, /* If key is usable without authentication. */
149 KM_TAG_USER_AUTH_ID = KM_INT_REP | 503, /* ID of the authenticator to use (e.g. password,
150 fingerprint, etc.). Repeatable to support
151 multi-factor auth. Disallowed if
152 KM_TAG_NO_AUTH_REQUIRED is present. */
153 KM_TAG_AUTH_TIMEOUT = KM_INT | 504, /* Required freshness of user authentication for
154 private/secret key operations, in seconds.
155 Public key operations require no authentication.
156 If absent, authentication is required for every
157 use. Authentication state is lost when the
158 device is powered off. */
Shawn Willden9d645a02014-06-12 13:48:46 -0600159
160 /* Application access control */
161 KM_TAG_ALL_APPLICATIONS = KM_BOOL | 600, /* If key is usable by all applications. */
162 KM_TAG_APPLICATION_ID = KM_BYTES | 601, /* ID of authorized application. Disallowed if
163 KM_TAG_ALL_APPLICATIONS is present. */
164
165 /*
166 * Semantically unenforceable tags, either because they have no specific meaning or because
167 * they're informational only.
168 */
169 KM_TAG_APPLICATION_DATA = KM_BYTES | 700, /* Data provided by authorized application. */
170 KM_TAG_CREATION_DATETIME = KM_DATE | 701, /* Key creation time */
171 KM_TAG_ORIGIN = KM_ENUM | 702, /* keymaster_key_origin_t. */
172 KM_TAG_ROLLBACK_RESISTANT = KM_BOOL | 703, /* Whether key is rollback-resistant. */
173 KM_TAG_ROOT_OF_TRUST = KM_BYTES | 704, /* Root of trust ID. Empty array means usable by all
174 roots. */
175
Shawn Willden67ba9e82015-02-06 17:04:53 -0700176 /* Tags used only to provide data to or receive data from operations */
177 KM_TAG_ASSOCIATED_DATA = KM_BYTES | 1000, /* Used to provide associated data for AEAD modes. */
Shawn Willden41e91e92015-01-30 06:23:26 -0700178 KM_TAG_NONCE = KM_BYTES | 1001, /* Nonce or Initialization Vector */
Shawn Willden9d645a02014-06-12 13:48:46 -0600179} keymaster_tag_t;
180
181/**
182 * Algorithms that may be provided by keymaster implementations. Those that must be provided by all
183 * implementations are tagged as "required". Note that where the values in this enumeration overlap
184 * with the values for the deprecated keymaster_keypair_t, the same algorithm must be
185 * specified. This type is new in 0_4 and replaces the deprecated keymaster_keypair_t.
186 */
187typedef enum {
188 /* Asymmetric algorithms. */
189 KM_ALGORITHM_RSA = 1, /* required */
Shawn Willdenf7745ac2015-02-03 11:10:48 -0700190 KM_ALGORITHM_DSA = 2,
Shawn Willden9d645a02014-06-12 13:48:46 -0600191 KM_ALGORITHM_ECDSA = 3, /* required */
192 KM_ALGORITHM_ECIES = 4,
193 /* FIPS Approved Ciphers */
194 KM_ALGORITHM_AES = 32, /* required */
195 KM_ALGORITHM_3DES = 33,
196 KM_ALGORITHM_SKIPJACK = 34,
197 /* AES Finalists */
198 KM_ALGORITHM_MARS = 48,
199 KM_ALGORITHM_RC6 = 49,
200 KM_ALGORITHM_SERPENT = 50,
201 KM_ALGORITHM_TWOFISH = 51,
202 /* Other common block ciphers */
203 KM_ALGORITHM_IDEA = 52,
204 KM_ALGORITHM_RC5 = 53,
205 KM_ALGORITHM_CAST5 = 54,
206 KM_ALGORITHM_BLOWFISH = 55,
207 /* Common stream ciphers */
208 KM_ALGORITHM_RC4 = 64,
209 KM_ALGORITHM_CHACHA20 = 65,
210 /* MAC algorithms */
211 KM_ALGORITHM_HMAC = 128, /* required */
212} keymaster_algorithm_t;
213
214/**
215 * Symmetric block cipher modes that may be provided by keymaster implementations. Those that must
216 * be provided by all implementations are tagged as "required". This type is new in 0_4.
217 *
218 * KM_MODE_FIRST_UNAUTHENTICATED, KM_MODE_FIRST_AUTHENTICATED and KM_MODE_FIRST_MAC are not modes,
219 * but markers used to separate the available modes into classes.
220 */
221typedef enum {
222 /* Unauthenticated modes, usable only for encryption/decryption and not generally recommended
223 * except for compatibility with existing other protocols. */
224 KM_MODE_FIRST_UNAUTHENTICATED = 1,
225 KM_MODE_ECB = KM_MODE_FIRST_UNAUTHENTICATED, /* required */
226 KM_MODE_CBC = 2, /* required */
227 KM_MODE_CBC_CTS = 3, /* recommended */
228 KM_MODE_CTR = 4, /* recommended */
229 KM_MODE_OFB = 5,
230 KM_MODE_CFB = 6,
231 KM_MODE_XTS = 7, /* Note: requires double-length keys */
232 /* Authenticated modes, usable for encryption/decryption and signing/verification. Recommended
233 * over unauthenticated modes for all purposes. One of KM_MODE_GCM and KM_MODE_OCB is
234 * required. */
235 KM_MODE_FIRST_AUTHENTICATED = 32,
236 KM_MODE_GCM = KM_MODE_FIRST_AUTHENTICATED,
237 KM_MODE_OCB = 33,
238 KM_MODE_CCM = 34,
239 /* MAC modes -- only for signing/verification */
240 KM_MODE_FIRST_MAC = 128,
241 KM_MODE_CMAC = KM_MODE_FIRST_MAC,
242 KM_MODE_POLY1305 = 129,
243} keymaster_block_mode_t;
244
245/**
246 * Padding modes that may be applied to plaintext for encryption operations. This list includes
247 * padding modes for both symmetric and asymmetric algorithms. Note that implementations should not
248 * provide all possible combinations of algorithm and padding, only the
249 * cryptographically-appropriate pairs.
250 */
251typedef enum {
252 KM_PAD_NONE = 1, /* required, deprecated */
253 KM_PAD_RSA_OAEP = 2, /* required */
254 KM_PAD_RSA_PSS = 3, /* required */
255 KM_PAD_RSA_PKCS1_1_5_ENCRYPT = 4,
256 KM_PAD_RSA_PKCS1_1_5_SIGN = 5,
257 KM_PAD_ANSI_X923 = 32,
258 KM_PAD_ISO_10126 = 33,
259 KM_PAD_ZERO = 64, /* required */
260 KM_PAD_PKCS7 = 65, /* required */
261 KM_PAD_ISO_7816_4 = 66,
262} keymaster_padding_t;
263
264/**
265 * Digests that may be provided by keymaster implementations. Those that must be provided by all
266 * implementations are tagged as "required". Those that have been added since version 0_2 of the
267 * API are tagged as "new".
268 */
269typedef enum {
270 KM_DIGEST_NONE = 0, /* new, required */
271 DIGEST_NONE = KM_DIGEST_NONE, /* For 0_2 compatibility */
272 KM_DIGEST_MD5 = 1, /* new, for compatibility with old protocols only */
273 KM_DIGEST_SHA1 = 2, /* new */
274 KM_DIGEST_SHA_2_224 = 3, /* new */
275 KM_DIGEST_SHA_2_256 = 4, /* new, required */
276 KM_DIGEST_SHA_2_384 = 5, /* new, recommended */
277 KM_DIGEST_SHA_2_512 = 6, /* new, recommended */
278 KM_DIGEST_SHA_3_256 = 7, /* new */
279 KM_DIGEST_SHA_3_384 = 8, /* new */
280 KM_DIGEST_SHA_3_512 = 9, /* new */
281} keymaster_digest_t;
282
283/**
284 * The origin of a key (or pair), i.e. where it was generated. Origin and can be used together to
285 * determine whether a key may have existed outside of secure hardware. This type is new in 0_4.
286 */
287typedef enum {
288 KM_ORIGIN_HARDWARE = 0, /* Generated in secure hardware */
289 KM_ORIGIN_SOFTWARE = 1, /* Generated in non-secure software */
290 KM_ORIGIN_IMPORTED = 2, /* Imported, origin unknown */
291} keymaster_key_origin_t;
292
293/**
294 * Usability requirements of key blobs. This defines what system functionality must be available
295 * for the key to function. For example, key "blobs" which are actually handles referencing
296 * encrypted key material stored in the file system cannot be used until the file system is
297 * available, and should have BLOB_REQUIRES_FILE_SYSTEM. Other requirements entries will be added
298 * as needed for implementations. This type is new in 0_4.
299 */
300typedef enum {
301 KM_BLOB_STANDALONE = 0,
302 KM_BLOB_REQUIRES_FILE_SYSTEM = 1,
303} keymaster_key_blob_usage_requirements_t;
304
305/**
306 * Possible purposes of a key (or pair). This type is new in 0_4.
307 */
308typedef enum {
309 KM_PURPOSE_ENCRYPT = 0,
310 KM_PURPOSE_DECRYPT = 1,
311 KM_PURPOSE_SIGN = 2,
312 KM_PURPOSE_VERIFY = 3,
313} keymaster_purpose_t;
314
315typedef struct {
316 const uint8_t* data;
317 size_t data_length;
318} keymaster_blob_t;
319
320typedef struct {
321 keymaster_tag_t tag;
322 union {
323 uint32_t enumerated; /* KM_ENUM and KM_ENUM_REP */
324 bool boolean; /* KM_BOOL */
325 uint32_t integer; /* KM_INT and KM_INT_REP */
326 uint64_t long_integer; /* KM_LONG */
327 uint64_t date_time; /* KM_DATE */
328 keymaster_blob_t blob; /* KM_BIGNUM and KM_BYTES*/
329 };
330} keymaster_key_param_t;
331
332typedef struct {
333 keymaster_key_param_t* params; /* may be NULL if length == 0 */
334 size_t length;
335} keymaster_key_param_set_t;
336
337/**
338 * Parameters that define a key's characteristics, including authorized modes of usage and access
339 * control restrictions. The parameters are divided into two categories, those that are enforced by
340 * secure hardware, and those that are not. For a software-only keymaster implementation the
341 * enforced array must NULL. Hardware implementations must enforce everything in the enforced
342 * array.
343 */
344typedef struct {
345 keymaster_key_param_set_t hw_enforced;
346 keymaster_key_param_set_t sw_enforced;
347} keymaster_key_characteristics_t;
348
349typedef struct {
350 const uint8_t* key_material;
351 size_t key_material_size;
352} keymaster_key_blob_t;
353
354/**
355 * Formats for key import and export. At present, only asymmetric key import/export is supported.
356 * In the future this list will expand greatly to accommodate asymmetric key import/export.
357 */
358typedef enum {
359 KM_KEY_FORMAT_X509, /* for public key export, required */
360 KM_KEY_FORMAT_PKCS8, /* for asymmetric key pair import, required */
361 KM_KEY_FORMAT_PKCS12, /* for asymmetric key pair import, not required */
Shawn Willdene1b76362015-02-03 11:12:20 -0700362 KM_KEY_FORMAT_RAW, /* for symmetric key import, required */
Shawn Willden9d645a02014-06-12 13:48:46 -0600363} keymaster_key_format_t;
364
365/**
366 * The keymaster operation API consists of begin, update, finish and abort. This is the type of the
367 * handle used to tie the sequence of calls together. A 64-bit value is used because it's important
368 * that handles not be predictable. Implementations must use strong random numbers for handle
369 * values.
370 */
371typedef uint64_t keymaster_operation_handle_t;
372
373typedef enum {
374 KM_ERROR_OK = 0,
375 KM_ERROR_ROOT_OF_TRUST_ALREADY_SET = -1,
376 KM_ERROR_UNSUPPORTED_PURPOSE = -2,
377 KM_ERROR_INCOMPATIBLE_PURPOSE = -3,
378 KM_ERROR_UNSUPPORTED_ALGORITHM = -4,
379 KM_ERROR_INCOMPATIBLE_ALGORITHM = -5,
380 KM_ERROR_UNSUPPORTED_KEY_SIZE = -6,
381 KM_ERROR_UNSUPPORTED_BLOCK_MODE = -7,
382 KM_ERROR_INCOMPATIBLE_BLOCK_MODE = -8,
Shawn Willden6b424be2015-01-26 13:04:28 -0700383 KM_ERROR_UNSUPPORTED_MAC_LENGTH = -9,
Shawn Willden9d645a02014-06-12 13:48:46 -0600384 KM_ERROR_UNSUPPORTED_PADDING_MODE = -10,
385 KM_ERROR_INCOMPATIBLE_PADDING_MODE = -11,
386 KM_ERROR_UNSUPPORTED_DIGEST = -12,
387 KM_ERROR_INCOMPATIBLE_DIGEST = -13,
388 KM_ERROR_INVALID_EXPIRATION_TIME = -14,
389 KM_ERROR_INVALID_USER_ID = -15,
390 KM_ERROR_INVALID_AUTHORIZATION_TIMEOUT = -16,
391 KM_ERROR_UNSUPPORTED_KEY_FORMAT = -17,
392 KM_ERROR_INCOMPATIBLE_KEY_FORMAT = -18,
393 KM_ERROR_UNSUPPORTED_KEY_ENCRYPTION_ALGORITHM = -19, /* For PKCS8 & PKCS12 */
394 KM_ERROR_UNSUPPORTED_KEY_VERIFICATION_ALGORITHM = -20, /* For PKCS8 & PKCS12 */
395 KM_ERROR_INVALID_INPUT_LENGTH = -21,
396 KM_ERROR_KEY_EXPORT_OPTIONS_INVALID = -22,
397 KM_ERROR_DELEGATION_NOT_ALLOWED = -23,
398 KM_ERROR_KEY_NOT_YET_VALID = -24,
399 KM_ERROR_KEY_EXPIRED = -25,
400 KM_ERROR_KEY_USER_NOT_AUTHENTICATED = -26,
401 KM_ERROR_OUTPUT_PARAMETER_NULL = -27,
402 KM_ERROR_INVALID_OPERATION_HANDLE = -28,
403 KM_ERROR_INSUFFICIENT_BUFFER_SPACE = -29,
404 KM_ERROR_VERIFICATION_FAILED = -30,
405 KM_ERROR_TOO_MANY_OPERATIONS = -31,
406 KM_ERROR_UNEXPECTED_NULL_POINTER = -32,
407 KM_ERROR_INVALID_KEY_BLOB = -33,
408 KM_ERROR_IMPORTED_KEY_NOT_ENCRYPTED = -34,
409 KM_ERROR_IMPORTED_KEY_DECRYPTION_FAILED = -35,
410 KM_ERROR_IMPORTED_KEY_NOT_SIGNED = -36,
411 KM_ERROR_IMPORTED_KEY_VERIFICATION_FAILED = -37,
412 KM_ERROR_INVALID_ARGUMENT = -38,
413 KM_ERROR_UNSUPPORTED_TAG = -39,
414 KM_ERROR_INVALID_TAG = -40,
415 KM_ERROR_MEMORY_ALLOCATION_FAILED = -41,
416 KM_ERROR_INVALID_RESCOPING = -42,
417 KM_ERROR_INVALID_DSA_PARAMS = -43,
418 KM_ERROR_IMPORT_PARAMETER_MISMATCH = -44,
419 KM_ERROR_SECURE_HW_ACCESS_DENIED = -45,
420 KM_ERROR_OPERATION_CANCELLED = -46,
421 KM_ERROR_CONCURRENT_ACCESS_CONFLICT = -47,
422 KM_ERROR_SECURE_HW_BUSY = -48,
423 KM_ERROR_SECURE_HW_COMMUNICATION_FAILED = -49,
424 KM_ERROR_UNSUPPORTED_EC_FIELD = -50,
425 KM_ERROR_UNIMPLEMENTED = -100,
426 KM_ERROR_VERSION_MISMATCH = -101,
427
428 /* Additional error codes may be added by implementations, but implementers should coordinate
429 * with Google to avoid code collision. */
430 KM_ERROR_UNKNOWN_ERROR = -1000,
431} keymaster_error_t;
432
433/**
434 * \deprecated Parameters needed to generate an RSA key.
435 */
436typedef struct {
437 uint32_t modulus_size; /* bits */
438 uint64_t public_exponent;
439} keymaster_rsa_keygen_params_t;
440
441/**
442 * \deprecated Parameters needed to generate a DSA key.
443 */
444typedef struct {
445 uint32_t key_size; /* bits */
446 uint32_t generator_len;
447 uint32_t prime_p_len;
448 uint32_t prime_q_len;
449 const uint8_t* generator;
450 const uint8_t* prime_p;
451 const uint8_t* prime_q;
452} keymaster_dsa_keygen_params_t;
453
454/**
455 * \deprecated Parameters needed to generate an EC key.
456 *
457 * Field size is the only parameter in version 4. The sizes correspond to these required curves:
458 *
459 * 192 = NIST P-192
460 * 224 = NIST P-224
461 * 256 = NIST P-256
462 * 384 = NIST P-384
463 * 521 = NIST P-521
464 *
465 * The parameters for these curves are available at: http://www.nsa.gov/ia/_files/nist-routines.pdf
466 * in Chapter 4.
467 */
468typedef struct { uint32_t field_size; /* bits */ } keymaster_ec_keygen_params_t;
469
470/**
471 * \deprecated Type of padding used for RSA operations.
472 */
473typedef enum {
474 PADDING_NONE,
475} keymaster_rsa_padding_t;
476
477/**
478 * \deprecated
479 */
480typedef struct { keymaster_digest_t digest_type; } keymaster_dsa_sign_params_t;
481
482/**
483 * \deprecated
484 */
485typedef struct { keymaster_digest_t digest_type; } keymaster_ec_sign_params_t;
486
487/**
488 *\deprecated
489 */
490typedef struct {
491 keymaster_digest_t digest_type;
492 keymaster_rsa_padding_t padding_type;
493} keymaster_rsa_sign_params_t;
494
495/* Convenience functions for manipulating keymaster tag types */
496
497static inline keymaster_tag_type_t keymaster_tag_get_type(keymaster_tag_t tag) {
498 return (keymaster_tag_type_t)(tag & (0xF << 28));
499}
500
501static inline uint32_t keymaster_tag_mask_type(keymaster_tag_t tag) {
502 return tag & 0x0FFFFFFF;
503}
504
505static inline bool keymaster_tag_type_repeatable(keymaster_tag_type_t type) {
506 switch (type) {
507 case KM_INT_REP:
508 case KM_ENUM_REP:
509 return true;
510 default:
511 return false;
512 }
513}
514
515static inline bool keymaster_tag_repeatable(keymaster_tag_t tag) {
516 return keymaster_tag_type_repeatable(keymaster_tag_get_type(tag));
517}
518
519/* Convenience functions for manipulating keymaster_key_param_t structs */
520
521inline keymaster_key_param_t keymaster_param_enum(keymaster_tag_t tag, uint32_t value) {
522 // assert(keymaster_tag_get_type(tag) == KM_ENUM || keymaster_tag_get_type(tag) == KM_ENUM_REP);
523 keymaster_key_param_t param;
524 memset(&param, 0, sizeof(param));
525 param.tag = tag;
526 param.enumerated = value;
527 return param;
528}
529
530inline keymaster_key_param_t keymaster_param_int(keymaster_tag_t tag, uint32_t value) {
531 // assert(keymaster_tag_get_type(tag) == KM_INT || keymaster_tag_get_type(tag) == KM_INT_REP);
532 keymaster_key_param_t param;
533 memset(&param, 0, sizeof(param));
534 param.tag = tag;
535 param.integer = value;
536 return param;
537}
538
539inline keymaster_key_param_t keymaster_param_long(keymaster_tag_t tag, uint64_t value) {
540 // assert(keymaster_tag_get_type(tag) == KM_LONG);
541 keymaster_key_param_t param;
542 memset(&param, 0, sizeof(param));
543 param.tag = tag;
544 param.long_integer = value;
545 return param;
546}
547
548inline keymaster_key_param_t keymaster_param_blob(keymaster_tag_t tag, const uint8_t* bytes,
549 size_t bytes_len) {
550 // assert(keymaster_tag_get_type(tag) == KM_BYTES || keymaster_tag_get_type(tag) == KM_BIGNUM);
551 keymaster_key_param_t param;
552 memset(&param, 0, sizeof(param));
553 param.tag = tag;
554 param.blob.data = (uint8_t*)bytes;
555 param.blob.data_length = bytes_len;
556 return param;
557}
558
559inline keymaster_key_param_t keymaster_param_bool(keymaster_tag_t tag) {
560 // assert(keymaster_tag_get_type(tag) == KM_BOOL);
561 keymaster_key_param_t param;
562 memset(&param, 0, sizeof(param));
563 param.tag = tag;
564 param.boolean = true;
565 return param;
566}
567
568inline keymaster_key_param_t keymaster_param_date(keymaster_tag_t tag, uint64_t value) {
569 // assert(keymaster_tag_get_type(tag) == KM_DATE);
570 keymaster_key_param_t param;
571 memset(&param, 0, sizeof(param));
572 param.tag = tag;
573 param.date_time = value;
574 return param;
575}
576
577inline void keymaster_free_param_values(keymaster_key_param_t* param, size_t param_count) {
578 while (param_count-- > 0) {
579 switch (keymaster_tag_get_type(param->tag)) {
580 case KM_BIGNUM:
581 case KM_BYTES:
582 free((void*)param->blob.data);
583 param->blob.data = NULL;
584 break;
585 default:
586 // NOP
587 break;
588 }
589 ++param;
590 }
591}
592
593inline void keymaster_free_param_set(keymaster_key_param_set_t* set) {
594 if (set) {
595 keymaster_free_param_values(set->params, set->length);
596 free(set->params);
597 set->params = NULL;
598 }
599}
600
601inline void keymaster_free_characteristics(keymaster_key_characteristics_t* characteristics) {
602 if (characteristics) {
603 keymaster_free_param_set(&characteristics->hw_enforced);
604 keymaster_free_param_set(&characteristics->sw_enforced);
605 }
606}
607
608#if defined(__cplusplus)
609} // extern "C"
610#endif // defined(__cplusplus)
611
612#endif // ANDROID_HARDWARE_KEYMASTER_DEFS_H