Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TpmtSignature and TpmtSigScheme #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
65 changes: 65 additions & 0 deletions base/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,23 @@ pub enum TpmiAlgRsaScheme{
OAEP = TpmAlgId::OAEP.0,
}

/// TpmiAlgSigScheme represents values that may appear in the scheme parameter of a TpmtSigScheme (TPMI_ALG_SIG_SCHEME).
/// See definition in Part 2: Structures, section 9.37.
#[open_enum]
#[repr(u16)]
#[rustfmt::skip] #[derive(Debug)] // Keep debug derivation separate for open_enum override.
#[derive(Copy, Clone, PartialEq, Default, Marshalable)]
#[allow(clippy::upper_case_acronyms)]
pub enum TpmiAlgSigScheme {
RSAPSS = TpmAlgId::RSAPSS.0,
RSASSA = TpmAlgId::RSASSA.0,
ECDSA = TpmAlgId::ECDSA.0,
ECDAA = TpmAlgId::ECDAA.0,
SM2 = TpmAlgId::SM2.0,
ECSchnorr = TpmAlgId::ECSchnorr.0,
HMAC = TpmAlgId::HMAC.0,
}

/// TpmiAlgEccScheme represents values that may appear in the scheme parameter of a TpmtEccScheme (TPMI_ALG_ECC_SCHEME).
/// See definition in Part 2: Structures, section 11.2.5.4.
#[open_enum]
Expand Down Expand Up @@ -922,6 +939,54 @@ pub struct TpmsSymCipherParms {
pub sym: TpmtSymDefObject,
}

#[repr(C)]
#[derive(Clone, Copy, PartialEq, Debug, Marshalable)]
pub struct TpmsSignatureRsa {
pub hash: TpmiAlgHash,
pub sig: Tpm2bPublicKeyRsa,
}

#[repr(C)]
#[derive(Clone, Copy, PartialEq, Debug, Marshalable)]
pub struct TpmsSignatureEcc {
pub hash: TpmiAlgHash,
pub signature_r: Tpm2bEccParameter,
pub signature_s: Tpm2bEccParameter,
}

pub type TpmsSignatureRsassa = TpmsSignatureRsa;
pub type TpmsSignatureRsapss = TpmsSignatureRsa;
pub type TpmsSignatureEcdsa = TpmsSignatureEcc;
pub type TpmsSignatureEcdaa = TpmsSignatureEcc;
pub type TpmsSignatureSm2 = TpmsSignatureEcc;
pub type TpmsSignatureEcschnorr = TpmsSignatureEcc;

#[repr(C, u16)]
#[derive(Clone, Copy, PartialEq, Debug, Discriminant, Marshalable)]
pub enum TpmtSignature {
Rsassa(TpmsSignatureRsassa) = TpmAlgId::RSASSA.0,
Rsapss(TpmsSignatureRsapss) = TpmAlgId::RSAPSS.0,
Ecdsa(TpmsSignatureEcdsa) = TpmAlgId::ECDSA.0,
Ecdaa(TpmsSignatureEcdaa) = TpmAlgId::ECDAA.0,
Sm2(TpmsSignatureSm2) = TpmAlgId::SM2.0,
Ecschnorr(TpmsSignatureEcschnorr) = TpmAlgId::ECSchnorr.0,
Hmac(TpmtHa) = TpmAlgId::HMAC.0,
Null(TpmsEmpty) = TpmAlgId::Null.0,
}

#[repr(C, u16)]
#[derive(Clone, Copy, PartialEq, Debug, Discriminant, Marshalable)]
pub enum TpmtSigScheme {
Rsassa(TpmsSigSchemeRsassa) = TpmAlgId::RSASSA.0,
Rsapss(TpmsSigSchemeRsapss) = TpmAlgId::RSAPSS.0,
Ecdsa(TpmsSigSchemeEcdsa) = TpmAlgId::ECDSA.0,
Ecdaa(TpmsSigSchemeEcdaa) = TpmAlgId::ECDAA.0,
Sm2(TpmsSigSchemeSm2) = TpmAlgId::SM2.0,
Ecschnorr(TpmsSigSchemeEcschnorr) = TpmAlgId::ECSchnorr.0,
Hmac(TpmsSchemeHmac) = TpmAlgId::HMAC.0,
Null(TpmsEmpty) = TpmAlgId::Null.0,
}

#[repr(C)]
#[derive(Clone, Copy, PartialEq, Debug, Marshalable)]
pub struct TpmsSchemeHash {
Expand Down
Loading