Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shared: Introduce max_message_size_… features #331

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
30 changes: 30 additions & 0 deletions shared/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,33 @@ python-bindings = ["pyo3", "hex"]
## larger sizes (especially for experimentation) without making sizes explode
## on embedded.
quadruple_sizes = []

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

max_message_size_len_256 = []
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 = []
39 changes: 34 additions & 5 deletions shared/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,20 @@ pub const SCALE_FACTOR: usize = 1;
#[doc(hidden)]
pub const SCALE_FACTOR: usize = 4;
geonnave marked this conversation as resolved.
Show resolved Hide resolved

// TODO: find a way to configure the buffer size
// need 128 to handle EAD fields, and 192 for the EAD_1 voucher
pub const MAX_MESSAGE_SIZE_LEN: usize = SCALE_FACTOR * (128 + 64);
pub const MAX_MESSAGE_SIZE_LEN: usize = if cfg!(feature = "max_message_size_len_512") {
512
} else if cfg!(feature = "max_message_size_len_448") {
448
} else if cfg!(feature = "max_message_size_len_384") {
384
} else if cfg!(feature = "max_message_size_len_320") {
320
} else if cfg!(feature = "max_message_size_len_256") {
256
} else {
// need 128 to handle EAD fields, and 192 for the EAD_1 voucher
SCALE_FACTOR * (128 + 64)
};

pub const ID_CRED_LEN: usize = 4;
pub const SUITES_LEN: usize = 9;
Expand All @@ -61,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
Loading