mirror of
https://github.com/matter-labs/teepot.git
synced 2025-07-21 15:13:56 +02:00
feat: add tdx-extend, sha384-extend and rtmr-calc
This enables pre-calculating the TDX rtmr[1,2,3] values for an attested boot process. Signed-off-by: Harald Hoyer <harald@matterlabs.dev>
This commit is contained in:
parent
fbc4897dad
commit
5d32396966
12 changed files with 603 additions and 2 deletions
14
bin/sha384-extend/Cargo.toml
Normal file
14
bin/sha384-extend/Cargo.toml
Normal file
|
@ -0,0 +1,14 @@
|
|||
[package]
|
||||
name = "sha384-extend"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
authors.workspace = true
|
||||
license.workspace = true
|
||||
repository.workspace = true
|
||||
homepage.workspace = true
|
||||
|
||||
[dependencies]
|
||||
anyhow.workspace = true
|
||||
clap.workspace = true
|
||||
hex.workspace = true
|
||||
sha2.workspace = true
|
39
bin/sha384-extend/src/main.rs
Normal file
39
bin/sha384-extend/src/main.rs
Normal file
|
@ -0,0 +1,39 @@
|
|||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright (c) 2024 Matter Labs
|
||||
|
||||
//! Extend the TDX measurement
|
||||
|
||||
#![deny(missing_docs)]
|
||||
#![deny(clippy::all)]
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use clap::Parser;
|
||||
use sha2::Digest;
|
||||
|
||||
/// Calculate a TDX rtmr or TPM pcr sha384 value by extending it
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(author, version, about, long_about = None)]
|
||||
struct Arguments {
|
||||
/// digest in hex to extend with
|
||||
#[arg(long)]
|
||||
extend: String,
|
||||
/// initial digest in hex
|
||||
#[arg(long)]
|
||||
digest: String,
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let args = Arguments::parse();
|
||||
|
||||
// Parse the digest string as a hex array
|
||||
let extend_bytes = hex::decode(&args.extend).context("Invalid digest format")?;
|
||||
let mut digest_bytes = hex::decode(&args.digest).context("Invalid digest format")?;
|
||||
|
||||
digest_bytes.extend(extend_bytes);
|
||||
|
||||
let bytes = sha2::Sha384::digest(&digest_bytes);
|
||||
let hex = hex::encode(bytes);
|
||||
|
||||
println!("{hex}");
|
||||
Ok(())
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue