xref: /openbmc/u-boot/doc/imx/habv4/introduction_habv4.txt (revision b89074f65047c4058741ed2bf3e6ff0c5af4c5bc)
1*cbc4b041SBreno Matheus Lima          +=======================================================+
2*cbc4b041SBreno Matheus Lima          +     i.MX Secure and Encrypted Boot using HABv4        +
3*cbc4b041SBreno Matheus Lima          +=======================================================+
4*cbc4b041SBreno Matheus Lima
5*cbc4b041SBreno Matheus Lima1. Introduction
6*cbc4b041SBreno Matheus Lima----------------
7*cbc4b041SBreno Matheus Lima
8*cbc4b041SBreno Matheus LimaThe i.MX family of applications processors provides the High Assurance Boot
9*cbc4b041SBreno Matheus Lima(HAB) feature in the on-chip ROM. The ROM is responsible for loading the
10*cbc4b041SBreno Matheus Limainitial program image (U-Boot) from the boot media and HAB enables the ROM
11*cbc4b041SBreno Matheus Limato authenticate and/or decrypt the program image by using cryptography
12*cbc4b041SBreno Matheus Limaoperations.
13*cbc4b041SBreno Matheus Lima
14*cbc4b041SBreno Matheus LimaThis feature is supported in i.MX 50, i.MX 53, i.MX 6, i.MX 7 series and
15*cbc4b041SBreno Matheus Lima i.MX 8M, i.MX 8MM devices.
16*cbc4b041SBreno Matheus Lima
17*cbc4b041SBreno Matheus LimaStep-by-step guides are available under doc/imx/habv4/guides/ directory,
18*cbc4b041SBreno Matheus Limausers familiar with HAB and CST PKI tree generation should refer to these
19*cbc4b041SBreno Matheus Limadocuments instead.
20*cbc4b041SBreno Matheus Lima
21*cbc4b041SBreno Matheus Lima1.1 The HABv4 Secure Boot Architecture
22*cbc4b041SBreno Matheus Lima---------------------------------------
23*cbc4b041SBreno Matheus Lima
24*cbc4b041SBreno Matheus LimaThe HABv4 secure boot feature uses digital signatures to prevent unauthorized
25*cbc4b041SBreno Matheus Limasoftware execution during the device boot sequence. In case a malware takes
26*cbc4b041SBreno Matheus Limacontrol of the boot sequence, sensitive data, services and network can be
27*cbc4b041SBreno Matheus Limaimpacted.
28*cbc4b041SBreno Matheus Lima
29*cbc4b041SBreno Matheus LimaThe HAB authentication is based on public key cryptography using the RSA
30*cbc4b041SBreno Matheus Limaalgorithm in which image data is signed offline using a series of private
31*cbc4b041SBreno Matheus Limakeys. The resulting signed image data is then verified on the i.MX processor
32*cbc4b041SBreno Matheus Limausing the corresponding public keys. The public keys are included in the CSF
33*cbc4b041SBreno Matheus Limabinary and the SRK Hash is programmed in the SoC fuses for establishing the
34*cbc4b041SBreno Matheus Limaroot of trust.
35*cbc4b041SBreno Matheus Lima
36*cbc4b041SBreno Matheus LimaThe diagram below illustrate the secure boot process overview:
37*cbc4b041SBreno Matheus Lima
38*cbc4b041SBreno Matheus Lima          Host PC + CST                             i.MX + HAB
39*cbc4b041SBreno Matheus Lima          +----------+                             +----------+
40*cbc4b041SBreno Matheus Lima     ---> |  U-Boot  |                             | Compare  |
41*cbc4b041SBreno Matheus Lima     |    +----------+                             +----------+
42*cbc4b041SBreno Matheus Lima     |          |                                     ^    ^
43*cbc4b041SBreno Matheus Lima     |          v                         Reference  /      \  Generated
44*cbc4b041SBreno Matheus Lima     |    +----------+                      Hash    /        \   Hash
45*cbc4b041SBreno Matheus Lima     |    |   Hash   |  Private                    /          \
46*cbc4b041SBreno Matheus Lima     |    +----------+    Key                     /            \
47*cbc4b041SBreno Matheus Lima     |          |          |                +----------+  +----------+
48*cbc4b041SBreno Matheus Lima     |          v          |                |  Verify  |  |   Hash   |
49*cbc4b041SBreno Matheus Lima     |    +----------+     |                +----------+  +----------+
50*cbc4b041SBreno Matheus Lima     |    |   Sign   |  <---      SRK            ^            ^
51*cbc4b041SBreno Matheus Lima     |    +----------+            HASH            \          /
52*cbc4b041SBreno Matheus Lima     |          |                  |          CSF  \        /   U-Boot
53*cbc4b041SBreno Matheus Lima     |          v                  v                \      /
54*cbc4b041SBreno Matheus Lima     |    +----------+        +----------+        +----------+
55*cbc4b041SBreno Matheus Lima     |    |  U-Boot  |        |          |        |  U-Boot  |
56*cbc4b041SBreno Matheus Lima     ---> |     +    | -----> |   i.MX   | -----> |     +    |
57*cbc4b041SBreno Matheus Lima          |    CSF   |        |          |        |    CSF   |
58*cbc4b041SBreno Matheus Lima          +----------+        +----------+        +----------+
59*cbc4b041SBreno Matheus Lima
60*cbc4b041SBreno Matheus LimaThe U-Boot image to be programmed into the boot media needs to be properly
61*cbc4b041SBreno Matheus Limaconstructed i.e. it must contain a proper Command Sequence File (CSF).
62*cbc4b041SBreno Matheus Lima
63*cbc4b041SBreno Matheus LimaThe CSF is a binary data structure interpreted by the HAB to guide
64*cbc4b041SBreno Matheus Limaauthentication process, this is generated by the Code Signing Tool[1].
65*cbc4b041SBreno Matheus LimaThe CSF structure contains the commands, SRK table, signatures and
66*cbc4b041SBreno Matheus Limacertificates.
67*cbc4b041SBreno Matheus Lima
68*cbc4b041SBreno Matheus LimaDetails about the Secure Boot and Code Signing Tool (CST) can be found in
69*cbc4b041SBreno Matheus Limathe application note AN4581[2] and in the secure boot guides.
70*cbc4b041SBreno Matheus Lima
71*cbc4b041SBreno Matheus Lima1.2 The HABv4 Encrypted Boot Architecture
72*cbc4b041SBreno Matheus Lima------------------------------------------
73*cbc4b041SBreno Matheus Lima
74*cbc4b041SBreno Matheus LimaThe HAB Encrypted Boot feature available in CAAM supported devices adds an
75*cbc4b041SBreno Matheus Limaextra security operation to the bootloading sequence. It uses cryptographic
76*cbc4b041SBreno Matheus Limatechniques (AES-CCM) to obscure the U-Boot data, so it cannot be seen or used
77*cbc4b041SBreno Matheus Limaby unauthorized users. This mechanism protects the U-Boot code residing on
78*cbc4b041SBreno Matheus Limaflash or external memory and also ensures that the final image is unique
79*cbc4b041SBreno Matheus Limaper device.
80*cbc4b041SBreno Matheus Lima
81*cbc4b041SBreno Matheus LimaThe process can be divided into two protection mechanisms. The first mechanism
82*cbc4b041SBreno Matheus Limais the bootloader code encryption which provides data confidentiality and the
83*cbc4b041SBreno Matheus Limasecond mechanism is the digital signature, which authenticates the encrypted
84*cbc4b041SBreno Matheus Limaimage.
85*cbc4b041SBreno Matheus Lima
86*cbc4b041SBreno Matheus LimaKeep in mind that the encrypted boot makes use of both mechanisms whatever the
87*cbc4b041SBreno Matheus Limaorder is (sign and then encrypt, or encrypt and then sign), both operations
88*cbc4b041SBreno Matheus Limacan be applied on the same region with exception of the U-Boot Header (IVT,
89*cbc4b041SBreno Matheus Limaboot data and DCD) which can only be signed, not encrypted.
90*cbc4b041SBreno Matheus Lima
91*cbc4b041SBreno Matheus LimaThe diagram below illustrate the encrypted boot process overview:
92*cbc4b041SBreno Matheus Lima
93*cbc4b041SBreno Matheus Lima     Host PC + CST                                      i.MX + HAB
94*cbc4b041SBreno Matheus Lima     +------------+                                  +--------------+
95*cbc4b041SBreno Matheus Lima     |   U-Boot   |                                  |    U-Boot    |
96*cbc4b041SBreno Matheus Lima     +------------+                                  +--------------+
97*cbc4b041SBreno Matheus Lima            |                                                ^
98*cbc4b041SBreno Matheus Lima            |                                                |
99*cbc4b041SBreno Matheus Lima            v         DEK                            +--------------+
100*cbc4b041SBreno Matheus Lima     +------------+    |                       ----> |    Decrypt   |
101*cbc4b041SBreno Matheus Lima     |   Encrypt  | <---                       |     +--------------+
102*cbc4b041SBreno Matheus Lima     +------------+                        DEK |             ^
103*cbc4b041SBreno Matheus Lima            |                                  |             |
104*cbc4b041SBreno Matheus Lima            |       Private                    |             |
105*cbc4b041SBreno Matheus Lima            v         Key                  +------+   +--------------+
106*cbc4b041SBreno Matheus Lima     +------------+    |                   | CAAM |   | Authenticate |
107*cbc4b041SBreno Matheus Lima     |    Sign    | <---                   +------+   +--------------+
108*cbc4b041SBreno Matheus Lima     +------------+            DEK             ^             ^
109*cbc4b041SBreno Matheus Lima            |                + OTPMK       DEK  \           /  U-Boot
110*cbc4b041SBreno Matheus Lima            |                   |          Blob  \         /   + CSF
111*cbc4b041SBreno Matheus Lima            v                   v                 \       /
112*cbc4b041SBreno Matheus Lima     +------------+       +----------+          +------------+
113*cbc4b041SBreno Matheus Lima     | Enc U-Boot |       |          |          | Enc U-Boot |
114*cbc4b041SBreno Matheus Lima     |   + CSF    | ----> |   i.MX   | -------> |   + CSF    |
115*cbc4b041SBreno Matheus Lima     | + DEK Blob |       |          |          | + DEK Blob |
116*cbc4b041SBreno Matheus Lima     +------------+       +----------+          +------------+
117*cbc4b041SBreno Matheus Lima            ^                   |
118*cbc4b041SBreno Matheus Lima            |                   |
119*cbc4b041SBreno Matheus Lima            ---------------------
120*cbc4b041SBreno Matheus Lima                   DEK Blob
121*cbc4b041SBreno Matheus Lima                    (CAAM)
122*cbc4b041SBreno Matheus Lima
123*cbc4b041SBreno Matheus LimaThe Code Signing Tool automatically generates a random AES Data Encryption Key
124*cbc4b041SBreno Matheus Lima(DEK) when encrypting an image. This key is used in both encrypt and decrypt
125*cbc4b041SBreno Matheus Limaoperations and should be present in the final image structure encapsulated
126*cbc4b041SBreno Matheus Limaby a CAAM blob.
127*cbc4b041SBreno Matheus Lima
128*cbc4b041SBreno Matheus LimaThe OTP Master Key (OTPMK) is used to encrypt and wrap the DEK in a blob
129*cbc4b041SBreno Matheus Limastructure. The OTPMK is unique per device and can be accessed by CAAM only.
130*cbc4b041SBreno Matheus LimaTo further add to the security of the DEK, the blob is decapsulated and
131*cbc4b041SBreno Matheus Limadecrypted inside a secure memory partition that can only be accessed by CAAM.
132*cbc4b041SBreno Matheus Lima
133*cbc4b041SBreno Matheus LimaDuring the design of encrypted boot using DEK blob, it is necessary to inhibit
134*cbc4b041SBreno Matheus Limaany modification or replacement of DEK blob with a counterfeit one allowing
135*cbc4b041SBreno Matheus Limaexecution of malicious code. The PRIBLOB setting in CAAM allows secure boot
136*cbc4b041SBreno Matheus Limasoftware to have its own private blobs that cannot be decapsulated or
137*cbc4b041SBreno Matheus Limaencapsulated by any other user code, including any software running in trusted
138*cbc4b041SBreno Matheus Limamode.
139*cbc4b041SBreno Matheus Lima
140*cbc4b041SBreno Matheus LimaDetails about DEK Blob generation and PRIBLOB setting can be found in the
141*cbc4b041SBreno Matheus Limaencrypted boot guide and application note AN12056[3] .
142*cbc4b041SBreno Matheus Lima
143*cbc4b041SBreno Matheus Lima2. Generating a PKI tree
144*cbc4b041SBreno Matheus Lima-------------------------
145*cbc4b041SBreno Matheus Lima
146*cbc4b041SBreno Matheus LimaThe first step is to generate the private keys and public keys certificates.
147*cbc4b041SBreno Matheus LimaThe HAB architecture is based in a Public Key Infrastructure (PKI) tree.
148*cbc4b041SBreno Matheus Lima
149*cbc4b041SBreno Matheus LimaThe Code Signing Tools package contains an OpenSSL based key generation script
150*cbc4b041SBreno Matheus Limaunder keys/ directory. The hab4_pki_tree.sh script is able to generate a PKI
151*cbc4b041SBreno Matheus Limatree containing up to 4 Super Root Keys (SRK) as well as their subordinated
152*cbc4b041SBreno Matheus LimaIMG and CSF keys.
153*cbc4b041SBreno Matheus Lima
154*cbc4b041SBreno Matheus LimaA new PKI tree can be generated by following the example below:
155*cbc4b041SBreno Matheus Lima
156*cbc4b041SBreno Matheus Lima- Generating 2048-bit PKI tree on CST v3.1.0:
157*cbc4b041SBreno Matheus Lima
158*cbc4b041SBreno Matheus Lima  $ ./hab4_pki_tree.sh
159*cbc4b041SBreno Matheus Lima  ...
160*cbc4b041SBreno Matheus Lima  Do you want to use an existing CA key (y/n)?: n
161*cbc4b041SBreno Matheus Lima  Do you want to use Elliptic Curve Cryptography (y/n)?: n
162*cbc4b041SBreno Matheus Lima  Enter key length in bits for PKI tree: 2048
163*cbc4b041SBreno Matheus Lima  Enter PKI tree duration (years): 5
164*cbc4b041SBreno Matheus Lima  How many Super Root Keys should be generated? 4
165*cbc4b041SBreno Matheus Lima  Do you want the SRK certificates to have the CA flag set? (y/n)?: y
166*cbc4b041SBreno Matheus Lima
167*cbc4b041SBreno Matheus LimaThe diagram below illustrate the PKI tree:
168*cbc4b041SBreno Matheus Lima
169*cbc4b041SBreno Matheus Lima                                +---------+
170*cbc4b041SBreno Matheus Lima                                |   CA    |
171*cbc4b041SBreno Matheus Lima                                +---------+
172*cbc4b041SBreno Matheus Lima                                     |
173*cbc4b041SBreno Matheus Lima                                     |
174*cbc4b041SBreno Matheus Lima            ---------------------------------------------------
175*cbc4b041SBreno Matheus Lima            |               |                 |               |
176*cbc4b041SBreno Matheus Lima            |               |                 |               |
177*cbc4b041SBreno Matheus Lima            v               v                 v               v
178*cbc4b041SBreno Matheus Lima       +--------+       +--------+       +--------+       +--------+
179*cbc4b041SBreno Matheus Lima       |  SRK1  |       |  SRK2  |       |  SRK3  |       |  SRK4  |
180*cbc4b041SBreno Matheus Lima       +--------+       +--------+       +--------+       +--------+
181*cbc4b041SBreno Matheus Lima         /    \           /    \           /    \           /    \
182*cbc4b041SBreno Matheus Lima        v      v         v      v         v      v         v      v
183*cbc4b041SBreno Matheus Lima     +----+  +----+   +----+  +----+   +----+  +----+   +----+  +----+
184*cbc4b041SBreno Matheus Lima     |CSF1|  |IMG1|   |CSF2|  |IMG2|   |CSF3|  |IMG3|   |CSF4|  |IMG4|
185*cbc4b041SBreno Matheus Lima     +----+  +----+   +----+  +----+   +----+  +----+   +----+  +----+
186*cbc4b041SBreno Matheus Lima
187*cbc4b041SBreno Matheus LimaAfter running the script users can check the private keys under keys/ directory
188*cbc4b041SBreno Matheus Limaand their respective X.509v3 public key certificates under crts/ directory.
189*cbc4b041SBreno Matheus LimaThose files will be used during the signing and authentication process.
190*cbc4b041SBreno Matheus Lima
191*cbc4b041SBreno Matheus Lima2.1 Generating a fast authentication PKI tree
192*cbc4b041SBreno Matheus Lima----------------------------------------------
193*cbc4b041SBreno Matheus Lima
194*cbc4b041SBreno Matheus LimaStarting in HAB v4.1.2 users can use a single SRK key to authenticate the both
195*cbc4b041SBreno Matheus LimaCSF and IMG contents. This reduces the number of key pair authentications that
196*cbc4b041SBreno Matheus Limamust occur during the ROM/HAB boot stage, thus providing a faster boot process.
197*cbc4b041SBreno Matheus Lima
198*cbc4b041SBreno Matheus LimaThe script hab4_pki_tree.sh is also able to generate a Public Key Infrastructure
199*cbc4b041SBreno Matheus Lima(PKI) tree which only contains SRK Keys, users should not set the CA flag when
200*cbc4b041SBreno Matheus Limagenerating the SRK certificates.
201*cbc4b041SBreno Matheus Lima
202*cbc4b041SBreno Matheus Lima- Generating 2048-bit fast authentication PKI tree on CST v3.1.0:
203*cbc4b041SBreno Matheus Lima
204*cbc4b041SBreno Matheus Lima  $ ./hab4_pki_tree.sh
205*cbc4b041SBreno Matheus Lima  ...
206*cbc4b041SBreno Matheus Lima  Do you want to use an existing CA key (y/n)?: n
207*cbc4b041SBreno Matheus Lima  Do you want to use Elliptic Curve Cryptography (y/n)?: n
208*cbc4b041SBreno Matheus Lima  Enter key length in bits for PKI tree: 2048
209*cbc4b041SBreno Matheus Lima  Enter PKI tree duration (years): 5
210*cbc4b041SBreno Matheus Lima  How many Super Root Keys should be generated? 4
211*cbc4b041SBreno Matheus Lima  Do you want the SRK certificates to have the CA flag set? (y/n)?: n
212*cbc4b041SBreno Matheus Lima
213*cbc4b041SBreno Matheus LimaThe diagram below illustrate the PKI tree generated:
214*cbc4b041SBreno Matheus Lima
215*cbc4b041SBreno Matheus Lima                             +---------+
216*cbc4b041SBreno Matheus Lima                             |   CA    |
217*cbc4b041SBreno Matheus Lima                             +---------+
218*cbc4b041SBreno Matheus Lima                                  |
219*cbc4b041SBreno Matheus Lima                                  |
220*cbc4b041SBreno Matheus Lima         ---------------------------------------------------
221*cbc4b041SBreno Matheus Lima         |               |                 |               |
222*cbc4b041SBreno Matheus Lima         |               |                 |               |
223*cbc4b041SBreno Matheus Lima         v               v                 v               v
224*cbc4b041SBreno Matheus Lima    +--------+       +--------+       +--------+       +--------+
225*cbc4b041SBreno Matheus Lima    |  SRK1  |       |  SRK2  |       |  SRK3  |       |  SRK4  |
226*cbc4b041SBreno Matheus Lima    +--------+       +--------+       +--------+       +--------+
227*cbc4b041SBreno Matheus Lima
228*cbc4b041SBreno Matheus Lima2.2 Generating a SRK Table and SRK Hash
229*cbc4b041SBreno Matheus Lima----------------------------------------
230*cbc4b041SBreno Matheus Lima
231*cbc4b041SBreno Matheus LimaThe next step is to generated the SRK Table and its respective SRK Table Hash
232*cbc4b041SBreno Matheus Limafrom the SRK public key certificates created in one of the steps above.
233*cbc4b041SBreno Matheus Lima
234*cbc4b041SBreno Matheus LimaIn the HAB architecture, the SRK Table is included in the CSF binary and the
235*cbc4b041SBreno Matheus LimaSRK Hash is programmed in the SoC SRK_HASH[255:0] fuses.
236*cbc4b041SBreno Matheus Lima
237*cbc4b041SBreno Matheus LimaOn the target device during the authentication process the HAB code verify the
238*cbc4b041SBreno Matheus LimaSRK Table against the SoC SRK_HASH fuses, in case the verification success the
239*cbc4b041SBreno Matheus Limaroot of trust is established and the HAB code can progress with the image
240*cbc4b041SBreno Matheus Limaauthentication.
241*cbc4b041SBreno Matheus Lima
242*cbc4b041SBreno Matheus LimaThe srktool can be used for generating the SRK Table and its respective SRK
243*cbc4b041SBreno Matheus LimaTable Hash.
244*cbc4b041SBreno Matheus Lima
245*cbc4b041SBreno Matheus Lima- Generating SRK Table and SRK Hash in Linux 64-bit machines:
246*cbc4b041SBreno Matheus Lima
247*cbc4b041SBreno Matheus Lima  $ ../linux64/bin/srktool -h 4 -t SRK_1_2_3_4_table.bin -e \
248*cbc4b041SBreno Matheus Lima	SRK_1_2_3_4_fuse.bin -d sha256 -c \
249*cbc4b041SBreno Matheus Lima	SRK1_sha256_2048_65537_v3_ca_crt.pem,\
250*cbc4b041SBreno Matheus Lima	SRK2_sha256_2048_65537_v3_ca_crt.pem,\
251*cbc4b041SBreno Matheus Lima	SRK3_sha256_2048_65537_v3_ca_crt.pem,\
252*cbc4b041SBreno Matheus Lima	SRK4_sha256_2048_65537_v3_ca_crt.pem
253*cbc4b041SBreno Matheus Lima
254*cbc4b041SBreno Matheus LimaThe SRK_1_2_3_4_table.bin and SRK_1_2_3_4_fuse.bin files can be used in further
255*cbc4b041SBreno Matheus Limasteps as explained in HAB guides available under doc/imx/habv4/guides/
256*cbc4b041SBreno Matheus Limadirectory.
257*cbc4b041SBreno Matheus Lima
258*cbc4b041SBreno Matheus LimaReferences:
259*cbc4b041SBreno Matheus Lima[1] CST: i.MX High Assurance Boot Reference Code Signing Tool.
260*cbc4b041SBreno Matheus Lima[2] AN4581: "Secure Boot on i.MX 50, i.MX 53, i.MX 6 and i.MX 7 Series using
261*cbc4b041SBreno Matheus Lima HABv4" - Rev 2.
262*cbc4b041SBreno Matheus Lima[3] AN12056: "Encrypted Boot on HABv4 and CAAM Enabled Devices" - Rev. 1
263