diff --git a/compiler/.claw/sessions/e15cadfd658771bb/session-1779385820883-0.jsonl b/compiler/.claw/sessions/e15cadfd658771bb/session-1779385820883-0.jsonl new file mode 100644 index 0000000..3d3f10a --- /dev/null +++ b/compiler/.claw/sessions/e15cadfd658771bb/session-1779385820883-0.jsonl @@ -0,0 +1,5 @@ +{"created_at_ms":1779385820882,"model":"nvidia/nemotron-3-super-120b-a12b:free","session_id":"session-1779385820883-0","type":"session_meta","updated_at_ms":1779385820882,"version":1,"workspace_root":"/home/pbk/school/P10-Master/compiler"} +{"text":"using the language trivilang (compiler in this directory) please make crt-rsa inside the @eval_cases folder.","timestamp_ms":1779385840153,"type":"prompt_history"} +{"message":{"blocks":[{"text":"using the language trivilang (compiler in this directory) please make crt-rsa inside the @eval_cases folder.","type":"text"}],"role":"user"},"type":"message"} +{"message":{"blocks":[{"id":"chatcmpl-tool-a2ef1f611a265f43","input":"{\"command\": \"ls -la eval_cases/\"}","name":"bash","type":"tool_use"}],"role":"assistant","usage":{"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"input_tokens":9800,"output_tokens":184}},"type":"message"} +{"message":{"blocks":[{"is_error":false,"output":"{\n \"stdout\": \"total 8\\ndrwxr-xr-x 1 root root 54 May 21 19:50 .\\ndrwxr-xr-x 1 root root 356 May 21 19:50 ..\\ndrwxr-xr-x 1 root root 16 May 21 19:50 .claw\\n-rw-r--r-- 1 root root 0 May 21 19:50 crt-rsa.trv\\n-rw-r--r-- 1 root root 740 May 21 19:47 out.s\\n-rw-r--r-- 1 root root 742 May 21 19:47 out.wh\\n\",\n \"stderr\": \"\",\n \"rawOutputPath\": null,\n \"interrupted\": false,\n \"isImage\": null,\n \"backgroundTaskId\": null,\n \"backgroundedByUser\": null,\n \"assistantAutoBackgrounded\": null,\n \"dangerouslyDisableSandbox\": null,\n \"returnCodeInterpretation\": null,\n \"noOutputExpected\": false,\n \"structuredContent\": null,\n \"persistedOutputPath\": null,\n \"persistedOutputSize\": null,\n \"sandboxStatus\": {\n \"enabled\": true,\n \"requested\": {\n \"enabled\": true,\n \"namespace_restrictions\": true,\n \"network_isolation\": false,\n \"filesystem_mode\": \"workspace-only\",\n \"allowed_mounts\": []\n },\n \"supported\": true,\n \"active\": true,\n \"namespace_supported\": true,\n \"namespace_active\": true,\n \"network_supported\": true,\n \"network_active\": false,\n \"filesystem_mode\": \"workspace-only\",\n \"filesystem_active\": true,\n \"allowed_mounts\": [],\n \"in_container\": false,\n \"container_markers\": [],\n \"fallback_reason\": null\n }\n}","tool_name":"bash","tool_use_id":"chatcmpl-tool-a2ef1f611a265f43","type":"tool_result"}],"role":"tool"},"type":"message"} diff --git a/compiler/.claw/sessions/e15cadfd658771bb/session-1779385972409-0.jsonl b/compiler/.claw/sessions/e15cadfd658771bb/session-1779385972409-0.jsonl new file mode 100644 index 0000000..ee275cd --- /dev/null +++ b/compiler/.claw/sessions/e15cadfd658771bb/session-1779385972409-0.jsonl @@ -0,0 +1,5 @@ +{"created_at_ms":1779385972408,"model":"nvidia/nemotron-3-super-120b-a12b:free","session_id":"session-1779385972409-0","type":"session_meta","updated_at_ms":1779385972408,"version":1,"workspace_root":"/home/pbk/school/P10-Master/compiler"} +{"text":"Please implement crt-rsa inside the @eval_codes/crt-rsa.trv file using the trivilang language in this folder using the compiler in @src","timestamp_ms":1779385991361,"type":"prompt_history"} +{"message":{"blocks":[{"text":"Please implement crt-rsa inside the @eval_codes/crt-rsa.trv file using the trivilang language in this folder using the compiler in @src","type":"text"}],"role":"user"},"type":"message"} +{"message":{"blocks":[{"id":"chatcmpl-tool-ac197642acc42ed0","input":"{\"command\": \"ls -la\"}","name":"bash","type":"tool_use"}],"role":"assistant","usage":{"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"input_tokens":9846,"output_tokens":536}},"type":"message"} +{"message":{"blocks":[{"is_error":false,"output":"{\n \"stdout\": \"total 40\\ndrwxr-xr-x 1 root root 356 May 21 19:50 .\\ndrwxr-xr-x 1 root root 372 May 21 18:59 ..\\ndrwxr-xr-x 1 root root 28 May 7 10:32 bin\\n-rw-r--r-- 1 root root 5975 Apr 28 14:25 Cargo.lock\\n-rw-r--r-- 1 root root 242 Apr 28 14:25 Cargo.toml\\ndrwxr-xr-x 1 root root 16 May 21 18:59 .claw\\ndrwxr-xr-x 1 root root 54 May 21 19:50 eval_cases\\ndrwxr-xr-x 1 root root 68 Apr 28 14:25 fissc\\ndrwxr-xr-x 1 root root 30 Apr 28 14:25 output_test\\n-rw-r--r-- 1 root root 2017 May 7 10:32 pinny.s\\n-rw-r--r-- 1 root root 137 Apr 28 14:25 README.md\\ndrwxr-xr-x 1 root root 0 May 21 19:50 .sandbox-home\\ndrwxr-xr-x 1 root root 0 May 21 19:50 .sandbox-tmp\\ndrwxr-xr-x 1 root root 66 May 20 10:26 src\\ndrwxr-xr-x 1 root root 98 May 21 09:32 target\\ndrwxr-xr-x 1 root root 10 Apr 29 09:00 temp\\ndrwxr-xr-x 1 root root 884 May 13 11:55 test_codes\\ndrwxr-xr-x 1 root root 254 May 21 09:22 test_codes_compiled\\ndrwxr-xr-x 1 root root 102 May 18 13:12 test_else_return\\n-rw-r--r-- 1 root root 6535 May 21 18:59 test.s\\n-rw-r--r-- 1 root root 1366 May 21 18:59 test.trv\\n-rw-r--r-- 1 root root 4414 May 21 18:59 test.wh\\ndrwxr-xr-x 1 root root 142 May 21 19:21 vpin\\n\",\n \"stderr\": \"\",\n \"rawOutputPath\": null,\n \"interrupted\": false,\n \"isImage\": null,\n \"backgroundTaskId\": null,\n \"backgroundedByUser\": null,\n \"assistantAutoBackgrounded\": null,\n \"dangerouslyDisableSandbox\": null,\n \"returnCodeInterpretation\": null,\n \"noOutputExpected\": false,\n \"structuredContent\": null,\n \"persistedOutputPath\": null,\n \"persistedOutputSize\": null,\n \"sandboxStatus\": {\n \"enabled\": true,\n \"requested\": {\n \"enabled\": true,\n \"namespace_restrictions\": true,\n \"network_isolation\": false,\n \"filesystem_mode\": \"workspace-only\",\n \"allowed_mounts\": []\n },\n \"supported\": true,\n \"active\": true,\n \"namespace_supported\": true,\n \"namespace_active\": true,\n \"network_supported\": true,\n \"network_active\": false,\n \"filesystem_mode\": \"workspace-only\",\n \"filesystem_active\": true,\n \"allowed_mounts\": [],\n \"in_container\": false,\n \"container_markers\": [],\n \"fallback_reason\": null\n }\n}","tool_name":"bash","tool_use_id":"chatcmpl-tool-ac197642acc42ed0","type":"tool_result"}],"role":"tool"},"type":"message"} diff --git a/compiler/.claw/sessions/e15cadfd658771bb/session-1779386059106-0.jsonl b/compiler/.claw/sessions/e15cadfd658771bb/session-1779386059106-0.jsonl new file mode 100644 index 0000000..27dca9d --- /dev/null +++ b/compiler/.claw/sessions/e15cadfd658771bb/session-1779386059106-0.jsonl @@ -0,0 +1 @@ +{"created_at_ms":1779386059105,"model":"nvidia/nemotron-3-super-120b-a12b:free","session_id":"session-1779386059106-0","type":"session_meta","updated_at_ms":1779386059105,"version":1,"workspace_root":"/home/pbk/school/P10-Master/compiler"} diff --git a/compiler/.claw/sessions/e15cadfd658771bb/session-1779386060570-0.jsonl b/compiler/.claw/sessions/e15cadfd658771bb/session-1779386060570-0.jsonl new file mode 100644 index 0000000..15f8d94 --- /dev/null +++ b/compiler/.claw/sessions/e15cadfd658771bb/session-1779386060570-0.jsonl @@ -0,0 +1 @@ +{"created_at_ms":1779386060569,"model":"nvidia/nemotron-3-super-120b-a12b:free","session_id":"session-1779386060570-0","type":"session_meta","updated_at_ms":1779386060569,"version":1,"workspace_root":"/home/pbk/school/P10-Master/compiler"} diff --git a/compiler/eval_cases/.claw/sessions/5399607f57f45960/session-1779385813088-0.jsonl b/compiler/eval_cases/.claw/sessions/5399607f57f45960/session-1779385813088-0.jsonl new file mode 100644 index 0000000..7e4dbf9 --- /dev/null +++ b/compiler/eval_cases/.claw/sessions/5399607f57f45960/session-1779385813088-0.jsonl @@ -0,0 +1 @@ +{"created_at_ms":1779385813087,"model":"nvidia/nemotron-3-super-120b-a12b:free","session_id":"session-1779385813088-0","type":"session_meta","updated_at_ms":1779385813087,"version":1,"workspace_root":"/home/pbk/school/P10-Master/compiler/eval_cases"} diff --git a/test_results/tests/pinny.trv.output b/compiler/eval_cases/crt-rsa.trv similarity index 100% rename from test_results/tests/pinny.trv.output rename to compiler/eval_cases/crt-rsa.trv diff --git a/compiler/hard.s b/compiler/hard.s new file mode 100644 index 0000000..5b1792e --- /dev/null +++ b/compiler/hard.s @@ -0,0 +1,220 @@ +.syntax unified +.thumb + +.section .text +.global _start +.type _start, %function + +_start: + mov r9, #0 + mov r10, #1 + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + sub sp, sp, #4 + mov r0, #2 + str r0, [sp] + sub sp, sp, #4 + mov r0, #2 + str r0, [sp] + sub sp, sp, #4 + mov r0, #4 + str r0, [sp] + sub sp, sp, #4 + mov r0, #4 + str r0, [sp] + ldr r0, [sp, #20] + ldr r1, [sp, #16] + cmp r1, r0 + bne countermeasure + ldr r0, [sp, #12] + ldr r1, [sp, #8] + cmp r1, r0 + bne countermeasure + ldr r0, [sp, #4] + ldr r1, [sp, #0] + cmp r1, r0 + bne countermeasure + sub sp, sp, #4 + ldr r0, [sp, #24] + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #20] + ldr r1, [sp, #0] + add sp, sp, #4 + add r0, r1, r0 + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #12] + ldr r1, [sp, #0] + add sp, sp, #4 + add r0, r1, r0 + sub sp, sp, #4 + str r0, [sp, #0] + mov r0, #1 + ldr r1, [sp, #0] + add sp, sp, #4 + add r0, r1, r0 + str r0, [sp] + sub sp, sp, #4 + ldr r0, [sp, #24] + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #20] + ldr r1, [sp, #0] + add sp, sp, #4 + add r0, r1, r0 + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #12] + ldr r1, [sp, #0] + add sp, sp, #4 + add r0, r1, r0 + sub sp, sp, #4 + str r0, [sp, #0] + mov r0, #1 + ldr r1, [sp, #0] + add sp, sp, #4 + add r0, r1, r0 + str r0, [sp] + ldr r0, [sp, #4] + ldr r1, [sp, #0] + cmp r1, r0 + bne countermeasure + ldr r0, [sp, #4] + sub sp, sp, #4 + str r0, [sp, #0] + mov r0, #6 + ldr r1, [sp, #0] + add sp, sp, #4 + cmp r1, r0 + mov r0, #0 + it eq + moveq r0, #1 + cmp r0, #0 + beq else_0 + add r9, r9, #1 + cmp r9, #1 + bne countermeasure + ldr r0, [sp, #4] + ldr r1, [sp, #0] + cmp r1, r0 + bne countermeasure + mov r0, #7 + str r0, [sp, #4] + add r9, r9, #1 + cmp r9, #2 + bne countermeasure + mov r0, #7 + str r0, [sp] + add r9, r9, #1 + cmp r9, #3 + bne countermeasure + b endif_0 +else_0: + ldr r0, [sp, #4] + ldr r1, [sp, #0] + cmp r1, r0 + bne countermeasure + mov r0, #8 + str r0, [sp, #4] + add r9, r9, #1 + cmp r9, #1 + bne countermeasure + mov r0, #8 + str r0, [sp] + add r9, r9, #1 + cmp r9, #2 + bne countermeasure + mov r9, #3 +endif_0: + ldr r0, [sp, #4] + ldr r1, [sp, #0] + cmp r1, r0 + bne countermeasure + ldr r0, [sp, #4] + mov r7, #1 + svc #0 +countermeasure: + mov r0, #1 + ldr r1, =.Lstr0 + mov r2, #14 + mov r7, #4 + svc #0 + mov r0, #77 + mov r7, #1 + svc #0 + +.size _start, .-_start + +.section .data +.Lstr0: + .ascii "COUNTERMEASURE" +step_counter: + .word 0 +fault_msg: + .ascii "Control flow violation detected\n" +_metadata: + .word 0x10000000 @ 0 + .word 0xa+3 + .word 0xb+5 + .word 0x0 @ [r0] + .word 0x00000001 @ x + .word 0x10000000 @ 1 + .word 0xa+6 + .word 0xb+8 + .word 0x0 @ [r0] + .word 0x00000001 @ x_dup + .word 0x10000000 @ 2 + .word 0xa+9 + .word 0xb+11 + .word 0x0 @ [r0] + .word 0x00000001 @ y + .word 0x10000000 @ 3 + .word 0xa+12 + .word 0xb+14 + .word 0x0 @ [r0] + .word 0x00000001 @ y_dup + .word 0x10000000 @ 4 + .word 0xa+15 + .word 0xb+17 + .word 0x0 @ [r0] + .word 0x00000001 @ z + .word 0x10000000 @ 5 + .word 0xa+18 + .word 0xb+20 + .word 0x0 @ [r0] + .word 0x00000001 @ z_dup + .word 0x10000000 @ 6 + .word 0xa+33 + .word 0xb+53 + .word 0x0 @ [r0] + .word 0x00000001 @ vd + .word 0x10000000 @ 7 + .word 0xa+54 + .word 0xb+74 + .word 0x0 @ [r0] + .word 0x00000001 @ vd_dup + .word 0x10000000 @ 8 + .word 0xa+98 + .word 0xb+102 + .word 0x0 @ [r0] + .word 0x00000001 @ vd + .word 0x10000000 @ 9 + .word 0xa+103 + .word 0xb+107 + .word 0x0 @ [r0] + .word 0x00000001 @ vd_dup + .word 0x10000000 @ 10 + .word 0xa+114 + .word 0xb+118 + .word 0x0 @ [r0] + .word 0x00000001 @ vd + .word 0x10000000 @ 11 + .word 0xa+119 + .word 0xb+123 + .word 0x0 @ [r0] + .word 0x00000001 @ vd_dup diff --git a/compiler/hard.wh b/compiler/hard.wh new file mode 100644 index 0000000..0323ec1 --- /dev/null +++ b/compiler/hard.wh @@ -0,0 +1,122 @@ +ui32 res; +ui32 stmt; +ui32 bit_shift; +ui32 flip_mask; + +fn main(ui32 stmt, ui32 flip_mask) -> ui32 { + ui32 x; + ui32 x_dup; + ui32 y; + ui32 y_dup; + ui32 z; + ui32 z_dup; + ui32 vd; + ui32 vd_dup; + ui32 step_counter; + step_counter = (0 as ui32); + x = (0 as ui32); + if (stmt == (0 as ui32)) { + x = (0 as ui32) ^ flip_mask; + } + x_dup = (0 as ui32); + if (stmt == (1 as ui32)) { + x_dup = (0 as ui32) ^ flip_mask; + } + y = (2 as ui32); + if (stmt == (2 as ui32)) { + y = (2 as ui32) ^ flip_mask; + } + y_dup = (2 as ui32); + if (stmt == (3 as ui32)) { + y_dup = (2 as ui32) ^ flip_mask; + } + z = (4 as ui32); + if (stmt == (4 as ui32)) { + z = (4 as ui32) ^ flip_mask; + } + z_dup = (4 as ui32); + if (stmt == (5 as ui32)) { + z_dup = (4 as ui32) ^ flip_mask; + } + if (x != x_dup) { + return 77; + } + if (y != y_dup) { + return 77; + } + if (z != z_dup) { + return 77; + } + vd = x + y + z + (1 as ui32); + if (stmt == (6 as ui32)) { + vd = x + y + z + (1 as ui32) ^ flip_mask; + } + vd_dup = x_dup + y_dup + z_dup + (1 as ui32); + if (stmt == (7 as ui32)) { + vd_dup = x_dup + y_dup + z_dup + (1 as ui32) ^ flip_mask; + } + if (vd != vd_dup) { + return 77; + } + if ( vd == (6 as ui32)) { + step_counter++; + if (step_counter != (1 as ui32)) { + return (77 as ui32); + } + if (vd != vd_dup) { + return 77; + } + vd = (7 as ui32); + if (stmt == (8 as ui32)) { + vd = (7 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (2 as ui32)) { + return (77 as ui32); + } + vd_dup = (7 as ui32); + if (stmt == (9 as ui32)) { + vd_dup = (7 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (3 as ui32)) { + return (77 as ui32); + } + } + else { + if (vd != vd_dup) { + return 77; + } + vd = (8 as ui32); + if (stmt == (10 as ui32)) { + vd = (8 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (1 as ui32)) { + return (77 as ui32); + } + vd_dup = (8 as ui32); + if (stmt == (11 as ui32)) { + vd_dup = (8 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (2 as ui32)) { + return (77 as ui32); + } + step_counter = (3 as ui32); + } + if (vd != vd_dup) { + return 77; + } + return (vd as ui32); +} +stmt = (? as ui32); +bit_shift = (? as ui32); +assume (bit_shift <= (31 as ui32)); +assume (bit_shift >= (0 as ui32)); +assume (stmt >= (0 as ui32)); +assume (stmt <= (11 as ui32)); +flip_mask = ((1 as ui32) << bit_shift); + +res = main(stmt, flip_mask); +assert(res == (XYZ as ui32)); diff --git a/compiler/src/codegen/codegen.rs b/compiler/src/codegen/codegen.rs index 70394d3..7440c18 100644 --- a/compiler/src/codegen/codegen.rs +++ b/compiler/src/codegen/codegen.rs @@ -18,10 +18,10 @@ pub struct CodeGenerator { pub file: File, pub wh_file: File, locals: HashMap, - dup_pairs: HashMap, stack_offset: i32, label_count: usize, - hard: bool, + sc: bool, + vd: bool, string_literals: Vec<(String, String)>, need_int_print: bool, step_counter: i32, @@ -40,10 +40,10 @@ impl CodeGenerator { file, wh_file, locals: HashMap::new(), - dup_pairs: HashMap::new(), stack_offset: 0, label_count: 0, - hard: false, + sc: false, + vd: false, string_literals: Vec::new(), need_int_print: false, step_counter: 0, @@ -56,8 +56,9 @@ impl CodeGenerator { metadata_current_registers: Vec::new(), } } - pub fn generate(&mut self, ast: AST, is_hard: bool) { - self.hard = is_hard; + pub fn generate(&mut self, ast: AST, only_sc: bool, only_vd: bool) { + self.sc = only_sc; + self.vd = only_vd; self.gen_init(); for func in ast { self.emit(func); @@ -65,17 +66,16 @@ impl CodeGenerator { self.emit_print_data(); self.insert_metadata(); - self.wh_write_line(format!("stmt = (? as ui32);").as_str(), 0); - self.wh_write_line(format!("bit_shift = (? as ui32);").as_str(), 0); - self.wh_write_line(format!("assume (bit_shift <= (31 as ui32));").as_str(), 0); - self.wh_write_line(format!("assume (bit_shift >= (0 as ui32));").as_str(), 0); - self.wh_write_line(format!("assume (stmt >= (0 as ui32));").as_str(), 0); - self.wh_write_line(format!("assume (stmt <= ({} as ui32));",self.stmt-1).as_str(), 0); - self.wh_write_line(format!("flip_mask = ((1 as ui32) << bit_shift);").as_str(), 0); + self.wh_write_line("stmt = (? as ui32);", 0); + self.wh_write_line("bit_shift = (? as ui32);", 0); + self.wh_write_line("assume (bit_shift <= (31 as ui32));", 0); + self.wh_write_line("assume (bit_shift >= (0 as ui32));", 0); + self.wh_write_line("assume (stmt >= (0 as ui32));", 0); + self.wh_write_line(format!("assume (stmt <= ({} as ui32));", self.stmt - 1).as_str(), 0); + self.wh_write_line("flip_mask = ((1 as ui32) << bit_shift);", 0); self.wh_write_line("\nres = main(stmt, flip_mask);", 0); - self.wh_write_line(format!("assert(res == (0 as ui32));").as_str(), 0); - + self.wh_write_line("assert(res == (XYZ as ui32));".to_string().as_str(), 0); } fn gen_init(&mut self) { @@ -123,41 +123,93 @@ ui32 bit_shift; ui32 flip_mask; "#, 0); self.wh_write_line("fn main(ui32 stmt, ui32 flip_mask) -> ui32 {", 0); - if self.hard { + self.wh_write_line("ui32 has_faulted;", 1); + if self.sc { self.write_line("mov r9, #0", 1, true); // step counter in register self.write_line("mov r10, #1", 1, true); // step counter in register self.wh_write_line("ui32 step_counter;", 1); self.wh_write_line("step_counter = (0 as ui32);", 1); } + self.wh_write_line("has_faulted = (0 as ui32);", 1); self.emit_block(func.body, true); - if self.hard { + if self.sc || self.vd { self.emit_countermeasure(); } self.write_line("\n.size _start, .-_start", 0, true); self.wh_write_line("}", 0); } + fn emit_vd(&mut self, expr: Expr) { + //husk det er den der laver vd checket + let collected_identifiers = expr.get_all_identifiers(); + for c in collected_identifiers.clone() { + let duped = c.clone() + "_dup"; + let dup_offset = self.stack_offset - *self.locals.get(&duped).unwrap(); + let offset = self.stack_offset - *self.locals.get(&c).unwrap(); + self.write_line(format!("ldr r0, [sp, #{}]", offset).as_str(), 1, true); + self.write_line(format!("ldr r1, [sp, #{}]", dup_offset).as_str(), 1, true); + self.write_line("cmp r1, r0", 1, true); + self.write_line("bne countermeasure", 1, true); + self.write_line(format!("str r0, [sp, #{}]", offset).as_str(), 1, true); + self.write_line(format!("str r1, [sp, #{}]", dup_offset).as_str(), 1, true); + self.wh_write_line(&format!("if ({} != {}) {{", c, duped), self.wh_indent); + self.wh_indent += 1; + self.wh_write_line("return (77 as ui32);", self.wh_indent); + self.wh_indent -= 1; + self.wh_write_line("}", self.wh_indent); + } + } fn emit_block(&mut self, block: Block, is_main: bool) { let initial_offset = self.stack_offset; let initial_locals = self.locals.clone(); - let initial_dup_pairs = self.dup_pairs.clone(); let mut has_return = false; for stmt in block.statements { match stmt { - Stmt::Let(_, _, _) => self.emit_let(stmt), - Stmt::AssignStatement(_, _) => self.emit_assign(stmt), - Stmt::Return(_) => { + Stmt::Let(ref name, ref typ, ref expr) => { + if self.vd { + self.emit_vd(expr.clone()); + } + self.emit_let(stmt.clone()); + if self.vd { + let dup_expr = expr.duplicate_identifiers("_dup"); + let dup_stmt = Stmt::Let(format!("{}_dup", name), typ.clone(), dup_expr); + self.emit_let(dup_stmt); + } + } + Stmt::AssignStatement(ref name, ref expr) => { + if self.vd { + self.emit_vd(Expr::Identifier(name.into())); + self.emit_vd(expr.clone()); + } + self.emit_assign(stmt.clone()); + if self.vd { + let dup_expr = expr.duplicate_identifiers("_dup"); + let dup_stmt = Stmt::AssignStatement(format!("{}_dup", name), dup_expr); + self.emit_assign(dup_stmt); + } + } + Stmt::Return(ref expr) => { + if self.vd { + self.emit_vd(expr.clone()); + } self.emit_return(stmt, is_main); has_return = true; } - Stmt::If { .. } => self.emit_if(stmt), - Stmt::While { .. } => self.emit_while(stmt), + Stmt::If { condition: ref expr, .. } => { + if self.vd { + self.emit_vd(expr.clone()); + } + self.emit_if(stmt); + } + Stmt::While { ref expr, .. } => { + if self.vd { + self.emit_vd(expr.clone()); + } + self.emit_while(stmt); + } Stmt::Print(exprs) => self.emit_print(exprs), _ => panic!("Error found in expression in return"), } - // if self.hard { - // self.emit_step_check(); - // } } let offset_diff = self.stack_offset - initial_offset; @@ -167,7 +219,6 @@ ui32 flip_mask; self.stack_offset = initial_offset; self.locals = initial_locals; - self.dup_pairs = initial_dup_pairs; } fn emit_countermeasure(&mut self) { self.write_line("countermeasure:", 0, true); @@ -180,31 +231,24 @@ ui32 flip_mask; } fn emit_step_check(&mut self) { - if !self.hard { + if !self.sc { return; } self.step_counter += 1; - if self.in_loop { - self.write_line("add r9, r9, #1", 1, true); - self.write_line("cmp r9, r10", 1, true); - self.write_line("bne countermeasure", 1, true); - self.write_line("add r10, r10, #1", 1, true); - } else { - self.write_line("add r9, r9, #1", 1, true); - self.write_line(&format!("cmp r9, #{}", self.step_counter), 1, true); - self.write_line("bne countermeasure", 1, true); + self.write_line("add r9, r9, #1", 1, true); + self.write_line(&format!("cmp r9, #{}", self.step_counter), 1, true); + self.write_line("bne countermeasure", 1, true); - self.wh_write_line("step_counter++;", self.wh_indent); - self.wh_write_line( - &format!("if (step_counter != ({} as ui32)) {{", self.step_counter), - self.wh_indent - ); - self.wh_indent += 1; - self.wh_write_line("return (77 as ui32);", self.wh_indent); - self.wh_indent -= 1; - self.wh_write_line("}", self.wh_indent); - } + self.wh_write_line("step_counter++;", self.wh_indent); + self.wh_write_line( + &format!("if (step_counter != ({} as ui32)) {{", self.step_counter), + self.wh_indent + ); + self.wh_indent += 1; + self.wh_write_line("return (77 as ui32);", self.wh_indent); + self.wh_indent -= 1; + self.wh_write_line("}", self.wh_indent); } fn emit_print_data(&mut self) { @@ -226,7 +270,7 @@ ui32 flip_mask; self.write_line("num_buf:", 0, false); self.write_line(".space 16", 1, false); } - if self.hard { + if self.sc { self.write_line("step_counter:", 0, false); self.write_line(".word 0", 1, false); self.write_line("fault_msg:", 0, false); @@ -234,13 +278,6 @@ ui32 flip_mask; } } - fn wh_emit_if_start(&mut self, condition: Expr) { - self.wh_emit_dup_checks_for_expr(&condition); - let expr = self.wh_build_expr_str(condition); - self.wh_write_line(&format!("if ( {expr}) {{"), self.wh_indent); - self.wh_indent += 1; - } - fn emit_if(&mut self, if_stmt: Stmt) { match if_stmt { Stmt::If { condition, block, option } => { @@ -248,7 +285,9 @@ ui32 flip_mask; self.label_count += 1; self.emit_expr(condition.clone()); - self.wh_emit_if_start(condition); + let expr = self.wh_build_expr_str(condition); + self.wh_write_line(&format!("if ( {expr}) {{"), self.wh_indent); + self.wh_indent += 1; self.write_line("cmp r0, #0", 1, true); self.write_line(&format!("beq else_{}", label_id), 1, true); @@ -269,14 +308,14 @@ ui32 flip_mask; self.wh_indent -= 1; self.wh_write_line("}", self.wh_indent); - if let Some(else_block) = option { - if self.hard { + if let Some(else_block) = option.clone() { + if self.sc { self.step_counter = saved; } self.wh_write_line("else {", self.wh_indent); self.wh_indent += 1; self.emit_block(else_block, false); - if self.hard { + if self.sc { self.step_counter = std::cmp::max(self.step_counter, saved_then); self.write_line(&format!("mov r9, #{}", self.step_counter), 1, true); self.wh_write_line( @@ -289,6 +328,14 @@ ui32 flip_mask; } self.write_line(&format!("endif_{}:", label_id), 0, true); + if option.is_none() && self.sc { + self.step_counter = std::cmp::max(self.step_counter, saved_then); + self.write_line(&format!("mov r9, #{}", self.step_counter), 1, true); + self.wh_write_line( + &format!("step_counter = ({} as ui32);", self.step_counter), + self.wh_indent + ); + } } _ => panic!("emit_if called with non-if statement"), } @@ -302,10 +349,17 @@ ui32 flip_mask; let saved = self.step_counter; self.in_loop = true; - if self.hard { + self.step_counter = 0; + + self.write_line(&format!("while_{}:", label_id), 0, true); + let cond = self.wh_build_expr_str(expr.clone()); + self.wh_write_line(&format!("while ( {cond}) {{"), self.wh_indent); + self.wh_indent += 1; + if self.sc { + self.write_line(&format!("mov r9, #{}", self.step_counter), 1, true); self.write_line(&format!("mov r10, #{}", self.step_counter + 1), 1, true); + self.wh_write_line("step_counter = (0 as ui32);", self.wh_indent); } - self.write_line(&format!("while_{}:", label_id), 0, true); self.emit_step_check(); self.emit_expr(expr); @@ -317,9 +371,12 @@ ui32 flip_mask; self.write_line(&format!("b while_{}", label_id), 1, true); self.write_line(&format!("end_while_{}:", label_id), 0, true); - if self.hard { + self.wh_indent -= 1; + self.wh_write_line("}", self.wh_indent); + if self.sc { self.step_counter = saved; self.write_line(&format!("mov r9, #{}", self.step_counter), 1, true); + self.wh_write_line(&format!("step_counter = ({} as ui32);", self.step_counter), self.wh_indent); } self.in_loop = false; } @@ -422,7 +479,6 @@ ui32 flip_mask; fn emit_return(&mut self, return_stmt: Stmt, _is_main: bool) { match return_stmt { Stmt::Return(expr) => { - self.wh_emit_dup_checks_for_expr(&expr); let return_string = self.wh_build_expr_str(expr.clone()); self.wh_emit_return(&return_string); self.emit_expr(expr); @@ -450,21 +506,8 @@ ui32 flip_mask; true ); } - if self.hard && self.dup_pairs.contains_key(&name) { - let dup_name = self.dup_pairs.get(&name).unwrap(); - let dup_offset = self.locals.get(dup_name).expect("Undefined dup variable"); - if self.stack_offset - dup_offset == 0 { - self.write_line("str r0, [sp]", 1, true); - } else { - self.write_line( - &format!("str r0, [sp, #{}]", self.stack_offset - dup_offset), - 1, - true - ); - } - } self.wh_emit_assign(assign_stmt); - if self.hard { + if self.sc { self.emit_step_check(); } let pc_after = self.pc - 1; @@ -476,10 +519,6 @@ ui32 flip_mask; self.metadata.push(format!(r#".word 0x0 @ {register_string}"#)); self.metadata_current_registers.clear(); self.metadata.push(format!(r#".word 0x00000001 @ {name}"#)); - if self.hard && self.dup_pairs.contains_key(&name) { - let dup_name = self.dup_pairs.get(&name).unwrap(); - self.metadata.push(format!(r#".word 0x00000001 @ {dup_name}"#)); - } } _ => panic!("Not a valid assignment"), } @@ -487,20 +526,13 @@ ui32 flip_mask; fn wh_emit_assign(&mut self, assign_stmt: Stmt) { match assign_stmt { Stmt::AssignStatement(identifyer, expr) => { - self.wh_emit_dup_checks_for_expr(&expr); - let expr_str = self.wh_build_expr_str(expr); + let expr_str = self.wh_build_expr_str(expr.clone()); if expr_str == "".to_string() { return; } let assign_line = format!("{identifyer} = {expr_str}"); self.wh_write_line(&format!("{assign_line};"), self.wh_indent); - if self.hard && self.dup_pairs.contains_key(&identifyer) { - let dup_name = self.dup_pairs.get(&identifyer).unwrap(); - let assign_dup_line = format!("{dup_name} = {expr_str}"); - self.wh_write_line(&format!("{assign_dup_line};"), self.wh_indent); - } - self.wh_instrument_assign(assign_line.as_str()); } _ => panic!("Not an assign stmt (wh)"), @@ -553,7 +585,6 @@ ui32 flip_mask; self.wh_emit_let(let_stmt.clone()); match let_stmt { Stmt::Let(name, _type_name, expr) => { - let dup_name = format!("{}_dup", name); self.metadata_current_registers.clear(); self.metadata_current_registers.push("r0".to_string()); self.stack_offset += 4; @@ -563,17 +594,6 @@ ui32 flip_mask; self.write_line("str r0, [sp]", 1, true); self.locals.insert(name.clone(), self.stack_offset); - if self.hard { - self.stack_offset += 4; - self.write_line("sub sp, sp, #4", 1, true); - self.emit_expr(expr.clone()); - self.write_line("str r0, [sp]", 1, true); - self.locals.insert(dup_name.clone(), self.stack_offset); - self.dup_pairs.insert(name.clone(), dup_name.clone()); - self.dup_pairs.insert(dup_name.clone(), name.clone()); - self.emit_step_check(); - } - let pc_after = self.pc - 1; self.metadata.push(format!(r#".word 0x10000000 @ {curr_stmt}"#)); @@ -583,9 +603,6 @@ ui32 flip_mask; self.metadata.push(format!(r#".word 0x0 @ {register_string}"#)); self.metadata_current_registers.clear(); self.metadata.push(format!(r#".word 0x00000001 @ {name}"#)); - if self.hard { - self.metadata.push(format!(r#".word 0x00000002 @ {dup_name}"#)); - } } _ => panic!("Not a let statement format sorry "), } @@ -598,88 +615,47 @@ ui32 flip_mask; self.insert_at_line(self.next_assignment_location, combined.as_str()); self.next_assignment_location += 1; - if self.hard { - let dup_name = format!("{}_dup", name); - let combined_dup = indent_str.clone() + "ui32 " + dup_name.as_str() + ";"; - self.insert_at_line(self.next_assignment_location, combined_dup.as_str()); - self.next_assignment_location += 1; - self.dup_pairs.insert(name.clone(), dup_name.clone()); - self.dup_pairs.insert(dup_name, name.clone()); - } - - let val = self.wh_build_expr_str(expr); + let val = self.wh_build_expr_str(expr.clone()); let assign_line = name.clone() + " = " + val.as_str(); self.wh_write_line(format!("{};", assign_line.as_str()).as_str(), self.wh_indent); - if self.hard { - let dup_name = format!("{}_dup", name); - let assign_dup_line = dup_name + " = " + val.as_str(); - self.wh_write_line(format!("{};", assign_dup_line.as_str()).as_str(), self.wh_indent); - } - self.wh_instrument_assign(assign_line.as_str()); } _ => panic!("Not a let statement format sorry (wh emit)"), } } fn wh_instrument_assign(&mut self, assign_line: &str) { + self.wh_write_line( + "if (has_faulted == (0 as ui32)) {", + self.wh_indent + ); + self.wh_indent += 1; self.wh_write_line( format!("if (stmt == ({} as ui32)) {{", self.stmt).as_str(), self.wh_indent ); self.wh_indent += 1; self.wh_write_line(format!("{} ^ flip_mask;", assign_line).as_str(), self.wh_indent); + self.wh_write_line( + "has_faulted = (1 as ui32);", + self.wh_indent + ); + self.wh_indent -= 1; + self.wh_write_line("}", self.wh_indent); self.wh_indent -= 1; self.wh_write_line("}", self.wh_indent); self.stmt += 1; } - fn wh_emit_dup_check(&mut self, name: &str) { - if self.hard && self.dup_pairs.contains_key(name) { - let dup_name = self.dup_pairs.get(name).unwrap().clone(); - self.wh_write_line(&format!("if ({name} != {dup_name}) {{"), self.wh_indent); - self.wh_indent += 1; - self.wh_write_line("return (77 as ui32);", self.wh_indent); - self.wh_indent -= 1; - self.wh_write_line("}", self.wh_indent); - } - } - fn wh_emit_dup_checks_for_expr(&mut self, expr: &Expr) { - match expr { - Expr::Identifier(name) => { - self.wh_emit_dup_check(name); - } - Expr::BinaryOp(left, _, right) => { - self.wh_emit_dup_checks_for_expr(left); - self.wh_emit_dup_checks_for_expr(right); - } - Expr::UnaryOp(_, inner) => { - self.wh_emit_dup_checks_for_expr(inner); - } - _ => {} - } - } fn wh_build_expr_str(&self, expr: Expr) -> String { - // IntegerLiteral(i64), - // BooleanLiteral(bool), - // StringLiteral(String), - // Identifier(String), - // BinaryOp(Box, BinOp, Box), - // UnaryOp(UnOp, Box), match expr { - Expr::IntegerLiteral(val) => { - return format!("({val} as ui32)"); - } + Expr::IntegerLiteral(val) => format!("({val} as ui32)"), Expr::BooleanLiteral(val) => { let ival = if val { 1 } else { 0 }; - return format!("{ival}"); - } - Expr::StringLiteral(_val) => { - return "".to_string(); - } - Expr::Identifier(val) => { - return val; + format!("{ival}") } + Expr::StringLiteral(_val) => "".to_string(), + Expr::Identifier(val) => val, Expr::BinaryOp(left, op, right) => { let left_str = self.wh_build_expr_str(*left); let right_str = self.wh_build_expr_str(*right); @@ -693,11 +669,9 @@ ui32 flip_mask; BinOp::Equals => "==", BinOp::NotEquals => "!=", }; - return format!("{left_str} {op_str} {right_str}"); - } - Expr::UnaryOp(_, _) => { - return "".to_string(); + format!("{left_str} {op_str} {right_str}") } + Expr::UnaryOp(_, _) => "".to_string(), _ => panic!("building expr string went wrong"), } } @@ -715,13 +689,6 @@ ui32 flip_mask; Expr::Identifier(name) => { let offset = self.locals.get(&name).expect("Undefined variable"); self.write_line(&format!("ldr r0, [sp, #{}]", self.stack_offset - offset), 1, true); - if self.hard && self.dup_pairs.contains_key(&name) { - let dup_name = self.dup_pairs.get(&name).unwrap(); - let dup_offset = self.locals.get(dup_name).expect("Undefined dup variable"); - self.write_line(&format!("ldr r2, [sp, #{}]", self.stack_offset - dup_offset), 1, true); - self.write_line("cmp r0, r2", 1, true); - self.write_line("bne countermeasure", 1, true); - } } Expr::BinaryOp(_, _, _) => { self.emit_bin_op(expr); @@ -734,9 +701,13 @@ ui32 flip_mask; match bin_op_expr { Expr::BinaryOp(left, op, right) => { self.emit_expr(*left); - self.write_line("mov r1, r0", 1, true); // store left - self.metadata_current_registers.push_unique("r1".to_string()); + self.write_line("sub sp, sp, #4", 1, true); + self.stack_offset += 4; + self.write_line("str r0, [sp, #0]", 1, true); self.emit_expr(*right); + self.write_line("ldr r1, [sp, #0]", 1, true); + self.write_line("add sp, sp, #4", 1, true); + self.stack_offset -= 4; match op { BinOp::Add => self.write_line("add r0, r1, r0", 1, true), @@ -816,7 +787,7 @@ mod tests { .expect("Failed to create file: /temp/tests/test_can_generate_init.wh"); let ast = AST::new(); let mut codegen = CodeGenerator::new(output_file, wh_output_file); - codegen.generate(ast, false); + codegen.generate(ast, false, false); codegen.file.seek(SeekFrom::Start(0)).unwrap(); let mut buf = String::new(); codegen.file.read_to_string(&mut buf).unwrap(); @@ -862,7 +833,7 @@ mod tests { .open("temp/tests/test_can_generate_return.wh") .expect("Failed to create file: /temp/tests/test_can_generate_return.wh"); let mut codegen = CodeGenerator::new(output_file, wh_output_file); - codegen.generate(ast, false); + codegen.generate(ast, false, false); codegen.file.seek(SeekFrom::Start(0)).unwrap(); let mut buf = String::new(); codegen.file.read_to_string(&mut buf).unwrap(); @@ -914,7 +885,7 @@ mod tests { .open("temp/tests/test_can_generate_let.wh") .expect("Failed to create file: /temp/tests/test_can_generate_let.wh"); let mut codegen = CodeGenerator::new(output_file, wh_output_file); - codegen.generate(ast, false); + codegen.generate(ast, false, false); codegen.file.seek(SeekFrom::Start(0)).unwrap(); let mut buf = String::new(); codegen.file.read_to_string(&mut buf).unwrap(); @@ -973,7 +944,7 @@ mod tests { .open("temp/tests/test_can_generate_if_else.wh") .expect("Failed to create file: /temp/tests/test_can_generate_if_else.wh"); let mut codegen = CodeGenerator::new(output_file, wh_output_file); - codegen.generate(ast, false); + codegen.generate(ast, false, false); codegen.file.seek(SeekFrom::Start(0)).unwrap(); let mut buf = String::new(); codegen.file.read_to_string(&mut buf).unwrap(); @@ -1059,7 +1030,7 @@ mod tests { .open("temp/tests/test_can_generate_while.wh") .expect("Failed to create file: /temp/tests/test_can_generate_while.wh"); let mut codegen = CodeGenerator::new(output_file, wh_output_file); - codegen.generate(ast, false); + codegen.generate(ast, false, false); codegen.file.seek(SeekFrom::Start(0)).unwrap(); let mut buf = String::new(); codegen.file.read_to_string(&mut buf).unwrap(); @@ -1141,7 +1112,7 @@ mod tests { .open("temp/tests/test_can_generate_two_whiles.wh") .expect("Failed to create file: /temp/tests/test_can_generate_two_whiles.wh"); let mut codegen = CodeGenerator::new(output_file, wh_output_file); - codegen.generate(ast, false); + codegen.generate(ast, false, false); codegen.file.seek(SeekFrom::Start(0)).unwrap(); let mut buf = String::new(); codegen.file.read_to_string(&mut buf).unwrap(); @@ -1256,7 +1227,7 @@ mod tests { .open("temp/tests/test_can_generate_nested_while.wh") .expect("Failed to create file: /temp/tests/test_can_generate_nested_while.wh"); let mut codegen = CodeGenerator::new(output_file, wh_output_file); - codegen.generate(ast, false); + codegen.generate(ast, false, false); codegen.file.seek(SeekFrom::Start(0)).unwrap(); let mut buf = String::new(); codegen.file.read_to_string(&mut buf).unwrap(); @@ -1343,78 +1314,4 @@ mod tests { ).to_string(); assert_eq!(expected, buf) } - - #[test] - fn compiles_all_correct() { - initialize(); - - let test_codes_dir = std::path::Path::new("test_codes"); - let trv_files: Vec<_> = std::fs - ::read_dir(test_codes_dir) - .unwrap() - .filter_map(|entry| { - let path = entry.unwrap().path(); - if path.extension().map_or(false, |ext| ext == "trv") { - Some(path) - } else { - None - } - }) - .collect(); - - for trv_path in trv_files { - let source = std::fs::read_to_string(&trv_path).expect("Failed to read trv file"); - let mut lexer: Lexer = Lexer::new(source); - let tokens: Vec = lexer.tokenize(); - let mut parser: Parser = Parser::new(tokens); - let ast: AST = parser.parse_program(); - - let file_stem = trv_path.file_stem().unwrap().to_str().unwrap(); - let output_asm_path = format!("temp/tests/{}.s", file_stem); - let output_wh_path = format!("temp/tests/{}.wh", file_stem); - let output_file = File::options() - .read(true) - .write(true) - .create(true) - .truncate(true) - .open(&output_asm_path) - .expect(&format!("Failed to create file: {}", output_asm_path)); - - let wh_output_file = File::options() - .read(true) - .write(true) - .create(true) - .truncate(true) - .open(&output_wh_path) - .expect(&format!("Failed to create file: {}", output_wh_path)); - let mut codegen = CodeGenerator::new(output_file, wh_output_file); - codegen.generate(ast, false); - - let output_path = trv_path.with_extension("trv.output"); - let expected_exit_code = std::fs - ::read_to_string(&output_path) - .expect("Failed to read output file") - .trim() - .parse::() - .expect("Failed to parse exit code"); - - let result = std::process::Command::new("./bin/run_asm").arg(&output_asm_path).output(); - - let actual_exit_code = match result { - Ok(output) => output.status.code().unwrap_or(-1), - Err(e) => panic!("{}",e), - }; - - std::fs::remove_file(&output_asm_path).ok(); - - assert_eq!( - expected_exit_code, - actual_exit_code, - "File {}: expected exit code {}, got {}", - file_stem, - expected_exit_code, - actual_exit_code - ); - } - } } diff --git a/compiler/src/crt-rsa-enc.trv b/compiler/src/crt-rsa-enc.trv new file mode 100644 index 0000000..4defd20 --- /dev/null +++ b/compiler/src/crt-rsa-enc.trv @@ -0,0 +1,102 @@ +# CRT-RSA Encryption +# Message: 65 +# Public key: (e=17, n=3233) +# p = 61, q = 53 +# Expected ciphertext: 2790 + +func main() -> Integer { + let p : Integer = 61; + let q : Integer = 53; + let n : Integer = 3233; + let e : Integer = 17; + let m : Integer = 65; + + # CRT exponents: ep = e mod (p-1), eq = e mod (q-1) + let p_minus_1 : Integer = 0; + let q_minus_1 : Integer = 0; + let ep : Integer = 0; + let eq : Integer = 0; + + p_minus_1 = p - 1; + q_minus_1 = q - 1; + + # ep = e - (e / p_minus_1) * p_minus_1 (manual mod) + ep = e - (e / p_minus_1) * p_minus_1; + # eq = e - (e / q_minus_1) * q_minus_1 + eq = e - (e / q_minus_1) * q_minus_1; + + # c1 = m^ep mod p (modular exponentiation inlined) + let c1 : Integer = 0; + let base1 : Integer = 0; + let exp1 : Integer = 0; + c1 = 1; + base1 = m - (m / p) * p; + exp1 = ep; + while exp1 > 0 do { + if exp1 - (exp1 / 2) * 2 == 1 then { + c1 = (c1 * base1) - ((c1 * base1) / p) * p; + } + exp1 = exp1 / 2; + base1 = (base1 * base1) - ((base1 * base1) / p) * p; + } + + # c2 = m^eq mod q + let c2 : Integer = 0; + let base2 : Integer = 0; + let exp2 : Integer = 0; + c2 = 1; + base2 = m - (m / q) * q; + exp2 = eq; + while exp2 > 0 do { + if exp2 - (exp2 / 2) * 2 == 1 then { + c2 = (c2 * base2) - ((c2 * base2) / q) * q; + } + exp2 = exp2 / 2; + base2 = (base2 * base2) - ((base2 * base2) / q) * q; + } + + # qinv = q^(-1) mod p using extended Euclidean algorithm + let qinv : Integer = 0; + let t : Integer = 0; + let newt : Integer = 0; + let r : Integer = 0; + let newr : Integer = 0; + let quotient : Integer = 0; + let tmp : Integer = 0; + + t = 0; + newt = 1; + r = p; + newr = q; + while newr != 0 do { + quotient = r / newr; + tmp = t - quotient * newt; + t = newt; + newt = tmp; + tmp = r - quotient * newr; + r = newr; + newr = tmp; + } + if t < 0 then { + qinv = t + p; + } else { + qinv = t; + } + + # h = qinv * (c1 - c2) mod p + let h : Integer = 0; + let diff : Integer = 0; + diff = c1 - c2; + h = qinv * diff - (qinv * diff / p) * p; + if h < 0 then { + h = h + p; + } + + # c = c2 + h * q + let c : Integer = 0; + c = c2 + h * q; + + print c; + + return c; +} diff --git a/compiler/src/crt-rsa.trv b/compiler/src/crt-rsa.trv new file mode 100644 index 0000000..2243e4c --- /dev/null +++ b/compiler/src/crt-rsa.trv @@ -0,0 +1,110 @@ +# CRT-RSA Decryption +# Message: 65 +# Public key: (e=17, n=3233) +# p = 61, q = 53 +# d (private exponent) = 2753 +# Ciphertext c = 2790 +# Expected result: 65 + +func main() -> Integer { + let p : Integer = 61; + let q : Integer = 53; + let n : Integer = 3233; + let d : Integer = 2753; + let c : Integer = 2790; + + # CRT exponents: dp = d mod (p-1), dq = d mod (q-1) + let p_minus_1 : Integer = 0; + let q_minus_1 : Integer = 0; + let dp : Integer = 0; + let dq : Integer = 0; + + p_minus_1 = p - 1; + q_minus_1 = q - 1; + + # dp = d - (d / p_minus_1) * p_minus_1 (manual mod) + dp = d - (d / p_minus_1) * p_minus_1; + # dq = d - (d / q_minus_1) * q_minus_1 + dq = d - (d / q_minus_1) * q_minus_1; + + # m1 = c^dp mod p (modular exponentiation inlined) + let m1 : Integer = 0; + let base1 : Integer = 0; + let exp1 : Integer = 0; + m1 = 1; + base1 = c - (c / p) * p; + exp1 = dp; + while exp1 > 0 do { + if exp1 - (exp1 / 2) * 2 == 1 then { + m1 = (m1 * base1) - ((m1 * base1) / p) * p; + } + exp1 = exp1 / 2; + base1 = (base1 * base1) - ((base1 * base1) / p) * p; + } + + # Single-event upset: bit-flip in m1 (Bellcore-style fault) + # This flips the LSB of m1 exactly once, leaking info via faulty CRT output + let fault_triggered : Integer = 0; + if fault_triggered == 0 then { + m1 = m1 + 1; + fault_triggered = 1; + } + + # m2 = c^dq mod q + let m2 : Integer = 0; + let base2 : Integer = 0; + let exp2 : Integer = 0; + m2 = 1; + base2 = c - (c / q) * q; + exp2 = dq; + while exp2 > 0 do { + if exp2 - (exp2 / 2) * 2 == 1 then { + m2 = (m2 * base2) - ((m2 * base2) / q) * q; + } + exp2 = exp2 / 2; + base2 = (base2 * base2) - ((base2 * base2) / q) * q; + } + + # qinv = q^(-1) mod p using extended Euclidean algorithm + let qinv : Integer = 0; + let t : Integer = 0; + let newt : Integer = 0; + let r : Integer = 0; + let newr : Integer = 0; + let quotient : Integer = 0; + let tmp : Integer = 0; + + t = 0; + newt = 1; + r = p; + newr = q; + while newr != 0 do { + quotient = r / newr; + tmp = t - quotient * newt; + t = newt; + newt = tmp; + tmp = r - quotient * newr; + r = newr; + newr = tmp; + } + if t < 0 then { + qinv = t + p; + } else { + qinv = t; + } + + # h = qinv * (m1 - m2) mod p + let h : Integer = 0; + let diff : Integer = 0; + diff = m1 - m2; + h = qinv * diff - (qinv * diff / p) * p; + if h < 0 then { + h = h + p; + } + + # m = m2 + h * q + let m : Integer = 0; + m = m2 + h * q; + + return m; +} diff --git a/compiler/src/fuzz_bellcore.py b/compiler/src/fuzz_bellcore.py new file mode 100644 index 0000000..905c18b --- /dev/null +++ b/compiler/src/fuzz_bellcore.py @@ -0,0 +1,270 @@ +#!/usr/bin/env python3 +"""Bellcore attack fuzzer - tests fault injection with random keys and messages.""" + +import subprocess +import math +import random +import os +import sys +import tempfile + +COMPILER = "/home/pbk/school/P10-Master/compiler/target/release/trivic" +RUNNER = "/home/pbk/school/P10-Master/compiler/bin/run_asm" +OUT_DIR = "/tmp/bellcore_fuzz" + +os.makedirs(OUT_DIR, exist_ok=True) + +def is_prime(n): + if n < 2: return False + if n < 4: return True + if n % 2 == 0 or n % 3 == 0: return False + i = 5 + while i * i <= n: + if n % i == 0 or n % (i + 2) == 0: return False + i += 6 + return True + +def mod_pow(base, exp, mod): + result = 1 + base = base % mod + while exp > 0: + if exp % 2 == 1: + result = (result * base) % mod + exp //= 2 + base = (base * base) % mod + return result + +def mod_inverse(a, m): + g, x, _ = extended_gcd(a, m) + if g != 1: + raise ValueError("No modular inverse") + return x % m + +def extended_gcd(a, b): + if a == 0: + return b, 0, 1 + g, x, y = extended_gcd(b % a, a) + return g, y - (b // a) * x, x + +def gen_small_prime(min_val=30, max_val=200): + while True: + p = random.randint(min_val, max_val) + if is_prime(p): + return p + +def gen_keypair(): + p = gen_small_prime() + q = gen_small_prime() + while q == p: + q = gen_small_prime() + n = p * q + phi = (p - 1) * (q - 1) + e = 17 + while math.gcd(e, phi) != 1: + e = random.randint(3, phi - 1) + d = mod_inverse(e, phi) + return p, q, n, e, d + +def make_trv(p, q, n, e, m, out_path): + src = f"""# CRT-RSA Encryption (fuzzed) +# Message: {m} +# Public key: (e={e}, n={n}) +# p = {p}, q = {q} + +func main() -> Integer {{ + let p : Integer = {p}; + let q : Integer = {q}; + let n : Integer = {n}; + let e : Integer = {e}; + let m : Integer = {m}; + + let p_minus_1 : Integer = 0; + let q_minus_1 : Integer = 0; + let ep : Integer = 0; + let eq : Integer = 0; + + p_minus_1 = p - 1; + q_minus_1 = q - 1; + + ep = e - (e / p_minus_1) * p_minus_1; + eq = e - (e / q_minus_1) * q_minus_1; + + let c1 : Integer = 0; + let base1 : Integer = 0; + let exp1 : Integer = 0; + c1 = 1; + base1 = m - (m / p) * p; + exp1 = ep; + while exp1 > 0 do {{ + if exp1 - (exp1 / 2) * 2 == 1 then {{ + c1 = (c1 * base1) - ((c1 * base1) / p) * p; + }} + exp1 = exp1 / 2; + base1 = (base1 * base1) - ((base1 * base1) / p) * p; + }} + + # SEU: bit-flip in c1 (Bellcore-style fault) + let fault_triggered : Integer = 0; + if fault_triggered == 0 then {{ + c1 = c1 + 1; + fault_triggered = 1; + }} + + let c2 : Integer = 0; + let base2 : Integer = 0; + let exp2 : Integer = 0; + c2 = 1; + base2 = m - (m / q) * q; + exp2 = eq; + while exp2 > 0 do {{ + if exp2 - (exp2 / 2) * 2 == 1 then {{ + c2 = (c2 * base2) - ((c2 * base2) / q) * q; + }} + exp2 = exp2 / 2; + base2 = (base2 * base2) - ((base2 * base2) / q) * q; + }} + + let qinv : Integer = 0; + let t : Integer = 0; + let newt : Integer = 0; + let r : Integer = 0; + let newr : Integer = 0; + let quotient : Integer = 0; + let tmp : Integer = 0; + + t = 0; + newt = 1; + r = p; + newr = q; + while newr != 0 do {{ + quotient = r / newr; + tmp = t - quotient * newt; + t = newt; + newt = tmp; + tmp = r - quotient * newr; + r = newr; + newr = tmp; + }} + if t < 0 then {{ + qinv = t + p; + }} else {{ + qinv = t; + }} + + let h : Integer = 0; + let diff : Integer = 0; + diff = c1 - c2; + h = qinv * diff - (qinv * diff / p) * p; + if h < 0 then {{ + h = h + p; + }} + + let c : Integer = 0; + c = c2 + h * q; + + print c; + + return c; +}} +""" + with open(out_path, 'w') as f: + f.write(src) + +def run_attack(p, q, n, e, m, iteration): + trv_path = os.path.join(OUT_DIR, f"test_{iteration}.trv") + base_path = os.path.join(OUT_DIR, f"test_{iteration}") + s_path = base_path + ".s" + + make_trv(p, q, n, e, m, trv_path) + + # Compile (compiler appends .s automatically) + result = subprocess.run( + [COMPILER, trv_path, "-o", base_path], + capture_output=True, text=True, timeout=10 + ) + if result.returncode != 0: + print(f" [!] Compile failed: {result.stderr.strip()}") + return False + + # Run (run_asm expects relative paths, so we cd to OUT_DIR) + result = subprocess.run( + [RUNNER, f"test_{iteration}.s"], + capture_output=True, text=True, timeout=10, + cwd=OUT_DIR + ) + + output = result.stdout.strip() + lines = [l.strip() for l in output.splitlines() if l.strip()] + faulty_c = None + for line in reversed(lines): + try: + faulty_c = int(line) + break + except ValueError: + continue + + if faulty_c is None: + print(f" [!] Could not parse output") + return False + + correct_c = mod_pow(m, e, n) + + if faulty_c == correct_c: + print(f" [!] No fault triggered (c' == c)") + return False + + diff = abs(faulty_c - correct_c) + recovered = math.gcd(diff, n) + + if recovered == q: + print(f" [+] Recovered q={recovered} (p={p})") + return True + elif recovered == p: + print(f" [+] Recovered p={recovered} (q={q})") + return True + else: + print(f" [!] gcd={recovered}, expected p={p} or q={q}") + return False + +def main(): + print("=" * 60) + print("Bellcore Attack Fuzzer") + print("=" * 60) + + tests = [ + # (p, q, n, e, m, label) + (61, 53, 3233, 17, 65, "original"), + (71, 89, 6319, 17, 42, "small primes"), + (97, 101, 9797, 17, 123, "medium primes"), + (113, 127, 14351, 17, 999, "larger primes"), + (131, 137, 17947, 17, 5000, "even larger"), + (151, 157, 23707, 17, 12345, "big message"), + ] + + # Add random tests + for i in range(5): + p, q, n, e, d = gen_keypair() + m = random.randint(2, n - 1) + tests.append((p, q, n, e, m, f"random #{i+1}")) + + passed = 0 + total = len(tests) + + for i, (p, q, n, e, m, label) in enumerate(tests): + correct_c = mod_pow(m, e, n) + print(f"\n[{i+1}/{total}] {label}: p={p}, q={q}, n={n}, e={e}, m={m}") + print(f" correct ciphertext = {correct_c}") + + if run_attack(p, q, n, e, m, i): + passed += 1 + + print(f"\n{'=' * 60}") + print(f"Results: {passed}/{total} attacks succeeded") + if passed == total: + print("ALL TESTS PASSED - fault injection consistently leaks key!") + else: + print(f"{total - passed} test(s) failed") + print(f"{'=' * 60}") + +if __name__ == "__main__": + main() diff --git a/compiler/src/main.rs b/compiler/src/main.rs index 70a0a6b..f05862d 100644 --- a/compiler/src/main.rs +++ b/compiler/src/main.rs @@ -27,7 +27,10 @@ struct Args { hard: bool, #[arg(long)] - normal: bool, + sc: bool, + + #[arg(long)] + vd: bool, } fn main() { @@ -57,8 +60,15 @@ fn main() { let mut parser: Parser = Parser::new(_tokens); let _ast: AST = parser.parse_program(); let mut codegen: CodeGenerator = CodeGenerator::new(output,wh_output); - let mut hard = false; - codegen.generate(_ast, args.hard); + let mut sc = args.sc; + let mut vd = args.vd; + + if args.hard { + sc = true; + vd = true; + } + + codegen.generate(_ast, sc, vd); diff --git a/compiler/src/out-hard.s.wh b/compiler/src/out-hard.s.wh new file mode 100644 index 0000000..20ec996 --- /dev/null +++ b/compiler/src/out-hard.s.wh @@ -0,0 +1,849 @@ +ui32 res; +ui32 stmt; +ui32 bit_shift; +ui32 flip_mask; + +fn main(ui32 stmt, ui32 flip_mask) -> ui32 { + ui32 p; + ui32 p_dup; + ui32 q; + ui32 q_dup; + ui32 n; + ui32 n_dup; + ui32 d; + ui32 d_dup; + ui32 c; + ui32 c_dup; + ui32 p_minus_1; + ui32 p_minus_1_dup; + ui32 q_minus_1; + ui32 q_minus_1_dup; + ui32 dp; + ui32 dp_dup; + ui32 dq; + ui32 dq_dup; + ui32 m1; + ui32 m1_dup; + ui32 base1; + ui32 base1_dup; + ui32 exp1; + ui32 exp1_dup; + ui32 fault_triggered; + ui32 fault_triggered_dup; + ui32 m2; + ui32 m2_dup; + ui32 base2; + ui32 base2_dup; + ui32 exp2; + ui32 exp2_dup; + ui32 qinv; + ui32 qinv_dup; + ui32 t; + ui32 t_dup; + ui32 newt; + ui32 newt_dup; + ui32 r; + ui32 r_dup; + ui32 newr; + ui32 newr_dup; + ui32 quotient; + ui32 quotient_dup; + ui32 tmp; + ui32 tmp_dup; + ui32 h; + ui32 h_dup; + ui32 diff; + ui32 diff_dup; + ui32 m; + ui32 m_dup; + ui32 step_counter; + step_counter = (0 as ui32); + p = (61 as ui32); + p_dup = (61 as ui32); + if (stmt == (0 as ui32)) { + p = (61 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (1 as ui32)) { + return (77 as ui32); + } + q = (53 as ui32); + q_dup = (53 as ui32); + if (stmt == (1 as ui32)) { + q = (53 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (2 as ui32)) { + return (77 as ui32); + } + n = (3233 as ui32); + n_dup = (3233 as ui32); + if (stmt == (2 as ui32)) { + n = (3233 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (3 as ui32)) { + return (77 as ui32); + } + d = (2753 as ui32); + d_dup = (2753 as ui32); + if (stmt == (3 as ui32)) { + d = (2753 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (4 as ui32)) { + return (77 as ui32); + } + c = (2790 as ui32); + c_dup = (2790 as ui32); + if (stmt == (4 as ui32)) { + c = (2790 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (5 as ui32)) { + return (77 as ui32); + } + p_minus_1 = (0 as ui32); + p_minus_1_dup = (0 as ui32); + if (stmt == (5 as ui32)) { + p_minus_1 = (0 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (6 as ui32)) { + return (77 as ui32); + } + q_minus_1 = (0 as ui32); + q_minus_1_dup = (0 as ui32); + if (stmt == (6 as ui32)) { + q_minus_1 = (0 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (7 as ui32)) { + return (77 as ui32); + } + dp = (0 as ui32); + dp_dup = (0 as ui32); + if (stmt == (7 as ui32)) { + dp = (0 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (8 as ui32)) { + return (77 as ui32); + } + dq = (0 as ui32); + dq_dup = (0 as ui32); + if (stmt == (8 as ui32)) { + dq = (0 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (9 as ui32)) { + return (77 as ui32); + } + if (p != p_dup) { + return (77 as ui32); + } + p_minus_1 = p - (1 as ui32); + p_minus_1_dup = p - (1 as ui32); + if (stmt == (9 as ui32)) { + p_minus_1 = p - (1 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (10 as ui32)) { + return (77 as ui32); + } + if (q != q_dup) { + return (77 as ui32); + } + q_minus_1 = q - (1 as ui32); + q_minus_1_dup = q - (1 as ui32); + if (stmt == (10 as ui32)) { + q_minus_1 = q - (1 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (11 as ui32)) { + return (77 as ui32); + } + if (d != d_dup) { + return (77 as ui32); + } + if (d != d_dup) { + return (77 as ui32); + } + if (p_minus_1 != p_minus_1_dup) { + return (77 as ui32); + } + if (p_minus_1 != p_minus_1_dup) { + return (77 as ui32); + } + dp = d - d / p_minus_1 * p_minus_1; + dp_dup = d - d / p_minus_1 * p_minus_1; + if (stmt == (11 as ui32)) { + dp = d - d / p_minus_1 * p_minus_1 ^ flip_mask; + } + step_counter++; + if (step_counter != (12 as ui32)) { + return (77 as ui32); + } + if (d != d_dup) { + return (77 as ui32); + } + if (d != d_dup) { + return (77 as ui32); + } + if (q_minus_1 != q_minus_1_dup) { + return (77 as ui32); + } + if (q_minus_1 != q_minus_1_dup) { + return (77 as ui32); + } + dq = d - d / q_minus_1 * q_minus_1; + dq_dup = d - d / q_minus_1 * q_minus_1; + if (stmt == (12 as ui32)) { + dq = d - d / q_minus_1 * q_minus_1 ^ flip_mask; + } + step_counter++; + if (step_counter != (13 as ui32)) { + return (77 as ui32); + } + m1 = (0 as ui32); + m1_dup = (0 as ui32); + if (stmt == (13 as ui32)) { + m1 = (0 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (14 as ui32)) { + return (77 as ui32); + } + base1 = (0 as ui32); + base1_dup = (0 as ui32); + if (stmt == (14 as ui32)) { + base1 = (0 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (15 as ui32)) { + return (77 as ui32); + } + exp1 = (0 as ui32); + exp1_dup = (0 as ui32); + if (stmt == (15 as ui32)) { + exp1 = (0 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (16 as ui32)) { + return (77 as ui32); + } + m1 = (1 as ui32); + m1_dup = (1 as ui32); + if (stmt == (16 as ui32)) { + m1 = (1 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (17 as ui32)) { + return (77 as ui32); + } + if (c != c_dup) { + return (77 as ui32); + } + if (c != c_dup) { + return (77 as ui32); + } + if (p != p_dup) { + return (77 as ui32); + } + if (p != p_dup) { + return (77 as ui32); + } + base1 = c - c / p * p; + base1_dup = c - c / p * p; + if (stmt == (17 as ui32)) { + base1 = c - c / p * p ^ flip_mask; + } + step_counter++; + if (step_counter != (18 as ui32)) { + return (77 as ui32); + } + if (dp != dp_dup) { + return (77 as ui32); + } + exp1 = dp; + exp1_dup = dp; + if (stmt == (18 as ui32)) { + exp1 = dp ^ flip_mask; + } + step_counter++; + if (step_counter != (19 as ui32)) { + return (77 as ui32); + } + if (exp1 != exp1_dup) { + return (77 as ui32); + } + if (exp1 != exp1_dup) { + return (77 as ui32); + } + if ( exp1 - exp1 / (2 as ui32) * (2 as ui32) == (1 as ui32)) { + if (m1 != m1_dup) { + return (77 as ui32); + } + if (base1 != base1_dup) { + return (77 as ui32); + } + if (m1 != m1_dup) { + return (77 as ui32); + } + if (base1 != base1_dup) { + return (77 as ui32); + } + if (p != p_dup) { + return (77 as ui32); + } + if (p != p_dup) { + return (77 as ui32); + } + m1 = m1 * base1 - m1 * base1 / p * p; + m1_dup = m1 * base1 - m1 * base1 / p * p; + if (stmt == (19 as ui32)) { + m1 = m1 * base1 - m1 * base1 / p * p ^ flip_mask; + } + } + if (exp1 != exp1_dup) { + return (77 as ui32); + } + exp1 = exp1 / (2 as ui32); + exp1_dup = exp1 / (2 as ui32); + if (stmt == (20 as ui32)) { + exp1 = exp1 / (2 as ui32) ^ flip_mask; + } + if (base1 != base1_dup) { + return (77 as ui32); + } + if (base1 != base1_dup) { + return (77 as ui32); + } + if (base1 != base1_dup) { + return (77 as ui32); + } + if (base1 != base1_dup) { + return (77 as ui32); + } + if (p != p_dup) { + return (77 as ui32); + } + if (p != p_dup) { + return (77 as ui32); + } + base1 = base1 * base1 - base1 * base1 / p * p; + base1_dup = base1 * base1 - base1 * base1 / p * p; + if (stmt == (21 as ui32)) { + base1 = base1 * base1 - base1 * base1 / p * p ^ flip_mask; + } + fault_triggered = (0 as ui32); + fault_triggered_dup = (0 as ui32); + if (stmt == (22 as ui32)) { + fault_triggered = (0 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (20 as ui32)) { + return (77 as ui32); + } + if (fault_triggered != fault_triggered_dup) { + return (77 as ui32); + } + if ( fault_triggered == (0 as ui32)) { + step_counter++; + if (step_counter != (21 as ui32)) { + return (77 as ui32); + } + if (m1 != m1_dup) { + return (77 as ui32); + } + m1 = m1 + (1 as ui32); + m1_dup = m1 + (1 as ui32); + if (stmt == (23 as ui32)) { + m1 = m1 + (1 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (22 as ui32)) { + return (77 as ui32); + } + fault_triggered = (1 as ui32); + fault_triggered_dup = (1 as ui32); + if (stmt == (24 as ui32)) { + fault_triggered = (1 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (23 as ui32)) { + return (77 as ui32); + } + } + m2 = (0 as ui32); + m2_dup = (0 as ui32); + if (stmt == (25 as ui32)) { + m2 = (0 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (24 as ui32)) { + return (77 as ui32); + } + base2 = (0 as ui32); + base2_dup = (0 as ui32); + if (stmt == (26 as ui32)) { + base2 = (0 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (25 as ui32)) { + return (77 as ui32); + } + exp2 = (0 as ui32); + exp2_dup = (0 as ui32); + if (stmt == (27 as ui32)) { + exp2 = (0 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (26 as ui32)) { + return (77 as ui32); + } + m2 = (1 as ui32); + m2_dup = (1 as ui32); + if (stmt == (28 as ui32)) { + m2 = (1 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (27 as ui32)) { + return (77 as ui32); + } + if (c != c_dup) { + return (77 as ui32); + } + if (c != c_dup) { + return (77 as ui32); + } + if (q != q_dup) { + return (77 as ui32); + } + if (q != q_dup) { + return (77 as ui32); + } + base2 = c - c / q * q; + base2_dup = c - c / q * q; + if (stmt == (29 as ui32)) { + base2 = c - c / q * q ^ flip_mask; + } + step_counter++; + if (step_counter != (28 as ui32)) { + return (77 as ui32); + } + if (dq != dq_dup) { + return (77 as ui32); + } + exp2 = dq; + exp2_dup = dq; + if (stmt == (30 as ui32)) { + exp2 = dq ^ flip_mask; + } + step_counter++; + if (step_counter != (29 as ui32)) { + return (77 as ui32); + } + if (exp2 != exp2_dup) { + return (77 as ui32); + } + if (exp2 != exp2_dup) { + return (77 as ui32); + } + if ( exp2 - exp2 / (2 as ui32) * (2 as ui32) == (1 as ui32)) { + if (m2 != m2_dup) { + return (77 as ui32); + } + if (base2 != base2_dup) { + return (77 as ui32); + } + if (m2 != m2_dup) { + return (77 as ui32); + } + if (base2 != base2_dup) { + return (77 as ui32); + } + if (q != q_dup) { + return (77 as ui32); + } + if (q != q_dup) { + return (77 as ui32); + } + m2 = m2 * base2 - m2 * base2 / q * q; + m2_dup = m2 * base2 - m2 * base2 / q * q; + if (stmt == (31 as ui32)) { + m2 = m2 * base2 - m2 * base2 / q * q ^ flip_mask; + } + } + if (exp2 != exp2_dup) { + return (77 as ui32); + } + exp2 = exp2 / (2 as ui32); + exp2_dup = exp2 / (2 as ui32); + if (stmt == (32 as ui32)) { + exp2 = exp2 / (2 as ui32) ^ flip_mask; + } + if (base2 != base2_dup) { + return (77 as ui32); + } + if (base2 != base2_dup) { + return (77 as ui32); + } + if (base2 != base2_dup) { + return (77 as ui32); + } + if (base2 != base2_dup) { + return (77 as ui32); + } + if (q != q_dup) { + return (77 as ui32); + } + if (q != q_dup) { + return (77 as ui32); + } + base2 = base2 * base2 - base2 * base2 / q * q; + base2_dup = base2 * base2 - base2 * base2 / q * q; + if (stmt == (33 as ui32)) { + base2 = base2 * base2 - base2 * base2 / q * q ^ flip_mask; + } + qinv = (0 as ui32); + qinv_dup = (0 as ui32); + if (stmt == (34 as ui32)) { + qinv = (0 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (30 as ui32)) { + return (77 as ui32); + } + t = (0 as ui32); + t_dup = (0 as ui32); + if (stmt == (35 as ui32)) { + t = (0 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (31 as ui32)) { + return (77 as ui32); + } + newt = (0 as ui32); + newt_dup = (0 as ui32); + if (stmt == (36 as ui32)) { + newt = (0 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (32 as ui32)) { + return (77 as ui32); + } + r = (0 as ui32); + r_dup = (0 as ui32); + if (stmt == (37 as ui32)) { + r = (0 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (33 as ui32)) { + return (77 as ui32); + } + newr = (0 as ui32); + newr_dup = (0 as ui32); + if (stmt == (38 as ui32)) { + newr = (0 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (34 as ui32)) { + return (77 as ui32); + } + quotient = (0 as ui32); + quotient_dup = (0 as ui32); + if (stmt == (39 as ui32)) { + quotient = (0 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (35 as ui32)) { + return (77 as ui32); + } + tmp = (0 as ui32); + tmp_dup = (0 as ui32); + if (stmt == (40 as ui32)) { + tmp = (0 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (36 as ui32)) { + return (77 as ui32); + } + t = (0 as ui32); + t_dup = (0 as ui32); + if (stmt == (41 as ui32)) { + t = (0 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (37 as ui32)) { + return (77 as ui32); + } + newt = (1 as ui32); + newt_dup = (1 as ui32); + if (stmt == (42 as ui32)) { + newt = (1 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (38 as ui32)) { + return (77 as ui32); + } + if (p != p_dup) { + return (77 as ui32); + } + r = p; + r_dup = p; + if (stmt == (43 as ui32)) { + r = p ^ flip_mask; + } + step_counter++; + if (step_counter != (39 as ui32)) { + return (77 as ui32); + } + if (q != q_dup) { + return (77 as ui32); + } + newr = q; + newr_dup = q; + if (stmt == (44 as ui32)) { + newr = q ^ flip_mask; + } + step_counter++; + if (step_counter != (40 as ui32)) { + return (77 as ui32); + } + if (r != r_dup) { + return (77 as ui32); + } + if (newr != newr_dup) { + return (77 as ui32); + } + quotient = r / newr; + quotient_dup = r / newr; + if (stmt == (45 as ui32)) { + quotient = r / newr ^ flip_mask; + } + if (t != t_dup) { + return (77 as ui32); + } + if (quotient != quotient_dup) { + return (77 as ui32); + } + if (newt != newt_dup) { + return (77 as ui32); + } + tmp = t - quotient * newt; + tmp_dup = t - quotient * newt; + if (stmt == (46 as ui32)) { + tmp = t - quotient * newt ^ flip_mask; + } + if (newt != newt_dup) { + return (77 as ui32); + } + t = newt; + t_dup = newt; + if (stmt == (47 as ui32)) { + t = newt ^ flip_mask; + } + if (tmp != tmp_dup) { + return (77 as ui32); + } + newt = tmp; + newt_dup = tmp; + if (stmt == (48 as ui32)) { + newt = tmp ^ flip_mask; + } + if (r != r_dup) { + return (77 as ui32); + } + if (quotient != quotient_dup) { + return (77 as ui32); + } + if (newr != newr_dup) { + return (77 as ui32); + } + tmp = r - quotient * newr; + tmp_dup = r - quotient * newr; + if (stmt == (49 as ui32)) { + tmp = r - quotient * newr ^ flip_mask; + } + if (newr != newr_dup) { + return (77 as ui32); + } + r = newr; + r_dup = newr; + if (stmt == (50 as ui32)) { + r = newr ^ flip_mask; + } + if (tmp != tmp_dup) { + return (77 as ui32); + } + newr = tmp; + newr_dup = tmp; + if (stmt == (51 as ui32)) { + newr = tmp ^ flip_mask; + } + if (t != t_dup) { + return (77 as ui32); + } + if ( t < (0 as ui32)) { + step_counter++; + if (step_counter != (41 as ui32)) { + return (77 as ui32); + } + if (t != t_dup) { + return (77 as ui32); + } + if (p != p_dup) { + return (77 as ui32); + } + qinv = t + p; + qinv_dup = t + p; + if (stmt == (52 as ui32)) { + qinv = t + p ^ flip_mask; + } + step_counter++; + if (step_counter != (42 as ui32)) { + return (77 as ui32); + } + } + else { + if (t != t_dup) { + return (77 as ui32); + } + qinv = t; + qinv_dup = t; + if (stmt == (53 as ui32)) { + qinv = t ^ flip_mask; + } + step_counter++; + if (step_counter != (41 as ui32)) { + return (77 as ui32); + } + step_counter = (42 as ui32); + } + h = (0 as ui32); + h_dup = (0 as ui32); + if (stmt == (54 as ui32)) { + h = (0 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (43 as ui32)) { + return (77 as ui32); + } + diff = (0 as ui32); + diff_dup = (0 as ui32); + if (stmt == (55 as ui32)) { + diff = (0 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (44 as ui32)) { + return (77 as ui32); + } + if (m1 != m1_dup) { + return (77 as ui32); + } + if (m2 != m2_dup) { + return (77 as ui32); + } + diff = m1 - m2; + diff_dup = m1 - m2; + if (stmt == (56 as ui32)) { + diff = m1 - m2 ^ flip_mask; + } + step_counter++; + if (step_counter != (45 as ui32)) { + return (77 as ui32); + } + if (qinv != qinv_dup) { + return (77 as ui32); + } + if (diff != diff_dup) { + return (77 as ui32); + } + if (qinv != qinv_dup) { + return (77 as ui32); + } + if (diff != diff_dup) { + return (77 as ui32); + } + if (p != p_dup) { + return (77 as ui32); + } + if (p != p_dup) { + return (77 as ui32); + } + h = qinv * diff - qinv * diff / p * p; + h_dup = qinv * diff - qinv * diff / p * p; + if (stmt == (57 as ui32)) { + h = qinv * diff - qinv * diff / p * p ^ flip_mask; + } + step_counter++; + if (step_counter != (46 as ui32)) { + return (77 as ui32); + } + if (h != h_dup) { + return (77 as ui32); + } + if ( h < (0 as ui32)) { + step_counter++; + if (step_counter != (47 as ui32)) { + return (77 as ui32); + } + if (h != h_dup) { + return (77 as ui32); + } + if (p != p_dup) { + return (77 as ui32); + } + h = h + p; + h_dup = h + p; + if (stmt == (58 as ui32)) { + h = h + p ^ flip_mask; + } + step_counter++; + if (step_counter != (48 as ui32)) { + return (77 as ui32); + } + } + m = (0 as ui32); + m_dup = (0 as ui32); + if (stmt == (59 as ui32)) { + m = (0 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (49 as ui32)) { + return (77 as ui32); + } + if (m2 != m2_dup) { + return (77 as ui32); + } + if (h != h_dup) { + return (77 as ui32); + } + if (q != q_dup) { + return (77 as ui32); + } + m = m2 + h * q; + m_dup = m2 + h * q; + if (stmt == (60 as ui32)) { + m = m2 + h * q ^ flip_mask; + } + step_counter++; + if (step_counter != (50 as ui32)) { + return (77 as ui32); + } + if (m != m_dup) { + return (77 as ui32); + } + return (m as ui32); +} +stmt = (? as ui32); +bit_shift = (? as ui32); +assume (bit_shift <= (31 as ui32)); +assume (bit_shift >= (0 as ui32)); +assume (stmt >= (0 as ui32)); +assume (stmt <= (60 as ui32)); +flip_mask = ((1 as ui32) << bit_shift); + +res = main(stmt, flip_mask); +assert(res == (0 as ui32)); diff --git a/compiler/src/out.s b/compiler/src/out.s new file mode 100644 index 0000000..b092293 --- /dev/null +++ b/compiler/src/out.s @@ -0,0 +1,977 @@ +.syntax unified +.thumb + +.section .text +.global _start +.type _start, %function + +_start: + sub sp, sp, #4 + mov r0, #61 + str r0, [sp] + sub sp, sp, #4 + mov r0, #53 + str r0, [sp] + sub sp, sp, #4 + mov r0, #3233 + str r0, [sp] + sub sp, sp, #4 + mov r0, #17 + str r0, [sp] + sub sp, sp, #4 + mov r0, #65 + str r0, [sp] + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + ldr r0, [sp, #32] + sub sp, sp, #4 + str r0, [sp, #0] + mov r0, #1 + ldr r1, [sp, #0] + add sp, sp, #4 + sub r0, r1, r0 + str r0, [sp, #12] + ldr r0, [sp, #28] + sub sp, sp, #4 + str r0, [sp, #0] + mov r0, #1 + ldr r1, [sp, #0] + add sp, sp, #4 + sub r0, r1, r0 + str r0, [sp, #8] + ldr r0, [sp, #20] + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #24] + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #20] + ldr r1, [sp, #0] + add sp, sp, #4 + sdiv r0, r1, r0 + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #20] + ldr r1, [sp, #0] + add sp, sp, #4 + mul r0, r1, r0 + ldr r1, [sp, #0] + add sp, sp, #4 + sub r0, r1, r0 + str r0, [sp, #4] + ldr r0, [sp, #20] + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #24] + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #16] + ldr r1, [sp, #0] + add sp, sp, #4 + sdiv r0, r1, r0 + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #16] + ldr r1, [sp, #0] + add sp, sp, #4 + mul r0, r1, r0 + ldr r1, [sp, #0] + add sp, sp, #4 + sub r0, r1, r0 + str r0, [sp] + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + mov r0, #1 + str r0, [sp, #8] + ldr r0, [sp, #28] + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #32] + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #52] + ldr r1, [sp, #0] + add sp, sp, #4 + sdiv r0, r1, r0 + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #52] + ldr r1, [sp, #0] + add sp, sp, #4 + mul r0, r1, r0 + ldr r1, [sp, #0] + add sp, sp, #4 + sub r0, r1, r0 + str r0, [sp, #4] + ldr r0, [sp, #16] + str r0, [sp] +while_0: + ldr r0, [sp, #0] + sub sp, sp, #4 + str r0, [sp, #0] + mov r0, #0 + ldr r1, [sp, #0] + add sp, sp, #4 + cmp r1, r0 + mov r0, #0 + it gt + movgt r0, #1 + cmp r0, #0 + beq end_while_0 + ldr r0, [sp, #0] + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #4] + sub sp, sp, #4 + str r0, [sp, #0] + mov r0, #2 + ldr r1, [sp, #0] + add sp, sp, #4 + sdiv r0, r1, r0 + sub sp, sp, #4 + str r0, [sp, #0] + mov r0, #2 + ldr r1, [sp, #0] + add sp, sp, #4 + mul r0, r1, r0 + ldr r1, [sp, #0] + add sp, sp, #4 + sub r0, r1, r0 + sub sp, sp, #4 + str r0, [sp, #0] + mov r0, #1 + ldr r1, [sp, #0] + add sp, sp, #4 + cmp r1, r0 + mov r0, #0 + it eq + moveq r0, #1 + cmp r0, #0 + beq else_1 + ldr r0, [sp, #8] + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #8] + ldr r1, [sp, #0] + add sp, sp, #4 + mul r0, r1, r0 + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #12] + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #12] + ldr r1, [sp, #0] + add sp, sp, #4 + mul r0, r1, r0 + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #52] + ldr r1, [sp, #0] + add sp, sp, #4 + sdiv r0, r1, r0 + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #52] + ldr r1, [sp, #0] + add sp, sp, #4 + mul r0, r1, r0 + ldr r1, [sp, #0] + add sp, sp, #4 + sub r0, r1, r0 + str r0, [sp, #8] + b endif_1 +else_1: +endif_1: + ldr r0, [sp, #0] + sub sp, sp, #4 + str r0, [sp, #0] + mov r0, #2 + ldr r1, [sp, #0] + add sp, sp, #4 + sdiv r0, r1, r0 + str r0, [sp] + ldr r0, [sp, #4] + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #8] + ldr r1, [sp, #0] + add sp, sp, #4 + mul r0, r1, r0 + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #8] + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #12] + ldr r1, [sp, #0] + add sp, sp, #4 + mul r0, r1, r0 + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #52] + ldr r1, [sp, #0] + add sp, sp, #4 + sdiv r0, r1, r0 + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #52] + ldr r1, [sp, #0] + add sp, sp, #4 + mul r0, r1, r0 + ldr r1, [sp, #0] + add sp, sp, #4 + sub r0, r1, r0 + str r0, [sp, #4] + b while_0 +end_while_0: + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + ldr r0, [sp, #0] + sub sp, sp, #4 + str r0, [sp, #0] + mov r0, #0 + ldr r1, [sp, #0] + add sp, sp, #4 + cmp r1, r0 + mov r0, #0 + it eq + moveq r0, #1 + cmp r0, #0 + beq else_2 + ldr r0, [sp, #12] + sub sp, sp, #4 + str r0, [sp, #0] + mov r0, #1 + ldr r1, [sp, #0] + add sp, sp, #4 + add r0, r1, r0 + str r0, [sp, #12] + mov r0, #1 + str r0, [sp] + b endif_2 +else_2: +endif_2: + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + mov r0, #1 + str r0, [sp, #8] + ldr r0, [sp, #44] + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #48] + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #64] + ldr r1, [sp, #0] + add sp, sp, #4 + sdiv r0, r1, r0 + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #64] + ldr r1, [sp, #0] + add sp, sp, #4 + mul r0, r1, r0 + ldr r1, [sp, #0] + add sp, sp, #4 + sub r0, r1, r0 + str r0, [sp, #4] + ldr r0, [sp, #28] + str r0, [sp] +while_3: + ldr r0, [sp, #0] + sub sp, sp, #4 + str r0, [sp, #0] + mov r0, #0 + ldr r1, [sp, #0] + add sp, sp, #4 + cmp r1, r0 + mov r0, #0 + it gt + movgt r0, #1 + cmp r0, #0 + beq end_while_3 + ldr r0, [sp, #0] + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #4] + sub sp, sp, #4 + str r0, [sp, #0] + mov r0, #2 + ldr r1, [sp, #0] + add sp, sp, #4 + sdiv r0, r1, r0 + sub sp, sp, #4 + str r0, [sp, #0] + mov r0, #2 + ldr r1, [sp, #0] + add sp, sp, #4 + mul r0, r1, r0 + ldr r1, [sp, #0] + add sp, sp, #4 + sub r0, r1, r0 + sub sp, sp, #4 + str r0, [sp, #0] + mov r0, #1 + ldr r1, [sp, #0] + add sp, sp, #4 + cmp r1, r0 + mov r0, #0 + it eq + moveq r0, #1 + cmp r0, #0 + beq else_4 + ldr r0, [sp, #8] + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #8] + ldr r1, [sp, #0] + add sp, sp, #4 + mul r0, r1, r0 + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #12] + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #12] + ldr r1, [sp, #0] + add sp, sp, #4 + mul r0, r1, r0 + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #64] + ldr r1, [sp, #0] + add sp, sp, #4 + sdiv r0, r1, r0 + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #64] + ldr r1, [sp, #0] + add sp, sp, #4 + mul r0, r1, r0 + ldr r1, [sp, #0] + add sp, sp, #4 + sub r0, r1, r0 + str r0, [sp, #8] + b endif_4 +else_4: +endif_4: + ldr r0, [sp, #0] + sub sp, sp, #4 + str r0, [sp, #0] + mov r0, #2 + ldr r1, [sp, #0] + add sp, sp, #4 + sdiv r0, r1, r0 + str r0, [sp] + ldr r0, [sp, #4] + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #8] + ldr r1, [sp, #0] + add sp, sp, #4 + mul r0, r1, r0 + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #8] + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #12] + ldr r1, [sp, #0] + add sp, sp, #4 + mul r0, r1, r0 + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #64] + ldr r1, [sp, #0] + add sp, sp, #4 + sdiv r0, r1, r0 + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #64] + ldr r1, [sp, #0] + add sp, sp, #4 + mul r0, r1, r0 + ldr r1, [sp, #0] + add sp, sp, #4 + sub r0, r1, r0 + str r0, [sp, #4] + b while_3 +end_while_3: + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + mov r0, #0 + str r0, [sp, #20] + mov r0, #1 + str r0, [sp, #16] + ldr r0, [sp, #88] + str r0, [sp, #12] + ldr r0, [sp, #84] + str r0, [sp, #8] +while_5: + ldr r0, [sp, #8] + sub sp, sp, #4 + str r0, [sp, #0] + mov r0, #0 + ldr r1, [sp, #0] + add sp, sp, #4 + cmp r1, r0 + mov r0, #0 + it ne + movne r0, #1 + cmp r0, #0 + beq end_while_5 + ldr r0, [sp, #12] + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #12] + ldr r1, [sp, #0] + add sp, sp, #4 + sdiv r0, r1, r0 + str r0, [sp, #4] + ldr r0, [sp, #20] + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #8] + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #24] + ldr r1, [sp, #0] + add sp, sp, #4 + mul r0, r1, r0 + ldr r1, [sp, #0] + add sp, sp, #4 + sub r0, r1, r0 + str r0, [sp] + ldr r0, [sp, #16] + str r0, [sp, #20] + ldr r0, [sp, #0] + str r0, [sp, #16] + ldr r0, [sp, #12] + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #8] + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #16] + ldr r1, [sp, #0] + add sp, sp, #4 + mul r0, r1, r0 + ldr r1, [sp, #0] + add sp, sp, #4 + sub r0, r1, r0 + str r0, [sp] + ldr r0, [sp, #8] + str r0, [sp, #12] + ldr r0, [sp, #0] + str r0, [sp, #8] + b while_5 +end_while_5: + ldr r0, [sp, #20] + sub sp, sp, #4 + str r0, [sp, #0] + mov r0, #0 + ldr r1, [sp, #0] + add sp, sp, #4 + cmp r1, r0 + mov r0, #0 + it lt + movlt r0, #1 + cmp r0, #0 + beq else_6 + ldr r0, [sp, #20] + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #92] + ldr r1, [sp, #0] + add sp, sp, #4 + add r0, r1, r0 + str r0, [sp, #24] + b endif_6 +else_6: + ldr r0, [sp, #20] + str r0, [sp, #24] +endif_6: + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + ldr r0, [sp, #60] + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #48] + ldr r1, [sp, #0] + add sp, sp, #4 + sub r0, r1, r0 + str r0, [sp] + ldr r0, [sp, #32] + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #4] + ldr r1, [sp, #0] + add sp, sp, #4 + mul r0, r1, r0 + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #36] + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #8] + ldr r1, [sp, #0] + add sp, sp, #4 + mul r0, r1, r0 + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #104] + ldr r1, [sp, #0] + add sp, sp, #4 + sdiv r0, r1, r0 + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #104] + ldr r1, [sp, #0] + add sp, sp, #4 + mul r0, r1, r0 + ldr r1, [sp, #0] + add sp, sp, #4 + sub r0, r1, r0 + str r0, [sp, #4] + ldr r0, [sp, #4] + sub sp, sp, #4 + str r0, [sp, #0] + mov r0, #0 + ldr r1, [sp, #0] + add sp, sp, #4 + cmp r1, r0 + mov r0, #0 + it lt + movlt r0, #1 + cmp r0, #0 + beq else_7 + ldr r0, [sp, #4] + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #100] + ldr r1, [sp, #0] + add sp, sp, #4 + add r0, r1, r0 + str r0, [sp, #4] + b endif_7 +else_7: +endif_7: + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + ldr r0, [sp, #48] + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #12] + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #104] + ldr r1, [sp, #0] + add sp, sp, #4 + mul r0, r1, r0 + ldr r1, [sp, #0] + add sp, sp, #4 + add r0, r1, r0 + str r0, [sp] + ldr r0, [sp, #0] + mov r4, r0 + ldr r1, =num_buf + add r1, r1, #16 + mov r2, #0 + cmp r4, #0 + bne print_int_loop_8 + mov r3, #48 + sub r1, r1, #1 + strb r3, [r1] + mov r2, #1 + b print_int_done_8 +print_int_loop_8: + mov r0, r4 + mov r3, #10 + sdiv r5, r0, r3 + mul r6, r5, r3 + sub r7, r0, r6 + add r7, r7, #48 + sub r1, r1, #1 + strb r7, [r1] + add r2, r2, #1 + mov r4, r5 + cmp r4, #0 + bne print_int_loop_8 +print_int_done_8: + mov r0, #1 + mov r1, r1 + mov r2, r2 + mov r7, #4 + svc #0 + mov r0, #1 + ldr r1, =newline + mov r2, #1 + mov r7, #4 + svc #0 + ldr r0, [sp, #0] + mov r7, #1 + svc #0 + +.size _start, .-_start + +.section .data +newline: + .ascii "\n" +num_buf: + .space 16 +_metadata: + .word 0x10000000 @ 0 + .word 0xa+1 + .word 0xb+3 + .word 0x0 @ [r0] + .word 0x00000001 @ p + .word 0x10000000 @ 1 + .word 0xa+4 + .word 0xb+6 + .word 0x0 @ [r0] + .word 0x00000001 @ q + .word 0x10000000 @ 2 + .word 0xa+7 + .word 0xb+9 + .word 0x0 @ [r0] + .word 0x00000001 @ n + .word 0x10000000 @ 3 + .word 0xa+10 + .word 0xb+12 + .word 0x0 @ [r0] + .word 0x00000001 @ e + .word 0x10000000 @ 4 + .word 0xa+13 + .word 0xb+15 + .word 0x0 @ [r0] + .word 0x00000001 @ m + .word 0x10000000 @ 5 + .word 0xa+16 + .word 0xb+18 + .word 0x0 @ [r0] + .word 0x00000001 @ p_minus_1 + .word 0x10000000 @ 6 + .word 0xa+19 + .word 0xb+21 + .word 0x0 @ [r0] + .word 0x00000001 @ q_minus_1 + .word 0x10000000 @ 7 + .word 0xa+22 + .word 0xb+24 + .word 0x0 @ [r0] + .word 0x00000001 @ ep + .word 0x10000000 @ 8 + .word 0xa+25 + .word 0xb+27 + .word 0x0 @ [r0] + .word 0x00000001 @ eq + .word 0x10000000 @ 9 + .word 0xa+28 + .word 0xb+35 + .word 0x0 @ [r0] + .word 0x00000001 @ p_minus_1 + .word 0x10000000 @ 10 + .word 0xa+36 + .word 0xb+43 + .word 0x0 @ [r0] + .word 0x00000001 @ q_minus_1 + .word 0x10000000 @ 11 + .word 0xa+44 + .word 0xb+63 + .word 0x0 @ [r0] + .word 0x00000001 @ ep + .word 0x10000000 @ 12 + .word 0xa+64 + .word 0xb+83 + .word 0x0 @ [r0] + .word 0x00000001 @ eq + .word 0x10000000 @ 13 + .word 0xa+84 + .word 0xb+86 + .word 0x0 @ [r0] + .word 0x00000001 @ c1 + .word 0x10000000 @ 14 + .word 0xa+87 + .word 0xb+89 + .word 0x0 @ [r0] + .word 0x00000001 @ base1 + .word 0x10000000 @ 15 + .word 0xa+90 + .word 0xb+92 + .word 0x0 @ [r0] + .word 0x00000001 @ exp1 + .word 0x10000000 @ 16 + .word 0xa+93 + .word 0xb+94 + .word 0x0 @ [r0] + .word 0x00000001 @ c1 + .word 0x10000000 @ 17 + .word 0xa+95 + .word 0xb+114 + .word 0x0 @ [r0] + .word 0x00000001 @ base1 + .word 0x10000000 @ 18 + .word 0xa+115 + .word 0xb+116 + .word 0x0 @ [r0] + .word 0x00000001 @ exp1 + .word 0x10000000 @ 19 + .word 0xa+160 + .word 0xb+191 + .word 0x0 @ [r0] + .word 0x00000001 @ c1 + .word 0x10000000 @ 20 + .word 0xa+195 + .word 0xb+202 + .word 0x0 @ [r0] + .word 0x00000001 @ exp1 + .word 0x10000000 @ 21 + .word 0xa+203 + .word 0xb+234 + .word 0x0 @ [r0] + .word 0x00000001 @ base1 + .word 0x10000000 @ 22 + .word 0xa+237 + .word 0xb+239 + .word 0x0 @ [r0] + .word 0x00000001 @ fault_triggered + .word 0x10000000 @ 23 + .word 0xa+252 + .word 0xb+259 + .word 0x0 @ [r0] + .word 0x00000001 @ c1 + .word 0x10000000 @ 24 + .word 0xa+260 + .word 0xb+261 + .word 0x0 @ [r0] + .word 0x00000001 @ fault_triggered + .word 0x10000000 @ 25 + .word 0xa+265 + .word 0xb+267 + .word 0x0 @ [r0] + .word 0x00000001 @ c2 + .word 0x10000000 @ 26 + .word 0xa+268 + .word 0xb+270 + .word 0x0 @ [r0] + .word 0x00000001 @ base2 + .word 0x10000000 @ 27 + .word 0xa+271 + .word 0xb+273 + .word 0x0 @ [r0] + .word 0x00000001 @ exp2 + .word 0x10000000 @ 28 + .word 0xa+274 + .word 0xb+275 + .word 0x0 @ [r0] + .word 0x00000001 @ c2 + .word 0x10000000 @ 29 + .word 0xa+276 + .word 0xb+295 + .word 0x0 @ [r0] + .word 0x00000001 @ base2 + .word 0x10000000 @ 30 + .word 0xa+296 + .word 0xb+297 + .word 0x0 @ [r0] + .word 0x00000001 @ exp2 + .word 0x10000000 @ 31 + .word 0xa+341 + .word 0xb+372 + .word 0x0 @ [r0] + .word 0x00000001 @ c2 + .word 0x10000000 @ 32 + .word 0xa+376 + .word 0xb+383 + .word 0x0 @ [r0] + .word 0x00000001 @ exp2 + .word 0x10000000 @ 33 + .word 0xa+384 + .word 0xb+415 + .word 0x0 @ [r0] + .word 0x00000001 @ base2 + .word 0x10000000 @ 34 + .word 0xa+418 + .word 0xb+420 + .word 0x0 @ [r0] + .word 0x00000001 @ qinv + .word 0x10000000 @ 35 + .word 0xa+421 + .word 0xb+423 + .word 0x0 @ [r0] + .word 0x00000001 @ t + .word 0x10000000 @ 36 + .word 0xa+424 + .word 0xb+426 + .word 0x0 @ [r0] + .word 0x00000001 @ newt + .word 0x10000000 @ 37 + .word 0xa+427 + .word 0xb+429 + .word 0x0 @ [r0] + .word 0x00000001 @ r + .word 0x10000000 @ 38 + .word 0xa+430 + .word 0xb+432 + .word 0x0 @ [r0] + .word 0x00000001 @ newr + .word 0x10000000 @ 39 + .word 0xa+433 + .word 0xb+435 + .word 0x0 @ [r0] + .word 0x00000001 @ quotient + .word 0x10000000 @ 40 + .word 0xa+436 + .word 0xb+438 + .word 0x0 @ [r0] + .word 0x00000001 @ tmp + .word 0x10000000 @ 41 + .word 0xa+439 + .word 0xb+440 + .word 0x0 @ [r0] + .word 0x00000001 @ t + .word 0x10000000 @ 42 + .word 0xa+441 + .word 0xb+442 + .word 0x0 @ [r0] + .word 0x00000001 @ newt + .word 0x10000000 @ 43 + .word 0xa+443 + .word 0xb+444 + .word 0x0 @ [r0] + .word 0x00000001 @ r + .word 0x10000000 @ 44 + .word 0xa+445 + .word 0xb+446 + .word 0x0 @ [r0] + .word 0x00000001 @ newr + .word 0x10000000 @ 45 + .word 0xa+460 + .word 0xb+467 + .word 0x0 @ [r0] + .word 0x00000001 @ quotient + .word 0x10000000 @ 46 + .word 0xa+468 + .word 0xb+481 + .word 0x0 @ [r0] + .word 0x00000001 @ tmp + .word 0x10000000 @ 47 + .word 0xa+482 + .word 0xb+483 + .word 0x0 @ [r0] + .word 0x00000001 @ t + .word 0x10000000 @ 48 + .word 0xa+484 + .word 0xb+485 + .word 0x0 @ [r0] + .word 0x00000001 @ newt + .word 0x10000000 @ 49 + .word 0xa+486 + .word 0xb+499 + .word 0x0 @ [r0] + .word 0x00000001 @ tmp + .word 0x10000000 @ 50 + .word 0xa+500 + .word 0xb+501 + .word 0x0 @ [r0] + .word 0x00000001 @ r + .word 0x10000000 @ 51 + .word 0xa+502 + .word 0xb+503 + .word 0x0 @ [r0] + .word 0x00000001 @ newr + .word 0x10000000 @ 52 + .word 0xa+518 + .word 0xb+525 + .word 0x0 @ [r0] + .word 0x00000001 @ qinv + .word 0x10000000 @ 53 + .word 0xa+528 + .word 0xb+529 + .word 0x0 @ [r0] + .word 0x00000001 @ qinv + .word 0x10000000 @ 54 + .word 0xa+531 + .word 0xb+533 + .word 0x0 @ [r0] + .word 0x00000001 @ h + .word 0x10000000 @ 55 + .word 0xa+534 + .word 0xb+536 + .word 0x0 @ [r0] + .word 0x00000001 @ diff + .word 0x10000000 @ 56 + .word 0xa+537 + .word 0xb+544 + .word 0x0 @ [r0] + .word 0x00000001 @ diff + .word 0x10000000 @ 57 + .word 0xa+545 + .word 0xb+576 + .word 0x0 @ [r0] + .word 0x00000001 @ h + .word 0x10000000 @ 58 + .word 0xa+589 + .word 0xb+596 + .word 0x0 @ [r0] + .word 0x00000001 @ h + .word 0x10000000 @ 59 + .word 0xa+600 + .word 0xb+602 + .word 0x0 @ [r0] + .word 0x00000001 @ c + .word 0x10000000 @ 60 + .word 0xa+603 + .word 0xb+616 + .word 0x0 @ [r0] + .word 0x00000001 @ c diff --git a/compiler/src/out.s.s b/compiler/src/out.s.s new file mode 100644 index 0000000..98b08c5 --- /dev/null +++ b/compiler/src/out.s.s @@ -0,0 +1,1610 @@ +.syntax unified +.thumb + +.section .text +.global _start +.type _start, %function + +_start: + mov r9, #0 + mov r10, #1 + sub sp, sp, #4 + mov r0, #61 + str r0, [sp] + sub sp, sp, #4 + mov r0, #61 + str r0, [sp] + add r9, r9, #1 + cmp r9, #1 + bne countermeasure + sub sp, sp, #4 + mov r0, #53 + str r0, [sp] + sub sp, sp, #4 + mov r0, #53 + str r0, [sp] + add r9, r9, #1 + cmp r9, #2 + bne countermeasure + sub sp, sp, #4 + mov r0, #3233 + str r0, [sp] + sub sp, sp, #4 + mov r0, #3233 + str r0, [sp] + add r9, r9, #1 + cmp r9, #3 + bne countermeasure + sub sp, sp, #4 + mov r0, #17 + str r0, [sp] + sub sp, sp, #4 + mov r0, #17 + str r0, [sp] + add r9, r9, #1 + cmp r9, #4 + bne countermeasure + sub sp, sp, #4 + mov r0, #65 + str r0, [sp] + sub sp, sp, #4 + mov r0, #65 + str r0, [sp] + add r9, r9, #1 + cmp r9, #5 + bne countermeasure + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + add r9, r9, #1 + cmp r9, #6 + bne countermeasure + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + add r9, r9, #1 + cmp r9, #7 + bne countermeasure + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + add r9, r9, #1 + cmp r9, #8 + bne countermeasure + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + add r9, r9, #1 + cmp r9, #9 + bne countermeasure + ldr r0, [sp, #68] + ldr r2, [sp, #64] + cmp r0, r2 + bne countermeasure + sub sp, sp, #4 + str r0, [sp, #0] + mov r0, #1 + ldr r1, [sp, #0] + add sp, sp, #4 + sub r0, r1, r0 + str r0, [sp, #28] + str r0, [sp, #24] + add r9, r9, #1 + cmp r9, #10 + bne countermeasure + ldr r0, [sp, #60] + ldr r2, [sp, #56] + cmp r0, r2 + bne countermeasure + sub sp, sp, #4 + str r0, [sp, #0] + mov r0, #1 + ldr r1, [sp, #0] + add sp, sp, #4 + sub r0, r1, r0 + str r0, [sp, #20] + str r0, [sp, #16] + add r9, r9, #1 + cmp r9, #11 + bne countermeasure + ldr r0, [sp, #44] + ldr r2, [sp, #40] + cmp r0, r2 + bne countermeasure + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #48] + ldr r2, [sp, #44] + cmp r0, r2 + bne countermeasure + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #36] + ldr r2, [sp, #32] + cmp r0, r2 + bne countermeasure + ldr r1, [sp, #0] + add sp, sp, #4 + sdiv r0, r1, r0 + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #36] + ldr r2, [sp, #32] + cmp r0, r2 + bne countermeasure + ldr r1, [sp, #0] + add sp, sp, #4 + mul r0, r1, r0 + ldr r1, [sp, #0] + add sp, sp, #4 + sub r0, r1, r0 + str r0, [sp, #12] + str r0, [sp, #8] + add r9, r9, #1 + cmp r9, #12 + bne countermeasure + ldr r0, [sp, #44] + ldr r2, [sp, #40] + cmp r0, r2 + bne countermeasure + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #48] + ldr r2, [sp, #44] + cmp r0, r2 + bne countermeasure + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #28] + ldr r2, [sp, #24] + cmp r0, r2 + bne countermeasure + ldr r1, [sp, #0] + add sp, sp, #4 + sdiv r0, r1, r0 + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #28] + ldr r2, [sp, #24] + cmp r0, r2 + bne countermeasure + ldr r1, [sp, #0] + add sp, sp, #4 + mul r0, r1, r0 + ldr r1, [sp, #0] + add sp, sp, #4 + sub r0, r1, r0 + str r0, [sp, #4] + str r0, [sp] + add r9, r9, #1 + cmp r9, #13 + bne countermeasure + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + add r9, r9, #1 + cmp r9, #14 + bne countermeasure + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + add r9, r9, #1 + cmp r9, #15 + bne countermeasure + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + add r9, r9, #1 + cmp r9, #16 + bne countermeasure + mov r0, #1 + str r0, [sp, #20] + str r0, [sp, #16] + add r9, r9, #1 + cmp r9, #17 + bne countermeasure + ldr r0, [sp, #60] + ldr r2, [sp, #56] + cmp r0, r2 + bne countermeasure + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #64] + ldr r2, [sp, #60] + cmp r0, r2 + bne countermeasure + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #100] + ldr r2, [sp, #96] + cmp r0, r2 + bne countermeasure + ldr r1, [sp, #0] + add sp, sp, #4 + sdiv r0, r1, r0 + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #100] + ldr r2, [sp, #96] + cmp r0, r2 + bne countermeasure + ldr r1, [sp, #0] + add sp, sp, #4 + mul r0, r1, r0 + ldr r1, [sp, #0] + add sp, sp, #4 + sub r0, r1, r0 + str r0, [sp, #12] + str r0, [sp, #8] + add r9, r9, #1 + cmp r9, #18 + bne countermeasure + ldr r0, [sp, #36] + ldr r2, [sp, #32] + cmp r0, r2 + bne countermeasure + str r0, [sp, #4] + str r0, [sp] + add r9, r9, #1 + cmp r9, #19 + bne countermeasure + mov r10, #20 +while_0: + add r9, r9, #1 + cmp r9, r10 + bne countermeasure + add r10, r10, #1 + ldr r0, [sp, #4] + ldr r2, [sp, #0] + cmp r0, r2 + bne countermeasure + sub sp, sp, #4 + str r0, [sp, #0] + mov r0, #0 + ldr r1, [sp, #0] + add sp, sp, #4 + cmp r1, r0 + mov r0, #0 + it gt + movgt r0, #1 + cmp r0, #0 + beq end_while_0 + ldr r0, [sp, #4] + ldr r2, [sp, #0] + cmp r0, r2 + bne countermeasure + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #8] + ldr r2, [sp, #4] + cmp r0, r2 + bne countermeasure + sub sp, sp, #4 + str r0, [sp, #0] + mov r0, #2 + ldr r1, [sp, #0] + add sp, sp, #4 + sdiv r0, r1, r0 + sub sp, sp, #4 + str r0, [sp, #0] + mov r0, #2 + ldr r1, [sp, #0] + add sp, sp, #4 + mul r0, r1, r0 + ldr r1, [sp, #0] + add sp, sp, #4 + sub r0, r1, r0 + sub sp, sp, #4 + str r0, [sp, #0] + mov r0, #1 + ldr r1, [sp, #0] + add sp, sp, #4 + cmp r1, r0 + mov r0, #0 + it eq + moveq r0, #1 + cmp r0, #0 + beq else_1 + add r9, r9, #1 + cmp r9, r10 + bne countermeasure + add r10, r10, #1 + ldr r0, [sp, #20] + ldr r2, [sp, #16] + cmp r0, r2 + bne countermeasure + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #16] + ldr r2, [sp, #12] + cmp r0, r2 + bne countermeasure + ldr r1, [sp, #0] + add sp, sp, #4 + mul r0, r1, r0 + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #24] + ldr r2, [sp, #20] + cmp r0, r2 + bne countermeasure + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #20] + ldr r2, [sp, #16] + cmp r0, r2 + bne countermeasure + ldr r1, [sp, #0] + add sp, sp, #4 + mul r0, r1, r0 + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #100] + ldr r2, [sp, #96] + cmp r0, r2 + bne countermeasure + ldr r1, [sp, #0] + add sp, sp, #4 + sdiv r0, r1, r0 + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #100] + ldr r2, [sp, #96] + cmp r0, r2 + bne countermeasure + ldr r1, [sp, #0] + add sp, sp, #4 + mul r0, r1, r0 + ldr r1, [sp, #0] + add sp, sp, #4 + sub r0, r1, r0 + str r0, [sp, #20] + str r0, [sp, #16] + add r9, r9, #1 + cmp r9, r10 + bne countermeasure + add r10, r10, #1 + b endif_1 +else_1: +endif_1: + ldr r0, [sp, #4] + ldr r2, [sp, #0] + cmp r0, r2 + bne countermeasure + sub sp, sp, #4 + str r0, [sp, #0] + mov r0, #2 + ldr r1, [sp, #0] + add sp, sp, #4 + sdiv r0, r1, r0 + str r0, [sp, #4] + str r0, [sp] + add r9, r9, #1 + cmp r9, r10 + bne countermeasure + add r10, r10, #1 + ldr r0, [sp, #12] + ldr r2, [sp, #8] + cmp r0, r2 + bne countermeasure + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #16] + ldr r2, [sp, #12] + cmp r0, r2 + bne countermeasure + ldr r1, [sp, #0] + add sp, sp, #4 + mul r0, r1, r0 + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #16] + ldr r2, [sp, #12] + cmp r0, r2 + bne countermeasure + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #20] + ldr r2, [sp, #16] + cmp r0, r2 + bne countermeasure + ldr r1, [sp, #0] + add sp, sp, #4 + mul r0, r1, r0 + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #100] + ldr r2, [sp, #96] + cmp r0, r2 + bne countermeasure + ldr r1, [sp, #0] + add sp, sp, #4 + sdiv r0, r1, r0 + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #100] + ldr r2, [sp, #96] + cmp r0, r2 + bne countermeasure + ldr r1, [sp, #0] + add sp, sp, #4 + mul r0, r1, r0 + ldr r1, [sp, #0] + add sp, sp, #4 + sub r0, r1, r0 + str r0, [sp, #12] + str r0, [sp, #8] + add r9, r9, #1 + cmp r9, r10 + bne countermeasure + add r10, r10, #1 + add r9, r9, #1 + cmp r9, r10 + bne countermeasure + add r10, r10, #1 + b while_0 +end_while_0: + mov r9, #19 + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + add r9, r9, #1 + cmp r9, #20 + bne countermeasure + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + add r9, r9, #1 + cmp r9, #21 + bne countermeasure + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + add r9, r9, #1 + cmp r9, #22 + bne countermeasure + mov r0, #1 + str r0, [sp, #20] + str r0, [sp, #16] + add r9, r9, #1 + cmp r9, #23 + bne countermeasure + ldr r0, [sp, #84] + ldr r2, [sp, #80] + cmp r0, r2 + bne countermeasure + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #88] + ldr r2, [sp, #84] + cmp r0, r2 + bne countermeasure + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #116] + ldr r2, [sp, #112] + cmp r0, r2 + bne countermeasure + ldr r1, [sp, #0] + add sp, sp, #4 + sdiv r0, r1, r0 + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #116] + ldr r2, [sp, #112] + cmp r0, r2 + bne countermeasure + ldr r1, [sp, #0] + add sp, sp, #4 + mul r0, r1, r0 + ldr r1, [sp, #0] + add sp, sp, #4 + sub r0, r1, r0 + str r0, [sp, #12] + str r0, [sp, #8] + add r9, r9, #1 + cmp r9, #24 + bne countermeasure + ldr r0, [sp, #52] + ldr r2, [sp, #48] + cmp r0, r2 + bne countermeasure + str r0, [sp, #4] + str r0, [sp] + add r9, r9, #1 + cmp r9, #25 + bne countermeasure + mov r10, #26 +while_2: + add r9, r9, #1 + cmp r9, r10 + bne countermeasure + add r10, r10, #1 + ldr r0, [sp, #4] + ldr r2, [sp, #0] + cmp r0, r2 + bne countermeasure + sub sp, sp, #4 + str r0, [sp, #0] + mov r0, #0 + ldr r1, [sp, #0] + add sp, sp, #4 + cmp r1, r0 + mov r0, #0 + it gt + movgt r0, #1 + cmp r0, #0 + beq end_while_2 + ldr r0, [sp, #4] + ldr r2, [sp, #0] + cmp r0, r2 + bne countermeasure + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #8] + ldr r2, [sp, #4] + cmp r0, r2 + bne countermeasure + sub sp, sp, #4 + str r0, [sp, #0] + mov r0, #2 + ldr r1, [sp, #0] + add sp, sp, #4 + sdiv r0, r1, r0 + sub sp, sp, #4 + str r0, [sp, #0] + mov r0, #2 + ldr r1, [sp, #0] + add sp, sp, #4 + mul r0, r1, r0 + ldr r1, [sp, #0] + add sp, sp, #4 + sub r0, r1, r0 + sub sp, sp, #4 + str r0, [sp, #0] + mov r0, #1 + ldr r1, [sp, #0] + add sp, sp, #4 + cmp r1, r0 + mov r0, #0 + it eq + moveq r0, #1 + cmp r0, #0 + beq else_3 + add r9, r9, #1 + cmp r9, r10 + bne countermeasure + add r10, r10, #1 + ldr r0, [sp, #20] + ldr r2, [sp, #16] + cmp r0, r2 + bne countermeasure + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #16] + ldr r2, [sp, #12] + cmp r0, r2 + bne countermeasure + ldr r1, [sp, #0] + add sp, sp, #4 + mul r0, r1, r0 + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #24] + ldr r2, [sp, #20] + cmp r0, r2 + bne countermeasure + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #20] + ldr r2, [sp, #16] + cmp r0, r2 + bne countermeasure + ldr r1, [sp, #0] + add sp, sp, #4 + mul r0, r1, r0 + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #116] + ldr r2, [sp, #112] + cmp r0, r2 + bne countermeasure + ldr r1, [sp, #0] + add sp, sp, #4 + sdiv r0, r1, r0 + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #116] + ldr r2, [sp, #112] + cmp r0, r2 + bne countermeasure + ldr r1, [sp, #0] + add sp, sp, #4 + mul r0, r1, r0 + ldr r1, [sp, #0] + add sp, sp, #4 + sub r0, r1, r0 + str r0, [sp, #20] + str r0, [sp, #16] + add r9, r9, #1 + cmp r9, r10 + bne countermeasure + add r10, r10, #1 + b endif_3 +else_3: +endif_3: + ldr r0, [sp, #4] + ldr r2, [sp, #0] + cmp r0, r2 + bne countermeasure + sub sp, sp, #4 + str r0, [sp, #0] + mov r0, #2 + ldr r1, [sp, #0] + add sp, sp, #4 + sdiv r0, r1, r0 + str r0, [sp, #4] + str r0, [sp] + add r9, r9, #1 + cmp r9, r10 + bne countermeasure + add r10, r10, #1 + ldr r0, [sp, #12] + ldr r2, [sp, #8] + cmp r0, r2 + bne countermeasure + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #16] + ldr r2, [sp, #12] + cmp r0, r2 + bne countermeasure + ldr r1, [sp, #0] + add sp, sp, #4 + mul r0, r1, r0 + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #16] + ldr r2, [sp, #12] + cmp r0, r2 + bne countermeasure + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #20] + ldr r2, [sp, #16] + cmp r0, r2 + bne countermeasure + ldr r1, [sp, #0] + add sp, sp, #4 + mul r0, r1, r0 + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #116] + ldr r2, [sp, #112] + cmp r0, r2 + bne countermeasure + ldr r1, [sp, #0] + add sp, sp, #4 + sdiv r0, r1, r0 + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #116] + ldr r2, [sp, #112] + cmp r0, r2 + bne countermeasure + ldr r1, [sp, #0] + add sp, sp, #4 + mul r0, r1, r0 + ldr r1, [sp, #0] + add sp, sp, #4 + sub r0, r1, r0 + str r0, [sp, #12] + str r0, [sp, #8] + add r9, r9, #1 + cmp r9, r10 + bne countermeasure + add r10, r10, #1 + add r9, r9, #1 + cmp r9, r10 + bne countermeasure + add r10, r10, #1 + b while_2 +end_while_2: + mov r9, #25 + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + add r9, r9, #1 + cmp r9, #26 + bne countermeasure + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + add r9, r9, #1 + cmp r9, #27 + bne countermeasure + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + add r9, r9, #1 + cmp r9, #28 + bne countermeasure + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + add r9, r9, #1 + cmp r9, #29 + bne countermeasure + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + add r9, r9, #1 + cmp r9, #30 + bne countermeasure + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + add r9, r9, #1 + cmp r9, #31 + bne countermeasure + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + add r9, r9, #1 + cmp r9, #32 + bne countermeasure + mov r0, #0 + str r0, [sp, #44] + str r0, [sp, #40] + add r9, r9, #1 + cmp r9, #33 + bne countermeasure + mov r0, #1 + str r0, [sp, #36] + str r0, [sp, #32] + add r9, r9, #1 + cmp r9, #34 + bne countermeasure + ldr r0, [sp, #172] + ldr r2, [sp, #168] + cmp r0, r2 + bne countermeasure + str r0, [sp, #28] + str r0, [sp, #24] + add r9, r9, #1 + cmp r9, #35 + bne countermeasure + ldr r0, [sp, #164] + ldr r2, [sp, #160] + cmp r0, r2 + bne countermeasure + str r0, [sp, #20] + str r0, [sp, #16] + add r9, r9, #1 + cmp r9, #36 + bne countermeasure + mov r10, #37 +while_4: + add r9, r9, #1 + cmp r9, r10 + bne countermeasure + add r10, r10, #1 + ldr r0, [sp, #20] + ldr r2, [sp, #16] + cmp r0, r2 + bne countermeasure + sub sp, sp, #4 + str r0, [sp, #0] + mov r0, #0 + ldr r1, [sp, #0] + add sp, sp, #4 + cmp r1, r0 + mov r0, #0 + it ne + movne r0, #1 + cmp r0, #0 + beq end_while_4 + ldr r0, [sp, #28] + ldr r2, [sp, #24] + cmp r0, r2 + bne countermeasure + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #24] + ldr r2, [sp, #20] + cmp r0, r2 + bne countermeasure + ldr r1, [sp, #0] + add sp, sp, #4 + sdiv r0, r1, r0 + str r0, [sp, #12] + str r0, [sp, #8] + add r9, r9, #1 + cmp r9, r10 + bne countermeasure + add r10, r10, #1 + ldr r0, [sp, #44] + ldr r2, [sp, #40] + cmp r0, r2 + bne countermeasure + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #16] + ldr r2, [sp, #12] + cmp r0, r2 + bne countermeasure + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #44] + ldr r2, [sp, #40] + cmp r0, r2 + bne countermeasure + ldr r1, [sp, #0] + add sp, sp, #4 + mul r0, r1, r0 + ldr r1, [sp, #0] + add sp, sp, #4 + sub r0, r1, r0 + str r0, [sp, #4] + str r0, [sp] + add r9, r9, #1 + cmp r9, r10 + bne countermeasure + add r10, r10, #1 + ldr r0, [sp, #36] + ldr r2, [sp, #32] + cmp r0, r2 + bne countermeasure + str r0, [sp, #44] + str r0, [sp, #40] + add r9, r9, #1 + cmp r9, r10 + bne countermeasure + add r10, r10, #1 + ldr r0, [sp, #4] + ldr r2, [sp, #0] + cmp r0, r2 + bne countermeasure + str r0, [sp, #36] + str r0, [sp, #32] + add r9, r9, #1 + cmp r9, r10 + bne countermeasure + add r10, r10, #1 + ldr r0, [sp, #28] + ldr r2, [sp, #24] + cmp r0, r2 + bne countermeasure + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #16] + ldr r2, [sp, #12] + cmp r0, r2 + bne countermeasure + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #28] + ldr r2, [sp, #24] + cmp r0, r2 + bne countermeasure + ldr r1, [sp, #0] + add sp, sp, #4 + mul r0, r1, r0 + ldr r1, [sp, #0] + add sp, sp, #4 + sub r0, r1, r0 + str r0, [sp, #4] + str r0, [sp] + add r9, r9, #1 + cmp r9, r10 + bne countermeasure + add r10, r10, #1 + ldr r0, [sp, #20] + ldr r2, [sp, #16] + cmp r0, r2 + bne countermeasure + str r0, [sp, #28] + str r0, [sp, #24] + add r9, r9, #1 + cmp r9, r10 + bne countermeasure + add r10, r10, #1 + ldr r0, [sp, #4] + ldr r2, [sp, #0] + cmp r0, r2 + bne countermeasure + str r0, [sp, #20] + str r0, [sp, #16] + add r9, r9, #1 + cmp r9, r10 + bne countermeasure + add r10, r10, #1 + add r9, r9, #1 + cmp r9, r10 + bne countermeasure + add r10, r10, #1 + b while_4 +end_while_4: + mov r9, #36 + ldr r0, [sp, #44] + ldr r2, [sp, #40] + cmp r0, r2 + bne countermeasure + sub sp, sp, #4 + str r0, [sp, #0] + mov r0, #0 + ldr r1, [sp, #0] + add sp, sp, #4 + cmp r1, r0 + mov r0, #0 + it lt + movlt r0, #1 + cmp r0, #0 + beq else_5 + add r9, r9, #1 + cmp r9, #37 + bne countermeasure + ldr r0, [sp, #44] + ldr r2, [sp, #40] + cmp r0, r2 + bne countermeasure + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #176] + ldr r2, [sp, #172] + cmp r0, r2 + bne countermeasure + ldr r1, [sp, #0] + add sp, sp, #4 + add r0, r1, r0 + str r0, [sp, #52] + str r0, [sp, #48] + add r9, r9, #1 + cmp r9, #38 + bne countermeasure + b endif_5 +else_5: + ldr r0, [sp, #44] + ldr r2, [sp, #40] + cmp r0, r2 + bne countermeasure + str r0, [sp, #52] + str r0, [sp, #48] + add r9, r9, #1 + cmp r9, #37 + bne countermeasure + mov r9, #38 +endif_5: + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + add r9, r9, #1 + cmp r9, #39 + bne countermeasure + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + add r9, r9, #1 + cmp r9, #40 + bne countermeasure + ldr r0, [sp, #116] + ldr r2, [sp, #112] + cmp r0, r2 + bne countermeasure + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #96] + ldr r2, [sp, #92] + cmp r0, r2 + bne countermeasure + ldr r1, [sp, #0] + add sp, sp, #4 + sub r0, r1, r0 + str r0, [sp, #4] + str r0, [sp] + add r9, r9, #1 + cmp r9, #41 + bne countermeasure + ldr r0, [sp, #68] + ldr r2, [sp, #64] + cmp r0, r2 + bne countermeasure + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #8] + ldr r2, [sp, #4] + cmp r0, r2 + bne countermeasure + ldr r1, [sp, #0] + add sp, sp, #4 + mul r0, r1, r0 + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #72] + ldr r2, [sp, #68] + cmp r0, r2 + bne countermeasure + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #12] + ldr r2, [sp, #8] + cmp r0, r2 + bne countermeasure + ldr r1, [sp, #0] + add sp, sp, #4 + mul r0, r1, r0 + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #196] + ldr r2, [sp, #192] + cmp r0, r2 + bne countermeasure + ldr r1, [sp, #0] + add sp, sp, #4 + sdiv r0, r1, r0 + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #196] + ldr r2, [sp, #192] + cmp r0, r2 + bne countermeasure + ldr r1, [sp, #0] + add sp, sp, #4 + mul r0, r1, r0 + ldr r1, [sp, #0] + add sp, sp, #4 + sub r0, r1, r0 + str r0, [sp, #12] + str r0, [sp, #8] + add r9, r9, #1 + cmp r9, #42 + bne countermeasure + ldr r0, [sp, #12] + ldr r2, [sp, #8] + cmp r0, r2 + bne countermeasure + sub sp, sp, #4 + str r0, [sp, #0] + mov r0, #0 + ldr r1, [sp, #0] + add sp, sp, #4 + cmp r1, r0 + mov r0, #0 + it lt + movlt r0, #1 + cmp r0, #0 + beq else_6 + add r9, r9, #1 + cmp r9, #43 + bne countermeasure + ldr r0, [sp, #12] + ldr r2, [sp, #8] + cmp r0, r2 + bne countermeasure + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #192] + ldr r2, [sp, #188] + cmp r0, r2 + bne countermeasure + ldr r1, [sp, #0] + add sp, sp, #4 + add r0, r1, r0 + str r0, [sp, #12] + str r0, [sp, #8] + add r9, r9, #1 + cmp r9, #44 + bne countermeasure + b endif_6 +else_6: +endif_6: + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + add r9, r9, #1 + cmp r9, #45 + bne countermeasure + ldr r0, [sp, #100] + ldr r2, [sp, #96] + cmp r0, r2 + bne countermeasure + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #24] + ldr r2, [sp, #20] + cmp r0, r2 + bne countermeasure + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #196] + ldr r2, [sp, #192] + cmp r0, r2 + bne countermeasure + ldr r1, [sp, #0] + add sp, sp, #4 + mul r0, r1, r0 + ldr r1, [sp, #0] + add sp, sp, #4 + add r0, r1, r0 + str r0, [sp, #4] + str r0, [sp] + add r9, r9, #1 + cmp r9, #46 + bne countermeasure + ldr r0, [sp, #4] + ldr r2, [sp, #0] + cmp r0, r2 + bne countermeasure + mov r4, r0 + ldr r1, =num_buf + add r1, r1, #16 + mov r2, #0 + cmp r4, #0 + bne print_int_loop_7 + mov r3, #48 + sub r1, r1, #1 + strb r3, [r1] + mov r2, #1 + b print_int_done_7 +print_int_loop_7: + mov r0, r4 + mov r3, #10 + sdiv r5, r0, r3 + mul r6, r5, r3 + sub r7, r0, r6 + add r7, r7, #48 + sub r1, r1, #1 + strb r7, [r1] + add r2, r2, #1 + mov r4, r5 + cmp r4, #0 + bne print_int_loop_7 +print_int_done_7: + mov r0, #1 + mov r1, r1 + mov r2, r2 + mov r7, #4 + svc #0 + mov r0, #1 + ldr r1, =newline + mov r2, #1 + mov r7, #4 + svc #0 + ldr r0, [sp, #4] + ldr r2, [sp, #0] + cmp r0, r2 + bne countermeasure + mov r7, #1 + svc #0 +countermeasure: + mov r0, #1 + ldr r1, =.Lstr0 + mov r2, #14 + mov r7, #4 + svc #0 + mov r0, #77 + mov r7, #1 + svc #0 + +.size _start, .-_start + +.section .data +.Lstr0: + .ascii "COUNTERMEASURE" +newline: + .ascii "\n" +num_buf: + .space 16 +step_counter: + .word 0 +fault_msg: + .ascii "Control flow violation detected\n" +_metadata: + .word 0x10000000 @ 0 + .word 0xa+3 + .word 0xb+11 + .word 0x0 @ [r0] + .word 0x00000001 @ p + .word 0x00000002 @ p_dup + .word 0x10000000 @ 1 + .word 0xa+12 + .word 0xb+20 + .word 0x0 @ [r0] + .word 0x00000001 @ q + .word 0x00000002 @ q_dup + .word 0x10000000 @ 2 + .word 0xa+21 + .word 0xb+29 + .word 0x0 @ [r0] + .word 0x00000001 @ n + .word 0x00000002 @ n_dup + .word 0x10000000 @ 3 + .word 0xa+30 + .word 0xb+38 + .word 0x0 @ [r0] + .word 0x00000001 @ e + .word 0x00000002 @ e_dup + .word 0x10000000 @ 4 + .word 0xa+39 + .word 0xb+47 + .word 0x0 @ [r0] + .word 0x00000001 @ m + .word 0x00000002 @ m_dup + .word 0x10000000 @ 5 + .word 0xa+48 + .word 0xb+56 + .word 0x0 @ [r0] + .word 0x00000001 @ p_minus_1 + .word 0x00000002 @ p_minus_1_dup + .word 0x10000000 @ 6 + .word 0xa+57 + .word 0xb+65 + .word 0x0 @ [r0] + .word 0x00000001 @ q_minus_1 + .word 0x00000002 @ q_minus_1_dup + .word 0x10000000 @ 7 + .word 0xa+66 + .word 0xb+74 + .word 0x0 @ [r0] + .word 0x00000001 @ ep + .word 0x00000002 @ ep_dup + .word 0x10000000 @ 8 + .word 0xa+75 + .word 0xb+83 + .word 0x0 @ [r0] + .word 0x00000001 @ eq + .word 0x00000002 @ eq_dup + .word 0x10000000 @ 9 + .word 0xa+84 + .word 0xb+98 + .word 0x0 @ [r0] + .word 0x00000001 @ p_minus_1 + .word 0x00000001 @ p_minus_1_dup + .word 0x10000000 @ 10 + .word 0xa+99 + .word 0xb+113 + .word 0x0 @ [r0] + .word 0x00000001 @ q_minus_1 + .word 0x00000001 @ q_minus_1_dup + .word 0x10000000 @ 11 + .word 0xa+114 + .word 0xb+149 + .word 0x0 @ [r0] + .word 0x00000001 @ ep + .word 0x00000001 @ ep_dup + .word 0x10000000 @ 12 + .word 0xa+150 + .word 0xb+185 + .word 0x0 @ [r0] + .word 0x00000001 @ eq + .word 0x00000001 @ eq_dup + .word 0x10000000 @ 13 + .word 0xa+186 + .word 0xb+194 + .word 0x0 @ [r0] + .word 0x00000001 @ c1 + .word 0x00000002 @ c1_dup + .word 0x10000000 @ 14 + .word 0xa+195 + .word 0xb+203 + .word 0x0 @ [r0] + .word 0x00000001 @ base1 + .word 0x00000002 @ base1_dup + .word 0x10000000 @ 15 + .word 0xa+204 + .word 0xb+212 + .word 0x0 @ [r0] + .word 0x00000001 @ exp1 + .word 0x00000002 @ exp1_dup + .word 0x10000000 @ 16 + .word 0xa+213 + .word 0xb+218 + .word 0x0 @ [r0] + .word 0x00000001 @ c1 + .word 0x00000001 @ c1_dup + .word 0x10000000 @ 17 + .word 0xa+219 + .word 0xb+254 + .word 0x0 @ [r0] + .word 0x00000001 @ base1 + .word 0x00000001 @ base1_dup + .word 0x10000000 @ 18 + .word 0xa+255 + .word 0xb+263 + .word 0x0 @ [r0] + .word 0x00000001 @ exp1 + .word 0x00000001 @ exp1_dup + .word 0x10000000 @ 19 + .word 0xa+325 + .word 0xb+379 + .word 0x0 @ [r0] + .word 0x00000001 @ c1 + .word 0x00000001 @ c1_dup + .word 0x10000000 @ 20 + .word 0xa+383 + .word 0xb+398 + .word 0x0 @ [r0] + .word 0x00000001 @ exp1 + .word 0x00000001 @ exp1_dup + .word 0x10000000 @ 21 + .word 0xa+399 + .word 0xb+453 + .word 0x0 @ [r0] + .word 0x00000001 @ base1 + .word 0x00000001 @ base1_dup + .word 0x10000000 @ 22 + .word 0xa+461 + .word 0xb+469 + .word 0x0 @ [r0] + .word 0x00000001 @ c2 + .word 0x00000002 @ c2_dup + .word 0x10000000 @ 23 + .word 0xa+470 + .word 0xb+478 + .word 0x0 @ [r0] + .word 0x00000001 @ base2 + .word 0x00000002 @ base2_dup + .word 0x10000000 @ 24 + .word 0xa+479 + .word 0xb+487 + .word 0x0 @ [r0] + .word 0x00000001 @ exp2 + .word 0x00000002 @ exp2_dup + .word 0x10000000 @ 25 + .word 0xa+488 + .word 0xb+493 + .word 0x0 @ [r0] + .word 0x00000001 @ c2 + .word 0x00000001 @ c2_dup + .word 0x10000000 @ 26 + .word 0xa+494 + .word 0xb+529 + .word 0x0 @ [r0] + .word 0x00000001 @ base2 + .word 0x00000001 @ base2_dup + .word 0x10000000 @ 27 + .word 0xa+530 + .word 0xb+538 + .word 0x0 @ [r0] + .word 0x00000001 @ exp2 + .word 0x00000001 @ exp2_dup + .word 0x10000000 @ 28 + .word 0xa+600 + .word 0xb+654 + .word 0x0 @ [r0] + .word 0x00000001 @ c2 + .word 0x00000001 @ c2_dup + .word 0x10000000 @ 29 + .word 0xa+658 + .word 0xb+673 + .word 0x0 @ [r0] + .word 0x00000001 @ exp2 + .word 0x00000001 @ exp2_dup + .word 0x10000000 @ 30 + .word 0xa+674 + .word 0xb+728 + .word 0x0 @ [r0] + .word 0x00000001 @ base2 + .word 0x00000001 @ base2_dup + .word 0x10000000 @ 31 + .word 0xa+736 + .word 0xb+744 + .word 0x0 @ [r0] + .word 0x00000001 @ qinv + .word 0x00000002 @ qinv_dup + .word 0x10000000 @ 32 + .word 0xa+745 + .word 0xb+753 + .word 0x0 @ [r0] + .word 0x00000001 @ t + .word 0x00000002 @ t_dup + .word 0x10000000 @ 33 + .word 0xa+754 + .word 0xb+762 + .word 0x0 @ [r0] + .word 0x00000001 @ newt + .word 0x00000002 @ newt_dup + .word 0x10000000 @ 34 + .word 0xa+763 + .word 0xb+771 + .word 0x0 @ [r0] + .word 0x00000001 @ r + .word 0x00000002 @ r_dup + .word 0x10000000 @ 35 + .word 0xa+772 + .word 0xb+780 + .word 0x0 @ [r0] + .word 0x00000001 @ newr + .word 0x00000002 @ newr_dup + .word 0x10000000 @ 36 + .word 0xa+781 + .word 0xb+789 + .word 0x0 @ [r0] + .word 0x00000001 @ quotient + .word 0x00000002 @ quotient_dup + .word 0x10000000 @ 37 + .word 0xa+790 + .word 0xb+798 + .word 0x0 @ [r0] + .word 0x00000001 @ tmp + .word 0x00000002 @ tmp_dup + .word 0x10000000 @ 38 + .word 0xa+799 + .word 0xb+804 + .word 0x0 @ [r0] + .word 0x00000001 @ t + .word 0x00000001 @ t_dup + .word 0x10000000 @ 39 + .word 0xa+805 + .word 0xb+810 + .word 0x0 @ [r0] + .word 0x00000001 @ newt + .word 0x00000001 @ newt_dup + .word 0x10000000 @ 40 + .word 0xa+811 + .word 0xb+819 + .word 0x0 @ [r0] + .word 0x00000001 @ r + .word 0x00000001 @ r_dup + .word 0x10000000 @ 41 + .word 0xa+820 + .word 0xb+828 + .word 0x0 @ [r0] + .word 0x00000001 @ newr + .word 0x00000001 @ newr_dup + .word 0x10000000 @ 42 + .word 0xa+850 + .word 0xb+868 + .word 0x0 @ [r0] + .word 0x00000001 @ quotient + .word 0x00000001 @ quotient_dup + .word 0x10000000 @ 43 + .word 0xa+869 + .word 0xb+896 + .word 0x0 @ [r0] + .word 0x00000001 @ tmp + .word 0x00000001 @ tmp_dup + .word 0x10000000 @ 44 + .word 0xa+897 + .word 0xb+906 + .word 0x0 @ [r0] + .word 0x00000001 @ t + .word 0x00000001 @ t_dup + .word 0x10000000 @ 45 + .word 0xa+907 + .word 0xb+916 + .word 0x0 @ [r0] + .word 0x00000001 @ newt + .word 0x00000001 @ newt_dup + .word 0x10000000 @ 46 + .word 0xa+917 + .word 0xb+944 + .word 0x0 @ [r0] + .word 0x00000001 @ tmp + .word 0x00000001 @ tmp_dup + .word 0x10000000 @ 47 + .word 0xa+945 + .word 0xb+954 + .word 0x0 @ [r0] + .word 0x00000001 @ r + .word 0x00000001 @ r_dup + .word 0x10000000 @ 48 + .word 0xa+955 + .word 0xb+964 + .word 0x0 @ [r0] + .word 0x00000001 @ newr + .word 0x00000001 @ newr_dup + .word 0x10000000 @ 49 + .word 0xa+990 + .word 0xb+1007 + .word 0x0 @ [r0] + .word 0x00000001 @ qinv + .word 0x00000001 @ qinv_dup + .word 0x10000000 @ 50 + .word 0xa+1010 + .word 0xb+1018 + .word 0x0 @ [r0] + .word 0x00000001 @ qinv + .word 0x00000001 @ qinv_dup + .word 0x10000000 @ 51 + .word 0xa+1021 + .word 0xb+1029 + .word 0x0 @ [r0] + .word 0x00000001 @ h + .word 0x00000002 @ h_dup + .word 0x10000000 @ 52 + .word 0xa+1030 + .word 0xb+1038 + .word 0x0 @ [r0] + .word 0x00000001 @ diff + .word 0x00000002 @ diff_dup + .word 0x10000000 @ 53 + .word 0xa+1039 + .word 0xb+1056 + .word 0x0 @ [r0] + .word 0x00000001 @ diff + .word 0x00000001 @ diff_dup + .word 0x10000000 @ 54 + .word 0xa+1057 + .word 0xb+1110 + .word 0x0 @ [r0] + .word 0x00000001 @ h + .word 0x00000001 @ h_dup + .word 0x10000000 @ 55 + .word 0xa+1129 + .word 0xb+1146 + .word 0x0 @ [r0] + .word 0x00000001 @ h + .word 0x00000001 @ h_dup + .word 0x10000000 @ 56 + .word 0xa+1150 + .word 0xb+1158 + .word 0x0 @ [r0] + .word 0x00000001 @ c + .word 0x00000002 @ c_dup + .word 0x10000000 @ 57 + .word 0xa+1159 + .word 0xb+1185 + .word 0x0 @ [r0] + .word 0x00000001 @ c + .word 0x00000001 @ c_dup diff --git a/compiler/src/out.s.wh b/compiler/src/out.s.wh new file mode 100644 index 0000000..c498af2 --- /dev/null +++ b/compiler/src/out.s.wh @@ -0,0 +1,808 @@ +ui32 res; +ui32 stmt; +ui32 bit_shift; +ui32 flip_mask; + +fn main(ui32 stmt, ui32 flip_mask) -> ui32 { + ui32 p; + ui32 p_dup; + ui32 q; + ui32 q_dup; + ui32 n; + ui32 n_dup; + ui32 e; + ui32 e_dup; + ui32 m; + ui32 m_dup; + ui32 p_minus_1; + ui32 p_minus_1_dup; + ui32 q_minus_1; + ui32 q_minus_1_dup; + ui32 ep; + ui32 ep_dup; + ui32 eq; + ui32 eq_dup; + ui32 c1; + ui32 c1_dup; + ui32 base1; + ui32 base1_dup; + ui32 exp1; + ui32 exp1_dup; + ui32 c2; + ui32 c2_dup; + ui32 base2; + ui32 base2_dup; + ui32 exp2; + ui32 exp2_dup; + ui32 qinv; + ui32 qinv_dup; + ui32 t; + ui32 t_dup; + ui32 newt; + ui32 newt_dup; + ui32 r; + ui32 r_dup; + ui32 newr; + ui32 newr_dup; + ui32 quotient; + ui32 quotient_dup; + ui32 tmp; + ui32 tmp_dup; + ui32 h; + ui32 h_dup; + ui32 diff; + ui32 diff_dup; + ui32 c; + ui32 c_dup; + ui32 step_counter; + step_counter = (0 as ui32); + p = (61 as ui32); + p_dup = (61 as ui32); + if (stmt == (0 as ui32)) { + p = (61 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (1 as ui32)) { + return (77 as ui32); + } + q = (53 as ui32); + q_dup = (53 as ui32); + if (stmt == (1 as ui32)) { + q = (53 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (2 as ui32)) { + return (77 as ui32); + } + n = (3233 as ui32); + n_dup = (3233 as ui32); + if (stmt == (2 as ui32)) { + n = (3233 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (3 as ui32)) { + return (77 as ui32); + } + e = (17 as ui32); + e_dup = (17 as ui32); + if (stmt == (3 as ui32)) { + e = (17 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (4 as ui32)) { + return (77 as ui32); + } + m = (65 as ui32); + m_dup = (65 as ui32); + if (stmt == (4 as ui32)) { + m = (65 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (5 as ui32)) { + return (77 as ui32); + } + p_minus_1 = (0 as ui32); + p_minus_1_dup = (0 as ui32); + if (stmt == (5 as ui32)) { + p_minus_1 = (0 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (6 as ui32)) { + return (77 as ui32); + } + q_minus_1 = (0 as ui32); + q_minus_1_dup = (0 as ui32); + if (stmt == (6 as ui32)) { + q_minus_1 = (0 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (7 as ui32)) { + return (77 as ui32); + } + ep = (0 as ui32); + ep_dup = (0 as ui32); + if (stmt == (7 as ui32)) { + ep = (0 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (8 as ui32)) { + return (77 as ui32); + } + eq = (0 as ui32); + eq_dup = (0 as ui32); + if (stmt == (8 as ui32)) { + eq = (0 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (9 as ui32)) { + return (77 as ui32); + } + if (p != p_dup) { + return (77 as ui32); + } + p_minus_1 = p - (1 as ui32); + p_minus_1_dup = p - (1 as ui32); + if (stmt == (9 as ui32)) { + p_minus_1 = p - (1 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (10 as ui32)) { + return (77 as ui32); + } + if (q != q_dup) { + return (77 as ui32); + } + q_minus_1 = q - (1 as ui32); + q_minus_1_dup = q - (1 as ui32); + if (stmt == (10 as ui32)) { + q_minus_1 = q - (1 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (11 as ui32)) { + return (77 as ui32); + } + if (e != e_dup) { + return (77 as ui32); + } + if (e != e_dup) { + return (77 as ui32); + } + if (p_minus_1 != p_minus_1_dup) { + return (77 as ui32); + } + if (p_minus_1 != p_minus_1_dup) { + return (77 as ui32); + } + ep = e - e / p_minus_1 * p_minus_1; + ep_dup = e - e / p_minus_1 * p_minus_1; + if (stmt == (11 as ui32)) { + ep = e - e / p_minus_1 * p_minus_1 ^ flip_mask; + } + step_counter++; + if (step_counter != (12 as ui32)) { + return (77 as ui32); + } + if (e != e_dup) { + return (77 as ui32); + } + if (e != e_dup) { + return (77 as ui32); + } + if (q_minus_1 != q_minus_1_dup) { + return (77 as ui32); + } + if (q_minus_1 != q_minus_1_dup) { + return (77 as ui32); + } + eq = e - e / q_minus_1 * q_minus_1; + eq_dup = e - e / q_minus_1 * q_minus_1; + if (stmt == (12 as ui32)) { + eq = e - e / q_minus_1 * q_minus_1 ^ flip_mask; + } + step_counter++; + if (step_counter != (13 as ui32)) { + return (77 as ui32); + } + c1 = (0 as ui32); + c1_dup = (0 as ui32); + if (stmt == (13 as ui32)) { + c1 = (0 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (14 as ui32)) { + return (77 as ui32); + } + base1 = (0 as ui32); + base1_dup = (0 as ui32); + if (stmt == (14 as ui32)) { + base1 = (0 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (15 as ui32)) { + return (77 as ui32); + } + exp1 = (0 as ui32); + exp1_dup = (0 as ui32); + if (stmt == (15 as ui32)) { + exp1 = (0 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (16 as ui32)) { + return (77 as ui32); + } + c1 = (1 as ui32); + c1_dup = (1 as ui32); + if (stmt == (16 as ui32)) { + c1 = (1 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (17 as ui32)) { + return (77 as ui32); + } + if (m != m_dup) { + return (77 as ui32); + } + if (m != m_dup) { + return (77 as ui32); + } + if (p != p_dup) { + return (77 as ui32); + } + if (p != p_dup) { + return (77 as ui32); + } + base1 = m - m / p * p; + base1_dup = m - m / p * p; + if (stmt == (17 as ui32)) { + base1 = m - m / p * p ^ flip_mask; + } + step_counter++; + if (step_counter != (18 as ui32)) { + return (77 as ui32); + } + if (ep != ep_dup) { + return (77 as ui32); + } + exp1 = ep; + exp1_dup = ep; + if (stmt == (18 as ui32)) { + exp1 = ep ^ flip_mask; + } + step_counter++; + if (step_counter != (19 as ui32)) { + return (77 as ui32); + } + if (exp1 != exp1_dup) { + return (77 as ui32); + } + if (exp1 != exp1_dup) { + return (77 as ui32); + } + if ( exp1 - exp1 / (2 as ui32) * (2 as ui32) == (1 as ui32)) { + if (c1 != c1_dup) { + return (77 as ui32); + } + if (base1 != base1_dup) { + return (77 as ui32); + } + if (c1 != c1_dup) { + return (77 as ui32); + } + if (base1 != base1_dup) { + return (77 as ui32); + } + if (p != p_dup) { + return (77 as ui32); + } + if (p != p_dup) { + return (77 as ui32); + } + c1 = c1 * base1 - c1 * base1 / p * p; + c1_dup = c1 * base1 - c1 * base1 / p * p; + if (stmt == (19 as ui32)) { + c1 = c1 * base1 - c1 * base1 / p * p ^ flip_mask; + } + } + if (exp1 != exp1_dup) { + return (77 as ui32); + } + exp1 = exp1 / (2 as ui32); + exp1_dup = exp1 / (2 as ui32); + if (stmt == (20 as ui32)) { + exp1 = exp1 / (2 as ui32) ^ flip_mask; + } + if (base1 != base1_dup) { + return (77 as ui32); + } + if (base1 != base1_dup) { + return (77 as ui32); + } + if (base1 != base1_dup) { + return (77 as ui32); + } + if (base1 != base1_dup) { + return (77 as ui32); + } + if (p != p_dup) { + return (77 as ui32); + } + if (p != p_dup) { + return (77 as ui32); + } + base1 = base1 * base1 - base1 * base1 / p * p; + base1_dup = base1 * base1 - base1 * base1 / p * p; + if (stmt == (21 as ui32)) { + base1 = base1 * base1 - base1 * base1 / p * p ^ flip_mask; + } + c2 = (0 as ui32); + c2_dup = (0 as ui32); + if (stmt == (22 as ui32)) { + c2 = (0 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (20 as ui32)) { + return (77 as ui32); + } + base2 = (0 as ui32); + base2_dup = (0 as ui32); + if (stmt == (23 as ui32)) { + base2 = (0 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (21 as ui32)) { + return (77 as ui32); + } + exp2 = (0 as ui32); + exp2_dup = (0 as ui32); + if (stmt == (24 as ui32)) { + exp2 = (0 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (22 as ui32)) { + return (77 as ui32); + } + c2 = (1 as ui32); + c2_dup = (1 as ui32); + if (stmt == (25 as ui32)) { + c2 = (1 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (23 as ui32)) { + return (77 as ui32); + } + if (m != m_dup) { + return (77 as ui32); + } + if (m != m_dup) { + return (77 as ui32); + } + if (q != q_dup) { + return (77 as ui32); + } + if (q != q_dup) { + return (77 as ui32); + } + base2 = m - m / q * q; + base2_dup = m - m / q * q; + if (stmt == (26 as ui32)) { + base2 = m - m / q * q ^ flip_mask; + } + step_counter++; + if (step_counter != (24 as ui32)) { + return (77 as ui32); + } + if (eq != eq_dup) { + return (77 as ui32); + } + exp2 = eq; + exp2_dup = eq; + if (stmt == (27 as ui32)) { + exp2 = eq ^ flip_mask; + } + step_counter++; + if (step_counter != (25 as ui32)) { + return (77 as ui32); + } + if (exp2 != exp2_dup) { + return (77 as ui32); + } + if (exp2 != exp2_dup) { + return (77 as ui32); + } + if ( exp2 - exp2 / (2 as ui32) * (2 as ui32) == (1 as ui32)) { + if (c2 != c2_dup) { + return (77 as ui32); + } + if (base2 != base2_dup) { + return (77 as ui32); + } + if (c2 != c2_dup) { + return (77 as ui32); + } + if (base2 != base2_dup) { + return (77 as ui32); + } + if (q != q_dup) { + return (77 as ui32); + } + if (q != q_dup) { + return (77 as ui32); + } + c2 = c2 * base2 - c2 * base2 / q * q; + c2_dup = c2 * base2 - c2 * base2 / q * q; + if (stmt == (28 as ui32)) { + c2 = c2 * base2 - c2 * base2 / q * q ^ flip_mask; + } + } + if (exp2 != exp2_dup) { + return (77 as ui32); + } + exp2 = exp2 / (2 as ui32); + exp2_dup = exp2 / (2 as ui32); + if (stmt == (29 as ui32)) { + exp2 = exp2 / (2 as ui32) ^ flip_mask; + } + if (base2 != base2_dup) { + return (77 as ui32); + } + if (base2 != base2_dup) { + return (77 as ui32); + } + if (base2 != base2_dup) { + return (77 as ui32); + } + if (base2 != base2_dup) { + return (77 as ui32); + } + if (q != q_dup) { + return (77 as ui32); + } + if (q != q_dup) { + return (77 as ui32); + } + base2 = base2 * base2 - base2 * base2 / q * q; + base2_dup = base2 * base2 - base2 * base2 / q * q; + if (stmt == (30 as ui32)) { + base2 = base2 * base2 - base2 * base2 / q * q ^ flip_mask; + } + qinv = (0 as ui32); + qinv_dup = (0 as ui32); + if (stmt == (31 as ui32)) { + qinv = (0 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (26 as ui32)) { + return (77 as ui32); + } + t = (0 as ui32); + t_dup = (0 as ui32); + if (stmt == (32 as ui32)) { + t = (0 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (27 as ui32)) { + return (77 as ui32); + } + newt = (0 as ui32); + newt_dup = (0 as ui32); + if (stmt == (33 as ui32)) { + newt = (0 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (28 as ui32)) { + return (77 as ui32); + } + r = (0 as ui32); + r_dup = (0 as ui32); + if (stmt == (34 as ui32)) { + r = (0 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (29 as ui32)) { + return (77 as ui32); + } + newr = (0 as ui32); + newr_dup = (0 as ui32); + if (stmt == (35 as ui32)) { + newr = (0 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (30 as ui32)) { + return (77 as ui32); + } + quotient = (0 as ui32); + quotient_dup = (0 as ui32); + if (stmt == (36 as ui32)) { + quotient = (0 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (31 as ui32)) { + return (77 as ui32); + } + tmp = (0 as ui32); + tmp_dup = (0 as ui32); + if (stmt == (37 as ui32)) { + tmp = (0 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (32 as ui32)) { + return (77 as ui32); + } + t = (0 as ui32); + t_dup = (0 as ui32); + if (stmt == (38 as ui32)) { + t = (0 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (33 as ui32)) { + return (77 as ui32); + } + newt = (1 as ui32); + newt_dup = (1 as ui32); + if (stmt == (39 as ui32)) { + newt = (1 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (34 as ui32)) { + return (77 as ui32); + } + if (p != p_dup) { + return (77 as ui32); + } + r = p; + r_dup = p; + if (stmt == (40 as ui32)) { + r = p ^ flip_mask; + } + step_counter++; + if (step_counter != (35 as ui32)) { + return (77 as ui32); + } + if (q != q_dup) { + return (77 as ui32); + } + newr = q; + newr_dup = q; + if (stmt == (41 as ui32)) { + newr = q ^ flip_mask; + } + step_counter++; + if (step_counter != (36 as ui32)) { + return (77 as ui32); + } + if (r != r_dup) { + return (77 as ui32); + } + if (newr != newr_dup) { + return (77 as ui32); + } + quotient = r / newr; + quotient_dup = r / newr; + if (stmt == (42 as ui32)) { + quotient = r / newr ^ flip_mask; + } + if (t != t_dup) { + return (77 as ui32); + } + if (quotient != quotient_dup) { + return (77 as ui32); + } + if (newt != newt_dup) { + return (77 as ui32); + } + tmp = t - quotient * newt; + tmp_dup = t - quotient * newt; + if (stmt == (43 as ui32)) { + tmp = t - quotient * newt ^ flip_mask; + } + if (newt != newt_dup) { + return (77 as ui32); + } + t = newt; + t_dup = newt; + if (stmt == (44 as ui32)) { + t = newt ^ flip_mask; + } + if (tmp != tmp_dup) { + return (77 as ui32); + } + newt = tmp; + newt_dup = tmp; + if (stmt == (45 as ui32)) { + newt = tmp ^ flip_mask; + } + if (r != r_dup) { + return (77 as ui32); + } + if (quotient != quotient_dup) { + return (77 as ui32); + } + if (newr != newr_dup) { + return (77 as ui32); + } + tmp = r - quotient * newr; + tmp_dup = r - quotient * newr; + if (stmt == (46 as ui32)) { + tmp = r - quotient * newr ^ flip_mask; + } + if (newr != newr_dup) { + return (77 as ui32); + } + r = newr; + r_dup = newr; + if (stmt == (47 as ui32)) { + r = newr ^ flip_mask; + } + if (tmp != tmp_dup) { + return (77 as ui32); + } + newr = tmp; + newr_dup = tmp; + if (stmt == (48 as ui32)) { + newr = tmp ^ flip_mask; + } + if (t != t_dup) { + return (77 as ui32); + } + if ( t < (0 as ui32)) { + step_counter++; + if (step_counter != (37 as ui32)) { + return (77 as ui32); + } + if (t != t_dup) { + return (77 as ui32); + } + if (p != p_dup) { + return (77 as ui32); + } + qinv = t + p; + qinv_dup = t + p; + if (stmt == (49 as ui32)) { + qinv = t + p ^ flip_mask; + } + step_counter++; + if (step_counter != (38 as ui32)) { + return (77 as ui32); + } + } + else { + if (t != t_dup) { + return (77 as ui32); + } + qinv = t; + qinv_dup = t; + if (stmt == (50 as ui32)) { + qinv = t ^ flip_mask; + } + step_counter++; + if (step_counter != (37 as ui32)) { + return (77 as ui32); + } + step_counter = (38 as ui32); + } + h = (0 as ui32); + h_dup = (0 as ui32); + if (stmt == (51 as ui32)) { + h = (0 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (39 as ui32)) { + return (77 as ui32); + } + diff = (0 as ui32); + diff_dup = (0 as ui32); + if (stmt == (52 as ui32)) { + diff = (0 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (40 as ui32)) { + return (77 as ui32); + } + if (c1 != c1_dup) { + return (77 as ui32); + } + if (c2 != c2_dup) { + return (77 as ui32); + } + diff = c1 - c2; + diff_dup = c1 - c2; + if (stmt == (53 as ui32)) { + diff = c1 - c2 ^ flip_mask; + } + step_counter++; + if (step_counter != (41 as ui32)) { + return (77 as ui32); + } + if (qinv != qinv_dup) { + return (77 as ui32); + } + if (diff != diff_dup) { + return (77 as ui32); + } + if (qinv != qinv_dup) { + return (77 as ui32); + } + if (diff != diff_dup) { + return (77 as ui32); + } + if (p != p_dup) { + return (77 as ui32); + } + if (p != p_dup) { + return (77 as ui32); + } + h = qinv * diff - qinv * diff / p * p; + h_dup = qinv * diff - qinv * diff / p * p; + if (stmt == (54 as ui32)) { + h = qinv * diff - qinv * diff / p * p ^ flip_mask; + } + step_counter++; + if (step_counter != (42 as ui32)) { + return (77 as ui32); + } + if (h != h_dup) { + return (77 as ui32); + } + if ( h < (0 as ui32)) { + step_counter++; + if (step_counter != (43 as ui32)) { + return (77 as ui32); + } + if (h != h_dup) { + return (77 as ui32); + } + if (p != p_dup) { + return (77 as ui32); + } + h = h + p; + h_dup = h + p; + if (stmt == (55 as ui32)) { + h = h + p ^ flip_mask; + } + step_counter++; + if (step_counter != (44 as ui32)) { + return (77 as ui32); + } + } + c = (0 as ui32); + c_dup = (0 as ui32); + if (stmt == (56 as ui32)) { + c = (0 as ui32) ^ flip_mask; + } + step_counter++; + if (step_counter != (45 as ui32)) { + return (77 as ui32); + } + if (c2 != c2_dup) { + return (77 as ui32); + } + if (h != h_dup) { + return (77 as ui32); + } + if (q != q_dup) { + return (77 as ui32); + } + c = c2 + h * q; + c_dup = c2 + h * q; + if (stmt == (57 as ui32)) { + c = c2 + h * q ^ flip_mask; + } + step_counter++; + if (step_counter != (46 as ui32)) { + return (77 as ui32); + } + if (c != c_dup) { + return (77 as ui32); + } + return (c as ui32); +} +stmt = (? as ui32); +bit_shift = (? as ui32); +assume (bit_shift <= (31 as ui32)); +assume (bit_shift >= (0 as ui32)); +assume (stmt >= (0 as ui32)); +assume (stmt <= (57 as ui32)); +flip_mask = ((1 as ui32) << bit_shift); + +res = main(stmt, flip_mask); +assert(res == (0 as ui32)); diff --git a/compiler/src/out.wh b/compiler/src/out.wh new file mode 100644 index 0000000..3125aee --- /dev/null +++ b/compiler/src/out.wh @@ -0,0 +1,300 @@ +ui32 res; +ui32 stmt; +ui32 bit_shift; +ui32 flip_mask; + +fn main(ui32 stmt, ui32 flip_mask) -> ui32 { + ui32 p; + ui32 q; + ui32 n; + ui32 e; + ui32 m; + ui32 p_minus_1; + ui32 q_minus_1; + ui32 ep; + ui32 eq; + ui32 c1; + ui32 base1; + ui32 exp1; + ui32 fault_triggered; + ui32 c2; + ui32 base2; + ui32 exp2; + ui32 qinv; + ui32 t; + ui32 newt; + ui32 r; + ui32 newr; + ui32 quotient; + ui32 tmp; + ui32 h; + ui32 diff; + ui32 c; + p = (61 as ui32); + if (stmt == (0 as ui32)) { + p = (61 as ui32) ^ flip_mask; + } + q = (53 as ui32); + if (stmt == (1 as ui32)) { + q = (53 as ui32) ^ flip_mask; + } + n = (3233 as ui32); + if (stmt == (2 as ui32)) { + n = (3233 as ui32) ^ flip_mask; + } + e = (17 as ui32); + if (stmt == (3 as ui32)) { + e = (17 as ui32) ^ flip_mask; + } + m = (65 as ui32); + if (stmt == (4 as ui32)) { + m = (65 as ui32) ^ flip_mask; + } + p_minus_1 = (0 as ui32); + if (stmt == (5 as ui32)) { + p_minus_1 = (0 as ui32) ^ flip_mask; + } + q_minus_1 = (0 as ui32); + if (stmt == (6 as ui32)) { + q_minus_1 = (0 as ui32) ^ flip_mask; + } + ep = (0 as ui32); + if (stmt == (7 as ui32)) { + ep = (0 as ui32) ^ flip_mask; + } + eq = (0 as ui32); + if (stmt == (8 as ui32)) { + eq = (0 as ui32) ^ flip_mask; + } + p_minus_1 = p - (1 as ui32); + if (stmt == (9 as ui32)) { + p_minus_1 = p - (1 as ui32) ^ flip_mask; + } + q_minus_1 = q - (1 as ui32); + if (stmt == (10 as ui32)) { + q_minus_1 = q - (1 as ui32) ^ flip_mask; + } + ep = e - e / p_minus_1 * p_minus_1; + if (stmt == (11 as ui32)) { + ep = e - e / p_minus_1 * p_minus_1 ^ flip_mask; + } + eq = e - e / q_minus_1 * q_minus_1; + if (stmt == (12 as ui32)) { + eq = e - e / q_minus_1 * q_minus_1 ^ flip_mask; + } + c1 = (0 as ui32); + if (stmt == (13 as ui32)) { + c1 = (0 as ui32) ^ flip_mask; + } + base1 = (0 as ui32); + if (stmt == (14 as ui32)) { + base1 = (0 as ui32) ^ flip_mask; + } + exp1 = (0 as ui32); + if (stmt == (15 as ui32)) { + exp1 = (0 as ui32) ^ flip_mask; + } + c1 = (1 as ui32); + if (stmt == (16 as ui32)) { + c1 = (1 as ui32) ^ flip_mask; + } + base1 = m - m / p * p; + if (stmt == (17 as ui32)) { + base1 = m - m / p * p ^ flip_mask; + } + exp1 = ep; + if (stmt == (18 as ui32)) { + exp1 = ep ^ flip_mask; + } + if ( exp1 - exp1 / (2 as ui32) * (2 as ui32) == (1 as ui32)) { + c1 = c1 * base1 - c1 * base1 / p * p; + if (stmt == (19 as ui32)) { + c1 = c1 * base1 - c1 * base1 / p * p ^ flip_mask; + } + } + exp1 = exp1 / (2 as ui32); + if (stmt == (20 as ui32)) { + exp1 = exp1 / (2 as ui32) ^ flip_mask; + } + base1 = base1 * base1 - base1 * base1 / p * p; + if (stmt == (21 as ui32)) { + base1 = base1 * base1 - base1 * base1 / p * p ^ flip_mask; + } + fault_triggered = (0 as ui32); + if (stmt == (22 as ui32)) { + fault_triggered = (0 as ui32) ^ flip_mask; + } + if ( fault_triggered == (0 as ui32)) { + c1 = c1 + (1 as ui32); + if (stmt == (23 as ui32)) { + c1 = c1 + (1 as ui32) ^ flip_mask; + } + fault_triggered = (1 as ui32); + if (stmt == (24 as ui32)) { + fault_triggered = (1 as ui32) ^ flip_mask; + } + } + c2 = (0 as ui32); + if (stmt == (25 as ui32)) { + c2 = (0 as ui32) ^ flip_mask; + } + base2 = (0 as ui32); + if (stmt == (26 as ui32)) { + base2 = (0 as ui32) ^ flip_mask; + } + exp2 = (0 as ui32); + if (stmt == (27 as ui32)) { + exp2 = (0 as ui32) ^ flip_mask; + } + c2 = (1 as ui32); + if (stmt == (28 as ui32)) { + c2 = (1 as ui32) ^ flip_mask; + } + base2 = m - m / q * q; + if (stmt == (29 as ui32)) { + base2 = m - m / q * q ^ flip_mask; + } + exp2 = eq; + if (stmt == (30 as ui32)) { + exp2 = eq ^ flip_mask; + } + if ( exp2 - exp2 / (2 as ui32) * (2 as ui32) == (1 as ui32)) { + c2 = c2 * base2 - c2 * base2 / q * q; + if (stmt == (31 as ui32)) { + c2 = c2 * base2 - c2 * base2 / q * q ^ flip_mask; + } + } + exp2 = exp2 / (2 as ui32); + if (stmt == (32 as ui32)) { + exp2 = exp2 / (2 as ui32) ^ flip_mask; + } + base2 = base2 * base2 - base2 * base2 / q * q; + if (stmt == (33 as ui32)) { + base2 = base2 * base2 - base2 * base2 / q * q ^ flip_mask; + } + qinv = (0 as ui32); + if (stmt == (34 as ui32)) { + qinv = (0 as ui32) ^ flip_mask; + } + t = (0 as ui32); + if (stmt == (35 as ui32)) { + t = (0 as ui32) ^ flip_mask; + } + newt = (0 as ui32); + if (stmt == (36 as ui32)) { + newt = (0 as ui32) ^ flip_mask; + } + r = (0 as ui32); + if (stmt == (37 as ui32)) { + r = (0 as ui32) ^ flip_mask; + } + newr = (0 as ui32); + if (stmt == (38 as ui32)) { + newr = (0 as ui32) ^ flip_mask; + } + quotient = (0 as ui32); + if (stmt == (39 as ui32)) { + quotient = (0 as ui32) ^ flip_mask; + } + tmp = (0 as ui32); + if (stmt == (40 as ui32)) { + tmp = (0 as ui32) ^ flip_mask; + } + t = (0 as ui32); + if (stmt == (41 as ui32)) { + t = (0 as ui32) ^ flip_mask; + } + newt = (1 as ui32); + if (stmt == (42 as ui32)) { + newt = (1 as ui32) ^ flip_mask; + } + r = p; + if (stmt == (43 as ui32)) { + r = p ^ flip_mask; + } + newr = q; + if (stmt == (44 as ui32)) { + newr = q ^ flip_mask; + } + quotient = r / newr; + if (stmt == (45 as ui32)) { + quotient = r / newr ^ flip_mask; + } + tmp = t - quotient * newt; + if (stmt == (46 as ui32)) { + tmp = t - quotient * newt ^ flip_mask; + } + t = newt; + if (stmt == (47 as ui32)) { + t = newt ^ flip_mask; + } + newt = tmp; + if (stmt == (48 as ui32)) { + newt = tmp ^ flip_mask; + } + tmp = r - quotient * newr; + if (stmt == (49 as ui32)) { + tmp = r - quotient * newr ^ flip_mask; + } + r = newr; + if (stmt == (50 as ui32)) { + r = newr ^ flip_mask; + } + newr = tmp; + if (stmt == (51 as ui32)) { + newr = tmp ^ flip_mask; + } + if ( t < (0 as ui32)) { + qinv = t + p; + if (stmt == (52 as ui32)) { + qinv = t + p ^ flip_mask; + } + } + else { + qinv = t; + if (stmt == (53 as ui32)) { + qinv = t ^ flip_mask; + } + } + h = (0 as ui32); + if (stmt == (54 as ui32)) { + h = (0 as ui32) ^ flip_mask; + } + diff = (0 as ui32); + if (stmt == (55 as ui32)) { + diff = (0 as ui32) ^ flip_mask; + } + diff = c1 - c2; + if (stmt == (56 as ui32)) { + diff = c1 - c2 ^ flip_mask; + } + h = qinv * diff - qinv * diff / p * p; + if (stmt == (57 as ui32)) { + h = qinv * diff - qinv * diff / p * p ^ flip_mask; + } + if ( h < (0 as ui32)) { + h = h + p; + if (stmt == (58 as ui32)) { + h = h + p ^ flip_mask; + } + } + c = (0 as ui32); + if (stmt == (59 as ui32)) { + c = (0 as ui32) ^ flip_mask; + } + c = c2 + h * q; + if (stmt == (60 as ui32)) { + c = c2 + h * q ^ flip_mask; + } + return (c as ui32); +} +stmt = (? as ui32); +bit_shift = (? as ui32); +assume (bit_shift <= (31 as ui32)); +assume (bit_shift >= (0 as ui32)); +assume (stmt >= (0 as ui32)); +assume (stmt <= (60 as ui32)); +flip_mask = ((1 as ui32) << bit_shift); + +res = main(stmt, flip_mask); +assert(res == (0 as ui32)); diff --git a/compiler/src/parser/parser.rs b/compiler/src/parser/parser.rs index 2f1d5c7..1297139 100644 --- a/compiler/src/parser/parser.rs +++ b/compiler/src/parser/parser.rs @@ -1,6 +1,4 @@ -use crate::{ - lexer::token::{Token, TokenType}, -}; +use crate::{ lexer::token::{ Token, TokenType } }; #[derive(Debug, Clone, PartialEq)] pub enum Stmt { Let(String, Type, Expr), @@ -49,7 +47,66 @@ pub enum Expr { Identifier(String), BinaryOp(Box, BinOp, Box), UnaryOp(UnOp, Box), - Call(Vec), + Call(Vec), +} + +impl Expr { + /// Recursively traverses the expression and appends a suffix to all Identifiers. + pub fn duplicate_identifiers(&self, suffix: &str) -> Self { + match self { + Expr::Identifier(name) => { Expr::Identifier(format!("{}{}", name, suffix)) } + Expr::BinaryOp(left, op, right) => { + Expr::BinaryOp( + Box::new(left.duplicate_identifiers(suffix)), + op.clone(), + Box::new(right.duplicate_identifiers(suffix)) + ) + } + Expr::UnaryOp(op, expr) => { + Expr::UnaryOp(op.clone(), Box::new(expr.duplicate_identifiers(suffix))) + } + Expr::Call(args) => { + let dup_args = args + .iter() + .map(|arg| arg.duplicate_identifiers(suffix)) + .collect(); + Expr::Call(dup_args) + } + // Literals don't contain identifiers, so they remain unchanged + Expr::IntegerLiteral(_) | Expr::BooleanLiteral(_) | Expr::StringLiteral(_) => { + self.clone() + } + } + } + pub fn get_all_identifiers(&self) -> Vec { + let mut identifiers = Vec::new(); + self.collect_identifiers(&mut identifiers); + identifiers + } + + // A private helper function that passes a mutable reference + // to avoid allocating multiple vectors during recursion. + fn collect_identifiers(&self, acc: &mut Vec) { + match self { + Expr::Identifier(name) => { + acc.push(name.clone()); + } + Expr::BinaryOp(left, _, right) => { + left.collect_identifiers(acc); + right.collect_identifiers(acc); + } + Expr::UnaryOp(_, expr) => { + expr.collect_identifiers(acc); + } + Expr::Call(args) => { + for arg in args { + arg.collect_identifiers(acc); + } + } + // Literals do not contain any identifiers + Expr::IntegerLiteral(_) | Expr::BooleanLiteral(_) | Expr::StringLiteral(_) => {} + } + } } #[derive(Debug, Clone, PartialEq)] @@ -89,12 +146,13 @@ impl Parser { TokenType::Func => { ast.push(self.parse_func()); } - _ => panic!( - "Wrong token {} at {}:{}", - self.current(), - self.current().line, - self.current().column, - ), + _ => + panic!( + "Wrong token {} at {}:{}", + self.current(), + self.current().line, + self.current().column + ), } } ast @@ -144,10 +202,7 @@ impl Parser { let _ = self.expect(TokenType::Boolean); Type::Boolean } - _ => panic!( - "Unknown return type for function: {}", - self.current().token_type - ), + _ => panic!("Unknown return type for function: {}", self.current().token_type), }; let _ = self.expect(TokenType::LeftBrace); @@ -260,13 +315,14 @@ impl Parser { let type_of_var = match self.current().token_type { TokenType::Integer => Type::Integer, TokenType::Boolean => Type::Boolean, - _ => panic!( - "Expected type, got {:?} ({}) at {}:{}", - self.current().token_type, - self.current().value, - self.current().line, - self.current().column - ), + _ => + panic!( + "Expected type, got {:?} ({}) at {}:{}", + self.current().token_type, + self.current().value, + self.current().line, + self.current().column + ), }; self.consume(); let _ = self.expect(TokenType::Assign); @@ -290,115 +346,112 @@ impl Parser { } fn parse_expression(&mut self) -> Expr { + self.parse_equality() + } + + fn parse_equality(&mut self) -> Expr { + let mut left = self.parse_comparison(); + loop { + if self.match_any(&[TokenType::Equals, TokenType::NotEquals]) { + let op = self.token_to_binop(&self.current().token_type); + self.consume(); + let right = self.parse_comparison(); + left = Expr::BinaryOp(Box::new(left), op, Box::new(right)); + } else { + break; + } + } + left + } + + fn parse_comparison(&mut self) -> Expr { + let mut left = self.parse_additive(); + loop { + if self.match_any(&[TokenType::GreaterThan, TokenType::LessThan]) { + let op = self.token_to_binop(&self.current().token_type); + self.consume(); + let right = self.parse_additive(); + left = Expr::BinaryOp(Box::new(left), op, Box::new(right)); + } else { + break; + } + } + left + } + + fn parse_additive(&mut self) -> Expr { + let mut left = self.parse_multiplicative(); + loop { + if self.match_any(&[TokenType::Plus, TokenType::Minus]) { + let op = self.token_to_binop(&self.current().token_type); + self.consume(); + let right = self.parse_multiplicative(); + left = Expr::BinaryOp(Box::new(left), op, Box::new(right)); + } else { + break; + } + } + left + } + + fn parse_multiplicative(&mut self) -> Expr { + let mut left = self.parse_unary(); + loop { + if self.match_any(&[TokenType::Multiply, TokenType::Division]) { + let op = self.token_to_binop(&self.current().token_type); + self.consume(); + let right = self.parse_unary(); + left = Expr::BinaryOp(Box::new(left), op, Box::new(right)); + } else { + break; + } + } + left + } + + fn parse_unary(&mut self) -> Expr { + if self.match_token(TokenType::Not) { + self.consume(); + let expr = self.parse_unary(); + return Expr::UnaryOp(UnOp::Not, Box::new(expr)); + } + if self.match_token(TokenType::Minus) { + self.consume(); + let expr = self.parse_unary(); + return Expr::UnaryOp(UnOp::Neg, Box::new(expr)); + } + self.parse_primary() + } + + fn parse_primary(&mut self) -> Expr { let tok = self.consume(); match tok.token_type { - TokenType::IntegerLiteral | TokenType::Identifier => { - if self.match_any(&[ - TokenType::Minus, - TokenType::Plus, - TokenType::Multiply, - TokenType::Division, - TokenType::GreaterThan, - TokenType::LessThan, - TokenType::Equals, - TokenType::NotEquals, - ]) { - let op_token = self.consume(); - let op = self.token_to_binop(&op_token.token_type); - let right = self.parse_expression(); - Expr::BinaryOp( - match tok.token_type { - TokenType::IntegerLiteral => { - Box::new(Expr::IntegerLiteral(tok.value.parse::().unwrap())) - } - TokenType::Identifier => Box::new(Expr::Identifier(tok.value)), - _ => panic!("SOMETHING IS WRONGDOG"), - }, - op, - Box::new(right), - ) - } else { - match tok.token_type { - TokenType::IntegerLiteral => { - Expr::IntegerLiteral(tok.value.parse::().unwrap()) + TokenType::IntegerLiteral => { Expr::IntegerLiteral(tok.value.parse::().unwrap()) } + TokenType::Identifier => { + if self.match_token(TokenType::LeftParen) { + self.consume(); + let mut args = Vec::new(); + if !self.match_token(TokenType::RightParen) { + args.push(self.parse_expression()); + while self.match_token(TokenType::Comma) { + self.consume(); + args.push(self.parse_expression()); } - TokenType::Identifier => Expr::Identifier(tok.value), - _ => panic!("tokentype wrong, should be integer literal or identifyer"), } - } - } - TokenType::BooleanLiteral => { - if self.match_any(&[TokenType::Equals, TokenType::NotEquals]) { - let op_token = self.consume(); - let op = self.token_to_binop(&op_token.token_type); - let right = self.parse_expression(); - Expr::BinaryOp( - Box::new(Expr::BooleanLiteral(tok.value.parse::().unwrap())), - op, - Box::new(right), - ) - } else { - let _val = tok.value.clone(); - Expr::BooleanLiteral(tok.value.to_lowercase().parse::().unwrap()) - } - } - TokenType::StringLiteral => { - if self.match_token(TokenType::Equals) { - let op_token = self.consume(); - let op = self.token_to_binop(&op_token.token_type); - let right = self.expect(TokenType::StringLiteral).unwrap(); - Expr::BinaryOp( - Box::new(Expr::StringLiteral(tok.value.parse::().unwrap())), - op, - Box::new(Expr::StringLiteral(right.value.parse::().unwrap())), - ) - } else if self.match_token(TokenType::Not) { - let _ = self.expect(TokenType::Equals); - let op = BinOp::NotEquals; - let right = self.expect(TokenType::StringLiteral).unwrap(); - Expr::BinaryOp( - Box::new(Expr::StringLiteral(tok.value.parse::().unwrap())), - op, - Box::new(Expr::StringLiteral(right.value.parse::().unwrap())), - ) + let _ = self.expect(TokenType::RightParen); + Expr::Call(args) } else { - Expr::StringLiteral(tok.value.clone()) + Expr::Identifier(tok.value) } } - TokenType::Not => { - let exprs = self.parse_expression(); - Expr::UnaryOp(UnOp::Not, Box::new(exprs)) + TokenType::BooleanLiteral => { + Expr::BooleanLiteral(tok.value.to_lowercase().parse::().unwrap()) } - TokenType::Minus => match self.current().token_type { - TokenType::IntegerLiteral => { - let cur = self.consume(); - Expr::IntegerLiteral(-cur.value.parse::().unwrap()) - } - _ => { - let expr = self.parse_expression(); - Expr::UnaryOp(UnOp::Neg, Box::new(expr)) - } - }, + TokenType::StringLiteral => Expr::StringLiteral(tok.value), TokenType::LeftParen => { let expr = self.parse_expression(); let _ = self.expect(TokenType::RightParen); - if self.match_any(&[ - TokenType::Minus, - TokenType::Plus, - TokenType::Multiply, - TokenType::Division, - TokenType::GreaterThan, - TokenType::LessThan, - TokenType::Equals, - TokenType::NotEquals, - ]) { - let op_token = self.consume(); - let op = self.token_to_binop(&op_token.token_type); - let right = self.parse_expression(); - Expr::BinaryOp(Box::new(expr), op, Box::new(right)) - } else { - expr - } + expr } _ => panic!("Unexpected token {:?} in expression", tok.token_type), } @@ -436,10 +489,15 @@ impl Parser { if tok.token_type == expected { Ok(self.consume()) } else { - Err(format!( - "Expected {:?} at {}:{}, found {:?}", - expected, tok.line, tok.column, tok.token_type - )) + Err( + format!( + "Expected {:?} at {}:{}, found {:?}", + expected, + tok.line, + tok.column, + tok.token_type + ) + ) } } } @@ -450,13 +508,15 @@ mod tests { use crate::parser::parser::Stmt; use crate::{ lexer::lexer::Lexer, - parser::parser::{BinOp, Block, Expr, Function, Type, AST}, + parser::parser::{ BinOp, Block, Expr, Function, Type, UnOp, AST }, }; #[test] fn test_parser_parses_correct_ast() { use std::fs; - let source = fs::read_to_string("test_codes/test_correct_ast.trv").expect("Failed to read file"); + let source = fs + ::read_to_string("test_codes/test_correct_ast.trv") + .expect("Failed to read file"); let mut lexer = Lexer::new(source); let tokens = lexer.tokenize(); let mut parser = Parser::new(tokens); @@ -473,39 +533,218 @@ mod tests { expr: Expr::BinaryOp( Box::new(Expr::Identifier("num".to_string())), BinOp::LessThan, - Box::new(Expr::IntegerLiteral(10)), + Box::new(Expr::IntegerLiteral(10)) ), block: Block { - statements: vec![Stmt::AssignStatement( - "num".to_string(), - Expr::IntegerLiteral(11), - )], + statements: vec![ + Stmt::AssignStatement("num".to_string(), Expr::IntegerLiteral(11)) + ], }, }, Stmt::If { condition: Expr::BinaryOp( Box::new(Expr::Identifier("num".to_string())), BinOp::GreaterThan, - Box::new(Expr::IntegerLiteral(10)), + Box::new(Expr::IntegerLiteral(10)) ), block: Block { - statements: vec![Stmt::AssignStatement( - "num".to_string(), - Expr::IntegerLiteral(12), - )], + statements: vec![ + Stmt::AssignStatement("num".to_string(), Expr::IntegerLiteral(12)) + ], }, option: Some(Block { - statements: vec![Stmt::AssignStatement( - "num".to_string(), - Expr::IntegerLiteral(11), - )], + statements: vec![ + Stmt::AssignStatement("num".to_string(), Expr::IntegerLiteral(11)) + ], }), }, - Stmt::Return(Expr::Identifier("num".to_string())), + Stmt::Return(Expr::Identifier("num".to_string())) ], }, }]; assert_eq!(actual, expected); } + + fn parse_expr(source: &str) -> Expr { + let full = format!("func test() -> Integer {{ return {}; }}", source); + let mut lexer = Lexer::new(full); + let tokens = lexer.tokenize(); + let mut parser = Parser::new(tokens); + let ast = parser.parse_program(); + match &ast[0].body.statements[0] { + Stmt::Return(e) => e.clone(), + _ => panic!("Expected return statement"), + } + } + + #[test] + fn test_mul_binds_tighter_than_add() { + let ast = parse_expr("1 + 2 * 3"); + let expected = Expr::BinaryOp( + Box::new(Expr::IntegerLiteral(1)), + BinOp::Add, + Box::new( + Expr::BinaryOp( + Box::new(Expr::IntegerLiteral(2)), + BinOp::Mul, + Box::new(Expr::IntegerLiteral(3)) + ) + ) + ); + assert_eq!(ast, expected); + } + + #[test] + fn test_add_binds_tighter_than_mul() { + let ast = parse_expr("1 * 2 + 3"); + let expected = Expr::BinaryOp( + Box::new( + Expr::BinaryOp( + Box::new(Expr::IntegerLiteral(1)), + BinOp::Mul, + Box::new(Expr::IntegerLiteral(2)) + ) + ), + BinOp::Add, + Box::new(Expr::IntegerLiteral(3)) + ); + assert_eq!(ast, expected); + } + + #[test] + fn test_relational_binds_tighter_than_equality() { + let ast = parse_expr("a == b < c"); + let expected = Expr::BinaryOp( + Box::new(Expr::Identifier("a".to_string())), + BinOp::Equals, + Box::new( + Expr::BinaryOp( + Box::new(Expr::Identifier("b".to_string())), + BinOp::LessThan, + Box::new(Expr::Identifier("c".to_string())) + ) + ) + ); + assert_eq!(ast, expected); + } + + #[test] + fn test_additive_binds_tighter_than_relational() { + let ast = parse_expr("a < b + c"); + let expected = Expr::BinaryOp( + Box::new(Expr::Identifier("a".to_string())), + BinOp::LessThan, + Box::new( + Expr::BinaryOp( + Box::new(Expr::Identifier("b".to_string())), + BinOp::Add, + Box::new(Expr::Identifier("c".to_string())) + ) + ) + ); + assert_eq!(ast, expected); + } + + #[test] + fn test_add_is_left_associative() { + let ast = parse_expr("1 + 2 + 3"); + let expected = Expr::BinaryOp( + Box::new( + Expr::BinaryOp( + Box::new(Expr::IntegerLiteral(1)), + BinOp::Add, + Box::new(Expr::IntegerLiteral(2)) + ) + ), + BinOp::Add, + Box::new(Expr::IntegerLiteral(3)) + ); + assert_eq!(ast, expected); + } + + #[test] + fn test_mul_is_left_associative() { + let ast = parse_expr("1 * 2 * 3"); + let expected = Expr::BinaryOp( + Box::new( + Expr::BinaryOp( + Box::new(Expr::IntegerLiteral(1)), + BinOp::Mul, + Box::new(Expr::IntegerLiteral(2)) + ) + ), + BinOp::Mul, + Box::new(Expr::IntegerLiteral(3)) + ); + assert_eq!(ast, expected); + } + + #[test] + fn test_mixed_precedence_complex() { + let ast = parse_expr("1 + 2 * 3 - 4 / 2"); + let expected = Expr::BinaryOp( + Box::new( + Expr::BinaryOp( + Box::new(Expr::IntegerLiteral(1)), + BinOp::Add, + Box::new( + Expr::BinaryOp( + Box::new(Expr::IntegerLiteral(2)), + BinOp::Mul, + Box::new(Expr::IntegerLiteral(3)) + ) + ) + ) + ), + BinOp::Sub, + Box::new( + Expr::BinaryOp( + Box::new(Expr::IntegerLiteral(4)), + BinOp::Div, + Box::new(Expr::IntegerLiteral(2)) + ) + ) + ); + assert_eq!(ast, expected); + } + + #[test] + fn test_parentheses_override_precedence() { + let ast = parse_expr("(1 + 2) * 3"); + let expected = Expr::BinaryOp( + Box::new( + Expr::BinaryOp( + Box::new(Expr::IntegerLiteral(1)), + BinOp::Add, + Box::new(Expr::IntegerLiteral(2)) + ) + ), + BinOp::Mul, + Box::new(Expr::IntegerLiteral(3)) + ); + assert_eq!(ast, expected); + } + + #[test] + fn test_unary_neg_precedence() { + let ast = parse_expr("-1 * 2"); + let expected = Expr::BinaryOp( + Box::new(Expr::UnaryOp(UnOp::Neg, Box::new(Expr::IntegerLiteral(1)))), + BinOp::Mul, + Box::new(Expr::IntegerLiteral(2)) + ); + assert_eq!(ast, expected); + } + + #[test] + fn test_not_precedence() { + let ast = parse_expr("not True == False"); + let expected = Expr::BinaryOp( + Box::new(Expr::UnaryOp(UnOp::Not, Box::new(Expr::BooleanLiteral(true)))), + BinOp::Equals, + Box::new(Expr::BooleanLiteral(false)) + ); + assert_eq!(ast, expected); + } } diff --git a/compiler/src/test.trv b/compiler/src/test.trv new file mode 100644 index 0000000..0245a65 --- /dev/null +++ b/compiler/src/test.trv @@ -0,0 +1,8 @@ + +func main() -> Integer { + let d : Integer = 5; + let p_minus_1: Integer = 3; + let x : Integer = d - (d / p_minus_1) * p_minus_1; + print x; + return x; +} diff --git a/compiler/src/verify_bellcore.py b/compiler/src/verify_bellcore.py new file mode 100644 index 0000000..0d24438 --- /dev/null +++ b/compiler/src/verify_bellcore.py @@ -0,0 +1,83 @@ +#!/usr/bin/env python3 +"""Bellcore attack verifier for CRT-RSA with SEU fault injection.""" + +import subprocess +import math +import sys + +BIN = "../bin/run_asm" +ASM = "out.s" + +# Known parameters from the source +M = 65 +E = 17 +N = 3233 +P = 61 +Q = 53 + +def mod_pow(base, exp, mod): + result = 1 + base = base % mod + while exp > 0: + if exp % 2 == 1: + result = (result * base) % mod + exp //= 2 + base = (base * base) % mod + return result + +def main(): + print(f"[*] Running {BIN} on {ASM}...") + result = subprocess.run( + [BIN, ASM], + capture_output=True, text=True, timeout=10 + ) + + output = result.stdout.strip() + print(f"[*] stdout:\n{output}") + + # Extract the printed ciphertext (last numeric line before "Finished") + lines = [l.strip() for l in output.splitlines() if l.strip()] + faulty_c = None + for line in reversed(lines): + try: + faulty_c = int(line) + break + except ValueError: + continue + + if faulty_c is None: + print("[!] Could not parse ciphertext from output") + sys.exit(1) + + print(f"[*] Faulty ciphertext c' = {faulty_c}") + + # Compute correct ciphertext + correct_c = mod_pow(M, E, N) + print(f"[*] Correct ciphertext c = {correct_c}") + + if faulty_c == correct_c: + print("[!] No fault detected — ciphertext is correct, attack not applicable") + sys.exit(1) + + # Bellcore attack: gcd(c' - c, n) should reveal q + diff = abs(faulty_c - correct_c) + recovered = math.gcd(diff, N) + + print(f"[*] |c' - c| = {diff}") + print(f"[*] gcd(|c' - c|, n) = {recovered}") + + if recovered == Q: + print(f"[+] SUCCESS: Recovered q = {recovered}") + print(f"[+] p = n / q = {N // recovered}") + elif recovered == P: + print(f"[+] SUCCESS: Recovered p = {recovered}") + print(f"[+] q = n / p = {N // recovered}") + elif recovered == N: + print(f"[!] gcd is n itself — fault may not have been in one CRT half") + sys.exit(1) + else: + print(f"[!] gcd = {recovered} is not p or q — attack failed") + sys.exit(1) + +if __name__ == "__main__": + main() diff --git a/compiler/test_codes/hash.trv b/compiler/test_codes/hash.trv new file mode 100644 index 0000000..dbdbfc2 --- /dev/null +++ b/compiler/test_codes/hash.trv @@ -0,0 +1,46 @@ +func main() -> Integer { + # 123456789 is too big for a single ARM move. + # We build it: 12345 * 10000 + 6789 + let message : Integer = 0; + message = 12345; + + # Initialize hash with a non-zero prime offset (like FNV) + let h : Integer = 5381; + let multiplier : Integer = 33; + + # 104729 is too big for a single ARM move. + # We build it: 104 * 1000 + 729 + let prime_modulo : Integer = 0; + prime_modulo = 104 * 1000 + 729; + + let temp_msg : Integer = message; + let chunk : Integer = 0; + + # Handle a 0 message quickly + if temp_msg == 0 then { + temp_msg = 7; # Fallback seed + } + + # Single loop: process the integer by stripping off digits/chunks + while temp_msg > 0 do { + # chunk = temp_msg mod 100 (processes two digits at a time) + chunk = temp_msg - (temp_msg / 100) * 100; + + # Mix the chunk into the hash + h = (h * multiplier) + chunk; + + # Inline modulo: h = h mod prime_modulo + h = h - (h / prime_modulo) * prime_modulo; + + # Move to the next chunk + temp_msg = temp_msg / 100; + } + + # Final guard statement if operations pushed the integer into negative wrap + if h < 0 then { + h = h + prime_modulo; + } + + print h; + return h; +} diff --git a/compiler/test_codes/hash.trv.output b/compiler/test_codes/hash.trv.output new file mode 100644 index 0000000..4602eed --- /dev/null +++ b/compiler/test_codes/hash.trv.output @@ -0,0 +1 @@ +97028 diff --git a/compiler/test_codes/simple.trv b/compiler/test_codes/simple.trv index 0205385..f0ad105 100644 --- a/compiler/test_codes/simple.trv +++ b/compiler/test_codes/simple.trv @@ -1,6 +1,5 @@ -func main() -> Boolean { +func main() -> Integer { let num : Integer = 0; - let test : Boolean = True; while num < 10 do { let etellerandet : Integer = 1; @@ -14,9 +13,5 @@ func main() -> Boolean { num = 11; } - if test != True { - return test; - } else { - return num; - } + return num; } diff --git a/compiler/test_codes/simple.trv.output b/compiler/test_codes/simple.trv.output index b4de394..9d60796 100644 --- a/compiler/test_codes/simple.trv.output +++ b/compiler/test_codes/simple.trv.output @@ -1 +1 @@ -11 +11 \ No newline at end of file diff --git a/compiler/test_codes/test_correct_ast_dupped.trv b/compiler/test_codes/test_correct_ast_dupped.trv new file mode 100644 index 0000000..b5b4b6d --- /dev/null +++ b/compiler/test_codes/test_correct_ast_dupped.trv @@ -0,0 +1,13 @@ +func main() -> Integer { + let num : Integer = 0; + + while num < 10 do { + num = 11; + } + if num > 10 { + num = 12; + } else { + num = 11; + } + return num; +} diff --git a/compiler/test_vd.trv b/compiler/test_vd.trv new file mode 100644 index 0000000..12a740e --- /dev/null +++ b/compiler/test_vd.trv @@ -0,0 +1,13 @@ +func main() -> Integer { + let x : Integer = 0; + let y : Integer = 2; + let z : Integer = 4; + let vd : Integer = x + y + z + 1; + + if vd == 6 then { + vd = 7; + } else { + vd = 8; + } + return vd; +} diff --git a/compiler/test_vd_dup.trv b/compiler/test_vd_dup.trv new file mode 100644 index 0000000..c1591f2 --- /dev/null +++ b/compiler/test_vd_dup.trv @@ -0,0 +1,44 @@ +func main() -> Integer { + let x : Integer = 0; + let x_dup : Integer = 0; + let y : Integer = 2; + let y_dup : Integer = 2; + let z : Integer = 4; + let z_dup : Integer = 4; + if x != x_dup { + return 77; + } + + if y != y_dup { + return 77; + } + + if z != z_dup { + return 77; + } + + let vd : Integer = x + y + z + 1; + let vd_dup : Integer = x_dup + y_dup + z_dup + 1; + + if vd != vd_dup { + return 77; + } + if vd == 6 then { + if vd != vd_dup { + return 77; + } + vd = 7; + vd_dup = 7; + } else { + if vd != vd_dup { + return 77; + } + vd = 8; + vd_dup = 8; + } + + if vd != vd_dup { + return 77; + } + return vd; +} diff --git a/compiler/vpin/VerifyPIN_0/Makefile b/compiler/vpin/VerifyPIN_0/Makefile deleted file mode 100755 index 094bf73..0000000 --- a/compiler/vpin/VerifyPIN_0/Makefile +++ /dev/null @@ -1,26 +0,0 @@ -# Makefile script with commands to generate the benchmark assembly and binaries. -# Description of the targets: -# x86-ptc: produce lazart object files with oracle PTC -# x86-auth: produce lazart object files with oracle AUTH -# clean: clean generated files, including output binaries - -.PHONY: clean x86-ptc x86-auth - -TARGET = verifypin_0 -FILES = src/countermeasure.c src/initialize.c src/oracle.c src/code.c src/main.c - -INC_DIR = -I../share -Iinclude -BIN_DIR = bin - -CFLAGS = $(INC_DIR) -Wall -Wextra - -x86-auth: - @mkdir -p $(BIN_DIR) - @clang -DAUTH $(FILES) $(CFLAGS) -o $(BIN_DIR)/$(TARGET) - -x86-ptc: - @mkdir -p $(BIN_DIR) - @clang -DPTC $(FILES) $(CFLAGS) -o $(BIN_DIR)/$(TARGET) - -clean: - @rm -rf $(BIN_DIR) diff --git a/compiler/vpin/VerifyPIN_0/src/code.c b/compiler/vpin/VerifyPIN_0/src/code.c deleted file mode 100755 index 72553cd..0000000 --- a/compiler/vpin/VerifyPIN_0/src/code.c +++ /dev/null @@ -1,58 +0,0 @@ -/**************************************************************************/ -/* */ -/* This file is part of FISSC. */ -/* */ -/* you can redistribute it and/or modify it under the terms of the GNU */ -/* Lesser General Public License as published by the Free Software */ -/* Foundation, version 3.0. */ -/* */ -/* It is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ -/* GNU Lesser General Public License for more details. */ -/* */ -/* See the GNU Lesser General Public License version 3.0 */ -/* for more details (enclosed in the file LICENSE). */ -/* */ -/**************************************************************************/ - -#include "interface.h" -#include "types.h" -#include "commons.h" - -extern SBYTE g_ptc; -extern BOOL g_authenticated; -extern UBYTE g_userPin[PIN_SIZE]; -extern UBYTE g_cardPin[PIN_SIZE]; - -#ifdef INLINE -__attribute__((always_inline)) inline BOOL byteArrayCompare(UBYTE* a1, UBYTE* a2, UBYTE size) -#else -BOOL byteArrayCompare(UBYTE* a1, UBYTE* a2, UBYTE size) -#endif -{ - int i; - for(i = 0; i < size; i++) { - if(a1[i] != a2[i]) { - return 0; - } - } - return 1; -} - -BOOL verifyPIN() { - g_authenticated = 0; - - if(g_ptc > 0) { - if(byteArrayCompare(g_userPin, g_cardPin, PIN_SIZE) == 1) { - g_ptc = 3; - g_authenticated = 1; // Authentication(); - return 1; - } else { - g_ptc--; - return 0; - } - } - - return 0; -} diff --git a/compiler/vpin/VerifyPIN_0/src/commons.h b/compiler/vpin/VerifyPIN_0/src/commons.h deleted file mode 100755 index 78ce18f..0000000 --- a/compiler/vpin/VerifyPIN_0/src/commons.h +++ /dev/null @@ -1,26 +0,0 @@ -/**************************************************************************/ -/* */ -/* This file is part of FISSC. */ -/* */ -/* you can redistribute it and/or modify it under the terms of the GNU */ -/* Lesser General Public License as published by the Free Software */ -/* Foundation, version 3.0. */ -/* */ -/* It is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ -/* GNU Lesser General Public License for more details. */ -/* */ -/* See the GNU Lesser General Public License version 3.0 */ -/* for more details (enclosed in the file LICENSE). */ -/* */ -/**************************************************************************/ - -#ifndef H_COMMONS -#define H_COMMONS - -// macro definitions -#define INITIAL_VALUE 0x2a -#define PIN_SIZE 4 - -#endif // H_COMMONS diff --git a/compiler/vpin/VerifyPIN_0/src/countermeasure.c b/compiler/vpin/VerifyPIN_0/src/countermeasure.c deleted file mode 100755 index 3475fbf..0000000 --- a/compiler/vpin/VerifyPIN_0/src/countermeasure.c +++ /dev/null @@ -1,27 +0,0 @@ -/**************************************************************************/ -/* */ -/* This file is part of FISSC. */ -/* */ -/* you can redistribute it and/or modify it under the terms of the GNU */ -/* Lesser General Public License as published by the Free Software */ -/* Foundation, version 3.0. */ -/* */ -/* It is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ -/* GNU Lesser General Public License for more details. */ -/* */ -/* See the GNU Lesser General Public License version 3.0 */ -/* for more details (enclosed in the file LICENSE). */ -/* */ -/**************************************************************************/ - -#include "interface.h" -#include "types.h" - -extern UBYTE g_countermeasure; - -void countermeasure() -{ - g_countermeasure = 1; -} diff --git a/compiler/vpin/VerifyPIN_0/src/initialize.c b/compiler/vpin/VerifyPIN_0/src/initialize.c deleted file mode 100755 index 50abcc9..0000000 --- a/compiler/vpin/VerifyPIN_0/src/initialize.c +++ /dev/null @@ -1,48 +0,0 @@ -/**************************************************************************/ -/* */ -/* This file is part of FISSC. */ -/* */ -/* you can redistribute it and/or modify it under the terms of the GNU */ -/* Lesser General Public License as published by the Free Software */ -/* Foundation, version 3.0. */ -/* */ -/* It is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ -/* GNU Lesser General Public License for more details. */ -/* */ -/* See the GNU Lesser General Public License version 3.0 */ -/* for more details (enclosed in the file LICENSE). */ -/* */ -/**************************************************************************/ - -#include "types.h" -#include "interface.h" -#include "commons.h" - -// global variables definition -BOOL g_authenticated; -SBYTE g_ptc; -UBYTE g_countermeasure; -UBYTE g_userPin[PIN_SIZE]; -UBYTE g_cardPin[PIN_SIZE]; - - -void initialize() -{ - // local variables - int i; - // global variables initialization - g_authenticated = 0; - g_ptc = 3; - g_countermeasure = 0; - // card PIN = 1 2 3 4 5... - for (i = 0; i < PIN_SIZE; ++i) { - g_cardPin[i] = i+1; - } - // user PIN = 0 0 0 0 0... - for (i = 0 ; i < PIN_SIZE; ++i) { - g_userPin[i] = 0; - } -} - diff --git a/compiler/vpin/VerifyPIN_0/src/main.c b/compiler/vpin/VerifyPIN_0/src/main.c deleted file mode 100755 index 159fb1c..0000000 --- a/compiler/vpin/VerifyPIN_0/src/main.c +++ /dev/null @@ -1,50 +0,0 @@ -/**************************************************************************/ -/* */ -/* This file is part of FISSC. */ -/* */ -/* You can redistribute it and/or modify it under the terms of the GNU */ -/* Lesser General Public License as published by the Free Software */ -/* Foundation, version 3.0. */ -/* */ -/* It is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ -/* GNU Lesser General Public License for more details. */ -/* */ -/* See the GNU Lesser General Public License version 3.0 */ -/* for more details (enclosed in the file LICENSE). */ -/* */ -/**************************************************************************/ - -/*$ - @name = VerifyPIN_0 - @feature = verifyPIN - @fault-model = test-inversion - @attack-scenario = oracle - @countermeasure = none - @maintainers = Etienne Boespflug, VERIMAG - @authors = Lionel Rivière, SERTIF Consortium - @version 2.2 -*/ - -#include - -#include "interface.h" -#include "types.h" -#include "lazart.h" - -extern UBYTE g_countermeasure; -extern BOOL g_authenticated; -extern SBYTE g_ptc; - -BOOL verifyPIN(void); - -int main() -{ - initialize(); - verifyPIN(); - LAZART_ORACLE(oracle()); - - printf("[@] g_countermeasure = %i, g_authenticated = %x, g_ptc = %i\n", g_countermeasure, g_authenticated, g_ptc); - return 0; -} diff --git a/compiler/vpin/VerifyPIN_0/src/oracle.c b/compiler/vpin/VerifyPIN_0/src/oracle.c deleted file mode 100755 index 72306cb..0000000 --- a/compiler/vpin/VerifyPIN_0/src/oracle.c +++ /dev/null @@ -1,45 +0,0 @@ -/**************************************************************************/ -/* */ -/* This file is part of FISSC. */ -/* */ -/* you can redistribute it and/or modify it under the terms of the GNU */ -/* Lesser General Public License as published by the Free Software */ -/* Foundation, version 3.0. */ -/* */ -/* It is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ -/* GNU Lesser General Public License for more details. */ -/* */ -/* See the GNU Lesser General Public License version 3.0 */ -/* for more details (enclosed in the file LICENSE). */ -/* */ -/**************************************************************************/ - -#include "interface.h" -#include "types.h" - -// define the oracle you want to use. -#ifdef AUTH -#define oracle_auth oracle -#endif - -#ifdef PTC -#define oracle_ptc oracle -#endif - -extern UBYTE g_countermeasure; -extern BOOL g_authenticated; -extern SBYTE g_ptc; - -BOOL oracle_auth() -{ - return g_countermeasure != 1 && g_authenticated == 1; -} - -BOOL oracle_ptc() -{ - return g_countermeasure != 1 && g_ptc >= 3; -} - - diff --git a/compiler/vpin/crt-rsa.asm b/compiler/vpin/crt-rsa.asm deleted file mode 100644 index 4840fca..0000000 --- a/compiler/vpin/crt-rsa.asm +++ /dev/null @@ -1,498 +0,0 @@ -.syntax unified -.thumb - -.section .text -.global _start -.type _start, %function - -_start: - sub sp, sp, #4 - mov r0, #0 - str r0, [sp] - sub sp, sp, #4 - mov r0, #11413 - str r0, [sp] - sub sp, sp, #4 - mov r0, #3533 - str r0, [sp] - sub sp, sp, #4 - mov r0, #101 - str r0, [sp] - sub sp, sp, #4 - mov r0, #113 - str r0, [sp] - sub sp, sp, #4 - mov r0, #59 - str r0, [sp] - sub sp, sp, #4 - mov r0, #97 - str r0, [sp] - sub sp, sp, #4 - mov r0, #101 - str r0, [sp] - sub sp, sp, #4 - mov r0, #-1 - str r0, [sp] - sub sp, sp, #4 - mov r0, #23 - str r0, [sp] - sub sp, sp, #4 - mov r0, #0 - str r0, [sp] - sub sp, sp, #4 - mov r0, #0 - str r0, [sp] - sub sp, sp, #4 - mov r0, #0 - str r0, [sp] - sub sp, sp, #4 - mov r0, #0 - str r0, [sp] - sub sp, sp, #4 - mov r0, #0 - str r0, [sp] - sub sp, sp, #4 - mov r0, #0 - str r0, [sp] - sub sp, sp, #4 - mov r0, #0 - str r0, [sp] - sub sp, sp, #4 - mov r0, #0 - str r0, [sp] - sub sp, sp, #4 - mov r0, #0 - str r0, [sp] - sub sp, sp, #4 - mov r0, #0 - str r0, [sp] - sub sp, sp, #4 - mov r0, #0 - str r0, [sp] - sub sp, sp, #4 - mov r0, #0 - str r0, [sp] - sub sp, sp, #4 - mov r0, #0 - str r0, [sp] - sub sp, sp, #4 - mov r0, #0 - str r0, [sp] - sub sp, sp, #4 - mov r0, #0 - str r0, [sp] - sub sp, sp, #4 - mov r0, #0 - str r0, [sp] - ldr r0, [sp, #64] - str r0, [sp, #48] - ldr r0, [sp, #76] - str r0, [sp, #44] - ldr r0, [sp, #88] - str r0, [sp, #40] - mov r0, #1 - str r0, [sp, #36] - mov r0, #0 - str r0, [sp, #4] -while_0: - ldr r0, [sp, #4] - mov r1, r0 - ldr r0, [sp, #44] - cmp r1, r0 - mov r0, #0 - it lt - movlt r0, #1 - cmp r0, #0 - beq end_while_0 - ldr r0, [sp, #36] - str r0, [sp, #28] - ldr r0, [sp, #48] - str r0, [sp, #24] - ldr r0, [sp, #40] - str r0, [sp, #20] - mov r0, #0 - str r0, [sp, #16] -while_1: - ldr r0, [sp, #24] - mov r1, r0 - mov r0, #0 - cmp r1, r0 - mov r0, #0 - it gt - movgt r0, #1 - cmp r0, #0 - beq end_while_1 - ldr r0, [sp, #16] - mov r1, r0 - ldr r0, [sp, #28] - add r0, r1, r0 - str r0, [sp, #16] -while_2: - ldr r0, [sp, #16] - mov r1, r0 - ldr r0, [sp, #20] - cmp r1, r0 - mov r0, #0 - it gt - movgt r0, #1 - cmp r0, #0 - beq end_while_2 - ldr r0, [sp, #16] - mov r1, r0 - ldr r0, [sp, #20] - sub r0, r1, r0 - str r0, [sp, #16] - b while_2 -end_while_2: -while_3: - ldr r0, [sp, #16] - mov r1, r0 - mov r0, #0 - cmp r1, r0 - mov r0, #0 - it lt - movlt r0, #1 - cmp r0, #0 - beq end_while_3 - ldr r0, [sp, #16] - mov r1, r0 - ldr r0, [sp, #20] - add r0, r1, r0 - str r0, [sp, #16] - b while_3 -end_while_3: - ldr r0, [sp, #16] - mov r1, r0 - ldr r0, [sp, #20] - cmp r1, r0 - mov r0, #0 - it eq - moveq r0, #1 - cmp r0, #0 - beq else_4 - mov r0, #0 - str r0, [sp, #16] - b endif_4 -else_4: -endif_4: - ldr r0, [sp, #24] - mov r1, r0 - mov r0, #1 - sub r0, r1, r0 - str r0, [sp, #24] - b while_1 -end_while_1: - ldr r0, [sp, #16] - str r0, [sp, #36] - ldr r0, [sp, #4] - mov r1, r0 - mov r0, #1 - add r0, r1, r0 - str r0, [sp, #4] - b while_0 -end_while_0: - ldr r0, [sp, #36] - str r0, [sp, #60] - ldr r0, [sp, #64] - str r0, [sp, #48] - ldr r0, [sp, #72] - str r0, [sp, #44] - ldr r0, [sp, #84] - str r0, [sp, #40] - mov r0, #1 - str r0, [sp, #36] - mov r0, #0 - str r0, [sp, #4] -while_5: - ldr r0, [sp, #4] - mov r1, r0 - ldr r0, [sp, #44] - cmp r1, r0 - mov r0, #0 - it lt - movlt r0, #1 - cmp r0, #0 - beq end_while_5 - ldr r0, [sp, #36] - str r0, [sp, #28] - ldr r0, [sp, #48] - str r0, [sp, #24] - ldr r0, [sp, #40] - str r0, [sp, #20] - mov r0, #0 - str r0, [sp, #16] -while_6: - ldr r0, [sp, #24] - mov r1, r0 - mov r0, #0 - cmp r1, r0 - mov r0, #0 - it gt - movgt r0, #1 - cmp r0, #0 - beq end_while_6 - ldr r0, [sp, #16] - mov r1, r0 - ldr r0, [sp, #28] - add r0, r1, r0 - str r0, [sp, #16] -while_7: - ldr r0, [sp, #16] - mov r1, r0 - ldr r0, [sp, #20] - cmp r1, r0 - mov r0, #0 - it gt - movgt r0, #1 - cmp r0, #0 - beq end_while_7 - ldr r0, [sp, #16] - mov r1, r0 - ldr r0, [sp, #20] - sub r0, r1, r0 - str r0, [sp, #16] - b while_7 -end_while_7: -while_8: - ldr r0, [sp, #16] - mov r1, r0 - mov r0, #0 - cmp r1, r0 - mov r0, #0 - it lt - movlt r0, #1 - cmp r0, #0 - beq end_while_8 - ldr r0, [sp, #16] - mov r1, r0 - ldr r0, [sp, #20] - add r0, r1, r0 - str r0, [sp, #16] - b while_8 -end_while_8: - ldr r0, [sp, #16] - mov r1, r0 - ldr r0, [sp, #20] - cmp r1, r0 - mov r0, #0 - it eq - moveq r0, #1 - cmp r0, #0 - beq else_9 - mov r0, #0 - str r0, [sp, #16] - b endif_9 -else_9: -endif_9: - ldr r0, [sp, #24] - mov r1, r0 - mov r0, #1 - sub r0, r1, r0 - str r0, [sp, #24] - b while_6 -end_while_6: - ldr r0, [sp, #16] - str r0, [sp, #36] - ldr r0, [sp, #4] - mov r1, r0 - mov r0, #1 - add r0, r1, r0 - str r0, [sp, #4] - b while_5 -end_while_5: - ldr r0, [sp, #36] - str r0, [sp, #56] - ldr r0, [sp, #60] - mov r1, r0 - ldr r0, [sp, #56] - sub r0, r1, r0 - str r0, [sp, #52] - ldr r0, [sp, #52] - str r0, [sp, #28] - ldr r0, [sp, #80] - str r0, [sp, #24] - ldr r0, [sp, #88] - str r0, [sp, #20] - mov r0, #0 - str r0, [sp, #16] -while_10: - ldr r0, [sp, #24] - mov r1, r0 - mov r0, #0 - cmp r1, r0 - mov r0, #0 - it gt - movgt r0, #1 - cmp r0, #0 - beq end_while_10 - ldr r0, [sp, #16] - mov r1, r0 - ldr r0, [sp, #28] - add r0, r1, r0 - str r0, [sp, #16] -while_11: - ldr r0, [sp, #16] - mov r1, r0 - ldr r0, [sp, #20] - cmp r1, r0 - mov r0, #0 - it gt - movgt r0, #1 - cmp r0, #0 - beq end_while_11 - ldr r0, [sp, #16] - mov r1, r0 - ldr r0, [sp, #20] - sub r0, r1, r0 - str r0, [sp, #16] - b while_11 -end_while_11: -while_12: - ldr r0, [sp, #16] - mov r1, r0 - mov r0, #0 - cmp r1, r0 - mov r0, #0 - it lt - movlt r0, #1 - cmp r0, #0 - beq end_while_12 - ldr r0, [sp, #16] - mov r1, r0 - ldr r0, [sp, #20] - add r0, r1, r0 - str r0, [sp, #16] - b while_12 -end_while_12: - ldr r0, [sp, #16] - mov r1, r0 - ldr r0, [sp, #20] - cmp r1, r0 - mov r0, #0 - it eq - moveq r0, #1 - cmp r0, #0 - beq else_13 - mov r0, #0 - str r0, [sp, #16] - b endif_13 -else_13: -endif_13: - ldr r0, [sp, #24] - mov r1, r0 - mov r0, #1 - sub r0, r1, r0 - str r0, [sp, #24] - b while_10 -end_while_10: - ldr r0, [sp, #16] - str r0, [sp, #52] - ldr r0, [sp, #52] - mov r1, r0 - ldr r0, [sp, #84] - mul r0, r1, r0 - str r0, [sp, #52] - ldr r0, [sp, #52] - mov r1, r0 - ldr r0, [sp, #56] - add r0, r1, r0 - str r0, [sp, #52] - ldr r0, [sp, #52] - str r0, [sp, #68] - mov r0, #1 - ldr r1, =.Lstr0 - mov r2, #9 - mov r7, #4 - svc #0 - ldr r0, [sp, #68] - mov r4, r0 - ldr r1, =num_buf - add r1, r1, #16 - mov r2, #0 - cmp r4, #0 - bne print_int_loop_14 - mov r3, #48 - sub r1, r1, #1 - strb r3, [r1] - mov r2, #1 - b print_int_done_14 -print_int_loop_14: - mov r0, r4 - mov r3, #10 - sdiv r5, r0, r3 - mul r6, r5, r3 - sub r7, r0, r6 - add r7, r7, #48 - sub r1, r1, #1 - strb r7, [r1] - add r2, r2, #1 - mov r4, r5 - cmp r4, #0 - bne print_int_loop_14 -print_int_done_14: - mov r0, #1 - mov r1, r1 - mov r2, r2 - mov r7, #4 - svc #0 - mov r0, #1 - ldr r1, =newline - mov r2, #1 - mov r7, #4 - svc #0 - mov r0, #1 - ldr r1, =.Lstr1 - mov r2, #18 - mov r7, #4 - svc #0 - ldr r0, [sp, #100] - mov r4, r0 - ldr r1, =num_buf - add r1, r1, #16 - mov r2, #0 - cmp r4, #0 - bne print_int_loop_15 - mov r3, #48 - sub r1, r1, #1 - strb r3, [r1] - mov r2, #1 - b print_int_done_15 -print_int_loop_15: - mov r0, r4 - mov r3, #10 - sdiv r5, r0, r3 - mul r6, r5, r3 - sub r7, r0, r6 - add r7, r7, #48 - sub r1, r1, #1 - strb r7, [r1] - add r2, r2, #1 - mov r4, r5 - cmp r4, #0 - bne print_int_loop_15 -print_int_done_15: - mov r0, #1 - mov r1, r1 - mov r2, r2 - mov r7, #4 - svc #0 - mov r0, #1 - ldr r1, =newline - mov r2, #1 - mov r7, #4 - svc #0 - ldr r0, [sp, #68] - mov r7, #1 - svc #0 - -.size _start, .-_start - -.section .data -.Lstr0: - .ascii "g_sign = " -.Lstr1: - .ascii "g_countermeasure: " -newline: - .ascii "\n" -num_buf: - .space 16 diff --git a/compiler/vpin/crt-rsa.trv b/compiler/vpin/crt-rsa.trv deleted file mode 100644 index 62fc913..0000000 --- a/compiler/vpin/crt-rsa.trv +++ /dev/null @@ -1,121 +0,0 @@ -func main() -> Integer { - let g_countermeasure : Integer = 0; - let g_N : Integer = 11413; - let g_e : Integer = 3533; - let g_p : Integer = 101; - let g_q : Integer = 113; - let g_iq : Integer = 59; - let g_dp : Integer = 97; - let g_dq : Integer = 101; - let g_sign : Integer = -1; - let g_M : Integer = 23; - - let Cp : Integer = 0; - let Cq : Integer = 0; - let tmp : Integer = 0; - - let a : Integer = 0; - let b : Integer = 0; - let n : Integer = 0; - let r : Integer = 0; - - let mul_r : Integer = 0; - let mul_a : Integer = 0; - let mul_b : Integer = 0; - let mul_n : Integer = 0; - let mul_tmp : Integer = 0; - - let pow_a : Integer = 0; - let pow_tmp : Integer = 0; - let pow_b : Integer = 0; - let pow_n : Integer = 0; - - a = g_M; - b = g_dp; - n = g_p; - r = 1; - pow_b = 0; - while pow_b < b { - mul_a = r; - mul_b = a; - mul_n = n; - mul_tmp = 0; - while mul_b > 0 { - mul_tmp = mul_tmp + mul_a; - while mul_tmp > mul_n { - mul_tmp = mul_tmp - mul_n; - } - while mul_tmp < 0 { - mul_tmp = mul_tmp + mul_n; - } - if mul_tmp == mul_n { - mul_tmp = 0; - } - mul_b = mul_b - 1; - } - r = mul_tmp; - pow_b = pow_b + 1; - } - Cp = r; - - a = g_M; - b = g_dq; - n = g_q; - r = 1; - pow_b = 0; - while pow_b < b { - mul_a = r; - mul_b = a; - mul_n = n; - mul_tmp = 0; - while mul_b > 0 { - mul_tmp = mul_tmp + mul_a; - while mul_tmp > mul_n { - mul_tmp = mul_tmp - mul_n; - } - while mul_tmp < 0 { - mul_tmp = mul_tmp + mul_n; - } - if mul_tmp == mul_n { - mul_tmp = 0; - } - mul_b = mul_b - 1; - } - r = mul_tmp; - pow_b = pow_b + 1; - } - Cq = r; - - tmp = Cp - Cq; - - mul_a = tmp; - mul_b = g_iq; - mul_n = g_p; - mul_tmp = 0; - while mul_b > 0 { - mul_tmp = mul_tmp + mul_a; - while mul_tmp > mul_n { - mul_tmp = mul_tmp - mul_n; - } - while mul_tmp < 0 { - mul_tmp = mul_tmp + mul_n; - } - if mul_tmp == mul_n { - mul_tmp = 0; - } - mul_b = mul_b - 1; - } - tmp = mul_tmp; - - tmp = tmp * g_q; - - tmp = tmp + Cq; - - g_sign = tmp; - - print("g_sign = ", g_sign); - - print("g_countermeasure: ", g_countermeasure); - - return g_sign; -} diff --git a/compiler/vpin/out.asm b/compiler/vpin/out.asm deleted file mode 100644 index 83c42ef..0000000 --- a/compiler/vpin/out.asm +++ /dev/null @@ -1,276 +0,0 @@ -.syntax unified -.thumb - -.section .text -.global _start -.type _start, %function - -_start: - sub sp, sp, #4 - mov r0, #0 - str r0, [sp] - sub sp, sp, #4 - mov r0, #3 - str r0, [sp] - sub sp, sp, #4 - mov r0, #0 - str r0, [sp] - sub sp, sp, #4 - mov r0, #1 - str r0, [sp] - sub sp, sp, #4 - mov r0, #2 - str r0, [sp] - sub sp, sp, #4 - mov r0, #3 - str r0, [sp] - sub sp, sp, #4 - mov r0, #4 - str r0, [sp] - sub sp, sp, #4 - mov r0, #0 - str r0, [sp] - sub sp, sp, #4 - mov r0, #0 - str r0, [sp] - sub sp, sp, #4 - mov r0, #0 - str r0, [sp] - sub sp, sp, #4 - mov r0, #0 - str r0, [sp] - mov r0, #0 - str r0, [sp, #32] - ldr r0, [sp, #36] - mov r1, r0 - mov r0, #0 - cmp r1, r0 - mov r0, #0 - it gt - movgt r0, #1 - cmp r0, #0 - beq else_0 - sub sp, sp, #4 - mov r0, #1 - str r0, [sp] - ldr r0, [sp, #16] - mov r1, r0 - ldr r0, [sp, #32] - cmp r1, r0 - mov r0, #0 - it ne - movne r0, #1 - cmp r0, #0 - beq else_1 - mov r0, #0 - str r0, [sp] - b endif_1 -else_1: -endif_1: - ldr r0, [sp, #12] - mov r1, r0 - ldr r0, [sp, #28] - cmp r1, r0 - mov r0, #0 - it ne - movne r0, #1 - cmp r0, #0 - beq else_2 - mov r0, #0 - str r0, [sp] - b endif_2 -else_2: -endif_2: - ldr r0, [sp, #8] - mov r1, r0 - ldr r0, [sp, #24] - cmp r1, r0 - mov r0, #0 - it ne - movne r0, #1 - cmp r0, #0 - beq else_3 - mov r0, #0 - str r0, [sp] - b endif_3 -else_3: -endif_3: - ldr r0, [sp, #4] - mov r1, r0 - ldr r0, [sp, #20] - cmp r1, r0 - mov r0, #0 - it ne - movne r0, #1 - cmp r0, #0 - beq else_4 - mov r0, #0 - str r0, [sp] - b endif_4 -else_4: -endif_4: - ldr r0, [sp, #0] - mov r1, r0 - mov r0, #1 - cmp r1, r0 - mov r0, #0 - it eq - moveq r0, #1 - cmp r0, #0 - beq else_5 - mov r0, #3 - str r0, [sp, #40] - mov r0, #1 - str r0, [sp, #36] - b endif_5 -else_5: - ldr r0, [sp, #40] - mov r1, r0 - mov r0, #1 - sub r0, r1, r0 - str r0, [sp, #40] -endif_5: - add sp, sp, #4 - b endif_0 -else_0: -endif_0: - mov r0, #1 - ldr r1, =.Lstr0 - mov r2, #18 - mov r7, #4 - svc #0 - ldr r0, [sp, #40] - mov r4, r0 - ldr r1, =num_buf - add r1, r1, #16 - mov r2, #0 - cmp r4, #0 - bne print_int_loop_6 - mov r3, #48 - sub r1, r1, #1 - strb r3, [r1] - mov r2, #1 - b print_int_done_6 -print_int_loop_6: - mov r0, r4 - mov r3, #10 - sdiv r5, r0, r3 - mul r6, r5, r3 - sub r7, r0, r6 - add r7, r7, #48 - sub r1, r1, #1 - strb r7, [r1] - add r2, r2, #1 - mov r4, r5 - cmp r4, #0 - bne print_int_loop_6 -print_int_done_6: - mov r0, #1 - mov r1, r1 - mov r2, r2 - mov r7, #4 - svc #0 - mov r0, #1 - ldr r1, =newline - mov r2, #1 - mov r7, #4 - svc #0 - mov r0, #1 - ldr r1, =.Lstr1 - mov r2, #17 - mov r7, #4 - svc #0 - ldr r0, [sp, #32] - mov r4, r0 - ldr r1, =num_buf - add r1, r1, #16 - mov r2, #0 - cmp r4, #0 - bne print_int_loop_7 - mov r3, #48 - sub r1, r1, #1 - strb r3, [r1] - mov r2, #1 - b print_int_done_7 -print_int_loop_7: - mov r0, r4 - mov r3, #10 - sdiv r5, r0, r3 - mul r6, r5, r3 - sub r7, r0, r6 - add r7, r7, #48 - sub r1, r1, #1 - strb r7, [r1] - add r2, r2, #1 - mov r4, r5 - cmp r4, #0 - bne print_int_loop_7 -print_int_done_7: - mov r0, #1 - mov r1, r1 - mov r2, r2 - mov r7, #4 - svc #0 - mov r0, #1 - ldr r1, =newline - mov r2, #1 - mov r7, #4 - svc #0 - mov r0, #1 - ldr r1, =.Lstr2 - mov r2, #7 - mov r7, #4 - svc #0 - ldr r0, [sp, #36] - mov r4, r0 - ldr r1, =num_buf - add r1, r1, #16 - mov r2, #0 - cmp r4, #0 - bne print_int_loop_8 - mov r3, #48 - sub r1, r1, #1 - strb r3, [r1] - mov r2, #1 - b print_int_done_8 -print_int_loop_8: - mov r0, r4 - mov r3, #10 - sdiv r5, r0, r3 - mul r6, r5, r3 - sub r7, r0, r6 - add r7, r7, #48 - sub r1, r1, #1 - strb r7, [r1] - add r2, r2, #1 - mov r4, r5 - cmp r4, #0 - bne print_int_loop_8 -print_int_done_8: - mov r0, #1 - mov r1, r1 - mov r2, r2 - mov r7, #4 - svc #0 - mov r0, #1 - ldr r1, =newline - mov r2, #1 - mov r7, #4 - svc #0 - ldr r0, [sp, #32] - mov r7, #1 - svc #0 - -.size _start, .-_start - -.section .data -.Lstr0: - .ascii "g_countermeasure: " -.Lstr1: - .ascii "g_authenticated: " -.Lstr2: - .ascii "g_ptc: " -newline: - .ascii "\n" -num_buf: - .space 16 diff --git a/compiler/vpin/share/interface.h b/compiler/vpin/share/interface.h deleted file mode 100755 index 62ea22f..0000000 --- a/compiler/vpin/share/interface.h +++ /dev/null @@ -1,49 +0,0 @@ -/**************************************************************************/ -/* */ -/* This file is part of FISSC. */ -/* */ -/* you can redistribute it and/or modify it under the terms of the GNU */ -/* Lesser General Public License as published by the Free Software */ -/* Foundation, version 3.0. */ -/* */ -/* It is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ -/* GNU Lesser General Public License for more details. */ -/* */ -/* See the GNU Lesser General Public License version 3.0 */ -/* for more details (enclosed in the file LICENSE). */ -/* */ -/**************************************************************************/ - -/*$ - @authors = SERTIF Consortium - @feature = N/A - @target = N/A - @countermeasure = N/A - @difficulties = N/A - @purpose = shared interface for examples -*/ - -#ifndef H_INTERFACE -#define H_INTERFACE - -#include "types.h" - -/* defines what happens when a fault has been detected - implementation defined -*/ -void countermeasure(void); - -/* initializes global variables at the beginning of an example - implementation-defined - example-defined -*/ -void initialize(void); - -/* determines whether an attack is successful - example-defined -*/ -BOOL oracle(void); - -#endif // H_INTERFACE diff --git a/compiler/vpin/share/lazart.h b/compiler/vpin/share/lazart.h deleted file mode 100755 index cf68670..0000000 --- a/compiler/vpin/share/lazart.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef LAZART_API_HPP -#define LAZART_API_HPP - -#ifdef LAZART - -#include - -/*#define LAZART_ORACLE(oracle) \ - if(oracle) { \ - klee_assume(oracle); \ - } else { \ - klee_assume(0 != 0 ); \ - }*/ - -#define LAZART_ORACLE(oracle) klee_assume(oracle) - -#else -#define LAZART_ORACLE(oracle) -#endif // LAZART - -#endif // LAZART_API_HPP diff --git a/compiler/vpin/share/types.h b/compiler/vpin/share/types.h deleted file mode 100755 index 74bb38e..0000000 --- a/compiler/vpin/share/types.h +++ /dev/null @@ -1,29 +0,0 @@ -/**************************************************************************/ -/* */ -/* This file is part of FISSC. */ -/* */ -/* you can redistribute it and/or modify it under the terms of the GNU */ -/* Lesser General Public License as published by the Free Software */ -/* Foundation, version 3.0. */ -/* */ -/* It is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ -/* GNU Lesser General Public License for more details. */ -/* */ -/* See the GNU Lesser General Public License version 3.0 */ -/* for more details (enclosed in the file LICENSE). */ -/* */ -/**************************************************************************/ - -#ifndef H_TYPES -#define H_TYPES -typedef signed char SBYTE; -typedef unsigned char UBYTE; -typedef unsigned char BOOL; -typedef unsigned long ULONG; - -#define BOOL_TRUE 0xAA -#define BOOL_FALSE 0x55 - -#endif // H_TYPES diff --git a/compiler/vpin/verifypin.asm b/compiler/vpin/verifypin.asm deleted file mode 100644 index 204cb5b..0000000 --- a/compiler/vpin/verifypin.asm +++ /dev/null @@ -1,282 +0,0 @@ -.syntax unified -.thumb - -.section .text -.global _start -.type _start, %function - -_start: - sub sp, sp, #4 - mov r0, #0 - str r0, [sp] - sub sp, sp, #4 - mov r0, #3 - str r0, [sp] - sub sp, sp, #4 - mov r0, #0 - str r0, [sp] - sub sp, sp, #4 - mov r0, #1 - str r0, [sp] - sub sp, sp, #4 - mov r0, #2 - str r0, [sp] - sub sp, sp, #4 - mov r0, #3 - str r0, [sp] - sub sp, sp, #4 - mov r0, #4 - str r0, [sp] - sub sp, sp, #4 - mov r0, #0 - str r0, [sp] - sub sp, sp, #4 - mov r0, #0 - str r0, [sp] - sub sp, sp, #4 - mov r0, #0 - str r0, [sp] - sub sp, sp, #4 - mov r0, #0 - str r0, [sp] - mov r0, #0 - str r0, [sp, #32] - ldr r0, [sp, #36] - mov r1, r0 - mov r0, #0 - cmp r1, r0 - mov r0, #0 - it gt - movgt r0, #1 - cmp r0, #0 - beq else_0 - sub sp, sp, #4 - mov r0, #1 - str r0, [sp] - ldr r0, [sp, #16] - mov r1, r0 - ldr r0, [sp, #32] - cmp r1, r0 - mov r0, #0 - it ne - movne r0, #1 - cmp r0, #0 - beq else_1 - mov r0, #0 - str r0, [sp] - b endif_1 -else_1: -endif_1: - ldr r0, [sp, #12] - mov r1, r0 - ldr r0, [sp, #28] - cmp r1, r0 - mov r0, #0 - it ne - movne r0, #1 - cmp r0, #0 - beq else_2 - mov r0, #0 - str r0, [sp] - b endif_2 -else_2: -endif_2: - ldr r0, [sp, #8] - mov r1, r0 - ldr r0, [sp, #24] - cmp r1, r0 - mov r0, #0 - it ne - movne r0, #1 - cmp r0, #0 - beq else_3 - mov r0, #0 - str r0, [sp] - b endif_3 -else_3: -endif_3: - ldr r0, [sp, #4] - mov r1, r0 - ldr r0, [sp, #20] - cmp r1, r0 - mov r0, #0 - it ne - movne r0, #1 - cmp r0, #0 - beq else_4 - mov r0, #0 - str r0, [sp] - b endif_4 -else_4: -endif_4: - ldr r0, [sp, #0] - mov r1, r0 - mov r0, #1 - cmp r1, r0 - mov r0, #0 - it eq - moveq r0, #1 - cmp r0, #0 - beq else_5 - mov r0, #3 - str r0, [sp, #40] - mov r0, #1 - str r0, [sp, #36] - ldr r0, [sp, #36] - mov r7, #1 - svc #0 - b endif_5 -else_5: - ldr r0, [sp, #40] - mov r1, r0 - mov r0, #1 - sub r0, r1, r0 - str r0, [sp, #40] - mov r0, #0 - mov r7, #1 - svc #0 -endif_5: - add sp, sp, #4 - b endif_0 -else_0: -endif_0: - mov r0, #1 - ldr r1, =.Lstr0 - mov r2, #18 - mov r7, #4 - svc #0 - ldr r0, [sp, #40] - mov r4, r0 - ldr r1, =num_buf - add r1, r1, #16 - mov r2, #0 - cmp r4, #0 - bne print_int_loop_6 - mov r3, #48 - sub r1, r1, #1 - strb r3, [r1] - mov r2, #1 - b print_int_done_6 -print_int_loop_6: - mov r0, r4 - mov r3, #10 - sdiv r5, r0, r3 - mul r6, r5, r3 - sub r7, r0, r6 - add r7, r7, #48 - sub r1, r1, #1 - strb r7, [r1] - add r2, r2, #1 - mov r4, r5 - cmp r4, #0 - bne print_int_loop_6 -print_int_done_6: - mov r0, #1 - mov r1, r1 - mov r2, r2 - mov r7, #4 - svc #0 - mov r0, #1 - ldr r1, =newline - mov r2, #1 - mov r7, #4 - svc #0 - mov r0, #1 - ldr r1, =.Lstr1 - mov r2, #17 - mov r7, #4 - svc #0 - ldr r0, [sp, #32] - mov r4, r0 - ldr r1, =num_buf - add r1, r1, #16 - mov r2, #0 - cmp r4, #0 - bne print_int_loop_7 - mov r3, #48 - sub r1, r1, #1 - strb r3, [r1] - mov r2, #1 - b print_int_done_7 -print_int_loop_7: - mov r0, r4 - mov r3, #10 - sdiv r5, r0, r3 - mul r6, r5, r3 - sub r7, r0, r6 - add r7, r7, #48 - sub r1, r1, #1 - strb r7, [r1] - add r2, r2, #1 - mov r4, r5 - cmp r4, #0 - bne print_int_loop_7 -print_int_done_7: - mov r0, #1 - mov r1, r1 - mov r2, r2 - mov r7, #4 - svc #0 - mov r0, #1 - ldr r1, =newline - mov r2, #1 - mov r7, #4 - svc #0 - mov r0, #1 - ldr r1, =.Lstr2 - mov r2, #7 - mov r7, #4 - svc #0 - ldr r0, [sp, #36] - mov r4, r0 - ldr r1, =num_buf - add r1, r1, #16 - mov r2, #0 - cmp r4, #0 - bne print_int_loop_8 - mov r3, #48 - sub r1, r1, #1 - strb r3, [r1] - mov r2, #1 - b print_int_done_8 -print_int_loop_8: - mov r0, r4 - mov r3, #10 - sdiv r5, r0, r3 - mul r6, r5, r3 - sub r7, r0, r6 - add r7, r7, #48 - sub r1, r1, #1 - strb r7, [r1] - add r2, r2, #1 - mov r4, r5 - cmp r4, #0 - bne print_int_loop_8 -print_int_done_8: - mov r0, #1 - mov r1, r1 - mov r2, r2 - mov r7, #4 - svc #0 - mov r0, #1 - ldr r1, =newline - mov r2, #1 - mov r7, #4 - svc #0 - mov r0, #0 - mov r7, #1 - svc #0 - -.size _start, .-_start - -.section .data -.Lstr0: - .ascii "g_countermeasure: " -.Lstr1: - .ascii "g_authenticated: " -.Lstr2: - .ascii "g_ptc: " -newline: - .ascii "\n" -num_buf: - .space 16 diff --git a/compiler/vpin/verifypin.trv b/compiler/vpin/verifypin.trv deleted file mode 100644 index 904bbf5..0000000 --- a/compiler/vpin/verifypin.trv +++ /dev/null @@ -1,46 +0,0 @@ -func main() -> Integer { - let g_countermeasure : Integer = 0; - let ptc : Integer = 3; - let authenticated : Integer = 0; - let cardPin1 : Integer = 1; - let cardPin2 : Integer = 2; - let cardPin3 : Integer = 3; - let cardPin4 : Integer = 4; - let userPin1 : Integer = 0; - let userPin2 : Integer = 0; - let userPin3 : Integer = 0; - let userPin4 : Integer = 0; - - authenticated = 0; - - if ptc > 0 then { - let pinsEqual : Integer = 1; - if userPin1 != cardPin1 then { - pinsEqual = 0; - } - - if userPin2 != cardPin2 then { - pinsEqual = 0; - } - - if userPin3 != cardPin3 then { - pinsEqual = 0; - } - - if userPin4 != cardPin4 then { - pinsEqual = 0; - } - - if pinsEqual == 1 then { - ptc = 3; - authenticated = 1; - } else { - ptc = ptc - 1; - } - } - print("g_countermeasure: ", g_countermeasure); - print("g_authenticated: ", authenticated); - print("g_ptc: ", ptc); - - return authenticated; -} diff --git a/compiler/fissc/Basic/.Makefile.swp b/fissc/Basic/.Makefile.swp similarity index 100% rename from compiler/fissc/Basic/.Makefile.swp rename to fissc/Basic/.Makefile.swp diff --git a/compiler/fissc/Basic/Makefile b/fissc/Basic/Makefile similarity index 100% rename from compiler/fissc/Basic/Makefile rename to fissc/Basic/Makefile diff --git a/compiler/fissc/Basic/bin/crt-rsa b/fissc/Basic/bin/crt-rsa similarity index 100% rename from compiler/fissc/Basic/bin/crt-rsa rename to fissc/Basic/bin/crt-rsa diff --git a/compiler/fissc/Basic/include/commons.h b/fissc/Basic/include/commons.h similarity index 100% rename from compiler/fissc/Basic/include/commons.h rename to fissc/Basic/include/commons.h diff --git a/compiler/fissc/Basic/src/countermeasure.c b/fissc/Basic/src/countermeasure.c similarity index 100% rename from compiler/fissc/Basic/src/countermeasure.c rename to fissc/Basic/src/countermeasure.c diff --git a/compiler/fissc/Basic/src/crt-rsa.c b/fissc/Basic/src/crt-rsa.c similarity index 100% rename from compiler/fissc/Basic/src/crt-rsa.c rename to fissc/Basic/src/crt-rsa.c diff --git a/compiler/fissc/Basic/src/initialize.c b/fissc/Basic/src/initialize.c similarity index 100% rename from compiler/fissc/Basic/src/initialize.c rename to fissc/Basic/src/initialize.c diff --git a/compiler/fissc/Basic/src/main.c b/fissc/Basic/src/main.c similarity index 100% rename from compiler/fissc/Basic/src/main.c rename to fissc/Basic/src/main.c diff --git a/compiler/fissc/Basic/src/oracle.c b/fissc/Basic/src/oracle.c similarity index 100% rename from compiler/fissc/Basic/src/oracle.c rename to fissc/Basic/src/oracle.c diff --git a/compiler/fissc/crt-rsa.trv b/fissc/crt-rsa.trv similarity index 100% rename from compiler/fissc/crt-rsa.trv rename to fissc/crt-rsa.trv diff --git a/compiler/fissc/share/interface.h b/fissc/share/interface.h similarity index 100% rename from compiler/fissc/share/interface.h rename to fissc/share/interface.h diff --git a/compiler/fissc/share/lazart.h b/fissc/share/lazart.h similarity index 100% rename from compiler/fissc/share/lazart.h rename to fissc/share/lazart.h diff --git a/compiler/fissc/share/types.h b/fissc/share/types.h similarity index 100% rename from compiler/fissc/share/types.h rename to fissc/share/types.h diff --git a/compiler/fissc/verifypin.trv b/fissc/verifypin.trv similarity index 100% rename from compiler/fissc/verifypin.trv rename to fissc/verifypin.trv diff --git a/interpreter/out.s b/interpreter/out.s new file mode 100644 index 0000000..b934c95 --- /dev/null +++ b/interpreter/out.s @@ -0,0 +1,289 @@ +.syntax unified +.thumb + +.section .text +.global _start +.type _start, %function + +_start: + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + mov r0, #12345 + sub sp, sp, #4 + str r0, [sp, #0] + mov r0, #10000 + ldr r1, [sp, #0] + add sp, sp, #4 + mul r0, r1, r0 + sub sp, sp, #4 + str r0, [sp, #0] + mov r0, #6789 + ldr r1, [sp, #0] + add sp, sp, #4 + add r0, r1, r0 + str r0, [sp] + sub sp, sp, #4 + mov r0, #5381 + str r0, [sp] + sub sp, sp, #4 + mov r0, #33 + str r0, [sp] + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + mov r0, #104 + sub sp, sp, #4 + str r0, [sp, #0] + mov r0, #1000 + ldr r1, [sp, #0] + add sp, sp, #4 + mul r0, r1, r0 + sub sp, sp, #4 + str r0, [sp, #0] + mov r0, #729 + ldr r1, [sp, #0] + add sp, sp, #4 + add r0, r1, r0 + str r0, [sp] + sub sp, sp, #4 + ldr r0, [sp, #16] + str r0, [sp] + sub sp, sp, #4 + mov r0, #0 + str r0, [sp] + ldr r0, [sp, #4] + sub sp, sp, #4 + str r0, [sp, #0] + mov r0, #0 + ldr r1, [sp, #0] + add sp, sp, #4 + cmp r1, r0 + mov r0, #0 + it eq + moveq r0, #1 + cmp r0, #0 + beq else_0 + mov r0, #7 + str r0, [sp, #4] + b endif_0 +else_0: +endif_0: +while_1: + ldr r0, [sp, #4] + sub sp, sp, #4 + str r0, [sp, #0] + mov r0, #0 + ldr r1, [sp, #0] + add sp, sp, #4 + cmp r1, r0 + mov r0, #0 + it gt + movgt r0, #1 + cmp r0, #0 + beq end_while_1 + ldr r0, [sp, #4] + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #8] + sub sp, sp, #4 + str r0, [sp, #0] + mov r0, #100 + ldr r1, [sp, #0] + add sp, sp, #4 + sdiv r0, r1, r0 + sub sp, sp, #4 + str r0, [sp, #0] + mov r0, #100 + ldr r1, [sp, #0] + add sp, sp, #4 + mul r0, r1, r0 + ldr r1, [sp, #0] + add sp, sp, #4 + sub r0, r1, r0 + str r0, [sp] + ldr r0, [sp, #16] + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #16] + ldr r1, [sp, #0] + add sp, sp, #4 + mul r0, r1, r0 + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #4] + ldr r1, [sp, #0] + add sp, sp, #4 + add r0, r1, r0 + str r0, [sp, #16] + ldr r0, [sp, #16] + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #20] + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #16] + ldr r1, [sp, #0] + add sp, sp, #4 + sdiv r0, r1, r0 + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #16] + ldr r1, [sp, #0] + add sp, sp, #4 + mul r0, r1, r0 + ldr r1, [sp, #0] + add sp, sp, #4 + sub r0, r1, r0 + str r0, [sp, #16] + ldr r0, [sp, #4] + sub sp, sp, #4 + str r0, [sp, #0] + mov r0, #100 + ldr r1, [sp, #0] + add sp, sp, #4 + sdiv r0, r1, r0 + str r0, [sp, #4] + b while_1 +end_while_1: + ldr r0, [sp, #16] + sub sp, sp, #4 + str r0, [sp, #0] + mov r0, #0 + ldr r1, [sp, #0] + add sp, sp, #4 + cmp r1, r0 + mov r0, #0 + it lt + movlt r0, #1 + cmp r0, #0 + beq else_2 + ldr r0, [sp, #16] + sub sp, sp, #4 + str r0, [sp, #0] + ldr r0, [sp, #12] + ldr r1, [sp, #0] + add sp, sp, #4 + add r0, r1, r0 + str r0, [sp, #16] + b endif_2 +else_2: +endif_2: + ldr r0, [sp, #16] + mov r4, r0 + ldr r1, =num_buf + add r1, r1, #16 + mov r2, #0 + cmp r4, #0 + bne print_int_loop_3 + mov r3, #48 + sub r1, r1, #1 + strb r3, [r1] + mov r2, #1 + b print_int_done_3 +print_int_loop_3: + mov r0, r4 + mov r3, #10 + sdiv r5, r0, r3 + mul r6, r5, r3 + sub r7, r0, r6 + add r7, r7, #48 + sub r1, r1, #1 + strb r7, [r1] + add r2, r2, #1 + mov r4, r5 + cmp r4, #0 + bne print_int_loop_3 +print_int_done_3: + mov r0, #1 + mov r1, r1 + mov r2, r2 + mov r7, #4 + svc #0 + mov r0, #1 + ldr r1, =newline + mov r2, #1 + mov r7, #4 + svc #0 + ldr r0, [sp, #16] + mov r7, #1 + svc #0 + +.size _start, .-_start + +.section .data +newline: + .ascii "\n" +num_buf: + .space 16 +_metadata: + .word 0x10000000 @ 0 + .word 0xa+1 + .word 0xb+3 + .word 0x0 @ [r0] + .word 0x00000001 @ message + .word 0x10000000 @ 1 + .word 0xa+4 + .word 0xb+17 + .word 0x0 @ [r0] + .word 0x00000001 @ message + .word 0x10000000 @ 2 + .word 0xa+18 + .word 0xb+20 + .word 0x0 @ [r0] + .word 0x00000001 @ h + .word 0x10000000 @ 3 + .word 0xa+21 + .word 0xb+23 + .word 0x0 @ [r0] + .word 0x00000001 @ multiplier + .word 0x10000000 @ 4 + .word 0xa+24 + .word 0xb+26 + .word 0x0 @ [r0] + .word 0x00000001 @ prime_modulo + .word 0x10000000 @ 5 + .word 0xa+27 + .word 0xb+40 + .word 0x0 @ [r0] + .word 0x00000001 @ prime_modulo + .word 0x10000000 @ 6 + .word 0xa+41 + .word 0xb+43 + .word 0x0 @ [r0] + .word 0x00000001 @ temp_msg + .word 0x10000000 @ 7 + .word 0xa+44 + .word 0xb+46 + .word 0x0 @ [r0] + .word 0x00000001 @ chunk + .word 0x10000000 @ 8 + .word 0xa+59 + .word 0xb+60 + .word 0x0 @ [r0] + .word 0x00000001 @ temp_msg + .word 0x10000000 @ 9 + .word 0xa+77 + .word 0xb+96 + .word 0x0 @ [r0] + .word 0x00000001 @ chunk + .word 0x10000000 @ 10 + .word 0xa+97 + .word 0xb+110 + .word 0x0 @ [r0] + .word 0x00000001 @ h + .word 0x10000000 @ 11 + .word 0xa+111 + .word 0xb+130 + .word 0x0 @ [r0] + .word 0x00000001 @ h + .word 0x10000000 @ 12 + .word 0xa+131 + .word 0xb+138 + .word 0x0 @ [r0] + .word 0x00000001 @ temp_msg + .word 0x10000000 @ 13 + .word 0xa+153 + .word 0xb+160 + .word 0x0 @ [r0] + .word 0x00000001 @ h diff --git a/test_results/compiled_test_files/pinny.hard.s b/test_results/compiled_test_files/pinny.hard.s deleted file mode 100644 index c81165a..0000000 --- a/test_results/compiled_test_files/pinny.hard.s +++ /dev/null @@ -1,280 +0,0 @@ -.syntax unified -.thumb - -.section .text -.global _start -.type _start, %function - -_start: - mov r9, #0 - mov r10, #1 - sub sp, sp, #4 - mov r0, #0 - str r0, [sp] - add r9, r9, #1 - cmp r9, #1 - bne countermeasure - sub sp, sp, #4 - mov r0, #1 - str r0, [sp] - add r9, r9, #1 - cmp r9, #2 - bne countermeasure - sub sp, sp, #4 - mov r0, #2 - str r0, [sp] - add r9, r9, #1 - cmp r9, #3 - bne countermeasure - sub sp, sp, #4 - mov r0, #3 - str r0, [sp] - add r9, r9, #1 - cmp r9, #4 - bne countermeasure - sub sp, sp, #4 - mov r0, #4 - str r0, [sp] - add r9, r9, #1 - cmp r9, #5 - bne countermeasure - sub sp, sp, #4 - mov r0, #0 - str r0, [sp] - add r9, r9, #1 - cmp r9, #6 - bne countermeasure - sub sp, sp, #4 - mov r0, #0 - str r0, [sp] - add r9, r9, #1 - cmp r9, #7 - bne countermeasure - sub sp, sp, #4 - mov r0, #0 - str r0, [sp] - add r9, r9, #1 - cmp r9, #8 - bne countermeasure - sub sp, sp, #4 - mov r0, #0 - str r0, [sp] - add r9, r9, #1 - cmp r9, #9 - bne countermeasure - sub sp, sp, #4 - mov r0, #0 - str r0, [sp] - add r9, r9, #1 - cmp r9, #10 - bne countermeasure - ldr r0, [sp, #16] - mov r1, r0 - ldr r0, [sp, #32] - cmp r1, r0 - mov r0, #0 - it eq - moveq r0, #1 - cmp r0, #0 - beq else_0 - add r9, r9, #1 - cmp r9, #11 - bne countermeasure - ldr r0, [sp, #0] - mov r1, r0 - mov r0, #1 - add r0, r1, r0 - str r0, [sp] - add r9, r9, #1 - cmp r9, #12 - bne countermeasure - b endif_0 -else_0: -endif_0: - ldr r0, [sp, #12] - mov r1, r0 - ldr r0, [sp, #28] - cmp r1, r0 - mov r0, #0 - it eq - moveq r0, #1 - cmp r0, #0 - beq else_1 - add r9, r9, #1 - cmp r9, #13 - bne countermeasure - ldr r0, [sp, #0] - mov r1, r0 - mov r0, #1 - add r0, r1, r0 - str r0, [sp] - add r9, r9, #1 - cmp r9, #14 - bne countermeasure - b endif_1 -else_1: -endif_1: - ldr r0, [sp, #8] - mov r1, r0 - ldr r0, [sp, #24] - cmp r1, r0 - mov r0, #0 - it eq - moveq r0, #1 - cmp r0, #0 - beq else_2 - add r9, r9, #1 - cmp r9, #15 - bne countermeasure - ldr r0, [sp, #0] - mov r1, r0 - mov r0, #1 - add r0, r1, r0 - str r0, [sp] - add r9, r9, #1 - cmp r9, #16 - bne countermeasure - b endif_2 -else_2: -endif_2: - ldr r0, [sp, #4] - mov r1, r0 - ldr r0, [sp, #20] - cmp r1, r0 - mov r0, #0 - it eq - moveq r0, #1 - cmp r0, #0 - beq else_3 - add r9, r9, #1 - cmp r9, #17 - bne countermeasure - ldr r0, [sp, #0] - mov r1, r0 - mov r0, #1 - add r0, r1, r0 - str r0, [sp] - add r9, r9, #1 - cmp r9, #18 - bne countermeasure - b endif_3 -else_3: -endif_3: - ldr r0, [sp, #0] - mov r1, r0 - mov r0, #4 - cmp r1, r0 - mov r0, #0 - it eq - moveq r0, #1 - cmp r0, #0 - beq else_4 - add r9, r9, #1 - cmp r9, #19 - bne countermeasure - mov r0, #1 - str r0, [sp, #36] - add r9, r9, #1 - cmp r9, #20 - bne countermeasure - b endif_4 -else_4: -endif_4: - ldr r0, [sp, #36] - mov r7, #1 - svc #0 -countermeasure: - mov r0, #1 - ldr r1, =.Lstr0 - mov r2, #14 - mov r7, #4 - svc #0 - mov r0, #77 - mov r7, #1 - svc #0 - -.size _start, .-_start - -.section .data -.Lstr0: - .ascii "COUNTERMEASURE" -step_counter: - .word 0 -fault_msg: - .ascii "Control flow violation detected\n" -_metadata: - .word 0x10000000 @ 0 - .word 0xa+3 - .word 0xb+8 - .word 0x0 @ [r0] - .word 0x00000001 @ authenticated - .word 0x10000000 @ 1 - .word 0xa+9 - .word 0xb+14 - .word 0x0 @ [r0] - .word 0x00000001 @ cardPin1 - .word 0x10000000 @ 2 - .word 0xa+15 - .word 0xb+20 - .word 0x0 @ [r0] - .word 0x00000001 @ cardPin2 - .word 0x10000000 @ 3 - .word 0xa+21 - .word 0xb+26 - .word 0x0 @ [r0] - .word 0x00000001 @ cardPin3 - .word 0x10000000 @ 4 - .word 0xa+27 - .word 0xb+32 - .word 0x0 @ [r0] - .word 0x00000001 @ cardPin4 - .word 0x10000000 @ 5 - .word 0xa+33 - .word 0xb+38 - .word 0x0 @ [r0] - .word 0x00000001 @ userPin1 - .word 0x10000000 @ 6 - .word 0xa+39 - .word 0xb+44 - .word 0x0 @ [r0] - .word 0x00000001 @ userPin2 - .word 0x10000000 @ 7 - .word 0xa+45 - .word 0xb+50 - .word 0x0 @ [r0] - .word 0x00000001 @ userPin3 - .word 0x10000000 @ 8 - .word 0xa+51 - .word 0xb+56 - .word 0x0 @ [r0] - .word 0x00000001 @ userPin4 - .word 0x10000000 @ 9 - .word 0xa+57 - .word 0xb+62 - .word 0x0 @ [r0] - .word 0x00000001 @ pinsEqual - .word 0x10000000 @ 10 - .word 0xa+75 - .word 0xb+82 - .word 0x0 @ [r0,r1] - .word 0x00000001 @ pinsEqual - .word 0x10000000 @ 11 - .word 0xa+98 - .word 0xb+105 - .word 0x0 @ [r0,r1] - .word 0x00000001 @ pinsEqual - .word 0x10000000 @ 12 - .word 0xa+121 - .word 0xb+128 - .word 0x0 @ [r0,r1] - .word 0x00000001 @ pinsEqual - .word 0x10000000 @ 13 - .word 0xa+144 - .word 0xb+151 - .word 0x0 @ [r0,r1] - .word 0x00000001 @ pinsEqual - .word 0x10000000 @ 14 - .word 0xa+167 - .word 0xb+171 - .word 0x0 @ [r0] - .word 0x00000001 @ authenticated diff --git a/test_results/compiled_test_files/pinny.hard.wh b/test_results/compiled_test_files/pinny.hard.wh deleted file mode 100644 index a74a5ef..0000000 --- a/test_results/compiled_test_files/pinny.hard.wh +++ /dev/null @@ -1,180 +0,0 @@ -ui32 res; -ui32 stmt; -ui32 bit_shift; -ui32 flip_mask; - -fn main(ui32 stmt, ui32 flip_mask) -> ui32 { - ui32 authenticated; - ui32 cardPin1; - ui32 cardPin2; - ui32 cardPin3; - ui32 cardPin4; - ui32 userPin1; - ui32 userPin2; - ui32 userPin3; - ui32 userPin4; - ui32 pinsEqual; - ui32 step_counter; - step_counter = (0 as ui32); - authenticated = (0 as ui32); - if (stmt == (0 as ui32)) { - authenticated = (0 as ui32) ^ flip_mask; - } - step_counter++; - if (step_counter != (1 as ui32)) { - return (77 as ui32); - } - cardPin1 = (1 as ui32); - if (stmt == (1 as ui32)) { - cardPin1 = (1 as ui32) ^ flip_mask; - } - step_counter++; - if (step_counter != (2 as ui32)) { - return (77 as ui32); - } - cardPin2 = (2 as ui32); - if (stmt == (2 as ui32)) { - cardPin2 = (2 as ui32) ^ flip_mask; - } - step_counter++; - if (step_counter != (3 as ui32)) { - return (77 as ui32); - } - cardPin3 = (3 as ui32); - if (stmt == (3 as ui32)) { - cardPin3 = (3 as ui32) ^ flip_mask; - } - step_counter++; - if (step_counter != (4 as ui32)) { - return (77 as ui32); - } - cardPin4 = (4 as ui32); - if (stmt == (4 as ui32)) { - cardPin4 = (4 as ui32) ^ flip_mask; - } - step_counter++; - if (step_counter != (5 as ui32)) { - return (77 as ui32); - } - userPin1 = (0 as ui32); - if (stmt == (5 as ui32)) { - userPin1 = (0 as ui32) ^ flip_mask; - } - step_counter++; - if (step_counter != (6 as ui32)) { - return (77 as ui32); - } - userPin2 = (0 as ui32); - if (stmt == (6 as ui32)) { - userPin2 = (0 as ui32) ^ flip_mask; - } - step_counter++; - if (step_counter != (7 as ui32)) { - return (77 as ui32); - } - userPin3 = (0 as ui32); - if (stmt == (7 as ui32)) { - userPin3 = (0 as ui32) ^ flip_mask; - } - step_counter++; - if (step_counter != (8 as ui32)) { - return (77 as ui32); - } - userPin4 = (0 as ui32); - if (stmt == (8 as ui32)) { - userPin4 = (0 as ui32) ^ flip_mask; - } - step_counter++; - if (step_counter != (9 as ui32)) { - return (77 as ui32); - } - pinsEqual = (0 as ui32); - if (stmt == (9 as ui32)) { - pinsEqual = (0 as ui32) ^ flip_mask; - } - step_counter++; - if (step_counter != (10 as ui32)) { - return (77 as ui32); - } - if ( userPin1 == cardPin1) { - step_counter++; - if (step_counter != (11 as ui32)) { - return (77 as ui32); - } - pinsEqual = pinsEqual + (1 as ui32); - if (stmt == (10 as ui32)) { - pinsEqual = pinsEqual + (1 as ui32) ^ flip_mask; - } - step_counter++; - if (step_counter != (12 as ui32)) { - return (77 as ui32); - } - } - if ( userPin2 == cardPin2) { - step_counter++; - if (step_counter != (13 as ui32)) { - return (77 as ui32); - } - pinsEqual = pinsEqual + (1 as ui32); - if (stmt == (11 as ui32)) { - pinsEqual = pinsEqual + (1 as ui32) ^ flip_mask; - } - step_counter++; - if (step_counter != (14 as ui32)) { - return (77 as ui32); - } - } - if ( userPin3 == cardPin3) { - step_counter++; - if (step_counter != (15 as ui32)) { - return (77 as ui32); - } - pinsEqual = pinsEqual + (1 as ui32); - if (stmt == (12 as ui32)) { - pinsEqual = pinsEqual + (1 as ui32) ^ flip_mask; - } - step_counter++; - if (step_counter != (16 as ui32)) { - return (77 as ui32); - } - } - if ( userPin4 == cardPin4) { - step_counter++; - if (step_counter != (17 as ui32)) { - return (77 as ui32); - } - pinsEqual = pinsEqual + (1 as ui32); - if (stmt == (13 as ui32)) { - pinsEqual = pinsEqual + (1 as ui32) ^ flip_mask; - } - step_counter++; - if (step_counter != (18 as ui32)) { - return (77 as ui32); - } - } - if ( pinsEqual == (4 as ui32)) { - step_counter++; - if (step_counter != (19 as ui32)) { - return (77 as ui32); - } - authenticated = (1 as ui32); - if (stmt == (14 as ui32)) { - authenticated = (1 as ui32) ^ flip_mask; - } - step_counter++; - if (step_counter != (20 as ui32)) { - return (77 as ui32); - } - } - return (authenticated as ui32); -} -stmt = (? as ui32); -bit_shift = (? as ui32); -assume (bit_shift <= (31 as ui32)); -assume (bit_shift >= (0 as ui32)); -assume (stmt >= (0 as ui32)); -assume (stmt <= (14 as ui32)); -flip_mask = ((1 as ui32) << bit_shift); - -res = main(stmt, flip_mask); -assert(res == (0 as ui32)); diff --git a/test_results/compiled_test_files/pinny.s b/test_results/compiled_test_files/pinny.s deleted file mode 100644 index c6aa62b..0000000 --- a/test_results/compiled_test_files/pinny.s +++ /dev/null @@ -1,201 +0,0 @@ -.syntax unified -.thumb - -.section .text -.global _start -.type _start, %function - -_start: - sub sp, sp, #4 - mov r0, #0 - str r0, [sp] - sub sp, sp, #4 - mov r0, #1 - str r0, [sp] - sub sp, sp, #4 - mov r0, #2 - str r0, [sp] - sub sp, sp, #4 - mov r0, #3 - str r0, [sp] - sub sp, sp, #4 - mov r0, #4 - str r0, [sp] - sub sp, sp, #4 - mov r0, #0 - str r0, [sp] - sub sp, sp, #4 - mov r0, #0 - str r0, [sp] - sub sp, sp, #4 - mov r0, #0 - str r0, [sp] - sub sp, sp, #4 - mov r0, #0 - str r0, [sp] - sub sp, sp, #4 - mov r0, #0 - str r0, [sp] - ldr r0, [sp, #16] - mov r1, r0 - ldr r0, [sp, #32] - cmp r1, r0 - mov r0, #0 - it eq - moveq r0, #1 - cmp r0, #0 - beq else_0 - ldr r0, [sp, #0] - mov r1, r0 - mov r0, #1 - add r0, r1, r0 - str r0, [sp] - b endif_0 -else_0: -endif_0: - ldr r0, [sp, #12] - mov r1, r0 - ldr r0, [sp, #28] - cmp r1, r0 - mov r0, #0 - it eq - moveq r0, #1 - cmp r0, #0 - beq else_1 - ldr r0, [sp, #0] - mov r1, r0 - mov r0, #1 - add r0, r1, r0 - str r0, [sp] - b endif_1 -else_1: -endif_1: - ldr r0, [sp, #8] - mov r1, r0 - ldr r0, [sp, #24] - cmp r1, r0 - mov r0, #0 - it eq - moveq r0, #1 - cmp r0, #0 - beq else_2 - ldr r0, [sp, #0] - mov r1, r0 - mov r0, #1 - add r0, r1, r0 - str r0, [sp] - b endif_2 -else_2: -endif_2: - ldr r0, [sp, #4] - mov r1, r0 - ldr r0, [sp, #20] - cmp r1, r0 - mov r0, #0 - it eq - moveq r0, #1 - cmp r0, #0 - beq else_3 - ldr r0, [sp, #0] - mov r1, r0 - mov r0, #1 - add r0, r1, r0 - str r0, [sp] - b endif_3 -else_3: -endif_3: - ldr r0, [sp, #0] - mov r1, r0 - mov r0, #4 - cmp r1, r0 - mov r0, #0 - it eq - moveq r0, #1 - cmp r0, #0 - beq else_4 - mov r0, #1 - str r0, [sp, #36] - b endif_4 -else_4: -endif_4: - ldr r0, [sp, #36] - mov r7, #1 - svc #0 - -.size _start, .-_start -_metadata: - .word 0x10000000 @ 0 - .word 0xa+1 - .word 0xb+3 - .word 0x0 @ [r0] - .word 0x00000001 @ authenticated - .word 0x10000000 @ 1 - .word 0xa+4 - .word 0xb+6 - .word 0x0 @ [r0] - .word 0x00000001 @ cardPin1 - .word 0x10000000 @ 2 - .word 0xa+7 - .word 0xb+9 - .word 0x0 @ [r0] - .word 0x00000001 @ cardPin2 - .word 0x10000000 @ 3 - .word 0xa+10 - .word 0xb+12 - .word 0x0 @ [r0] - .word 0x00000001 @ cardPin3 - .word 0x10000000 @ 4 - .word 0xa+13 - .word 0xb+15 - .word 0x0 @ [r0] - .word 0x00000001 @ cardPin4 - .word 0x10000000 @ 5 - .word 0xa+16 - .word 0xb+18 - .word 0x0 @ [r0] - .word 0x00000001 @ userPin1 - .word 0x10000000 @ 6 - .word 0xa+19 - .word 0xb+21 - .word 0x0 @ [r0] - .word 0x00000001 @ userPin2 - .word 0x10000000 @ 7 - .word 0xa+22 - .word 0xb+24 - .word 0x0 @ [r0] - .word 0x00000001 @ userPin3 - .word 0x10000000 @ 8 - .word 0xa+25 - .word 0xb+27 - .word 0x0 @ [r0] - .word 0x00000001 @ userPin4 - .word 0x10000000 @ 9 - .word 0xa+28 - .word 0xb+30 - .word 0x0 @ [r0] - .word 0x00000001 @ pinsEqual - .word 0x10000000 @ 10 - .word 0xa+40 - .word 0xb+44 - .word 0x0 @ [r0,r1] - .word 0x00000001 @ pinsEqual - .word 0x10000000 @ 11 - .word 0xa+57 - .word 0xb+61 - .word 0x0 @ [r0,r1] - .word 0x00000001 @ pinsEqual - .word 0x10000000 @ 12 - .word 0xa+74 - .word 0xb+78 - .word 0x0 @ [r0,r1] - .word 0x00000001 @ pinsEqual - .word 0x10000000 @ 13 - .word 0xa+91 - .word 0xb+95 - .word 0x0 @ [r0,r1] - .word 0x00000001 @ pinsEqual - .word 0x10000000 @ 14 - .word 0xa+108 - .word 0xb+109 - .word 0x0 @ [r0] - .word 0x00000001 @ authenticated diff --git a/test_results/compiled_test_files/pinny.wh b/test_results/compiled_test_files/pinny.wh deleted file mode 100644 index d2765e9..0000000 --- a/test_results/compiled_test_files/pinny.wh +++ /dev/null @@ -1,98 +0,0 @@ -ui32 res; -ui32 stmt; -ui32 bit_shift; -ui32 flip_mask; - -fn main(ui32 stmt, ui32 flip_mask) -> ui32 { - ui32 authenticated; - ui32 cardPin1; - ui32 cardPin2; - ui32 cardPin3; - ui32 cardPin4; - ui32 userPin1; - ui32 userPin2; - ui32 userPin3; - ui32 userPin4; - ui32 pinsEqual; - authenticated = (0 as ui32); - if (stmt == (0 as ui32)) { - authenticated = (0 as ui32) ^ flip_mask; - } - cardPin1 = (1 as ui32); - if (stmt == (1 as ui32)) { - cardPin1 = (1 as ui32) ^ flip_mask; - } - cardPin2 = (2 as ui32); - if (stmt == (2 as ui32)) { - cardPin2 = (2 as ui32) ^ flip_mask; - } - cardPin3 = (3 as ui32); - if (stmt == (3 as ui32)) { - cardPin3 = (3 as ui32) ^ flip_mask; - } - cardPin4 = (4 as ui32); - if (stmt == (4 as ui32)) { - cardPin4 = (4 as ui32) ^ flip_mask; - } - userPin1 = (0 as ui32); - if (stmt == (5 as ui32)) { - userPin1 = (0 as ui32) ^ flip_mask; - } - userPin2 = (0 as ui32); - if (stmt == (6 as ui32)) { - userPin2 = (0 as ui32) ^ flip_mask; - } - userPin3 = (0 as ui32); - if (stmt == (7 as ui32)) { - userPin3 = (0 as ui32) ^ flip_mask; - } - userPin4 = (0 as ui32); - if (stmt == (8 as ui32)) { - userPin4 = (0 as ui32) ^ flip_mask; - } - pinsEqual = (0 as ui32); - if (stmt == (9 as ui32)) { - pinsEqual = (0 as ui32) ^ flip_mask; - } - if ( userPin1 == cardPin1) { - pinsEqual = pinsEqual + (1 as ui32); - if (stmt == (10 as ui32)) { - pinsEqual = pinsEqual + (1 as ui32) ^ flip_mask; - } - } - if ( userPin2 == cardPin2) { - pinsEqual = pinsEqual + (1 as ui32); - if (stmt == (11 as ui32)) { - pinsEqual = pinsEqual + (1 as ui32) ^ flip_mask; - } - } - if ( userPin3 == cardPin3) { - pinsEqual = pinsEqual + (1 as ui32); - if (stmt == (12 as ui32)) { - pinsEqual = pinsEqual + (1 as ui32) ^ flip_mask; - } - } - if ( userPin4 == cardPin4) { - pinsEqual = pinsEqual + (1 as ui32); - if (stmt == (13 as ui32)) { - pinsEqual = pinsEqual + (1 as ui32) ^ flip_mask; - } - } - if ( pinsEqual == (4 as ui32)) { - authenticated = (1 as ui32); - if (stmt == (14 as ui32)) { - authenticated = (1 as ui32) ^ flip_mask; - } - } - return (authenticated as ui32); -} -stmt = (? as ui32); -bit_shift = (? as ui32); -assume (bit_shift <= (31 as ui32)); -assume (bit_shift >= (0 as ui32)); -assume (stmt >= (0 as ui32)); -assume (stmt <= (14 as ui32)); -flip_mask = ((1 as ui32) << bit_shift); - -res = main(stmt, flip_mask); -assert(res == (0 as ui32)); diff --git a/test_results/edited_test_files/pinny.edited.hard.s b/test_results/edited_test_files/pinny.edited.hard.s deleted file mode 100644 index dc62604..0000000 --- a/test_results/edited_test_files/pinny.edited.hard.s +++ /dev/null @@ -1,316 +0,0 @@ -.syntax unified -.thumb - -.section .text -.global _start -.type _start, %function - -_start: - mov r9, #0 - mov r10, #1 - sub sp, sp, #4 - mov r0, #0 - str r0, [sp] - add r9, r9, #1 - cmp r9, #1 - bne countermeasure - ldr r0, [sp, #0] - mov r1, r0 - mov r0, #0 - cmp r1, r0 - mov r0, #0 - it ne - movne r0, #1 - cmp r0, #0 - beq else_0 - add r9, r9, #1 - cmp r9, #2 - bne countermeasure - mov r0, #77 - mov r7, #1 - svc #0 - b endif_0 -else_0: -endif_0: - sub sp, sp, #4 - mov r0, #1 - str r0, [sp] - add r9, r9, #1 - cmp r9, #3 - bne countermeasure - sub sp, sp, #4 - mov r0, #2 - str r0, [sp] - add r9, r9, #1 - cmp r9, #4 - bne countermeasure - sub sp, sp, #4 - mov r0, #3 - str r0, [sp] - add r9, r9, #1 - cmp r9, #5 - bne countermeasure - sub sp, sp, #4 - mov r0, #4 - str r0, [sp] - add r9, r9, #1 - cmp r9, #6 - bne countermeasure - sub sp, sp, #4 - mov r0, #0 - str r0, [sp] - add r9, r9, #1 - cmp r9, #7 - bne countermeasure - sub sp, sp, #4 - mov r0, #0 - str r0, [sp] - add r9, r9, #1 - cmp r9, #8 - bne countermeasure - sub sp, sp, #4 - mov r0, #0 - str r0, [sp] - add r9, r9, #1 - cmp r9, #9 - bne countermeasure - sub sp, sp, #4 - mov r0, #0 - str r0, [sp] - add r9, r9, #1 - cmp r9, #10 - bne countermeasure - sub sp, sp, #4 - mov r0, #0 - str r0, [sp] - add r9, r9, #1 - cmp r9, #11 - bne countermeasure - ldr r0, [sp, #0] - mov r1, r0 - mov r0, #0 - cmp r1, r0 - mov r0, #0 - it ne - movne r0, #1 - cmp r0, #0 - beq else_1 - add r9, r9, #1 - cmp r9, #12 - bne countermeasure - mov r0, #77 - mov r7, #1 - svc #0 - b endif_1 -else_1: -endif_1: - ldr r0, [sp, #16] - mov r1, r0 - ldr r0, [sp, #32] - cmp r1, r0 - mov r0, #0 - it eq - moveq r0, #1 - cmp r0, #0 - beq else_2 - add r9, r9, #1 - cmp r9, #13 - bne countermeasure - ldr r0, [sp, #0] - mov r1, r0 - mov r0, #1 - add r0, r1, r0 - str r0, [sp] - add r9, r9, #1 - cmp r9, #14 - bne countermeasure - b endif_2 -else_2: -endif_2: - ldr r0, [sp, #12] - mov r1, r0 - ldr r0, [sp, #28] - cmp r1, r0 - mov r0, #0 - it eq - moveq r0, #1 - cmp r0, #0 - beq else_3 - add r9, r9, #1 - cmp r9, #15 - bne countermeasure - ldr r0, [sp, #0] - mov r1, r0 - mov r0, #1 - add r0, r1, r0 - str r0, [sp] - add r9, r9, #1 - cmp r9, #16 - bne countermeasure - b endif_3 -else_3: -endif_3: - ldr r0, [sp, #8] - mov r1, r0 - ldr r0, [sp, #24] - cmp r1, r0 - mov r0, #0 - it eq - moveq r0, #1 - cmp r0, #0 - beq else_4 - add r9, r9, #1 - cmp r9, #17 - bne countermeasure - ldr r0, [sp, #0] - mov r1, r0 - mov r0, #1 - add r0, r1, r0 - str r0, [sp] - add r9, r9, #1 - cmp r9, #18 - bne countermeasure - b endif_4 -else_4: -endif_4: - ldr r0, [sp, #4] - mov r1, r0 - ldr r0, [sp, #20] - cmp r1, r0 - mov r0, #0 - it eq - moveq r0, #1 - cmp r0, #0 - beq else_5 - add r9, r9, #1 - cmp r9, #19 - bne countermeasure - ldr r0, [sp, #0] - mov r1, r0 - mov r0, #1 - add r0, r1, r0 - str r0, [sp] - add r9, r9, #1 - cmp r9, #20 - bne countermeasure - b endif_5 -else_5: -endif_5: - ldr r0, [sp, #0] - mov r1, r0 - mov r0, #4 - cmp r1, r0 - mov r0, #0 - it eq - moveq r0, #1 - cmp r0, #0 - beq else_6 - add r9, r9, #1 - cmp r9, #21 - bne countermeasure - mov r0, #1 - str r0, [sp, #36] - add r9, r9, #1 - cmp r9, #22 - bne countermeasure - b endif_6 -else_6: -endif_6: - ldr r0, [sp, #36] - mov r7, #1 - svc #0 -countermeasure: - mov r0, #1 - ldr r1, =.Lstr0 - mov r2, #14 - mov r7, #4 - svc #0 - mov r0, #77 - mov r7, #1 - svc #0 - -.size _start, .-_start - -.section .data -.Lstr0: - .ascii "COUNTERMEASURE" -step_counter: - .word 0 -fault_msg: - .ascii "Control flow violation detected\n" -_metadata: - .word 0x10000000 @ 0 - .word 0xa+3 - .word 0xb+8 - .word 0x0 @ [r0] - .word 0x00000001 @ authenticated - .word 0x10000000 @ 1 - .word 0xa+27 - .word 0xb+32 - .word 0x0 @ [r0] - .word 0x00000001 @ cardPin1 - .word 0x10000000 @ 2 - .word 0xa+33 - .word 0xb+38 - .word 0x0 @ [r0] - .word 0x00000001 @ cardPin2 - .word 0x10000000 @ 3 - .word 0xa+39 - .word 0xb+44 - .word 0x0 @ [r0] - .word 0x00000001 @ cardPin3 - .word 0x10000000 @ 4 - .word 0xa+45 - .word 0xb+50 - .word 0x0 @ [r0] - .word 0x00000001 @ cardPin4 - .word 0x10000000 @ 5 - .word 0xa+51 - .word 0xb+56 - .word 0x0 @ [r0] - .word 0x00000001 @ userPin1 - .word 0x10000000 @ 6 - .word 0xa+57 - .word 0xb+62 - .word 0x0 @ [r0] - .word 0x00000001 @ userPin2 - .word 0x10000000 @ 7 - .word 0xa+63 - .word 0xb+68 - .word 0x0 @ [r0] - .word 0x00000001 @ userPin3 - .word 0x10000000 @ 8 - .word 0xa+69 - .word 0xb+74 - .word 0x0 @ [r0] - .word 0x00000001 @ userPin4 - .word 0x10000000 @ 9 - .word 0xa+75 - .word 0xb+80 - .word 0x0 @ [r0] - .word 0x00000001 @ pinsEqual - .word 0x10000000 @ 10 - .word 0xa+111 - .word 0xb+118 - .word 0x0 @ [r0,r1] - .word 0x00000001 @ pinsEqual - .word 0x10000000 @ 11 - .word 0xa+134 - .word 0xb+141 - .word 0x0 @ [r0,r1] - .word 0x00000001 @ pinsEqual - .word 0x10000000 @ 12 - .word 0xa+157 - .word 0xb+164 - .word 0x0 @ [r0,r1] - .word 0x00000001 @ pinsEqual - .word 0x10000000 @ 13 - .word 0xa+180 - .word 0xb+187 - .word 0x0 @ [r0,r1] - .word 0x00000001 @ pinsEqual - .word 0x10000000 @ 14 - .word 0xa+203 - .word 0xb+207 - .word 0x0 @ [r0] - .word 0x00000001 @ authenticated diff --git a/test_results/edited_test_files/pinny.edited.hard.wh b/test_results/edited_test_files/pinny.edited.hard.wh deleted file mode 100644 index b3b639f..0000000 --- a/test_results/edited_test_files/pinny.edited.hard.wh +++ /dev/null @@ -1,194 +0,0 @@ -ui32 res; -ui32 stmt; -ui32 bit_shift; -ui32 flip_mask; - -fn main(ui32 stmt, ui32 flip_mask) -> ui32 { - ui32 authenticated; - ui32 cardPin1; - ui32 cardPin2; - ui32 cardPin3; - ui32 cardPin4; - ui32 userPin1; - ui32 userPin2; - ui32 userPin3; - ui32 userPin4; - ui32 pinsEqual; - ui32 step_counter; - step_counter = (0 as ui32); - authenticated = (0 as ui32); - if (stmt == (0 as ui32)) { - authenticated = (0 as ui32) ^ flip_mask; - } - step_counter++; - if (step_counter != (1 as ui32)) { - return (77 as ui32); - } - if ( authenticated != (0 as ui32)) { - step_counter++; - if (step_counter != (2 as ui32)) { - return (77 as ui32); - } - return ((77 as ui32) as ui32); - } - cardPin1 = (1 as ui32); - if (stmt == (1 as ui32)) { - cardPin1 = (1 as ui32) ^ flip_mask; - } - step_counter++; - if (step_counter != (3 as ui32)) { - return (77 as ui32); - } - cardPin2 = (2 as ui32); - if (stmt == (2 as ui32)) { - cardPin2 = (2 as ui32) ^ flip_mask; - } - step_counter++; - if (step_counter != (4 as ui32)) { - return (77 as ui32); - } - cardPin3 = (3 as ui32); - if (stmt == (3 as ui32)) { - cardPin3 = (3 as ui32) ^ flip_mask; - } - step_counter++; - if (step_counter != (5 as ui32)) { - return (77 as ui32); - } - cardPin4 = (4 as ui32); - if (stmt == (4 as ui32)) { - cardPin4 = (4 as ui32) ^ flip_mask; - } - step_counter++; - if (step_counter != (6 as ui32)) { - return (77 as ui32); - } - userPin1 = (0 as ui32); - if (stmt == (5 as ui32)) { - userPin1 = (0 as ui32) ^ flip_mask; - } - step_counter++; - if (step_counter != (7 as ui32)) { - return (77 as ui32); - } - userPin2 = (0 as ui32); - if (stmt == (6 as ui32)) { - userPin2 = (0 as ui32) ^ flip_mask; - } - step_counter++; - if (step_counter != (8 as ui32)) { - return (77 as ui32); - } - userPin3 = (0 as ui32); - if (stmt == (7 as ui32)) { - userPin3 = (0 as ui32) ^ flip_mask; - } - step_counter++; - if (step_counter != (9 as ui32)) { - return (77 as ui32); - } - userPin4 = (0 as ui32); - if (stmt == (8 as ui32)) { - userPin4 = (0 as ui32) ^ flip_mask; - } - step_counter++; - if (step_counter != (10 as ui32)) { - return (77 as ui32); - } - pinsEqual = (0 as ui32); - if (stmt == (9 as ui32)) { - pinsEqual = (0 as ui32) ^ flip_mask; - } - step_counter++; - if (step_counter != (11 as ui32)) { - return (77 as ui32); - } - if ( pinsEqual != (0 as ui32)) { - step_counter++; - if (step_counter != (12 as ui32)) { - return (77 as ui32); - } - return ((77 as ui32) as ui32); - } - if ( userPin1 == cardPin1) { - step_counter++; - if (step_counter != (13 as ui32)) { - return (77 as ui32); - } - pinsEqual = pinsEqual + (1 as ui32); - if (stmt == (10 as ui32)) { - pinsEqual = pinsEqual + (1 as ui32) ^ flip_mask; - } - step_counter++; - if (step_counter != (14 as ui32)) { - return (77 as ui32); - } - } - if ( userPin2 == cardPin2) { - step_counter++; - if (step_counter != (15 as ui32)) { - return (77 as ui32); - } - pinsEqual = pinsEqual + (1 as ui32); - if (stmt == (11 as ui32)) { - pinsEqual = pinsEqual + (1 as ui32) ^ flip_mask; - } - step_counter++; - if (step_counter != (16 as ui32)) { - return (77 as ui32); - } - } - if ( userPin3 == cardPin3) { - step_counter++; - if (step_counter != (17 as ui32)) { - return (77 as ui32); - } - pinsEqual = pinsEqual + (1 as ui32); - if (stmt == (12 as ui32)) { - pinsEqual = pinsEqual + (1 as ui32) ^ flip_mask; - } - step_counter++; - if (step_counter != (18 as ui32)) { - return (77 as ui32); - } - } - if ( userPin4 == cardPin4) { - step_counter++; - if (step_counter != (19 as ui32)) { - return (77 as ui32); - } - pinsEqual = pinsEqual + (1 as ui32); - if (stmt == (13 as ui32)) { - pinsEqual = pinsEqual + (1 as ui32) ^ flip_mask; - } - step_counter++; - if (step_counter != (20 as ui32)) { - return (77 as ui32); - } - } - if ( pinsEqual == (4 as ui32)) { - step_counter++; - if (step_counter != (21 as ui32)) { - return (77 as ui32); - } - authenticated = (1 as ui32); - if (stmt == (14 as ui32)) { - authenticated = (1 as ui32) ^ flip_mask; - } - step_counter++; - if (step_counter != (22 as ui32)) { - return (77 as ui32); - } - } - return (authenticated as ui32); -} -stmt = (? as ui32); -bit_shift = (? as ui32); -assume (bit_shift <= (31 as ui32)); -assume (bit_shift >= (0 as ui32)); -assume (stmt >= (0 as ui32)); -assume (stmt <= (14 as ui32)); -flip_mask = ((1 as ui32) << bit_shift); - -res = main(stmt, flip_mask); -assert(res == (0 as ui32)); diff --git a/test_results/edited_test_files/pinny.edited.s b/test_results/edited_test_files/pinny.edited.s deleted file mode 100644 index 0bec9db..0000000 --- a/test_results/edited_test_files/pinny.edited.s +++ /dev/null @@ -1,231 +0,0 @@ -.syntax unified -.thumb - -.section .text -.global _start -.type _start, %function - -_start: - sub sp, sp, #4 - mov r0, #0 - str r0, [sp] - ldr r0, [sp, #0] - mov r1, r0 - mov r0, #0 - cmp r1, r0 - mov r0, #0 - it ne - movne r0, #1 - cmp r0, #0 - beq else_0 - mov r0, #77 - mov r7, #1 - svc #0 - b endif_0 -else_0: -endif_0: - sub sp, sp, #4 - mov r0, #1 - str r0, [sp] - sub sp, sp, #4 - mov r0, #2 - str r0, [sp] - sub sp, sp, #4 - mov r0, #3 - str r0, [sp] - sub sp, sp, #4 - mov r0, #4 - str r0, [sp] - sub sp, sp, #4 - mov r0, #0 - str r0, [sp] - sub sp, sp, #4 - mov r0, #0 - str r0, [sp] - sub sp, sp, #4 - mov r0, #0 - str r0, [sp] - sub sp, sp, #4 - mov r0, #0 - str r0, [sp] - sub sp, sp, #4 - mov r0, #0 - str r0, [sp] - ldr r0, [sp, #0] - mov r1, r0 - mov r0, #0 - cmp r1, r0 - mov r0, #0 - it ne - movne r0, #1 - cmp r0, #0 - beq else_1 - mov r0, #77 - mov r7, #1 - svc #0 - b endif_1 -else_1: -endif_1: - ldr r0, [sp, #16] - mov r1, r0 - ldr r0, [sp, #32] - cmp r1, r0 - mov r0, #0 - it eq - moveq r0, #1 - cmp r0, #0 - beq else_2 - ldr r0, [sp, #0] - mov r1, r0 - mov r0, #1 - add r0, r1, r0 - str r0, [sp] - b endif_2 -else_2: -endif_2: - ldr r0, [sp, #12] - mov r1, r0 - ldr r0, [sp, #28] - cmp r1, r0 - mov r0, #0 - it eq - moveq r0, #1 - cmp r0, #0 - beq else_3 - ldr r0, [sp, #0] - mov r1, r0 - mov r0, #1 - add r0, r1, r0 - str r0, [sp] - b endif_3 -else_3: -endif_3: - ldr r0, [sp, #8] - mov r1, r0 - ldr r0, [sp, #24] - cmp r1, r0 - mov r0, #0 - it eq - moveq r0, #1 - cmp r0, #0 - beq else_4 - ldr r0, [sp, #0] - mov r1, r0 - mov r0, #1 - add r0, r1, r0 - str r0, [sp] - b endif_4 -else_4: -endif_4: - ldr r0, [sp, #4] - mov r1, r0 - ldr r0, [sp, #20] - cmp r1, r0 - mov r0, #0 - it eq - moveq r0, #1 - cmp r0, #0 - beq else_5 - ldr r0, [sp, #0] - mov r1, r0 - mov r0, #1 - add r0, r1, r0 - str r0, [sp] - b endif_5 -else_5: -endif_5: - ldr r0, [sp, #0] - mov r1, r0 - mov r0, #4 - cmp r1, r0 - mov r0, #0 - it eq - moveq r0, #1 - cmp r0, #0 - beq else_6 - mov r0, #1 - str r0, [sp, #36] - b endif_6 -else_6: -endif_6: - ldr r0, [sp, #36] - mov r7, #1 - svc #0 - -.size _start, .-_start -_metadata: - .word 0x10000000 @ 0 - .word 0xa+1 - .word 0xb+3 - .word 0x0 @ [r0] - .word 0x00000001 @ authenticated - .word 0x10000000 @ 1 - .word 0xa+19 - .word 0xb+21 - .word 0x0 @ [r0] - .word 0x00000001 @ cardPin1 - .word 0x10000000 @ 2 - .word 0xa+22 - .word 0xb+24 - .word 0x0 @ [r0] - .word 0x00000001 @ cardPin2 - .word 0x10000000 @ 3 - .word 0xa+25 - .word 0xb+27 - .word 0x0 @ [r0] - .word 0x00000001 @ cardPin3 - .word 0x10000000 @ 4 - .word 0xa+28 - .word 0xb+30 - .word 0x0 @ [r0] - .word 0x00000001 @ cardPin4 - .word 0x10000000 @ 5 - .word 0xa+31 - .word 0xb+33 - .word 0x0 @ [r0] - .word 0x00000001 @ userPin1 - .word 0x10000000 @ 6 - .word 0xa+34 - .word 0xb+36 - .word 0x0 @ [r0] - .word 0x00000001 @ userPin2 - .word 0x10000000 @ 7 - .word 0xa+37 - .word 0xb+39 - .word 0x0 @ [r0] - .word 0x00000001 @ userPin3 - .word 0x10000000 @ 8 - .word 0xa+40 - .word 0xb+42 - .word 0x0 @ [r0] - .word 0x00000001 @ userPin4 - .word 0x10000000 @ 9 - .word 0xa+43 - .word 0xb+45 - .word 0x0 @ [r0] - .word 0x00000001 @ pinsEqual - .word 0x10000000 @ 10 - .word 0xa+70 - .word 0xb+74 - .word 0x0 @ [r0,r1] - .word 0x00000001 @ pinsEqual - .word 0x10000000 @ 11 - .word 0xa+87 - .word 0xb+91 - .word 0x0 @ [r0,r1] - .word 0x00000001 @ pinsEqual - .word 0x10000000 @ 12 - .word 0xa+104 - .word 0xb+108 - .word 0x0 @ [r0,r1] - .word 0x00000001 @ pinsEqual - .word 0x10000000 @ 13 - .word 0xa+121 - .word 0xb+125 - .word 0x0 @ [r0,r1] - .word 0x00000001 @ pinsEqual - .word 0x10000000 @ 14 - .word 0xa+138 - .word 0xb+139 - .word 0x0 @ [r0] - .word 0x00000001 @ authenticated diff --git a/test_results/edited_test_files/pinny.edited.wh b/test_results/edited_test_files/pinny.edited.wh deleted file mode 100644 index 361e57c..0000000 --- a/test_results/edited_test_files/pinny.edited.wh +++ /dev/null @@ -1,104 +0,0 @@ -ui32 res; -ui32 stmt; -ui32 bit_shift; -ui32 flip_mask; - -fn main(ui32 stmt, ui32 flip_mask) -> ui32 { - ui32 authenticated; - ui32 cardPin1; - ui32 cardPin2; - ui32 cardPin3; - ui32 cardPin4; - ui32 userPin1; - ui32 userPin2; - ui32 userPin3; - ui32 userPin4; - ui32 pinsEqual; - authenticated = (0 as ui32); - if (stmt == (0 as ui32)) { - authenticated = (0 as ui32) ^ flip_mask; - } - if ( authenticated != (0 as ui32)) { - return ((77 as ui32) as ui32); - } - cardPin1 = (1 as ui32); - if (stmt == (1 as ui32)) { - cardPin1 = (1 as ui32) ^ flip_mask; - } - cardPin2 = (2 as ui32); - if (stmt == (2 as ui32)) { - cardPin2 = (2 as ui32) ^ flip_mask; - } - cardPin3 = (3 as ui32); - if (stmt == (3 as ui32)) { - cardPin3 = (3 as ui32) ^ flip_mask; - } - cardPin4 = (4 as ui32); - if (stmt == (4 as ui32)) { - cardPin4 = (4 as ui32) ^ flip_mask; - } - userPin1 = (0 as ui32); - if (stmt == (5 as ui32)) { - userPin1 = (0 as ui32) ^ flip_mask; - } - userPin2 = (0 as ui32); - if (stmt == (6 as ui32)) { - userPin2 = (0 as ui32) ^ flip_mask; - } - userPin3 = (0 as ui32); - if (stmt == (7 as ui32)) { - userPin3 = (0 as ui32) ^ flip_mask; - } - userPin4 = (0 as ui32); - if (stmt == (8 as ui32)) { - userPin4 = (0 as ui32) ^ flip_mask; - } - pinsEqual = (0 as ui32); - if (stmt == (9 as ui32)) { - pinsEqual = (0 as ui32) ^ flip_mask; - } - if ( pinsEqual != (0 as ui32)) { - return ((77 as ui32) as ui32); - } - if ( userPin1 == cardPin1) { - pinsEqual = pinsEqual + (1 as ui32); - if (stmt == (10 as ui32)) { - pinsEqual = pinsEqual + (1 as ui32) ^ flip_mask; - } - } - if ( userPin2 == cardPin2) { - pinsEqual = pinsEqual + (1 as ui32); - if (stmt == (11 as ui32)) { - pinsEqual = pinsEqual + (1 as ui32) ^ flip_mask; - } - } - if ( userPin3 == cardPin3) { - pinsEqual = pinsEqual + (1 as ui32); - if (stmt == (12 as ui32)) { - pinsEqual = pinsEqual + (1 as ui32) ^ flip_mask; - } - } - if ( userPin4 == cardPin4) { - pinsEqual = pinsEqual + (1 as ui32); - if (stmt == (13 as ui32)) { - pinsEqual = pinsEqual + (1 as ui32) ^ flip_mask; - } - } - if ( pinsEqual == (4 as ui32)) { - authenticated = (1 as ui32); - if (stmt == (14 as ui32)) { - authenticated = (1 as ui32) ^ flip_mask; - } - } - return (authenticated as ui32); -} -stmt = (? as ui32); -bit_shift = (? as ui32); -assume (bit_shift <= (31 as ui32)); -assume (bit_shift >= (0 as ui32)); -assume (stmt >= (0 as ui32)); -assume (stmt <= (14 as ui32)); -flip_mask = ((1 as ui32) << bit_shift); - -res = main(stmt, flip_mask); -assert(res == (0 as ui32)); diff --git a/test_results/plots/exhaustive.svg b/test_results/plots/exhaustive.svg deleted file mode 100644 index 61428e9..0000000 --- a/test_results/plots/exhaustive.svg +++ /dev/null @@ -1,2172 +0,0 @@ - - - - - - - - 2026-05-19T11:37:29.014955 - image/svg+xml - - - Matplotlib v3.10.9, https://matplotlib.org/ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/test_results/plots/exhaustive_edited.svg b/test_results/plots/exhaustive_edited.svg deleted file mode 100644 index 7f319f8..0000000 --- a/test_results/plots/exhaustive_edited.svg +++ /dev/null @@ -1,2142 +0,0 @@ - - - - - - - - 2026-05-19T11:37:29.206517 - image/svg+xml - - - Matplotlib v3.10.9, https://matplotlib.org/ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/test_results/plots/exhaustive_fault_types_hard.svg b/test_results/plots/exhaustive_fault_types_hard.svg deleted file mode 100644 index b217b55..0000000 --- a/test_results/plots/exhaustive_fault_types_hard.svg +++ /dev/null @@ -1,2230 +0,0 @@ - - - - - - - - 2026-05-19T11:37:29.837794 - image/svg+xml - - - Matplotlib v3.10.9, https://matplotlib.org/ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/test_results/plots/exhaustive_fault_types_normal.svg b/test_results/plots/exhaustive_fault_types_normal.svg deleted file mode 100644 index 0969ba3..0000000 --- a/test_results/plots/exhaustive_fault_types_normal.svg +++ /dev/null @@ -1,2184 +0,0 @@ - - - - - - - - 2026-05-19T11:37:29.636416 - image/svg+xml - - - Matplotlib v3.10.9, https://matplotlib.org/ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/test_results/plots/exhaustive_fault_types_normal_edited.svg b/test_results/plots/exhaustive_fault_types_normal_edited.svg deleted file mode 100644 index 48ee736..0000000 --- a/test_results/plots/exhaustive_fault_types_normal_edited.svg +++ /dev/null @@ -1,2427 +0,0 @@ - - - - - - - - 2026-05-19T11:37:30.042083 - image/svg+xml - - - Matplotlib v3.10.9, https://matplotlib.org/ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/test_results/plots/guided.svg b/test_results/plots/guided.svg deleted file mode 100644 index d997df9..0000000 --- a/test_results/plots/guided.svg +++ /dev/null @@ -1,1542 +0,0 @@ - - - - - - - - 2026-05-19T11:37:29.351972 - image/svg+xml - - - Matplotlib v3.10.9, https://matplotlib.org/ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/test_results/plots/guided_edited.svg b/test_results/plots/guided_edited.svg deleted file mode 100644 index 5a77ad4..0000000 --- a/test_results/plots/guided_edited.svg +++ /dev/null @@ -1,1445 +0,0 @@ - - - - - - - - 2026-05-19T11:37:29.480288 - image/svg+xml - - - Matplotlib v3.10.9, https://matplotlib.org/ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/test_results/plots/guided_fault_types_hard.svg b/test_results/plots/guided_fault_types_hard.svg deleted file mode 100644 index 471c8f1..0000000 --- a/test_results/plots/guided_fault_types_hard.svg +++ /dev/null @@ -1,1593 +0,0 @@ - - - - - - - - 2026-05-19T11:37:30.296612 - image/svg+xml - - - Matplotlib v3.10.9, https://matplotlib.org/ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/test_results/plots/guided_fault_types_normal.svg b/test_results/plots/guided_fault_types_normal.svg deleted file mode 100644 index 3e40e31..0000000 --- a/test_results/plots/guided_fault_types_normal.svg +++ /dev/null @@ -1,1457 +0,0 @@ - - - - - - - - 2026-05-19T11:37:30.182039 - image/svg+xml - - - Matplotlib v3.10.9, https://matplotlib.org/ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/test_results/plots/guided_fault_types_normal_edited.svg b/test_results/plots/guided_fault_types_normal_edited.svg deleted file mode 100644 index c0a7c35..0000000 --- a/test_results/plots/guided_fault_types_normal_edited.svg +++ /dev/null @@ -1,1618 +0,0 @@ - - - - - - - - 2026-05-19T11:37:30.400464 - image/svg+xml - - - Matplotlib v3.10.9, https://matplotlib.org/ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/test_results/plots/symex_results.csv b/test_results/plots/symex_results.csv deleted file mode 100644 index 2852f76..0000000 --- a/test_results/plots/symex_results.csv +++ /dev/null @@ -1,11 +0,0 @@ -id,run_id,test,variant,stmt,faulty_bit,result,edited -1,1,pinny,Hard,9,2,77,0 -2,1,pinny,Hard,8,2,77,0 -3,1,pinny,Hard,6,1,77,0 -4,1,pinny,Hard,4,2,77,0 -5,1,pinny,Hard,2,1,77,0 -6,1,pinny,Hard,0,0,1,0 -7,1,pinny,Normal,9,2,1,0 -8,1,pinny,Normal,0,0,1,0 -9,1,pinny.edited,Normal,9,0,77,1 -10,1,pinny.edited,Normal,0,0,77,1 diff --git a/test_results/results.db b/test_results/results.db deleted file mode 100644 index eae78e7..0000000 Binary files a/test_results/results.db and /dev/null differ diff --git a/test_results/tests/pinny.edited.trv b/test_results/tests/pinny.edited.trv deleted file mode 100644 index 76a67d5..0000000 --- a/test_results/tests/pinny.edited.trv +++ /dev/null @@ -1,40 +0,0 @@ -func main() -> Integer { - let authenticated : Integer = 0; - if authenticated != 0 { - return 77; - } - let cardPin1 : Integer = 1; - let cardPin2 : Integer = 2; - let cardPin3 : Integer = 3; - let cardPin4 : Integer = 4; - let userPin1 : Integer = 0; - let userPin2 : Integer = 0; - let userPin3 : Integer = 0; - let userPin4 : Integer = 0; - let pinsEqual : Integer = 0; - if pinsEqual != 0 { - return 77; - } - - if userPin1 == cardPin1 then { - pinsEqual = pinsEqual + 1; - } - - if userPin2 == cardPin2 then { - pinsEqual = pinsEqual + 1; - } - - if userPin3 == cardPin3 then { - pinsEqual = pinsEqual + 1; - } - - if userPin4 == cardPin4 then { - pinsEqual = pinsEqual + 1; - } - - if pinsEqual == 4 then { - authenticated = 1; - } - - return authenticated; -} diff --git a/test_results/tests/pinny.wh b/test_results/tests/pinny.wh deleted file mode 100644 index 4abe1e9..0000000 --- a/test_results/tests/pinny.wh +++ /dev/null @@ -1,103 +0,0 @@ -ui32 res; -ui32 stmt; -ui32 bit_shift; -ui32 flip_mask; - -fn main(ui32 stmt, ui32 flip_mask) -> ui32 { - ui32 ptc; - ui32 authenticated; - ui32 cardPin1; - ui32 cardPin2; - ui32 cardPin3; - ui32 cardPin4; - ui32 userPin1; - ui32 userPin2; - ui32 userPin3; - ui32 userPin4; - ui32 pinsEqual; - authenticated = (0 as ui32); - if(stmt == (1 as ui32)) { - authenticated = (0 as ui32) ^ flip_mask; - } - cardPin1 = (1 as ui32); - if(stmt == (2 as ui32)) { - cardPin1 = (1 as ui32) ^ flip_mask; - } - cardPin2 = (2 as ui32); - if(stmt == (3 as ui32)) { - cardPin2 = (2 as ui32) ^ flip_mask; - } - cardPin3 = (3 as ui32); - if(stmt == (4 as ui32)) { - cardPin3 = (3 as ui32) ^ flip_mask; - } - cardPin4 = (4 as ui32); - if(stmt == (5 as ui32)) { - cardPin4 = (4 as ui32) ^ flip_mask; - } - userPin1 = (0 as ui32); - if(stmt == (6 as ui32)) { - userPin1 = (0 as ui32) ^ flip_mask; - } - userPin2 = (0 as ui32); - if(stmt == (7 as ui32)) { - userPin2 = (0 as ui32) ^ flip_mask; - } - userPin3 = (0 as ui32); - if(stmt == (8 as ui32)) { - userPin3 = (0 as ui32) ^ flip_mask; - } - userPin4 = (0 as ui32); - if(stmt == (9 as ui32)) { - userPin4 = (0 as ui32) ^ flip_mask; - } - pinsEqual = (0 as ui32); - if(stmt == (10 as ui32)) { - pinsEqual = (0 as ui32) ^ flip_mask; - } - - if ( userPin1 == cardPin1) { - pinsEqual++; - if(stmt == (11 as ui32)) { - pinsEqual = pinsEqual ^ flip_mask; - } - } - - if ( userPin2 == cardPin2) { - pinsEqual++; - if(stmt == (12 as ui32)) { - pinsEqual = pinsEqual ^ flip_mask; - } - } - if ( userPin3 == cardPin3) { - pinsEqual++; - if(stmt == (13 as ui32)) { - pinsEqual = pinsEqual ^ flip_mask; - } - } - - if ( userPin4 == cardPin4) { - pinsEqual++; - if(stmt == (14 as ui32)) { - pinsEqual = pinsEqual ^ flip_mask; - } - } - - if ( pinsEqual == (4 as ui32)) { - authenticated = (1 as ui32); - if(stmt == (14 as ui32)) { - authenticated = (1 as ui32) ^ flip_mask; - } - } - return (authenticated as ui32); -} - -stmt = (? as ui32); -bit_shift = (? as ui32); -assume (bit_shift <= (31 as ui32)); -assume (bit_shift >= (0 as ui32)); -assume (stmt >= (1 as ui32)); -assume (stmt <= (14 as ui32)); -flip_mask = ((1 as ui32) << bit_shift); -res = main(stmt, flip_mask); -assert(res == (0 as ui32)); diff --git a/testing/config.toml b/testing/config.toml index 0bbcc2b..49de0e9 100644 --- a/testing/config.toml +++ b/testing/config.toml @@ -1,16 +1,2 @@ -test_folder = "pinny" +test_folder = "eval_cases/pinny" plotmode = "save" # show, save or both - -injection_points = [] - -[pass_mode] -default = "returncode" - -[pass_mode.returncode] -passed = 0 -failed = 1 -paniced = 2 - -[pass_mode.stdout] -expected_pass = "g_authenticated: 0" -expected_fail = "g_authenticated: 1" diff --git a/testing/eval_cases/crt/crt-rsa.trv b/testing/eval_cases/crt/crt-rsa.trv new file mode 100644 index 0000000..4defd20 --- /dev/null +++ b/testing/eval_cases/crt/crt-rsa.trv @@ -0,0 +1,102 @@ +# CRT-RSA Encryption +# Message: 65 +# Public key: (e=17, n=3233) +# p = 61, q = 53 +# Expected ciphertext: 2790 + +func main() -> Integer { + let p : Integer = 61; + let q : Integer = 53; + let n : Integer = 3233; + let e : Integer = 17; + let m : Integer = 65; + + # CRT exponents: ep = e mod (p-1), eq = e mod (q-1) + let p_minus_1 : Integer = 0; + let q_minus_1 : Integer = 0; + let ep : Integer = 0; + let eq : Integer = 0; + + p_minus_1 = p - 1; + q_minus_1 = q - 1; + + # ep = e - (e / p_minus_1) * p_minus_1 (manual mod) + ep = e - (e / p_minus_1) * p_minus_1; + # eq = e - (e / q_minus_1) * q_minus_1 + eq = e - (e / q_minus_1) * q_minus_1; + + # c1 = m^ep mod p (modular exponentiation inlined) + let c1 : Integer = 0; + let base1 : Integer = 0; + let exp1 : Integer = 0; + c1 = 1; + base1 = m - (m / p) * p; + exp1 = ep; + while exp1 > 0 do { + if exp1 - (exp1 / 2) * 2 == 1 then { + c1 = (c1 * base1) - ((c1 * base1) / p) * p; + } + exp1 = exp1 / 2; + base1 = (base1 * base1) - ((base1 * base1) / p) * p; + } + + # c2 = m^eq mod q + let c2 : Integer = 0; + let base2 : Integer = 0; + let exp2 : Integer = 0; + c2 = 1; + base2 = m - (m / q) * q; + exp2 = eq; + while exp2 > 0 do { + if exp2 - (exp2 / 2) * 2 == 1 then { + c2 = (c2 * base2) - ((c2 * base2) / q) * q; + } + exp2 = exp2 / 2; + base2 = (base2 * base2) - ((base2 * base2) / q) * q; + } + + # qinv = q^(-1) mod p using extended Euclidean algorithm + let qinv : Integer = 0; + let t : Integer = 0; + let newt : Integer = 0; + let r : Integer = 0; + let newr : Integer = 0; + let quotient : Integer = 0; + let tmp : Integer = 0; + + t = 0; + newt = 1; + r = p; + newr = q; + while newr != 0 do { + quotient = r / newr; + tmp = t - quotient * newt; + t = newt; + newt = tmp; + tmp = r - quotient * newr; + r = newr; + newr = tmp; + } + if t < 0 then { + qinv = t + p; + } else { + qinv = t; + } + + # h = qinv * (c1 - c2) mod p + let h : Integer = 0; + let diff : Integer = 0; + diff = c1 - c2; + h = qinv * diff - (qinv * diff / p) * p; + if h < 0 then { + h = h + p; + } + + # c = c2 + h * q + let c : Integer = 0; + c = c2 + h * q; + + print c; + + return c; +} diff --git a/testing/eval_cases/crt/test.conf b/testing/eval_cases/crt/test.conf new file mode 100644 index 0000000..fc4345d --- /dev/null +++ b/testing/eval_cases/crt/test.conf @@ -0,0 +1,3 @@ +mode: stdout +passed: 2790,3233 +failed: 61,53,65 diff --git a/testing/eval_cases/hash/hash.trv b/testing/eval_cases/hash/hash.trv new file mode 100644 index 0000000..e56aec7 --- /dev/null +++ b/testing/eval_cases/hash/hash.trv @@ -0,0 +1,41 @@ +func main() -> Integer { + # 123456789 is too big for a single ARM move. + # We build it: 12345 * 10000 + 6789 + let message : Integer = 0; + message = 12345; + + # Initialize hash with a non-zero prime offset (like FNV) + let h : Integer = 5381; + let multiplier : Integer = 33; + + # 104729 is too big for a single ARM move. + # We build it: 104 * 1000 + 729 + let prime_modulo : Integer = 0; + prime_modulo = 104 * 1000 + 729; + + let temp_msg : Integer = message; + let chunk : Integer = 0; + + # Single loop: process the integer by stripping off digits/chunks + while temp_msg > 0 do { + # chunk = temp_msg mod 100 (processes two digits at a time) + chunk = temp_msg - (temp_msg / 100) * 100; + + # Mix the chunk into the hash + h = (h * multiplier) + chunk; + + # Inline modulo: h = h mod prime_modulo + h = h - (h / prime_modulo) * prime_modulo; + + # Move to the next chunk + temp_msg = temp_msg / 100; + } + + # Final guard statement if operations pushed the integer into negative wrap + if h < 0 then { + h = h + prime_modulo; + } + + print h; + return h; +} diff --git a/testing/eval_cases/hash/test.conf b/testing/eval_cases/hash/test.conf new file mode 100644 index 0000000..1e8eae5 --- /dev/null +++ b/testing/eval_cases/hash/test.conf @@ -0,0 +1,3 @@ +mode: stdout +passed: 97028 +failed: 12345 diff --git a/test_results/tests/pinny.trv b/testing/eval_cases/pinny/pinny.trv similarity index 100% rename from test_results/tests/pinny.trv rename to testing/eval_cases/pinny/pinny.trv diff --git a/testing/eval_cases/pinny/test.conf b/testing/eval_cases/pinny/test.conf new file mode 100644 index 0000000..eb657d9 --- /dev/null +++ b/testing/eval_cases/pinny/test.conf @@ -0,0 +1,3 @@ +mode: returncode +passed: 0 +failed: 1 diff --git a/testing/pinny/disabled/crt-rsa.trv b/testing/pinny/disabled/crt-rsa.trv deleted file mode 100644 index 62fc913..0000000 --- a/testing/pinny/disabled/crt-rsa.trv +++ /dev/null @@ -1,121 +0,0 @@ -func main() -> Integer { - let g_countermeasure : Integer = 0; - let g_N : Integer = 11413; - let g_e : Integer = 3533; - let g_p : Integer = 101; - let g_q : Integer = 113; - let g_iq : Integer = 59; - let g_dp : Integer = 97; - let g_dq : Integer = 101; - let g_sign : Integer = -1; - let g_M : Integer = 23; - - let Cp : Integer = 0; - let Cq : Integer = 0; - let tmp : Integer = 0; - - let a : Integer = 0; - let b : Integer = 0; - let n : Integer = 0; - let r : Integer = 0; - - let mul_r : Integer = 0; - let mul_a : Integer = 0; - let mul_b : Integer = 0; - let mul_n : Integer = 0; - let mul_tmp : Integer = 0; - - let pow_a : Integer = 0; - let pow_tmp : Integer = 0; - let pow_b : Integer = 0; - let pow_n : Integer = 0; - - a = g_M; - b = g_dp; - n = g_p; - r = 1; - pow_b = 0; - while pow_b < b { - mul_a = r; - mul_b = a; - mul_n = n; - mul_tmp = 0; - while mul_b > 0 { - mul_tmp = mul_tmp + mul_a; - while mul_tmp > mul_n { - mul_tmp = mul_tmp - mul_n; - } - while mul_tmp < 0 { - mul_tmp = mul_tmp + mul_n; - } - if mul_tmp == mul_n { - mul_tmp = 0; - } - mul_b = mul_b - 1; - } - r = mul_tmp; - pow_b = pow_b + 1; - } - Cp = r; - - a = g_M; - b = g_dq; - n = g_q; - r = 1; - pow_b = 0; - while pow_b < b { - mul_a = r; - mul_b = a; - mul_n = n; - mul_tmp = 0; - while mul_b > 0 { - mul_tmp = mul_tmp + mul_a; - while mul_tmp > mul_n { - mul_tmp = mul_tmp - mul_n; - } - while mul_tmp < 0 { - mul_tmp = mul_tmp + mul_n; - } - if mul_tmp == mul_n { - mul_tmp = 0; - } - mul_b = mul_b - 1; - } - r = mul_tmp; - pow_b = pow_b + 1; - } - Cq = r; - - tmp = Cp - Cq; - - mul_a = tmp; - mul_b = g_iq; - mul_n = g_p; - mul_tmp = 0; - while mul_b > 0 { - mul_tmp = mul_tmp + mul_a; - while mul_tmp > mul_n { - mul_tmp = mul_tmp - mul_n; - } - while mul_tmp < 0 { - mul_tmp = mul_tmp + mul_n; - } - if mul_tmp == mul_n { - mul_tmp = 0; - } - mul_b = mul_b - 1; - } - tmp = mul_tmp; - - tmp = tmp * g_q; - - tmp = tmp + Cq; - - g_sign = tmp; - - print("g_sign = ", g_sign); - - print("g_countermeasure: ", g_countermeasure); - - return g_sign; -} diff --git a/testing/pinny/disabled/crt-rsa.trv.output b/testing/pinny/disabled/crt-rsa.trv.output deleted file mode 100644 index cfeff4a..0000000 --- a/testing/pinny/disabled/crt-rsa.trv.output +++ /dev/null @@ -1 +0,0 @@ -11254 diff --git a/testing/pinny/pinny.trv b/testing/pinny/pinny.trv deleted file mode 100644 index f14b225..0000000 --- a/testing/pinny/pinny.trv +++ /dev/null @@ -1,34 +0,0 @@ -func main() -> Integer { - let authenticated : Integer = 0; - let cardPin1 : Integer = 1; - let cardPin2 : Integer = 2; - let cardPin3 : Integer = 3; - let cardPin4 : Integer = 4; - let userPin1 : Integer = 0; - let userPin2 : Integer = 0; - let userPin3 : Integer = 0; - let userPin4 : Integer = 0; - let pinsEqual : Integer = 0; - - if userPin1 == cardPin1 then { - pinsEqual = pinsEqual + 1; - } - - if userPin2 == cardPin2 then { - pinsEqual = pinsEqual + 1; - } - - if userPin3 == cardPin3 then { - pinsEqual = pinsEqual + 1; - } - - if userPin4 == cardPin4 then { - pinsEqual = pinsEqual + 1; - } - - if pinsEqual == 4 then { - authenticated = 1; - } - - return authenticated; -} diff --git a/testing/pinny/pinny.trv.output b/testing/pinny/pinny.trv.output deleted file mode 100644 index e69de29..0000000 diff --git a/testing/pinny/pinny.wh b/testing/pinny/pinny.wh deleted file mode 100644 index 4abe1e9..0000000 --- a/testing/pinny/pinny.wh +++ /dev/null @@ -1,103 +0,0 @@ -ui32 res; -ui32 stmt; -ui32 bit_shift; -ui32 flip_mask; - -fn main(ui32 stmt, ui32 flip_mask) -> ui32 { - ui32 ptc; - ui32 authenticated; - ui32 cardPin1; - ui32 cardPin2; - ui32 cardPin3; - ui32 cardPin4; - ui32 userPin1; - ui32 userPin2; - ui32 userPin3; - ui32 userPin4; - ui32 pinsEqual; - authenticated = (0 as ui32); - if(stmt == (1 as ui32)) { - authenticated = (0 as ui32) ^ flip_mask; - } - cardPin1 = (1 as ui32); - if(stmt == (2 as ui32)) { - cardPin1 = (1 as ui32) ^ flip_mask; - } - cardPin2 = (2 as ui32); - if(stmt == (3 as ui32)) { - cardPin2 = (2 as ui32) ^ flip_mask; - } - cardPin3 = (3 as ui32); - if(stmt == (4 as ui32)) { - cardPin3 = (3 as ui32) ^ flip_mask; - } - cardPin4 = (4 as ui32); - if(stmt == (5 as ui32)) { - cardPin4 = (4 as ui32) ^ flip_mask; - } - userPin1 = (0 as ui32); - if(stmt == (6 as ui32)) { - userPin1 = (0 as ui32) ^ flip_mask; - } - userPin2 = (0 as ui32); - if(stmt == (7 as ui32)) { - userPin2 = (0 as ui32) ^ flip_mask; - } - userPin3 = (0 as ui32); - if(stmt == (8 as ui32)) { - userPin3 = (0 as ui32) ^ flip_mask; - } - userPin4 = (0 as ui32); - if(stmt == (9 as ui32)) { - userPin4 = (0 as ui32) ^ flip_mask; - } - pinsEqual = (0 as ui32); - if(stmt == (10 as ui32)) { - pinsEqual = (0 as ui32) ^ flip_mask; - } - - if ( userPin1 == cardPin1) { - pinsEqual++; - if(stmt == (11 as ui32)) { - pinsEqual = pinsEqual ^ flip_mask; - } - } - - if ( userPin2 == cardPin2) { - pinsEqual++; - if(stmt == (12 as ui32)) { - pinsEqual = pinsEqual ^ flip_mask; - } - } - if ( userPin3 == cardPin3) { - pinsEqual++; - if(stmt == (13 as ui32)) { - pinsEqual = pinsEqual ^ flip_mask; - } - } - - if ( userPin4 == cardPin4) { - pinsEqual++; - if(stmt == (14 as ui32)) { - pinsEqual = pinsEqual ^ flip_mask; - } - } - - if ( pinsEqual == (4 as ui32)) { - authenticated = (1 as ui32); - if(stmt == (14 as ui32)) { - authenticated = (1 as ui32) ^ flip_mask; - } - } - return (authenticated as ui32); -} - -stmt = (? as ui32); -bit_shift = (? as ui32); -assume (bit_shift <= (31 as ui32)); -assume (bit_shift >= (0 as ui32)); -assume (stmt >= (1 as ui32)); -assume (stmt <= (14 as ui32)); -flip_mask = ((1 as ui32) << bit_shift); -res = main(stmt, flip_mask); -assert(res == (0 as ui32)); diff --git a/testing/run_tests b/testing/run_tests index bdcc20e..cf090c1 100755 --- a/testing/run_tests +++ b/testing/run_tests @@ -1,6 +1,11 @@ #!/bin/python3 import argparse, os, toml, shutil, subprocess, sys +import matplotlib + +from src.oracles import Oracle + +matplotlib.use("Agg") import matplotlib.pyplot as plt from datetime import datetime from src.database import ResultsDatabase @@ -10,6 +15,41 @@ from src.plotenator import Plotter from rich.console import Console +def replot(folder): + db_path = os.path.join(folder, "results.db") + if not os.path.exists(db_path): + print(f"Error: no results.db found in {folder}") + sys.exit(1) + + db = ResultsDatabase(db_path) + + df = db.query_df("SELECT tests_folder FROM runs ORDER BY id DESC LIMIT 1") + if df.empty: + print("Error: no runs found in database") + sys.exit(1) + + tests_folder = df.iloc[0, 0] + test_name = tests_folder.rstrip("/").split("/")[-1] + + plotter = Plotter(db, test_name) + plots = plotter.create_plots() + + plots_dir = os.path.join(folder, "plots") + os.makedirs(plots_dir, exist_ok=True) + + for name, fig in plots.items(): + path = os.path.join(plots_dir, f"{name}.svg") + fig.savefig(path, format="svg", bbox_inches="tight") + plt.close(fig) + + symex_csv_path = os.path.join(plots_dir, "symex_results.csv") + plotter.export_symex_csv(symex_csv_path) + + db.close() + print(f"Plots regenerated in {plots_dir}/") + print(f"Symex results exported to {symex_csv_path}") + + class Experiment: def __init__(self, args, run_variants, config_path=None): if config_path is None: @@ -17,6 +57,7 @@ class Experiment: with open(config_path, "r") as f: config = toml.load(f) + self.config = config self.args = args self.run_variants = run_variants self.base_dir = os.path.dirname(__file__) @@ -25,113 +66,133 @@ class Experiment: ) self.artifacts_folder = os.path.join(self.base_dir, "artifacts") self.plot_mode = config.get("plotmode", "save") - self.injection_points = config.get( - "injection_points", - [ - "r0", - "r1", - "r2", - "r3", - "r4", - "r5", - "r6", - "r7", - "r8", - "r9", - "r10", - "r11", - "r12", - ], - ) - self.default_pass_mode = config.get("pass_mode", {}).get( - "default", "returncode" - ) - self.pass_mode_configs = config.get("pass_mode", {}) - self.runner = TestRunner(config_path=args.config) + self.oracle = Oracle() + self.runner = TestRunner(config_path=args.config, oracle=None) self.tests = self.runner._discover_tests() self.compile_results = None def _build_stmt_to_trv_mapping(self, wh_path, trv_path): """Build a mapping from stmt numbers to .trv file lines.""" import re + print(f"Trying to map {wh_path} to {trv_path}") + stmt_to_expr = {} - + if not os.path.exists(wh_path) or not os.path.exists(trv_path): return stmt_to_expr - - with open(wh_path, 'r') as f: + + with open(wh_path, "r") as f: wh_lines = f.readlines() - + for i, line in enumerate(wh_lines): - match = re.search(r'if\s*\(stmt\s*==\s*\((\d+)\s+as\s+ui32\)\)', line) + match = re.search(r"if\s*\(stmt\s*==\s*\((\d+)\s+as\s+ui32\)\)", line) if match: stmt_num = int(match.group(1)) if i > 0: - prev_line = wh_lines[i-1].strip().rstrip(';') - expr_match = re.match(r'(\w+)\s*=\s*(.+)', prev_line) + prev_line = wh_lines[i - 1].strip().rstrip(";") + expr_match = re.match(r"(\w+)\s*=\s*(.+)", prev_line) if expr_match: var_name = expr_match.group(1) rhs = expr_match.group(2).strip() - rhs_normalized = re.sub(r'\s*\(?\d+\s+as\s+ui32\)?', lambda m: re.search(r'\d+', m.group()).group(), rhs) + rhs_normalized = re.sub( + r"\s*\(?\d+\s+as\s+ui32\)?", + lambda m: re.search(r"\d+", m.group()).group(), + rhs, + ) stmt_to_expr[stmt_num] = (var_name, rhs_normalized) - - with open(trv_path, 'r') as f: + + with open(trv_path, "r") as f: trv_lines = f.readlines() - + stmt_to_trv_line = {} used_trv_lines = set() - + for stmt_num, (var_name, rhs_normalized) in stmt_to_expr.items(): best_match = None for line_idx, trv_line in enumerate(trv_lines): if line_idx in used_trv_lines: continue - stripped = trv_line.strip().rstrip(';') - - trv_expr_match = re.match(r'(?:let\s+)?(\w+)\s*(?::\s*\w+\s*)?=\s*(.+)', stripped) + stripped = trv_line.strip().rstrip(";") + + trv_expr_match = re.match( + r"(?:let\s+)?(\w+)\s*(?::\s*\w+\s*)?=\s*(.+)", stripped + ) if trv_expr_match: trv_var = trv_expr_match.group(1) trv_rhs = trv_expr_match.group(2).strip() - + if trv_var == var_name: if rhs_normalized == trv_rhs: best_match = (line_idx + 1, stripped) break - elif best_match is None and re.search(re.escape(var_name), trv_rhs): + elif best_match is None and re.search( + re.escape(var_name), trv_rhs + ): best_match = (line_idx + 1, stripped) - + if best_match: stmt_to_trv_line[stmt_num] = best_match used_trv_lines.add(best_match[0] - 1) - + return stmt_to_trv_line def _run_edited_tests(self, edited_trv_path, test_name): """Compile and run symex + fault injection on an edited .trv file.""" edited_folder = os.path.join(self.run_folder, "edited_test_files") os.makedirs(edited_folder, exist_ok=True) - + print(f"\n{'='*60}") - print(f"RE-RUNNING ANALYSIS ON EDITED FILE: {os.path.basename(edited_trv_path)}") + print( + f"RE-RUNNING ANALYSIS ON EDITED FILE: {os.path.basename(edited_trv_path)}" + ) print(f"{'='*60}") - + + conf_file = "test.conf" + pass_mode_conf = {} + + if conf_file: + conf_path = os.path.join(self.tests_folder, conf_file) + config = {} + with open(conf_path, "r") as f: + for line in f: + line = line.strip() + if not line or ":" not in line: + continue + key, _, value = line.partition(":") + config[key.strip()] = value.strip() + + mode = config.get("mode") + if mode is None: + raise Exception("test.conf missing mode") + expected_pass = config.get("passed") + if expected_pass is None: + raise Exception("Failed to parse expected_pass from test.conf") + expected_fail = config.get("failed") + if expected_fail is None: + raise Exception("Failed to parse expected_fail from test.conf") + pass_mode_conf = { + "mode": mode, + "expected_pass": expected_pass, + "expected_fail": expected_fail + } + edited_test_name = os.path.splitext(os.path.basename(edited_trv_path))[0] - + + edited_test = { "name": edited_test_name, "path": edited_trv_path, - "expected_output": "", - "pass_mode": {"mode": "returncode", "expected_pass": 0, "expected_fail": 1}, + "pass_mode": pass_mode_conf } - + orig_tests = self.runner.tests orig_compile_results = self.runner.compile_results orig_compiled_folder = self.runner.compiled_folder - + self.runner.tests = [edited_test] self.runner.compile_results = None self.runner.compiled_folder = edited_folder - + print(f"\nCompiling edited test...") compile_results = self.runner.compile() for res in compile_results: @@ -145,29 +206,45 @@ class Experiment: self.runner.compile_results = orig_compile_results self.runner.compiled_folder = orig_compiled_folder return - + print(f"\nRunning symex on edited file...") symex_runner = SymexRunner(config_path=self.args.config) symex_runner.artifacts_folder = edited_folder edited_symex_results = symex_runner.run("normal") - - self.db.insert_symex_results_batch(self.run_id, edited_symex_results, edited=True) + + self.db.insert_symex_results_batch( + self.run_id, edited_symex_results, edited=True + ) print(edited_symex_results) - + print(f"\nRunning Interpreter Guided on edited file...") - guided_results = self.runner.run_tests(limit=self.args.limit, run_variants="normal", minimc_res=edited_symex_results) - + guided_results = self.runner.run_tests( + limit=self.args.limit, + run_variants="normal", + minimc_res=edited_symex_results, + ) + print(f"\nRunning Interpreter Exhaustively on edited file...") self.runner.compile_results = None - exhaustive_results = self.runner.run_tests(limit=self.args.limit, run_variants="normal") - - self.db.insert_interpreter_results_batch(self.run_id, exhaustive_results, edited=True) - self.db.insert_interpreter_results_batch(self.run_id, guided_results, True, edited=True) - - print(f"\nDisplaying errors found by symex on edited file (normal variant only)...") + exhaustive_results = self.runner.run_tests( + limit=self.args.limit, run_variants="normal" + ) + + self.db.insert_interpreter_results_batch( + self.run_id, exhaustive_results, edited=True + ) + self.db.insert_interpreter_results_batch( + self.run_id, guided_results, True, edited=True + ) + + print( + f"\nDisplaying errors found by symex on edited file (normal variant only)..." + ) print(f"{'='*60}") if edited_symex_results: - normal_results = [r for r in edited_symex_results if r.get("variant") == "Normal"] + normal_results = [ + r for r in edited_symex_results if r.get("variant") == "Normal" + ] if normal_results: results_by_test = {} for result in normal_results: @@ -175,7 +252,7 @@ class Experiment: if tname not in results_by_test: results_by_test[tname] = [] results_by_test[tname].append(result) - + for tname, results in results_by_test.items(): print(f"\nTest: {tname}") print("-" * 40) @@ -184,17 +261,19 @@ class Experiment: faulty_bit = result.get("faulty_bit") variant = result.get("variant") res_val = result.get("result") - print(f" Stmt {stmt}: Faulty bit: {faulty_bit}, Variant: {variant}, Result: {res_val}") + print( + f" Stmt {stmt}: Faulty bit: {faulty_bit}, Variant: {variant}, Result: {res_val}" + ) else: print(" No errors found by symex for normal variant.") else: print(" No errors found by symex.") print(f"{'='*60}") - + self.runner.tests = orig_tests self.runner.compile_results = orig_compile_results self.runner.compiled_folder = orig_compiled_folder - + return edited_symex_results, guided_results, exhaustive_results def run(self): @@ -213,34 +292,43 @@ class Experiment: wh_files = sorted( [f for f in os.listdir(self.runner.compiled_folder) if f.endswith(".wh")] ) - + self.runner.oracle = self.oracle.get(self.config.get("test_folder", None)) print("Whiley Files are ready for adding fault injections...") print("\nRunning symex...") - symex_runner = SymexRunner(config_path=self.args.config) - symex_runner.artifacts_folder = self.runner.compiled_folder - symex_results = symex_runner.run(self.run_variants) - - self.db.insert_symex_results_batch(self.run_id, symex_results) + if not self.args.skip_minimc: + symex_runner = SymexRunner(config_path=self.args.config) + symex_runner.artifacts_folder = self.runner.compiled_folder + symex_results = symex_runner.run(self.run_variants) + self.db.insert_symex_results_batch(self.run_id, symex_results) if not self.args.skip_run: - print(f"\nRunning Interpreter Guided...") - guided_fault_results = self.runner.run_tests(limit=self.args.limit, run_variants=run_variants, minimc_res=symex_results) + if not self.args.skip_minimc: + print(f"\nRunning Interpreter Guided...") + guided_fault_results = self.runner.run_tests( + limit=self.args.limit, + run_variants=self.run_variants, + minimc_res=symex_results, + guided=True, + ) + self.db.insert_interpreter_results_batch( + self.run_id, guided_fault_results, True + ) print(f"\nRunning Interpreter Exhaustively...") exhaustive_fault_results = self.runner.run_tests( - limit=self.args.limit, run_variants=run_variants + limit=self.args.limit, run_variants=self.run_variants + ) + self.db.insert_interpreter_results_batch( + self.run_id, exhaustive_fault_results ) - self.db.insert_interpreter_results_batch(self.run_id, exhaustive_fault_results) - self.db.insert_interpreter_results_batch(self.run_id, guided_fault_results, True) else: print(f"\nSkipping test run (--skip-run)") - # Display errors found by symex for normal variant only print(f"\n{'='*60}") print("ERRORS FOUND BY SYMEX (Symbolic Execution) - Normal Variant Only") print(f"{'='*60}") trv_files_to_edit = set() - if symex_results: + if not self.args.skip_minimc and symex_results: normal_results = [r for r in symex_results if r.get("variant") == "Normal"] if normal_results: results_by_test = {} @@ -249,40 +337,54 @@ class Experiment: if test_name not in results_by_test: results_by_test[test_name] = [] results_by_test[test_name].append(result) - + for test_name, results in results_by_test.items(): print(f"\nTest: {test_name}") print("-" * 40) - + trv_path = None wh_path = None for test in self.tests: if test["name"] == test_name: trv_path = test["path"] break - + if trv_path: test_base = os.path.splitext(os.path.basename(trv_path))[0] - wh_path = os.path.join(self.runner.compiled_folder, f"{test_base}.wh") - artifact_trv = os.path.join(self.run_tests_folder, f"{test_base}.trv") + wh_path = os.path.join( + self.runner.compiled_folder, f"{test_base}.wh" + ) + artifact_trv = os.path.join( + self.run_tests_folder, f"{test_base}.trv" + ) if os.path.exists(artifact_trv): trv_files_to_edit.add(artifact_trv) - - stmt_mapping = self._build_stmt_to_trv_mapping(wh_path, trv_path) if trv_path and wh_path else {} - + + stmt_mapping = ( + self._build_stmt_to_trv_mapping(wh_path, trv_path) + if trv_path and wh_path + else {} + ) + if trv_path and os.path.exists(trv_path): for result in results: stmt = result.get("stmt") faulty_bit = result.get("faulty_bit") variant = result.get("variant") res_val = result.get("result") - + if stmt in stmt_mapping: line_number, line_content = stmt_mapping[stmt] - print(f" Stmt {stmt} (line {line_number}): {line_content}") - print(f" -> Faulty bit: {faulty_bit}, Variant: {variant}, Result: {res_val}") + print( + f" Stmt {stmt} (line {line_number}): {line_content}" + ) + print( + f" -> Faulty bit: {faulty_bit}, Variant: {variant}, Result: {res_val}" + ) else: - print(f" Stmt {stmt}: (could not map to source) Faulty bit: {faulty_bit}, Variant: {variant}, Result: {res_val}") + print( + f" Stmt {stmt}: (could not map to source) Faulty bit: {faulty_bit}, Variant: {variant}, Result: {res_val}" + ) else: print(f" .trv file not found for test {test_name}") for result in results: @@ -290,80 +392,114 @@ class Experiment: faulty_bit = result.get("faulty_bit") variant = result.get("variant") res_val = result.get("result") - print(f" Stmt {stmt}: Faulty bit: {faulty_bit}, Variant: {variant}, Result: {res_val}") + print( + f" Stmt {stmt}: Faulty bit: {faulty_bit}, Variant: {variant}, Result: {res_val}" + ) else: print(" No errors found by symex for normal variant.") else: print(" No errors found by symex.") print(f"{'='*60}") - + if trv_files_to_edit: editor = os.environ.get("EDITOR", "nano") - - known_terminals = ["foot", "alacritty", "kitty", "gnome-terminal", "xterm", "konsole", "ghostty"] + + known_terminals = [ + "foot", + "alacritty", + "kitty", + "gnome-terminal", + "xterm", + "kgx", + "ghostty", + ] term_cmd = None for t in known_terminals: if shutil.which(t): term_cmd = t break - + edited_files = [] for trv_file in sorted(trv_files_to_edit): edited_path = trv_file.replace(".trv", ".edited.trv") shutil.copy2(trv_file, edited_path) edited_files.append(edited_path) - + while True: editor_procs = [] for edited_file in edited_files: - print(f"\nOpening {edited_file} in {editor} (new terminal window)...") + print( + f"\nOpening {edited_file} in {editor} (new terminal window)..." + ) if term_cmd: - if term_cmd == "gnome-terminal": - p = subprocess.Popen(["gnome-terminal", "--wait", "--", editor, edited_file], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + if term_cmd == "kgx": + p = subprocess.Popen( + ["kgx", "--wait", "--", editor, edited_file], + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, + ) elif term_cmd == "xterm": - p = subprocess.Popen(["xterm", "-e", editor, edited_file], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + p = subprocess.Popen( + ["xterm", "-e", editor, edited_file], + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, + ) elif term_cmd == "konsole": - p = subprocess.Popen(["konsole", "-e", editor, edited_file], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + p = subprocess.Popen( + ["konsole", "-e", editor, edited_file], + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, + ) elif term_cmd in ("alacritty", "kitty", "foot", "ghostty"): - p = subprocess.Popen([term_cmd, "-e", editor, edited_file], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + p = subprocess.Popen( + [term_cmd, "-e", editor, edited_file], + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, + ) editor_procs.append(p) else: - print(f" Warning: No terminal emulator found, opening in current terminal") + print( + f" Warning: No terminal emulator found, opening in current terminal" + ) subprocess.run([editor, edited_file]) - + for p in editor_procs: p.wait() - + while True: try: - response = input("\nHave you made the edits you wanted? (y/n): ").strip().lower() + response = ( + input("\nHave you made the edits you wanted? (y/n): ") + .strip() + .lower() + ) if response in ("y", "n"): break except EOFError: response = "y" break - + if response == "y": break - + print(f"\n{'='*60}") print("Compiling and re-running analysis on edited files...") print(f"{'='*60}") - + for edited_file in edited_files: - test_base = os.path.splitext(os.path.basename(edited_file))[0].replace(".edited", "") + test_base = os.path.splitext(os.path.basename(edited_file))[0].replace( + ".edited", "" + ) self._run_edited_tests(edited_file, test_base) - - plotter = Plotter(self.db) + test_name = self.tests_folder.split("/")[-1] + plotter = Plotter(self.db, test_name) plots = plotter.create_plots() - plots_dir = os.path.join(self.run_folder, "plots") os.makedirs(plots_dir, exist_ok=True) - def save_plot(name, fig): """Handles the saving of the figure to a specific directory.""" path = os.path.join(plots_dir, f"{name}.svg") @@ -376,31 +512,55 @@ class Experiment: save_plot("exhaustive_edited", plots["exhaustive_edited"]) save_plot("guided", plots["guided"]) save_plot("guided_edited", plots["guided_edited"]) - save_plot("exhaustive_fault_types_normal", plots["exhaustive_fault_types_normal"]) - save_plot("exhaustive_fault_types_hard", plots["exhaustive_fault_types_hard"]) - save_plot("exhaustive_fault_types_normal_edited", plots["exhaustive_fault_types_normal_edited"]) + save_plot( + "exhaustive_fault_types_normal", plots["exhaustive_fault_types_normal"] + ) + save_plot( + "exhaustive_fault_types_hard", plots["exhaustive_fault_types_hard"] + ) + save_plot( + "exhaustive_fault_types_sc", plots["exhaustive_fault_types_sc"] + ) + save_plot( + "exhaustive_fault_types_vd", plots["exhaustive_fault_types_vd"] + ) + save_plot( + "exhaustive_fault_types_normal_edited", + plots["exhaustive_fault_types_normal_edited"], + ) save_plot("guided_fault_types_normal", plots["guided_fault_types_normal"]) save_plot("guided_fault_types_hard", plots["guided_fault_types_hard"]) - save_plot("guided_fault_types_normal_edited", plots["guided_fault_types_normal_edited"]) + save_plot("guided_fault_types_sc", plots["guided_fault_types_sc"]) + save_plot("guided_fault_types_vd", plots["guided_fault_types_vd"]) + save_plot( + "guided_fault_types_normal_edited", + plots["guided_fault_types_normal_edited"], + ) if self.plot_mode == "show" or self.plot_mode == "both": print("Showing Plots...") plt.show() for fig in plots.values(): plt.close(fig) - - # symex exported as CSV instead of plot - symex_csv_path = os.path.join(plots_dir, "symex_results.csv") - plotter.export_symex_csv(symex_csv_path) + if not self.args.skip_minimc: + # symex exported as CSV instead of plot + symex_csv_path = os.path.join(plots_dir, "symex_results.csv") + plotter.export_symex_csv(symex_csv_path) self.db.close() - - zip_base = os.path.join(self.artifacts_folder, self.run_name) + + prompt = f"Name for artifact zip (default: {self.run_name}): " + try: + name = input(prompt).strip() + except EOFError: + name = "" + if not name: + name = self.run_name + + zip_base = os.path.join(self.artifacts_folder, name) temp_name = os.path.join(self.artifacts_folder, "test_results") os.rename(self.run_folder, temp_name) - shutil.make_archive( - zip_base, "zip", self.artifacts_folder, "test_results" - ) + shutil.make_archive(zip_base, "zip", self.artifacts_folder, "test_results") shutil.rmtree(temp_name) print(f"\nArtifacts saved to: {zip_base}.zip") @@ -422,7 +582,7 @@ class Experiment: os.makedirs(self.runner.compiled_folder, exist_ok=True) for f in os.listdir(self.tests_folder): - if f.endswith(".trv") or f.endswith(".trv.output") or f.endswith(".wh"): + if f.endswith(".trv") or f.endswith(".trv.output") or f.endswith(".wh") or f == "test.conf": shutil.copy(os.path.join(self.tests_folder, f), self.run_tests_folder) self.db = ResultsDatabase(db_path) @@ -486,6 +646,11 @@ if __name__ == "__main__": action="store_true", help="Only setup and compile, skip running tests", ) + parser.add_argument( + "--skip-minimc", + action="store_true", + help="Only setup and compile, skip running tests", + ) parser.add_argument( "--limit", type=int, @@ -498,6 +663,8 @@ if __name__ == "__main__": help="Skip hardened version when running tests", ) parser.add_argument("--hard", action="store_true", help="Only run hardened version") + parser.add_argument("--replot", type=str, metavar="FOLDER", + help="Replot all plots from a test_results folder") args, unknown = parser.parse_known_args() force = "-f" in unknown or "--reinit" in unknown @@ -505,6 +672,10 @@ if __name__ == "__main__": if args.setup: exit(run_setup(target=args.setup, force=force)) + if args.replot: + replot(args.replot) + sys.exit(0) + missing_bins = get_missing_binaries() if missing_bins: print(f"\033[91mError: Binaries not found: {', '.join(missing_bins)}\033[0m") @@ -514,7 +685,6 @@ if __name__ == "__main__": print("Run 'test --setup' to compile the binary") exit(1) - if args.nohard and args.hard: print("Error: Cannot use both --nohard and --hard") exit() @@ -524,6 +694,6 @@ if __name__ == "__main__": elif args.nohard: run_variants = "normal" else: - run_variants = "both" + run_variants = "all" exp = Experiment(args, run_variants) exp.run() diff --git a/testing/src/oracles.py b/testing/src/oracles.py new file mode 100644 index 0000000..faad94c --- /dev/null +++ b/testing/src/oracles.py @@ -0,0 +1,148 @@ +import math +class Oracle: + def __init__(self): + self.oracle_map = { + "hash": hash_check_passed, + "pinny": pinny_check_passed, + "crt": crt_check_passed, + } + + def get(self, test_folder: str): + if test_folder is None: + raise Exception("test_folder not found in config") + test_name = test_folder.split("/")[-1] + return self.oracle_map.get(test_name) + + +def hash_check_passed(result, pass_mode_config, cm_start, cm_end, injection_point): + mode = pass_mode_config.get("mode", "stdout") + expected_pass = pass_mode_config.get("expected_pass", None) + expected_fail = pass_mode_config.get("expected_fail", None) + + + if cm_start is not None and cm_end is not None and injection_point is not None and result.returncode == 77: + parts = injection_point.split(":") + if parts[0] == "pc": + pc_value = int(parts[1]) + bit_value = int(parts[2]) + mask = 1 << bit_value + flipped_pc = pc_value ^ mask + if flipped_pc in range(cm_start, cm_end + 1): + return 78 + if "panic" in result.stderr: + return 2 + if "COUNTERMEASURE" in result.stdout or result.returncode == 77: + return 77 + elif "Detected Infinite Loop" in result.stdout: + return 3 + + if mode == "stdout": + if expected_pass and str(expected_pass) in result.stdout: + return 1 + elif expected_fail and str(expected_fail) in result.stdout: + return 0 + return 4 + else: + print(f"STDOUT: {result.stdout}") + print(f"STDERR: {result.stderr}") + print(f"RETURNCODE: {result.returncode}") + raise ValueError(f"Unknown pass mode: {mode}") + +def calc_passed_val(actual_output, expected_fail, n_value, expected_pass) -> bool: + diff = abs(actual_output - expected_pass) + recovered = math.gcd(diff, n_value) + if recovered == expected_fail: + return True + return + +def crt_check_passed(result, pass_mode_config, cm_start, cm_end, injection_point): + got_p = False + got_q = False + mode = pass_mode_config.get("mode", "stdout") + expected_pass, n_value = pass_mode_config.get("expected_pass", None).split(",") + expected_pass = int(expected_pass) + n_value = int(n_value) + expected_fail_p, expected_fail_q, unencrypted_msg = pass_mode_config.get("expected_fail", None).split(",") + expected_fail_p = int(expected_fail_p) + expected_fail_q = int(expected_fail_q) + unencrypted_msg = int(unencrypted_msg) + + actual_output = None + try: + actual_output = int(result.stdout.strip().splitlines()[-2]) + except: + actual_output = None + + if actual_output is not None: + got_p = calc_passed_val(actual_output, expected_fail_p, n_value, expected_pass) + got_q = calc_passed_val(actual_output, expected_fail_q, n_value, expected_pass) + + if cm_start is not None and cm_end is not None and injection_point is not None and result.returncode == 77: + parts = injection_point.split(":") + if parts[0] == "pc": + pc_value = int(parts[1]) + bit_value = int(parts[2]) + mask = 1 << bit_value + flipped_pc = pc_value ^ mask + if flipped_pc in range(cm_start, cm_end + 1): + return 78 + + if "panic" in result.stderr: + return 2 + if "COUNTERMEASURE" in result.stdout or result.returncode == 77: + return 77 + elif "Detected Infinite Loop" in result.stdout: + return 3 + if mode == "stdout": + if expected_pass and str(expected_pass) in result.stdout: + return 1 + if unencrypted_msg and str(unencrypted_msg) in result.stdout: + return 4 + elif got_p or got_q: + return 0 + else: + return 7 + else: + print(f"STDOUT: {result.stdout}") + print(f"STDERR: {result.stderr}") + print(f"RETURNCODE: {result.returncode}") + raise ValueError(f"Unknown pass mode: {mode}") + + +def pinny_check_passed(result, pass_mode_config, cm_start, cm_end, injection_point): + mode = pass_mode_config.get("mode", "returncode") + expected_pass = pass_mode_config.get("expected_pass", None) + expected_fail = pass_mode_config.get("expected_fail", None) + if cm_start is not None and cm_end is not None and injection_point is not None and result.returncode == 77: + parts = injection_point.split(":") + if parts[0] == "pc": + pc_value = int(parts[1]) + bit_value = int(parts[2]) + mask = 1 << bit_value + flipped_pc = pc_value ^ mask + if flipped_pc in range(cm_start, cm_end + 1): + return 78 + if "COUNTERMEASURE" in result.stdout or result.returncode == 77: + return 77 + elif "Detected Infinite Loop" in result.stdout: + return 3 + elif "panic" in result.stderr: + return 2 + if mode == "returncode": + if int(result.returncode) == int(expected_pass): + return 1 + elif int(result.returncode) == int(expected_fail): + return 0 + else: + return 7 + elif mode == "stdout": + if expected_pass and str(expected_pass) in result.stdout: + return 1 + elif expected_fail and str(expected_fail) in result.stdout: + return 0 + return 1 + else: + print(f"STDOUT: {result.stdout}") + print(f"STDERR: {result.stderr}") + print(f"RETURNCODE: {result.returncode}") + raise ValueError(f"Unknown pass mode: {mode}") diff --git a/testing/src/plotenator.py b/testing/src/plotenator.py index 4a76fd8..d551060 100644 --- a/testing/src/plotenator.py +++ b/testing/src/plotenator.py @@ -2,23 +2,36 @@ from src.database import ResultsDatabase import matplotlib.pyplot as plt import pandas as pd -import textwrap OUTCOME_COLOR_MAP = { "Normal Execution": "#4daf4a", - "Faulty": "#ff2a2c", + "Faulty (Authenticated = 1)": "#ff2a2c", + "Faulty (Message Leaked)": "#ff2a2c", + "Faulty (P or Q Derived)": "#ff2a2c", "Panicked": "#984ea3", - "Infinite Loop": "#ff7f00", + "Infinite Loop": "#555555", + "Message Leaked": "#e6ab02", + "Wrong Hash Returned": "#e6ab02", + "Faulty Encryption": "#ff7f00", "Countermeasure Activated": "#377eb8", - "Faulty Jump to Countermeasure": "#377eb8", - "Other": "#C9A227", + "Faulty Jump to Countermeasure": "#00FFFF", + "Other": "#FFFF00", } OUTCOME_COLORS = list(OUTCOME_COLOR_MAP.values()) -FAULT_TYPE_COLORS = ["#a6cee3", "#ff4411", "#b2df8a"] +FAULT_TYPE_COLOR_MAP = {"PC": "#a6cee3", "REG": "#ff4411", "CPSR": "#b2df8a"} +FIG_WIDTH = 13 +FIG_HEIGHT = 8 +LABEL_WRAP_WIDTH = 14 class Plotter: - def __init__(self, db: ResultsDatabase): + def __init__(self, db: ResultsDatabase, test_name: str): self.db = db + self.test_name = test_name + + @property + def display_test_name(self): + mapping = {"crt": "Encrypty", "hash": "Hashy", "pinny": "Pinny"} + return mapping.get(self.test_name.lower(), self.test_name.capitalize()) def create_plots(self): return { @@ -28,12 +41,101 @@ def create_plots(self): "guided_edited": self.plot_guided(edited=True), "exhaustive_fault_types_normal": self.plot_fault_types(edited=False, table="exhaustive", variant="normal"), "exhaustive_fault_types_hard": self.plot_fault_types(edited=False, table="exhaustive", variant="hard"), + "exhaustive_fault_types_sc": self.plot_fault_types(edited=False, table="exhaustive", variant="sc"), + "exhaustive_fault_types_vd": self.plot_fault_types(edited=False, table="exhaustive", variant="vd"), "exhaustive_fault_types_normal_edited": self.plot_fault_types(edited=True, table="exhaustive", variant="normal"), "guided_fault_types_normal": self.plot_fault_types(edited=False, table="guided", variant="normal"), "guided_fault_types_hard": self.plot_fault_types(edited=False, table="guided", variant="hard"), + "guided_fault_types_sc": self.plot_fault_types(edited=False, table="guided", variant="sc"), + "guided_fault_types_vd": self.plot_fault_types(edited=False, table="guided", variant="vd"), "guided_fault_types_normal_edited": self.plot_fault_types(edited=True, table="guided", variant="normal"), } + @staticmethod + def _wrap_label(label, width=LABEL_WRAP_WIDTH): + words = label.split() + if len(label) <= width or len(words) <= 1: + return label + lines = [] + current_line = [words[0]] + for word in words[1:]: + if len(' '.join(current_line + [word])) > width: + lines.append(' '.join(current_line)) + current_line = [word] + else: + current_line.append(word) + lines.append(' '.join(current_line)) + return '\n'.join(lines) + + def get_return_labels(self, variant=None): + if variant == "normal": + if self.test_name == "crt": + return { + 0: "Faulty (P or Q Derived)", + 1: "Normal Execution", + 2: "Panicked", + 3: "Infinite Loop", + 4: "Message Leaked", + 7: "Faulty Encryption", + 77: "Faulty Encryption", + "Other": "Other", + } + elif self.test_name == "pinny": + return { + 0: "Faulty (Authenticated = 1)", + 1: "Normal Execution", + 2: "Panicked", + 3: "Infinite Loop", + "Other": "Other", + } + elif self.test_name == "hash": + return { + 0: "Faulty (Message Leaked)", + 1: "Normal Execution", + 2: "Panicked", + 4: "Wrong Hash Returned", + 3: "Infinite Loop", + 77: "Wrong Hash Returned", + "Other": "Other", + } + else: + raise Exception("something wrong with the name") + + if self.test_name == "crt": + return { + 0: "Faulty (P or Q Derived)", + 1: "Normal Execution", + 2: "Panicked", + 3: "Infinite Loop", + 4: "Message Leaked", + 7: "Faulty Encryption", + 77: "Countermeasure Activated", + 78: "Faulty Jump to Countermeasure", + "Other": "Other", + } + elif self.test_name == "pinny": + return { + 0: "Faulty (Authenticated = 1)", + 1: "Normal Execution", + 2: "Panicked", + 3: "Infinite Loop", + 77: "Countermeasure Activated", + 78: "Faulty Jump to Countermeasure", + "Other": "Other", + } + elif self.test_name == "hash": + return { + 0: "Faulty (Message Leaked)", + 1: "Normal Execution", + 2: "Panicked", + 4: "Wrong Hash Returned", + 3: "Infinite Loop", + 77: "Countermeasure Activated", + 78: "Faulty Jump to Countermeasure", + "Other": "Other", + } + else: + raise Exception("something wrong with the name") def plot_exhaustive(self, edited=False): suffix = " (Guided Manual Hardening)" if edited else "" @@ -41,28 +143,35 @@ def plot_exhaustive(self, edited=False): df = self.db.query_df(f"SELECT * FROM exhaustive_interpreter_results {where}") if df.empty: - fig, ax = plt.subplots() + fig, ax = plt.subplots(figsize=(FIG_WIDTH, FIG_HEIGHT)) ax.text(0.5, 0.5, f"No data{suffix}", ha='center', va='center', transform=ax.transAxes) - ax.set_title(f"Exhaustive Interpreter - Outcome Distribution{suffix}") + ax.set_title(f"Exhaustive Interpreter - Outcome Distribution of {self.display_test_name}{suffix}") return fig - known_codes = {0, 1, 2, 3, 77, 78} df = df.copy() - df["outcome"] = df["returncode"].apply( - lambda rc: rc if rc in known_codes else "Other" - ) + normal_labels = [] + returncode_labels = self.get_return_labels() + if not edited: + normal_labels = self.get_return_labels(variant="normal") + else: + normal_labels = self.get_return_labels() - returncode_labels = { - 0: "Normal Execution", - 1: "Faulty", - 2: "Panicked", - 3: "Infinite Loop", - 77: "Countermeasure Activated", - 78: "Faulty Jump to Countermeasure", - "Other": "Other", - } + normal_known = {k for k in normal_labels if isinstance(k, int)} + non_normal_known = {k for k in returncode_labels if isinstance(k, int)} + + def _get_outcome(row): + rc = row["passed"] + if row["variant"] == "normal": + known = normal_known + labels = normal_labels + else: + known = non_normal_known + labels = returncode_labels + code = rc if rc in known else "Other" + return labels.get(code, "Other") - fig, ax = plt.subplots() + df["outcome"] = df.apply(_get_outcome, axis=1) + fig, ax = plt.subplots(figsize=(FIG_WIDTH, FIG_HEIGHT)) if edited: counts = df["outcome"].value_counts().rename(returncode_labels) @@ -70,40 +179,64 @@ def plot_exhaustive(self, edited=False): if "Other" in counts.index: ordered_outcomes.append("Other") counts = counts[ordered_outcomes] - + counts = counts.sort_values(ascending=False) + if "Other" in counts.index: + other_val = counts.pop("Other") + counts["Other"] = other_val colors = [OUTCOME_COLOR_MAP.get(outcome, "#a65628") for outcome in counts.index] + counts.index = [self._wrap_label(l) for l in counts.index] + ax.bar(range(len(counts)), counts.values, color=colors) ax.set_xticks(range(len(counts))) - wrapped = [textwrap.fill(o, width=14) for o in counts.index] - ax.set_xticklabels(wrapped, ha='center') + ax.set_xticklabels(counts.index, ha='center') else: grouped = df.groupby(["variant", "outcome"]).size().unstack(fill_value=0) - grouped = grouped.rename(columns=returncode_labels) - col_order = [c for c in returncode_labels.values() if c != "Other" and c in grouped.columns] + all_label_values = list(normal_labels.values()) + list(returncode_labels.values()) + seen_labels = set() + unique_labels = [] + for l in all_label_values: + if l not in seen_labels: + seen_labels.add(l) + unique_labels.append(l) + + col_order = [c for c in unique_labels if c != "Other" and c in grouped.columns] if "Other" in grouped.columns: col_order.append("Other") grouped = grouped[col_order] - colors = [OUTCOME_COLOR_MAP.get(col, "#a65628") for col in grouped.columns] - grouped.plot(kind="bar", stacked=False, ax=ax, color=colors, legend=False) - - for container in ax.containers: - ax.bar_label( - container, - labels=[ - f'{int(v.get_height())}' if v.get_height() > 0 else '' - for v in container - ], - label_type='center', - fontsize=8, - rotation=90, - color='black', - fontweight='bold' - ) + variant_labels = {"sc": "Statement Counter", "vd": "Variable Duplication", "hard": "Hard", "normal" : "Normal"} + grouped.index = [variant_labels.get(v, v) for v in grouped.index] + + variants = grouped.index.tolist() + n_variants = len(variants) + max_bars = max((grouped.loc[v] > 0).sum() for v in variants) if variants else 1 + group_width = 0.8 + + seen_outcomes = set() + for i, variant in enumerate(variants): + row = grouped.loc[variant] + sorted_row = row.sort_values(ascending=False) + sorted_row = sorted_row[sorted_row > 0] + n = len(sorted_row) + for j, (outcome, val) in enumerate(sorted_row.items()): + if n == 1: + x = i + else: + x = i - group_width / 2 + (j + 0.5) * group_width / n + color = OUTCOME_COLOR_MAP.get(outcome, "#a65628") + label = outcome if outcome not in seen_outcomes else None + if label: + seen_outcomes.add(outcome) + ax.bar(x, val, width=0.9 * group_width / n, color=color, label=label) + + ax.set_xticks(range(n_variants)) + ax.set_xticklabels(variants) + + self._label_bars(ax) self._add_horizontal_legend(fig, ax, "Outcome") - ax.set_title(f"Exhaustive Interpreter - Outcome Distribution{suffix}") + ax.set_title(f"Exhaustive Interpreter - Outcome Distribution of {self.display_test_name}{suffix}") ax.set_xlabel(None) self._apply_scale(ax) @@ -115,8 +248,28 @@ def plot_exhaustive(self, edited=False): y_pos = (ymin * val) ** 0.5 else: y_pos = val / 2 - ax.text(i, y_pos, f'{int(val)}', ha='center', va='center', - fontsize=8, rotation=90, color='black', fontweight='bold') + + # --- 1. CALCULATE THE ACTUAL BAR HEIGHT IN PIXELS --- + # Convert the top of your bar (val) and the bottom of the axis (ymin) to pixel coordinates + pixel_top = ax.transData.transform((i, val)) + pixel_bottom = ax.transData.transform((i, ymin)) + bar_height_pixels = pixel_top - pixel_bottom + + # --- 2. CALCULATE THE LABEL HEIGHT IN PIXELS --- + # (Using the same length logic you had) + num_digits = len(str(int(val))) # Use int(val) since that's what you display + dpi = ax.get_figure().dpi + char_width_pixels = (12 * 0.6) * (dpi / 10) + label_height_pixels = num_digits * char_width_pixels + + # Draw the text + if y_pos > label_height_pixels: + ax.text(i, y_pos, f'{int(val)}', ha='center', va='center', + fontsize=12, rotation=90, color='black', fontweight='bold') + else: + ax.text(i, y_pos*2, f'{int(val)}', ha='center', va='top', + fontsize=12, rotation=90, color='black', fontweight='bold') + self._style_axes(ax) @@ -128,28 +281,30 @@ def plot_guided(self, edited=False): df = self.db.query_df(f"SELECT * FROM guided_interpreter_results {where}") if df.empty: - fig, ax = plt.subplots() + fig, ax = plt.subplots(figsize=(FIG_WIDTH, FIG_HEIGHT)) ax.text(0.5, 0.5, f"No data{suffix}", ha='center', va='center', transform=ax.transAxes) - ax.set_title(f"Guided Interpreter - Outcome Distribution{suffix}") + ax.set_title(f"Guided Interpreter - Outcome Distribution of {self.display_test_name}{suffix}") return fig - known_codes = {0, 1, 2, 3, 77, 78} df = df.copy() - df["outcome"] = df["returncode"].apply( - lambda rc: rc if rc in known_codes else "Other" - ) - - returncode_labels = { - 0: "Normal Execution", - 1: "Faulty", - 2: "Panicked", - 3: "Infinite Loop", - 77: "Countermeasure Activated", - 78: "Faulty Jump to Countermeasure", - "Other": "Other", - } - - fig, ax = plt.subplots() + returncode_labels = self.get_return_labels() + normal_labels = self.get_return_labels(variant="normal") + normal_known = {k for k in normal_labels if isinstance(k, int)} + non_normal_known = {k for k in returncode_labels if isinstance(k, int)} + + def _get_outcome(row): + rc = row["passed"] + if row["variant"] == "normal": + known = normal_known + labels = normal_labels + else: + known = non_normal_known + labels = returncode_labels + code = rc if rc in known else "Other" + return labels.get(code, "Other") + + df["outcome"] = df.apply(_get_outcome, axis=1) + fig, ax = plt.subplots(figsize=(FIG_WIDTH, FIG_HEIGHT)) if edited: counts = df["outcome"].value_counts().rename(returncode_labels) @@ -157,40 +312,64 @@ def plot_guided(self, edited=False): if "Other" in counts.index: ordered_outcomes.append("Other") counts = counts[ordered_outcomes] - + counts = counts.sort_values(ascending=False) + if "Other" in counts.index: + other_val = counts.pop("Other") + counts["Other"] = other_val colors = [OUTCOME_COLOR_MAP.get(outcome, "#a65628") for outcome in counts.index] + counts.index = [self._wrap_label(l) for l in counts.index] + ax.bar(range(len(counts)), counts.values, color=colors) ax.set_xticks(range(len(counts))) - wrapped = [textwrap.fill(o, width=14) for o in counts.index] - ax.set_xticklabels(wrapped, ha='center') + ax.set_xticklabels(counts.index, ha='center') else: grouped = df.groupby(["variant", "outcome"]).size().unstack(fill_value=0) - grouped = grouped.rename(columns=returncode_labels) - col_order = [c for c in returncode_labels.values() if c != "Other" and c in grouped.columns] + all_label_values = list(normal_labels.values()) + list(returncode_labels.values()) + seen_labels = set() + unique_labels = [] + for l in all_label_values: + if l not in seen_labels: + seen_labels.add(l) + unique_labels.append(l) + + col_order = [c for c in unique_labels if c != "Other" and c in grouped.columns] if "Other" in grouped.columns: col_order.append("Other") grouped = grouped[col_order] - colors = [OUTCOME_COLOR_MAP.get(col, "#a65628") for col in grouped.columns] - grouped.plot(kind="bar", stacked=False, ax=ax, color=colors, legend=False) - - for container in ax.containers: - ax.bar_label( - container, - labels=[ - f'{int(v.get_height())}' if v.get_height() > 0 else '' - for v in container - ], - label_type='center', - fontsize=8, - rotation=90, - color='black', - fontweight='bold' - ) + variant_labels = {"sc": "Statement Counter", "vd": "Variable Duplication", "hard": "Hard", "normal" : "Normal"} + grouped.index = [variant_labels.get(v, v) for v in grouped.index] + + variants = grouped.index.tolist() + n_variants = len(variants) + max_bars = max((grouped.loc[v] > 0).sum() for v in variants) if variants else 1 + group_width = 0.8 + + seen_outcomes = set() + for i, variant in enumerate(variants): + row = grouped.loc[variant] + sorted_row = row.sort_values(ascending=False) + sorted_row = sorted_row[sorted_row > 0] + n = len(sorted_row) + for j, (outcome, val) in enumerate(sorted_row.items()): + if n == 1: + x = i + else: + x = i - group_width / 2 + (j + 0.5) * group_width / n + color = OUTCOME_COLOR_MAP.get(outcome, "#a65628") + label = outcome if outcome not in seen_outcomes else None + if label: + seen_outcomes.add(outcome) + ax.bar(x, val, width=0.9 * group_width / n, color=color, label=label) + + ax.set_xticks(range(n_variants)) + ax.set_xticklabels(variants) + + self._label_bars(ax) self._add_horizontal_legend(fig, ax, "Outcome") - ax.set_title(f"Guided Interpreter - Outcome Distribution{suffix}") + ax.set_title(f"Guided Interpreter - Outcome Distribution of {self.display_test_name}{suffix}") ax.set_xlabel(None) self._apply_scale(ax) @@ -203,7 +382,7 @@ def plot_guided(self, edited=False): else: y_pos = val / 2 ax.text(i, y_pos, f'{int(val)}', ha='center', va='center', - fontsize=8, rotation=90, color='black', fontweight='bold') + fontsize=12, rotation=90, color='black', fontweight='bold') self._style_axes(ax) @@ -214,14 +393,6 @@ def _style_axes(self, ax: Axes): ax.yaxis.label.set_fontweight('bold') ax.tick_params(axis='x', rotation=0) - wrapped_labels = [] - for label in ax.get_xticklabels(): - text = label.get_text() - wrapped_text = textwrap.fill(text, width=14) - wrapped_labels.append(wrapped_text) - - ax.set_xticklabels(wrapped_labels, ha='center') - def _apply_scale(self, ax: Axes, ratio_threshold=10): heights = [] for container in ax.containers: @@ -245,17 +416,28 @@ def _apply_scale(self, ax: Axes, ratio_threshold=10): ax.set_ylabel("Count") ymin, ymax = ax.get_ylim() - def _add_horizontal_legend(self, fig, ax, title, wrap_width=14): + def _label_bars(self, ax): + for container in ax.containers: + ax.bar_label( + container, + labels=[f'{int(v.get_height())}' if v.get_height() > 0 else '' for v in container], + label_type='center', + fontsize=12, + rotation=90, + color='black', + fontweight='bold' + ) + + def _add_horizontal_legend(self, fig, ax, title): handles, labels = ax.get_legend_handles_labels() - wrapped = [textwrap.fill(l, width=wrap_width) for l in labels] leg = fig.legend( - handles, wrapped, + handles, labels, title=title, loc='lower center', bbox_to_anchor=(0.5, 0.05), - ncol=min(len(handles), 4), - fontsize=8, - title_fontsize=9, + ncol=min(len(handles), 6), + fontsize=12, + title_fontsize=13, frameon=True, ) leg.get_title().set_fontweight('bold') @@ -286,65 +468,61 @@ def plot_fault_types(self, edited=False, table="exhaustive", variant="normal"): if df.empty: fig, ax = plt.subplots() - display_label = variant.title() + variant_display = {"sc": "Statement Counter", "vd": "Variable Duplication", "hard": "Hard", "normal" : "Normal"} + display_label = variant_display.get(variant, variant.title()) ax.text(0.5, 0.5, f"No data ({display_label}){suffix}", ha='center', va='center', transform=ax.transAxes) ax.set_title(f"Fault Type Distribution - {display_label}{suffix}") return fig fault_outcomes = df.copy() - known_codes = {0, 1, 2, 3, 77, 78} - fault_outcomes["outcome"] = fault_outcomes["returncode"].apply( + returncode_labels = self.get_return_labels(variant=variant) + known_codes = {k for k in returncode_labels if isinstance(k, int)} + fault_outcomes["outcome"] = fault_outcomes["passed"].apply( lambda rc: rc if rc in known_codes else "Other" ) - - returncode_labels = { - 0: "Normal Execution", - 1: "Faulty", - 2: "Panicked!", - 3: "Infinite Loop", - 77: "Countermeasure Activated", - 78: "Faulty Jump to Countermeasure", - "Other": "Other", - } fault_outcomes["outcome"] = fault_outcomes["outcome"].map(returncode_labels) fault_type_map = {"pc": "PC", "reg": "REG", "cpsr": "CPSR"} fault_outcomes["fault_type_label"] = fault_outcomes["fault_type"].map(fault_type_map) + if edited: + fault_outcomes = fault_outcomes[fault_outcomes["fault_type_label"] == "REG"] + grouped = fault_outcomes.groupby(["outcome", "fault_type_label"]).size().unstack(fill_value=0) - ordered_outcomes = [c for c in returncode_labels.values() if c != "Other" and c in grouped.index] + seen_outcomes = set() + ordered_outcomes = [] + for c in returncode_labels.values(): + if c != "Other" and c in grouped.index and c not in seen_outcomes: + seen_outcomes.add(c) + ordered_outcomes.append(c) if "Other" in grouped.index: ordered_outcomes.append("Other") grouped = grouped.reindex(ordered_outcomes) + row_totals = grouped.sum(axis=1) + grouped = grouped.loc[row_totals.sort_values(ascending=False).index] + if "Other" in grouped.index: + other_row = grouped.loc[["Other"]] + grouped = pd.concat([grouped.drop("Other"), other_row]) - ordered_cols = ["PC", "REG", "CPSR"] + ordered_cols = ["REG"] if edited else ["PC", "REG", "CPSR"] for col in ordered_cols: if col not in grouped.columns: grouped[col] = 0 grouped = grouped[ordered_cols] + grouped.index = [self._wrap_label(l) for l in grouped.index] - fig, ax = plt.subplots() - grouped.plot(kind="bar", stacked=False, ax=ax, color=FAULT_TYPE_COLORS[:len(grouped.columns)], legend=False) + fig, ax = plt.subplots(figsize=(FIG_WIDTH, FIG_HEIGHT)) + grouped.plot(kind="bar", stacked=False, ax=ax, color=[FAULT_TYPE_COLOR_MAP[c] for c in grouped.columns], legend=False) - for container in ax.containers: - ax.bar_label( - container, - labels=[ - f'{int(v.get_height())}' if v.get_height() > 0 else '' - for v in container - ], - label_type='center', - fontsize=8, - rotation=90, - color='black', - fontweight='bold' - ) + self._label_bars(ax) interpreter_name = "Exhaustive" if table == "exhaustive" else "Guided" - display_label = variant.title() - ax.set_title(f"{interpreter_name} - Fault Type Distribution - {display_label}{suffix}") + variant_display = {"sc": "Statement Counter", "vd": "Variable Duplication", "hard": "Hard", "normal" : "Normal"} + display_label = variant_display.get(variant, variant.title()) + + ax.set_title(f"{interpreter_name} - Fault Type Distribution ({self.display_test_name}, {display_label}){suffix}") ax.set_xlabel(None) self._apply_scale(ax) self._add_horizontal_legend(fig, ax, "Fault Type") diff --git a/testing/src/symexrunner.py b/testing/src/symexrunner.py index bf86b46..e542ffa 100644 --- a/testing/src/symexrunner.py +++ b/testing/src/symexrunner.py @@ -17,53 +17,75 @@ def __init__(self, config_path=None): bin_dir = os.path.join(os.path.dirname(__file__), "..", "bin") self.minimc_path = os.path.join(bin_dir, "minimc") def run(self, run_variants): - wh_files = sorted( - [ - f - for f in os.listdir(self.artifacts_folder) - if f.endswith(".wh") - and ( - run_variants == "both" - or (run_variants == "normal" and not f.endswith(".hard.wh")) - or (run_variants == "hard" and f.endswith(".hard.wh")) - ) - ] - ) - - all_results = [] - - for wh_file in wh_files: - wh_path = os.path.join(self.artifacts_folder, wh_file) - print(f"Running MiniMC on {wh_file}") - cmd = [self.minimc_path, wh_path, "mc", "--mc.symbolic", "--mc.all", "--mc.concretize"] - - result = subprocess.run( - cmd, - cwd=self.tests_folder, - capture_output=True, - text=True, - env={**os.environ, "TERM": "dumb"}, # cleaner output - ) - - violations = extract_violations(result.stdout) - parsed = [parse_violation(v) for v in violations] - variant = "Normal" - if wh_file.__contains__(".hard.wh"): - variant = "Hard" - - - for v in parsed: - all_results.append( - { - "test": wh_file.replace(".hard.wh", "").replace(".wh", ""), - "variant": variant, - "stmt": v.get("stmt"), - "faulty_bit": v.get("bit_shift"), - "result": v.get("res"), - } + # 1. Gather and filter the files based on the requested run_variants strategy + wh_files = [] + for f in os.listdir(self.artifacts_folder): + if not f.endswith(".wh"): + continue + + is_hard = f.endswith(".hard.wh") + is_vd = f.endswith(".vd.wh") + is_sc = f.endswith(".sc.wh") + is_normal = not (is_hard or is_vd or is_sc) + + if ( + run_variants == "all" + or (run_variants == "normal" and is_normal) + or (run_variants == "hard" and is_hard) + or (run_variants == "vd" and is_vd) + or (run_variants == "sc" and is_sc) + ): + wh_files.append(f) + + wh_files.sort() + + all_results = [] + + for wh_file in wh_files: + wh_path = os.path.join(self.artifacts_folder, wh_file) + print(f"Running MiniMC on {wh_file}") + cmd = [self.minimc_path, wh_path, "mc", "--mc.symbolic", "--mc.all", "--mc.concretize"] + + result = subprocess.run( + cmd, + cwd=self.tests_folder, + capture_output=True, + text=True, + env={**os.environ, "TERM": "dumb"}, # cleaner output ) - return all_results + violations = extract_violations(result.stdout) + parsed = [parse_violation(v) for v in violations] + + # 2. Determine the clean variant name string + if wh_file.endswith(".hard.wh"): + variant = "Hard" + elif wh_file.endswith(".vd.wh"): + variant = "VD" + elif wh_file.endswith(".sc.wh"): + variant = "SC" + else: + variant = "Normal" + + # 3. Strip all suffixes from the test name cleanly + test_name = wh_file + for suffix in [".hard.wh", ".vd.wh", ".sc.wh", ".wh"]: + if test_name.endswith(suffix): + test_name = test_name[:-len(suffix)] + break + + for v in parsed: + all_results.append( + { + "test": test_name, + "variant": variant, + "stmt": v.get("stmt"), + "faulty_bit": v.get("bit_shift"), + "result": v.get("res"), + } + ) + + return all_results def strip_ansi(text): diff --git a/testing/src/testrunner.py b/testing/src/testrunner.py index 8503a9e..0df371f 100644 --- a/testing/src/testrunner.py +++ b/testing/src/testrunner.py @@ -1,3 +1,4 @@ +from pathlib import Path import os import re import subprocess @@ -49,49 +50,6 @@ def _get_countermeasure_location_range(asm_path: str): # start, end = _get_countermeasure_location_range("code.s") # print(f"Countermeasure range: {start} to {end}") -def _fault_worker(args): - asm_path, injection_point, pass_mode_config = args - - bin_dir = os.path.join(os.path.dirname(__file__), "..", "bin") - interpreter_path = os.path.join(bin_dir, "interpreter") - - cmd = [interpreter_path, asm_path, "--injection-point", injection_point, "--test-mode"] - - result = subprocess.run(cmd, cwd=bin_dir, capture_output=True, text=True) - - (cm_start, cm_end) = _get_countermeasure_location_range(asm_path) - passed = _check_passed(result, pass_mode_config, cm_start, cm_end, injection_point) - - matched_output_line = None - if pass_mode_config.get("mode") == "stdout": - expected_pass = pass_mode_config.get("expected_pass", "") - expected_fail = pass_mode_config.get("expected_fail", "") - - stdout_lines = result.stdout.strip().split("\n") - - if passed and expected_pass: - for line in stdout_lines: - if expected_pass in line: - matched_output_line = line.strip() - break - elif not passed and expected_fail: - for line in stdout_lines: - if expected_fail in line: - matched_output_line = line.strip() - break - - if matched_output_line is None: - matched_output_line = "N/A" - return { - "injection_point": injection_point, - "returncode": result.returncode, - "stdout": result.stdout.strip(), - "stderr": result.stderr.strip(), - "expected_output": pass_mode_config.get("expected_pass", ""), - "matched_output_line": matched_output_line, - "passed": passed, - "test_report": _extract_test_report(result.stdout), - } def _extract_test_report(stdout: str): keyword = r'"title":\s*"test_report"' @@ -101,47 +59,10 @@ def _extract_test_report(stdout: str): return match.group(0) return '{"title": "test_report"}' -def _check_passed(result, pass_mode_config, cm_start, cm_end, injection_point): - mode = pass_mode_config.get("mode", "returncode") - expected_pass = pass_mode_config.get("expected_pass", None) - expected_fail = pass_mode_config.get("expected_fail", None) - - if "COUNTERMEASURE" in result.stdout or result.returncode == 77: - return 77 - elif "Detected Infinite Loop" in result.stdout: - return 3 - if mode == "returncode" and result.returncode == 0: - return 1 - elif "panic" in result.stderr: - return 2 - elif mode == "returncode" and result.returncode != 0: - if cm_start is not None and cm_end is not None and injection_point is not None: - parts = injection_point.split(":") - if parts[0] == "pc": - pc_value = int(parts[1]) - bit_value = int(parts[2]) - mask = 1 << bit_value - flipped_pc = pc_value ^ mask - if(flipped_pc in range(cm_start, cm_end+1)): - return 78 - return 0 - return 0 - return 0 - elif mode == "stdout": - if expected_pass and expected_pass in result.stdout: - return 1 - elif expected_fail and expected_fail in result.stdout and result.returncode == 1: - return 0 - return 1 - else: - print(f"STDOUT: {result.stdout}") - print(f"STDERR: {result.stderr}") - print(f"RETURNCODE: {result.returncode}") - raise ValueError(f"Unknown pass mode: {mode}") class TestRunner: - def __init__(self, config_path=None): + def __init__(self, config_path=None, oracle=None): if config_path is None: config_path = os.path.join(os.path.dirname(__file__), "..", "config.toml") @@ -152,6 +73,7 @@ def __init__(self, config_path=None): self.tests_folder = os.path.join( self.base_dir, config.get("test_folder", "fissc") ) + self.oracle = oracle self.artifacts_folder = os.path.join(self.base_dir, "artifacts") self.injection_points = config.get( "injection_points", @@ -171,11 +93,56 @@ def __init__(self, config_path=None): "r12", ], ) - self.default_pass_mode = config.get("pass_mode", {}).get("default", "returncode") - self.pass_mode_configs = config.get("pass_mode", {}) self.tests = self._discover_tests() self.compile_results = None + def _fault_worker(self, args): + asm_path, injection_point, pass_mode_config = args + + bin_dir = os.path.join(os.path.dirname(__file__), "..", "bin") + interpreter_path = os.path.join(bin_dir, "interpreter") + + cmd = [interpreter_path, asm_path, "--injection-point", injection_point, "--test-mode"] + + result = subprocess.run(cmd, cwd=bin_dir, capture_output=True, text=True) + + (cm_start, cm_end) = _get_countermeasure_location_range(asm_path) + passed = self._check_passed(result, pass_mode_config, cm_start, cm_end, injection_point) + + matched_output_line = None + if pass_mode_config.get("mode") == "stdout": + expected_pass = pass_mode_config.get("expected_pass", "") + expected_fail = pass_mode_config.get("expected_fail", "") + + stdout_lines = result.stdout.strip().split("\n") + + if passed and expected_pass: + for line in stdout_lines: + if expected_pass in line: + matched_output_line = line.strip() + break + elif not passed and expected_fail: + for line in stdout_lines: + if expected_fail in line: + matched_output_line = line.strip() + break + + if matched_output_line is None: + matched_output_line = "N/A" + return { + "injection_point": injection_point, + "returncode": result.returncode, + "stdout": result.stdout.strip(), + "stderr": result.stderr.strip(), + "expected_output": pass_mode_config.get("expected_pass", ""), + "matched_output_line": matched_output_line, + "passed": passed, + "test_report": _extract_test_report(result.stdout), + } + + def _check_passed(self, result, pass_mode_config, cm_start, cm_end, injection_point): + return self.oracle(result, pass_mode_config, cm_start, cm_end, injection_point) + def _discover_tests(self): tests = [] if not os.path.exists(self.tests_folder): @@ -186,17 +153,7 @@ def _discover_tests(self): for trv_file in trv_files: test_name = trv_file[:-4] - output_file = trv_file + ".output" - toml_file = trv_file + ".toml" - - if output_file not in files: - continue - trv_path = os.path.join(self.tests_folder, trv_file) - output_path = os.path.join(self.tests_folder, output_file) - - with open(output_path, "r") as f: - expected_output = f.read().strip() pass_mode_config = self._load_pass_mode_config(test_name, trv_file, files) @@ -204,7 +161,7 @@ def _discover_tests(self): { "name": test_name, "path": trv_path, - "expected_output": expected_output, + "expected_output": "", "pass_mode": pass_mode_config, } ) @@ -212,29 +169,37 @@ def _discover_tests(self): return tests def _load_pass_mode_config(self, test_name, trv_file, files): - toml_file = trv_file + ".toml" - - if toml_file in files: - toml_path = os.path.join(self.tests_folder, toml_file) - with open(toml_path, "r") as f: - test_config = toml.load(f) - pass_mode = test_config.get("pass_mode", {}) - if "mode" in pass_mode: - mode = pass_mode["mode"] - mode_config = self.pass_mode_configs.get(mode, {}) + conf_file = "test.conf" + + if conf_file in files: + conf_path = os.path.join(self.tests_folder, conf_file) + config = {} + with open(conf_path, "r") as f: + for line in f: + line = line.strip() + if not line or ":" not in line: + continue + key, _, value = line.partition(":") + config[key.strip()] = value.strip() + + mode = config.get("mode", "returncode") + if mode == "returncode": + return { + "mode": mode, + "expected_pass": int(config.get("passed", "0")), + "expected_fail": int(config.get("failed", "1")), + } + else: return { "mode": mode, - "expected_pass": pass_mode.get("passed", 0) if mode == "returncode" else pass_mode.get("expected_pass"), - "expected_fail": pass_mode.get("failed", 1) if mode == "returncode" else pass_mode.get("expected_fail"), + "expected_pass": config.get("passed", ""), + "expected_fail": config.get("failed", ""), } - mode = self.default_pass_mode - mode_config = self.pass_mode_configs.get(mode, {}) - return { - "mode": mode, - "expected_pass": mode_config.get("passed", 0) if mode == "returncode" else mode_config.get("expected_pass"), - "expected_fail": mode_config.get("failed", 1) if mode == "returncode" else mode_config.get("expected_fail"), - } + raise FileNotFoundError( + f"Missing test.conf in {self.tests_folder}. " + "Each test folder must have a test.conf file defining mode, passed, and failed." + ) def check_bin(self): from pathlib import Path @@ -269,16 +234,24 @@ def compile_test(self, test, hard, compiled_folder): trv_path = test["path"] test_name = test["name"] - if hard: + if hard == "hard": asm_path = os.path.join(compiled_folder, f"{test_name}.hard") + elif hard == "sc": + asm_path = os.path.join(compiled_folder, f"{test_name}.sc") + elif hard == "vd": + asm_path = os.path.join(compiled_folder, f"{test_name}.vd") else: asm_path = os.path.join(compiled_folder, f"{test_name}") compiler_dir = os.path.join(os.path.dirname(__file__), "..", "bin") cmd = [os.path.join(compiler_dir, "compiler"), trv_path, "-o", asm_path] - if hard: + if hard == "hard": cmd.append("--hard") + elif hard == "sc": + cmd.append("--sc") + elif hard == "vd": + cmd.append("--vd") result = subprocess.run(cmd, cwd=compiler_dir, capture_output=True, text=True) asm_path = asm_path + ".s" @@ -351,7 +324,7 @@ def _generate_injection_points(self, asm_path): registers = [] cpsr_registers = [] pc_points = [] - do_all = False + do_all = True if len(self.injection_points) == 0: do_all = True @@ -452,6 +425,10 @@ def _run_fault_campaign(self, test_name, variant, asm_path, pass_mode_config, li injection_points = self._generate_injection_points(asm_path) else: injection_points = self._symex_to_injection_points(variant, asm_path, minimc_res) + if injection_points is None or len(injection_points) == 0: + print("NO INJECTION POINTS FOUND FROM SYMEX") + else: + print("FOUND INJECTION POINTS FROM SYMEX") if limit is not None and len(injection_points) > limit: injection_points = injection_points[:limit] @@ -469,7 +446,7 @@ def _run_fault_campaign(self, test_name, variant, asm_path, pass_mode_config, li with concurrent.futures.ProcessPoolExecutor(max_workers=cpu_count) as executor: for res in tqdm( - executor.map(_fault_worker, tasks, chunksize=50), + executor.map(self._fault_worker, tasks, chunksize=50), total=len(tasks), desc="Fault Injection", ): @@ -479,17 +456,32 @@ def _run_fault_campaign(self, test_name, variant, asm_path, pass_mode_config, li return results - def compile(self, nohard=False): + def _patch_wh_assert(self, asm_path, expected_value): + wh_path = str(Path(asm_path).with_suffix(".wh")) + if not os.path.exists(wh_path): + return + with open(wh_path, "r") as f: + content = f.read() + if "XYZ" not in content: + return + content = content.replace("XYZ", str(expected_value)) + with open(wh_path, "w") as f: + f.write(content) + + def compile(self): results = [] for test in self.tests: - test_result = {"name": test["name"], "normal": None, "hard": None} + test_result = {"name": test["name"], "normal": None, "hard": None, "sc": None, "vd": None} - for hard in [False, True]: - hard_str = "hard" if hard else "normal" + for hard in ["hard", "sc", "vd", "normal"]: success, asm_path, stdout, stderr = self.compile_test( test, hard, self.compiled_folder ) - test_result[hard_str] = { + if success: + self._patch_wh_assert(asm_path, int(str(test["pass_mode"]["expected_pass"]).partition(",")[0])) + else: + raise Exception("Something went wrong compiling test") + test_result[hard] = { "success": success, "asm_path": asm_path, "stdout": stdout, @@ -500,29 +492,28 @@ def compile(self, nohard=False): self.compile_results = results return results - def run_tests(self, limit=None, run_variants="both", minimc_res=None): + def run_tests(self, limit=None, run_variants="all", minimc_res=None, guided=False): if self.compile_results is None: self.compile() all_fault_results = [] if run_variants == "normal": - variants = [False] + variants = ["normal"] elif run_variants == "hard": - variants = [True] + variants = ["hard"] else: - variants = [False, True] + variants = ["hard", "sc", "vd", "normal"] compile_results = self.compile_results or [] for test, result in zip(self.tests, compile_results): print(f"Test: {test['name']}") for hard in variants: - hard_str = "hard" if hard else "normal" - res = result[hard_str] + res = result[hard] if not res["success"]: - print(f" Compilation failed ({hard_str})") + print(f" Compilation failed ({hard})") if res["stdout"]: print(f" stdout: {res['stdout']}") if res["stderr"]: @@ -531,16 +522,20 @@ def run_tests(self, limit=None, run_variants="both", minimc_res=None): asm_path = res["asm_path"] max_pc = self._get_program_max_pc(asm_path) - injection_points = self._generate_injection_points(asm_path) + injection_points = [] + if guided: + injection_points = self._symex_to_injection_points(hard, asm_path, minimc_res) + else: + injection_points = self._generate_injection_points(asm_path) - print(f" Compiled ({hard_str}) successfully") + print(f" Compiled ({hard}) successfully") print(f" ASM path: {asm_path}") print(f" Max PC: {max_pc}") print(f" Fault runs to execute: {len(injection_points)}") fault_results = self._run_fault_campaign( test_name=test["name"], - variant=hard_str, + variant=hard, asm_path=asm_path, pass_mode_config=test["pass_mode"], limit=limit,