Skip to content

Commit 6b127e0

Browse files
committed
[dpe] Update to non-generic crypto API
Having generics in the API was duplicating much of the complicated DPE code (certificate encoding) which bloated the code size unnecessarily. DPE was updated to remove the generics so this gains some codespace back.
1 parent bc2900d commit 6b127e0

20 files changed

Lines changed: 361 additions & 264 deletions

Cargo.lock

Lines changed: 14 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ caliptra-auth-man-gen = { path = "auth-manifest/gen", default-features = false }
9898
caliptra-auth-man-types = { path = "auth-manifest/types", default-features = false }
9999

100100
# The caliptra-cfi commit rev MUST match the one in caliptra-dpe or the Caliptra runtime will be bloated with duplicate symbols.
101-
caliptra-cfi-lib = { git = "https://github.com/chipsalliance/caliptra-cfi.git", package = "caliptra-cfi-lib", rev = "767d4ef59a106aea683b883c07bd65456fb3ba6b", default-features = false, features = ["cfi", "cfi-counter" ] }
102-
caliptra-cfi-derive = { git = "https://github.com/chipsalliance/caliptra-cfi.git", package = "caliptra-cfi-derive", rev = "767d4ef59a106aea683b883c07bd65456fb3ba6b"}
101+
caliptra-cfi-lib = { git = "https://github.com/chipsalliance/caliptra-cfi.git", package = "caliptra-cfi-lib", rev = "aa96c53073ce7f298f7482c1ac57f5f65ffc115e", default-features = false, features = ["cfi", "cfi-counter" ] }
102+
caliptra-cfi-derive = { git = "https://github.com/chipsalliance/caliptra-cfi.git", package = "caliptra-cfi-derive", rev = "aa96c53073ce7f298f7482c1ac57f5f65ffc115e"}
103103

104104
caliptra-common = { path = "common", default-features = false }
105105
caliptra-coverage = { path = "coverage" }
@@ -109,9 +109,9 @@ caliptra-drivers = { path = "drivers" }
109109
caliptra-drivers-test-bin = { path = "drivers/test-fw" }
110110

111111
# DPE dependencies; keep git revs in sync alongside test/dpe_verification/go.mod
112-
caliptra-dpe = { git = "https://github.com/chipsalliance/caliptra-dpe", rev = "a883222aae7b9306aab089d6efab85d93dbaab26", default-features = false, features = ["hybrid"] }
113-
caliptra-dpe-crypto = { git = "https://github.com/chipsalliance/caliptra-dpe", rev = "a883222aae7b9306aab089d6efab85d93dbaab26", default-features = false }
114-
caliptra-dpe-platform = { git = "https://github.com/chipsalliance/caliptra-dpe", rev = "a883222aae7b9306aab089d6efab85d93dbaab26", default-features = false }
112+
caliptra-dpe = { git = "https://github.com/chipsalliance/caliptra-dpe", rev = "2635f47237cdb60029e8aa8ca6aebc27d88b0e1f", default-features = false, features = ["hybrid"] }
113+
caliptra-dpe-crypto = { git = "https://github.com/chipsalliance/caliptra-dpe", rev = "2635f47237cdb60029e8aa8ca6aebc27d88b0e1f", default-features = false }
114+
caliptra-dpe-platform = { git = "https://github.com/chipsalliance/caliptra-dpe", rev = "2635f47237cdb60029e8aa8ca6aebc27d88b0e1f", default-features = false }
115115

116116
caliptra-emu-bus = { path = "sw-emulator/lib/bus" }
117117
caliptra-emu-cpu = { path = "sw-emulator/lib/cpu" }

drivers/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ bitfield.workspace = true
1414
bitflags.workspace = true
1515
caliptra-api.workspace = true
1616
caliptra-dpe = { workspace = true, optional = true }
17+
caliptra-dpe-crypto = { workspace = true, optional = true }
1718
caliptra-error = { workspace = true, default-features = false }
1819
caliptra-image-types.workspace = true
1920
caliptra-lms-types.workspace = true
@@ -37,7 +38,7 @@ std = []
3738
emu = []
3839
riscv = []
3940
rom = []
40-
runtime = ["dep:caliptra-dpe"]
41+
runtime = ["dep:caliptra-dpe", "dep:caliptra-dpe-crypto"]
4142
fmc = []
4243
fpga_realtime = ["caliptra-hw-model/fpga_realtime"]
4344
fpga_subsystem = ["caliptra-hw-model/fpga_subsystem"]

drivers/src/sha2_512_384.rs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,68 @@ pub struct Sha384;
628628
/// SHA-512 variant implementation
629629
pub struct Sha512;
630630

631+
#[cfg(feature = "runtime")]
632+
pub struct DpeHasher<'a> {
633+
op: Sha2DigestOp<'a, Sha384>,
634+
active: Option<()>,
635+
}
636+
637+
#[cfg(feature = "runtime")]
638+
impl<'a> DpeHasher<'a> {
639+
pub fn new(sha: &'a mut Sha2_512_384) -> Result<Self, CaliptraError> {
640+
Ok(Self {
641+
op: sha.sha384_digest_init()?,
642+
active: None,
643+
})
644+
}
645+
646+
pub fn driver(&mut self) -> &mut Sha2_512_384 {
647+
self.op.sha
648+
}
649+
}
650+
651+
#[cfg(feature = "runtime")]
652+
impl caliptra_dpe_crypto::Hasher for DpeHasher<'_> {
653+
fn initialize(&mut self) -> Result<(), caliptra_dpe_crypto::CryptoError> {
654+
self.op.state = Sha2DigestState::Init;
655+
self.op.buf = [0u8; SHA512_BLOCK_BYTE_SIZE];
656+
self.op.buf_idx = 0;
657+
self.op.data_size = 0;
658+
self.active = Some(());
659+
Ok(())
660+
}
661+
fn update(&mut self, bytes: &[u8]) -> Result<(), caliptra_dpe_crypto::CryptoError> {
662+
if self.active.is_none() {
663+
return Err(caliptra_dpe_crypto::CryptoError::HashError(u32::from(
664+
CaliptraError::DRIVER_SHA2_512_384_INVALID_STATE_ERR,
665+
)));
666+
}
667+
self.op
668+
.update(bytes)
669+
.map_err(|e| caliptra_dpe_crypto::CryptoError::HashError(u32::from(e)))?;
670+
Ok(())
671+
}
672+
fn finish(&mut self) -> Result<caliptra_dpe_crypto::Digest, caliptra_dpe_crypto::CryptoError> {
673+
self.active
674+
.take()
675+
.ok_or(caliptra_dpe_crypto::CryptoError::HashError(0))?;
676+
let mut digest = Array4x12::default();
677+
Sha2DigestOp {
678+
sha: self.op.sha,
679+
state: self.op.state,
680+
buf: self.op.buf,
681+
buf_idx: self.op.buf_idx,
682+
data_size: self.op.data_size,
683+
_phantom: core::marker::PhantomData::<Sha384>,
684+
}
685+
.finalize(&mut digest)
686+
.map_err(|e| caliptra_dpe_crypto::CryptoError::HashError(u32::from(e)))?;
687+
Ok(caliptra_dpe_crypto::Digest::Sha384(
688+
caliptra_dpe_crypto::Sha384(digest.into()),
689+
))
690+
}
691+
}
692+
631693
/// SHA-384 key access error trait
632694
trait Sha384KeyAccessErr {
633695
/// Convert to read data operation error

0 commit comments

Comments
 (0)