1 /*
2 * Copyright 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <keymaster/keymaster_tags.h>
18
19 namespace keymaster {
20
21 #ifdef KEYMASTER_NAME_TAGS
StringifyTag(keymaster_tag_t tag)22 const char* StringifyTag(keymaster_tag_t tag) {
23 switch (tag) {
24 case KM_TAG_INVALID:
25 return "KM_TAG_INVALID";
26 case KM_TAG_PURPOSE:
27 return "KM_TAG_PURPOSE";
28 case KM_TAG_ALGORITHM:
29 return "KM_TAG_ALGORITHM";
30 case KM_TAG_KEY_SIZE:
31 return "KM_TAG_KEY_SIZE";
32 case KM_TAG_BLOCK_MODE:
33 return "KM_TAG_BLOCK_MODE";
34 case KM_TAG_DIGEST:
35 return "KM_TAG_DIGEST";
36 case KM_TAG_PADDING:
37 return "KM_TAG_PADDING";
38 case KM_TAG_CALLER_NONCE:
39 return "KM_TAG_CALLER_NONCE";
40 case KM_TAG_MIN_MAC_LENGTH:
41 return "KM_TAG_MIN_MAC_LENGTH";
42 case KM_TAG_RSA_PUBLIC_EXPONENT:
43 return "KM_TAG_RSA_PUBLIC_EXPONENT";
44 case KM_TAG_BLOB_USAGE_REQUIREMENTS:
45 return "KM_TAG_BLOB_USAGE_REQUIREMENTS";
46 case KM_TAG_BOOTLOADER_ONLY:
47 return "KM_TAG_BOOTLOADER_ONLY";
48 case KM_TAG_ACTIVE_DATETIME:
49 return "KM_TAG_ACTIVE_DATETIME";
50 case KM_TAG_ORIGINATION_EXPIRE_DATETIME:
51 return "KM_TAG_ORIGINATION_EXPIRE_DATETIME";
52 case KM_TAG_USAGE_EXPIRE_DATETIME:
53 return "KM_TAG_USAGE_EXPIRE_DATETIME";
54 case KM_TAG_MIN_SECONDS_BETWEEN_OPS:
55 return "KM_TAG_MIN_SECONDS_BETWEEN_OPS";
56 case KM_TAG_MAX_USES_PER_BOOT:
57 return "KM_TAG_MAX_USES_PER_BOOT";
58 case KM_TAG_ALL_USERS:
59 return "KM_TAG_ALL_USERS";
60 case KM_TAG_USER_ID:
61 return "KM_TAG_USER_ID";
62 case KM_TAG_USER_SECURE_ID:
63 return "KM_TAG_USER_SECURE_ID";
64 case KM_TAG_NO_AUTH_REQUIRED:
65 return "KM_TAG_NO_AUTH_REQUIRED";
66 case KM_TAG_USER_AUTH_TYPE:
67 return "KM_TAG_USER_AUTH_TYPE";
68 case KM_TAG_AUTH_TIMEOUT:
69 return "KM_TAG_AUTH_TIMEOUT";
70 case KM_TAG_ALL_APPLICATIONS:
71 return "KM_TAG_ALL_APPLICATIONS";
72 case KM_TAG_APPLICATION_ID:
73 return "KM_TAG_APPLICATION_ID";
74 case KM_TAG_APPLICATION_DATA:
75 return "KM_TAG_APPLICATION_DATA";
76 case KM_TAG_CREATION_DATETIME:
77 return "KM_TAG_CREATION_DATETIME";
78 case KM_TAG_ORIGIN:
79 return "KM_TAG_ORIGIN";
80 case KM_TAG_ROLLBACK_RESISTANT:
81 return "KM_TAG_ROLLBACK_RESISTANT";
82 case KM_TAG_ROOT_OF_TRUST:
83 return "KM_TAG_ROOT_OF_TRUST";
84 case KM_TAG_ASSOCIATED_DATA:
85 return "KM_TAG_ASSOCIATED_DATA";
86 case KM_TAG_NONCE:
87 return "KM_TAG_NONCE";
88 case KM_TAG_AUTH_TOKEN:
89 return "KM_TAG_AUTH_TOKEN";
90 case KM_TAG_MAC_LENGTH:
91 return "KM_TAG_MAC_LENGTH";
92 case KM_TAG_KDF:
93 return "KM_TAG_KDF";
94 case KM_TAG_EC_CURVE:
95 return "KM_TAG_EC_CURVE";
96 case KM_TAG_ECIES_SINGLE_HASH_MODE:
97 return "KM_TAG_ECIES_SINGLE_HASH_MODE";
98 case KM_TAG_OS_VERSION:
99 return "KM_TAG_OS_VERSION";
100 case KM_TAG_OS_PATCHLEVEL:
101 return "KM_TAG_OS_PATCHLEVEL";
102 case KM_TAG_EXPORTABLE:
103 return "KM_TAG_EXPORTABLE";
104 case KM_TAG_UNIQUE_ID:
105 return "KM_TAG_UNIQUE_ID";
106 case KM_TAG_INCLUDE_UNIQUE_ID:
107 return "KM_TAG_INCLUDE_UNIQUE_ID";
108 case KM_TAG_RESET_SINCE_ID_ROTATION:
109 return "KM_TAG_RESET_SINCE_ID_ROTATION";
110 case KM_TAG_ALLOW_WHILE_ON_BODY:
111 return "KM_TAG_ALLOW_WHILE_ON_BODY";
112 case KM_TAG_ATTESTATION_CHALLENGE:
113 return "KM_TAG_ATTESTATION_CHALLENGE";
114 case KM_TAG_ATTESTATION_APPLICATION_ID:
115 return "KM_TAG_ATTESTATION_APPLICATION_ID";
116 case KM_TAG_ATTESTATION_ID_BRAND:
117 return "KM_TAG_ATTESTATION_ID_BRAND";
118 case KM_TAG_ATTESTATION_ID_DEVICE:
119 return "KM_TAG_ATTESTATION_ID_DEVICE";
120 case KM_TAG_ATTESTATION_ID_PRODUCT:
121 return "KM_TAG_ATTESTATION_ID_PRODUCT";
122 case KM_TAG_ATTESTATION_ID_SERIAL:
123 return "KM_TAG_ATTESTATION_ID_SERIAL";
124 case KM_TAG_ATTESTATION_ID_IMEI:
125 return "KM_TAG_ATTESTATION_ID_IMEI";
126 case KM_TAG_ATTESTATION_ID_MEID:
127 return "KM_TAG_ATTESTATION_ID_MEID";
128 case KM_TAG_ATTESTATION_ID_MANUFACTURER:
129 return "KM_TAG_ATTESTATION_ID_MANUFACTURER";
130 case KM_TAG_ATTESTATION_ID_MODEL:
131 return "KM_TAG_ATTESTATION_ID_MODEL";
132 }
133 return "<Unknown>";
134 }
135 #endif // KEYMASTER_NAME_TAGS
136
137 // DEFINE_KEYMASTER_TAG is used to create TypedTag instances for each non-enum keymaster tag.
138 #define DEFINE_KEYMASTER_TAG(type, name) TypedTag<type, KM_##name> name
139
140 DEFINE_KEYMASTER_TAG(KM_INVALID, TAG_INVALID);
141 DEFINE_KEYMASTER_TAG(KM_UINT, TAG_KEY_SIZE);
142 DEFINE_KEYMASTER_TAG(KM_UINT, TAG_MAC_LENGTH);
143 DEFINE_KEYMASTER_TAG(KM_BOOL, TAG_CALLER_NONCE);
144 DEFINE_KEYMASTER_TAG(KM_UINT, TAG_MIN_MAC_LENGTH);
145 DEFINE_KEYMASTER_TAG(KM_ULONG, TAG_RSA_PUBLIC_EXPONENT);
146 DEFINE_KEYMASTER_TAG(KM_BOOL, TAG_ECIES_SINGLE_HASH_MODE);
147 DEFINE_KEYMASTER_TAG(KM_BOOL, TAG_INCLUDE_UNIQUE_ID);
148 DEFINE_KEYMASTER_TAG(KM_DATE, TAG_ACTIVE_DATETIME);
149 DEFINE_KEYMASTER_TAG(KM_DATE, TAG_ORIGINATION_EXPIRE_DATETIME);
150 DEFINE_KEYMASTER_TAG(KM_DATE, TAG_USAGE_EXPIRE_DATETIME);
151 DEFINE_KEYMASTER_TAG(KM_UINT, TAG_MIN_SECONDS_BETWEEN_OPS);
152 DEFINE_KEYMASTER_TAG(KM_UINT, TAG_MAX_USES_PER_BOOT);
153 DEFINE_KEYMASTER_TAG(KM_BOOL, TAG_ALL_USERS);
154 DEFINE_KEYMASTER_TAG(KM_UINT, TAG_USER_ID);
155 DEFINE_KEYMASTER_TAG(KM_ULONG_REP, TAG_USER_SECURE_ID);
156 DEFINE_KEYMASTER_TAG(KM_BOOL, TAG_NO_AUTH_REQUIRED);
157 DEFINE_KEYMASTER_TAG(KM_UINT, TAG_AUTH_TIMEOUT);
158 DEFINE_KEYMASTER_TAG(KM_BOOL, TAG_ALLOW_WHILE_ON_BODY);
159 DEFINE_KEYMASTER_TAG(KM_BOOL, TAG_ALL_APPLICATIONS);
160 DEFINE_KEYMASTER_TAG(KM_BYTES, TAG_APPLICATION_ID);
161 DEFINE_KEYMASTER_TAG(KM_BYTES, TAG_APPLICATION_DATA);
162 DEFINE_KEYMASTER_TAG(KM_DATE, TAG_CREATION_DATETIME);
163 DEFINE_KEYMASTER_TAG(KM_BOOL, TAG_ROLLBACK_RESISTANT);
164 DEFINE_KEYMASTER_TAG(KM_BYTES, TAG_ROOT_OF_TRUST);
165 DEFINE_KEYMASTER_TAG(KM_BYTES, TAG_ASSOCIATED_DATA);
166 DEFINE_KEYMASTER_TAG(KM_BYTES, TAG_NONCE);
167 DEFINE_KEYMASTER_TAG(KM_BYTES, TAG_AUTH_TOKEN);
168 DEFINE_KEYMASTER_TAG(KM_BOOL, TAG_BOOTLOADER_ONLY);
169 DEFINE_KEYMASTER_TAG(KM_UINT, TAG_OS_VERSION);
170 DEFINE_KEYMASTER_TAG(KM_UINT, TAG_OS_PATCHLEVEL);
171 DEFINE_KEYMASTER_TAG(KM_BYTES, TAG_UNIQUE_ID);
172 DEFINE_KEYMASTER_TAG(KM_BYTES, TAG_ATTESTATION_APPLICATION_ID);
173 DEFINE_KEYMASTER_TAG(KM_BYTES, TAG_ATTESTATION_ID_BRAND);
174 DEFINE_KEYMASTER_TAG(KM_BYTES, TAG_ATTESTATION_ID_DEVICE);
175 DEFINE_KEYMASTER_TAG(KM_BYTES, TAG_ATTESTATION_ID_PRODUCT);
176 DEFINE_KEYMASTER_TAG(KM_BYTES, TAG_ATTESTATION_ID_SERIAL);
177 DEFINE_KEYMASTER_TAG(KM_BYTES, TAG_ATTESTATION_ID_IMEI);
178 DEFINE_KEYMASTER_TAG(KM_BYTES, TAG_ATTESTATION_ID_MEID);
179 DEFINE_KEYMASTER_TAG(KM_BYTES, TAG_ATTESTATION_ID_MANUFACTURER);
180 DEFINE_KEYMASTER_TAG(KM_BYTES, TAG_ATTESTATION_ID_MODEL);
181
182 // DEFINE_KEYMASTER_ENUM_TAG is used to create TypedEnumTag instances for each enum keymaster tag.
183
184 #define DEFINE_KEYMASTER_ENUM_TAG(type, name, enumtype) TypedEnumTag<type, KM_##name, enumtype> name
185
186 DEFINE_KEYMASTER_ENUM_TAG(KM_ENUM_REP, TAG_PURPOSE, keymaster_purpose_t);
187 DEFINE_KEYMASTER_ENUM_TAG(KM_ENUM, TAG_ALGORITHM, keymaster_algorithm_t);
188 DEFINE_KEYMASTER_ENUM_TAG(KM_ENUM_REP, TAG_BLOCK_MODE, keymaster_block_mode_t);
189 DEFINE_KEYMASTER_ENUM_TAG(KM_ENUM_REP, TAG_DIGEST, keymaster_digest_t);
190 DEFINE_KEYMASTER_ENUM_TAG(KM_ENUM, TAG_DIGEST_OLD, keymaster_digest_t);
191 DEFINE_KEYMASTER_ENUM_TAG(KM_ENUM_REP, TAG_PADDING, keymaster_padding_t);
192 DEFINE_KEYMASTER_ENUM_TAG(KM_ENUM, TAG_PADDING_OLD, keymaster_padding_t);
193 DEFINE_KEYMASTER_ENUM_TAG(KM_ENUM, TAG_BLOB_USAGE_REQUIREMENTS,
194 keymaster_key_blob_usage_requirements_t);
195 DEFINE_KEYMASTER_ENUM_TAG(KM_ENUM, TAG_ORIGIN, keymaster_key_origin_t);
196 DEFINE_KEYMASTER_ENUM_TAG(KM_ENUM, TAG_USER_AUTH_TYPE, hw_authenticator_type_t);
197 DEFINE_KEYMASTER_ENUM_TAG(KM_ENUM_REP, TAG_KDF, keymaster_kdf_t);
198 DEFINE_KEYMASTER_ENUM_TAG(KM_ENUM, TAG_EC_CURVE, keymaster_ec_curve_t);
199
200 } // namespace keymaster
201