@@ -6,7 +6,7 @@ use embedded_hal::digital::v2::OutputPin;
6
6
7
7
use tiva:: {
8
8
driverlib:: * ,
9
- log, setup_board, Board , words_to_bytes, Signer , Verifier , get_combined_entropy
9
+ log, setup_board, Board , words_to_bytes, Signer , Verifier , get_combined_entropy, get_timer_entropy
10
10
} ;
11
11
12
12
use p256_cortex_m4:: { SecretKey , Signature , PublicKey } ;
@@ -88,6 +88,7 @@ fn main() -> ! {
88
88
89
89
// Seed RNG with entropy sources
90
90
let entropy: [ u8 ; 32 ] = get_combined_entropy ( ) ;
91
+ let mut timer_entropy: u64 = 0 ;
91
92
let mut rng = rand_chacha:: ChaChaRng :: from_seed ( entropy) ;
92
93
93
94
loop {
@@ -97,7 +98,7 @@ fn main() -> ! {
97
98
MAGIC_UNLOCK_REQ => {
98
99
// log!("Car: Received UNLOCK_REQ");
99
100
board. led_blue . set_high ( ) . unwrap ( ) ;
100
- unlock_start ( & mut rng, & mut board) ;
101
+ unlock_start ( & mut rng, & mut board, & mut timer_entropy ) ;
101
102
board. led_blue . set_low ( ) . unwrap ( ) ;
102
103
}
103
104
_ => {
@@ -109,12 +110,16 @@ fn main() -> ! {
109
110
}
110
111
111
112
/// Handle UNLOCK_REQ
112
- fn unlock_start ( rng : & mut ( impl CryptoRng + RngCore ) , board : & mut Board ) {
113
+ fn unlock_start ( rng : & mut ( impl CryptoRng + RngCore ) , board : & mut Board , timer_entropy : & mut u64 ) {
113
114
// Start timeout timer for 500ms, need time to rx from fob
114
115
start_delay_timer_us ( 500_000 ) ;
115
116
117
+ // Update timer entropy
118
+ let new_timer_entropy = get_timer_entropy ( ) ;
119
+ * timer_entropy ^= u64:: from_ne_bytes ( new_timer_entropy[ 0 ..8 ] . try_into ( ) . unwrap ( ) ) ;
120
+
116
121
// Initialize car nonce with random value :) it's very random
117
- let mut car_nonce: u64 = rng. next_u64 ( ) ^ get_tick_timer ( ) ;
122
+ let mut car_nonce: u64 = rng. next_u64 ( ) ^ * timer_entropy ;
118
123
let car_nonce_b: [ u8 ; 8 ] = car_nonce. to_be_bytes ( ) ;
119
124
120
125
// Get car secret key
0 commit comments