xref: /openbmc/linux/Documentation/security/keys/trusted-encrypted.rst (revision 7ae9fb1b7ecbb5d85d07857943f677fd1a559b18)
15395d312SKees Cook==========================
25395d312SKees CookTrusted and Encrypted Keys
35395d312SKees Cook==========================
45395d312SKees Cook
55395d312SKees CookTrusted and Encrypted Keys are two new key types added to the existing kernel
65395d312SKees Cookkey ring service.  Both of these new types are variable length symmetric keys,
75395d312SKees Cookand in both cases all keys are created in the kernel, and user space sees,
85395d312SKees Cookstores, and loads only encrypted blobs.  Trusted Keys require the availability
9c429805fSSumit Gargof a Trust Source for greater security, while Encrypted Keys can be used on any
10c429805fSSumit Gargsystem. All user level blobs, are displayed and loaded in hex ASCII for
11c429805fSSumit Gargconvenience, and are integrity verified.
125395d312SKees Cook
135395d312SKees Cook
14c429805fSSumit GargTrust Source
15c429805fSSumit Garg============
164264f27aSStefan Berger
17c429805fSSumit GargA trust source provides the source of security for Trusted Keys.  This
18c429805fSSumit Gargsection lists currently supported trust sources, along with their security
19c429805fSSumit Gargconsiderations.  Whether or not a trust source is sufficiently safe depends
20c429805fSSumit Gargon the strength and correctness of its implementation, as well as the threat
21c429805fSSumit Gargenvironment for a specific use case.  Since the kernel doesn't know what the
22c429805fSSumit Gargenvironment is, and there is no metric of trust, it is dependent on the
23c429805fSSumit Gargconsumer of the Trusted Keys to determine if the trust source is sufficiently
24c429805fSSumit Gargsafe.
255395d312SKees Cook
26c429805fSSumit Garg  *  Root of trust for storage
274264f27aSStefan Berger
28c429805fSSumit Garg     (1) TPM (Trusted Platform Module: hardware device)
29c429805fSSumit Garg
30c429805fSSumit Garg         Rooted to Storage Root Key (SRK) which never leaves the TPM that
31c429805fSSumit Garg         provides crypto operation to establish root of trust for storage.
32c429805fSSumit Garg
33c429805fSSumit Garg     (2) TEE (Trusted Execution Environment: OP-TEE based on Arm TrustZone)
34c429805fSSumit Garg
35c429805fSSumit Garg         Rooted to Hardware Unique Key (HUK) which is generally burnt in on-chip
36c429805fSSumit Garg         fuses and is accessible to TEE only.
37c429805fSSumit Garg
385002426eSAhmad Fatoum     (3) CAAM (Cryptographic Acceleration and Assurance Module: IP on NXP SoCs)
395002426eSAhmad Fatoum
405002426eSAhmad Fatoum         When High Assurance Boot (HAB) is enabled and the CAAM is in secure
415002426eSAhmad Fatoum         mode, trust is rooted to the OTPMK, a never-disclosed 256-bit key
425002426eSAhmad Fatoum         randomly generated and fused into each SoC at manufacturing time.
435002426eSAhmad Fatoum         Otherwise, a common fixed test key is used instead.
445002426eSAhmad Fatoum
45c429805fSSumit Garg  *  Execution isolation
46c429805fSSumit Garg
47c429805fSSumit Garg     (1) TPM
48c429805fSSumit Garg
49c429805fSSumit Garg         Fixed set of operations running in isolated execution environment.
50c429805fSSumit Garg
51c429805fSSumit Garg     (2) TEE
52c429805fSSumit Garg
53c429805fSSumit Garg         Customizable set of operations running in isolated execution
54c429805fSSumit Garg         environment verified via Secure/Trusted boot process.
55c429805fSSumit Garg
565002426eSAhmad Fatoum     (3) CAAM
575002426eSAhmad Fatoum
585002426eSAhmad Fatoum         Fixed set of operations running in isolated execution environment.
595002426eSAhmad Fatoum
60c429805fSSumit Garg  * Optional binding to platform integrity state
61c429805fSSumit Garg
62c429805fSSumit Garg     (1) TPM
63c429805fSSumit Garg
64c429805fSSumit Garg         Keys can be optionally sealed to specified PCR (integrity measurement)
65c429805fSSumit Garg         values, and only unsealed by the TPM, if PCRs and blob integrity
66c429805fSSumit Garg         verifications match. A loaded Trusted Key can be updated with new
67c429805fSSumit Garg         (future) PCR values, so keys are easily migrated to new PCR values,
68c429805fSSumit Garg         such as when the kernel and initramfs are updated. The same key can
69c429805fSSumit Garg         have many saved blobs under different PCR values, so multiple boots are
70c429805fSSumit Garg         easily supported.
71c429805fSSumit Garg
72c429805fSSumit Garg     (2) TEE
73c429805fSSumit Garg
74c429805fSSumit Garg         Relies on Secure/Trusted boot process for platform integrity. It can
75c429805fSSumit Garg         be extended with TEE based measured boot process.
76c429805fSSumit Garg
775002426eSAhmad Fatoum     (3) CAAM
785002426eSAhmad Fatoum
795002426eSAhmad Fatoum         Relies on the High Assurance Boot (HAB) mechanism of NXP SoCs
805002426eSAhmad Fatoum         for platform integrity.
815002426eSAhmad Fatoum
82c429805fSSumit Garg  *  Interfaces and APIs
83c429805fSSumit Garg
84c429805fSSumit Garg     (1) TPM
85c429805fSSumit Garg
86c429805fSSumit Garg         TPMs have well-documented, standardized interfaces and APIs.
87c429805fSSumit Garg
88c429805fSSumit Garg     (2) TEE
89c429805fSSumit Garg
90c429805fSSumit Garg         TEEs have well-documented, standardized client interface and APIs. For
91c429805fSSumit Garg         more details refer to ``Documentation/staging/tee.rst``.
92c429805fSSumit Garg
935002426eSAhmad Fatoum     (3) CAAM
945002426eSAhmad Fatoum
955002426eSAhmad Fatoum         Interface is specific to silicon vendor.
96c429805fSSumit Garg
97c429805fSSumit Garg  *  Threat model
98c429805fSSumit Garg
995002426eSAhmad Fatoum     The strength and appropriateness of a particular trust source for a given
100c429805fSSumit Garg     purpose must be assessed when using them to protect security-relevant data.
101c429805fSSumit Garg
102c429805fSSumit Garg
103c429805fSSumit GargKey Generation
104c429805fSSumit Garg==============
105c429805fSSumit Garg
106c429805fSSumit GargTrusted Keys
107c429805fSSumit Garg------------
108c429805fSSumit Garg
109fcd7c269SAhmad FatoumNew keys are created from random numbers. They are encrypted/decrypted using
110fcd7c269SAhmad Fatouma child key in the storage key hierarchy. Encryption and decryption of the
111fcd7c269SAhmad Fatoumchild key must be protected by a strong access control policy within the
112fcd7c269SAhmad Fatoumtrust source. The random number generator in use differs according to the
113fcd7c269SAhmad Fatoumselected trust source:
114c429805fSSumit Garg
115fcd7c269SAhmad Fatoum  *  TPM: hardware device based RNG
116c429805fSSumit Garg
117fcd7c269SAhmad Fatoum     Keys are generated within the TPM. Strength of random numbers may vary
118fcd7c269SAhmad Fatoum     from one device manufacturer to another.
119c429805fSSumit Garg
120fcd7c269SAhmad Fatoum  *  TEE: OP-TEE based on Arm TrustZone based RNG
121c429805fSSumit Garg
122c429805fSSumit Garg     RNG is customizable as per platform needs. It can either be direct output
123c429805fSSumit Garg     from platform specific hardware RNG or a software based Fortuna CSPRNG
124c429805fSSumit Garg     which can be seeded via multiple entropy sources.
125c429805fSSumit Garg
1265002426eSAhmad Fatoum  *  CAAM: Kernel RNG
1275002426eSAhmad Fatoum
1285002426eSAhmad Fatoum     The normal kernel random number generator is used. To seed it from the
1295002426eSAhmad Fatoum     CAAM HWRNG, enable CRYPTO_DEV_FSL_CAAM_RNG_API and ensure the device
1305002426eSAhmad Fatoum     is probed.
1315002426eSAhmad Fatoum
132fcd7c269SAhmad FatoumUsers may override this by specifying ``trusted.rng=kernel`` on the kernel
133fcd7c269SAhmad Fatoumcommand-line to override the used RNG with the kernel's random number pool.
134fcd7c269SAhmad Fatoum
135c429805fSSumit GargEncrypted Keys
136c429805fSSumit Garg--------------
137c429805fSSumit Garg
138c429805fSSumit GargEncrypted keys do not depend on a trust source, and are faster, as they use AES
139cd3bc044SYael Tzurfor encryption/decryption. New keys are created either from kernel-generated
140cd3bc044SYael Tzurrandom numbers or user-provided decrypted data, and are encrypted/decrypted
141cd3bc044SYael Tzurusing a specified ‘master’ key. The ‘master’ key can either be a trusted-key or
142cd3bc044SYael Tzuruser-key type. The main disadvantage of encrypted keys is that if they are not
143cd3bc044SYael Tzurrooted in a trusted key, they are only as secure as the user key encrypting
144cd3bc044SYael Tzurthem. The master user key should therefore be loaded in as secure a way as
145cd3bc044SYael Tzurpossible, preferably early in boot.
146c429805fSSumit Garg
147c429805fSSumit Garg
148c429805fSSumit GargUsage
149c429805fSSumit Garg=====
150c429805fSSumit Garg
151c429805fSSumit GargTrusted Keys usage: TPM
152c429805fSSumit Garg-----------------------
153c429805fSSumit Garg
154c429805fSSumit GargTPM 1.2: By default, trusted keys are sealed under the SRK, which has the
155c429805fSSumit Gargdefault authorization value (20 bytes of 0s).  This can be set at takeownership
156c429805fSSumit Gargtime with the TrouSerS utility: "tpm_takeownership -u -z".
157c429805fSSumit Garg
158c429805fSSumit GargTPM 2.0: The user must first create a storage key and make it persistent, so the
159c429805fSSumit Gargkey is available after reboot. This can be done using the following commands.
1604264f27aSStefan Berger
1614264f27aSStefan BergerWith the IBM TSS 2 stack::
1624264f27aSStefan Berger
1634264f27aSStefan Berger  #> tsscreateprimary -hi o -st
1644264f27aSStefan Berger  Handle 80000000
1654264f27aSStefan Berger  #> tssevictcontrol -hi o -ho 80000000 -hp 81000001
1664264f27aSStefan Berger
1674264f27aSStefan BergerOr with the Intel TSS 2 stack::
1684264f27aSStefan Berger
169bb84bc51SColy Li  #> tpm2_createprimary --hierarchy o -G rsa2048 -c key.ctxt
1704264f27aSStefan Berger  [...]
171bb84bc51SColy Li  #> tpm2_evictcontrol -c key.ctxt 0x81000001
1724264f27aSStefan Berger  persistentHandle: 0x81000001
1734264f27aSStefan Berger
1745395d312SKees CookUsage::
1755395d312SKees Cook
1765395d312SKees Cook    keyctl add trusted name "new keylen [options]" ring
1775395d312SKees Cook    keyctl add trusted name "load hex_blob [pcrlock=pcrnum]" ring
1785395d312SKees Cook    keyctl update key "update [options]"
1795395d312SKees Cook    keyctl print keyid
1805395d312SKees Cook
1815395d312SKees Cook    options:
1824264f27aSStefan Berger       keyhandle=    ascii hex value of sealing key
1834264f27aSStefan Berger                       TPM 1.2: default 0x40000000 (SRK)
1844264f27aSStefan Berger                       TPM 2.0: no default; must be passed every time
1855395d312SKees Cook       keyauth=	     ascii hex auth for sealing key default 0x00...i
1865395d312SKees Cook                     (40 ascii zeros)
1875395d312SKees Cook       blobauth=     ascii hex auth for sealed data default 0x00...
1885395d312SKees Cook                     (40 ascii zeros)
1895395d312SKees Cook       pcrinfo=	     ascii hex of PCR_INFO or PCR_INFO_LONG (no default)
1905395d312SKees Cook       pcrlock=	     pcr number to be extended to "lock" blob
1915395d312SKees Cook       migratable=   0|1 indicating permission to reseal to new PCR values,
1925395d312SKees Cook                     default 1 (resealing allowed)
1935395d312SKees Cook       hash=         hash algorithm name as a string. For TPM 1.x the only
1945395d312SKees Cook                     allowed value is sha1. For TPM 2.x the allowed values
1955395d312SKees Cook                     are sha1, sha256, sha384, sha512 and sm3-256.
1965395d312SKees Cook       policydigest= digest for the authorization policy. must be calculated
1975395d312SKees Cook                     with the same hash algorithm as specified by the 'hash='
1985395d312SKees Cook                     option.
1995395d312SKees Cook       policyhandle= handle to an authorization policy session that defines the
2005395d312SKees Cook                     same policy and with the same hash algorithm as was used to
2015395d312SKees Cook                     seal the key.
2025395d312SKees Cook
2035395d312SKees Cook"keyctl print" returns an ascii hex copy of the sealed key, which is in standard
2045395d312SKees CookTPM_STORED_DATA format.  The key length for new keys are always in bytes.
2055395d312SKees CookTrusted Keys can be 32 - 128 bytes (256 - 1024 bits), the upper limit is to fit
2065395d312SKees Cookwithin the 2048 bit SRK (RSA) keylength, with all necessary structure/padding.
2075395d312SKees Cook
208c429805fSSumit GargTrusted Keys usage: TEE
209c429805fSSumit Garg-----------------------
210c429805fSSumit Garg
211c429805fSSumit GargUsage::
212c429805fSSumit Garg
213c429805fSSumit Garg    keyctl add trusted name "new keylen" ring
214c429805fSSumit Garg    keyctl add trusted name "load hex_blob" ring
215c429805fSSumit Garg    keyctl print keyid
216c429805fSSumit Garg
217c429805fSSumit Garg"keyctl print" returns an ASCII hex copy of the sealed key, which is in format
218c429805fSSumit Gargspecific to TEE device implementation.  The key length for new keys is always
219c429805fSSumit Gargin bytes. Trusted Keys can be 32 - 128 bytes (256 - 1024 bits).
220c429805fSSumit Garg
2215002426eSAhmad FatoumTrusted Keys usage: CAAM
2225002426eSAhmad Fatoum------------------------
2235002426eSAhmad Fatoum
2245002426eSAhmad FatoumUsage::
2255002426eSAhmad Fatoum
2265002426eSAhmad Fatoum    keyctl add trusted name "new keylen" ring
2275002426eSAhmad Fatoum    keyctl add trusted name "load hex_blob" ring
2285002426eSAhmad Fatoum    keyctl print keyid
2295002426eSAhmad Fatoum
2305002426eSAhmad Fatoum"keyctl print" returns an ASCII hex copy of the sealed key, which is in a
2315002426eSAhmad FatoumCAAM-specific format.  The key length for new keys is always in bytes.
2325002426eSAhmad FatoumTrusted Keys can be 32 - 128 bytes (256 - 1024 bits).
2335002426eSAhmad Fatoum
234c429805fSSumit GargEncrypted Keys usage
235c429805fSSumit Garg--------------------
2365395d312SKees Cook
2375395d312SKees CookThe decrypted portion of encrypted keys can contain either a simple symmetric
2385395d312SKees Cookkey or a more complex structure. The format of the more complex structure is
2395395d312SKees Cookapplication specific, which is identified by 'format'.
2405395d312SKees Cook
2415395d312SKees CookUsage::
2425395d312SKees Cook
2435395d312SKees Cook    keyctl add encrypted name "new [format] key-type:master-key-name keylen"
2445395d312SKees Cook        ring
245cd3bc044SYael Tzur    keyctl add encrypted name "new [format] key-type:master-key-name keylen
246cd3bc044SYael Tzur        decrypted-data" ring
2475395d312SKees Cook    keyctl add encrypted name "load hex_blob" ring
2485395d312SKees Cook    keyctl update keyid "update key-type:master-key-name"
2495395d312SKees Cook
2505395d312SKees CookWhere::
2515395d312SKees Cook
2529db67581SDave Jiang	format:= 'default | ecryptfs | enc32'
2535395d312SKees Cook	key-type:= 'trusted' | 'user'
2545395d312SKees Cook
255c429805fSSumit GargExamples of trusted and encrypted key usage
256c429805fSSumit Garg-------------------------------------------
2575395d312SKees Cook
2586ad8b216SMauro Carvalho ChehabCreate and save a trusted key named "kmk" of length 32 bytes.
2595395d312SKees Cook
2604264f27aSStefan BergerNote: When using a TPM 2.0 with a persistent key with handle 0x81000001,
2614264f27aSStefan Bergerappend 'keyhandle=0x81000001' to statements between quotes, such as
2624264f27aSStefan Berger"new 32 keyhandle=0x81000001".
2634264f27aSStefan Berger
2646ad8b216SMauro Carvalho Chehab::
2656ad8b216SMauro Carvalho Chehab
2665395d312SKees Cook    $ keyctl add trusted kmk "new 32" @u
2675395d312SKees Cook    440502848
2685395d312SKees Cook
2695395d312SKees Cook    $ keyctl show
2705395d312SKees Cook    Session Keyring
2715395d312SKees Cook           -3 --alswrv    500   500  keyring: _ses
2725395d312SKees Cook     97833714 --alswrv    500    -1   \_ keyring: _uid.500
2735395d312SKees Cook    440502848 --alswrv    500   500       \_ trusted: kmk
2745395d312SKees Cook
2755395d312SKees Cook    $ keyctl print 440502848
2765395d312SKees Cook    0101000000000000000001005d01b7e3f4a6be5709930f3b70a743cbb42e0cc95e18e915
2775395d312SKees Cook    3f60da455bbf1144ad12e4f92b452f966929f6105fd29ca28e4d4d5a031d068478bacb0b
2785395d312SKees Cook    27351119f822911b0a11ba3d3498ba6a32e50dac7f32894dd890eb9ad578e4e292c83722
2795395d312SKees Cook    a52e56a097e6a68b3f56f7a52ece0cdccba1eb62cad7d817f6dc58898b3ac15f36026fec
2805395d312SKees Cook    d568bd4a706cb60bb37be6d8f1240661199d640b66fb0fe3b079f97f450b9ef9c22c6d5d
2815395d312SKees Cook    dd379f0facd1cd020281dfa3c70ba21a3fa6fc2471dc6d13ecf8298b946f65345faa5ef0
2825395d312SKees Cook    f1f8fff03ad0acb083725535636addb08d73dedb9832da198081e5deae84bfaf0409c22b
2835395d312SKees Cook    e4a8aea2b607ec96931e6f4d4fe563ba
2845395d312SKees Cook
2855395d312SKees Cook    $ keyctl pipe 440502848 > kmk.blob
2865395d312SKees Cook
2875395d312SKees CookLoad a trusted key from the saved blob::
2885395d312SKees Cook
2895395d312SKees Cook    $ keyctl add trusted kmk "load `cat kmk.blob`" @u
2905395d312SKees Cook    268728824
2915395d312SKees Cook
2925395d312SKees Cook    $ keyctl print 268728824
2935395d312SKees Cook    0101000000000000000001005d01b7e3f4a6be5709930f3b70a743cbb42e0cc95e18e915
2945395d312SKees Cook    3f60da455bbf1144ad12e4f92b452f966929f6105fd29ca28e4d4d5a031d068478bacb0b
2955395d312SKees Cook    27351119f822911b0a11ba3d3498ba6a32e50dac7f32894dd890eb9ad578e4e292c83722
2965395d312SKees Cook    a52e56a097e6a68b3f56f7a52ece0cdccba1eb62cad7d817f6dc58898b3ac15f36026fec
2975395d312SKees Cook    d568bd4a706cb60bb37be6d8f1240661199d640b66fb0fe3b079f97f450b9ef9c22c6d5d
2985395d312SKees Cook    dd379f0facd1cd020281dfa3c70ba21a3fa6fc2471dc6d13ecf8298b946f65345faa5ef0
2995395d312SKees Cook    f1f8fff03ad0acb083725535636addb08d73dedb9832da198081e5deae84bfaf0409c22b
3005395d312SKees Cook    e4a8aea2b607ec96931e6f4d4fe563ba
3015395d312SKees Cook
302c429805fSSumit GargReseal (TPM specific) a trusted key under new PCR values::
3035395d312SKees Cook
3045395d312SKees Cook    $ keyctl update 268728824 "update pcrinfo=`cat pcr.blob`"
3055395d312SKees Cook    $ keyctl print 268728824
3065395d312SKees Cook    010100000000002c0002800093c35a09b70fff26e7a98ae786c641e678ec6ffb6b46d805
3075395d312SKees Cook    77c8a6377aed9d3219c6dfec4b23ffe3000001005d37d472ac8a44023fbb3d18583a4f73
3085395d312SKees Cook    d3a076c0858f6f1dcaa39ea0f119911ff03f5406df4f7f27f41da8d7194f45c9f4e00f2e
3095395d312SKees Cook    df449f266253aa3f52e55c53de147773e00f0f9aca86c64d94c95382265968c354c5eab4
3105395d312SKees Cook    9638c5ae99c89de1e0997242edfb0b501744e11ff9762dfd951cffd93227cc513384e7e6
3115395d312SKees Cook    e782c29435c7ec2edafaa2f4c1fe6e7a781b59549ff5296371b42133777dcc5b8b971610
3125395d312SKees Cook    94bc67ede19e43ddb9dc2baacad374a36feaf0314d700af0a65c164b7082401740e489c9
3135395d312SKees Cook    7ef6a24defe4846104209bf0c3eced7fa1a672ed5b125fc9d8cd88b476a658a4434644ef
3145395d312SKees Cook    df8ae9a178e9f83ba9f08d10fa47e4226b98b0702f06b3b8
3155395d312SKees Cook
316c429805fSSumit Garg
3175395d312SKees CookThe initial consumer of trusted keys is EVM, which at boot time needs a high
3185395d312SKees Cookquality symmetric key for HMAC protection of file metadata. The use of a
3195395d312SKees Cooktrusted key provides strong guarantees that the EVM key has not been
320c429805fSSumit Gargcompromised by a user level problem, and when sealed to a platform integrity
321c429805fSSumit Gargstate, protects against boot and offline attacks. Create and save an
3225395d312SKees Cookencrypted key "evm" using the above trusted key "kmk":
3235395d312SKees Cook
3245395d312SKees Cookoption 1: omitting 'format'::
3255395d312SKees Cook
3265395d312SKees Cook    $ keyctl add encrypted evm "new trusted:kmk 32" @u
3275395d312SKees Cook    159771175
3285395d312SKees Cook
3295395d312SKees Cookoption 2: explicitly defining 'format' as 'default'::
3305395d312SKees Cook
3315395d312SKees Cook    $ keyctl add encrypted evm "new default trusted:kmk 32" @u
3325395d312SKees Cook    159771175
3335395d312SKees Cook
3345395d312SKees Cook    $ keyctl print 159771175
3355395d312SKees Cook    default trusted:kmk 32 2375725ad57798846a9bbd240de8906f006e66c03af53b1b3
3365395d312SKees Cook    82dbbc55be2a44616e4959430436dc4f2a7a9659aa60bb4652aeb2120f149ed197c564e0
3375395d312SKees Cook    24717c64 5972dcb82ab2dde83376d82b2e3c09ffc
3385395d312SKees Cook
3395395d312SKees Cook    $ keyctl pipe 159771175 > evm.blob
3405395d312SKees Cook
3415395d312SKees CookLoad an encrypted key "evm" from saved blob::
3425395d312SKees Cook
3435395d312SKees Cook    $ keyctl add encrypted evm "load `cat evm.blob`" @u
3445395d312SKees Cook    831684262
3455395d312SKees Cook
3465395d312SKees Cook    $ keyctl print 831684262
3475395d312SKees Cook    default trusted:kmk 32 2375725ad57798846a9bbd240de8906f006e66c03af53b1b3
3485395d312SKees Cook    82dbbc55be2a44616e4959430436dc4f2a7a9659aa60bb4652aeb2120f149ed197c564e0
3495395d312SKees Cook    24717c64 5972dcb82ab2dde83376d82b2e3c09ffc
3505395d312SKees Cook
351cd3bc044SYael TzurInstantiate an encrypted key "evm" using user-provided decrypted data::
352cd3bc044SYael Tzur
353*5adedd42SNikolaus Voss    $ evmkey=$(dd if=/dev/urandom bs=1 count=32 | xxd -c32 -p)
354*5adedd42SNikolaus Voss    $ keyctl add encrypted evm "new default user:kmk 32 $evmkey" @u
355cd3bc044SYael Tzur    794890253
356cd3bc044SYael Tzur
357cd3bc044SYael Tzur    $ keyctl print 794890253
358cd3bc044SYael Tzur    default user:kmk 32 2375725ad57798846a9bbd240de8906f006e66c03af53b1b382d
359cd3bc044SYael Tzur    bbc55be2a44616e4959430436dc4f2a7a9659aa60bb4652aeb2120f149ed197c564e0247
360cd3bc044SYael Tzur    17c64 5972dcb82ab2dde83376d82b2e3c09ffc
361cd3bc044SYael Tzur
3625395d312SKees CookOther uses for trusted and encrypted keys, such as for disk and file encryption
363b216685bSRandy Dunlapare anticipated.  In particular the new format 'ecryptfs' has been defined
3645395d312SKees Cookin order to use encrypted keys to mount an eCryptfs filesystem.  More details
3655395d312SKees Cookabout the usage can be found in the file
366adf31eebSJosh Holland``Documentation/security/keys/ecryptfs.rst``.
3679db67581SDave Jiang
3689db67581SDave JiangAnother new format 'enc32' has been defined in order to support encrypted keys
3699db67581SDave Jiangwith payload size of 32 bytes. This will initially be used for nvdimm security
3709db67581SDave Jiangbut may expand to other usages that require 32 bytes payload.
371f2219745SJames Bottomley
372f2219745SJames Bottomley
373f2219745SJames BottomleyTPM 2.0 ASN.1 Key Format
374f2219745SJames Bottomley------------------------
375f2219745SJames Bottomley
376f2219745SJames BottomleyThe TPM 2.0 ASN.1 key format is designed to be easily recognisable,
377f2219745SJames Bottomleyeven in binary form (fixing a problem we had with the TPM 1.2 ASN.1
378f2219745SJames Bottomleyformat) and to be extensible for additions like importable keys and
379f2219745SJames Bottomleypolicy::
380f2219745SJames Bottomley
381f2219745SJames Bottomley    TPMKey ::= SEQUENCE {
382f2219745SJames Bottomley        type		OBJECT IDENTIFIER
383f2219745SJames Bottomley        emptyAuth	[0] EXPLICIT BOOLEAN OPTIONAL
384f2219745SJames Bottomley        parent		INTEGER
385f2219745SJames Bottomley        pubkey		OCTET STRING
386f2219745SJames Bottomley        privkey		OCTET STRING
387f2219745SJames Bottomley    }
388f2219745SJames Bottomley
389f2219745SJames Bottomleytype is what distinguishes the key even in binary form since the OID
390f2219745SJames Bottomleyis provided by the TCG to be unique and thus forms a recognizable
391f2219745SJames Bottomleybinary pattern at offset 3 in the key.  The OIDs currently made
392f2219745SJames Bottomleyavailable are::
393f2219745SJames Bottomley
394f2219745SJames Bottomley    2.23.133.10.1.3 TPM Loadable key.  This is an asymmetric key (Usually
395f2219745SJames Bottomley                    RSA2048 or Elliptic Curve) which can be imported by a
396f2219745SJames Bottomley                    TPM2_Load() operation.
397f2219745SJames Bottomley
398f2219745SJames Bottomley    2.23.133.10.1.4 TPM Importable Key.  This is an asymmetric key (Usually
399f2219745SJames Bottomley                    RSA2048 or Elliptic Curve) which can be imported by a
400f2219745SJames Bottomley                    TPM2_Import() operation.
401f2219745SJames Bottomley
402f2219745SJames Bottomley    2.23.133.10.1.5 TPM Sealed Data.  This is a set of data (up to 128
403f2219745SJames Bottomley                    bytes) which is sealed by the TPM.  It usually
404f2219745SJames Bottomley                    represents a symmetric key and must be unsealed before
405f2219745SJames Bottomley                    use.
406f2219745SJames Bottomley
407f2219745SJames BottomleyThe trusted key code only uses the TPM Sealed Data OID.
408f2219745SJames Bottomley
409f2219745SJames BottomleyemptyAuth is true if the key has well known authorization "".  If it
410f2219745SJames Bottomleyis false or not present, the key requires an explicit authorization
411f2219745SJames Bottomleyphrase.  This is used by most user space consumers to decide whether
412f2219745SJames Bottomleyto prompt for a password.
413f2219745SJames Bottomley
414f2219745SJames Bottomleyparent represents the parent key handle, either in the 0x81 MSO space,
415f2219745SJames Bottomleylike 0x81000001 for the RSA primary storage key.  Userspace programmes
416f2219745SJames Bottomleyalso support specifying the primary handle in the 0x40 MSO space.  If
417f2219745SJames Bottomleythis happens the Elliptic Curve variant of the primary key using the
418f2219745SJames BottomleyTCG defined template will be generated on the fly into a volatile
419f2219745SJames Bottomleyobject and used as the parent.  The current kernel code only supports
420f2219745SJames Bottomleythe 0x81 MSO form.
421f2219745SJames Bottomley
422f2219745SJames Bottomleypubkey is the binary representation of TPM2B_PRIVATE excluding the
423f2219745SJames Bottomleyinitial TPM2B header, which can be reconstructed from the ASN.1 octet
424f2219745SJames Bottomleystring length.
425f2219745SJames Bottomley
426f2219745SJames Bottomleyprivkey is the binary representation of TPM2B_PUBLIC excluding the
427f2219745SJames Bottomleyinitial TPM2B header which can be reconstructed from the ASN.1 octed
428f2219745SJames Bottomleystring length.
429