18effa36ca6440604cf10bbc34fba2b60ff304f54Alex Klyubin/* 28effa36ca6440604cf10bbc34fba2b60ff304f54Alex Klyubin * Copyright (C) 2015 The Android Open Source Project 345ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker * 445ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker * Licensed under the Apache License, Version 2.0 (the "License"); 545ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker * you may not use this file except in compliance with the License. 645ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker * You may obtain a copy of the License at 745ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker * 88effa36ca6440604cf10bbc34fba2b60ff304f54Alex Klyubin * http://www.apache.org/licenses/LICENSE-2.0 945ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker * 1045ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker * Unless required by applicable law or agreed to in writing, software 1145ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker * distributed under the License is distributed on an "AS IS" BASIS, 1245ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1345ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker * See the License for the specific language governing permissions and 1445ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker * limitations under the License. 1545ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker */ 1645ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker 1745ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubakerpackage android.security.keymaster; 1845ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker 19d23a1f706f0c24fade1a1c2f604009a7c9e70002Alex Klyubinimport java.util.HashMap; 20d23a1f706f0c24fade1a1c2f604009a7c9e70002Alex Klyubinimport java.util.Map; 21d23a1f706f0c24fade1a1c2f604009a7c9e70002Alex Klyubin 2245ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker/** 2345ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker * Class tracking all the keymaster enum values needed for the binder API to keystore. 2445ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker * This must be kept in sync with hardware/libhardware/include/hardware/keymaster_defs.h 2545ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker * See keymaster_defs.h for detailed descriptions of each constant. 2645ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker * @hide 2745ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker */ 2845ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubakerpublic final class KeymasterDefs { 2945ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker 3045ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker private KeymasterDefs() {} 3145ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker 3245ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker // Tag types. 3345ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_INVALID = 0 << 28; 3445ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ENUM = 1 << 28; 3545ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ENUM_REP = 2 << 28; 363e7a9e4ec611a1306f8aa5e593c95237030bb5baAlex Klyubin public static final int KM_UINT = 3 << 28; 373e7a9e4ec611a1306f8aa5e593c95237030bb5baAlex Klyubin public static final int KM_UINT_REP = 4 << 28; 383e7a9e4ec611a1306f8aa5e593c95237030bb5baAlex Klyubin public static final int KM_ULONG = 5 << 28; 3945ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_DATE = 6 << 28; 4045ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_BOOL = 7 << 28; 4145ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_BIGNUM = 8 << 28; 4245ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_BYTES = 9 << 28; 433e7a9e4ec611a1306f8aa5e593c95237030bb5baAlex Klyubin public static final int KM_ULONG_REP = 10 << 28; 4445ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker 4545ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker // Tag values. 4645ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_TAG_INVALID = KM_INVALID | 0; 4745ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_TAG_PURPOSE = KM_ENUM_REP | 1; 4845ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_TAG_ALGORITHM = KM_ENUM | 2; 493e7a9e4ec611a1306f8aa5e593c95237030bb5baAlex Klyubin public static final int KM_TAG_KEY_SIZE = KM_UINT | 3; 5059f977c6988e21b3b8aa6c83428bd6ee1a98816dChad Brubaker public static final int KM_TAG_BLOCK_MODE = KM_ENUM_REP | 4; 5159f977c6988e21b3b8aa6c83428bd6ee1a98816dChad Brubaker public static final int KM_TAG_DIGEST = KM_ENUM_REP | 5; 5259f977c6988e21b3b8aa6c83428bd6ee1a98816dChad Brubaker public static final int KM_TAG_PADDING = KM_ENUM_REP | 6; 530fe70813e03891a2fe0efdc16cd289d646205682Alex Klyubin public static final int KM_TAG_CALLER_NONCE = KM_BOOL | 7; 54a95550f8016bbb0dba086dbd73eec63e6cdbbe98Alex Klyubin public static final int KM_TAG_MIN_MAC_LENGTH = KM_UINT | 8; 5545ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker 5645ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_TAG_RESCOPING_ADD = KM_ENUM_REP | 101; 5745ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_TAG_RESCOPING_DEL = KM_ENUM_REP | 102; 5845ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_TAG_BLOB_USAGE_REQUIREMENTS = KM_ENUM | 705; 5945ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker 603e7a9e4ec611a1306f8aa5e593c95237030bb5baAlex Klyubin public static final int KM_TAG_RSA_PUBLIC_EXPONENT = KM_ULONG | 200; 618d8c7477746c357d54f586fc92e8d422a4fc6441Shawn Willden public static final int KM_TAG_INCLUDE_UNIQUE_ID = KM_BOOL | 202; 628d8c7477746c357d54f586fc92e8d422a4fc6441Shawn Willden 6345ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_TAG_ACTIVE_DATETIME = KM_DATE | 400; 6445ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_TAG_ORIGINATION_EXPIRE_DATETIME = KM_DATE | 401; 6545ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_TAG_USAGE_EXPIRE_DATETIME = KM_DATE | 402; 663e7a9e4ec611a1306f8aa5e593c95237030bb5baAlex Klyubin public static final int KM_TAG_MIN_SECONDS_BETWEEN_OPS = KM_UINT | 403; 673e7a9e4ec611a1306f8aa5e593c95237030bb5baAlex Klyubin public static final int KM_TAG_MAX_USES_PER_BOOT = KM_UINT | 404; 6845ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker 6945ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_TAG_ALL_USERS = KM_BOOL | 500; 703e7a9e4ec611a1306f8aa5e593c95237030bb5baAlex Klyubin public static final int KM_TAG_USER_ID = KM_UINT | 501; 713e7a9e4ec611a1306f8aa5e593c95237030bb5baAlex Klyubin public static final int KM_TAG_USER_SECURE_ID = KM_ULONG_REP | 502; 727714a9413f1a170de4be3726618fbbdf9ff609f3Shawn Willden public static final int KM_TAG_NO_AUTH_REQUIRED = KM_BOOL | 503; 73e90774ddbceeebc293dd015094721874a2e1d954Shawn Willden public static final int KM_TAG_USER_AUTH_TYPE = KM_ENUM | 504; 743e7a9e4ec611a1306f8aa5e593c95237030bb5baAlex Klyubin public static final int KM_TAG_AUTH_TIMEOUT = KM_UINT | 505; 75adef49640d6339e6b4a6ad736c5815e35d9b8803Shawn Willden public static final int KM_TAG_ALLOW_WHILE_ON_BODY = KM_BOOL | 506; 7645ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker 7745ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_TAG_ALL_APPLICATIONS = KM_BOOL | 600; 7845ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_TAG_APPLICATION_ID = KM_BYTES | 601; 7945ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker 8045ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_TAG_CREATION_DATETIME = KM_DATE | 701; 8145ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_TAG_ORIGIN = KM_ENUM | 702; 8245ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_TAG_ROLLBACK_RESISTANT = KM_BOOL | 703; 8345ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_TAG_ROOT_OF_TRUST = KM_BYTES | 704; 848d8c7477746c357d54f586fc92e8d422a4fc6441Shawn Willden public static final int KM_TAG_UNIQUE_ID = KM_BYTES | 707; 858d8c7477746c357d54f586fc92e8d422a4fc6441Shawn Willden public static final int KM_TAG_ATTESTATION_CHALLENGE = KM_BYTES | 708; 8645ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker 8745ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_TAG_ASSOCIATED_DATA = KM_BYTES | 1000; 8845ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_TAG_NONCE = KM_BYTES | 1001; 8942abb74834dc56393fad9f32a6717269c58c1eb3Alex Klyubin public static final int KM_TAG_AUTH_TOKEN = KM_BYTES | 1002; 903e7a9e4ec611a1306f8aa5e593c95237030bb5baAlex Klyubin public static final int KM_TAG_MAC_LENGTH = KM_UINT | 1003; 9145ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker 9245ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker // Algorithm values. 9345ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ALGORITHM_RSA = 1; 94862e6c78148e2254dfeccd5cde2a53bab2a74397Alex Klyubin public static final int KM_ALGORITHM_EC = 3; 9545ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ALGORITHM_AES = 32; 9645ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ALGORITHM_HMAC = 128; 9745ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker 9845ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker // Block modes. 994699e43dc6370bd649c7b7cdfba06ca384ca42feAlex Klyubin public static final int KM_MODE_ECB = 1; 10045ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_MODE_CBC = 2; 1014699e43dc6370bd649c7b7cdfba06ca384ca42feAlex Klyubin public static final int KM_MODE_CTR = 3; 1024699e43dc6370bd649c7b7cdfba06ca384ca42feAlex Klyubin public static final int KM_MODE_GCM = 32; 10345ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker 10445ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker // Padding modes. 10545ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_PAD_NONE = 1; 10645ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_PAD_RSA_OAEP = 2; 10745ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_PAD_RSA_PSS = 3; 10845ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_PAD_RSA_PKCS1_1_5_ENCRYPT = 4; 10945ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_PAD_RSA_PKCS1_1_5_SIGN = 5; 11055f7c2770faade3543bebd833124f2f15c0f7455Alex Klyubin public static final int KM_PAD_PKCS7 = 64; 11145ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker 11245ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker // Digest modes. 11345ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_DIGEST_NONE = 0; 11445ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_DIGEST_MD5 = 1; 11545ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_DIGEST_SHA1 = 2; 11645ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_DIGEST_SHA_2_224 = 3; 11745ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_DIGEST_SHA_2_256 = 4; 11845ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_DIGEST_SHA_2_384 = 5; 11945ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_DIGEST_SHA_2_512 = 6; 12045ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker 12145ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker // Key origins. 12245d27836bde9e641a57b69a1502924a29b9b3bf1Alex Klyubin public static final int KM_ORIGIN_GENERATED = 0; 12345ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ORIGIN_IMPORTED = 2; 12445d27836bde9e641a57b69a1502924a29b9b3bf1Alex Klyubin public static final int KM_ORIGIN_UNKNOWN = 3; 12545ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker 12645ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker // Key usability requirements. 12745ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_BLOB_STANDALONE = 0; 12845ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_BLOB_REQUIRES_FILE_SYSTEM = 1; 12945ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker 13045ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker // Operation Purposes. 13145ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_PURPOSE_ENCRYPT = 0; 13245ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_PURPOSE_DECRYPT = 1; 13345ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_PURPOSE_SIGN = 2; 13445ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_PURPOSE_VERIFY = 3; 13545ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker 13645ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker // Key formats. 13745ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_KEY_FORMAT_X509 = 0; 13845ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_KEY_FORMAT_PKCS8 = 1; 13945ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_KEY_FORMAT_RAW = 3; 14045ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker 141c46e9e7da4558f6bc99262361fd1ca35c3a44090Alex Klyubin // User authenticators. 142c46e9e7da4558f6bc99262361fd1ca35c3a44090Alex Klyubin public static final int HW_AUTH_PASSWORD = 1 << 0; 1431620a65d32251ca058b60cb2751394e9ee1f0019Alex Klyubin public static final int HW_AUTH_FINGERPRINT = 1 << 1; 144c46e9e7da4558f6bc99262361fd1ca35c3a44090Alex Klyubin 14545ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker // Error codes. 14645ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ERROR_OK = 0; 14745ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ERROR_ROOT_OF_TRUST_ALREADY_SET = -1; 14845ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ERROR_UNSUPPORTED_PURPOSE = -2; 14945ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ERROR_INCOMPATIBLE_PURPOSE = -3; 15045ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ERROR_UNSUPPORTED_ALGORITHM = -4; 15145ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ERROR_INCOMPATIBLE_ALGORITHM = -5; 15245ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ERROR_UNSUPPORTED_KEY_SIZE = -6; 15345ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ERROR_UNSUPPORTED_BLOCK_MODE = -7; 15445ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ERROR_INCOMPATIBLE_BLOCK_MODE = -8; 155c0eb55ccc73ad295c8dd227dcd80d2988ffa4873Alex Klyubin public static final int KM_ERROR_UNSUPPORTED_MAC_LENGTH = -9; 15645ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ERROR_UNSUPPORTED_PADDING_MODE = -10; 15745ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ERROR_INCOMPATIBLE_PADDING_MODE = -11; 15845ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ERROR_UNSUPPORTED_DIGEST = -12; 15945ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ERROR_INCOMPATIBLE_DIGEST = -13; 16045ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ERROR_INVALID_EXPIRATION_TIME = -14; 16145ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ERROR_INVALID_USER_ID = -15; 16245ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ERROR_INVALID_AUTHORIZATION_TIMEOUT = -16; 16345ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ERROR_UNSUPPORTED_KEY_FORMAT = -17; 16445ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ERROR_INCOMPATIBLE_KEY_FORMAT = -18; 16545ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ERROR_UNSUPPORTED_KEY_ENCRYPTION_ALGORITHM = -19; 16645ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ERROR_UNSUPPORTED_KEY_VERIFICATION_ALGORITHM = -20; 16745ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ERROR_INVALID_INPUT_LENGTH = -21; 16845ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ERROR_KEY_EXPORT_OPTIONS_INVALID = -22; 16945ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ERROR_DELEGATION_NOT_ALLOWED = -23; 17045ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ERROR_KEY_NOT_YET_VALID = -24; 17145ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ERROR_KEY_EXPIRED = -25; 17245ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ERROR_KEY_USER_NOT_AUTHENTICATED = -26; 17345ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ERROR_OUTPUT_PARAMETER_NULL = -27; 17445ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ERROR_INVALID_OPERATION_HANDLE = -28; 17545ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ERROR_INSUFFICIENT_BUFFER_SPACE = -29; 17645ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ERROR_VERIFICATION_FAILED = -30; 17745ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ERROR_TOO_MANY_OPERATIONS = -31; 17845ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ERROR_UNEXPECTED_NULL_POINTER = -32; 17945ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ERROR_INVALID_KEY_BLOB = -33; 18045ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ERROR_IMPORTED_KEY_NOT_ENCRYPTED = -34; 18145ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ERROR_IMPORTED_KEY_DECRYPTION_FAILED = -35; 18245ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ERROR_IMPORTED_KEY_NOT_SIGNED = -36; 18345ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ERROR_IMPORTED_KEY_VERIFICATION_FAILED = -37; 18445ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ERROR_INVALID_ARGUMENT = -38; 18545ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ERROR_UNSUPPORTED_TAG = -39; 18645ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ERROR_INVALID_TAG = -40; 18745ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ERROR_MEMORY_ALLOCATION_FAILED = -41; 18845ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ERROR_INVALID_RESCOPING = -42; 18945ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ERROR_IMPORT_PARAMETER_MISMATCH = -44; 19045ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ERROR_SECURE_HW_ACCESS_DENIED = -45; 19145ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ERROR_OPERATION_CANCELLED = -46; 19245ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ERROR_CONCURRENT_ACCESS_CONFLICT = -47; 19345ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ERROR_SECURE_HW_BUSY = -48; 19445ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ERROR_SECURE_HW_COMMUNICATION_FAILED = -49; 19545ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ERROR_UNSUPPORTED_EC_FIELD = -50; 19637d81d035c8a51112f40b67db3fa479df58fd120Alex Klyubin public static final int KM_ERROR_MISSING_NONCE = -51; 19737d81d035c8a51112f40b67db3fa479df58fd120Alex Klyubin public static final int KM_ERROR_INVALID_NONCE = -52; 1980fe70813e03891a2fe0efdc16cd289d646205682Alex Klyubin public static final int KM_ERROR_MISSING_MAC_LENGTH = -53; 19991526c1430eb6799fabd8a163fb64f5098a45d68Shawn Willden public static final int KM_ERROR_KEY_RATE_LIMIT_EXCEEDED = -54; 200dbc00eb0aacfa7d93673798f0226260be2f3d194Shawn Willden public static final int KM_ERROR_CALLER_NONCE_PROHIBITED = -55; 20191526c1430eb6799fabd8a163fb64f5098a45d68Shawn Willden public static final int KM_ERROR_KEY_MAX_OPS_EXCEEDED = -56; 202a95550f8016bbb0dba086dbd73eec63e6cdbbe98Alex Klyubin public static final int KM_ERROR_INVALID_MAC_LENGTH = -57; 203a95550f8016bbb0dba086dbd73eec63e6cdbbe98Alex Klyubin public static final int KM_ERROR_MISSING_MIN_MAC_LENGTH = -58; 204a95550f8016bbb0dba086dbd73eec63e6cdbbe98Alex Klyubin public static final int KM_ERROR_UNSUPPORTED_MIN_MAC_LENGTH = -59; 20545ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ERROR_UNIMPLEMENTED = -100; 20645ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ERROR_VERSION_MISMATCH = -101; 20745ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static final int KM_ERROR_UNKNOWN_ERROR = -1000; 20845ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker 209d23a1f706f0c24fade1a1c2f604009a7c9e70002Alex Klyubin public static final Map<Integer, String> sErrorCodeToString = new HashMap<Integer, String>(); 210d23a1f706f0c24fade1a1c2f604009a7c9e70002Alex Klyubin static { 211d23a1f706f0c24fade1a1c2f604009a7c9e70002Alex Klyubin sErrorCodeToString.put(KM_ERROR_OK, "OK"); 212d23a1f706f0c24fade1a1c2f604009a7c9e70002Alex Klyubin sErrorCodeToString.put(KM_ERROR_UNSUPPORTED_PURPOSE, "Unsupported purpose"); 213d23a1f706f0c24fade1a1c2f604009a7c9e70002Alex Klyubin sErrorCodeToString.put(KM_ERROR_INCOMPATIBLE_PURPOSE, "Incompatible purpose"); 214d23a1f706f0c24fade1a1c2f604009a7c9e70002Alex Klyubin sErrorCodeToString.put(KM_ERROR_UNSUPPORTED_ALGORITHM, "Unsupported algorithm"); 215d23a1f706f0c24fade1a1c2f604009a7c9e70002Alex Klyubin sErrorCodeToString.put(KM_ERROR_INCOMPATIBLE_ALGORITHM, "Incompatible algorithm"); 216d23a1f706f0c24fade1a1c2f604009a7c9e70002Alex Klyubin sErrorCodeToString.put(KM_ERROR_UNSUPPORTED_KEY_SIZE, "Unsupported key size"); 217d23a1f706f0c24fade1a1c2f604009a7c9e70002Alex Klyubin sErrorCodeToString.put(KM_ERROR_UNSUPPORTED_BLOCK_MODE, "Unsupported block mode"); 218d23a1f706f0c24fade1a1c2f604009a7c9e70002Alex Klyubin sErrorCodeToString.put(KM_ERROR_INCOMPATIBLE_BLOCK_MODE, "Incompatible block mode"); 219c0eb55ccc73ad295c8dd227dcd80d2988ffa4873Alex Klyubin sErrorCodeToString.put(KM_ERROR_UNSUPPORTED_MAC_LENGTH, 220c0eb55ccc73ad295c8dd227dcd80d2988ffa4873Alex Klyubin "Unsupported MAC or authentication tag length"); 221d23a1f706f0c24fade1a1c2f604009a7c9e70002Alex Klyubin sErrorCodeToString.put(KM_ERROR_UNSUPPORTED_PADDING_MODE, "Unsupported padding mode"); 222d23a1f706f0c24fade1a1c2f604009a7c9e70002Alex Klyubin sErrorCodeToString.put(KM_ERROR_INCOMPATIBLE_PADDING_MODE, "Incompatible padding mode"); 223d23a1f706f0c24fade1a1c2f604009a7c9e70002Alex Klyubin sErrorCodeToString.put(KM_ERROR_UNSUPPORTED_DIGEST, "Unsupported digest"); 224d23a1f706f0c24fade1a1c2f604009a7c9e70002Alex Klyubin sErrorCodeToString.put(KM_ERROR_INCOMPATIBLE_DIGEST, "Incompatible digest"); 225d23a1f706f0c24fade1a1c2f604009a7c9e70002Alex Klyubin sErrorCodeToString.put(KM_ERROR_INVALID_EXPIRATION_TIME, "Invalid expiration time"); 226d23a1f706f0c24fade1a1c2f604009a7c9e70002Alex Klyubin sErrorCodeToString.put(KM_ERROR_INVALID_USER_ID, "Invalid user ID"); 227d23a1f706f0c24fade1a1c2f604009a7c9e70002Alex Klyubin sErrorCodeToString.put(KM_ERROR_INVALID_AUTHORIZATION_TIMEOUT, 228d23a1f706f0c24fade1a1c2f604009a7c9e70002Alex Klyubin "Invalid user authorization timeout"); 229d23a1f706f0c24fade1a1c2f604009a7c9e70002Alex Klyubin sErrorCodeToString.put(KM_ERROR_UNSUPPORTED_KEY_FORMAT, "Unsupported key format"); 230d23a1f706f0c24fade1a1c2f604009a7c9e70002Alex Klyubin sErrorCodeToString.put(KM_ERROR_INCOMPATIBLE_KEY_FORMAT, "Incompatible key format"); 231d23a1f706f0c24fade1a1c2f604009a7c9e70002Alex Klyubin sErrorCodeToString.put(KM_ERROR_INVALID_INPUT_LENGTH, "Invalid input length"); 232d23a1f706f0c24fade1a1c2f604009a7c9e70002Alex Klyubin sErrorCodeToString.put(KM_ERROR_KEY_NOT_YET_VALID, "Key not yet valid"); 233d23a1f706f0c24fade1a1c2f604009a7c9e70002Alex Klyubin sErrorCodeToString.put(KM_ERROR_KEY_EXPIRED, "Key expired"); 234d23a1f706f0c24fade1a1c2f604009a7c9e70002Alex Klyubin sErrorCodeToString.put(KM_ERROR_KEY_USER_NOT_AUTHENTICATED, "Key user not authenticated"); 235d23a1f706f0c24fade1a1c2f604009a7c9e70002Alex Klyubin sErrorCodeToString.put(KM_ERROR_INVALID_OPERATION_HANDLE, "Invalid operation handle"); 236d23a1f706f0c24fade1a1c2f604009a7c9e70002Alex Klyubin sErrorCodeToString.put(KM_ERROR_VERIFICATION_FAILED, "Signature/MAC verification failed"); 237d23a1f706f0c24fade1a1c2f604009a7c9e70002Alex Klyubin sErrorCodeToString.put(KM_ERROR_TOO_MANY_OPERATIONS, "Too many operations"); 238d23a1f706f0c24fade1a1c2f604009a7c9e70002Alex Klyubin sErrorCodeToString.put(KM_ERROR_INVALID_KEY_BLOB, "Invalid key blob"); 239d23a1f706f0c24fade1a1c2f604009a7c9e70002Alex Klyubin sErrorCodeToString.put(KM_ERROR_INVALID_ARGUMENT, "Invalid argument"); 240d23a1f706f0c24fade1a1c2f604009a7c9e70002Alex Klyubin sErrorCodeToString.put(KM_ERROR_UNSUPPORTED_TAG, "Unsupported tag"); 241d23a1f706f0c24fade1a1c2f604009a7c9e70002Alex Klyubin sErrorCodeToString.put(KM_ERROR_INVALID_TAG, "Invalid tag"); 242d23a1f706f0c24fade1a1c2f604009a7c9e70002Alex Klyubin sErrorCodeToString.put(KM_ERROR_MEMORY_ALLOCATION_FAILED, "Memory allocation failed"); 243c0eb55ccc73ad295c8dd227dcd80d2988ffa4873Alex Klyubin sErrorCodeToString.put(KM_ERROR_UNSUPPORTED_EC_FIELD, "Unsupported EC field"); 24437d81d035c8a51112f40b67db3fa479df58fd120Alex Klyubin sErrorCodeToString.put(KM_ERROR_MISSING_NONCE, "Required IV missing"); 24537d81d035c8a51112f40b67db3fa479df58fd120Alex Klyubin sErrorCodeToString.put(KM_ERROR_INVALID_NONCE, "Invalid IV"); 2466358b881f2e483a4d96ff440fb19136e2d25e893Alex Klyubin sErrorCodeToString.put(KM_ERROR_CALLER_NONCE_PROHIBITED, 2476358b881f2e483a4d96ff440fb19136e2d25e893Alex Klyubin "Caller-provided IV not permitted"); 248a95550f8016bbb0dba086dbd73eec63e6cdbbe98Alex Klyubin sErrorCodeToString.put(KM_ERROR_INVALID_MAC_LENGTH, 249a95550f8016bbb0dba086dbd73eec63e6cdbbe98Alex Klyubin "Invalid MAC or authentication tag length"); 250d23a1f706f0c24fade1a1c2f604009a7c9e70002Alex Klyubin sErrorCodeToString.put(KM_ERROR_UNIMPLEMENTED, "Not implemented"); 251d23a1f706f0c24fade1a1c2f604009a7c9e70002Alex Klyubin sErrorCodeToString.put(KM_ERROR_UNKNOWN_ERROR, "Unknown error"); 252d23a1f706f0c24fade1a1c2f604009a7c9e70002Alex Klyubin } 253d23a1f706f0c24fade1a1c2f604009a7c9e70002Alex Klyubin 25445ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker public static int getTagType(int tag) { 25545ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker return tag & (0xF << 28); 25645ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker } 257d23a1f706f0c24fade1a1c2f604009a7c9e70002Alex Klyubin 258d23a1f706f0c24fade1a1c2f604009a7c9e70002Alex Klyubin public static String getErrorMessage(int errorCode) { 259d23a1f706f0c24fade1a1c2f604009a7c9e70002Alex Klyubin String result = sErrorCodeToString.get(errorCode); 260d23a1f706f0c24fade1a1c2f604009a7c9e70002Alex Klyubin if (result != null) { 261d23a1f706f0c24fade1a1c2f604009a7c9e70002Alex Klyubin return result; 262d23a1f706f0c24fade1a1c2f604009a7c9e70002Alex Klyubin } 263d23a1f706f0c24fade1a1c2f604009a7c9e70002Alex Klyubin return String.valueOf(errorCode); 264d23a1f706f0c24fade1a1c2f604009a7c9e70002Alex Klyubin } 26545ff13ea28005b5af0caa80dbdeb09d49bd73fafChad Brubaker} 266