// K2466-K2470: portability.tool_versions — QEMU EDK2 sürüm farkı // Invariant: Aynı imaj farklı araçlarda ölçülür // Positive: İki QEMU iki firmware // Counterexample: Aynı firmware ikinci diye sayılır // Acceptance: Araç hashleri ve başarısızlıklar ayrı pub const PORTABILITY_TOOL_VERSIONS_SCHEMA: &str = "turkos.os.portability.tool_versions.v1"; pub const PORTABILITY_TOOL_VERSIONS_INVARIANT: &str = "Aynı imaj farklı araçlarda ölçülür"; pub const PORTABILITY_TOOL_VERSIONS_POSITIVE: &str = "İki QEMU iki firmware"; pub const PORTABILITY_TOOL_VERSIONS_COUNTEREXAMPLE: &str = "Aynı firmware ikinci diye sayılır"; pub const PORTABILITY_TOOL_VERSIONS_ACCEPTANCE: &str = "Araç hashleri ve başarısızlıklar ayrı"; pub const EXPECTED_DISTINCT_QEMU_VERSIONS: u32 = 2; pub const EXPECTED_DISTINCT_FIRMWARE_IMAGES: u32 = 2; pub const EXPECTED_SEPARATE_TOOL_HASH_RECORDS: u32 = 4; pub const EXPECTED_DUPLICATE_FIRMWARE_ALIASES: u32 = 0; #[repr(u8)] #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum PortabilityToolVersionsError { SameFirmwareCountedAsSecond = 1, ImageNotMeasuredAcrossDistinctTools = 2, ToolHashesOrFailuresMerged = 3, DistinctQemuVersionsMismatch = 4, DistinctFirmwareImagesMismatch = 5, SeparateToolHashRecordsMismatch = 6, ZeroToolVersionsEpoch = 7, NonMonotonicToolVersionsEpoch = 8, ZeroToolVersionsMatrixDigest = 9, UnboundPortabilityToolVersionsDigest = 10, AlreadyCommitted = 11, } #[repr(C)] #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct PortabilityToolVersionsRequest { pub same_firmware_counted_as_second: bool, pub image_not_measured_across_distinct_tools: bool, pub tool_hashes_and_failures_kept_separate: bool, pub distinct_qemu_versions: u32, pub distinct_firmware_images: u32, pub separate_tool_hash_records: u32, pub tool_versions_epoch: u64, pub previous_tool_versions_epoch: u64, pub tool_versions_matrix_digest: u64, pub tool_versions_binding_digest: u64, } #[repr(C)] #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct PortabilityToolVersionsReceipt { pub distinct_qemu_versions: u32, pub distinct_firmware_images: u32, pub separate_tool_hash_records: u32, pub duplicate_firmware_aliases: u32, pub tool_hashes_and_failures_kept_separate: bool, pub tool_versions_epoch: u64, pub tool_versions_matrix_digest: u64, pub receipt_digest: u64, } pub const fn compute_portability_tool_versions_binding_digest( distinct_qemu_versions: u32, distinct_firmware_images: u32, separate_tool_hash_records: u32, duplicate_firmware_aliases: u32, tool_versions_epoch: u64, tool_versions_matrix_digest: u64, ) -> u64 { let mut h: u64 = 0xcbf2_9ce4_8422_2325; h = (h ^ 0x2470_5052_544c_5631).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ (distinct_qemu_versions as u64)).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ (distinct_firmware_images as u64)).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ (separate_tool_hash_records as u64)).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ (duplicate_firmware_aliases as u64)).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ tool_versions_epoch).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ tool_versions_matrix_digest).wrapping_mul(0x0000_0100_0000_01b3); h } pub struct PortabilityToolVersionsCoordinator { committed: bool, committed_total: u64, rejected_total: u64, tool_identity_refusals: u64, tool_accounting_refusals: u64, committed_receipt: Option, } impl PortabilityToolVersionsCoordinator { pub const fn new() -> Self { Self { committed: false, committed_total: 0, rejected_total: 0, tool_identity_refusals: 0, tool_accounting_refusals: 0, committed_receipt: None, } } pub fn is_committed(&self) -> bool { self.committed } pub fn committed_total(&self) -> u64 { self.committed_total } pub fn rejected_total(&self) -> u64 { self.rejected_total } pub fn tool_identity_refusals(&self) -> u64 { self.tool_identity_refusals } pub fn tool_accounting_refusals(&self) -> u64 { self.tool_accounting_refusals } pub fn committed_receipt(&self) -> Option { self.committed_receipt } pub fn commit_tool_version_matrix( &mut self, req: &PortabilityToolVersionsRequest, ) -> Result { if self.committed { self.rejected_total += 1; return Err(PortabilityToolVersionsError::AlreadyCommitted); } if req.same_firmware_counted_as_second { self.rejected_total += 1; self.tool_identity_refusals += 1; return Err(PortabilityToolVersionsError::SameFirmwareCountedAsSecond); } if req.image_not_measured_across_distinct_tools { self.rejected_total += 1; self.tool_identity_refusals += 1; return Err(PortabilityToolVersionsError::ImageNotMeasuredAcrossDistinctTools); } if !req.tool_hashes_and_failures_kept_separate { self.rejected_total += 1; self.tool_identity_refusals += 1; return Err(PortabilityToolVersionsError::ToolHashesOrFailuresMerged); } if req.distinct_qemu_versions != EXPECTED_DISTINCT_QEMU_VERSIONS { self.rejected_total += 1; self.tool_accounting_refusals += 1; return Err(PortabilityToolVersionsError::DistinctQemuVersionsMismatch); } if req.distinct_firmware_images != EXPECTED_DISTINCT_FIRMWARE_IMAGES { self.rejected_total += 1; self.tool_accounting_refusals += 1; return Err(PortabilityToolVersionsError::DistinctFirmwareImagesMismatch); } if req.separate_tool_hash_records != EXPECTED_SEPARATE_TOOL_HASH_RECORDS { self.rejected_total += 1; self.tool_accounting_refusals += 1; return Err(PortabilityToolVersionsError::SeparateToolHashRecordsMismatch); } if req.tool_versions_epoch == 0 { self.rejected_total += 1; return Err(PortabilityToolVersionsError::ZeroToolVersionsEpoch); } if req.tool_versions_epoch <= req.previous_tool_versions_epoch { self.rejected_total += 1; return Err(PortabilityToolVersionsError::NonMonotonicToolVersionsEpoch); } if req.tool_versions_matrix_digest == 0 { self.rejected_total += 1; return Err(PortabilityToolVersionsError::ZeroToolVersionsMatrixDigest); } let expected_binding = compute_portability_tool_versions_binding_digest( req.distinct_qemu_versions, req.distinct_firmware_images, req.separate_tool_hash_records, EXPECTED_DUPLICATE_FIRMWARE_ALIASES, req.tool_versions_epoch, req.tool_versions_matrix_digest, ); if req.tool_versions_binding_digest != expected_binding { self.rejected_total += 1; self.tool_accounting_refusals += 1; return Err(PortabilityToolVersionsError::UnboundPortabilityToolVersionsDigest); } self.committed = true; self.committed_total += 1; let receipt = PortabilityToolVersionsReceipt { distinct_qemu_versions: req.distinct_qemu_versions, distinct_firmware_images: req.distinct_firmware_images, separate_tool_hash_records: req.separate_tool_hash_records, duplicate_firmware_aliases: EXPECTED_DUPLICATE_FIRMWARE_ALIASES, tool_hashes_and_failures_kept_separate: true, tool_versions_epoch: req.tool_versions_epoch, tool_versions_matrix_digest: req.tool_versions_matrix_digest, receipt_digest: expected_binding ^ 0x2470_ACE0_544c_5631, }; self.committed_receipt = Some(receipt); Ok(receipt) } }