Skip to content

Commit

Permalink
shared: Replace quadruple_sizes feature with large_buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
chrysn committed Jan 22, 2025
1 parent 152df74 commit 10db481
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 28 deletions.
2 changes: 1 addition & 1 deletion lakers-python/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ license.workspace = true
pyo3 = { version = "0.22", features = ["extension-module"] }
lakers = { package = "lakers", path = "../lib", default-features = false, features = [ "log" ] }
lakers-ead-authz = { path = "../ead/lakers-ead-authz", features = [ "log" ] }
lakers-shared = { path = "../shared", features = ["python-bindings", "quadruple_sizes"] }
lakers-shared = { path = "../shared", features = ["python-bindings", "large_buffers"] }
lakers-crypto = { path = "../crypto", default-features = false, features = ["rustcrypto"] }
log = "0.4"
pyo3-log = "0.11.0"
Expand Down
28 changes: 15 additions & 13 deletions shared/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,21 @@ rstest = "0.21.0"
default = [ ]
python-bindings = ["pyo3", "hex"]

## For all arbitrarily limited buffers, pick 4x the current default.
## For all arbitrarily limited buffers, pick the maximum.
##
## On the long run, this might be replaced with a more fine-grained feature set
## picking the minimum size of all the items, or even an option to generalize,
## but this provides an easy way to allow unconstrained systems to stomach
## larger sizes (especially for experimentation) without making sizes explode
## on embedded.
quadruple_sizes = []
## This provides an easy way to allow unconstrained systems to stomach larger
## sizes (especially for experimentation).
large_buffers = [
"max_message_size_len_1024",
"max_kdf_content_len_1024",
"max_buffer_len_1024",
"max_connid_encoded_len_24",
]

## 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.
## If any of those is set, they override the default of 192. If multiple are
## set, the highest wins.

max_message_size_len_256 = []
max_message_size_len_320 = []
Expand All @@ -49,8 +51,8 @@ max_message_size_len_1024 = []

## 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.
## If any of those is set, they override the default of 256. If multiple are
## set, the highest wins.

max_kdf_content_len_320 = []
max_kdf_content_len_384 = []
Expand All @@ -60,8 +62,8 @@ max_kdf_content_len_1024 = []

## 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.
## If any of those is set, they override the default of 320. If multiple are
## set, the highest wins.

max_buffer_len_384 = []
max_buffer_len_448 = []
Expand Down
2 changes: 1 addition & 1 deletion shared/cbindgen.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ include_guard = "LAKERS_SHARED_H"
cpp_compat = true

[defines]
"feature = quadruple_sizes" = "QUADRUPLE_SIZES"
"feature = large_buffers" = "LARGE_BUFFERS"

[export]
include = [
Expand Down
16 changes: 3 additions & 13 deletions shared/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,6 @@ use pyo3::prelude::*;
#[cfg(feature = "python-bindings")]
mod python_bindings;

/// Configured upscaling applied to fixed-size buffers
///
/// Do not rely on this: It is only pub because cbindgen needs it.
#[cfg(not(feature = "quadruple_sizes"))]
#[doc(hidden)]
pub const SCALE_FACTOR: usize = 1;
#[cfg(feature = "quadruple_sizes")]
#[doc(hidden)]
pub const SCALE_FACTOR: usize = 4;

pub const MAX_MESSAGE_SIZE_LEN: usize = if cfg!(feature = "max_message_size_len_1024") {
1024
} else if cfg!(feature = "max_message_size_len_512") {
Expand All @@ -56,7 +46,7 @@ pub const MAX_MESSAGE_SIZE_LEN: usize = if cfg!(feature = "max_message_size_len_
256
} else {
// need 128 to handle EAD fields, and 192 for the EAD_1 voucher
SCALE_FACTOR * (128 + 64)
128 + 64
};

pub const ID_CRED_LEN: usize = 4;
Expand Down Expand Up @@ -85,7 +75,7 @@ pub const MAX_KDF_CONTEXT_LEN: usize = if cfg!(feature = "max_kdf_content_len_10
} else if cfg!(feature = "max_kdf_content_len_320") {
320
} else {
SCALE_FACTOR * 256
256
};
pub const MAX_KDF_LABEL_LEN: usize = 15; // for "KEYSTREAM_2"
pub const MAX_BUFFER_LEN: usize = if cfg!(feature = "max_buffer_len_1024") {
Expand All @@ -97,7 +87,7 @@ pub const MAX_BUFFER_LEN: usize = if cfg!(feature = "max_buffer_len_1024") {
} else if cfg!(feature = "max_buffer_len_384") {
384
} else {
SCALE_FACTOR * 256 + 64
256 + 64
};
pub const CBOR_BYTE_STRING: u8 = 0x58u8;
pub const CBOR_TEXT_STRING: u8 = 0x78u8;
Expand Down

0 comments on commit 10db481

Please sign in to comment.