Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions firmware/design/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use core::panic::PanicInfo;
use cortex_m_rt::entry;
use design::sensitive;
use design::{eprintln, sensitive};
use design_macros::rand_ops;
use mspm0l222x_hal::{CorePeripherals, Peripherals, Trng, trng};

Expand All @@ -16,8 +16,9 @@ use design::{

/// On panic, inform the host with the information associated with the panic and reboot the board.
#[panic_handler]
fn handle_panics(_info: &PanicInfo) -> ! {
fn handle_panics(info: &PanicInfo) -> ! {
// if salt page is missing on reboot, error gets sent then
eprintln!("{:?}", info);
cortex_m::peripheral::SCB::sys_reset();
}

Expand Down
84 changes: 42 additions & 42 deletions firmware/design_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,48 +128,48 @@ pub fn rand_ops(input: TokenStream) -> TokenStream {
let loop_body = generate_rand_ops_body(&mut build_rng);

quote! {{
let mut rng = #rng;
let mut state = core::hint::black_box(rng.word());
// 16..1040 iterations
let iteration_count = core::hint::black_box((rng.word() & 0x2ff) + 16);
let mut check = core::hint::black_box(#base_check_val);
let mut i = core::hint::black_box(0u32);

// TODO: idk if keeping init nops is needed, no branches until after randomized loop body which could be glitched
// maybe it is still good ot have random nops ran one iteration, may be hard to measure exactly what they are
#init_nops

loop {
#loop_body

if core::hint::black_box(i == iteration_count) {
break;
}

i = core::hint::black_box(i.wrapping_add(1));
check = core::hint::black_box(check.wrapping_add(#check_inc_val));
}

#post_check_1_nops
if core::hint::black_box(i != iteration_count || check != core::hint::black_box(
(#base_check_val).wrapping_add(iteration_count.wrapping_mul(#check_inc_val)),
)) {
panic!();
}

#post_check_2_nops
if core::hint::black_box(check != core::hint::black_box(
(#base_check_val).wrapping_add(iteration_count.wrapping_mul(#check_inc_val)),
) || i != iteration_count) {
panic!();
}

#post_check_3_nops
if core::hint::black_box((i != iteration_count) | (check != core::hint::black_box(
(#base_check_val).wrapping_add(iteration_count.wrapping_mul(#check_inc_val)),
))) {
panic!();
}
// let mut rng = #rng;
// let mut state = core::hint::black_box(rng.word());
// // 16..1040 iterations
// let iteration_count = core::hint::black_box((rng.word() & 0x2ff) + 16);
// let mut check = core::hint::black_box(#base_check_val);
// let mut i = core::hint::black_box(0u32);

// // TODO: idk if keeping init nops is needed, no branches until after randomized loop body which could be glitched
// // maybe it is still good ot have random nops ran one iteration, may be hard to measure exactly what they are
// #init_nops

// loop {
// #loop_body

// if core::hint::black_box(i == iteration_count) {
// break;
// }

// i = core::hint::black_box(i.wrapping_add(1));
// check = core::hint::black_box(check.wrapping_add(#check_inc_val));
// }

// #post_check_1_nops
// if core::hint::black_box(i != iteration_count || check != core::hint::black_box(
// (#base_check_val).wrapping_add(iteration_count.wrapping_mul(#check_inc_val)),
// )) {
// panic!();
// }

// #post_check_2_nops
// if core::hint::black_box(check != core::hint::black_box(
// (#base_check_val).wrapping_add(iteration_count.wrapping_mul(#check_inc_val)),
// ) || i != iteration_count) {
// panic!();
// }

// #post_check_3_nops
// if core::hint::black_box((i != iteration_count) | (check != core::hint::black_box(
// (#base_check_val).wrapping_add(iteration_count.wrapping_mul(#check_inc_val)),
// ))) {
// panic!();
// }
}}
.into()
}
Expand Down
Loading