Skip to main content

securedrop_protocol_minimal/primitives/
pad.rs

1use alloc::vec::Vec;
2
3/// Fixed-length padded message length.
4///
5/// Note: I made this up. We should pick something based on actual reasons.
6pub const PADDED_MESSAGE_LEN: usize = 100000;
7
8#[cfg_attr(hax, hax_lib::fstar::verification_status(lax))]
9/// Pad a message to a fixed length
10pub fn pad_message(message: &[u8]) -> Vec<u8> {
11    if message.len() > PADDED_MESSAGE_LEN {
12        // TODO: Handle message truncation or error outside of this function
13        panic!("Message too long for padding");
14    }
15
16    let mut padded = Vec::with_capacity(PADDED_MESSAGE_LEN);
17    padded.extend_from_slice(message);
18
19    // Pad with zeros to reach the fixed length
20    let padding_needed = PADDED_MESSAGE_LEN - message.len();
21    for _ in 0..padding_needed {
22        padded.push(0u8);
23    }
24
25    padded
26}