blob: 7feae91d682eb859b80140959481c3b7db9cece0 [file] [log] [blame]
Bert McMeendaa11372015-09-17 16:35:18 -07001page.title=Features
2@jd:body
3
4<!--
5 Copyright 2015 The Android Open Source Project
6
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
10
11 http://www.apache.org/licenses/LICENSE-2.0
12
13 Unless required by applicable law or agreed to in writing, software
14 distributed under the License is distributed on an "AS IS" BASIS,
15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 See the License for the specific language governing permissions and
17 limitations under the License.
18-->
19<div id="qv-wrapper">
20 <div id="qv">
21 <h2>In this document</h2>
22 <ol id="auto-toc">
23 </ol>
24 </div>
25</div>
26
Danielle Roberts8bb806d2015-11-05 17:47:03 -080027<p>This page contains information about the features of <a href="index.html">Keymaster</a> 1.0.</p>
Bert McMeendaa11372015-09-17 16:35:18 -070028
29<h2 id=cryptographic_primitives>Cryptographic primitives</h2>
30
31<p>The <code>libkeymaster</code> library and Keymaster provide the following categories of operations:</p>
32
33<ul>
34 <li>Key generation
35 <li>Import and export of asymmetric keys (no key wrapping)
36 <li>Import of raw symmetric keys (again, no wrapping)
37 <li>Asymmetric encryption and decryption with appropriate padding modes
38 <li>Asymmetric signing and verification with digesting and appropriate padding
39modes
40 <li>Symmetric encryption and decryption in appropriate modes, including an AEAD
41mode
42 <li>Generation and verification of symmetric message authentication codes
43</ul>
44
45<p>Within each category, <code>libkeymaster</code> provides a mechanism for
46discovering the available options (algorithms,
47modes, etc.). But we also specify at least one required option, to ensure that
48client software can depend on the presence of the required primitives.</p>
49
50<p>Protocol elements, such as purpose, mode and padding, as well
51as <a href="#key_access_control">access control constraints</a>,
52must be specified when keys are generated or imported and are permanently
53bound to the key, ensuring the key cannot be used in any other way.</p>
54
55<p>In addition to the list above, there is one more service that Keymaster
56implementations must provide but which is not exposed as an API: Random number
57generation. This is used internally for generation of keys, Initialization
58Vectors (IVs), random padding and other elements of secure protocols that
59require randomness.</p>
60
61<h2 id=required_primitives>Required primitives</h2>
62
63<p>All implementations must provide:</p>
64
65<ul>
66 <li><a href="http://en.wikipedia.org/wiki/RSA_(cryptosystem)">RSA</a>
67 <ul>
68 <li>2048, 3072 and 4096-bit key support are required
69 <li>Support for public exponent F4 (2^16+1)
70 <li>Required padding modes for RSA signing are:
71 <ul>
72 <li>No padding (deprecated, will be removed in the future)
73 <li>RSASSA-PSS (<code>KM_PAD_RSA_PSS</code>)
74 <li>RSASSA-PKCS1-v1_5 (<code>KM_PAD_RSA_PKCS1_1_5_SIGN</code>)
75 </ul>
76 <li>Required digest modes for RSA signing are:
77 <ul>
78 <li>No digest (deprecated, will be removed in the future)
79 <li>SHA-256
80 </ul>
81 <li>Required padding modes for RSA encryption/decryption are:
82 <ul>
83 <li>RSAES-OAEP (<code>KM_PAD_RSA_OAEP</code>)
84 <li>RSAES-PKCS1-v1_5 (<code>KM_PAD_RSA_PKCS1_1_5_ENCRYPT</code>)
85 </ul>
86 <li>Unpadded RSA encryption must not be supported
87 </ul>
88 <li><a href="http://en.wikipedia.org/wiki/Elliptic_Curve_DSA">ECDSA</a>
89 <ul>
90 <li>224, 256, 384 and 521-bit key support are required, using the NIST P-224,
91P-256, P-384 and P-521 curves, respectively
92 <li>Required digest modes for ECDSA are:
93 <ul>
94 <li>No digest (deprecated, will be removed in the future)
95 <li>SHA-256
96 </ul>
97 </ul>
98 <li><a href="http://en.wikipedia.org/wiki/Advanced_Encryption_Standard">AES</a>
99 <ul>
100 <li>128 and 256-bit keys are required
101 <li><a href="http://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Cipher-block_chaining_.28CBC.29">CBC</a>,
102 CTR, ECB and and GCM. The GCM implementation must not allow the use of tags
103smaller than 96 bits or nonce lengths other than 96 bits.
104 <li>Padding modes <code>KM_PAD_NONE</code> and <code>KM_PAD_PKCS7</code> must
105 be supported for CBC and ECB modes. With no padding, CBC or ECB mode
106encryption must fail if the input isn't a multiple of the block size.
107 </ul>
108 <li><a href="http://en.wikipedia.org/wiki/Hash-based_message_authentication_code">HMAC</a>
109 <a href="http://en.wikipedia.org/wiki/SHA-2">SHA-256</a>, with any key size up to at least 32 bytes.
110</ul>
111</ul>
112
113<p>SHA1 and the other members of the SHA2 family (SHA-224, SHA384 and SHA512) are
114strongly recommended, but not required. Keystore will provide them in software
115if the hardware Keymaster implementation doesn't provide them.</p>
116
117<p>Some primitives are also recommended for interoperability with other systems:</p>
118
119<ul>
120 <li>Smaller key sizes for RSA
121 <li>Arbitrary public exponents for RSA
122</ul>
123
124<h2 id=key_access_control>Key access control</h2>
125
126<p>Hardware-based keys that can never be extracted from the device don't provide
127much security if an attacker can use them at will (though they're more secure
128than keys which <em>can</em> be exfiltrated). Thus, it's crucial that Keymaster enforce access controls.</p>
129
130<p>Access controls are defined as an "authorization list" of tag/value pairs.
131Authorization tags are 32-bit integers and the values are a variety of types.
132Some tags may be repeated to specify multiple values. Whether a tag may be
133repeated is specified in the documentation for the tag. When a key is created,
134the caller specifies an authorization list. The Keymaster implementation will
135modify the list to specify some additional information, such as whether the key
136has rollback protection, and return a "final" authorization list, encoded into
137the returned key blob. Any attempt to use the key for any cryptographic
138operation must fail if the final authorization list is modified.</p>
139
140<p>The set of possible tags is defined in the enumeration <code>keymaster_authorization_tag_t</code> and
141the set must be permanently fixed (though it can be extended).
142Names are prefixed with <code>KM_TAG_</code>. The top
143four bits of tag IDs are used to indicate the type.</p>
144
145<p>Possible types include:</p>
146
147<p><strong><code>KM_ENUM</code>:</strong> Many tags' values are defined in enumerations. For example, the possible
148values of <code>KM_TAG_PURPOSE</code> are defined in enum <code>keymaster_purpose_t</code>.</p>
149
150<p><strong><code>KM_ENUM_REP</code></strong>: Same as <code>KM_ENUM</code>, except that the tag may
151be repeated in an authorization list. Repetition
152indicates multiple authorized values. For example, an encryption key will
153likely have <code>KM_PURPOSE_ENCRYPT</code> and <code>KM_PURPOSE_DECRYPT</code>.</p>
154
155<p><strong><code>KM_UINT</code>:</strong> 32-bit unsigned integers. Example: <code>KM_TAG_KEY_SIZE</code></p>
156
157<p><strong><code>KM_UINT_REP</code></strong>: Same as <code>KM_UINT</code>, except that the tag may be
158repeated in an authorization list. Repetition indicates multiple authorized values.</p>
159
160<p><strong><code>KM_ULONG</code></strong>: 64-bit unsigned integers. Example: <code>KM_TAG_RSA_PUBLIC_EXPONENT</code></p>
161
162<p><strong><code>KM_ULONG_REP</code></strong>: Same as <code>KM_ULONG</code>, except that the tag may be
163repeated in an authorization list. Repetition
164indicates multiple authorized values.</p>
165
166<p><strong><code>KM_DATE</code></strong>: Date/time values, expressed as milliseconds since January 1, 1970.
167Example: <code>KM_TAG_PRIVKEY_EXPIRE_DATETIME</code></p>
168
169<p><strong><code>KM_BOOL</code></strong>: True or false. A tag of type <code>KM_BOOL</code> is assumed
170to be "false" if the tag is not present and "true" if present. Example: <code>KM_TAG_ROLLBACK_RESISTANT</code></p>
171
172<p><strong><code>KM_BIGNUM</code></strong>: Arbitrary-length integers, expressed as a byte array
173in big-endian order. Example: <code>KM_TAG_RSA_PUBLIC_EXPONENT</code></p>
174
175<p><strong><code>KM_BYTES</code></strong>: A sequence of bytes. Example: <code>KM_TAG_ROOT_OF_TRUST</code></p>
176
177<h3 id=hardware_vs_software_enforcement>Hardware vs. software enforcement</h3>
178
179<p>Not all Keymaster implementations will implement the same features. To support
180a variety of approaches, Keymaster 1.0 distinguishes between secure and
181non-secure world access control enforcement, which we call hardware and
182software enforcement, respectively.</p>
183
184<p>Implementations are required to:</p>
185
186<ul>
187 <li>Enforce exact matching (not enforcement) of all authorizations. Authorization
188lists in key blobs must exactly match the authorizations returned during key
189generation, including ordering. Any mismatch must cause an error diagnostic.
190 <li>Declare the authorizations whose semantic values are enforced.
191</ul>
192
193<p>The API mechanism for declaring hardware-enforced authorizations is in
194the <code>keymaster_key_characteristics_t</code> structure. It divides the authorization
195list into two sub-lists, <code>hw_enforced</code> and <code>sw_enforced</code>. The
196Keymaster implementation is responsible for placing the appropriate
197values in each, based on what it can enforce.</p>
198
199<p>In addition, the keystore daemon will implement software-based enforcement of <em>all</em> authorizations,
200whether they're enforced in hardware or not.</p>
201
202<p>For example, consider a TrustZone-based implementation that does not support
203key expiration. A key with an expiration date may still be created. That key's
204authorization list will include the tag <code>KM_TAG_ORIGINATION_EXPIRE_DATETIME</code> with
205the expiration date. A request to Keymaster for the key characteristics
206will find this tag in the <code>sw_enforced</code> list and the Keymaster implementation will
207not enforce the expiration
208requirement. However, attempts to use the key after expiration will be rejected
209by the keystore daemon.</p>
210
211<p>If the device is then upgraded with a Keymaster implementation that does
212support expiration, then a request for key characteristics will
213find <code>KM_TAG_ORIGINATION_EXPIRE_DATETIME</code> in
214the <code>hw_enforced</code> list, and attempts to use the key after expiration will fail even if the
215keystore is somehow subverted or bypassed.</p>
216
217<h3 id=cryptographic_message_construction_authorizations>Cryptographic message construction authorizations</h3>
218
219<p>The following tags are used to define the cryptographic characteristics of
220operations using the associated key: <code>KM_TAG_ALGORITHM</code>, <code>KM_TAG_KEY_SIZE</code>,
221<code>KM_TAG_BLOCK_MODE</code>, <code>KM_TAG_PADDING</code>, <code>KM_TAG_CALLER_NONCE</code>, and <code>KM_TAG_DIGEST</code></p>
222
223<p><code>KM_TAG_PADDING</code>, <code>KM_TAG_DIGEST</code>, and <code>KM_PAD_BLOCK_MODE</code>
224are repeatable, meaning that multiple values may be associated with a single
225key, and the value to be used will be specified at operation time.</p>
226
227<h3 id=purpose>Purpose</h3>
228
229<p>Keys have an associated set of purposes, expressed as one or more authorization
230entries with tag <code>KM_TAG_PURPOSE</code>, which defines how they can be used. The purposes are:</p>
231
232<ul>
233 <li><code>KM_PURPOSE_ENCRYPT</code>
234 <li><code>KM_PURPOSE_DECRYPT</code>
235 <li><code>KM_PURPOSE_SIGN</code>
236 <li><code>KM_PURPOSE_VERIFY</code>
237</ul>
238
239<p>Any key can have any subset of these purposes. Note that some combinations
240create security problems. For example, an RSA key that can be used to both
241encrypt and to sign allows an attacker who can convince the system to decrypt
242arbitrary data to generate signatures.</p>
243
244<p>Other purposes for keys that may be added in the future include:</p>
245
246<ul>
247 <li>"Derive Key" purpose, for key derivation keys
248 <li>"Attest" purpose, for keys that can generate attestations of the Keymaster
249implementation and/or its environment
250 <li>"Wrap Key" purpose, for keys used to wrap keys for secure import or export
251</ul>
252
253<h3 id=import_and_export>Import and export</h3>
254
255<p>Keymaster supports export of public keys only, in X.509 format, and import of:</p>
256
257<ul>
258 <li>Public and private key pairs in DER-encoded PKCS#8 format, without
259password-based encryption, and
260 <li>Symmetric keys as raw bytes
261</ul>
262
263<p>Future versions will likely expand the import/export options.</p>
264
265<p>To ensure that imported keys can be distinguished from securely-generated
266keys, <code>KM_TAG_ORIGIN</code> is included in the appropriate key
267authorization list. For example, if a key
268was generated in secure hardware, <code>KM_TAG_ORIGIN</code> with
269value <code>KM_ORIGIN_GENERATED</code> will be found in
270the <code>hw_enforced</code> list of the key characteristics, while a key
271that was imported into secure
272hardware will have the value <code>KM_ORIGIN_IMPORTED</code>.</p>
273
274<h3 id=user_authentication>User authentication</h3>
275
276<p>Keymaster does not implement user authentication, but depends on other trusted
277apps which do. For the interface that must be implemented by these apps, see
278the Gatekeeper page.</p>
279
280<p>User authentication requirements are specified via two sets of tags. The first
281set indicate which user can use the key:</p>
282
283<ul>
284 <li><code>KM_TAG_ALL_USERS</code> indicates the key is usable by all users. If
285 present, <code>KM_TAG_USER_ID</code> and <code>KM_TAG_SECURE_USER_ID</code> must not be present.
286 <li><code>KM_TAG_USER_ID</code> has a numeric value specifying the ID of the authorized user.
287 Note that this
288is the Android user ID (for multi-user), not the application UID, and it is
289enforced by non-secure software only. If present, <code>KM_TAG_ALL_USERS</code> must not be present.
290 <li><code>KM_TAG_SECURE_USER_ID</code> has a 64-bit numeric value specifying the secure user ID
291 that must be provided
292in a secure authentication token to unlock use of the key. If repeated, the key
293may be used if any of the values is provided in a secure authentication token.
294</ul>
295
296<p>The second set indicate whether and when the user must be authenticated. If
297neither of these tags is present, but <code>KM_TAG_SECURE_USER_ID</code> is, authentication is
298required for every use of the key.</p>
299
300<ul>
301 <li><code>KM_NO_AUTHENTICATION_REQUIRED</code> indicates no user authentication is required, though
302 the key still may only be
303used by apps running as the user(s) specified by <code>KM_TAG_USER_ID</code>.
304 <li><code>KM_TAG_AUTH_TIMEOUT</code> is a numeric value specifying, in seconds, how fresh the user
305 authentication
306must be to authorize key usage. This applies only to private/secret key
307operations. Public key operations don't require authentication. Timeouts do not
308cross reboots; after a reboot, all keys are "never authenticated." The timeout
309may be set to a large value to indicate that authentication is required once
310per boot (2^32 seconds is ~136 years; presumably Android devices are rebooted
311more often than that).
312</ul>
313
314<h3 id=client_binding>Client binding</h3>
315
316<p>Client binding, the association of a key with a particular client application,
317is done via an optional client ID and some optional client data (<code>KM_TAG_APPLICATION_ID</code>
318and <code>KM_TAG_APPLICATION_DATA</code>, respectively). Keymaster treats these values as opaque blobs,
319only ensuring
320that the same blobs presented during key generation/import are presented for
321every use and are byte-for-byte identical. The client binding data is not
322returned by Keymaster. The caller must know it in order to use the key.</p>
323
324<h3 id=expiration>Expiration</h3>
325
326<p>Keymaster supports restricting key usage by date. Key start of validity and key
327expirations can be associated with a key and Keymaster will refuse to perform
328key operations if the current date/time is outside of the valid range. The key
329validity range is specified with the tags <code>KM_TAG_ACTIVE_DATETIME</code>,
330<code>KM_TAG_ORIGINATION_EXPIRE_DATETIME</code>, and <code>KM_TAG_USAGE_EXPIRE_DATETIME</code>.
331The distinction between "origination" and "usage" is based on whether the key
332is being used to "originate" a new ciphertext/signature/etc., or to "use" an
333existing ciphertext/signature/etc.</p>
334
335<p>The <code>KM_TAG_ACTIVE_DATETIME</code>, <code>KM_TAG_ORIGINATION_EXPIRE_DATETIME</code>,
336and <code>KM_TAG_USAGE_EXPIRE_DATETIME</code> tags are optional. If the tags are absent, it is
337assumed that the key in
338question can always be used to decrypt/verify messages.</p>
339
340<p>Because wall-clock time is provided by the non-secure world, it's unlikely that
341the expiration-related tags will be in the hardware-enforced list. Hardware
342enforcement of expiry would require that the secure world somehow obtain
343trusted time and data, for example via a challenge response protocol with a
344trusted remote timeserver.</p>
345
346<h3 id=root_of_trust_binding>Root of trust binding</h3>
347
348<p>Keymaster allows keys to be bound to a root of trust, which is a bitstring
349provided to Keymaster during startup, preferably by the bootloader. If
350provided, this bitstring must be cryptographically bound to every key managed
351by Keymaster.</p>
352
353<p>The intent is for the bootloader to pass in the public key, used to verify the
354signature on the boot image, along with the verified boot state (locked or
355unlocked). If the public key is changed to allow a different system image to be
356used or if the verified boot state is changed, then none of the
357Keymaster-protected keys created by the previous system will be usable, unless
358the previous root of trust is restored and a system that is signed by that key
359is booted. The goal is to increase the value of the software-enforced key
360access controls by making it imposSTEM</code>sible for an attacker-installed operating
361system to use Keymaster keys.</p>
362
363<h3 id=standalone_keys>Standalone keys</h3>
364
365<p>Some Keymaster implementations may choose to store key material internally and
366return handles rather than encrypted key material. Or there may be other cases
367in which keys cannot be used until some other non-secure or secure world system
368component is available. The Keymaster 1.0 API allows the caller to request that
369a key be "standalone," via the <code>KM_TAG_STANDALONE</code> tag,
370meaning that no resources other than the blob and the running Keymaster
371system are required. The tags associated with a key may be inspected to see
372whether a key is standalone. At present, only two values are defined:</p>
373
374<ul>
375 <li><code>KM_BLOB_STANDALONE</code>
376 <li><code>KM_BLOB_REQUIRES_FILE_SYSTEM</code>
377</ul>
378
379<h3 id=velocity>Velocity</h3>
380
381<p>When it's created, the maximum usage velocity can be specified
382with <code>KM_TAG_MIN_SECONDS_BETWEEN_OPS</code>.
383TrustZone implementations will refuse to perform cryptographic operations
384with that key if an operation was performed less
385than <code>KM_TAG_MIN_SECONDS_BETWEEN_OPS</code> seconds earlier.</p>
386
387<p>The simple approach to implementing velocity limits is a table of key IDs and
388last-use timestamps. This table will likely be of limited size, but must
389accommodate at least 16 entries. In the event that the table is full and no
390entries may be updated or discarded, Keymaster implementations must "fail
391safe," preferring to refuse all velocity-limited key operations until one of
392the entries expires. It is acceptable for all entries to expire upon reboot.</p>
393
394<p>Keys can also be limited to <em>n</em> uses per boot with <code>KM_TAG_USES_PER_BOOT</code>.
395This also requires a tracking table, which must accommodate at least four
396keys, and must also fail safe. Note that applications will be unable to create
397per-boot limited keys. This feature will not be exposed through keystore and
398will be reserved for system operations.</p>
399
400<h3 id=random_number_generator_re-seeding>Random number generator re-seeding</h3>
401
402<p>Because Keymaster must generate random numbers for key material and
403Initialization Vectors (IVs), and because hardware random number generators may
404not always be fully trustworthy, Keymaster provides an interface to allow the
405client to provide additional entropy which will be mixed into the random
406numbers generated.</p>
407
408<p>A hardware random-number generator should be used as the primary seed source,
409if available, and the seed data provided through the external API must not be
410the sole source of randomness used for number generation. Further, the mixing
411operation used must ensure that the random output is unpredictable if any one
412of the seed sources is unpredictable.</p>