Skip to content

Commit

Permalink
Use normal for loop instead of map+fold for populating PCRs
Browse files Browse the repository at this point in the history
Depending on optimizations applied by the compiler, it sometimes inserts
a panic in the PCR accumulation code that depends on map/fold.

It is unclear in which cases it will insert one and which it won't, but
for simplicity, replace this code with a for loop.
  • Loading branch information
jhand2 committed Mar 27, 2024
1 parent 326680c commit 9d8206e
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions runtime/src/pcr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,18 @@ impl GetPcrQuoteCmd {
.ok_or(CaliptraError::RUNTIME_MAILBOX_INVALID_PARAMS)?;

let pcr_hash = drivers.sha384.gen_pcr_hash(args.nonce.into())?;

let signature = drivers.ecc384.pcr_sign_flow(&mut drivers.trng)?;

let raw_pcrs = drivers.pcr_bank.read_all_pcrs();

let pcrs_as_bytes = raw_pcrs
.into_iter()
.map(|raw_pcr_value| raw_pcr_value.into())
.enumerate()
.fold([[0; 48]; 32], |mut acc, (idx, pcr_value)| {
acc[idx] = pcr_value;
acc
});
let mut pcrs = [[0u8; 48]; 32];
for (i, p) in raw_pcrs.iter().enumerate() {
pcrs[i] = p.into()
}

Ok(MailboxResp::QuotePcrs(QuotePcrsResp {
hdr: MailboxRespHeader::default(),
nonce: args.nonce,
pcrs: pcrs_as_bytes,
pcrs,
reset_ctrs: drivers.persistent_data.get().pcr_reset.all_counters(),
digest: pcr_hash.into(),
signature_r: signature.r.into(),
Expand Down

0 comments on commit 9d8206e

Please sign in to comment.