Skip to main content

clerk_report/
lib.rs

1pub mod verification;
2mod versions;
3
4pub use sev::firmware::guest::AttestationReport;
5pub use versions::*;
6
7pub enum ReportSignature {
8    Ecdsa384 { r: [u8; 72], s: [u8; 72] },
9}
10
11impl TryFrom<&ReportSignature> for p384::ecdsa::Signature {
12    type Error = p384::ecdsa::Error;
13
14    fn try_from(value: &ReportSignature) -> Result<Self, Self::Error> {
15        match value {
16            ReportSignature::Ecdsa384 { r, s } => {
17                // `Signature::from_scalars` expects big endian values, but the valuev from the
18                // attestation report are little endian. Additionally, values are larger than
19                // required and zero filled
20                if r[48..] != [0; 24] || s[48..] != [0; 24] {
21                    return Err(Self::Error::new());
22                }
23                let mut r: [u8; 48] = r[..48].try_into().expect("Should have correct size");
24                r.reverse();
25                let mut s: [u8; 48] = s[..48].try_into().expect("Should have correct size");
26                s.reverse();
27
28                p384::ecdsa::Signature::from_scalars(r, s)
29            }
30        }
31    }
32}
33
34#[derive(Debug)]
35pub enum SignatureError {
36    UnknownAlgorithm,
37}
38
39impl TryFrom<&AttestationReport> for ReportSignature {
40    type Error = SignatureError;
41
42    fn try_from(report: &AttestationReport) -> Result<Self, Self::Error> {
43        match report.sig_algo {
44            1 => Ok(ReportSignature::Ecdsa384 {
45                r: *report.signature.r(),
46                s: *report.signature.s(),
47            }),
48            _ => Err(SignatureError::UnknownAlgorithm),
49        }
50    }
51}