diff --git a/Cargo.lock b/Cargo.lock index e18c80f..996588b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -357,6 +357,7 @@ version = "0.1.0" dependencies = [ "bytemuck", "consts", + "getrandom 0.2.15", "rand 0.9.1", "thiserror 2.0.12", ] diff --git a/Cargo.toml b/Cargo.toml index 085c151..7f45a6c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,9 +14,9 @@ foundation-api = { path = "api" } foundation-abstracted = { path = "abstracted" } btp = { path = "btp" } quantum-link-macros = { path = "quantum-link-macros" } -rand = "0.9.1" +getrandom = { version = "0.2" } [patch.crates-io] pqcrypto-traits = { git = "https://github.com/Foundation-Devices/pqcrypto", rev = "ebadf71214f67cb970242fa1053b4acb65767737" } pqcrypto-mldsa = { git = "https://github.com/Foundation-Devices/pqcrypto", rev = "ebadf71214f67cb970242fa1053b4acb65767737" } -pqcrypto-mlkem = { git = "https://github.com/Foundation-Devices/pqcrypto", rev = "ebadf71214f67cb970242fa1053b4acb65767737" } \ No newline at end of file +pqcrypto-mlkem = { git = "https://github.com/Foundation-Devices/pqcrypto", rev = "ebadf71214f67cb970242fa1053b4acb65767737" } diff --git a/btp/Cargo.toml b/btp/Cargo.toml index 1d0a7c3..6cbfbf0 100644 --- a/btp/Cargo.toml +++ b/btp/Cargo.toml @@ -9,5 +9,8 @@ bytemuck = { version = "1", features = ["derive"] } consts = { git = "https://github.com/Foundation-Devices/prime-ble-firmware.git", features = [ "dle", ] } -rand = { workspace = true } +getrandom = { workspace = true } thiserror = "2" + +[dev-dependencies] +rand = "0.9" diff --git a/btp/src/chunk.rs b/btp/src/chunk.rs index a411db8..3f06214 100644 --- a/btp/src/chunk.rs +++ b/btp/src/chunk.rs @@ -39,7 +39,13 @@ impl<'a> Iterator for Chunker<'a> { /// Splits data into chunks for transmission pub fn chunk(data: &[u8]) -> Chunker<'_> { - let message_id = rand::Rng::random::(&mut rand::rng()); + let mut message_id = [0; 2]; + getrandom::getrandom(&mut message_id).unwrap(); + let message_id = u16::from_le_bytes(message_id); + chunk_with_id(data, message_id) +} + +pub fn chunk_with_id(data: &[u8], message_id: u16) -> Chunker<'_> { let total_chunks = data.len().div_ceil(CHUNK_DATA_SIZE) as u16; Chunker {