// K2461-K2465: portability.mac_hosts — M1 ve M5 yeni imaj matrisi // Invariant: Eski K592 hash yeni kerneli doğrulamaz // Positive: Aynı yeni Image iki Macte // Counterexample: Eski M1 raporu yeni Imagea bağlanır // Acceptance: Yeni hashli altı boot iki hostta pub const PORTABILITY_MAC_HOSTS_SCHEMA: &str = "turkos.os.portability.mac_hosts.v1"; pub const PORTABILITY_MAC_HOSTS_INVARIANT: &str = "Eski K592 hash yeni kerneli doğrulamaz"; pub const PORTABILITY_MAC_HOSTS_POSITIVE: &str = "Aynı yeni Image iki Macte"; pub const PORTABILITY_MAC_HOSTS_COUNTEREXAMPLE: &str = "Eski M1 raporu yeni Imagea bağlanır"; pub const PORTABILITY_MAC_HOSTS_ACCEPTANCE: &str = "Yeni hashli altı boot iki hostta"; pub const EXPECTED_MAC_HOST_FAMILIES: u32 = 2; pub const EXPECTED_NEW_HASHED_HOST_BOOTS: u32 = 6; pub const EXPECTED_SHARED_NEW_IMAGE_HASHES: u32 = 1; pub const EXPECTED_STALE_K592_REPORT_REUSES: u32 = 0; #[repr(u8)] #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum PortabilityMacHostsError { StaleM1ReportBoundToNewImage = 1, StaleK592HashUsedForNewKernel = 2, MissingSixNewHashedBootsAcrossTwoHosts = 3, MacHostFamiliesMismatch = 4, NewHashedHostBootsMismatch = 5, SharedNewImageHashesMismatch = 6, ZeroMacHostsEpoch = 7, NonMonotonicMacHostsEpoch = 8, ZeroMacHostsMatrixDigest = 9, UnboundPortabilityMacHostsDigest = 10, AlreadyCommitted = 11, } #[repr(C)] #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct PortabilityMacHostsRequest { pub stale_m1_report_bound_to_new_image: bool, pub stale_k592_hash_used_for_new_kernel: bool, pub six_new_hashed_boots_across_two_hosts: bool, pub mac_host_families: u32, pub new_hashed_host_boots: u32, pub shared_new_image_hashes: u32, pub mac_hosts_epoch: u64, pub previous_mac_hosts_epoch: u64, pub mac_hosts_matrix_digest: u64, pub mac_hosts_binding_digest: u64, } #[repr(C)] #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct PortabilityMacHostsReceipt { pub mac_host_families: u32, pub new_hashed_host_boots: u32, pub shared_new_image_hashes: u32, pub stale_k592_report_reuses: u32, pub six_new_hashed_boots_across_two_hosts: bool, pub mac_hosts_epoch: u64, pub mac_hosts_matrix_digest: u64, pub receipt_digest: u64, } pub const fn compute_portability_mac_hosts_binding_digest( mac_host_families: u32, new_hashed_host_boots: u32, shared_new_image_hashes: u32, stale_k592_report_reuses: u32, mac_hosts_epoch: u64, mac_hosts_matrix_digest: u64, ) -> u64 { let mut h: u64 = 0xcbf2_9ce4_8422_2325; h = (h ^ 0x2465_5052_4d41_4331).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ (mac_host_families as u64)).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ (new_hashed_host_boots as u64)).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ (shared_new_image_hashes as u64)).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ (stale_k592_report_reuses as u64)).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ mac_hosts_epoch).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ mac_hosts_matrix_digest).wrapping_mul(0x0000_0100_0000_01b3); h } pub struct PortabilityMacHostsCoordinator { committed: bool, committed_total: u64, rejected_total: u64, host_lineage_refusals: u64, host_accounting_refusals: u64, committed_receipt: Option, } impl PortabilityMacHostsCoordinator { pub const fn new() -> Self { Self { committed: false, committed_total: 0, rejected_total: 0, host_lineage_refusals: 0, host_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 host_lineage_refusals(&self) -> u64 { self.host_lineage_refusals } pub fn host_accounting_refusals(&self) -> u64 { self.host_accounting_refusals } pub fn committed_receipt(&self) -> Option { self.committed_receipt } pub fn commit_mac_host_matrix( &mut self, req: &PortabilityMacHostsRequest, ) -> Result { if self.committed { self.rejected_total += 1; return Err(PortabilityMacHostsError::AlreadyCommitted); } if req.stale_m1_report_bound_to_new_image { self.rejected_total += 1; self.host_lineage_refusals += 1; return Err(PortabilityMacHostsError::StaleM1ReportBoundToNewImage); } if req.stale_k592_hash_used_for_new_kernel { self.rejected_total += 1; self.host_lineage_refusals += 1; return Err(PortabilityMacHostsError::StaleK592HashUsedForNewKernel); } if !req.six_new_hashed_boots_across_two_hosts { self.rejected_total += 1; self.host_lineage_refusals += 1; return Err(PortabilityMacHostsError::MissingSixNewHashedBootsAcrossTwoHosts); } if req.mac_host_families != EXPECTED_MAC_HOST_FAMILIES { self.rejected_total += 1; self.host_accounting_refusals += 1; return Err(PortabilityMacHostsError::MacHostFamiliesMismatch); } if req.new_hashed_host_boots != EXPECTED_NEW_HASHED_HOST_BOOTS { self.rejected_total += 1; self.host_accounting_refusals += 1; return Err(PortabilityMacHostsError::NewHashedHostBootsMismatch); } if req.shared_new_image_hashes != EXPECTED_SHARED_NEW_IMAGE_HASHES { self.rejected_total += 1; self.host_accounting_refusals += 1; return Err(PortabilityMacHostsError::SharedNewImageHashesMismatch); } if req.mac_hosts_epoch == 0 { self.rejected_total += 1; return Err(PortabilityMacHostsError::ZeroMacHostsEpoch); } if req.mac_hosts_epoch <= req.previous_mac_hosts_epoch { self.rejected_total += 1; return Err(PortabilityMacHostsError::NonMonotonicMacHostsEpoch); } if req.mac_hosts_matrix_digest == 0 { self.rejected_total += 1; return Err(PortabilityMacHostsError::ZeroMacHostsMatrixDigest); } let expected_binding = compute_portability_mac_hosts_binding_digest( req.mac_host_families, req.new_hashed_host_boots, req.shared_new_image_hashes, EXPECTED_STALE_K592_REPORT_REUSES, req.mac_hosts_epoch, req.mac_hosts_matrix_digest, ); if req.mac_hosts_binding_digest != expected_binding { self.rejected_total += 1; self.host_accounting_refusals += 1; return Err(PortabilityMacHostsError::UnboundPortabilityMacHostsDigest); } self.committed = true; self.committed_total += 1; let receipt = PortabilityMacHostsReceipt { mac_host_families: req.mac_host_families, new_hashed_host_boots: req.new_hashed_host_boots, shared_new_image_hashes: req.shared_new_image_hashes, stale_k592_report_reuses: EXPECTED_STALE_K592_REPORT_REUSES, six_new_hashed_boots_across_two_hosts: true, mac_hosts_epoch: req.mac_hosts_epoch, mac_hosts_matrix_digest: req.mac_hosts_matrix_digest, receipt_digest: expected_binding ^ 0x2465_ACE0_4d41_4331, }; self.committed_receipt = Some(receipt); Ok(receipt) } }