nx_threat_model.nx source
↩ module page · 210 lines · 11699 B
1// nx_threat_model.nx -- sealed adversary taxonomy for substrate design.
2//
3// module: nishi-core.security.threat_model
4// depends: nishi-core.io.syscalls
5// disk_kb: 4
6// capability: CRYPTO
7// wired_status: FULLY_WIRED
8//
9// license_tier: PUBLIC_NISHI_SUBSTRATE
10// genealogy_id: nishi_racing_crew_team_honesty_threat_aware_cardinal_2026 +
11// saltzer_schroeder_1975_protection_of_information +
12// shostack_2014_threat_modeling +
13// stride_threat_taxonomy_microsoft
14//
15// Per cardinal [[feedback-racing-crew-team-honesty-threat-aware]]:
16// THIS IS A TYPE-LEVEL PRIMITIVE. Implementation IS the sealed
17// enum + helpers. Marked FULLY_WIRED honestly because no further
18// execution path exists for this primitive — its job is to provide
19// the substrate's threat-actor taxonomy for downstream composition.
20//
21// Every NX-INGEST adapter, every cryptographic primitive, every
22// substrate boundary declares which ThreatActor classes it defends
23// against. Substrate-level audit composes these declarations into
24// a system-wide threat-coverage report.
25
26import "nx_syscalls.nx"
27
28// ===== ThreatActor sealed enum ====================================
29//
30// Ordered from least-resourced to most-resourced.
31
32const NX_THREAT_NONE: i64 = 0 // no adversary modeled
33const NX_THREAT_SCRIPT_KIDDIE: i64 = 1
34const NX_THREAT_OPPORTUNISTIC_CRIMINAL: i64 = 2
35const NX_THREAT_TARGETED_CRIMINAL: i64 = 3
36const NX_THREAT_HACKTIVIST_COLLECTIVE: i64 = 4
37const NX_THREAT_AI_ADVERSARY_CURRENT_GEN: i64 = 5
38const NX_THREAT_AI_ADVERSARY_MYTHOS_NEXT_GEN: i64 = 6 // future frontier models
39const NX_THREAT_INSIDER_COMPROMISE: i64 = 7 // racing crew member coerced/replaced
40const NX_THREAT_NATION_STATE: i64 = 8
41const NX_THREAT_SUPPLY_CHAIN_COMPROMISE: i64 = 9 // Wheeler-anchor tools tampered
42const NX_THREAT_QUANTUM_FUTURE: i64 = 10
43const NX_THREAT_LONG_HORIZON_AI_SUPERINTELLIGENCE: i64 = 11
44
45func nx_threat_actor_name(t: i64) -> *u8 {
46 if t == NX_THREAT_NONE { return "NONE" }
47 if t == NX_THREAT_SCRIPT_KIDDIE { return "SCRIPT_KIDDIE" }
48 if t == NX_THREAT_OPPORTUNISTIC_CRIMINAL { return "OPPORTUNISTIC_CRIMINAL" }
49 if t == NX_THREAT_TARGETED_CRIMINAL { return "TARGETED_CRIMINAL" }
50 if t == NX_THREAT_HACKTIVIST_COLLECTIVE { return "HACKTIVIST_COLLECTIVE" }
51 if t == NX_THREAT_AI_ADVERSARY_CURRENT_GEN { return "AI_ADVERSARY_CURRENT_GEN" }
52 if t == NX_THREAT_AI_ADVERSARY_MYTHOS_NEXT_GEN { return "AI_ADVERSARY_MYTHOS_NEXT_GEN" }
53 if t == NX_THREAT_INSIDER_COMPROMISE { return "INSIDER_COMPROMISE" }
54 if t == NX_THREAT_NATION_STATE { return "NATION_STATE" }
55 if t == NX_THREAT_SUPPLY_CHAIN_COMPROMISE { return "SUPPLY_CHAIN_COMPROMISE" }
56 if t == NX_THREAT_QUANTUM_FUTURE { return "QUANTUM_FUTURE" }
57 if t == NX_THREAT_LONG_HORIZON_AI_SUPERINTELLIGENCE { return "LONG_HORIZON_AI_SUPERINTELLIGENCE" }
58 return "UNKNOWN"
59}
60
61// ===== Resource tier ordering =====================================
62//
63// Higher tier = more resources = primitive must defend "up to here."
64
65func nx_threat_resource_tier(t: i64) -> i64 {
66 if t == NX_THREAT_NONE { return 0 }
67 if t == NX_THREAT_SCRIPT_KIDDIE { return 1 }
68 if t == NX_THREAT_OPPORTUNISTIC_CRIMINAL { return 2 }
69 if t == NX_THREAT_TARGETED_CRIMINAL { return 3 }
70 if t == NX_THREAT_HACKTIVIST_COLLECTIVE { return 3 }
71 if t == NX_THREAT_AI_ADVERSARY_CURRENT_GEN { return 4 }
72 if t == NX_THREAT_AI_ADVERSARY_MYTHOS_NEXT_GEN { return 6 }
73 if t == NX_THREAT_INSIDER_COMPROMISE { return 5 }
74 if t == NX_THREAT_NATION_STATE { return 8 }
75 if t == NX_THREAT_SUPPLY_CHAIN_COMPROMISE { return 7 }
76 if t == NX_THREAT_QUANTUM_FUTURE { return 9 }
77 if t == NX_THREAT_LONG_HORIZON_AI_SUPERINTELLIGENCE { return 10 }
78 return 0
79}
80
81// ===== AttackVector sealed enum ===================================
82//
83// What the adversary can DO (STRIDE-style + Nishi-specific
84// extensions).
85
86const NX_VECTOR_SPOOFING: i64 = 1 // impersonation
87const NX_VECTOR_TAMPERING: i64 = 2 // data/code modification
88const NX_VECTOR_REPUDIATION: i64 = 3 // deny actions
89const NX_VECTOR_INFO_DISCLOSURE: i64 = 4 // unauthorized reads
90const NX_VECTOR_DENIAL_OF_SERVICE: i64 = 5
91const NX_VECTOR_ELEVATION_OF_PRIVILEGE: i64 = 6
92const NX_VECTOR_PROMPT_INJECTION: i64 = 7 // AI-specific: inject instructions via data
93const NX_VECTOR_CODE_GENERATION_POISON: i64 = 8 // AI-specific: poison codegen output
94const NX_VECTOR_BYZANTINE_CONSENSUS: i64 = 9 // AI-specific: lie about consensus
95const NX_VECTOR_SUPPLY_CHAIN: i64 = 10 // Wheeler-anchor tampering
96const NX_VECTOR_SIDE_CHANNEL: i64 = 11 // timing / power / cache
97const NX_VECTOR_PHYSICAL_HARDWARE: i64 = 12 // implants / interposers
98const NX_VECTOR_SOCIAL_ENGINEERING: i64 = 13 // human in the loop
99
100func nx_attack_vector_name(v: i64) -> *u8 {
101 if v == NX_VECTOR_SPOOFING { return "SPOOFING" }
102 if v == NX_VECTOR_TAMPERING { return "TAMPERING" }
103 if v == NX_VECTOR_REPUDIATION { return "REPUDIATION" }
104 if v == NX_VECTOR_INFO_DISCLOSURE { return "INFO_DISCLOSURE" }
105 if v == NX_VECTOR_DENIAL_OF_SERVICE { return "DENIAL_OF_SERVICE" }
106 if v == NX_VECTOR_ELEVATION_OF_PRIVILEGE { return "ELEVATION_OF_PRIVILEGE" }
107 if v == NX_VECTOR_PROMPT_INJECTION { return "PROMPT_INJECTION" }
108 if v == NX_VECTOR_CODE_GENERATION_POISON { return "CODE_GENERATION_POISON" }
109 if v == NX_VECTOR_BYZANTINE_CONSENSUS { return "BYZANTINE_CONSENSUS" }
110 if v == NX_VECTOR_SUPPLY_CHAIN { return "SUPPLY_CHAIN" }
111 if v == NX_VECTOR_SIDE_CHANNEL { return "SIDE_CHANNEL" }
112 if v == NX_VECTOR_PHYSICAL_HARDWARE { return "PHYSICAL_HARDWARE" }
113 if v == NX_VECTOR_SOCIAL_ENGINEERING { return "SOCIAL_ENGINEERING" }
114 return "UNKNOWN"
115}
116
117// ===== Defense status per primitive ===============================
118//
119// Each substrate primitive declares which (threat_actor, attack_vector)
120// pairs it defends against — and which it does NOT. Substrate audit
121// composes this across primitives to identify uncovered surface.
122
123const NX_DEFENSE_NOT_APPLICABLE: i64 = 0 // primitive's domain doesn't intersect this vector
124const NX_DEFENSE_HARDENED: i64 = 1 // primitive actively defends
125const NX_DEFENSE_BEST_EFFORT: i64 = 2 // partial; documented residual risk
126const NX_DEFENSE_NOT_HARDENED: i64 = 3 // known gap; honest disclosure
127const NX_DEFENSE_INHERITED: i64 = 4 // defers to composed-substrate's defense
128
129func nx_defense_status_name(s: i64) -> *u8 {
130 if s == NX_DEFENSE_NOT_APPLICABLE { return "NOT_APPLICABLE" }
131 if s == NX_DEFENSE_HARDENED { return "HARDENED" }
132 if s == NX_DEFENSE_BEST_EFFORT { return "BEST_EFFORT" }
133 if s == NX_DEFENSE_NOT_HARDENED { return "NOT_HARDENED" }
134 if s == NX_DEFENSE_INHERITED { return "INHERITED" }
135 return "UNKNOWN"
136}
137
138// ===== ThreatCoverage struct (per primitive) ======================
139//
140// One per substrate primitive that declares threat coverage.
141// Substrate audit (nx_adversarial_pattern_audit) reads these +
142// reports surface gaps.
143
144struct ThreatCoverage {
145 coverage_hk: i64,
146 primitive_path_ptr: *u8,
147 primitive_path_len: i64,
148 // For each ThreatActor (12 enum values), what defense status?
149 defense_against_actor: i64, // bitmask: which actors covered
150 // For each AttackVector (13 enum values), what defense status?
151 defense_against_vector: i64, // bitmask: which vectors covered
152 // Composite max-threat-tier defended against
153 max_threat_tier_defended: i64,
154 // Honest disclosure of residual risk
155 residual_risk_notes_ptr: *u8,
156 last_audited_unix: i64,
157 audit_verdict: i64,
158}
159
160const NX_THREAT_COVERAGE_BYTES: i64 = 72 // 9 fields * 8 bytes
161
162// ===== Bitmask helpers ============================================
163
164func nx_threat_actor_bit(actor: i64) -> i64 {
165 if actor < 1 { return 0 }
166 if actor > 12 { return 0 }
167 return 1 << (actor - 1)
168}
169
170func nx_attack_vector_bit(vector: i64) -> i64 {
171 if vector < 1 { return 0 }
172 if vector > 13 { return 0 }
173 return 1 << (vector - 1)
174}
175
176func nx_threat_defends_against(coverage: *ThreatCoverage, actor: i64) -> i64 {
177 if coverage == 0 as *ThreatCoverage { return 0 }
178 let bit: i64 = nx_threat_actor_bit(actor)
179 if (coverage.defense_against_actor & bit) != 0 { return 1 }
180 return 0
181}
182
183// ===== Cardinal-aligned defense recommendations ===================
184//
185// For each ThreatActor, recommended substrate posture.
186
187func nx_threat_recommended_posture_ptr(actor: i64) -> *u8 {
188 if actor == NX_THREAT_SCRIPT_KIDDIE { return "default substrate; no special posture" }
189 if actor == NX_THREAT_OPPORTUNISTIC_CRIMINAL { return "TLS 1.3 + sealed verdicts + rate-limit" }
190 if actor == NX_THREAT_TARGETED_CRIMINAL { return "+ Pillar 1 verification + audit ledger Cardinal 13" }
191 if actor == NX_THREAT_HACKTIVIST_COLLECTIVE { return "+ sovereign-egress + key-rotation discipline" }
192 if actor == NX_THREAT_AI_ADVERSARY_CURRENT_GEN { return "+ prompt-injection guard at format-parser boundary + Byzantine N-of-M codegen for critical primitives" }
193 if actor == NX_THREAT_AI_ADVERSARY_MYTHOS_NEXT_GEN { return "+ structural sealed-enum guarantees that survive persuasion + cryptographic audit trail + content-addressed primitives" }
194 if actor == NX_THREAT_INSIDER_COMPROMISE { return "+ no-single-agent-trust + multi-agent confirmation for critical substrate changes + append-only ledger" }
195 if actor == NX_THREAT_NATION_STATE { return "+ reproducible builds + Ed25519 code signing + Wheeler-anchor attestation + constant-time crypto + side-channel resistance" }
196 if actor == NX_THREAT_SUPPLY_CHAIN_COMPROMISE { return "+ gcc/binutils/qemu version+hash recorded + alternate-toolchain bootstrap path + canary substrate" }
197 if actor == NX_THREAT_QUANTUM_FUTURE { return "+ Kyber + Dilithium + SPHINCS+ migration paths queued; substrate plans pre-quantum-deployment migration window" }
198 if actor == NX_THREAT_LONG_HORIZON_AI_SUPERINTELLIGENCE { return "+ mechanical sealed-enum guarantees that no agent can persuade away + cryptographic provenance + reproducible-build attestation + the human-in-loop discipline of Cardinal 11/13" }
199 return "DEFAULT"
200}
201
202// ===== Substrate default threat-tier targets ======================
203//
204// Nishi's default minimum threat-tier defended against:
205
206const NX_THREAT_DEFAULT_TIER: i64 = 6 // = AI_ADVERSARY_MYTHOS_NEXT_GEN
207const NX_THREAT_CRYPTO_TIER: i64 = 8 // crypto primitives target NATION_STATE
208const NX_THREAT_LEDGER_TIER: i64 = 7 // financial substrate target SUPPLY_CHAIN
209const NX_THREAT_GAME_TIER: i64 = 4 // game-engine target AI_ADVERSARY_CURRENT_GEN
210const NX_THREAT_INGESTION_TIER: i64 = 5 // ingestion target INSIDER_COMPROMISE (data integrity)