chipsalliance / caliptra-sw

Caliptra software (ROM, FMC, runtime firmware), and libraries/tools needed to build and test
Apache License 2.0
53 stars 39 forks source link

RT Cert obtained from the sw-emulator is inconsistent with that on verilator #1520

Closed LuiSzee closed 3 months ago

LuiSzee commented 4 months ago

Hello, I am doing the fmc::test_hand_off test and found that the RT Cert obtained from the sw-emulator is inconsistent with that on verilator. Before conducting the test, I made the following modifications in order to ensure that the Caliptra Image remains consistent throughout multiple runs. Additionally, I have printed the tci value.

diff --git a/fmc/src/flow/rt_alias.rs b/fmc/src/flow/rt_alias.rs
index 404925dd..e614a77f 100644
--- a/fmc/src/flow/rt_alias.rs
+++ b/fmc/src/flow/rt_alias.rs
@@ -251,6 +251,8 @@ impl RtAliasLayer {
         let image_manifest_digest: [u8; 48] = okref(&image_manifest_digest)?.into();
         tci[SHA384_HASH_SIZE..2 * SHA384_HASH_SIZE].copy_from_slice(&image_manifest_digest);

+        cprintln!("[tci] {}", HexBytes(&tci));
+
         // Permute CDI from FMC TCI
         Crypto::hmac384_kdf(env, fmc_cdi, b"rt_alias_cdi", Some(&tci), rt_cdi)?;
         report_boot_status(FmcBootStatus::RtAliasDeriveCdiComplete as u32);
diff --git a/fmc/tests/fmc_integration_tests/test_hand_off.rs b/fmc/tests/fmc_integration_tests/test_hand_off.rs
index c6407328..b4c73f29 100644
--- a/fmc/tests/fmc_integration_tests/test_hand_off.rs
+++ b/fmc/tests/fmc_integration_tests/test_hand_off.rs
@@ -1,24 +1,31 @@
 // Licensed under the Apache-2.0 license
 use caliptra_builder::{firmware, ImageOptions};
 use caliptra_hw_model::{BootParams, HwModel, InitParams};
+use std::fs;

 #[test]
 fn test_hand_off() {
     let rom = caliptra_builder::rom_for_fw_integration_tests().unwrap();

-    let image = caliptra_builder::build_and_sign_image(
-        &firmware::FMC_WITH_UART,
-        &firmware::runtime_tests::BOOT,
-        ImageOptions::default(),
-    )
-    .unwrap();
+    //  let image = caliptra_builder::build_and_sign_image(
+    //      &firmware::FMC_WITH_UART,
+    //      &firmware::runtime_tests::BOOT,
+    //      ImageOptions::default(),
+    //  )
+    //  .unwrap();
+
+    //  //println!("{:?}", &image.to_bytes().unwrap());
+    let filename = "/tmp/tmp.bin";
+    //  fs::write(filename, &image.to_bytes().unwrap()).unwrap();
+
+    let read_bytes = fs::read(filename).unwrap();

     let mut hw = caliptra_hw_model::new(BootParams {
         init_params: InitParams {
             rom: &rom,
             ..Default::default()
         },
-        fw_image: Some(&image.to_bytes().unwrap()),
+        fw_image: Some(&read_bytes),
         ..Default::default()
     })
     .unwrap();
diff --git a/kat/src/lms_kat.rs b/kat/src/lms_kat.rs
index 10a0b368..6857a00a 100644
--- a/kat/src/lms_kat.rs
+++ b/kat/src/lms_kat.rs
@@ -332,9 +332,10 @@ impl LmsKat {

         let success =
             lms.verify_lms_signature(sha256_driver, &MESSAGE, &LMS_PUBLIC_KEY, &LMS_SIG)?;
-        if success != LmsResult::Success {
-            Err(CaliptraError::KAT_LMS_DIGEST_MISMATCH)?;
-        }
+        // if success != LmsResult::Success {
+        //     Err(CaliptraError::KAT_LMS_DIGEST_MISMATCH)?;
+        //     Ok(())
+        // }

         Ok(())
     }

When running for the first time, I used the command "cargo test --package caliptra-fmc --test fmc_integration_tests -- test_hand_off::test_hand_off --exact --nocapture" And I got RT Cert:

  1,980,186 UART: [alias rt] PUB.X = EB4C79EDC32F51B12BA48DA9159A4F0020C830BC6378C38D7A451275B624B2BCE039AC7D79E6FEE5535AED2E8D4172AD
  1,987,029 UART: [alias rt] PUB.Y = 46B892A65906A423E592D1ED05310EFC8D30D31ACFDD81F28B73B3BA328F0722C080CEC12245C68ED0951959B1F901F0
  1,994,048 UART: [alias rt] SIG.R = ED2C4FFDE5B498CED5F06FDB44395082486A7F6FA1077C223971BE8E12245B596523762F55A8E62DDAE027CB74713952
  2,000,899 UART: [alias rt] SIG.S = 0A8DEC2558D21940E40764195E3087AEFCD35CD2EB411F3005B05DFC0230578668E5F0A8B2CCB471FA9EC69A1EB5CA75

When running for the second time, I made modifications to the "sw-emulator/lib/crypto/src/hmac512.rs" by renaming the "update" function to "orig_update" and calling it in the "init" function. I also implemented an empty function for the original "update" function, so that the sw-emulator only processes the first block.

diff --git a/sw-emulator/lib/crypto/src/hmac512.rs b/sw-emulator/lib/crypto/src/hmac512.rs
index bbb08052..fbad45c0 100644
--- a/sw-emulator/lib/crypto/src/hmac512.rs
+++ b/sw-emulator/lib/crypto/src/hmac512.rs
@@ -129,7 +129,7 @@ impl<const KEY_SIZE: usize> Hmac512<KEY_SIZE> {
         self.hash1.update(&ipad);

         // Hash the block
-        self.update(block);
+        self.orig_update(block);
     }

     /// Update the MAC with the block
@@ -137,7 +137,7 @@ impl<const KEY_SIZE: usize> Hmac512<KEY_SIZE> {
     /// # Arguments
     ///
     /// * `block` - Block to calculate MAC over
-    pub fn update(&mut self, block: &[u8; BLOCK_SIZE]) {
+    pub fn orig_update(&mut self, block: &[u8; BLOCK_SIZE]) {
         // hash the block
         self.hash1.update(block);

@@ -174,6 +174,15 @@ impl<const KEY_SIZE: usize> Hmac512<KEY_SIZE> {
         self.hash2.update(&sum_block);
     }

+    /// Update the MAC with the block
+    ///
+    /// # Arguments
+    ///
+    /// * `block` - Block to calculate MAC over
+    pub fn update(&mut self, block: &[u8; BLOCK_SIZE]) {
+
+    }
+
     /// Retrieve the tag
     ///
     /// # Arguments

And I got RT Cert:

  1,979,448 UART: [alias rt] PUB.X = 988DF52D19CC213D142F4407C67EEC9257934A45F9312681496970FED206CE035DA841CC523954562C2F06FCE82847AD
  1,986,281 UART: [alias rt] PUB.Y = A2B7C2E885F02E91EB8D51C38FBB117AB29287A1C6296BD047EFEE0724D6FFAF282407C6E320A41DC69C7456B0B7E6FC
  1,993,321 UART: [alias rt] SIG.R = 2C8EB816F05BC5733C4DCF7493CDA41A938CCC29D6186A66A2DF54BAE8B04FCE35DD7CD08870B74DD32EA6B2917E282C
  2,000,191 UART: [alias rt] SIG.S = B7569FCF8B93EF57FC0EDAFAED490EDB502ACFE8DBDF4F7707D8799FAA4F3B0D86951BF7C4EF06DE3DD651F3EDB85F07

On the third run, I used "cargo test --features=verilator --package caliptra-fmc --test fmc_integration_tests -- test_hand_off::test_hand_off --exact --nocapture". ran the same case using verilator. And I got RT Cert:

 26,864,404 UART: [alias rt] PUB.X = 988DF52D19CC213D142F4407C67EEC9257934A45F9312681496970FED206CE035DA841CC523954562C2F06FCE82847AD
 26,871,802 UART: [alias rt] PUB.Y = A2B7C2E885F02E91EB8D51C38FBB117AB29287A1C6296BD047EFEE0724D6FFAF282407C6E320A41DC69C7456B0B7E6FC
 26,879,414 UART: [alias rt] SIG.R = 2C8EB816F05BC5733C4DCF7493CDA41A938CCC29D6186A66A2DF54BAE8B04FCE35DD7CD08870B74DD32EA6B2917E282C
 26,886,852 UART: [alias rt] SIG.S = B7569FCF8B93EF57FC0EDAFAED490EDB502ACFE8DBDF4F7707D8799FAA4F3B0D86951BF7C4EF06DE3DD651F3EDB85F07

The result is the same as the second time, but the second time I ran the modified sw-emulator code, and the hmac only processed the first block. Therefore, I suspect that there may be a problem with the key vault-related code in the caliptra-rtl hmac, and I raised an issue: https://github.com/chipsalliance/caliptra-rtl/issues/515 At the same time, I checked the code of the sw-emulator, and personally, I think there is no problem with the implementation of hmac512.rs in the sw-emulator. Please help confirm whether the inconsistency here is caused by an error in the implementation of sw-emulator in caliptra-sw or an error in the implementation of caliptra-rtl. Thank you.

My Full log:

root@vultr:~/caliptra-sw# git diff
diff --git a/fmc/src/flow/rt_alias.rs b/fmc/src/flow/rt_alias.rs
index 404925dd..e614a77f 100644
--- a/fmc/src/flow/rt_alias.rs
+++ b/fmc/src/flow/rt_alias.rs
@@ -251,6 +251,8 @@ impl RtAliasLayer {
         let image_manifest_digest: [u8; 48] = okref(&image_manifest_digest)?.into();
         tci[SHA384_HASH_SIZE..2 * SHA384_HASH_SIZE].copy_from_slice(&image_manifest_digest);

+        cprintln!("[tci] {}", HexBytes(&tci));
+
         // Permute CDI from FMC TCI
         Crypto::hmac384_kdf(env, fmc_cdi, b"rt_alias_cdi", Some(&tci), rt_cdi)?;
         report_boot_status(FmcBootStatus::RtAliasDeriveCdiComplete as u32);
diff --git a/fmc/tests/fmc_integration_tests/test_hand_off.rs b/fmc/tests/fmc_integration_tests/test_hand_off.rs
index c6407328..b4c73f29 100644
--- a/fmc/tests/fmc_integration_tests/test_hand_off.rs
+++ b/fmc/tests/fmc_integration_tests/test_hand_off.rs
@@ -1,24 +1,31 @@
 // Licensed under the Apache-2.0 license
 use caliptra_builder::{firmware, ImageOptions};
 use caliptra_hw_model::{BootParams, HwModel, InitParams};
+use std::fs;

 #[test]
 fn test_hand_off() {
     let rom = caliptra_builder::rom_for_fw_integration_tests().unwrap();

-    let image = caliptra_builder::build_and_sign_image(
-        &firmware::FMC_WITH_UART,
-        &firmware::runtime_tests::BOOT,
-        ImageOptions::default(),
-    )
-    .unwrap();
+    //  let image = caliptra_builder::build_and_sign_image(
+    //      &firmware::FMC_WITH_UART,
+    //      &firmware::runtime_tests::BOOT,
+    //      ImageOptions::default(),
+    //  )
+    //  .unwrap();
+
+    //  //println!("{:?}", &image.to_bytes().unwrap());
+    let filename = "/tmp/tmp.bin";
+    //  fs::write(filename, &image.to_bytes().unwrap()).unwrap();
+
+    let read_bytes = fs::read(filename).unwrap();

     let mut hw = caliptra_hw_model::new(BootParams {
         init_params: InitParams {
             rom: &rom,
             ..Default::default()
         },
-        fw_image: Some(&image.to_bytes().unwrap()),
+        fw_image: Some(&read_bytes),
         ..Default::default()
     })
     .unwrap();
diff --git a/kat/src/lms_kat.rs b/kat/src/lms_kat.rs
index 10a0b368..6857a00a 100644
--- a/kat/src/lms_kat.rs
+++ b/kat/src/lms_kat.rs
@@ -332,9 +332,10 @@ impl LmsKat {

         let success =
             lms.verify_lms_signature(sha256_driver, &MESSAGE, &LMS_PUBLIC_KEY, &LMS_SIG)?;
-        if success != LmsResult::Success {
-            Err(CaliptraError::KAT_LMS_DIGEST_MISMATCH)?;
-        }
+        // if success != LmsResult::Success {
+        //     Err(CaliptraError::KAT_LMS_DIGEST_MISMATCH)?;
+        //     Ok(())
+        // }

         Ok(())
     }
root@vultr:~/caliptra-sw# cat hmac512.patch
diff --git a/sw-emulator/lib/crypto/src/hmac512.rs b/sw-emulator/lib/crypto/src/hmac512.rs
index bbb08052..fbad45c0 100644
--- a/sw-emulator/lib/crypto/src/hmac512.rs
+++ b/sw-emulator/lib/crypto/src/hmac512.rs
@@ -129,7 +129,7 @@ impl<const KEY_SIZE: usize> Hmac512<KEY_SIZE> {
         self.hash1.update(&ipad);

         // Hash the block
-        self.update(block);
+        self.orig_update(block);
     }

     /// Update the MAC with the block
@@ -137,7 +137,7 @@ impl<const KEY_SIZE: usize> Hmac512<KEY_SIZE> {
     /// # Arguments
     ///
     /// * `block` - Block to calculate MAC over
-    pub fn update(&mut self, block: &[u8; BLOCK_SIZE]) {
+    pub fn orig_update(&mut self, block: &[u8; BLOCK_SIZE]) {
         // hash the block
         self.hash1.update(block);

@@ -174,6 +174,15 @@ impl<const KEY_SIZE: usize> Hmac512<KEY_SIZE> {
         self.hash2.update(&sum_block);
     }

+    /// Update the MAC with the block
+    ///
+    /// # Arguments
+    ///
+    /// * `block` - Block to calculate MAC over
+    pub fn update(&mut self, block: &[u8; BLOCK_SIZE]) {
+
+    }
+
     /// Retrieve the tag
     ///
     /// # Arguments
root@vultr:~/caliptra-sw# cargo test --package caliptra-fmc --test fmc_integration_tests -- test_hand_off::test_hand_off --exact --nocapture
   Compiling caliptra-runtime v0.1.0 (/root/caliptra-sw/runtime)
warning: unused imports: `CaliptraError`, `LmsResult`
  --> kat/src/lms_kat.rs:15:24
   |
15 | use caliptra_drivers::{CaliptraError, CaliptraResult, Lms, LmsResult, Sha256};
   |                        ^^^^^^^^^^^^^                       ^^^^^^^^^
   |
   = note: `#[warn(unused_imports)]` on by default

warning: unused variable: `success`
   --> kat/src/lms_kat.rs:333:13
    |
333 |         let success =
    |             ^^^^^^^ help: if this is intentional, prefix it with an underscore: `_success`
    |
    = note: `#[warn(unused_variables)]` on by default

warning: `caliptra-kat` (lib) generated 2 warnings (run `cargo fix --lib -p caliptra-kat` to apply 2 suggestions)
   Compiling caliptra-test v0.1.0 (/root/caliptra-sw/test)
   Compiling caliptra-fmc v0.1.0 (/root/caliptra-sw/fmc)
warning: unused imports: `ImageOptions`, `firmware`
 --> fmc/tests/fmc_integration_tests/test_hand_off.rs:2:24
  |
2 | use caliptra_builder::{firmware, ImageOptions};
  |                        ^^^^^^^^  ^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: `caliptra-fmc` (test "fmc_integration_tests") generated 1 warning (run `cargo fix --test "fmc_integration_tests"` to apply 1 suggestion)
    Finished test [unoptimized + debuginfo] target(s) in 5.49s
     Running tests/fmc_integration_tests/main.rs (target/debug/deps/fmc_integration_tests-d58d11e10fa07e3f)

running 1 test
warning: unknown feature specified for `-Ctarget-feature`: `unaligned-scalar-mem`
  |
  = note: it is still passed through to the codegen backend
  = help: consider filing a feature request

warning: unused imports: `CaliptraError`, `LmsResult`
  --> kat/src/lms_kat.rs:15:24
   |
15 | use caliptra_drivers::{CaliptraError, CaliptraResult, Lms, LmsResult, Sha256};
   |                        ^^^^^^^^^^^^^                       ^^^^^^^^^
   |
   = note: `#[warn(unused_imports)]` on by default

warning: unused variable: `success`
   --> kat/src/lms_kat.rs:333:13
    |
333 |         let success =
    |             ^^^^^^^ help: if this is intentional, prefix it with an underscore: `_success`
    |
    = note: `#[warn(unused_variables)]` on by default

Using hardware-model ModelEmulated trng=External hw_rev_id={cptra_generation=0x0001, soc_stepping_id=0000}
InitParamsSummary {
    rom_sha384: "788f6e3c6092b22fcf56538d836450e3c332609c98a10fcb990a93bc4cf698cb822562d82da61f01d8fb7eab05d664d8",
    obf_key: [0xa0a1a2a3, 0xb0b1b2b3, 0xc0c1c2c3, 0xd0d1d2d3, 0xe0e1e2e3, 0xf0f1f2f3, 0xa4a5a6a7, 0xb4b5b6b7],
    security_state: SecurityState {
        debug_locked: false,
        device_lifecycle: Unprovisioned,
    },
}
Initializing fuses: Fuses {
    uds_seed: [0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f, 0x10111213, 0x14151617, 0x18191a1b, 0x1c1d1e1f, 0x20212223, 0x24252627, 0x28292a2b, 0x2c2d2e2f],
    field_entropy: [0x80818283, 0x84858687, 0x88898a8b, 0x8c8d8e8f, 0x90919293, 0x94959697, 0x98999a9b, 0x9c9d9e9f],
    key_manifest_pk_hash: [0x00000000; 12],
    key_manifest_pk_hash_mask: X0,
    owner_pk_hash: [0x00000000; 12],
    fmc_key_manifest_svn: 0x0,
    runtime_svn: [0x00000000; 4],
    anti_rollback_disable: false,
    idevid_cert_attr: [0x00000000; 24],
    idevid_manuf_hsm_id: [0x00000000; 4],
    life_cycle: Unprovisioned,
    lms_verify: false,
    fuse_lms_revocation: 0x0,
    soc_stepping_id: 0x0,
}
          0 writing to cptra_bootfsm_go
     82,032 UART:
     82,048 UART: Running Caliptra ROM ...
     82,456 UART:
     82,510 UART: [state] CFI Enabled
     85,352 UART: [state] LifecycleState = Unprovisioned
     86,007 UART: [state] DebugLocked = No
     86,713 UART: [state] Watchdog Timer is not started because the device is not locked for debugging
     88,388 UART: [kat] SHA2-256
    882,187 UART: ROM Digest: 5125362734CA12D5E4339E70AD8BA0A598F957E7E1F9FC8DD937310244387FA7
    886,312 UART: [kat] ++
    886,464 UART: [kat] sha1
    890,798 UART: [kat] SHA2-256
    892,737 UART: [kat] SHA2-384
    895,482 UART: [kat] SHA2-384-ACC
    897,251 UART: [kat] ECC-384
    902,692 UART: [kat] HMAC-384Kdf
    907,280 UART: [kat] LMS
  1,155,506 UART: [kat] --
  1,156,576 UART: [cold-reset] ++
  1,157,002 UART: [fht] Storing FHT @ 0x50003400
  1,159,965 UART: [idev] ++
  1,160,133 UART: [idev] CDI.KEYID = 6
  1,160,493 UART: [idev] SUBJECT.KEYID = 7
  1,160,917 UART: [idev] UDS.KEYID = 0
  1,161,262 ready_for_fw is high
  1,161,262 <<< Executing mbox cmd 0x46574c44 (28224 bytes) from SoC
  1,168,802 UART: [idev] Erasing UDS.KEYID = 0
  1,185,436 UART: [idev] Using Sha1 for KeyId Algorithm
  1,194,138 UART: [idev] --
  1,195,215 UART: [ldev] ++
  1,195,383 UART: [ldev] CDI.KEYID = 6
  1,195,746 UART: [ldev] SUBJECT.KEYID = 5
  1,196,172 UART: [ldev] AUTHORITY.KEYID = 7
  1,196,635 UART: [ldev] FE.KEYID = 1
  1,201,556 UART: [ldev] Erasing FE.KEYID = 1
  1,227,429 UART: [ldev] Signing Cert with AUTHORITY.KEYID = 7
  1,241,030 UART: [ldev] PUB.X = 504D38CA45D997901F48BA333A149A2FB2668B973AAC64D3B79ECC09A663F02ED2FABA133F5FA499677AEB7687C99B25
  1,246,746 UART: [ldev] PUB.Y = A5CD31125698B3322C086E4398A591946BF20A3ECEA8EB7D7C23410D49FA877E7ECFBE47BD883BD53D7DA865AC217F1D
  1,252,637 UART: [ldev] SIG.R = 9E51FC1FAF9F983A37AD9A33FDB3D96CC41126EDFB2EE0BD656C06A20630F7AB6C54769D2F722B4B8088EE01D6CD5710
  1,258,349 UART: [ldev] SIG.S = FC434A98116613BD7A84F734130980C2D552AC2F50544668B5ACE6D7135456D48FA3BED2387A2A26F6449C41B5D86AD0
  1,265,413 UART: [ldev] --
  1,266,896 UART: [fwproc] Waiting for Commands...
  1,267,687 UART: [fwproc] Received command 0x46574c44
  1,268,478 UART: [fwproc] Received Image of size 28224 bytes
  1,579,913 UART: [fwproc] Image verified using Vendor ECC Key Index 0
  1,606,903 UART: [fwproc] Loading FMC at address 0x40000000 len 16392
  1,632,643 UART: [fwproc] Loading Runtime at address 0x40005000 len 5948
  1,642,914 >>> mbox cmd response: success
  1,644,052 UART: [afmc] ++
  1,644,220 UART: [afmc] CDI.KEYID = 6
  1,644,582 UART: [afmc] SUBJECT.KEYID = 7
  1,645,007 UART: [afmc] AUTHORITY.KEYID = 5
  1,680,354 UART: [afmc] Signing Cert with AUTHORITY.KEYID = 5
  1,696,620 UART: [afmc] Erasing AUTHORITY.KEYID = 5
  1,697,400 UART: [afmc] PUB.X = 95A79B1122062EA4C6EBD0FAF0BF6B2C50F339722CA88984131A8D11F03F9D65D65D17D8E6477A0EBA7ABD9EAEFF6A1C
  1,703,118 UART: [afmc] PUB.Y = F8C810CB1362092082DBA839F653417F76A350F6CD0B06931D198D7B9DFE32BB4558444CA7331667D5B1043D425DA2A0
  1,708,998 UART: [afmc] SIG.R = 7198EB1EEFCD59F558258F4BEFEF12B86C67F458FF22FB14B1B9A4C263B705A2C7E220BB6622FA5643DB2C405BB5C0C0
  1,714,716 UART: [afmc] SIG.S = 633846D15C201F05ADF28EE2E2BB51F1A4918347CACD9A8D7ACB65EA1C5AFA88322356319264D82FA86B7F5CEC68625C
  1,722,540 UART: [afmc] --
  1,723,424 UART: [cold-reset] --
  1,724,234 UART: [state] Locking Datavault
  1,725,201 UART: [state] Locking PCR0, PCR1 and PCR31
  1,725,805 UART: [state] Locking ICCM
  1,726,281 UART: [exit] Launching FMC @ 0x40000130
  1,731,603 UART:
  1,731,619 UART: Running Caliptra FMC ...
  1,732,027 UART:
  1,732,081 UART: [state] CFI Enabled
  1,734,567 UART: [alias rt] Extend RT PCRs
  1,823,396 UART: [alias rt] Extend RT PCRs Done
  1,823,900 UART: [alias rt] Lock RT PCRs
  1,824,296 UART: [alias rt] Lock RT PCRs Done
  1,824,768 UART: [alias rt] Populate DV
  1,826,314 UART: [alias rt] Populate DV Done
  1,834,637 UART: [fht] Handoff : FMC CDI: 6
  1,835,126 UART: [fht] FMC Alias Private Key: 7
  1,836,219 UART: [alias rt] Derive CDI
  1,836,579 UART: [alias rt] Store in in slot 0x4
  1,915,087 UART: [tci] 39B634DCBCA634876A8C53D4DD15A752C9E60E13EB8464F45E0512093F38C3CE04F1E33B3DCBB19902B3FB4F45A729B0E8EC7492CF95F4D9A5167F2C591C995ED187DA3D41BEF5188E88368ABC7DD2F2716A3D5BBFA22CDFFAA30C83A52E288A
  1,934,806 UART: [alias rt] Derive Key Pair
  1,935,246 UART: [alias rt] Store priv key in slot 0x5
  1,948,250 UART: [alias rt] Derive Key Pair - Done
  1,963,858 UART: [alias rt] Signing Cert with AUTHO
  1,964,418 UART:             RITY.KEYID = 7
  1,979,343 UART: [alias rt] Erasing AUTHORITY.KEYID = 7
  1,980,186 UART: [alias rt] PUB.X = EB4C79EDC32F51B12BA48DA9159A4F0020C830BC6378C38D7A451275B624B2BCE039AC7D79E6FEE5535AED2E8D4172AD
  1,987,029 UART: [alias rt] PUB.Y = 46B892A65906A423E592D1ED05310EFC8D30D31ACFDD81F28B73B3BA328F0722C080CEC12245C68ED0951959B1F901F0
  1,994,048 UART: [alias rt] SIG.R = ED2C4FFDE5B498CED5F06FDB44395082486A7F6FA1077C223971BE8E12245B596523762F55A8E62DDAE027CB74713952
  2,000,899 UART: [alias rt] SIG.S = 0A8DEC2558D21940E40764195E3087AEFCD35CD2EB411F3005B05DFC0230578668E5F0A8B2CCB471FA9EC69A1EB5CA75
  2,024,842 UART: boot::test_boot...    [ok]
* TESTCASE PASSED
test test_hand_off::test_hand_off ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 4 filtered out; finished in 2.26s

root@vultr:~/caliptra-sw# patch -p1 < hmac512.patch
patching file sw-emulator/lib/crypto/src/hmac512.rs
root@vultr:~/caliptra-sw# cargo test --package caliptra-fmc --test fmc_integration_tests -- test_hand_off::test_hand_off --exact --nocapture
   Compiling caliptra-emu-crypto v0.1.0 (/root/caliptra-sw/sw-emulator/lib/crypto)
   Compiling caliptra-runtime v0.1.0 (/root/caliptra-sw/runtime)
warning: unused imports: `CaliptraError`, `LmsResult`
  --> kat/src/lms_kat.rs:15:24
   |
15 | use caliptra_drivers::{CaliptraError, CaliptraResult, Lms, LmsResult, Sha256};
   |                        ^^^^^^^^^^^^^                       ^^^^^^^^^
   |
   = note: `#[warn(unused_imports)]` on by default

warning: unused variable: `success`
   --> kat/src/lms_kat.rs:333:13
    |
333 |         let success =
    |             ^^^^^^^ help: if this is intentional, prefix it with an underscore: `_success`
    |
    = note: `#[warn(unused_variables)]` on by default

warning: `caliptra-kat` (lib) generated 2 warnings (run `cargo fix --lib -p caliptra-kat` to apply 2 suggestions)
warning: unused variable: `block`
   --> sw-emulator/lib/crypto/src/hmac512.rs:182:30
    |
182 |     pub fn update(&mut self, block: &[u8; BLOCK_SIZE]) {
    |                              ^^^^^ help: if this is intentional, prefix it with an underscore: `_block`
    |
    = note: `#[warn(unused_variables)]` on by default

warning: `caliptra-emu-crypto` (lib) generated 1 warning (run `cargo fix --lib -p caliptra-emu-crypto` to apply 1 suggestion)
   Compiling caliptra-emu-periph v0.1.0 (/root/caliptra-sw/sw-emulator/lib/periph)
   Compiling caliptra-hw-model v0.1.0 (/root/caliptra-sw/hw-model)
   Compiling caliptra-test v0.1.0 (/root/caliptra-sw/test)
   Compiling caliptra-fmc v0.1.0 (/root/caliptra-sw/fmc)
warning: unused imports: `ImageOptions`, `firmware`
 --> fmc/tests/fmc_integration_tests/test_hand_off.rs:2:24
  |
2 | use caliptra_builder::{firmware, ImageOptions};
  |                        ^^^^^^^^  ^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: `caliptra-fmc` (test "fmc_integration_tests") generated 1 warning (run `cargo fix --test "fmc_integration_tests"` to apply 1 suggestion)
    Finished test [unoptimized + debuginfo] target(s) in 7.21s
     Running tests/fmc_integration_tests/main.rs (target/debug/deps/fmc_integration_tests-d58d11e10fa07e3f)

running 1 test
warning: unknown feature specified for `-Ctarget-feature`: `unaligned-scalar-mem`
  |
  = note: it is still passed through to the codegen backend
  = help: consider filing a feature request

warning: unused imports: `CaliptraError`, `LmsResult`
  --> kat/src/lms_kat.rs:15:24
   |
15 | use caliptra_drivers::{CaliptraError, CaliptraResult, Lms, LmsResult, Sha256};
   |                        ^^^^^^^^^^^^^                       ^^^^^^^^^
   |
   = note: `#[warn(unused_imports)]` on by default

warning: unused variable: `success`
   --> kat/src/lms_kat.rs:333:13
    |
333 |         let success =
    |             ^^^^^^^ help: if this is intentional, prefix it with an underscore: `_success`
    |
    = note: `#[warn(unused_variables)]` on by default

Using hardware-model ModelEmulated trng=External hw_rev_id={cptra_generation=0x0001, soc_stepping_id=0000}
InitParamsSummary {
    rom_sha384: "788f6e3c6092b22fcf56538d836450e3c332609c98a10fcb990a93bc4cf698cb822562d82da61f01d8fb7eab05d664d8",
    obf_key: [0xa0a1a2a3, 0xb0b1b2b3, 0xc0c1c2c3, 0xd0d1d2d3, 0xe0e1e2e3, 0xf0f1f2f3, 0xa4a5a6a7, 0xb4b5b6b7],
    security_state: SecurityState {
        debug_locked: false,
        device_lifecycle: Unprovisioned,
    },
}
Initializing fuses: Fuses {
    uds_seed: [0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f, 0x10111213, 0x14151617, 0x18191a1b, 0x1c1d1e1f, 0x20212223, 0x24252627, 0x28292a2b, 0x2c2d2e2f],
    field_entropy: [0x80818283, 0x84858687, 0x88898a8b, 0x8c8d8e8f, 0x90919293, 0x94959697, 0x98999a9b, 0x9c9d9e9f],
    key_manifest_pk_hash: [0x00000000; 12],
    key_manifest_pk_hash_mask: X0,
    owner_pk_hash: [0x00000000; 12],
    fmc_key_manifest_svn: 0x0,
    runtime_svn: [0x00000000; 4],
    anti_rollback_disable: false,
    idevid_cert_attr: [0x00000000; 24],
    idevid_manuf_hsm_id: [0x00000000; 4],
    life_cycle: Unprovisioned,
    lms_verify: false,
    fuse_lms_revocation: 0x0,
    soc_stepping_id: 0x0,
}
          0 writing to cptra_bootfsm_go
     82,032 UART:
     82,048 UART: Running Caliptra ROM ...
     82,456 UART:
     82,510 UART: [state] CFI Enabled
     84,672 UART: [state] LifecycleState = Unprovisioned
     85,327 UART: [state] DebugLocked = No
     85,815 UART: [state] Watchdog Timer is not started because the device is not locked for debugging
     87,500 UART: [kat] SHA2-256
    881,299 UART: ROM Digest: 5125362734CA12D5E4339E70AD8BA0A598F957E7E1F9FC8DD937310244387FA7
    885,424 UART: [kat] ++
    885,576 UART: [kat] sha1
    889,846 UART: [kat] SHA2-256
    891,785 UART: [kat] SHA2-384
    894,702 UART: [kat] SHA2-384-ACC
    896,471 UART: [kat] ECC-384
    902,104 UART: [kat] HMAC-384Kdf
    906,700 UART: [kat] LMS
  1,154,926 UART: [kat] --
  1,155,914 UART: [cold-reset] ++
  1,156,244 UART: [fht] Storing FHT @ 0x50003400
  1,158,919 UART: [idev] ++
  1,159,087 UART: [idev] CDI.KEYID = 6
  1,159,447 UART: [idev] SUBJECT.KEYID = 7
  1,159,871 UART: [idev] UDS.KEYID = 0
  1,160,216 ready_for_fw is high
  1,160,216 <<< Executing mbox cmd 0x46574c44 (28224 bytes) from SoC
  1,167,498 UART: [idev] Erasing UDS.KEYID = 0
  1,184,434 UART: [idev] Using Sha1 for KeyId Algorithm
  1,193,106 UART: [idev] --
  1,194,131 UART: [ldev] ++
  1,194,299 UART: [ldev] CDI.KEYID = 6
  1,194,662 UART: [ldev] SUBJECT.KEYID = 5
  1,195,088 UART: [ldev] AUTHORITY.KEYID = 7
  1,195,551 UART: [ldev] FE.KEYID = 1
  1,200,544 UART: [ldev] Erasing FE.KEYID = 1
  1,226,107 UART: [ldev] Signing Cert with AUTHORITY.KEYID = 7
  1,239,572 UART: [ldev] PUB.X = 504D38CA45D997901F48BA333A149A2FB2668B973AAC64D3B79ECC09A663F02ED2FABA133F5FA499677AEB7687C99B25
  1,245,288 UART: [ldev] PUB.Y = A5CD31125698B3322C086E4398A591946BF20A3ECEA8EB7D7C23410D49FA877E7ECFBE47BD883BD53D7DA865AC217F1D
  1,251,179 UART: [ldev] SIG.R = 9E51FC1FAF9F983A37AD9A33FDB3D96CC41126EDFB2EE0BD656C06A20630F7AB6C54769D2F722B4B8088EE01D6CD5710
  1,256,891 UART: [ldev] SIG.S = FC434A98116613BD7A84F734130980C2D552AC2F50544668B5ACE6D7135456D48FA3BED2387A2A26F6449C41B5D86AD0
  1,263,803 UART: [ldev] --
  1,265,256 UART: [fwproc] Waiting for Commands...
  1,265,987 UART: [fwproc] Received command 0x46574c44
  1,266,778 UART: [fwproc] Received Image of size 28224 bytes
  1,576,395 UART: [fwproc] Image verified using Vendor ECC Key Index 0
  1,603,577 UART: [fwproc] Loading FMC at address 0x40000000 len 16392
  1,629,317 UART: [fwproc] Loading Runtime at address 0x40005000 len 5948
  1,639,700 >>> mbox cmd response: success
  1,640,754 UART: [afmc] ++
  1,640,922 UART: [afmc] CDI.KEYID = 6
  1,641,284 UART: [afmc] SUBJECT.KEYID = 7
  1,641,709 UART: [afmc] AUTHORITY.KEYID = 5
  1,677,794 UART: [afmc] Signing Cert with AUTHORITY.KEYID = 5
  1,694,204 UART: [afmc] Erasing AUTHORITY.KEYID = 5
  1,694,984 UART: [afmc] PUB.X = 95A79B1122062EA4C6EBD0FAF0BF6B2C50F339722CA88984131A8D11F03F9D65D65D17D8E6477A0EBA7ABD9EAEFF6A1C
  1,700,702 UART: [afmc] PUB.Y = F8C810CB1362092082DBA839F653417F76A350F6CD0B06931D198D7B9DFE32BB4558444CA7331667D5B1043D425DA2A0
  1,706,582 UART: [afmc] SIG.R = 7198EB1EEFCD59F558258F4BEFEF12B86C67F458FF22FB14B1B9A4C263B705A2C7E220BB6622FA5643DB2C405BB5C0C0
  1,712,300 UART: [afmc] SIG.S = 633846D15C201F05ADF28EE2E2BB51F1A4918347CACD9A8D7ACB65EA1C5AFA88322356319264D82FA86B7F5CEC68625C
  1,720,234 UART: [afmc] --
  1,721,284 UART: [cold-reset] --
  1,722,184 UART: [state] Locking Datavault
  1,723,389 UART: [state] Locking PCR0, PCR1 and PCR31
  1,723,993 UART: [state] Locking ICCM
  1,724,493 UART: [exit] Launching FMC @ 0x40000130
  1,729,815 UART:
  1,729,831 UART: Running Caliptra FMC ...
  1,730,239 UART:
  1,730,293 UART: [state] CFI Enabled
  1,732,955 UART: [alias rt] Extend RT PCRs
  1,821,428 UART: [alias rt] Extend RT PCRs Done
  1,821,932 UART: [alias rt] Lock RT PCRs
  1,822,328 UART: [alias rt] Lock RT PCRs Done
  1,822,800 UART: [alias rt] Populate DV
  1,824,480 UART: [alias rt] Populate DV Done
  1,832,899 UART: [fht] Handoff : FMC CDI: 6
  1,833,388 UART: [fht] FMC Alias Private Key: 7
  1,834,385 UART: [alias rt] Derive CDI
  1,834,745 UART: [alias rt] Store in in slot 0x4
  1,913,353 UART: [tci] 39B634DCBCA634876A8C53D4DD15A752C9E60E13EB8464F45E0512093F38C3CE04F1E33B3DCBB19902B3FB4F45A729B0E8EC7492CF95F4D9A5167F2C591C995ED187DA3D41BEF5188E88368ABC7DD2F2716A3D5BBFA22CDFFAA30C83A52E288A
  1,933,302 UART: [alias rt] Derive Key Pair
  1,933,742 UART: [alias rt] Store priv key in slot 0x5
  1,946,870 UART: [alias rt] Derive Key Pair - Done
  1,962,750 UART: [alias rt] Signing Cert with AUTHO
  1,963,310 UART:             RITY.KEYID = 7
  1,978,605 UART: [alias rt] Erasing AUTHORITY.KEYID = 7
  1,979,448 UART: [alias rt] PUB.X = 988DF52D19CC213D142F4407C67EEC9257934A45F9312681496970FED206CE035DA841CC523954562C2F06FCE82847AD
  1,986,281 UART: [alias rt] PUB.Y = A2B7C2E885F02E91EB8D51C38FBB117AB29287A1C6296BD047EFEE0724D6FFAF282407C6E320A41DC69C7456B0B7E6FC
  1,993,321 UART: [alias rt] SIG.R = 2C8EB816F05BC5733C4DCF7493CDA41A938CCC29D6186A66A2DF54BAE8B04FCE35DD7CD08870B74DD32EA6B2917E282C
  2,000,191 UART: [alias rt] SIG.S = B7569FCF8B93EF57FC0EDAFAED490EDB502ACFE8DBDF4F7707D8799FAA4F3B0D86951BF7C4EF06DE3DD651F3EDB85F07
  2,024,426 UART: boot::test_boot...    [ok]
* TESTCASE PASSED
test test_hand_off::test_hand_off ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 4 filtered out; finished in 2.29s

root@vultr:~/caliptra-sw# git status
On branch main
Your branch is up to date with 'origin/main'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   fmc/src/flow/rt_alias.rs
        modified:   fmc/tests/fmc_integration_tests/test_hand_off.rs
        modified:   kat/src/lms_kat.rs
        modified:   sw-emulator/lib/crypto/src/hmac512.rs

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        hmac512.patch

no changes added to commit (use "git add" and/or "git commit -a")
root@vultr:~/caliptra-sw# git checkout sw-emulator/lib/crypto/src/hmac512.rs
Updated 1 path from the index
root@vultr:~/caliptra-sw# cargo test --features=verilator --package caliptra-fmc --test fmc_integration_tests -- test_hand_off::test_hand_off --exact --nocapture
   Compiling caliptra-verilated v0.1.0 (/root/caliptra-sw/hw/verilated)
   Compiling caliptra-emu-crypto v0.1.0 (/root/caliptra-sw/sw-emulator/lib/crypto)
   Compiling caliptra-runtime v0.1.0 (/root/caliptra-sw/runtime)
   Compiling caliptra-emu-periph v0.1.0 (/root/caliptra-sw/sw-emulator/lib/periph)
warning: unused imports: `CaliptraError`, `LmsResult`
  --> kat/src/lms_kat.rs:15:24
   |
15 | use caliptra_drivers::{CaliptraError, CaliptraResult, Lms, LmsResult, Sha256};
   |                        ^^^^^^^^^^^^^                       ^^^^^^^^^
   |
   = note: `#[warn(unused_imports)]` on by default

warning: unused variable: `success`
   --> kat/src/lms_kat.rs:333:13
    |
333 |         let success =
    |             ^^^^^^^ help: if this is intentional, prefix it with an underscore: `_success`
    |
    = note: `#[warn(unused_variables)]` on by default

warning: `caliptra-kat` (lib) generated 2 warnings (run `cargo fix --lib -p caliptra-kat` to apply 2 suggestions)
   Compiling caliptra-hw-model v0.1.0 (/root/caliptra-sw/hw-model)
   Compiling caliptra-test v0.1.0 (/root/caliptra-sw/test)
   Compiling caliptra-fmc v0.1.0 (/root/caliptra-sw/fmc)
warning: unused imports: `ImageOptions`, `firmware`
 --> fmc/tests/fmc_integration_tests/test_hand_off.rs:2:24
  |
2 | use caliptra_builder::{firmware, ImageOptions};
  |                        ^^^^^^^^  ^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: `caliptra-fmc` (test "fmc_integration_tests") generated 1 warning (run `cargo fix --test "fmc_integration_tests"` to apply 1 suggestion)
    Finished test [unoptimized + debuginfo] target(s) in 8.67s
     Running tests/fmc_integration_tests/main.rs (target/debug/deps/fmc_integration_tests-9a8f9dc42a94e29b)

running 1 test
warning: unknown feature specified for `-Ctarget-feature`: `unaligned-scalar-mem`
  |
  = note: it is still passed through to the codegen backend
  = help: consider filing a feature request

warning: unused imports: `CaliptraError`, `LmsResult`
  --> kat/src/lms_kat.rs:15:24
   |
15 | use caliptra_drivers::{CaliptraError, CaliptraResult, Lms, LmsResult, Sha256};
   |                        ^^^^^^^^^^^^^                       ^^^^^^^^^
   |
   = note: `#[warn(unused_imports)]` on by default

warning: unused variable: `success`
   --> kat/src/lms_kat.rs:333:13
    |
333 |         let success =
    |             ^^^^^^^ help: if this is intentional, prefix it with an underscore: `_success`
    |
    = note: `#[warn(unused_variables)]` on by default

     14,347 ready_for_fuses is high
Using hardware-model ModelVerilated trng=External hw_rev_id={cptra_generation=0x0001, soc_stepping_id=0000}
InitParamsSummary {
    rom_sha384: "788f6e3c6092b22fcf56538d836450e3c332609c98a10fcb990a93bc4cf698cb822562d82da61f01d8fb7eab05d664d8",
    obf_key: [0xa0a1a2a3, 0xb0b1b2b3, 0xc0c1c2c3, 0xd0d1d2d3, 0xe0e1e2e3, 0xf0f1f2f3, 0xa4a5a6a7, 0xb4b5b6b7],
    security_state: SecurityState {
        debug_locked: false,
        device_lifecycle: Unprovisioned,
    },
}
Initializing fuses: Fuses {
    uds_seed: [0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f, 0x10111213, 0x14151617, 0x18191a1b, 0x1c1d1e1f, 0x20212223, 0x24252627, 0x28292a2b, 0x2c2d2e2f],
    field_entropy: [0x80818283, 0x84858687, 0x88898a8b, 0x8c8d8e8f, 0x90919293, 0x94959697, 0x98999a9b, 0x9c9d9e9f],
    key_manifest_pk_hash: [0x00000000; 12],
    key_manifest_pk_hash_mask: X0,
    owner_pk_hash: [0x00000000; 12],
    fmc_key_manifest_svn: 0x0,
    runtime_svn: [0x00000000; 4],
    anti_rollback_disable: false,
    idevid_cert_attr: [0x00000000; 24],
    idevid_manuf_hsm_id: [0x00000000; 4],
    life_cycle: Unprovisioned,
    lms_verify: false,
    fuse_lms_revocation: 0x0,
    soc_stepping_id: 0x0,
}
     14,533 writing to cptra_bootfsm_go
test test_hand_off::test_hand_off has been running for over 60 seconds
    203,381 UART:
    203,438 UART: Running Caliptra ROM ...
    204,859 UART:
    205,015 UART: [state] CFI Enabled
    219,160 UART: [state] LifecycleState = Unprovisioned
    221,417 UART: [state] DebugLocked = No
    224,010 UART: [state] Watchdog Timer is not started because the device is not locked for debugging
    230,590 UART: [kat] SHA2-256
    409,823 UART: ROM Digest: 5125362734CA12D5E4339E70AD8BA0A598F957E7E1F9FC8DD937310244387FA7
    421,207 UART: [kat] ++
    421,734 UART: [kat] sha1
    433,032 UART: [kat] SHA2-256
    436,065 UART: [kat] SHA2-384
    442,682 UART: [kat] SHA2-384-ACC
    445,039 UART: [kat] ECC-384
  2,728,697 UART: [kat] HMAC-384Kdf
  2,740,241 UART: [kat] LMS
  3,232,713 UART: [kat] --
  3,237,093 UART: [cold-reset] ++
  3,238,527 UART: [fht] Storing FHT @ 0x50003400
  3,250,494 UART: [idev] ++
  3,251,072 UART: [idev] CDI.KEYID = 6
  3,252,320 UART: [idev] SUBJECT.KEYID = 7
  3,253,790 UART: [idev] UDS.KEYID = 0
  3,254,977 ready_for_fw is high
  3,254,981 <<< Executing mbox cmd 0x46574c44 (28224 bytes) from SoC
  3,266,981 UART: [idev] Erasing UDS.KEYID = 0
  6,538,086 UART: [idev] Using Sha1 for KeyId Algorithm
  6,560,267 UART: [idev] --
  6,564,922 UART: [ldev] ++
  6,565,500 UART: [ldev] CDI.KEYID = 6
  6,566,738 UART: [ldev] SUBJECT.KEYID = 5
  6,568,186 UART: [ldev] AUTHORITY.KEYID = 7
  6,569,782 UART: [ldev] FE.KEYID = 1
  6,582,114 UART: [ldev] Erasing FE.KEYID = 1
  9,874,224 UART: [ldev] Signing Cert with AUTHORITY.KEYID = 7
 12,165,547 UART: [ldev] PUB.X = 504D38CA45D997901F48BA333A149A2FB2668B973AAC64D3B79ECC09A663F02ED2FABA133F5FA499677AEB7687C99B25
 12,181,395 UART: [ldev] PUB.Y = A5CD31125698B3322C086E4398A591946BF20A3ECEA8EB7D7C23410D49FA877E7ECFBE47BD883BD53D7DA865AC217F1D
 12,197,653 UART: [ldev] SIG.R = 9E51FC1FAF9F983A37AD9A33FDB3D96CC41126EDFB2EE0BD656C06A20630F7AB6C54769D2F722B4B8088EE01D6CD5710
 12,213,509 UART: [ldev] SIG.S = FC434A98116613BD7A84F734130980C2D552AC2F50544668B5ACE6D7135456D48FA3BED2387A2A26F6449C41B5D86AD0
 12,235,482 UART: [ldev] --
 12,240,646 UART: [fwproc] Waiting for Commands...
 12,243,281 UART: [fwproc] Received command 0x46574c44
 12,245,759 UART: [fwproc] Received Image of size 28224 bytes
 15,278,216 UART: [fwproc] Image verified using Vendor ECC Key Index 0
 15,353,684 UART: [fwproc] Loading FMC at address 0x40000000 len 16392
 15,455,632 UART: [fwproc] Loading Runtime at address 0x40005000 len 5948
 15,495,523 >>> mbox cmd response: success
 15,500,188 UART: [afmc] ++
 15,500,770 UART: [afmc] CDI.KEYID = 6
 15,502,018 UART: [afmc] SUBJECT.KEYID = 7
 15,503,474 UART: [afmc] AUTHORITY.KEYID = 5
 18,813,557 UART: [afmc] Signing Cert with AUTHORITY.KEYID = 5
 21,106,452 UART: [afmc] Erasing AUTHORITY.KEYID = 5
 21,108,911 UART: [afmc] PUB.X = 95A79B1122062EA4C6EBD0FAF0BF6B2C50F339722CA88984131A8D11F03F9D65D65D17D8E6477A0EBA7ABD9EAEFF6A1C
 21,124,851 UART: [afmc] PUB.Y = F8C810CB1362092082DBA839F653417F76A350F6CD0B06931D198D7B9DFE32BB4558444CA7331667D5B1043D425DA2A0
 21,140,947 UART: [afmc] SIG.R = 7198EB1EEFCD59F558258F4BEFEF12B86C67F458FF22FB14B1B9A4C263B705A2C7E220BB6622FA5643DB2C405BB5C0C0
 21,156,619 UART: [afmc] SIG.S = 633846D15C201F05ADF28EE2E2BB51F1A4918347CACD9A8D7ACB65EA1C5AFA88322356319264D82FA86B7F5CEC68625C
 21,181,288 UART: [afmc] --
 21,185,672 UART: [cold-reset] --
 21,189,396 UART: [state] Locking Datavault
 21,196,150 UART: [state] Locking PCR0, PCR1 and PCR31
 21,198,215 UART: [state] Locking ICCM
 21,200,196 UART: [exit] Launching FMC @ 0x40000130
 21,208,941 UART:
 21,208,974 UART: Running Caliptra FMC ...
 21,209,815 UART:
 21,209,909 UART: [state] CFI Enabled
 21,213,079 UART: [alias rt] Extend RT PCRs
 21,256,477 UART: [alias rt] Extend RT PCRs Done
 21,257,509 UART: [alias rt] Lock RT PCRs
 21,258,319 UART: [alias rt] Lock RT PCRs Done
 21,259,285 UART: [alias rt] Populate DV
 21,261,119 UART: [alias rt] Populate DV Done
 21,266,803 UART: [fht] Handoff : FMC CDI: 6
 21,267,759 UART: [fht] FMC Alias Private Key: 7
 21,269,471 UART: [alias rt] Derive CDI
 21,270,206 UART: [alias rt] Store in in slot 0x4
 21,307,334 UART: [tci] 39B634DCBCA634876A8C53D4DD15A752C9E60E13EB8464F45E0512093F38C3CE04F1E33B3DCBB19902B3FB4F45A729B0E8EC7492CF95F4D9A5167F2C591C995ED187DA3D41BEF5188E88368ABC7DD2F2716A3D5BBFA22CDFFAA30C83A52E288A
 21,326,628 UART: [alias rt] Derive Key Pair
 21,327,529 UART: [alias rt] Store priv key in slot 0x5
 24,568,585 UART: [alias rt] Derive Key Pair - Done
 24,582,264 UART: [alias rt] Signing Cert with AUTHO
 24,583,419 UART:             RITY.KEYID = 7
 26,862,895 UART: [alias rt] Erasing AUTHORITY.KEYID = 7
 26,864,404 UART: [alias rt] PUB.X = 988DF52D19CC213D142F4407C67EEC9257934A45F9312681496970FED206CE035DA841CC523954562C2F06FCE82847AD
 26,871,802 UART: [alias rt] PUB.Y = A2B7C2E885F02E91EB8D51C38FBB117AB29287A1C6296BD047EFEE0724D6FFAF282407C6E320A41DC69C7456B0B7E6FC
 26,879,414 UART: [alias rt] SIG.R = 2C8EB816F05BC5733C4DCF7493CDA41A938CCC29D6186A66A2DF54BAE8B04FCE35DD7CD08870B74DD32EA6B2917E282C
 26,886,852 UART: [alias rt] SIG.S = B7569FCF8B93EF57FC0EDAFAED490EDB502ACFE8DBDF4F7707D8799FAA4F3B0D86951BF7C4EF06DE3DD651F3EDB85F07
 28,191,604 UART: boot::test_boot...    [ok]
* TESTCASE PASSED
test test_hand_off::test_hand_off ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 4 filtered out; finished in 13693.09s

root@vultr:~/caliptra-sw#
jhand2 commented 4 months ago

Thanks @LuiSzee, we're taking a look. I'll update you as soon as I know more.

korran commented 4 months ago

Incorrect derivation confirmed on FPGA in #1526 :

thread 'smoke_test::smoke_test' panicked at 'assertion failed: expected_rt_alias_key.derive_public_key().public_eq(&rt_alias_cert.public_key().unwrap())', test/tests/caliptra_integration_tests/smoke_test.rs:430:5

Passes in emulator. I'm pretty sure this is because the FMC is using a 96-byte kdf context, which leads to a 113-byte HMAC operation, which triggers a second padding block, which the hardware doesn't like. The ROM uses a 48-byte kdf context (PCR0) that doesn't trigger this problem.

Will follow up with some lower level tests.

Nitsirks commented 4 months ago

If the block data extends beyond a single block, the key from KV will get cleared from the HMAC and needs to be re-loaded from the KV for the next block iteration. I believe the internal state of HMAC is maintained (we don't zeroize everything) after a KV transaction, so reloading the key should work.

korran commented 4 months ago

Nitsirks: Where is this procedure documented?

Nitsirks commented 4 months ago

Apparently it is not. I just checked the hardware specification and keyvault section does not mention the clearing of secrets after use.

I'll get this updated asap.

This feature came after an ask some time last year to ensure a key from the keyvault could never be used to generate a firmware readable digest, as that could expose device secrets.

korran commented 4 months ago

Postmortem for this issue: #1550