blob: 88cad79283978532449961f0fa388a7030542970 [file] [log] [blame]
Chad Brubaker45ff13e2015-01-21 14:00:55 -08001/**
2 * Copyright (c) 2015, 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.security.keymaster;
18
19/**
20 * Class tracking all the keymaster enum values needed for the binder API to keystore.
21 * This must be kept in sync with hardware/libhardware/include/hardware/keymaster_defs.h
22 * See keymaster_defs.h for detailed descriptions of each constant.
23 * @hide
24 */
25public final class KeymasterDefs {
26
27 private KeymasterDefs() {}
28
29 // Tag types.
30 public static final int KM_INVALID = 0 << 28;
31 public static final int KM_ENUM = 1 << 28;
32 public static final int KM_ENUM_REP = 2 << 28;
33 public static final int KM_INT = 3 << 28;
34 public static final int KM_INT_REP = 4 << 28;
35 public static final int KM_LONG = 5 << 28;
36 public static final int KM_DATE = 6 << 28;
37 public static final int KM_BOOL = 7 << 28;
38 public static final int KM_BIGNUM = 8 << 28;
39 public static final int KM_BYTES = 9 << 28;
40
41 // Tag values.
42 public static final int KM_TAG_INVALID = KM_INVALID | 0;
43 public static final int KM_TAG_PURPOSE = KM_ENUM_REP | 1;
44 public static final int KM_TAG_ALGORITHM = KM_ENUM | 2;
45 public static final int KM_TAG_KEY_SIZE = KM_INT | 3;
46 public static final int KM_TAG_BLOCK_MODE = KM_ENUM | 4;
47 public static final int KM_TAG_DIGEST = KM_ENUM | 5;
48 public static final int KM_TAG_MAC_LENGTH = KM_INT | 6;
49 public static final int KM_TAG_PADDING = KM_ENUM | 7;
50 public static final int KM_TAG_RETURN_UNAUTHED = KM_BOOL | 8;
51 public static final int KM_TAG_CALLER_NONCE = KM_BOOL | 9;
52
53 public static final int KM_TAG_RESCOPING_ADD = KM_ENUM_REP | 101;
54 public static final int KM_TAG_RESCOPING_DEL = KM_ENUM_REP | 102;
55 public static final int KM_TAG_BLOB_USAGE_REQUIREMENTS = KM_ENUM | 705;
56
57 public static final int KM_TAG_RSA_PUBLIC_EXPONENT = KM_LONG | 200;
58 public static final int KM_TAG_DSA_GENERATOR = KM_BIGNUM | 201;
59 public static final int KM_TAG_DSA_P = KM_BIGNUM | 202;
60 public static final int KM_TAG_DSA_Q = KM_BIGNUM | 203;
61 public static final int KM_TAG_ACTIVE_DATETIME = KM_DATE | 400;
62 public static final int KM_TAG_ORIGINATION_EXPIRE_DATETIME = KM_DATE | 401;
63 public static final int KM_TAG_USAGE_EXPIRE_DATETIME = KM_DATE | 402;
64 public static final int KM_TAG_MIN_SECONDS_BETWEEN_OPS = KM_INT | 403;
65 public static final int KM_TAG_MAX_USES_PER_BOOT = KM_INT | 404;
66
67 public static final int KM_TAG_ALL_USERS = KM_BOOL | 500;
68 public static final int KM_TAG_USER_ID = KM_INT | 501;
69 public static final int KM_TAG_NO_AUTH_REQUIRED = KM_BOOL | 502;
70 public static final int KM_TAG_USER_AUTH_ID = KM_INT_REP | 503;
71 public static final int KM_TAG_AUTH_TIMEOUT = KM_INT | 504;
72
73 public static final int KM_TAG_ALL_APPLICATIONS = KM_BOOL | 600;
74 public static final int KM_TAG_APPLICATION_ID = KM_BYTES | 601;
75
76 public static final int KM_TAG_APPLICATION_DATA = KM_BYTES | 700;
77 public static final int KM_TAG_CREATION_DATETIME = KM_DATE | 701;
78 public static final int KM_TAG_ORIGIN = KM_ENUM | 702;
79 public static final int KM_TAG_ROLLBACK_RESISTANT = KM_BOOL | 703;
80 public static final int KM_TAG_ROOT_OF_TRUST = KM_BYTES | 704;
81
82 public static final int KM_TAG_ASSOCIATED_DATA = KM_BYTES | 1000;
83 public static final int KM_TAG_NONCE = KM_BYTES | 1001;
84 public static final int KM_TAG_CHUNK_LENGTH = KM_INT | 1002;
85
86 // Algorithm values.
87 public static final int KM_ALGORITHM_RSA = 1;
88 public static final int KM_ALGORITHM_DSA = 2;
89 public static final int KM_ALGORITHM_ECDSA = 3;
90 public static final int KM_ALGORITHM_ECIES = 4;
91 public static final int KM_ALGORITHM_AES = 32;
92 public static final int KM_ALGORITHM_3DES = 33;
93 public static final int KM_ALGORITHM_SKIPJACK = 34;
94 public static final int KM_ALGORITHM_MARS = 48;
95 public static final int KM_ALGORITHM_RC6 = 49;
96 public static final int KM_ALGORITHM_SERPENT = 50;
97 public static final int KM_ALGORITHM_TWOFISH = 51;
98 public static final int KM_ALGORITHM_IDEA = 52;
99 public static final int KM_ALGORITHM_RC5 = 53;
100 public static final int KM_ALGORITHM_CAST5 = 54;
101 public static final int KM_ALGORITHM_BLOWFISH = 55;
102 public static final int KM_ALGORITHM_RC4 = 64;
103 public static final int KM_ALGORITHM_CHACHA20 = 65;
104 public static final int KM_ALGORITHM_HMAC = 128;
105
106 // Block modes.
107 public static final int KM_MODE_FIRST_UNAUTHENTICATED = 1;
108 public static final int KM_MODE_ECB = KM_MODE_FIRST_UNAUTHENTICATED;
109 public static final int KM_MODE_CBC = 2;
110 public static final int KM_MODE_CBC_CTS = 3;
111 public static final int KM_MODE_CTR = 4;
112 public static final int KM_MODE_OFB = 5;
113 public static final int KM_MODE_CFB = 6;
114 public static final int KM_MODE_XTS = 7;
115 public static final int KM_MODE_FIRST_AUTHENTICATED = 32;
116 public static final int KM_MODE_GCM = KM_MODE_FIRST_AUTHENTICATED;
117 public static final int KM_MODE_OCB = 33;
118 public static final int KM_MODE_CCM = 34;
119 public static final int KM_MODE_FIRST_MAC = 128;
120 public static final int KM_MODE_CMAC = KM_MODE_FIRST_MAC;
121 public static final int KM_MODE_POLY1305 = 129;
122
123 // Padding modes.
124 public static final int KM_PAD_NONE = 1;
125 public static final int KM_PAD_RSA_OAEP = 2;
126 public static final int KM_PAD_RSA_PSS = 3;
127 public static final int KM_PAD_RSA_PKCS1_1_5_ENCRYPT = 4;
128 public static final int KM_PAD_RSA_PKCS1_1_5_SIGN = 5;
129 public static final int KM_PAD_ANSI_X923 = 32;
130 public static final int KM_PAD_ISO_10126 = 33;
131 public static final int KM_PAD_ZERO = 64;
132 public static final int KM_PAD_PKCS7 = 65;
133 public static final int KM_PAD_ISO_7816_4 = 66;
134
135 // Digest modes.
136 public static final int KM_DIGEST_NONE = 0;
137 public static final int KM_DIGEST_MD5 = 1;
138 public static final int KM_DIGEST_SHA1 = 2;
139 public static final int KM_DIGEST_SHA_2_224 = 3;
140 public static final int KM_DIGEST_SHA_2_256 = 4;
141 public static final int KM_DIGEST_SHA_2_384 = 5;
142 public static final int KM_DIGEST_SHA_2_512 = 6;
143 public static final int KM_DIGEST_SHA_3_256 = 7;
144 public static final int KM_DIGEST_SHA_3_384 = 8;
145 public static final int KM_DIGEST_SHA_3_512 = 9;
146
147 // Key origins.
148 public static final int KM_ORIGIN_HARDWARE = 0;
149 public static final int KM_ORIGIN_SOFTWARE = 1;
150 public static final int KM_ORIGIN_IMPORTED = 2;
151
152 // Key usability requirements.
153 public static final int KM_BLOB_STANDALONE = 0;
154 public static final int KM_BLOB_REQUIRES_FILE_SYSTEM = 1;
155
156 // Operation Purposes.
157 public static final int KM_PURPOSE_ENCRYPT = 0;
158 public static final int KM_PURPOSE_DECRYPT = 1;
159 public static final int KM_PURPOSE_SIGN = 2;
160 public static final int KM_PURPOSE_VERIFY = 3;
161
162 // Key formats.
163 public static final int KM_KEY_FORMAT_X509 = 0;
164 public static final int KM_KEY_FORMAT_PKCS8 = 1;
165 public static final int KM_KEY_FORMAT_PKCS12 = 2;
166 public static final int KM_KEY_FORMAT_RAW = 3;
167
168 // Error codes.
169 public static final int KM_ERROR_OK = 0;
170 public static final int KM_ERROR_ROOT_OF_TRUST_ALREADY_SET = -1;
171 public static final int KM_ERROR_UNSUPPORTED_PURPOSE = -2;
172 public static final int KM_ERROR_INCOMPATIBLE_PURPOSE = -3;
173 public static final int KM_ERROR_UNSUPPORTED_ALGORITHM = -4;
174 public static final int KM_ERROR_INCOMPATIBLE_ALGORITHM = -5;
175 public static final int KM_ERROR_UNSUPPORTED_KEY_SIZE = -6;
176 public static final int KM_ERROR_UNSUPPORTED_BLOCK_MODE = -7;
177 public static final int KM_ERROR_INCOMPATIBLE_BLOCK_MODE = -8;
178 public static final int KM_ERROR_UNSUPPORTED_TAG_LENGTH = -9;
179 public static final int KM_ERROR_UNSUPPORTED_PADDING_MODE = -10;
180 public static final int KM_ERROR_INCOMPATIBLE_PADDING_MODE = -11;
181 public static final int KM_ERROR_UNSUPPORTED_DIGEST = -12;
182 public static final int KM_ERROR_INCOMPATIBLE_DIGEST = -13;
183 public static final int KM_ERROR_INVALID_EXPIRATION_TIME = -14;
184 public static final int KM_ERROR_INVALID_USER_ID = -15;
185 public static final int KM_ERROR_INVALID_AUTHORIZATION_TIMEOUT = -16;
186 public static final int KM_ERROR_UNSUPPORTED_KEY_FORMAT = -17;
187 public static final int KM_ERROR_INCOMPATIBLE_KEY_FORMAT = -18;
188 public static final int KM_ERROR_UNSUPPORTED_KEY_ENCRYPTION_ALGORITHM = -19;
189 public static final int KM_ERROR_UNSUPPORTED_KEY_VERIFICATION_ALGORITHM = -20;
190 public static final int KM_ERROR_INVALID_INPUT_LENGTH = -21;
191 public static final int KM_ERROR_KEY_EXPORT_OPTIONS_INVALID = -22;
192 public static final int KM_ERROR_DELEGATION_NOT_ALLOWED = -23;
193 public static final int KM_ERROR_KEY_NOT_YET_VALID = -24;
194 public static final int KM_ERROR_KEY_EXPIRED = -25;
195 public static final int KM_ERROR_KEY_USER_NOT_AUTHENTICATED = -26;
196 public static final int KM_ERROR_OUTPUT_PARAMETER_NULL = -27;
197 public static final int KM_ERROR_INVALID_OPERATION_HANDLE = -28;
198 public static final int KM_ERROR_INSUFFICIENT_BUFFER_SPACE = -29;
199 public static final int KM_ERROR_VERIFICATION_FAILED = -30;
200 public static final int KM_ERROR_TOO_MANY_OPERATIONS = -31;
201 public static final int KM_ERROR_UNEXPECTED_NULL_POINTER = -32;
202 public static final int KM_ERROR_INVALID_KEY_BLOB = -33;
203 public static final int KM_ERROR_IMPORTED_KEY_NOT_ENCRYPTED = -34;
204 public static final int KM_ERROR_IMPORTED_KEY_DECRYPTION_FAILED = -35;
205 public static final int KM_ERROR_IMPORTED_KEY_NOT_SIGNED = -36;
206 public static final int KM_ERROR_IMPORTED_KEY_VERIFICATION_FAILED = -37;
207 public static final int KM_ERROR_INVALID_ARGUMENT = -38;
208 public static final int KM_ERROR_UNSUPPORTED_TAG = -39;
209 public static final int KM_ERROR_INVALID_TAG = -40;
210 public static final int KM_ERROR_MEMORY_ALLOCATION_FAILED = -41;
211 public static final int KM_ERROR_INVALID_RESCOPING = -42;
212 public static final int KM_ERROR_INVALID_DSA_PARAMS = -43;
213 public static final int KM_ERROR_IMPORT_PARAMETER_MISMATCH = -44;
214 public static final int KM_ERROR_SECURE_HW_ACCESS_DENIED = -45;
215 public static final int KM_ERROR_OPERATION_CANCELLED = -46;
216 public static final int KM_ERROR_CONCURRENT_ACCESS_CONFLICT = -47;
217 public static final int KM_ERROR_SECURE_HW_BUSY = -48;
218 public static final int KM_ERROR_SECURE_HW_COMMUNICATION_FAILED = -49;
219 public static final int KM_ERROR_UNSUPPORTED_EC_FIELD = -50;
220 public static final int KM_ERROR_UNIMPLEMENTED = -100;
221 public static final int KM_ERROR_VERSION_MISMATCH = -101;
222 public static final int KM_ERROR_UNKNOWN_ERROR = -1000;
223
224 public static int getTagType(int tag) {
225 return tag & (0xF << 28);
226 }
227}