Repository: chipsalliance/caliptra-sw
Pull request #407 (2023-06-21 20:01:57)

[feat] Zeroize local variables on stack
These changes are in response to the following FIPs requirement (https://github.com/chipsalliance/caliptra-sw/issues/324)

JohnTraverAmd: https://github.com/chipsalliance/caliptra-sw/pull/373

Patch:
diff --git a/drivers/src/ecc384.rs b/drivers/src/ecc384.rs
index fbc41ce2..edb09218 100644
--- a/drivers/src/ecc384.rs
+++ b/drivers/src/ecc384.rs
@@ -110,6 +110,11 @@ impl Ecc384PubKey {
     pub fn to_der(&self) -> [u8; 97] {
         array_concat3([0x04], (&self.x).into(), (&self.y).into())
     }
+
+    pub fn zeroize(&mut self) {
+        self.x.0.fill(0);
+        self.y.0.fill(0);
+    }
 }
 
 /// ECC-384 Signature
@@ -123,6 +128,13 @@ pub struct Ecc384Signature {
     pub s: Ecc384Scalar,
 }
 
+impl Ecc384Signature {
+    pub fn zeroize(&mut self) {
+        self.r.0.fill(0);
+        self.s.0.fill(0);
+    }
+}
+
 /// Elliptic Curve P-384 API
 pub struct Ecc384 {
     ecc: EccReg,
@@ -146,7 +158,7 @@ impl Ecc384 {
     /// * `Ecc384PubKey` - Generated ECC-384 Public Key
     pub fn key_pair(
         &mut self,
-        seed: Ecc384Seed,
+        seed: &Ecc384Seed,
         nonce: &Array4x12,
         trng: &mut Trng,
         mut priv_key: Ecc384PrivKeyOut,
@@ -158,8 +170,8 @@ impl Ecc384 {
 
         // Configure hardware to route keys to user specified hardware blocks
         match &mut priv_key {
-            Ecc384PrivKeyOut::Array4x12(arr) => {
-                KvAccess::begin_copy_to_arr(ecc.kv_wr_pkey_status(), ecc.kv_wr_pkey_ctrl(), arr)?
+            Ecc384PrivKeyOut::Array4x12(_arr) => {
+                KvAccess::begin_copy_to_arr(ecc.kv_wr_pkey_status(), ecc.kv_wr_pkey_ctrl())?
             }
             Ecc384PrivKeyOut::Key(key) => {
                 KvAccess::begin_copy_to_kv(ecc.kv_wr_pkey_status(), ecc.kv_wr_pkey_ctrl(), *key)?
@@ -170,7 +182,7 @@ impl Ecc384 {
         match seed {
             Ecc384Seed::Array4x12(arr) => KvAccess::copy_from_arr(arr, ecc.seed())?,
             Ecc384Seed::Key(key) => {
-                KvAccess::copy_from_kv(key, ecc.kv_rd_seed_status(), ecc.kv_rd_seed_ctrl())
+                KvAccess::copy_from_kv(*key, ecc.kv_rd_seed_status(), ecc.kv_rd_seed_ctrl())
                     .map_err(|err| err.into_read_seed_err())?
             }
         }
@@ -218,7 +230,7 @@ impl Ecc384 {
     /// * `Ecc384Signature` - Generate signature
     pub fn sign(
         &mut self,
-        priv_key: Ecc384PrivKeyIn,
+        priv_key: &Ecc384PrivKeyIn,
         data: &Ecc384Scalar,
         trng: &mut Trng,
     ) -> CaliptraResult<Ecc384Signature> {
@@ -231,7 +243,7 @@ impl Ecc384 {
         match priv_key {
             Ecc384PrivKeyIn::Array4x12(arr) => KvAccess::copy_from_arr(arr, ecc.privkey_in())?,
             Ecc384PrivKeyIn::Key(key) => {
-                KvAccess::copy_from_kv(key, ecc.kv_rd_pkey_status(), ecc.kv_rd_pkey_ctrl())
+                KvAccess::copy_from_kv(*key, ecc.kv_rd_pkey_status(), ecc.kv_rd_pkey_ctrl())
                     .map_err(|err| err.into_read_priv_key_err())?
             }
         }
diff --git a/drivers/src/hmac384.rs b/drivers/src/hmac384.rs
index e51f9a76..9326b80e 100644
--- a/drivers/src/hmac384.rs
+++ b/drivers/src/hmac384.rs
@@ -126,7 +126,7 @@ impl Hmac384 {
     /// * `tag`  -  The calculated tag
     pub fn hmac_init<'a>(
         &'a mut self,
-        key: Hmac384Key,
+        key: &Hmac384Key,
         trng: &mut Trng,
         mut tag: Hmac384Tag<'a>,
     ) -> CaliptraResult<Hmac384Op> {
@@ -135,8 +135,8 @@ impl Hmac384 {
         // Configure the hardware so that the output tag is stored at a location specified by the
         // caller.
         match &mut tag {
-            Hmac384Tag::Array4x12(arr) => {
-                KvAccess::begin_copy_to_arr(hmac.kv_wr_status(), hmac.kv_wr_ctrl(), arr)?
+            Hmac384Tag::Array4x12(_arr) => {
+                KvAccess::begin_copy_to_arr(hmac.kv_wr_status(), hmac.kv_wr_ctrl())?
             }
             Hmac384Tag::Key(key) => {
                 KvAccess::begin_copy_to_kv(hmac.kv_wr_status(), hmac.kv_wr_ctrl(), *key)?
@@ -147,7 +147,7 @@ impl Hmac384 {
         match key {
             Hmac384Key::Array4x12(arr) => KvAccess::copy_from_arr(arr, hmac.key())?,
             Hmac384Key::Key(key) => {
-                KvAccess::copy_from_kv(key, hmac.kv_rd_key_status(), hmac.kv_rd_key_ctrl())
+                KvAccess::copy_from_kv(*key, hmac.kv_rd_key_status(), hmac.kv_rd_key_ctrl())
                     .map_err(|err| err.into_read_key_err())?
             }
         }
@@ -180,8 +180,8 @@ impl Hmac384 {
     /// * `tag`  -  The calculated tag
     pub fn hmac(
         &mut self,
-        key: Hmac384Key,
-        data: Hmac384Data,
+        key: &Hmac384Key,
+        data: &Hmac384Data,
         trng: &mut Trng,
         mut tag: Hmac384Tag,
     ) -> CaliptraResult<()> {
@@ -190,8 +190,8 @@ impl Hmac384 {
         // Configure the hardware so that the output tag is stored at a location specified by the
         // caller.
         match &mut tag {
-            Hmac384Tag::Array4x12(arr) => {
-                KvAccess::begin_copy_to_arr(hmac.kv_wr_status(), hmac.kv_wr_ctrl(), arr)?
+            Hmac384Tag::Array4x12(_arr) => {
+                KvAccess::begin_copy_to_arr(hmac.kv_wr_status(), hmac.kv_wr_ctrl())?
             }
             Hmac384Tag::Key(key) => {
                 KvAccess::begin_copy_to_kv(hmac.kv_wr_status(), hmac.kv_wr_ctrl(), *key)?
@@ -202,7 +202,7 @@ impl Hmac384 {
         match key {
             Hmac384Key::Array4x12(arr) => KvAccess::copy_from_arr(arr, hmac.key())?,
             Hmac384Key::Key(key) => {
-                KvAccess::copy_from_kv(key, hmac.kv_rd_key_status(), hmac.kv_rd_key_ctrl())
+                KvAccess::copy_from_kv(*key, hmac.kv_rd_key_status(), hmac.kv_rd_key_ctrl())
                     .map_err(|err| err.into_read_key_err())?
             }
         }
@@ -215,7 +215,7 @@ impl Hmac384 {
         // Calculate the hmac
         match data {
             Hmac384Data::Slice(buf) => self.hmac_buf(buf)?,
-            Hmac384Data::Key(key) => self.hmac_key(key)?,
+            Hmac384Data::Key(key) => self.hmac_key(*key)?,
         }
         let hmac = self.hmac.regs();
 
diff --git a/drivers/src/hmac384_kdf.rs b/drivers/src/hmac384_kdf.rs
index c6eb82e7..55ce44ac 100644
--- a/drivers/src/hmac384_kdf.rs
+++ b/drivers/src/hmac384_kdf.rs
@@ -39,7 +39,7 @@ pub fn hmac384_kdf(
     trng: &mut Trng,
     output: Hmac384Tag,
 ) -> CaliptraResult<()> {
-    let mut hmac_op = hmac.hmac_init(key, trng, output)?;
+    let mut hmac_op = hmac.hmac_init(&key, trng, output)?;
 
     hmac_op.update(&1_u32.to_be_bytes())?;
     hmac_op.update(label)?;
diff --git a/drivers/src/kv_access.rs b/drivers/src/kv_access.rs
index 8ffba4c2..f9d3908a 100644
--- a/drivers/src/kv_access.rs
+++ b/drivers/src/kv_access.rs
@@ -84,17 +84,13 @@ impl KvAccess {
     ///
     /// * `status_reg` - Status register
     /// * `ctrl_reg` - Control register
-    /// * `arr` - Array to copy the key into
     pub(crate) fn begin_copy_to_arr<
-        const ARR_WORD_LEN: usize,
-        const ARR_BYTE_LEN: usize,
         StatusReg: ureg::ReadableReg<ReadVal = KvStatusRegReadVal>,
         CtrlReg: ureg::ResettableReg + ureg::WritableReg<WriteVal = KvWriteCtrlRegWriteVal>,
         TMmio: MmioMut,
     >(
         status_reg: ureg::RegRef<StatusReg, TMmio>,
         ctrl_reg: ureg::RegRef<CtrlReg, TMmio>,
-        _arr: &mut Array4xN<ARR_WORD_LEN, ARR_BYTE_LEN>,
     ) -> CaliptraResult<()> {
         wait::until(|| status_reg.read().ready());
         ctrl_reg.write(|w| w.write_en(false));
diff --git a/drivers/src/lib.rs b/drivers/src/lib.rs
index af4c65e2..dc7be748 100644
--- a/drivers/src/lib.rs
+++ b/drivers/src/lib.rs
@@ -67,6 +67,7 @@ pub use lms::{
     D_LEAF, D_MESG, D_PBLC,
 };
 pub use mailbox::{Mailbox, MailboxRecvTxn, MailboxSendTxn};
+pub use okref::okmutref;
 pub use okref::okref;
 pub use pcr_bank::{PcrBank, PcrId};
 pub use sha1::{Sha1, Sha1Digest, Sha1DigestOp};
diff --git a/drivers/src/lms.rs b/drivers/src/lms.rs
index 02396bc0..e682780a 100644
--- a/drivers/src/lms.rs
+++ b/drivers/src/lms.rs
@@ -366,6 +366,7 @@ impl Lms {
         }
         hasher.finalize()?;
         let result = HashValue::<N>::from(digest);
+        digest.0.fill(0);
         Ok(result)
     }
 
@@ -453,11 +454,14 @@ impl Lms {
             temp = HashValue::<N>::from(digest);
             node_num /= 2;
             i += 1;
+            digest.0.fill(0);
         }
-        let candidate_key = temp;
-        if candidate_key != HashValue::from(lms_public_key.digest) {
+        let candidate_key = &temp;
+        if *candidate_key != HashValue::from(lms_public_key.digest) {
             return Ok(false);
         }
+        digest.0.fill(0);
+        temp.0.fill(0);
         Ok(true)
     }
 }
diff --git a/drivers/src/okref.rs b/drivers/src/okref.rs
index d114a487..f5b6f510 100644
--- a/drivers/src/okref.rs
+++ b/drivers/src/okref.rs
@@ -48,6 +48,13 @@ pub fn okref<T, E: Copy>(r: &Result<T, E>) -> Result<&T, E> {
     }
 }
 
+pub fn okmutref<T, E: Copy>(r: &mut Result<T, E>) -> Result<&mut T, E> {
+    match r {
+        Ok(r) => Ok(r),
+        Err(e) => Err(*e),
+    }
+}
+
 #[cfg(test)]
 mod tests {
     use super::*;
diff --git a/fmc/src/flow/crypto.rs b/fmc/src/flow/crypto.rs
index afbe263c..cf4a0696 100644
--- a/fmc/src/flow/crypto.rs
+++ b/fmc/src/flow/crypto.rs
@@ -73,8 +73,8 @@ impl Crypto {
     /// * `KeyId` - Key Id inputted
     pub fn hmac384_mac(
         env: &mut FmcEnv,
-        key: Hmac384Key,
-        data: Hmac384Data,
+        key: &Hmac384Key,
+        data: &Hmac384Data,
         tag: KeyId,
     ) -> CaliptraResult<KeyId> {
         // Tag
@@ -118,7 +118,7 @@ impl Crypto {
             priv_key,
             pub_key: env
                 .ecc384
-                .key_pair(seed, &Array4x12::default(), &mut env.trng, key_out)?,
+                .key_pair(&seed, &Array4x12::default(), &mut env.trng, key_out)?,
         })
     }
 
@@ -144,7 +144,7 @@ impl Crypto {
         let digest = okref(&digest)?;
         let priv_key_args = KeyReadArgs::new(priv_key);
         let priv_key = Ecc384PrivKeyIn::Key(priv_key_args);
-        env.ecc384.sign(priv_key, digest, &mut env.trng)
+        env.ecc384.sign(&priv_key, digest, &mut env.trng)
     }
 
     /// Verify the ECC Signature
diff --git a/fmc/src/flow/rt_alias.rs b/fmc/src/flow/rt_alias.rs
index a753e05d..07040350 100644
--- a/fmc/src/flow/rt_alias.rs
+++ b/fmc/src/flow/rt_alias.rs
@@ -177,7 +177,7 @@ impl RtAliasLayer {
 
         // Permute CDI from FMC TCI
         let data = Hmac384Data::Slice(&tci);
-        let cdi = Crypto::hmac384_mac(env, key, data, cdi)?;
+        let cdi = Crypto::hmac384_mac(env, &key, &data, cdi)?;
         Ok(cdi)
     }
 
diff --git a/kat/src/ecc384_kat.rs b/kat/src/ecc384_kat.rs
index b7a61ba9..4b7980a1 100644
--- a/kat/src/ecc384_kat.rs
+++ b/kat/src/ecc384_kat.rs
@@ -68,7 +68,7 @@ impl Ecc384Kat {
     fn kat_signature_generate(&self, ecc: &mut Ecc384, trng: &mut Trng) -> CaliptraResult<()> {
         let digest = Array4x12::new([0u32; 12]);
         let signature = ecc
-            .sign(Ecc384PrivKeyIn::from(&PRIV_KEY), &digest, trng)
+            .sign(&Ecc384PrivKeyIn::from(&PRIV_KEY), &digest, trng)
             .map_err(|_| CaliptraError::ROM_KAT_ECC384_SIGNATURE_GENERATE_FAILURE)?;
 
         if signature != SIGNATURE {
diff --git a/rom/dev/src/flow/cold_reset/crypto.rs b/rom/dev/src/flow/cold_reset/crypto.rs
index faa70ffb..886c96b7 100644
--- a/rom/dev/src/flow/cold_reset/crypto.rs
+++ b/rom/dev/src/flow/cold_reset/crypto.rs
@@ -44,6 +44,12 @@ pub struct Ecc384KeyPair {
     pub pub_key: Ecc384PubKey,
 }
 
+impl Ecc384KeyPair {
+    pub fn zeroize(&mut self) {
+        self.pub_key.zeroize();
+    }
+}
+
 pub enum Crypto {}
 
 impl Crypto {
@@ -104,8 +110,8 @@ impl Crypto {
     /// * `KeyId` - Key Id inputted
     pub fn hmac384_mac(
         env: &mut RomEnv,
-        key: Hmac384Key,
-        data: Hmac384Data,
+        key: &Hmac384Key,
+        data: &Hmac384Data,
         tag: KeyId,
     ) -> CaliptraResult<KeyId> {
         // Tag
@@ -149,7 +155,7 @@ impl Crypto {
             priv_key,
             pub_key: env
                 .ecc384
-                .key_pair(seed, &Array4x12::default(), &mut env.trng, key_out)?,
+                .key_pair(&seed, &Array4x12::default(), &mut env.trng, key_out)?,
         })
     }
 
@@ -171,11 +177,13 @@ impl Crypto {
         priv_key: KeyId,
         data: &[u8],
     ) -> CaliptraResult<Ecc384Signature> {
-        let digest = Self::sha384_digest(env, data);
-        let digest = okref(&digest)?;
+        let mut digest = Self::sha384_digest(env, data);
+        let digest = okmutref(&mut digest)?;
         let priv_key_args = KeyReadArgs::new(priv_key);
         let priv_key = Ecc384PrivKeyIn::Key(priv_key_args);
-        env.ecc384.sign(priv_key, digest, &mut env.trng)
+        let result = env.ecc384.sign(&priv_key, digest, &mut env.trng);
+        digest.0.fill(0);
+        result
     }
 
     /// Verify the ECC Signature
@@ -198,8 +206,10 @@ impl Crypto {
         data: &[u8],
         sig: &Ecc384Signature,
     ) -> CaliptraResult<bool> {
-        let digest = Self::sha384_digest(env, data);
-        let digest = okref(&digest)?;
-        env.ecc384.verify(pub_key, digest, sig)
+        let mut digest = Self::sha384_digest(env, data);
+        let digest = okmutref(&mut digest)?;
+        let result = env.ecc384.verify(pub_key, digest, sig);
+        digest.0.fill(0);
+        result
     }
 }
diff --git a/rom/dev/src/flow/cold_reset/dice.rs b/rom/dev/src/flow/cold_reset/dice.rs
index ed7023a1..711a7181 100644
--- a/rom/dev/src/flow/cold_reset/dice.rs
+++ b/rom/dev/src/flow/cold_reset/dice.rs
@@ -40,3 +40,11 @@ pub struct DiceOutput {
     /// Subject Key Identifier
     pub subj_key_id: [u8; 20],
 }
+
+impl DiceOutput {
+    pub fn zeroize(&mut self) {
+        self.subj_key_pair.zeroize();
+        self.subj_sn.fill(0);
+        self.subj_key_id.fill(0);
+    }
+}
diff --git a/rom/dev/src/flow/cold_reset/fmc_alias.rs b/rom/dev/src/flow/cold_reset/fmc_alias.rs
index 22054810..505c47a0 100644
--- a/rom/dev/src/flow/cold_reset/fmc_alias.rs
+++ b/rom/dev/src/flow/cold_reset/fmc_alias.rs
@@ -50,10 +50,12 @@ impl FmcAliasLayer {
         );
 
         // We use the value of PCR0 as the measurement for deriving the CDI.
-        let measurement = env.pcr_bank.read_pcr(caliptra_drivers::PcrId::PcrId0);
+        let mut measurement = env.pcr_bank.read_pcr(caliptra_drivers::PcrId::PcrId0);
 
         // Derive the DICE CDI from decrypted UDS
-        Self::derive_cdi(env, measurement, KEY_ID_CDI)?;
+        let result = Self::derive_cdi(env, &measurement, KEY_ID_CDI);
+        measurement.0.fill(0);
+        result?;
 
         // Derive DICE Key Pair from CDI
         let key_pair = Self::derive_key_pair(env, KEY_ID_CDI, KEY_ID_FMC_PRIV_KEY)?;
@@ -70,7 +72,7 @@ impl FmcAliasLayer {
         report_boot_status(FmcAliasSubjKeyIdGenerationComplete.into());
 
         // Generate the output for next layer
-        let output = DiceOutput {
+        let mut output = DiceOutput {
             subj_key_pair: key_pair,
             subj_sn,
             subj_key_id,
@@ -78,6 +80,7 @@ impl FmcAliasLayer {
 
         // Generate Local Device ID Certificate
         Self::generate_cert_sig(env, input, &output, fw_proc_info)?;
+        output.zeroize();
 
         report_boot_status(FmcAliasDerivationComplete.into());
         cprintln!("[afmc] --");
@@ -92,12 +95,14 @@ impl FmcAliasLayer {
     /// * `env` - ROM Environment
     /// * `measurements` - Array containing the FMC measurements
     /// * `cdi` - Key Slot to store the generated CDI
-    fn derive_cdi(env: &mut RomEnv, measurements: Array4x12, cdi: KeyId) -> CaliptraResult<()> {
+    fn derive_cdi(env: &mut RomEnv, measurements: &Array4x12, cdi: KeyId) -> CaliptraResult<()> {
         // CDI Key
         let key = Hmac384Key::Key(KeyReadArgs::new(cdi));
-        let data: [u8; 48] = measurements.into();
-        let data = Hmac384Data::Slice(&data);
-        Crypto::hmac384_mac(env, key, data, cdi)?;
+        let mut measurements: [u8; 48] = measurements.into();
+        let data = Hmac384Data::Slice(&measurements);
+        let result = Crypto::hmac384_mac(env, &key, &data, cdi);
+        measurements.fill(0);
+        result?;
         report_boot_status(FmcAliasDeriveCdiComplete.into());
         Ok(())
     }
diff --git a/rom/dev/src/flow/cold_reset/fw_processor.rs b/rom/dev/src/flow/cold_reset/fw_processor.rs
index 9a630c26..6faee6df 100644
--- a/rom/dev/src/flow/cold_reset/fw_processor.rs
+++ b/rom/dev/src/flow/cold_reset/fw_processor.rs
@@ -37,6 +37,14 @@ pub struct FwProcInfo {
     pub fmc_effective_fuse_svn: u32,
 }
 
+impl FwProcInfo {
+    pub fn zeroize(&mut self) {
+        self.fmc_cert_valid_not_before.value.fill(0);
+        self.fmc_cert_valid_not_after.value.fill(0);
+        self.fmc_effective_fuse_svn = 0;
+    }
+}
+
 pub struct FirmwareProcessor {}
 
 impl FirmwareProcessor {
diff --git a/rom/dev/src/flow/cold_reset/idev_id.rs b/rom/dev/src/flow/cold_reset/idev_id.rs
index 81abd7ee..a849dd88 100644
--- a/rom/dev/src/flow/cold_reset/idev_id.rs
+++ b/rom/dev/src/flow/cold_reset/idev_id.rs
@@ -154,8 +154,7 @@ impl InitDevIdLayer {
         // CDI Key
         let key = Hmac384Key::Array4x12(&IDEVID_CDI_KEY);
         let data = Hmac384Data::Key(KeyReadArgs::new(uds));
-        Crypto::hmac384_mac(env, key, data, cdi)?;
-
+        Crypto::hmac384_mac(env, &key, &data, cdi)?;
         cprintln!("[idev] Erasing UDS.KEYID = {}", uds as u8);
         env.key_vault.erase_key(uds)?;
         report_boot_status(IDevIdCdiDerivationComplete.into());
@@ -236,8 +235,8 @@ impl InitDevIdLayer {
         );
 
         // Sign the the `To Be Signed` portion
-        let sig = Crypto::ecdsa384_sign(env, key_pair.priv_key, tbs.tbs());
-        let sig = okref(&sig)?;
+        let mut sig = Crypto::ecdsa384_sign(env, key_pair.priv_key, tbs.tbs());
+        let sig = okmutref(&mut sig)?;
 
         // Verify the signature of the `To Be Signed` portion
         if !Crypto::ecdsa384_verify(env, &key_pair.pub_key, tbs.tbs(), sig)? {
@@ -272,7 +271,13 @@ impl InitDevIdLayer {
         report_boot_status(IDevIdMakeCsrComplete.into());
 
         // Execute Send CSR Flow
-        Self::send_csr(env, InitDevIdCsr::new(&csr, csr_len))
+        let result = Self::send_csr(env, InitDevIdCsr::new(&csr, csr_len));
+
+        // Zeroize locals.
+        sig.zeroize();
+        csr.fill(0);
+
+        result
     }
 
     /// Send Initial Device ID CSR to SOC
diff --git a/rom/dev/src/flow/cold_reset/ldev_id.rs b/rom/dev/src/flow/cold_reset/ldev_id.rs
index 741e8c44..6f6971b5 100644
--- a/rom/dev/src/flow/cold_reset/ldev_id.rs
+++ b/rom/dev/src/flow/cold_reset/ldev_id.rs
@@ -96,7 +96,7 @@ impl LocalDevIdLayer {
         // CDI Key
         let key = Hmac384Key::Key(KeyReadArgs::new(cdi));
         let data = Hmac384Data::Key(KeyReadArgs::new(fe));
-        Crypto::hmac384_mac(env, key, data, cdi)?;
+        Crypto::hmac384_mac(env, &key, &data, cdi)?;
 
         cprintln!("[ldev] Erasing FE.KEYID = {}", fe as u8);
         env.key_vault.erase_key(fe)?;
@@ -167,8 +167,8 @@ impl LocalDevIdLayer {
             "[ldev] Signing Cert with AUTHORITY.KEYID = {}",
             auth_priv_key as u8
         );
-        let sig = Crypto::ecdsa384_sign(env, auth_priv_key, tbs.tbs());
-        let sig = okref(&sig)?;
+        let mut sig = Crypto::ecdsa384_sign(env, auth_priv_key, tbs.tbs());
+        let sig = okmutref(&mut sig)?;
 
         // Clear the authority private key
         //To-Do : Disabling The Print Temporarily
@@ -193,6 +193,7 @@ impl LocalDevIdLayer {
         // Lock the Local Device ID cert signature in data vault until
         // cold reset
         env.data_vault.set_ldev_dice_signature(sig);
+        sig.zeroize();
 
         // Lock the Local Device ID public keys in data vault until
         // cold reset
diff --git a/rom/dev/src/flow/cold_reset/mod.rs b/rom/dev/src/flow/cold_reset/mod.rs
index 90dbaa7d..9b73b07b 100644
--- a/rom/dev/src/flow/cold_reset/mod.rs
+++ b/rom/dev/src/flow/cold_reset/mod.rs
@@ -62,18 +62,22 @@ impl ColdResetFlow {
         cprintln!("[cold-reset] ++");
 
         // Execute IDEVID layer
-        let idevid_layer_output = InitDevIdLayer::derive(env)?;
+        let mut idevid_layer_output = InitDevIdLayer::derive(env)?;
         let ldevid_layer_input = dice_input_from_output(&idevid_layer_output);
 
         // Execute LDEVID layer
-        let ldevid_layer_output = LocalDevIdLayer::derive(env, &ldevid_layer_input)?;
+        let result = LocalDevIdLayer::derive(env, &ldevid_layer_input);
+        idevid_layer_output.zeroize();
+        let mut ldevid_layer_output = result?;
         let fmc_layer_input = dice_input_from_output(&ldevid_layer_output);
 
         // Download and validate firmware.
-        let fw_proc_info = FirmwareProcessor::process(env)?;
+        let mut fw_proc_info = FirmwareProcessor::process(env)?;
 
         // Execute FMCALIAS layer
         FmcAliasLayer::derive(env, &fmc_layer_input, &fw_proc_info)?;
+        ldevid_layer_output.zeroize();
+        fw_proc_info.zeroize();
 
         cprintln!("[cold-reset] --");
 


Test patch:
diff --git a/drivers/test-fw/src/bin/doe_tests.rs b/drivers/test-fw/src/bin/doe_tests.rs
index fb9814b4..588cfdad 100644
--- a/drivers/test-fw/src/bin/doe_tests.rs
+++ b/drivers/test-fw/src/bin/doe_tests.rs
@@ -52,8 +52,8 @@ fn test_decrypt() {
     let mut result = Array4x12::default();
     hmac384
         .hmac(
-            Hmac384Key::Key(KeyReadArgs { id: KeyId::KeyId0 }),
-            Hmac384Data::Slice("Hello world!".as_bytes()),
+            &Hmac384Key::Key(KeyReadArgs { id: KeyId::KeyId0 }),
+            &Hmac384Data::Slice("Hello world!".as_bytes()),
             &mut trng,
             Hmac384Tag::Array4x12(&mut result),
         )
@@ -64,8 +64,8 @@ fn test_decrypt() {
     let mut result = Array4x12::default();
     hmac384
         .hmac(
-            Hmac384Key::Array4x12(&Array4x12::new(DOE_TEST_HMAC_KEY)),
-            Hmac384Data::Key(KeyReadArgs { id: KeyId::KeyId0 }),
+            &Hmac384Key::Array4x12(&Array4x12::new(DOE_TEST_HMAC_KEY)),
+            &Hmac384Data::Key(KeyReadArgs { id: KeyId::KeyId0 }),
             &mut trng,
             Hmac384Tag::Array4x12(&mut result),
         )
@@ -79,8 +79,8 @@ fn test_decrypt() {
     let mut result = Array4x12::default();
     hmac384
         .hmac(
-            Hmac384Key::Key(KeyReadArgs { id: KeyId::KeyId1 }),
-            Hmac384Data::Slice("Hello world!".as_bytes()),
+            &Hmac384Key::Key(KeyReadArgs { id: KeyId::KeyId1 }),
+            &Hmac384Data::Slice("Hello world!".as_bytes()),
             &mut trng,
             Hmac384Tag::Array4x12(&mut result),
         )
@@ -91,8 +91,8 @@ fn test_decrypt() {
     let mut result = Array4x12::default();
     hmac384
         .hmac(
-            Hmac384Key::Array4x12(&Array4x12::new(DOE_TEST_HMAC_KEY)),
-            Hmac384Data::Key(KeyReadArgs { id: KeyId::KeyId1 }),
+            &Hmac384Key::Array4x12(&Array4x12::new(DOE_TEST_HMAC_KEY)),
+            &Hmac384Data::Key(KeyReadArgs { id: KeyId::KeyId1 }),
             &mut trng,
             Hmac384Tag::Array4x12(&mut result),
         )
diff --git a/drivers/test-fw/src/bin/ecc384_tests.rs b/drivers/test-fw/src/bin/ecc384_tests.rs
index db31e0a8..87150cd3 100644
--- a/drivers/test-fw/src/bin/ecc384_tests.rs
+++ b/drivers/test-fw/src/bin/ecc384_tests.rs
@@ -71,7 +71,7 @@ fn test_gen_key_pair() {
     let seed = [0u8; 48];
     let mut priv_key = Array4x12::default();
     let result = ecc.key_pair(
-        Ecc384Seed::from(&Ecc384Scalar::from(seed)),
+        &Ecc384Seed::from(&Ecc384Scalar::from(seed)),
         &Array4x12::default(),
         &mut trng,
         Ecc384PrivKeyOut::from(&mut priv_key),
@@ -135,7 +135,7 @@ fn test_gen_key_pair_with_iv() {
 
     let mut priv_key = Array4x12::default();
     let result = ecc.key_pair(
-        Ecc384Seed::from(&Ecc384Scalar::from(seed)),
+        &Ecc384Seed::from(&Ecc384Scalar::from(seed)),
         &Array4x12::from(nonce),
         &mut trng,
         Ecc384PrivKeyOut::from(&mut priv_key),
@@ -160,7 +160,7 @@ fn test_sign() {
     };
     let digest = Array4x12::new([0u32; 12]);
     let result = ecc.sign(
-        Ecc384PrivKeyIn::from(&Array4x12::from(PRIV_KEY)),
+        &Ecc384PrivKeyIn::from(&Array4x12::from(PRIV_KEY)),
         &digest,
         &mut trng,
     );
@@ -183,7 +183,7 @@ fn test_verify() {
     };
     let digest = Array4x12::new([0u32; 12]);
     let result = ecc.sign(
-        Ecc384PrivKeyIn::from(&Array4x12::from(PRIV_KEY)),
+        &Ecc384PrivKeyIn::from(&Array4x12::from(PRIV_KEY)),
         &digest,
         &mut trng,
     );
@@ -211,7 +211,7 @@ fn test_verify_failure() {
     };
     let digest = Array4x12::new([0u32; 12]);
     let result = ecc.sign(
-        Ecc384PrivKeyIn::from(&Array4x12::from(PRIV_KEY)),
+        &Ecc384PrivKeyIn::from(&Array4x12::from(PRIV_KEY)),
         &digest,
         &mut trng,
     );
@@ -247,7 +247,7 @@ fn test_kv_seed_from_input_msg_from_input() {
         usage: KeyUsage::default().set_ecc_private_key_en(),
     };
     let result = ecc.key_pair(
-        Ecc384Seed::from(&Ecc384Scalar::from(seed)),
+        &Ecc384Seed::from(&Ecc384Scalar::from(seed)),
         &Array4x12::default(),
         &mut trng,
         Ecc384PrivKeyOut::from(key_out_1),
@@ -263,7 +263,7 @@ fn test_kv_seed_from_input_msg_from_input() {
     let digest = Array4x12::new([0u32; 12]);
     let key_in_1 = KeyReadArgs::new(KeyId::KeyId2);
 
-    let result = ecc.sign(key_in_1.into(), &digest, &mut trng);
+    let result = ecc.sign(&key_in_1.into(), &digest, &mut trng);
     assert!(result.is_ok());
     let signature = result.unwrap();
     assert_eq!(signature.r, Ecc384Scalar::from(SIGNATURE_R));
@@ -308,7 +308,7 @@ fn test_kv_seed_from_kv_msg_from_input() {
         usage: KeyUsage::default().set_ecc_key_gen_seed_en(),
     };
     let result = ecc.key_pair(
-        Ecc384Seed::from(&Ecc384Scalar::from(seed)),
+        &Ecc384Seed::from(&Ecc384Scalar::from(seed)),
         &Array4x12::default(),
         &mut trng,
         Ecc384PrivKeyOut::from(key_out_1),
@@ -346,7 +346,7 @@ fn test_kv_seed_from_kv_msg_from_input() {
         usage: KeyUsage::default().set_ecc_private_key_en(),
     };
     let result = ecc.key_pair(
-        Ecc384Seed::from(key_in_seed),
+        &Ecc384Seed::from(key_in_seed),
         &Array4x12::default(),
         &mut trng,
         Ecc384PrivKeyOut::from(key_out_priv_key),
@@ -383,7 +383,7 @@ fn test_kv_seed_from_kv_msg_from_input() {
         0xe8, 0x8c, 0x10,
     ];
     let key_in_priv_key = KeyReadArgs::new(KeyId::KeyId1);
-    let result = ecc.sign(key_in_priv_key.into(), &Array4x12::from(msg), &mut trng);
+    let result = ecc.sign(&key_in_priv_key.into(), &Array4x12::from(msg), &mut trng);
     assert!(result.is_ok());
     let signature = result.unwrap();
     assert_eq!(signature.r, Ecc384Scalar::from(sig_r));
diff --git a/drivers/test-fw/src/bin/hmac384_tests.rs b/drivers/test-fw/src/bin/hmac384_tests.rs
index 4835920f..1d0df68e 100755
--- a/drivers/test-fw/src/bin/hmac384_tests.rs
+++ b/drivers/test-fw/src/bin/hmac384_tests.rs
@@ -59,8 +59,8 @@ fn test_hmac0() {
 
     let mut out_tag = Array4x12::default();
     let actual = hmac384.hmac(
-        (&Array4x12::from(key)).into(),
-        (&data).into(),
+        &(&Array4x12::from(key)).into(),
+        &(&data).into(),
         &mut trng,
         (&mut out_tag).into(),
     );
@@ -101,9 +101,9 @@ fn test_hmac1() {
 
     let mut out_tag = Array4x12::default();
     let actual = hmac384.hmac(
-        (&Array4x12::from(key)).into(),
-        (&data).into(),
-        &mut &mut trng,
+        &(&Array4x12::from(key)).into(),
+        &(&data).into(),
+        &mut trng,
         (&mut out_tag).into(),
     );
 
@@ -132,7 +132,7 @@ fn test_hmac3() {
         usage: KeyUsage::default().set_hmac_key_en(),
     };
     let result = ecc.key_pair(
-        Ecc384Seed::from(&Ecc384Scalar::from(seed)),
+        &Ecc384Seed::from(&Ecc384Scalar::from(seed)),
         &Array4x12::default(),
         &mut trng,
         Ecc384PrivKeyOut::from(key_out_1),
@@ -156,7 +156,12 @@ fn test_hmac3() {
 
     let mut out_tag = Array4x12::default();
     let key = KeyReadArgs::new(KeyId::KeyId0);
-    let actual = hmac384.hmac(key.into(), (&data).into(), &mut trng, (&mut out_tag).into());
+    let actual = hmac384.hmac(
+        &key.into(),
+        &(&data).into(),
+        &mut trng,
+        (&mut out_tag).into(),
+    );
 
     assert!(actual.is_ok());
     assert_eq!(out_tag, Array4x12::from(result));
@@ -183,7 +188,7 @@ fn test_hmac4() {
         usage: KeyUsage::default().set_hmac_key_en(),
     };
     let result = ecc.key_pair(
-        Ecc384Seed::from(&Ecc384Scalar::from(seed)),
+        &Ecc384Seed::from(&Ecc384Scalar::from(seed)),
         &Array4x12::default(),
         &mut trng,
         Ecc384PrivKeyOut::from(key_out_1),
@@ -212,7 +217,12 @@ fn test_hmac4() {
     let mut out_tag = Array4x12::default();
     let key = KeyReadArgs::new(KeyId::KeyId0);
 
-    let actual = hmac384.hmac(key.into(), (&data).into(), &mut trng, (&mut out_tag).into());
+    let actual = hmac384.hmac(
+        &key.into(),
+        &(&data).into(),
+        &mut trng,
+        (&mut out_tag).into(),
+    );
 
     assert!(actual.is_ok());
     assert_eq!(out_tag, Array4x12::from(result));
@@ -239,7 +249,7 @@ fn test_hmac5() {
         usage: KeyUsage::default().set_hmac_key_en(),
     };
     let result = ecc.key_pair(
-        Ecc384Seed::from(&Ecc384Scalar::from(seed)),
+        &Ecc384Seed::from(&Ecc384Scalar::from(seed)),
         &Array4x12::default(),
         &mut trng,
         Ecc384PrivKeyOut::from(key_out_1),
@@ -268,7 +278,12 @@ fn test_hmac5() {
 
     let mut out_tag = Array4x12::default();
     let key = KeyReadArgs::new(KeyId::KeyId0);
-    let actual = hmac384.hmac(key.into(), (&data).into(), &mut trng, (&mut out_tag).into());
+    let actual = hmac384.hmac(
+        &key.into(),
+        &(&data).into(),
+        &mut trng,
+        (&mut out_tag).into(),
+    );
 
     assert!(actual.is_ok());
     assert_eq!(out_tag, Array4x12::from(result));
@@ -313,7 +328,7 @@ fn test_hmac6() {
         usage: KeyUsage::default().set_hmac_key_en(),
     };
     let result = ecc.key_pair(
-        Ecc384Seed::from(&Ecc384Scalar::from(seed)),
+        &Ecc384Seed::from(&Ecc384Scalar::from(seed)),
         &Array4x12::default(),
         &mut trng,
         Ecc384PrivKeyOut::from(key_out_1),
@@ -337,7 +352,12 @@ fn test_hmac6() {
 
     // Take the Data Generate the Tag in buffer
     let mut out_tag = Array4x12::default();
-    let actual = hmac384.hmac(key.into(), (&data).into(), &mut trng, (&mut out_tag).into());
+    let actual = hmac384.hmac(
+        &key.into(),
+        &(&data).into(),
+        &mut trng,
+        (&mut out_tag).into(),
+    );
     assert!(actual.is_ok());
     assert_eq!(out_tag, Array4x12::from(result));
 
@@ -351,8 +371,8 @@ fn test_hmac6() {
     // Generate the HMAC of the Tag in to a hmac_step_1
     let mut hmac_step_1 = Array4x12::default();
     let actual = hmac384.hmac(
-        key.into(),
-        (&result).into(),
+        &key.into(),
+        &(&result).into(),
         &mut trng,
         (&mut hmac_step_1).into(),
     );
@@ -361,7 +381,7 @@ fn test_hmac6() {
 
     // Generate the Tag Of Original Data and put the tag In KV @5.  KV @5 will be used as data in the next step
     let out_tag = KeyWriteArgs::new(KeyId::KeyId5, KeyUsage::default().set_hmac_data_en());
-    let actual = hmac384.hmac(key.into(), (&data).into(), &mut trng, out_tag.into());
+    let actual = hmac384.hmac(&key.into(), &(&data).into(), &mut trng, out_tag.into());
     assert!(actual.is_ok());
 
     // Data From Key Vault generate HMAC in to output buffer
@@ -369,8 +389,8 @@ fn test_hmac6() {
     let data_input: KeyReadArgs = KeyReadArgs::new(KeyId::KeyId5);
 
     let actual = hmac384.hmac(
-        key.into(),
-        data_input.into(),
+        &key.into(),
+        &data_input.into(),
         &mut trng,
         (&mut hmac_step_2).into(),
     );
@@ -407,7 +427,12 @@ fn test_kdf(
     let kdf_key_in = KeyReadArgs::new(KeyId::KeyId0);
 
     hmac384
-        .hmac((&key_0).into(), msg_0.into(), &mut trng, kdf_key_out.into())
+        .hmac(
+            &(&key_0).into(),
+            &(&msg_0.into()),
+            &mut trng,
+            kdf_key_out.into(),
+        )
         .unwrap();
 
     let kdf_out = KeyWriteArgs::new(out_key_id, KeyUsage::default().set_hmac_key_en());
@@ -426,8 +451,8 @@ fn test_kdf(
     let hmac_key = KeyReadArgs::new(out_key_id);
     hmac384
         .hmac(
-            hmac_key.into(),
-            msg_1.into(),
+            &hmac_key.into(),
+            &(&msg_1.into()),
             &mut trng,
             (&mut out_tag).into(),
         )
@@ -598,8 +623,8 @@ fn test_hmac_multi_block() {
 
     let mut out_tag = Array4x12::default();
     let actual = hmac384.hmac(
-        (&Array4x12::from(key)).into(),
-        (&data).into(),
+        &(&Array4x12::from(key)).into(),
+        &(&data).into(),
         &mut trng,
         (&mut out_tag).into(),
     );
@@ -647,8 +672,8 @@ fn test_hmac_exact_single_block() {
 
     let mut out_tag = Array4x12::default();
     let actual = hmac384.hmac(
-        (&Array4x12::from(key)).into(),
-        (&data).into(),
+        &(&Array4x12::from(key)).into(),
+        &(&data).into(),
         &mut trng,
         (&mut out_tag).into(),
     );
@@ -697,7 +722,7 @@ fn test_hmac_multi_block_two_step() {
     let mut out_tag = Array4x12::default();
     let mut hmac_op = hmac384
         .hmac_init(
-            (&Array4x12::from(key)).into(),
+            &(&Array4x12::from(key)).into(),
             &mut trng,
             (&mut out_tag).into(),
         )