Skip to content

Commit

Permalink
Switching to custom parser for binary.
Browse files Browse the repository at this point in the history
- Refactoring some misplaced code
- Adding custom parsing functionality
- Implemented new and updated existing unit tests to match new functionality
- Implemented parsing library in place of bincode where possible (eventually will completely remove it)
- Added clippy fixes
- Updated README.md

Signed-off-by: Larry Dewey <larry.dewey@amd.com>
  • Loading branch information
larrydewey committed Mar 4, 2025
1 parent 374d825 commit a4917e8
Show file tree
Hide file tree
Showing 35 changed files with 2,300 additions and 1,330 deletions.
365 changes: 205 additions & 160 deletions Cargo.lock

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@ snp = []
crypto_nossl = ["dep:p384", "dep:rsa", "dep:sha2", "dep:x509-cert"]

[target.'cfg(target_os = "linux")'.dependencies]
iocuddle = "0.1"
iocuddle = "^0.1"

[dependencies]
openssl = { version = "0.10", optional = true }
serde = { version = "1.0", features = ["derive"] }
serde_bytes = "0.11"
serde_arrays = "0.1.0"
bitflags = "1.2"
codicon = "3.0"
dirs = "5.0"
Expand All @@ -69,12 +70,12 @@ x509-cert = { version = "0.2.5", optional = true }
byteorder = "1.4.3"
base64 = "0.22.1"
rdrand = { version = "^0.8", optional = true }
reqwest = { version="0.11.10", features = ["blocking"], optional = true }
tokio = {version = "1.29.1", features =["rt-multi-thread"], optional = true }
reqwest = { version = "0.11.10", features = ["blocking"], optional = true }
tokio = { version = "1.29.1", features = ["rt-multi-thread"], optional = true }

[target.'cfg(target_os = "linux")'.dev-dependencies]
kvm-ioctls = ">=0.16"
kvm-bindings = ">=0.9.1"

[dev-dependencies]
kvm-bindings = ">=0.9.1"
serial_test = "3.0"
2 changes: 1 addition & 1 deletion src/certs/sev/sev/cert/v1/body/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use super::*;
#[repr(C, packed)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct Data {
pub firmware: crate::Version,
pub firmware: crate::firmware::host::Version,
pub reserved: u16,
pub key: key::PubKey,
}
Expand Down
40 changes: 13 additions & 27 deletions src/certs/sev/sev/cert/v1/sig/ecdsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,21 @@
#[cfg(feature = "openssl")]
use {super::*, openssl::ecdsa};

use crate::util::hexdump;
use crate::util::array::Array;

use serde::{Deserialize, Serialize};
use serde_big_array::BigArray;

const SIG_PIECE_SIZE: usize = std::mem::size_of::<[u8; 72]>();

/// An ECDSA Signature.
#[repr(C)]
#[derive(Copy, Clone, Deserialize, Serialize)]
#[derive(Default, Copy, Clone, Deserialize, Serialize)]
pub struct Signature {
#[serde(with = "BigArray")]
r: [u8; 72],
#[serde(with = "BigArray")]
s: [u8; 72],
#[serde(with = "BigArray")]
_reserved: [u8; 512 - (SIG_PIECE_SIZE * 2)],
r: Array<u8, 72>,

s: Array<u8, 72>,

_reserved: Array<u8, { 512 - (SIG_PIECE_SIZE * 2) }>,
}

impl std::fmt::Debug for Signature {
Expand All @@ -40,17 +38,6 @@ impl PartialEq for Signature {
}
}

#[allow(clippy::derivable_impls)]
impl Default for Signature {
fn default() -> Self {
Signature {
r: [0u8; 72],
s: [0u8; 72],
_reserved: [0u8; (512 - (SIG_PIECE_SIZE * 2))],
}
}
}

impl std::fmt::Display for Signature {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
Expand All @@ -60,8 +47,7 @@ Signature:
R: {}
S: {}
"#,
hexdump(&self.r),
hexdump(&self.s)
self.r, self.s
)
}
}
Expand All @@ -71,9 +57,9 @@ impl From<ecdsa::EcdsaSig> for Signature {
#[inline]
fn from(value: ecdsa::EcdsaSig) -> Self {
Signature {
r: value.r().as_le_bytes(),
s: value.s().as_le_bytes(),
_reserved: [0; 512 - (SIG_PIECE_SIZE * 2)],
r: Array(value.r().as_le_bytes()),
s: Array(value.s().as_le_bytes()),
_reserved: Array([0; 512 - (SIG_PIECE_SIZE * 2)]),
}
}
}
Expand All @@ -94,8 +80,8 @@ impl TryFrom<&Signature> for ecdsa::EcdsaSig {

#[inline]
fn try_from(value: &Signature) -> Result<Self> {
let r = bn::BigNum::from_le(&value.r)?;
let s = bn::BigNum::from_le(&value.s)?;
let r = bn::BigNum::from_le(&*value.r)?;
let s = bn::BigNum::from_le(&*value.s)?;
Ok(ecdsa::EcdsaSig::from_private_components(r, s)?)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/certs/snp/builtin/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: Apache-2.0

/// Interfaces for retrieving builtin ARKs and ASKs for their respective generations.
//! Interfaces for retrieving builtin ARKs and ASKs for their respective generations.
/// Genoa generation.
pub mod genoa;
Expand Down
4 changes: 2 additions & 2 deletions src/certs/snp/ca/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// SPDX-License-Identifier: Apache-2.0
//! Operations for a Certificate Authority (CA) chain.
#[cfg(feature = "openssl")]
use openssl::x509::X509;

use super::*;

/// Operations for a Certificate Authority (CA) chain.
/// A Certificate Authority (CA) chain.
#[derive(Clone, Debug)]
pub struct Chain {
Expand Down
Loading

0 comments on commit a4917e8

Please sign in to comment.