[dice] Move bcc_main_flow to the library libdiced_open_dice

This cl splits the existing BccMainFlow wrapper with retries
into a raw version and a retry version. The former is
available in both std and nostd environment. The latter
returns a ZerorizeOnDrop struct containing Attestation CDI
and Sealing CDI. This struct is going to replace the
`DiceContext` in microdroid as it is sets all the CDIs to
zero when the struct goes out of scope, which is more secure.

This is part of the project of merging the two existing dice
wrapper libraries into one library libdiced_open_dice.

Test: atest diced_utils_test diced_sample_inputs_test \
diced_test diced_vendor_test diced_open_dice_cbor_test
Test: m pvmfw_img microdroid_manager && atest \
microdroid_manager_test
Bug: 267575445

Change-Id: I94444619fe2dcddf8541a6c9971c7e565c44dda1
diff --git a/diced/open_dice/src/retry.rs b/diced/open_dice/src/retry.rs
index 648fd91..6af6f00 100644
--- a/diced/open_dice/src/retry.rs
+++ b/diced/open_dice/src/retry.rs
@@ -17,10 +17,22 @@
 //! memory allocation on heap, currently we only expose these functions in
 //! std environment.
 
-use crate::bcc::bcc_format_config_descriptor;
+use crate::bcc::{bcc_format_config_descriptor, bcc_main_flow};
+use crate::dice::{Cdi, CdiValues, InputValues};
 use crate::error::{DiceError, Result};
 use std::ffi::CStr;
 
+/// Artifacts stores a set of dice artifacts comprising CDI_ATTEST, CDI_SEAL,
+/// and the BCC formatted attestation certificate chain.
+/// As we align with the DICE standards today, this is the certificate chain
+/// is also called DICE certificate chain.
+pub struct OwnedDiceArtifacts {
+    /// CDI Values.
+    pub cdi_values: CdiValues,
+    /// Boot Certificate Chain.
+    pub bcc: Vec<u8>,
+}
+
 /// Retries the given function with bigger output buffer size.
 fn retry_with_bigger_buffer<F>(mut f: F) -> Result<Vec<u8>>
 where
@@ -62,3 +74,27 @@
         bcc_format_config_descriptor(name, version, resettable, buffer)
     })
 }
+
+/// Executes the main BCC flow.
+///
+/// Given a full set of input values along with the current BCC and CDI values,
+/// computes the next CDI values and matching updated BCC.
+pub fn retry_bcc_main_flow(
+    current_cdi_attest: &Cdi,
+    current_cdi_seal: &Cdi,
+    bcc: &[u8],
+    input_values: &InputValues,
+) -> Result<OwnedDiceArtifacts> {
+    let mut next_cdi_values = CdiValues::default();
+    let next_bcc = retry_with_bigger_buffer(|next_bcc| {
+        bcc_main_flow(
+            current_cdi_attest,
+            current_cdi_seal,
+            bcc,
+            input_values,
+            &mut next_cdi_values,
+            next_bcc,
+        )
+    })?;
+    Ok(OwnedDiceArtifacts { cdi_values: next_cdi_values, bcc: next_bcc })
+}