2121#include "sw/device/silicon_creator/lib/boot_svc/boot_svc_header.h"
2222#include "sw/device/silicon_creator/lib/boot_svc/boot_svc_msg.h"
2323#include "sw/device/silicon_creator/lib/dbg_print.h"
24+ #include "sw/device/silicon_creator/lib/dice.h"
2425#include "sw/device/silicon_creator/lib/drivers/ast.h"
2526#include "sw/device/silicon_creator/lib/drivers/flash_ctrl.h"
2627#include "sw/device/silicon_creator/lib/drivers/hmac.h"
@@ -207,12 +208,14 @@ static rom_error_t rom_ext_verify(const manifest_t *manifest,
207208 lc_state , & flash_exec );
208209}
209210
210- /* These symbols are defined in
211+ /**
212+ * These symbols are defined in
211213 * `opentitan/sw/device/silicon_creator/rom_ext/rom_ext.ld`, and describe the
212214 * location of the flash header.
213215 */
214216extern char _owner_virtual_start_address [];
215217extern char _owner_virtual_size [];
218+
216219/**
217220 * Compute the virtual address corresponding to the physical address `lma_addr`.
218221 *
@@ -227,79 +230,72 @@ static uintptr_t owner_vma_get(const manifest_t *manifest, uintptr_t lma_addr) {
227230}
228231
229232OT_WARN_UNUSED_RESULT
230- static rom_error_t rom_ext_attestation_keygen (const manifest_t * manifest ) {
233+ static rom_error_t rom_ext_attestation_keygen (
234+ const manifest_t * owner_manifest ) {
231235 attestation_public_key_t curr_attestation_pubkey = {.x = {0 }, .y = {0 }};
236+ hmac_digest_t curr_attestation_key_id = {.digest = {0 }};
237+
238+ // Configure certificate flash info pages.
239+ flash_ctrl_cert_info_pages_creator_cfg ();
232240
233- // Initialize the entropy complex for key manager operations.
241+ // Initialize the entropy complex and KMAC for key manager operations.
234242 // Note: `OTCRYPTO_OK.value` is equal to `kErrorOk` but we cannot add a static
235243 // assertion here since its definition is not an integer constant expression.
236244 HARDENED_RETURN_IF_ERROR ((rom_error_t )entropy_complex_init ().value );
237-
238- // Initialize KMAC for key manager operations.
239245 HARDENED_RETURN_IF_ERROR (kmac_keymgr_configure ());
240246
241- // Load OTBN attestation keygen program.
242- HARDENED_RETURN_IF_ERROR (otbn_boot_app_load ());
243-
244247 // ROM sets the SW binding values for the first key stage (CreatorRootKey) but
245248 // does not initialize the key manager. Advance key manager state twice to
246249 // transition to the creator root key state.
250+ HARDENED_RETURN_IF_ERROR (keymgr_state_check (kKeymgrStateReset ));
247251 keymgr_advance_state ();
248252 HARDENED_RETURN_IF_ERROR (keymgr_state_check (kKeymgrStateInit ));
249- keymgr_advance_state ();
250- HARDENED_RETURN_IF_ERROR (keymgr_state_check (kKeymgrStateCreatorRootKey ));
251253
252- // Generate UDS attestation keys.
253- HARDENED_RETURN_IF_ERROR (otbn_boot_attestation_keygen (
254- kUdsAttestationKeySeed , kUdsKeymgrDiversifier , & curr_attestation_pubkey ));
255- // TODO(#19588): check UDS public key matches that in UDS cert.
254+ // Load OTBN attestation keygen program.
255+ // TODO(#21550): this should already be loaded by the ROM.
256+ HARDENED_RETURN_IF_ERROR (otbn_boot_app_load ());
257+
258+ // Generate UDS keys.
259+ keymgr_advance_state ();
260+ HARDENED_RETURN_IF_ERROR (dice_attestation_keygen (
261+ kDiceKeyUds , & curr_attestation_key_id , & curr_attestation_pubkey ));
256262 HARDENED_RETURN_IF_ERROR (otbn_boot_attestation_key_save (
257263 kUdsAttestationKeySeed , kUdsKeymgrDiversifier ));
264+ // TODO(#19588): check UDS key ID matches that in the UDS cert.
258265
259- // Advance keymgr to OwnerIntermediate stage (root of Sealing_0 and CDI_0).
260- keymgr_sw_binding_unlock_wait ();
261- // We set the sealing binding value to all 0s, as sealing keys are not
262- // currently used at the ROM_EXT stage. For the attestation binding value, we
263- // use the ROM_EXT measurement preloaded in `static_critical` section by ROM.
266+ // Generate CDI_0 keys.
264267 keymgr_binding_value_t zero_binding_value = {.data = {0 }};
265- keymgr_sw_binding_set (
266- /*binding_value_sealing=*/ & zero_binding_value ,
267- /*binding_value_attestation=*/ & boot_measurements .rom_ext );
268268 const manifest_t * rom_ext_manifest =
269269 (const manifest_t * )_rom_ext_start_address ;
270- keymgr_owner_int_max_ver_set (rom_ext_manifest -> max_key_version );
271270 SEC_MMIO_WRITE_INCREMENT (kKeymgrSecMmioSwBindingSet +
272271 kKeymgrSecMmioOwnerIntMaxVerSet );
273- keymgr_advance_state ();
274272 HARDENED_RETURN_IF_ERROR (
275- keymgr_state_check (kKeymgrStateOwnerIntermediateKey ));
276-
277- // Generate CDI_0 attestation keys.
278- HARDENED_RETURN_IF_ERROR (otbn_boot_attestation_keygen (
279- kCdi0AttestationKeySeed , kCdi0KeymgrDiversifier ,
280- & curr_attestation_pubkey ));
281- // TODO(#19588): check ROM_EXT measurement / CDI_0 public key matches that in
282- // CDI_0 cert. If not, update the cert and endorse it.
273+ keymgr_owner_int_advance (/*sealing_binding=*/ & zero_binding_value ,
274+ /*attest_binding=*/ & boot_measurements .rom_ext ,
275+ rom_ext_manifest -> max_key_version ));
276+ HARDENED_RETURN_IF_ERROR (dice_attestation_keygen (
277+ kDiceKeyCdi0 , & curr_attestation_key_id , & curr_attestation_pubkey ));
278+ // TODO(#19588): check the CDI_0 key ID matches that in the CDI_0 cert. If
279+ // not, update the cert.
283280 HARDENED_RETURN_IF_ERROR (otbn_boot_attestation_key_save (
284281 kCdi0AttestationKeySeed , kCdi0KeymgrDiversifier ));
285282
286- // Advance keymgr to Owner stage (root of Sealing_1 and CDI_1).
287- // TODO(ttrippel): Put the real BL0 measurement in here.
288- keymgr_sw_binding_unlock_wait ();
289- keymgr_sw_binding_set (/*binding_value_sealing=*/ & manifest -> binding_value ,
290- /*binding_value_attestation=*/ & zero_binding_value );
291- keymgr_owner_max_ver_set (manifest -> max_key_version );
292- SEC_MMIO_WRITE_INCREMENT (kKeymgrSecMmioSwBindingSet +
293- kKeymgrSecMmioOwnerMaxVerSet );
294- keymgr_advance_state ();
295- HARDENED_RETURN_IF_ERROR (keymgr_state_check (kKeymgrStateOwnerKey ));
296-
297283 // Generate CDI_1 attestation keys.
284+ SEC_MMIO_WRITE_INCREMENT (kKeymgrSecMmioSwBindingSet +
285+ kKeymgrSecMmioOwnerIntMaxVerSet );
286+ // TODO(cfrantz): setup sealing binding to value specified in owner
287+ // configuration block.
288+ // TODO(timothytrippel): setup attestation key binding value manually since
289+ // static_critical section on ES silicon does not contain the Owner firmware
290+ // measurement.
291+ HARDENED_RETURN_IF_ERROR (keymgr_owner_advance (
292+ /*sealing_binding=*/ & zero_binding_value ,
293+ /*attest_binding=*/ & zero_binding_value , owner_manifest -> max_key_version ));
298294 HARDENED_RETURN_IF_ERROR (otbn_boot_attestation_keygen (
299295 kCdi1AttestationKeySeed , kCdi1KeymgrDiversifier ,
300296 & curr_attestation_pubkey ));
301- // TODO(#19588): check ROM_EXT measurement / CDI_1 public key matches that in
302- // CDI_1 cert. If not, update the cert and endorse it .
297+ // TODO(#19588): check the CDI_1 key ID matches that in the CDI_1 cert. If
298+ // not, update the cert.
303299 HARDENED_RETURN_IF_ERROR (otbn_boot_attestation_key_save (
304300 kCdi1AttestationKeySeed , kCdi1KeymgrDiversifier ));
305301
0 commit comments