1*4d7e907cSAndroid Build Coastguard Worker/* 2*4d7e907cSAndroid Build Coastguard Worker * Copyright (C) 2016 The Android Open Source Project 3*4d7e907cSAndroid Build Coastguard Worker * 4*4d7e907cSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*4d7e907cSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*4d7e907cSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*4d7e907cSAndroid Build Coastguard Worker * 8*4d7e907cSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*4d7e907cSAndroid Build Coastguard Worker * 10*4d7e907cSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*4d7e907cSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*4d7e907cSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*4d7e907cSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*4d7e907cSAndroid Build Coastguard Worker * limitations under the License. 15*4d7e907cSAndroid Build Coastguard Worker */ 16*4d7e907cSAndroid Build Coastguard Worker 17*4d7e907cSAndroid Build Coastguard Workerpackage [email protected]; 18*4d7e907cSAndroid Build Coastguard Worker 19*4d7e907cSAndroid Build Coastguard Worker/** 20*4d7e907cSAndroid Build Coastguard Worker * Keymaster device definition. For thorough documentation see the implementer's reference, at 21*4d7e907cSAndroid Build Coastguard Worker * https://source.android.com/security/keystore/implementer-ref.html 22*4d7e907cSAndroid Build Coastguard Worker */ 23*4d7e907cSAndroid Build Coastguard Worker@SensitiveData 24*4d7e907cSAndroid Build Coastguard Workerinterface IKeymasterDevice { 25*4d7e907cSAndroid Build Coastguard Worker 26*4d7e907cSAndroid Build Coastguard Worker /** 27*4d7e907cSAndroid Build Coastguard Worker * Returns information about the underlying keymaster hardware. 28*4d7e907cSAndroid Build Coastguard Worker * 29*4d7e907cSAndroid Build Coastguard Worker * @return isSecure is true if keys are stored and never leave secure hardware (Trusted 30*4d7e907cSAndroid Build Coastguard Worker * Execution Environment or similar). CDD requires that all devices initially 31*4d7e907cSAndroid Build Coastguard Worker * launched with Marshmallow or later must have secure hardware. 32*4d7e907cSAndroid Build Coastguard Worker * 33*4d7e907cSAndroid Build Coastguard Worker * @return supportsEllipticCurve is true if the hardware supports Elliptic Curve cryptography 34*4d7e907cSAndroid Build Coastguard Worker * with the NIST curves (P-224, P-256, P-384, and P-521). CDD requires that all 35*4d7e907cSAndroid Build Coastguard Worker * devices initially launched with Nougat or later must support Elliptic Curve 36*4d7e907cSAndroid Build Coastguard Worker * cryptography. 37*4d7e907cSAndroid Build Coastguard Worker * 38*4d7e907cSAndroid Build Coastguard Worker * @return supportsSymmetricCryptography is true if the hardware supports symmetric 39*4d7e907cSAndroid Build Coastguard Worker * cryptography, including AES and HMAC. CDD requires that all devices initially 40*4d7e907cSAndroid Build Coastguard Worker * launched with Nougat or later must support hardware enforcement of Keymaster 41*4d7e907cSAndroid Build Coastguard Worker * authorizations. 42*4d7e907cSAndroid Build Coastguard Worker * 43*4d7e907cSAndroid Build Coastguard Worker * @return supportsAttestation is true if the hardware supports generation of Keymaster public 44*4d7e907cSAndroid Build Coastguard Worker * key attestation certificates, signed with a key injected in a secure 45*4d7e907cSAndroid Build Coastguard Worker * environment. CDD requires that all devices initially launched with Android O or 46*4d7e907cSAndroid Build Coastguard Worker * later must support hardware attestation. 47*4d7e907cSAndroid Build Coastguard Worker * 48*4d7e907cSAndroid Build Coastguard Worker * @return supportsAllDigests is true if the hardware supports all keymaster digest functions, 49*4d7e907cSAndroid Build Coastguard Worker * namely ND-5, SHA-1, SHA-224, SHA-256, SHA-384 and SHA-512. CDD requires that all 50*4d7e907cSAndroid Build Coastguard Worker * devices launched initially with Android O or later must support all digests. 51*4d7e907cSAndroid Build Coastguard Worker * 52*4d7e907cSAndroid Build Coastguard Worker * @return keymasterName is the name of the keymaster implementation. 53*4d7e907cSAndroid Build Coastguard Worker * 54*4d7e907cSAndroid Build Coastguard Worker * @return keymasterAuthorName is the name of the author of the keymaster implementation 55*4d7e907cSAndroid Build Coastguard Worker * (generally this should be the name of an organization, not an individual.) 56*4d7e907cSAndroid Build Coastguard Worker */ 57*4d7e907cSAndroid Build Coastguard Worker getHardwareFeatures() 58*4d7e907cSAndroid Build Coastguard Worker generates(bool isSecure, bool supportsEllipticCurve, bool supportsSymmetricCryptography, 59*4d7e907cSAndroid Build Coastguard Worker bool supportsAttestation, bool supportsAllDigests, string keymasterName, 60*4d7e907cSAndroid Build Coastguard Worker string keymasterAuthorName); 61*4d7e907cSAndroid Build Coastguard Worker 62*4d7e907cSAndroid Build Coastguard Worker /** 63*4d7e907cSAndroid Build Coastguard Worker * Adds entropy to the RNG used by keymaster. Entropy added through this method is guaranteed 64*4d7e907cSAndroid Build Coastguard Worker * not to be the only source of entropy used, and the mixing function is required to be secure, 65*4d7e907cSAndroid Build Coastguard Worker * in the sense that if the RNG is seeded (from any source) with any data the attacker cannot 66*4d7e907cSAndroid Build Coastguard Worker * predict (or control), then the RNG output is indistinguishable from random. Thus, if the 67*4d7e907cSAndroid Build Coastguard Worker * entropy from any source is good, the output must be good. 68*4d7e907cSAndroid Build Coastguard Worker * 69*4d7e907cSAndroid Build Coastguard Worker * @param data Bytes to be mixed into the RNG. 70*4d7e907cSAndroid Build Coastguard Worker * 71*4d7e907cSAndroid Build Coastguard Worker * @return error See the ErrorCode enum in types.hal. 72*4d7e907cSAndroid Build Coastguard Worker */ 73*4d7e907cSAndroid Build Coastguard Worker addRngEntropy(vec<uint8_t> data) generates(ErrorCode error); 74*4d7e907cSAndroid Build Coastguard Worker 75*4d7e907cSAndroid Build Coastguard Worker /** 76*4d7e907cSAndroid Build Coastguard Worker * Generates a key, or key pair, returning a key blob and/or a description of the key. 77*4d7e907cSAndroid Build Coastguard Worker * 78*4d7e907cSAndroid Build Coastguard Worker * @param keyParams Key generation parameters are defined as keymaster tag/value pairs, provided 79*4d7e907cSAndroid Build Coastguard Worker * in params. See Tag in types.hal for the full list. 80*4d7e907cSAndroid Build Coastguard Worker * 81*4d7e907cSAndroid Build Coastguard Worker * @return error See the ErrorCode enum in types.hal. 82*4d7e907cSAndroid Build Coastguard Worker * 83*4d7e907cSAndroid Build Coastguard Worker * @return keyBlob Opaque, encrypted descriptor of the generated key, which generally contains a 84*4d7e907cSAndroid Build Coastguard Worker * copy of the key material, wrapped in a key unavailable outside secure hardware. 85*4d7e907cSAndroid Build Coastguard Worker * 86*4d7e907cSAndroid Build Coastguard Worker * @return keyCharacteristics Description of the generated key. See KeyCharacteristis in 87*4d7e907cSAndroid Build Coastguard Worker * types.hal. 88*4d7e907cSAndroid Build Coastguard Worker */ 89*4d7e907cSAndroid Build Coastguard Worker generateKey(vec<KeyParameter> keyParams) 90*4d7e907cSAndroid Build Coastguard Worker generates(ErrorCode error, vec<uint8_t> keyBlob, KeyCharacteristics keyCharacteristics); 91*4d7e907cSAndroid Build Coastguard Worker 92*4d7e907cSAndroid Build Coastguard Worker /** 93*4d7e907cSAndroid Build Coastguard Worker * Imports a key, or key pair, returning a key blob and/or a description of the key. 94*4d7e907cSAndroid Build Coastguard Worker * 95*4d7e907cSAndroid Build Coastguard Worker * @param keyParams Key generation parameters are defined as keymaster tag/value pairs, provided 96*4d7e907cSAndroid Build Coastguard Worker * in params. See Tag for the full list. 97*4d7e907cSAndroid Build Coastguard Worker * 98*4d7e907cSAndroid Build Coastguard Worker * @param keyFormat The format of the key material to import. See KeyFormat in types.hal. 99*4d7e907cSAndroid Build Coastguard Worker * 100*4d7e907cSAndroid Build Coastguard Worker * @pram keyData The key material to import, in the format specifed in keyFormat. 101*4d7e907cSAndroid Build Coastguard Worker * 102*4d7e907cSAndroid Build Coastguard Worker * @return error See the ErrorCode enum. 103*4d7e907cSAndroid Build Coastguard Worker * 104*4d7e907cSAndroid Build Coastguard Worker * @return keyBlob Opaque, encrypted descriptor of the generated key, which will generally 105*4d7e907cSAndroid Build Coastguard Worker * contain a copy of the key material, wrapped in a key unavailable outside secure 106*4d7e907cSAndroid Build Coastguard Worker * hardware. 107*4d7e907cSAndroid Build Coastguard Worker * 108*4d7e907cSAndroid Build Coastguard Worker * @return keyCharacteristics Decription of the generated key. See KeyCharacteristis. 109*4d7e907cSAndroid Build Coastguard Worker * 110*4d7e907cSAndroid Build Coastguard Worker * @return error See the ErrorCode enum. 111*4d7e907cSAndroid Build Coastguard Worker */ 112*4d7e907cSAndroid Build Coastguard Worker importKey(vec<KeyParameter> params, KeyFormat keyFormat, vec<uint8_t> keyData) 113*4d7e907cSAndroid Build Coastguard Worker generates(ErrorCode error, vec<uint8_t> keyBlob, KeyCharacteristics keyCharacteristics); 114*4d7e907cSAndroid Build Coastguard Worker 115*4d7e907cSAndroid Build Coastguard Worker /** 116*4d7e907cSAndroid Build Coastguard Worker * Returns the characteristics of the specified key, if the keyBlob is valid (implementations 117*4d7e907cSAndroid Build Coastguard Worker * must fully validate the integrity of the key). 118*4d7e907cSAndroid Build Coastguard Worker * 119*4d7e907cSAndroid Build Coastguard Worker * @param keyBlob The opaque descriptor returned by generateKey() or importKey(); 120*4d7e907cSAndroid Build Coastguard Worker * 121*4d7e907cSAndroid Build Coastguard Worker * @param clientId An opaque byte string identifying the client. This value must match the 122*4d7e907cSAndroid Build Coastguard Worker * Tag::APPLICATION_ID data provided during key generation/import. Without the 123*4d7e907cSAndroid Build Coastguard Worker * correct value it must be cryptographically impossible for the secure hardware to 124*4d7e907cSAndroid Build Coastguard Worker * obtain the key material. 125*4d7e907cSAndroid Build Coastguard Worker * 126*4d7e907cSAndroid Build Coastguard Worker * @param appData An opaque byte string provided by the application. This value must match the 127*4d7e907cSAndroid Build Coastguard Worker * Tag::APPLICATION_DATA data provided during key generation/import. Without the 128*4d7e907cSAndroid Build Coastguard Worker * correct value it must be cryptographically impossible for the secure hardware to 129*4d7e907cSAndroid Build Coastguard Worker * obtain the key material. 130*4d7e907cSAndroid Build Coastguard Worker * 131*4d7e907cSAndroid Build Coastguard Worker * @return error See the ErrorCode enum in types.hal. 132*4d7e907cSAndroid Build Coastguard Worker * 133*4d7e907cSAndroid Build Coastguard Worker * @return keyCharacteristics Decription of the generated key. See KeyCharacteristis in 134*4d7e907cSAndroid Build Coastguard Worker * types.hal. 135*4d7e907cSAndroid Build Coastguard Worker */ 136*4d7e907cSAndroid Build Coastguard Worker getKeyCharacteristics(vec<uint8_t> keyBlob, vec<uint8_t> clientId, vec<uint8_t> appData) 137*4d7e907cSAndroid Build Coastguard Worker generates(ErrorCode error, KeyCharacteristics keyCharacteristics); 138*4d7e907cSAndroid Build Coastguard Worker 139*4d7e907cSAndroid Build Coastguard Worker /** 140*4d7e907cSAndroid Build Coastguard Worker * Exports a public key, returning the key in the specified format. 141*4d7e907cSAndroid Build Coastguard Worker * 142*4d7e907cSAndroid Build Coastguard Worker * @parm keyFormat The format used for export. See KeyFormat in types.hal. 143*4d7e907cSAndroid Build Coastguard Worker * 144*4d7e907cSAndroid Build Coastguard Worker * @param keyBlob The opaque descriptor returned by generateKey() or importKey(). The 145*4d7e907cSAndroid Build Coastguard Worker * referenced key must be asymmetric. 146*4d7e907cSAndroid Build Coastguard Worker * 147*4d7e907cSAndroid Build Coastguard Worker * @param clientId An opaque byte string identifying the client. This value must match the 148*4d7e907cSAndroid Build Coastguard Worker * Tag::APPLICATION_ID data provided during key generation/import. Without the 149*4d7e907cSAndroid Build Coastguard Worker * correct value it must be cryptographically impossible for the secure hardware to 150*4d7e907cSAndroid Build Coastguard Worker * obtain the key material. 151*4d7e907cSAndroid Build Coastguard Worker * 152*4d7e907cSAndroid Build Coastguard Worker * @param appData An opaque byte string provided by the application. This value must match the 153*4d7e907cSAndroid Build Coastguard Worker * Tag::APPLICATION_DATA data provided during key generation/import. Without the 154*4d7e907cSAndroid Build Coastguard Worker * correct value it must be cryptographically impossible for the secure hardware to 155*4d7e907cSAndroid Build Coastguard Worker * obtain the key material. 156*4d7e907cSAndroid Build Coastguard Worker * 157*4d7e907cSAndroid Build Coastguard Worker * @return error See the ErrorCode enum in types.hal. 158*4d7e907cSAndroid Build Coastguard Worker * 159*4d7e907cSAndroid Build Coastguard Worker * @return keyMaterial The public key material in PKCS#8 format. 160*4d7e907cSAndroid Build Coastguard Worker */ 161*4d7e907cSAndroid Build Coastguard Worker exportKey(KeyFormat keyFormat, vec<uint8_t> keyBlob, vec<uint8_t> clientId, 162*4d7e907cSAndroid Build Coastguard Worker vec<uint8_t> appData) generates(ErrorCode error, vec<uint8_t> keyMaterial); 163*4d7e907cSAndroid Build Coastguard Worker 164*4d7e907cSAndroid Build Coastguard Worker /** 165*4d7e907cSAndroid Build Coastguard Worker * Generates a signed X.509 certificate chain attesting to the presence of keyToAttest in 166*4d7e907cSAndroid Build Coastguard Worker * keymaster. The certificate will contain an extension with OID 1.3.6.1.4.1.11129.2.1.17 and 167*4d7e907cSAndroid Build Coastguard Worker * value defined in: 168*4d7e907cSAndroid Build Coastguard Worker * 169*4d7e907cSAndroid Build Coastguard Worker * https://developer.android.com/training/articles/security-key-attestation.html. 170*4d7e907cSAndroid Build Coastguard Worker * 171*4d7e907cSAndroid Build Coastguard Worker * @param keyToAttest The opaque descriptor returned by generateKey() or importKey(). The 172*4d7e907cSAndroid Build Coastguard Worker * referenced key must be asymmetric. 173*4d7e907cSAndroid Build Coastguard Worker * 174*4d7e907cSAndroid Build Coastguard Worker * @param attestParams Parameters for the attestation, notably Tag::ATTESTATION_CHALLENGE. 175*4d7e907cSAndroid Build Coastguard Worker * 176*4d7e907cSAndroid Build Coastguard Worker * @return error See the ErrorCode enum in types.hal. 177*4d7e907cSAndroid Build Coastguard Worker */ 178*4d7e907cSAndroid Build Coastguard Worker attestKey(vec<uint8_t> keyToAttest, vec<KeyParameter> attestParams) 179*4d7e907cSAndroid Build Coastguard Worker generates(ErrorCode error, vec<vec<uint8_t>> certChain); 180*4d7e907cSAndroid Build Coastguard Worker 181*4d7e907cSAndroid Build Coastguard Worker /** 182*4d7e907cSAndroid Build Coastguard Worker * Upgrades an old key. Keys can become "old" in two ways: Keymaster can be upgraded to a new 183*4d7e907cSAndroid Build Coastguard Worker * version, or the system can be updated to invalidate the OS version and/or patch level. In 184*4d7e907cSAndroid Build Coastguard Worker * either case, attempts to use an old key with getKeyCharacteristics(), exportKey(), 185*4d7e907cSAndroid Build Coastguard Worker * attestKey() or begin() will result in keymaster returning 186*4d7e907cSAndroid Build Coastguard Worker * ErrorCode::KEY_REQUIRES_UPGRADE. This method must then be called to upgrade the key. 187*4d7e907cSAndroid Build Coastguard Worker * 188*4d7e907cSAndroid Build Coastguard Worker * @param keyBlobToUpgrade The opaque descriptor returned by generateKey() or importKey(); 189*4d7e907cSAndroid Build Coastguard Worker * 190*4d7e907cSAndroid Build Coastguard Worker * @param upgradeParams A parameter list containing any parameters needed to complete the 191*4d7e907cSAndroid Build Coastguard Worker * upgrade, including Tag::APPLICATION_ID and Tag::APPLICATION_DATA. 192*4d7e907cSAndroid Build Coastguard Worker * 193*4d7e907cSAndroid Build Coastguard Worker * @return error See the ErrorCode enum. 194*4d7e907cSAndroid Build Coastguard Worker */ 195*4d7e907cSAndroid Build Coastguard Worker upgradeKey(vec<uint8_t> keyBlobToUpgrade, vec<KeyParameter> upgradeParams) 196*4d7e907cSAndroid Build Coastguard Worker generates(ErrorCode error, vec<uint8_t> upgradedKeyBlob); 197*4d7e907cSAndroid Build Coastguard Worker 198*4d7e907cSAndroid Build Coastguard Worker /** 199*4d7e907cSAndroid Build Coastguard Worker * Deletes the key, or key pair, associated with the key blob. After calling this function it 200*4d7e907cSAndroid Build Coastguard Worker * will be impossible to use the key for any other operations. May be applied to keys from 201*4d7e907cSAndroid Build Coastguard Worker * foreign roots of trust (keys not usable under the current root of trust). 202*4d7e907cSAndroid Build Coastguard Worker * 203*4d7e907cSAndroid Build Coastguard Worker * This is a NOP for keys that don't have rollback protection. 204*4d7e907cSAndroid Build Coastguard Worker * 205*4d7e907cSAndroid Build Coastguard Worker * @param keyBlobToUpgrade The opaque descriptor returned by generateKey() or importKey(); 206*4d7e907cSAndroid Build Coastguard Worker * 207*4d7e907cSAndroid Build Coastguard Worker * @return error See the ErrorCode enum. 208*4d7e907cSAndroid Build Coastguard Worker */ 209*4d7e907cSAndroid Build Coastguard Worker deleteKey(vec<uint8_t> keyBlob) generates(ErrorCode error); 210*4d7e907cSAndroid Build Coastguard Worker 211*4d7e907cSAndroid Build Coastguard Worker /** 212*4d7e907cSAndroid Build Coastguard Worker * Deletes all keys in the hardware keystore. Used when keystore is reset completely. After 213*4d7e907cSAndroid Build Coastguard Worker * calling this function it will be impossible to use any previously generated or imported key 214*4d7e907cSAndroid Build Coastguard Worker * blobs for any operations. 215*4d7e907cSAndroid Build Coastguard Worker * 216*4d7e907cSAndroid Build Coastguard Worker * This is a NOP if keys don't have rollback protection. 217*4d7e907cSAndroid Build Coastguard Worker * 218*4d7e907cSAndroid Build Coastguard Worker * @return error See the ErrorCode enum. 219*4d7e907cSAndroid Build Coastguard Worker */ 220*4d7e907cSAndroid Build Coastguard Worker deleteAllKeys() generates(ErrorCode error); 221*4d7e907cSAndroid Build Coastguard Worker 222*4d7e907cSAndroid Build Coastguard Worker /** 223*4d7e907cSAndroid Build Coastguard Worker * Destroys knowledge of the device's ids. This prevents all device id attestation in the 224*4d7e907cSAndroid Build Coastguard Worker * future. The destruction must be permanent so that not even a factory reset will restore the 225*4d7e907cSAndroid Build Coastguard Worker * device ids. 226*4d7e907cSAndroid Build Coastguard Worker * 227*4d7e907cSAndroid Build Coastguard Worker * Device id attestation may be provided only if this method is fully implemented, allowing the 228*4d7e907cSAndroid Build Coastguard Worker * user to permanently disable device id attestation. If this cannot be guaranteed, the device 229*4d7e907cSAndroid Build Coastguard Worker * must never attest any device ids. 230*4d7e907cSAndroid Build Coastguard Worker * 231*4d7e907cSAndroid Build Coastguard Worker * This is a NOP if device id attestation is not supported. 232*4d7e907cSAndroid Build Coastguard Worker * 233*4d7e907cSAndroid Build Coastguard Worker * @return error See the ErrorCode enum. 234*4d7e907cSAndroid Build Coastguard Worker */ 235*4d7e907cSAndroid Build Coastguard Worker destroyAttestationIds() generates(ErrorCode error); 236*4d7e907cSAndroid Build Coastguard Worker 237*4d7e907cSAndroid Build Coastguard Worker /** 238*4d7e907cSAndroid Build Coastguard Worker * Begins a cryptographic operation using the specified key. If all is well, begin() will return 239*4d7e907cSAndroid Build Coastguard Worker * ErrorCode::OK and create an operation handle which must be passed to subsequent calls to 240*4d7e907cSAndroid Build Coastguard Worker * update(), finish() or abort(). 241*4d7e907cSAndroid Build Coastguard Worker * 242*4d7e907cSAndroid Build Coastguard Worker * It is critical that each call to begin() be paired with a subsequent call to finish() or 243*4d7e907cSAndroid Build Coastguard Worker * abort(), to allow the keymaster implementation to clean up any internal operation state. 244*4d7e907cSAndroid Build Coastguard Worker * Failure to do this may leak internal state space or other internal resources and may 245*4d7e907cSAndroid Build Coastguard Worker * eventually cause begin() to return ErrorCode::TOO_MANY_OPERATIONS when it runs out of space 246*4d7e907cSAndroid Build Coastguard Worker * for operations. Any result other than ErrorCode::OK from begin(), update() or finish() 247*4d7e907cSAndroid Build Coastguard Worker * implicitly aborts the operation, in which case abort() need not be called (and will return 248*4d7e907cSAndroid Build Coastguard Worker * ErrorCode::INVALID_OPERATION_HANDLE if called). 249*4d7e907cSAndroid Build Coastguard Worker * 250*4d7e907cSAndroid Build Coastguard Worker * @param purpose The purpose of the operation, one of KeyPurpose::ENCRYPT, KeyPurpose::DECRYPT, 251*4d7e907cSAndroid Build Coastguard Worker * KeyPurpose::SIGN or KeyPurpose::VERIFY. Note that for AEAD modes, encryption and 252*4d7e907cSAndroid Build Coastguard Worker * decryption imply signing and verification, respectively, but must be specified as 253*4d7e907cSAndroid Build Coastguard Worker * KeyPurpose::ENCRYPT and KeyPurpose::DECRYPT. 254*4d7e907cSAndroid Build Coastguard Worker * 255*4d7e907cSAndroid Build Coastguard Worker * @param keyBlob The opaque key descriptor returned by generateKey() or importKey(). The key 256*4d7e907cSAndroid Build Coastguard Worker * must have a purpose compatible with purpose and all of its usage requirements 257*4d7e907cSAndroid Build Coastguard Worker * must be satisfied, or begin() will return an appropriate error code. 258*4d7e907cSAndroid Build Coastguard Worker * 259*4d7e907cSAndroid Build Coastguard Worker * @param inParams Additional parameters for the operation. This is typically used to provide 260*4d7e907cSAndroid Build Coastguard Worker * authentication data, with Tag::AUTH_TOKEN. If Tag::APPLICATION_ID or 261*4d7e907cSAndroid Build Coastguard Worker * Tag::APPLICATION_DATA were provided during generation, they must be provided 262*4d7e907cSAndroid Build Coastguard Worker * here, or the operation will fail with ErrorCode::INVALID_KEY_BLOB. For operations 263*4d7e907cSAndroid Build Coastguard Worker * that require a nonce or IV, on keys that were generated with Tag::CALLER_NONCE, 264*4d7e907cSAndroid Build Coastguard Worker * inParams may contain a tag Tag::NONCE. 265*4d7e907cSAndroid Build Coastguard Worker * 266*4d7e907cSAndroid Build Coastguard Worker * @return error See the ErrorCode enum in types.hal. 267*4d7e907cSAndroid Build Coastguard Worker * 268*4d7e907cSAndroid Build Coastguard Worker * @return outParams Output parameters. Used to return additional data from the operation 269*4d7e907cSAndroid Build Coastguard Worker * initialization, notably to return the IV or nonce from operations that generate 270*4d7e907cSAndroid Build Coastguard Worker * an IV or nonce. 271*4d7e907cSAndroid Build Coastguard Worker * 272*4d7e907cSAndroid Build Coastguard Worker * @return operationHandle The newly-created operation handle which must be passed to update(), 273*4d7e907cSAndroid Build Coastguard Worker * finish() or abort(). 274*4d7e907cSAndroid Build Coastguard Worker */ 275*4d7e907cSAndroid Build Coastguard Worker begin(KeyPurpose purpose, vec<uint8_t> key, vec<KeyParameter> inParams) 276*4d7e907cSAndroid Build Coastguard Worker generates(ErrorCode error, vec<KeyParameter> outParams, OperationHandle operationHandle); 277*4d7e907cSAndroid Build Coastguard Worker 278*4d7e907cSAndroid Build Coastguard Worker /** 279*4d7e907cSAndroid Build Coastguard Worker * Provides data to, and possibly receives output from, an ongoing cryptographic operation begun 280*4d7e907cSAndroid Build Coastguard Worker * with begin(). 281*4d7e907cSAndroid Build Coastguard Worker * 282*4d7e907cSAndroid Build Coastguard Worker * If operationHandle is invalid, update() will return ErrorCode::INVALID_OPERATION_HANDLE. 283*4d7e907cSAndroid Build Coastguard Worker * 284*4d7e907cSAndroid Build Coastguard Worker * update() may not consume all of the data provided in the data buffer. update() will return 285*4d7e907cSAndroid Build Coastguard Worker * the amount consumed in inputConsumed. The caller may provide the unconsumed data in a 286*4d7e907cSAndroid Build Coastguard Worker * subsequent call. 287*4d7e907cSAndroid Build Coastguard Worker * 288*4d7e907cSAndroid Build Coastguard Worker * @param operationHandle The operation handle returned by begin(). 289*4d7e907cSAndroid Build Coastguard Worker * 290*4d7e907cSAndroid Build Coastguard Worker * @param inParams Additional parameters for the operation. For AEAD modes, this is used to 291*4d7e907cSAndroid Build Coastguard Worker * specify Tag::ADDITIONAL_DATA. Note that additional data may be provided in 292*4d7e907cSAndroid Build Coastguard Worker * multiple calls to update(), but only until input data has been provided. 293*4d7e907cSAndroid Build Coastguard Worker * 294*4d7e907cSAndroid Build Coastguard Worker * @param input Data to be processed, per the parameters established in the call to begin(). 295*4d7e907cSAndroid Build Coastguard Worker * Note that update() may or may not consume all of the data provided. See 296*4d7e907cSAndroid Build Coastguard Worker * inputConsumed. 297*4d7e907cSAndroid Build Coastguard Worker * 298*4d7e907cSAndroid Build Coastguard Worker * @return error See the ErrorCode enum in types.hal. 299*4d7e907cSAndroid Build Coastguard Worker * 300*4d7e907cSAndroid Build Coastguard Worker * @return inputConsumed Amount of data that was consumed by update(). If this is less than the 301*4d7e907cSAndroid Build Coastguard Worker * amount provided, the caller may provide the remainder in a subsequent call to 302*4d7e907cSAndroid Build Coastguard Worker * update() or finish(). 303*4d7e907cSAndroid Build Coastguard Worker * 304*4d7e907cSAndroid Build Coastguard Worker * @return outParams Output parameters, used to return additional data from the operation The 305*4d7e907cSAndroid Build Coastguard Worker * caller takes ownership of the output parameters array and must free it with 306*4d7e907cSAndroid Build Coastguard Worker * keymaster_free_param_set(). 307*4d7e907cSAndroid Build Coastguard Worker * 308*4d7e907cSAndroid Build Coastguard Worker * @return output The output data, if any. 309*4d7e907cSAndroid Build Coastguard Worker */ 310*4d7e907cSAndroid Build Coastguard Worker update(OperationHandle operationHandle, vec<KeyParameter> inParams, vec<uint8_t> input) 311*4d7e907cSAndroid Build Coastguard Worker generates(ErrorCode error, uint32_t inputConsumed, vec<KeyParameter> outParams, 312*4d7e907cSAndroid Build Coastguard Worker vec<uint8_t> output); 313*4d7e907cSAndroid Build Coastguard Worker 314*4d7e907cSAndroid Build Coastguard Worker /** 315*4d7e907cSAndroid Build Coastguard Worker * Finalizes a cryptographic operation begun with begin() and invalidates operationHandle. 316*4d7e907cSAndroid Build Coastguard Worker * 317*4d7e907cSAndroid Build Coastguard Worker * @param operationHandle The operation handle returned by begin(). This handle will be 318*4d7e907cSAndroid Build Coastguard Worker * invalid when finish() returns. 319*4d7e907cSAndroid Build Coastguard Worker * 320*4d7e907cSAndroid Build Coastguard Worker * @param inParams Additional parameters for the operation. For AEAD modes, this is used to 321*4d7e907cSAndroid Build Coastguard Worker * specify Tag::ADDITIONAL_DATA, but only if no input data was provided to update(). 322*4d7e907cSAndroid Build Coastguard Worker * 323*4d7e907cSAndroid Build Coastguard Worker * @param input Data to be processed, per the parameters established in the call to 324*4d7e907cSAndroid Build Coastguard Worker * begin(). finish() must consume all provided data or return 325*4d7e907cSAndroid Build Coastguard Worker * ErrorCode::INVALID_INPUT_LENGTH. 326*4d7e907cSAndroid Build Coastguard Worker * 327*4d7e907cSAndroid Build Coastguard Worker * @param signature The signature to be verified if the purpose specified in the begin() call 328*4d7e907cSAndroid Build Coastguard Worker * was KeyPurpose::VERIFY. 329*4d7e907cSAndroid Build Coastguard Worker * 330*4d7e907cSAndroid Build Coastguard Worker * @return error See the ErrorCode enum in types.hal. 331*4d7e907cSAndroid Build Coastguard Worker * 332*4d7e907cSAndroid Build Coastguard Worker * @return outParams Any output parameters generated by finish(). 333*4d7e907cSAndroid Build Coastguard Worker * 334*4d7e907cSAndroid Build Coastguard Worker * @return output The output data, if any. 335*4d7e907cSAndroid Build Coastguard Worker */ 336*4d7e907cSAndroid Build Coastguard Worker finish(OperationHandle operationHandle, vec<KeyParameter> inParams, vec<uint8_t> input, 337*4d7e907cSAndroid Build Coastguard Worker vec<uint8_t> signature) 338*4d7e907cSAndroid Build Coastguard Worker generates(ErrorCode error, vec<KeyParameter> outParams, vec<uint8_t> output); 339*4d7e907cSAndroid Build Coastguard Worker 340*4d7e907cSAndroid Build Coastguard Worker /** 341*4d7e907cSAndroid Build Coastguard Worker * Aborts a cryptographic operation begun with begin(), freeing all internal resources and 342*4d7e907cSAndroid Build Coastguard Worker * invalidating operationHandle. 343*4d7e907cSAndroid Build Coastguard Worker * 344*4d7e907cSAndroid Build Coastguard Worker * @param operationHandle The operation handle returned by begin(). This handle will be 345*4d7e907cSAndroid Build Coastguard Worker * invalid when abort() returns. 346*4d7e907cSAndroid Build Coastguard Worker * 347*4d7e907cSAndroid Build Coastguard Worker * @return error See the ErrorCode enum in types.hal. 348*4d7e907cSAndroid Build Coastguard Worker */ 349*4d7e907cSAndroid Build Coastguard Worker abort(OperationHandle operationHandle) generates(ErrorCode error); 350*4d7e907cSAndroid Build Coastguard Worker}; 351