blob: 5dac9291b64754ff8072c7459cb3ffe7e43c68a9 [file] [log] [blame]
Shawn Willden1e50c672017-11-10 11:49:02 -07001/*
2 * Copyright (C) 2017 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
17package android.hardware.keymaster@4.0;
18
19import android.hardware.keymaster@3.0::ErrorCode;
20import android.hardware.keymaster@3.0::KeyFormat;
21
22/**
23 * Keymaster device definition. For thorough documentation see the implementer's reference, at
24 * https://source.android.com/security/keystore/implementer-ref.html
25 */
Shawn Willden32aa7ec2017-11-30 19:35:54 -070026interface IKeymasterDevice {
Shawn Willden1e50c672017-11-10 11:49:02 -070027
28 /**
Shawn Willden9e0c1fe2017-10-30 17:57:42 -060029 * Returns information about the underlying Keymaster hardware.
Shawn Willden1e50c672017-11-10 11:49:02 -070030 *
Shawn Willden9e0c1fe2017-10-30 17:57:42 -060031 * @return security level of the Keymaster implementation accessed through this HAL.
Shawn Willden1e50c672017-11-10 11:49:02 -070032 *
Shawn Willden9e0c1fe2017-10-30 17:57:42 -060033 * @return keymasterName is the name of the Keymaster implementation.
Shawn Willden1e50c672017-11-10 11:49:02 -070034 *
Shawn Willden9e0c1fe2017-10-30 17:57:42 -060035 * @return keymasterAuthorName is the name of the author of the Keymaster implementation
Shawn Willden1e50c672017-11-10 11:49:02 -070036 * (organization name, not individual).
37 */
Shawn Willden9e0c1fe2017-10-30 17:57:42 -060038 getHardwareInfo()
39 generates (SecurityLevel securityLevel, string keymasterName, string keymasterAuthorName);
Shawn Willden1e50c672017-11-10 11:49:02 -070040
41 /**
Shawn Willden9e0c1fe2017-10-30 17:57:42 -060042 * Start the creation of an HMAC key, shared with another Keymaster implementation. Any device
43 * with a StrongBox Keymaster has two Keymaster instances, because there must be a TEE Keymaster
44 * as well. The HMAC key used to MAC and verify authentication tokens must be shared between
45 * TEE and StrongBox so they can each validate tokens produced by the other. This method is the
46 * first step in the process for for agreeing on a shared key. It is called by Keystore during
47 * startup if and only if Keystore loads multiple Keymaster HALs. Keystore calls it on each of
48 * the HAL instances and collects the results in preparation for the second step.
49 */
50 getHmacSharingParameters() generates (ErrorCode error, HmacSharingParameters params);
51
52 /**
53 * Complete the creation of an HMAC key, shared with another Keymaster implementation. Any
54 * device with a StrongBox Keymaster has two Keymasters instances, because there must be a TEE
55 * Keymaster as well. The HMAC key used to MAC and verify authentication tokens must be shared
56 * between TEE and StrongBox so they can each validate tokens produced by the other. This
Janis Danisevskisd29fb732017-12-27 09:09:38 -080057 * method is the second and final step in the process for agreeing on a shared key. It is
Shawn Willden9e0c1fe2017-10-30 17:57:42 -060058 * called by Keystore during startup if and only if Keystore loads multiple Keymaster HALs.
59 * Keystore calls it on each of the HAL instances, and sends to it all of the
60 * HmacSharingParameters returned by all HALs.
61 *
62 * This method computes the shared 32-byte HMAC ``H'' as follows (all Keymaster instances
63 * perform the same computation to arrive at the same result):
64 *
65 * H = CKDF(key = K,
66 * context = P1 || P2 || ... || Pn,
67 * label = "KeymasterSharedMac")
68 *
69 * where:
70 *
71 * ``CKDF'' is the standard AES-CMAC KDF from NIST SP 800-108 in counter mode (see Section
72 * 5.1 of the referenced publication). ``key'', ``context'', and ``label'' are
73 * defined in the standard. The counter is prefixed, as shown in the construction on
74 * page 12 of the standard. The label string is UTF-8 encoded.
75 *
76 * ``K'' is a pre-established shared secret, set up during factory reset. The mechanism for
77 * establishing this shared secret is implementation-defined, but see below for a
78 * recommended approach, which assumes that the TEE Keymaster does not have storage
79 * available to it, but the StrongBox Keymaster does.
80 *
81 * <b>CRITICAL SECURITY REQUIREMENT</b>: All keys created by a Keymaster instance must
82 * be cryptographically bound to the value of K, such that establishing a new K
83 * permanently destroys them.
84 *
85 * ``||'' represents concatenation.
86 *
87 * ``Pi'' is the i'th HmacSharingParameters value in the params vector. Note that at
88 * present only two Keymaster implementations are supported, but this mechanism
89 * extends without modification to any number of implementations. Encoding of an
90 * HmacSharingParameters is the concatenation of its two fields, i.e. seed || nonce.
91 *
92 * Process for establishing K:
93 *
94 * Any method of securely establishing K that ensures that an attacker cannot obtain or
95 * derive its value is acceptable. What follows is a recommended approach, to be executed
96 * during each factory reset. It relies on use of the factory-installed attestation keys to
Janis Danisevskisd29fb732017-12-27 09:09:38 -080097 * mitigate man-in-the-middle attacks. This protocol requires that one of the instances
Shawn Willden9e0c1fe2017-10-30 17:57:42 -060098 * have secure persistent storage. This model was chosen because StrongBox has secure
99 * persistent storage (by definition), but the TEE may not. The instance without storage is
100 * assumed to be able to derive a unique hardware-bound key (HBK) which is used only for
101 * this purpose, and is not derivable outside of the secure environment..
102 *
103 * In what follows, T is the Keymaster instance without storage, S is the Keymaster instance
104 * with storage:
105 *
106 * 1. T generates an ephemeral EC P-256 key pair K1
107 * 2. T sends K1_pub to S, signed with T's attestation key.
108 * 3. S validates the signature on K1_pub.
109 * 4. S generates an ephemeral EC P-256 key pair K2.
110 * 5. S sends {K1_pub, K2_pub}, to T, signed with S's attestation key.
111 * 6. T validates the signature on {K1_pub, K2_pub}
112 * 7. T uses {K1_priv, K2_pub} with ECDH to compute session secret Q.
113 * 8. T generates a random seed S
114 * 9. T computes K = KDF(HBK, S), where KDF is some secure key derivation function.
115 * 10. T sends M = AES-GCM-ENCRYPT(Q, {S || K}) to S.
116 * 10. S uses {K2_priv, K1_pub} with ECDH to compute session secret Q.
117 * 11. S computes S || K = AES-GCM-DECRYPT(Q, M) and stores S and K.
118 *
119 * When S receives the getHmacSharingParameters call, it returns the stored S as the seed
120 * and a nonce. When T receives the same call, it returns an empty seed and a nonce. When
121 * T receives the computeSharedHmac call, it uses the seed provided by S to compute K. S,
122 * of course, has K stored.
123 *
124 * @param params The HmacSharingParameters data returned by all Keymaster instances when
125 * getHmacSharingParameters was called.
126 *
127 * @return sharingCheck A 32-byte value used to verify that all Keymaster instances have
128 * computed the same shared HMAC key. The sharingCheck value is computed as follows:
129 *
130 * sharingCheck = HMAC(H, "Keymaster HMAC Verification")
131 *
132 * The string is UTF-8 encoded. If the returned values of all Keymaster instances don't
133 * match, Keystore will assume that HMAC agreement failed.
134 */
135 computeSharedHmac(vec<HmacSharingParameters> params)
136 generates (ErrorCode error, vec<uint8_t> sharingCheck);
137
138 /**
139 * Verify authorizations for another Keymaster instance.
140 *
141 * On systems with both a StrongBox and a TEE Keymaster instance it is sometimes useful to ask
142 * the TEE Keymaster to verify authorizations for a key hosted in StrongBox.
143 *
144 * For every StrongBox operation, Keystore is required to call this method on the TEE Keymaster,
145 * passing in the StrongBox key's hardwareEnforced authorization list and the operation handle
146 * returned by StrongBox begin(). The TEE Keymaster must validate all of the authorizations it
147 * can and return those it validated in the VerificationToken. If it cannot verify any, the
148 * parametersVerified field of the VerificationToken must be empty. Keystore must then pass the
149 * VerificationToken to the subsequent invocations of StrongBox update() and finish().
150 *
151 * StrongBox implementations must return ErrorCode::UNIMPLEMENTED.
152 *
153 * @param operationHandle the operation handle returned by StrongBox Keymaster's begin().
154 *
155 * @param parametersToVerify Set of authorizations to verify.
156 *
157 * @param authToken A HardwareAuthToken if needed to authorize key usage.
158 */
159 verifyAuthorization(uint64_t operationHandle, vec<KeyParameter> parametersToVerify,
160 HardwareAuthToken authToken)
161 generates (ErrorCode error, VerificationToken token);
162
163
164 /**
165 * Adds entropy to the RNG used by Keymaster. Entropy added through this method is guaranteed
166 * not to be the only source of entropy used, and the mixing function is required to be secure,
167 * in the sense that if the RNG is seeded (from any source) with any data the attacker cannot
168 * predict (or control), then the RNG output is indistinguishable from random. Thus, if the
169 * entropy from any source is good, the output must be good.
Shawn Willden1e50c672017-11-10 11:49:02 -0700170 *
171 * @param data Bytes to be mixed into the RNG.
172 *
173 * @return error See the ErrorCode enum in types.hal.
174 */
175 addRngEntropy(vec<uint8_t> data) generates (ErrorCode error);
176
177 /**
178 * Generates a key, or key pair, returning a key blob and a description of the key.
179 *
Shawn Willden9e0c1fe2017-10-30 17:57:42 -0600180 * @param keyParams Key generation parameters are defined as Keymaster tag/value pairs, provided
Shawn Willden1e50c672017-11-10 11:49:02 -0700181 * in params. See Tag in types.hal for the full list.
182 *
183 * @return error See the ErrorCode enum in types.hal.
184 *
185 * @return keyBlob Opaque, encrypted descriptor of the generated key. A recommended
186 * implementation strategy is to include an encrypted copy of the key material, wrapped
187 * in a key unavailable outside secure hardware.
188 *
189 * @return keyCharacteristics Description of the generated key. See KeyCharacteristis in
190 * types.hal.
191 */
192 generateKey(vec<KeyParameter> keyParams)
193 generates (ErrorCode error, vec<uint8_t> keyBlob, KeyCharacteristics keyCharacteristics);
194
195 /**
196 * Imports a key, or key pair, returning a key blob and/or a description of the key.
197 *
Shawn Willden9e0c1fe2017-10-30 17:57:42 -0600198 * @param keyParams Key generation parameters are defined as Keymaster tag/value pairs, provided
Shawn Willden1e50c672017-11-10 11:49:02 -0700199 * in params. See Tag for the full list.
200 *
201 * @param keyFormat The format of the key material to import.
202 *
203 * @pram keyData The key material to import, in the format specifed in keyFormat.
204 *
205 * @return error See the ErrorCode enum.
206 *
207 * @return keyBlob Opaque, encrypted descriptor of the generated key, which will generally
208 * contain a copy of the key material, wrapped in a key unavailable outside secure
209 * hardware.
210 *
211 * @return keyCharacteristics Decription of the generated key.
212 */
213 importKey(vec<KeyParameter> keyParams, KeyFormat keyFormat, vec<uint8_t> keyData)
214 generates (ErrorCode error, vec<uint8_t> keyBlob, KeyCharacteristics keyCharacteristics);
215
216 /**
Shawn Willden9e0c1fe2017-10-30 17:57:42 -0600217 * Securely imports a key, or key pair, returning a key blob and a description of the imported
218 * key.
219 *
220 * @param wrappedKeyData The wrapped key material to import. The wrapped key is in DER-encoded
221 * ASN.1 format, specified by the following schema:
222 *
223 * KeyDescription ::= SEQUENCE(
224 * keyFormat INTEGER, # Values from KeyFormat enum.
225 * keyParams AuthorizationList,
226 * )
227 *
228 * SecureKeyWrapper ::= SEQUENCE(
229 * version INTEGER, # Contains value 0
230 * encryptedTransportKey OCTET_STRING,
231 * initializationVector OCTET_STRING,
232 * keyDescription KeyDescription,
233 * encryptedKey OCTET_STRING,
234 * tag OCTET_STRING
235 * )
236 *
237 * Where:
238 *
239 * o keyFormat is an integer from the KeyFormat enum, defining the format of the plaintext
240 * key material.
241 * o keyParams is the characteristics of the key to be imported (as with generateKey or
242 * importKey). If the secure import is successful, these characteristics must be
243 * associated with the key exactly as if the key material had been insecurely imported
244 * with the @3.0::IKeymasterDevice::importKey.
245 * o encryptedTransportKey is a 256-bit AES key, XORed with a masking key and then encrypted
246 * in RSA-OAEP mode (SHA-256 digest, SHA-1 MGF1 digest) with the wrapping key specified by
247 * wrappingKeyBlob.
248 * o keyDescription is a KeyDescription, above.
249 * o encryptedKey is the key material of the key to be imported, in format keyFormat, and
250 * encrypted with encryptedEphemeralKey in AES-GCM mode, with the DER-encoded
251 * representation of keyDescription provided as additional authenticated data.
252 * o tag is the tag produced by the AES-GCM encryption of encryptedKey.
253 *
254 * So, importWrappedKey does the following:
255 *
256 * 1. Get the private key material for wrappingKeyBlob, verifying that the wrapping key has
257 * purpose KEY_WRAP, padding mode RSA_OAEP, and digest SHA_2_256, returning the
258 * appropriate error if any of those requirements fail.
259 * 2. Extract the encryptedTransportKey field from the SecureKeyWrapper, and decrypt
260 * it with the wrapping key.
261 * 3. XOR the result of step 2 with maskingKey.
262 * 4. Use the result of step 3 as an AES-GCM key to decrypt encryptedKey, using the encoded
263 * value of keyDescription as the additional authenticated data. Call the result
264 * "keyData" for the next step.
265 * 5. Perform the equivalent of calling importKey(keyParams, keyFormat, keyData), except
266 * that the origin tag should be set to SECURELY_IMPORTED.
267 *
268 * @param wrappingKeyBlob The opaque key descriptor returned by generateKey() or importKey().
269 * This key must have been created with Purpose::WRAP_KEY, and must be a key algorithm
270 * that supports encryption and must be at least as strong (in key size) as the key to be
271 * imported (per NIST key length recommendations: 112 bits symmetric is equivalent to
272 * 2048-bit RSA or 224-bit EC, 128 bits symmetric ~ 3072-bit RSA or 256-bit EC, etc.).
273 *
274 * @param maskingKey The 32-byte value XOR'd with the transport key in the SecureWrappedKey
275 * structure.
276 *
Shawn Willden8d28efa2018-01-19 13:37:42 -0700277 * @param unwrappingParams must contain any parameters needed to perform the unwrapping
278 * operation. For example, if the wrapping key is an AES key the block and padding modes
279 * must be specified in this argument.
280 *
281 * @param passwordSid specifies the password secure ID (SID) of the user that owns the key being
282 * installed. If the authorization list in wrappedKeyData contains a Tag::USER_SECURE_ID
283 * with a value that has the HardwareAuthenticatorType::PASSWORD bit set, the constructed
284 * key must be bound to the SID value provided by this argument. If the wrappedKeyData
285 * does not contain such a tag and value, this argument must be ignored.
286 *
287 * @param biometricSid specifies the biometric secure ID (SID) of the user that owns the key
288 * being installed. If the authorization list in wrappedKeyData contains a
289 * Tag::USER_SECURE_ID with a value that has the HardwareAuthenticatorType::FINGERPRINT
290 * bit set, the constructed key must be bound to the SID value provided by this argument.
291 * If the wrappedKeyData does not contain such a tag and value, this argument must be
292 * ignored.
293 *
Shawn Willden9e0c1fe2017-10-30 17:57:42 -0600294 * @return error See the ErrorCode enum.
295 *
296 * @return keyBlob Opaque descriptor of the imported key. It is recommended that the keyBlob
297 * contain a copy of the key material, wrapped in a key unavailable outside secure
298 * hardware.
299 */
300 importWrappedKey(vec<uint8_t> wrappedKeyData, vec<uint8_t> wrappingKeyBlob,
Shawn Willden8d28efa2018-01-19 13:37:42 -0700301 vec<uint8_t> maskingKey, vec<KeyParameter> unwrappingParams,
302 uint64_t passwordSid, uint64_t biometricSid)
303 generates(ErrorCode error, vec<uint8_t> keyBlob, KeyCharacteristics keyCharacteristics);
Shawn Willden9e0c1fe2017-10-30 17:57:42 -0600304
305 /**
Shawn Willden1e50c672017-11-10 11:49:02 -0700306 * Returns the characteristics of the specified key, if the keyBlob is valid (implementations
307 * must fully validate the integrity of the key).
308 *
309 * @param keyBlob The opaque descriptor returned by generateKey() or importKey();
310 *
311 * @param clientId An opaque byte string identifying the client. This value must match the
312 * Tag::APPLICATION_ID data provided during key generation/import. Without the correct
313 * value, it must be computationally infeasible for the secure hardware to obtain the key
314 * material.
315 *
316 * @param appData An opaque byte string provided by the application. This value must match the
317 * Tag::APPLICATION_DATA data provided during key generation/import. Without the correct
318 * value, it must be computationally infeasible for the secure hardware to obtain the key
319 * material.
320 *
321 * @return error See the ErrorCode enum in types.hal.
322 *
323 * @return keyCharacteristics Decription of the generated key. See KeyCharacteristis in
324 * types.hal.
325 */
326 getKeyCharacteristics(vec<uint8_t> keyBlob, vec<uint8_t> clientId, vec<uint8_t> appData)
327 generates (ErrorCode error, KeyCharacteristics keyCharacteristics);
328
329 /**
330 * Exports a public key, returning the key in the specified format.
331 *
332 * @parm keyFormat The format used for export. See KeyFormat in types.hal.
333 *
334 * @param keyBlob The opaque descriptor returned by generateKey() or importKey(). The
335 * referenced key must be asymmetric.
336 *
337 * @param clientId An opaque byte string identifying the client. This value must match the
338 * Tag::APPLICATION_ID data provided during key generation/import. Without the correct
339 * value, it must be computationally infeasible for the secure hardware to obtain the key
340 * material.
341 *
342 * @param appData An opaque byte string provided by the application. This value must match the
343 * Tag::APPLICATION_DATA data provided during key generation/import. Without the correct
344 * value, it must be computationally infeasible for the secure hardware to obtain the key
345 * material.
346 *
347 * @return error See the ErrorCode enum in types.hal.
348 *
349 * @return keyMaterial The public key material in PKCS#8 format.
350 */
351 exportKey(KeyFormat keyFormat, vec<uint8_t> keyBlob, vec<uint8_t> clientId,
352 vec<uint8_t> appData) generates (ErrorCode error, vec<uint8_t> keyMaterial);
353
354 /**
355 * Generates a signed X.509 certificate chain attesting to the presence of keyToAttest in
Shawn Willden9e0c1fe2017-10-30 17:57:42 -0600356 * Keymaster. The certificate must contain an extension with OID 1.3.6.1.4.1.11129.2.1.17 and
Shawn Willden1e50c672017-11-10 11:49:02 -0700357 * value defined in:
358 *
359 * https://developer.android.com/training/articles/security-key-attestation.html.
360 *
361 * @param keyToAttest The opaque descriptor returned by generateKey() or importKey(). The
362 * referenced key must be asymmetric.
363 *
364 * @param attestParams Parameters for the attestation, notably Tag::ATTESTATION_CHALLENGE.
365 *
366 * @return error See the ErrorCode enum in types.hal.
367 *
368 * @return certChain The attestation certificate, and additional certificates back to the root
369 * attestation certificate, which clients will need to check against a known-good value.
370 */
371 attestKey(vec<uint8_t> keyToAttest, vec<KeyParameter> attestParams)
372 generates (ErrorCode error, vec<vec<uint8_t>> certChain);
373
374 /**
375 * Upgrades an old key blob. Keys can become "old" in two ways: Keymaster can be upgraded to a
376 * new version with an incompatible key blob format, or the system can be updated to invalidate
377 * the OS version and/or patch level. In either case, attempts to use an old key blob with
Shawn Willden9e0c1fe2017-10-30 17:57:42 -0600378 * getKeyCharacteristics(), exportKey(), attestKey() or begin() must result in Keymaster
Shawn Willden1e50c672017-11-10 11:49:02 -0700379 * returning ErrorCode::KEY_REQUIRES_UPGRADE. The caller must use this method to upgrade the
380 * key blob.
381 *
382 * @param keyBlobToUpgrade The opaque descriptor returned by generateKey() or importKey();
383 *
384 * @param upgradeParams A parameter list containing any parameters needed to complete the
385 * upgrade, including Tag::APPLICATION_ID and Tag::APPLICATION_DATA.
386 *
387 * @return error See the ErrorCode enum.
388 *
389 * @return upgradedKeyBlob A new key blob that references the same key as keyBlobToUpgrade, but
390 * is in the new format, or has the new version data.
391 */
392 upgradeKey(vec<uint8_t> keyBlobToUpgrade, vec<KeyParameter> upgradeParams)
393 generates (ErrorCode error, vec<uint8_t> upgradedKeyBlob);
394
395 /**
396 * Deletes the key, or key pair, associated with the key blob. Calling this function on a key
397 * with Tag::ROLLBACK_RESISTANCE in its hardware-enforced authorization list must render the key
398 * permanently unusable. Keys without Tag::ROLLBACK_RESISTANCE may or may not be rendered
399 * unusable.
400 *
401 * @param keyBlob The opaque descriptor returned by generateKey() or importKey();
402 *
403 * @return error See the ErrorCode enum.
404 */
405 deleteKey(vec<uint8_t> keyBlob) generates (ErrorCode error);
406
407 /**
408 * Deletes all keys in the hardware keystore. Used when keystore is reset completely. After
409 * this function is called all keys with Tag::ROLLBACK_RESISTANCE in their hardware-enforced
410 * authorization lists must be rendered permanently unusable. Keys without
411 * Tag::ROLLBACK_RESISTANCE may or may not be rendered unusable.
412 *
413 * @return error See the ErrorCode enum.
414 */
415 deleteAllKeys() generates (ErrorCode error);
416
417 /**
418 * Destroys knowledge of the device's ids. This prevents all device id attestation in the
419 * future. The destruction must be permanent so that not even a factory reset will restore the
420 * device ids.
421 *
422 * Device id attestation may be provided only if this method is fully implemented, allowing the
423 * user to permanently disable device id attestation. If this cannot be guaranteed, the device
424 * must never attest any device ids.
425 *
426 * This is a NOP if device id attestation is not supported.
427 *
428 * @return error See the ErrorCode enum.
429 */
430 destroyAttestationIds() generates (ErrorCode error);
431
432 /**
433 * Begins a cryptographic operation using the specified key. If all is well, begin() must
434 * return ErrorCode::OK and create an operation handle which must be passed to subsequent calls
435 * to update(), finish() or abort().
436 *
437 * It is critical that each call to begin() be paired with a subsequent call to finish() or
Shawn Willden9e0c1fe2017-10-30 17:57:42 -0600438 * abort(), to allow the Keymaster implementation to clean up any internal operation state. The
Shawn Willden1e50c672017-11-10 11:49:02 -0700439 * caller's failure to do this may leak internal state space or other internal resources and may
440 * eventually cause begin() to return ErrorCode::TOO_MANY_OPERATIONS when it runs out of space
441 * for operations. Any result other than ErrorCode::OK from begin(), update() or finish()
442 * implicitly aborts the operation, in which case abort() need not be called (and must return
443 * ErrorCode::INVALID_OPERATION_HANDLE if called).
444 *
445 * @param purpose The purpose of the operation, one of KeyPurpose::ENCRYPT, KeyPurpose::DECRYPT,
446 * KeyPurpose::SIGN or KeyPurpose::VERIFY. Note that for AEAD modes, encryption and
447 * decryption imply signing and verification, respectively, but must be specified as
448 * KeyPurpose::ENCRYPT and KeyPurpose::DECRYPT.
449 *
450 * @param keyBlob The opaque key descriptor returned by generateKey() or importKey(). The key
451 * must have a purpose compatible with purpose and all of its usage requirements must be
452 * satisfied, or begin() must return an appropriate error code.
453 *
454 * @param inParams Additional parameters for the operation. If Tag::APPLICATION_ID or
455 * Tag::APPLICATION_DATA were provided during generation, they must be provided here, or
456 * the operation must fail with ErrorCode::INVALID_KEY_BLOB. For operations that require
457 * a nonce or IV, on keys that were generated with Tag::CALLER_NONCE, inParams may
458 * contain a tag Tag::NONCE. If Tag::NONCE is provided for a key without
459 * Tag:CALLER_NONCE, ErrorCode::CALLER_NONCE_PROHIBITED must be returned.
460 *
461 * @param authToken Authentication token. Callers that provide no token must set all numeric
462 * fields to zero and the MAC must be an empty vector.
463 *
464 * @return error See the ErrorCode enum in types.hal.
465 *
466 * @return outParams Output parameters. Used to return additional data from the operation
467 * initialization, notably to return the IV or nonce from operations that generate an IV
468 * or nonce.
469 *
470 * @return operationHandle The newly-created operation handle which must be passed to update(),
471 * finish() or abort().
472 */
473 begin(KeyPurpose purpose, vec<uint8_t> keyBlob, vec<KeyParameter> inParams,
474 HardwareAuthToken authToken)
475 generates (ErrorCode error, vec<KeyParameter> outParams, OperationHandle operationHandle);
476
477 /**
478 * Provides data to, and possibly receives output from, an ongoing cryptographic operation begun
479 * with begin().
480 *
481 * If operationHandle is invalid, update() must return ErrorCode::INVALID_OPERATION_HANDLE.
482 *
483 * update() may not consume all of the data provided in the data buffer. update() must return
484 * the amount consumed in inputConsumed. The caller may provide the unconsumed data in a
485 * subsequent call.
486 *
487 * @param operationHandle The operation handle returned by begin().
488 *
489 * @param inParams Additional parameters for the operation. For AEAD modes, this is used to
490 * specify Tag::ADDITIONAL_DATA. Note that additional data may be provided in multiple
491 * calls to update(), but only until input data has been provided.
492 *
493 * @param input Data to be processed. Note that update() may or may not consume all of the data
494 * provided. See inputConsumed.
495 *
496 * @param authToken Authentication token. Callers that provide no token must set all numeric
497 * fields to zero and the MAC must be an empty vector.
498 *
Shawn Willden9e0c1fe2017-10-30 17:57:42 -0600499 * @param verificationToken Verification token, used to prove that another Keymaster HAL has
500 * verified some parameters, and to deliver the other HAL's current timestamp, if needed.
501 * If not provided, all fields must be initialized to zero and vectors empty.
502 *
Shawn Willden1e50c672017-11-10 11:49:02 -0700503 * @return error See the ErrorCode enum in types.hal.
504 *
505 * @return inputConsumed Amount of data that was consumed by update(). If this is less than the
506 * amount provided, the caller may provide the remainder in a subsequent call to
507 * update() or finish(). Every call to update must consume at least one byte, and
508 * implementations should consume as much data as reasonably possible for each call.
509 *
510 * @return outParams Output parameters, used to return additional data from the operation.
511 *
512 * @return output The output data, if any.
513 */
514 update(OperationHandle operationHandle, vec<KeyParameter> inParams, vec<uint8_t> input,
Shawn Willden9e0c1fe2017-10-30 17:57:42 -0600515 HardwareAuthToken authToken, VerificationToken verificationToken)
Shawn Willden1e50c672017-11-10 11:49:02 -0700516 generates (ErrorCode error, uint32_t inputConsumed, vec<KeyParameter> outParams,
517 vec<uint8_t> output);
518
519 /**
520 * Finalizes a cryptographic operation begun with begin() and invalidates operationHandle.
521 *
522 * @param operationHandle The operation handle returned by begin(). This handle must be invalid
523 * when finish() returns.
524 *
525 * @param inParams Additional parameters for the operation. For AEAD modes, this is used to
526 * specify Tag::ADDITIONAL_DATA, but only if no input data was provided to update().
527 *
528 * @param input Data to be processed, per the parameters established in the call to begin().
529 * finish() must consume all provided data or return ErrorCode::INVALID_INPUT_LENGTH.
530 *
531 * @param signature The signature to be verified if the purpose specified in the begin() call
532 * was KeyPurpose::VERIFY.
533 *
534 * @param authToken Authentication token. Callers that provide no token must set all numeric
535 * fields to zero and the MAC must be an empty vector.
536 *
Shawn Willden9e0c1fe2017-10-30 17:57:42 -0600537 * @param verificationToken Verification token, used to prove that another Keymaster HAL has
538 * verified some parameters, and to deliver the other HAL's current timestamp, if needed.
539 * If not provided, all fields must be initialized to zero and vectors empty.
540 *
Shawn Willden1e50c672017-11-10 11:49:02 -0700541 * @return error See the ErrorCode enum in types.hal.
542 *
543 * @return outParams Any output parameters generated by finish().
544 *
545 * @return output The output data, if any.
546 */
547 finish(OperationHandle operationHandle, vec<KeyParameter> inParams, vec<uint8_t> input,
Shawn Willden9e0c1fe2017-10-30 17:57:42 -0600548 vec<uint8_t> signature, HardwareAuthToken authToken, VerificationToken verificationToken)
Shawn Willden1e50c672017-11-10 11:49:02 -0700549 generates (ErrorCode error, vec<KeyParameter> outParams, vec<uint8_t> output);
550
551 /**
552 * Aborts a cryptographic operation begun with begin(), freeing all internal resources and
553 * invalidating operationHandle.
554 *
555 * @param operationHandle The operation handle returned by begin(). This handle must be
556 * invalid when abort() returns.
557 *
558 * @return error See the ErrorCode enum in types.hal.
559 */
560 abort(OperationHandle operationHandle) generates (ErrorCode error);
561};