From 10db4811a3baea65021eec40dab6243f49bfd79f Mon Sep 17 00:00:00 2001 From: chrysn Date: Wed, 22 Jan 2025 14:24:51 +0100 Subject: [PATCH] shared: Replace quadruple_sizes feature with large_buffers --- lakers-python/Cargo.toml | 2 +- shared/Cargo.toml | 28 +++++++++++++++------------- shared/cbindgen.toml | 2 +- shared/src/lib.rs | 16 +++------------- 4 files changed, 20 insertions(+), 28 deletions(-) diff --git a/lakers-python/Cargo.toml b/lakers-python/Cargo.toml index 9c155478..7cc1dbd4 100644 --- a/lakers-python/Cargo.toml +++ b/lakers-python/Cargo.toml @@ -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" diff --git a/shared/Cargo.toml b/shared/Cargo.toml index 514e91c9..da67fe4f 100644 --- a/shared/Cargo.toml +++ b/shared/Cargo.toml @@ -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 = [] @@ -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 = [] @@ -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 = [] diff --git a/shared/cbindgen.toml b/shared/cbindgen.toml index ff11b562..8b6f2b8f 100644 --- a/shared/cbindgen.toml +++ b/shared/cbindgen.toml @@ -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 = [ diff --git a/shared/src/lib.rs b/shared/src/lib.rs index 676c98db..01a4f7ed 100644 --- a/shared/src/lib.rs +++ b/shared/src/lib.rs @@ -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") { @@ -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; @@ -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") { @@ -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;