Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ pub mod certs;

pub mod firmware;
pub mod launch;
#[cfg(all(any(feature = "sev", feature = "snp"), feature = "openssl"))]
#[cfg(all(
any(feature = "sev", feature = "snp"),
any(feature = "openssl", feature = "crypto_nossl")
))]
pub mod measurement;
#[cfg(all(target_os = "linux", feature = "openssl", feature = "sev"))]
pub mod session;
Expand Down
10 changes: 10 additions & 0 deletions src/measurement/gctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,18 @@
//! Operations to handle and create a Guest Context
use std::convert::TryInto;

#[cfg(feature = "openssl")]
use openssl::sha::sha384;

#[cfg(feature = "crypto_nossl")]
fn sha384(data: &[u8]) -> [u8; 48] {
use sha2::Digest;
let hash = sha2::Sha384::digest(data);
let mut out = [0u8; 48];
out.copy_from_slice(&hash);
out
}

use crate::{
error::*,
launch::PageType,
Expand Down
9 changes: 6 additions & 3 deletions src/measurement/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! Everything one needs to calculate a launch measurement for a SEV encrypted confidential guest.
//! This includes, GCTX, SEV-HASHES, VMSA and OVMF pages.

#[cfg(all(feature = "snp", feature = "openssl"))]
#[cfg(all(feature = "snp", any(feature = "openssl", feature = "crypto_nossl")))]
pub mod gctx;

#[cfg(any(feature = "sev", feature = "snp"))]
Expand All @@ -12,13 +12,16 @@ pub mod ovmf;
#[cfg(any(feature = "sev", feature = "snp"))]
pub mod vmsa;

#[cfg(all(any(feature = "sev", feature = "snp"), feature = "openssl"))]
#[cfg(all(
any(feature = "sev", feature = "snp"),
any(feature = "openssl", feature = "crypto_nossl")
))]
Comment on lines +15 to +18
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to this PR, @DGonzalezVillal we should take a serious look on simplifying these combination conditionals. For example, AFAIU any(feature = "sev", feature = "snp") will always be true.

pub mod sev_hashes;

#[cfg(any(feature = "sev", feature = "snp"))]
pub mod vcpu_types;

#[cfg(all(feature = "snp", feature = "openssl"))]
#[cfg(all(feature = "snp", any(feature = "openssl", feature = "crypto_nossl")))]
pub mod snp;

#[cfg(all(feature = "sev", feature = "openssl"))]
Expand Down
10 changes: 10 additions & 0 deletions src/measurement/sev_hashes.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
// SPDX-License-Identifier: Apache-2.0

//! Operations to handle OVMF SEV-HASHES
#[cfg(feature = "openssl")]
use openssl::sha::sha256;

#[cfg(feature = "crypto_nossl")]
fn sha256(data: &[u8]) -> [u8; 32] {
use sha2::Digest;
let hash = sha2::Sha256::digest(data);
let mut out = [0u8; 32];
out.copy_from_slice(&hash);
out
}
use std::fs::File;
use std::io::Write;
use std::{
Expand Down
Loading