Skip to content

Commit

Permalink
shared: Extend size features to other buffers that are easily exceeded
Browse files Browse the repository at this point in the history
  • Loading branch information
chrysn committed Jan 17, 2025
1 parent 4920deb commit bac7af7
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
19 changes: 19 additions & 0 deletions shared/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,22 @@ max_message_size_len_320 = []
max_message_size_len_384 = []
max_message_size_len_448 = []
max_message_size_len_512 = []

## Precise control of `MAX_KDF_CONTENT_LEN`.
##
## If any of those is set, they override the default of 256 (as well as
## `quadruple_sizes`). If multiple are set, the highest wins.

max_kdf_content_len_320 = []
max_kdf_content_len_384 = []
max_kdf_content_len_448 = []
max_kdf_content_len_512 = []

## Precise control of `MAX_BUFFER_LEN`.
##
## If any of those is set, they override the default of 320 (as well as
## `quadruple_sizes`). If multiple are set, the highest wins.

max_buffer_len_384 = []
max_buffer_len_448 = []
max_buffer_len_512 = []
22 changes: 20 additions & 2 deletions shared/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,27 @@ pub const MAC_LENGTH_3: usize = MAC_LENGTH_2;
pub const ENCODED_VOUCHER_LEN: usize = 1 + MAC_LENGTH; // 1 byte for the length of the bstr-encoded voucher

// maximum supported length of connection identifier for R
pub const MAX_KDF_CONTEXT_LEN: usize = SCALE_FACTOR * 256;
pub const MAX_KDF_CONTEXT_LEN: usize = if cfg!(feature = "max_kdf_content_len_512") {
512
} else if cfg!(feature = "max_kdf_content_len_448") {
448
} else if cfg!(feature = "max_kdf_content_len_384") {
384
} else if cfg!(feature = "max_kdf_content_len_320") {
320
} else {
SCALE_FACTOR * 256
};
pub const MAX_KDF_LABEL_LEN: usize = 15; // for "KEYSTREAM_2"
pub const MAX_BUFFER_LEN: usize = SCALE_FACTOR * 256 + 64;
pub const MAX_BUFFER_LEN: usize = if cfg!(feature = "max_buffer_len_512") {
512
} else if cfg!(feature = "max_buffer_len_448") {
448
} else if cfg!(feature = "max_buffer_len_384") {
384
} else {
SCALE_FACTOR * 256 + 64
};
pub const CBOR_BYTE_STRING: u8 = 0x58u8;
pub const CBOR_TEXT_STRING: u8 = 0x78u8;
pub const CBOR_UINT_1BYTE: u8 = 0x18u8;
Expand Down

0 comments on commit bac7af7

Please sign in to comment.