From 7e892abb69df1ba18bc40675753ff25e6f4592fc Mon Sep 17 00:00:00 2001 From: chrysn Date: Thu, 16 Jan 2025 16:24:26 +0100 Subject: [PATCH 1/9] =?UTF-8?q?shared:=20Introduce=20max=5Fmessage=5Fsize?= =?UTF-8?q?=5F=E2=80=A6=20features?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes: https://github.com/openwsn-berkeley/lakers/issues/330 --- shared/Cargo.toml | 11 +++++++++++ shared/src/lib.rs | 17 ++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/shared/Cargo.toml b/shared/Cargo.toml index 68d86502..6169b589 100644 --- a/shared/Cargo.toml +++ b/shared/Cargo.toml @@ -34,3 +34,14 @@ 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 = [] diff --git a/shared/src/lib.rs b/shared/src/lib.rs index d900924f..c78e35fc 100644 --- a/shared/src/lib.rs +++ b/shared/src/lib.rs @@ -42,9 +42,20 @@ pub const SCALE_FACTOR: usize = 1; #[doc(hidden)] pub const SCALE_FACTOR: usize = 4; -// 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; From 7f8e8944602aaa90d89eab459f4124a5e1a9fdec Mon Sep 17 00:00:00 2001 From: chrysn Date: Fri, 17 Jan 2025 21:47:05 +0100 Subject: [PATCH 2/9] shared: Extend size features to other buffers that are easily exceeded --- shared/Cargo.toml | 19 +++++++++++++++++++ shared/src/lib.rs | 22 ++++++++++++++++++++-- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/shared/Cargo.toml b/shared/Cargo.toml index 6169b589..93ffc9ba 100644 --- a/shared/Cargo.toml +++ b/shared/Cargo.toml @@ -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 = [] diff --git a/shared/src/lib.rs b/shared/src/lib.rs index c78e35fc..f6eb65cd 100644 --- a/shared/src/lib.rs +++ b/shared/src/lib.rs @@ -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; From 2c09c3fbc92a259dfd6329d0bcf8f79e1dbde36e Mon Sep 17 00:00:00 2001 From: chrysn Date: Wed, 22 Jan 2025 14:19:25 +0100 Subject: [PATCH 3/9] shared: Add 1KiB buffer option --- shared/Cargo.toml | 3 +++ shared/src/lib.rs | 12 +++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/shared/Cargo.toml b/shared/Cargo.toml index 93ffc9ba..9cee1593 100644 --- a/shared/Cargo.toml +++ b/shared/Cargo.toml @@ -45,6 +45,7 @@ max_message_size_len_320 = [] max_message_size_len_384 = [] max_message_size_len_448 = [] max_message_size_len_512 = [] +max_message_size_len_1024 = [] ## Precise control of `MAX_KDF_CONTENT_LEN`. ## @@ -55,6 +56,7 @@ max_kdf_content_len_320 = [] max_kdf_content_len_384 = [] max_kdf_content_len_448 = [] max_kdf_content_len_512 = [] +max_kdf_content_len_1024 = [] ## Precise control of `MAX_BUFFER_LEN`. ## @@ -64,3 +66,4 @@ max_kdf_content_len_512 = [] max_buffer_len_384 = [] max_buffer_len_448 = [] max_buffer_len_512 = [] +max_buffer_len_1024 = [] diff --git a/shared/src/lib.rs b/shared/src/lib.rs index f6eb65cd..64c8f8b1 100644 --- a/shared/src/lib.rs +++ b/shared/src/lib.rs @@ -42,7 +42,9 @@ pub const SCALE_FACTOR: usize = 1; #[doc(hidden)] pub const SCALE_FACTOR: usize = 4; -pub const MAX_MESSAGE_SIZE_LEN: usize = if cfg!(feature = "max_message_size_len_512") { +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") { 512 } else if cfg!(feature = "max_message_size_len_448") { 448 @@ -72,7 +74,9 @@ 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 = if cfg!(feature = "max_kdf_content_len_512") { +pub const MAX_KDF_CONTEXT_LEN: usize = if cfg!(feature = "max_kdf_content_len_1024") { + 1024 +} else if cfg!(feature = "max_kdf_content_len_512") { 512 } else if cfg!(feature = "max_kdf_content_len_448") { 448 @@ -84,7 +88,9 @@ pub const MAX_KDF_CONTEXT_LEN: usize = if cfg!(feature = "max_kdf_content_len_51 SCALE_FACTOR * 256 }; pub const MAX_KDF_LABEL_LEN: usize = 15; // for "KEYSTREAM_2" -pub const MAX_BUFFER_LEN: usize = if cfg!(feature = "max_buffer_len_512") { +pub const MAX_BUFFER_LEN: usize = if cfg!(feature = "max_buffer_len_1024") { + 1024 +} else if cfg!(feature = "max_buffer_len_512") { 512 } else if cfg!(feature = "max_buffer_len_448") { 448 From 9afb674f0b889c4e3601b5caa21a7ad309aca0d1 Mon Sep 17 00:00:00 2001 From: chrysn Date: Wed, 22 Jan 2025 14:20:51 +0100 Subject: [PATCH 4/9] shared: Add explicit sizes where the quadruple feature had no replacement so far --- shared/Cargo.toml | 6 ++++++ shared/src/lib.rs | 5 +++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/shared/Cargo.toml b/shared/Cargo.toml index 9cee1593..514e91c9 100644 --- a/shared/Cargo.toml +++ b/shared/Cargo.toml @@ -67,3 +67,9 @@ max_buffer_len_384 = [] max_buffer_len_448 = [] max_buffer_len_512 = [] max_buffer_len_1024 = [] + +## Control of `MAX_CONNID_ENCODED_LEN`. +## +## If this is not set, the minimum sensible default (8 bytes) is used. + +max_connid_encoded_len_24 = [] diff --git a/shared/src/lib.rs b/shared/src/lib.rs index 64c8f8b1..2c678d9c 100644 --- a/shared/src/lib.rs +++ b/shared/src/lib.rs @@ -127,8 +127,9 @@ pub const MAX_EAD_SIZE_LEN: usize = SCALE_FACTOR * 64; /// Maximum length of a [`ConnId`] (`C_x`). /// /// This length includes the leading CBOR encoding byte(s). -// If ints had a const `.clamp()` feature, this could be (8 * SCALE_FACTOR).clamp(1, 23). -const MAX_CONNID_ENCODED_LEN: usize = if cfg!(feature = "quadruple_sizes") { +// Note that when implementing larger sizes than 24, the encoding will need to use actual CBOR +// rather than masking a known short length into a byte. +const MAX_CONNID_ENCODED_LEN: usize = if cfg!(feature = "max_connid_encoded_len_24") { 24 } else { 8 From 152df7451bdeb37beb6cfe9bbb315701a335a846 Mon Sep 17 00:00:00 2001 From: chrysn Date: Wed, 22 Jan 2025 14:26:09 +0100 Subject: [PATCH 5/9] shared: Ignore SCALE_FACTOR in MAX_EAD_SIZE That value is not used anyway. --- shared/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared/src/lib.rs b/shared/src/lib.rs index 2c678d9c..676c98db 100644 --- a/shared/src/lib.rs +++ b/shared/src/lib.rs @@ -122,7 +122,7 @@ pub const KID_LABEL: u8 = 4; pub const ENC_STRUCTURE_LEN: usize = 8 + 5 + SHA256_DIGEST_LEN; // 8 for ENCRYPT0 -pub const MAX_EAD_SIZE_LEN: usize = SCALE_FACTOR * 64; +pub const MAX_EAD_SIZE_LEN: usize = 64; /// Maximum length of a [`ConnId`] (`C_x`). /// From 10db4811a3baea65021eec40dab6243f49bfd79f Mon Sep 17 00:00:00 2001 From: chrysn Date: Wed, 22 Jan 2025 14:24:51 +0100 Subject: [PATCH 6/9] 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; From b2196cb753a52e923a91e8c1aa3cf5ef3551bfde Mon Sep 17 00:00:00 2001 From: chrysn Date: Mon, 3 Feb 2025 11:20:31 +0100 Subject: [PATCH 7/9] python tests: Increase data to produce buffer error With the recently increased buffer sizes, the original test failed to achieve its goal of producing an overflow error. --- lakers-python/test/test_lakers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lakers-python/test/test_lakers.py b/lakers-python/test/test_lakers.py index 9dc93715..0a670230 100644 --- a/lakers-python/test/test_lakers.py +++ b/lakers-python/test/test_lakers.py @@ -90,7 +90,7 @@ def test_edhoc_error(): def test_buffer_error(): initiator = EdhocInitiator() with pytest.raises(ValueError) as err: - _ = initiator.parse_message_2([1] * 1000) + _ = initiator.parse_message_2([1] * 10000) assert str(err.value) == "MessageBufferError::SliceTooLong" @pytest.mark.parametrize("cred_r_transfer", [CredentialTransfer.ByReference, CredentialTransfer.ByValue]) From 7506ad42a5096fd9432888ddbc8baab8bbbbbd3c Mon Sep 17 00:00:00 2001 From: chrysn Date: Mon, 3 Feb 2025 11:25:11 +0100 Subject: [PATCH 8/9] python tests: Make test case more realistic When this test failed, the resulting "Type state mismatch" runtime error was confusing -- and while currently we raise the buffer error first, there's no guarantee that that couldn't flip around. Therefore, the example is made more realistic to ensure that it's really the buffer error that triggers first. --- lakers-python/test/test_lakers.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lakers-python/test/test_lakers.py b/lakers-python/test/test_lakers.py index 0a670230..4c7f9749 100644 --- a/lakers-python/test/test_lakers.py +++ b/lakers-python/test/test_lakers.py @@ -89,8 +89,9 @@ def test_edhoc_error(): def test_buffer_error(): initiator = EdhocInitiator() + initiator.prepare_message_1() with pytest.raises(ValueError) as err: - _ = initiator.parse_message_2([1] * 10000) + _ = initiator.parse_message_2(cbor2.dumps(bytes([1] * 10000))) assert str(err.value) == "MessageBufferError::SliceTooLong" @pytest.mark.parametrize("cred_r_transfer", [CredentialTransfer.ByReference, CredentialTransfer.ByValue]) From 8f2fc259d9bc23634832a97797dc91e6be49920b Mon Sep 17 00:00:00 2001 From: chrysn Date: Mon, 3 Feb 2025 12:42:26 +0100 Subject: [PATCH 9/9] lakers-c: Manually reconstruct the buffer size selection for C Workaround-For: https://github.com/mozilla/cbindgen/issues/1018 --- shared/cbindgen.toml | 75 ++++++++++++++++++++++++++++++++++++++++++-- shared/src/lib.rs | 7 +++++ 2 files changed, 80 insertions(+), 2 deletions(-) diff --git a/shared/cbindgen.toml b/shared/cbindgen.toml index 4624e088..2b5bd355 100644 --- a/shared/cbindgen.toml +++ b/shared/cbindgen.toml @@ -7,12 +7,83 @@ header = """ * ================================================================================================ * WARNING: This file is automatically generated by cbindgen. Manual edits are likely to be lost. * ================================================================================================ - */""" -include_guard = "LAKERS_SHARED_H" + */ + +#ifndef LAKERS_SHARED_H +#define LAKERS_SHARED_H + +/* Manually implemented to work around https://github.com/mozilla/cbindgen/issues/1018 */ + +#if defined(_MAX_MESSAGE_SIZE_LEN_1024) +#define MAX_MESSAGE_SIZE_LEN 1024 +#elif defined(_MAX_MESSAGE_SIZE_LEN_512) +#define MAX_MESSAGE_SIZE_LEN 512 +#elif defined(_MAX_MESSAGE_SIZE_LEN_448) +#define MAX_MESSAGE_SIZE_LEN 448 +#elif defined(_MAX_MESSAGE_SIZE_LEN_384) +#define MAX_MESSAGE_SIZE_LEN 384 +#else +#define MAX_MESSAGE_SIZE_LEN 256 + 64 +#endif + +#if defined(_MAX_KDF_CONTENT_LEN_1024) +#define MAX_KDF_CONTEXT_LEN 1024 +#elif defined(_MAX_KDF_CONTENT_LEN_512) +#define MAX_KDF_CONTEXT_LEN 512 +#elif defined(_MAX_KDF_CONTENT_LEN_448) +#define MAX_KDF_CONTEXT_LEN 448 +#elif defined(_MAX_KDF_CONTENT_LEN_384) +#define MAX_KDF_CONTEXT_LEN 384 +#elif defined(_MAX_KDF_CONTENT_LEN_320) +#define MAX_KDF_CONTEXT_LEN 320 +#else +#define MAX_KDF_CONTEXT_LEN 256 +#endif + +#if defined(_MAX_KDF_CONTENT_LEN_1024) +#define MAX_BUFFER_LEN 1024 +#elif defined(_MAX_KDF_CONTENT_LEN_512) +#define MAX_BUFFER_LEN 512 +#elif defined(_MAX_KDF_CONTENT_LEN_448) +#define MAX_BUFFER_LEN 448 +#elif defined(_MAX_KDF_CONTENT_LEN_384) +#define MAX_BUFFER_LEN 384 +#else +#define MAX_BUFFER_LEN 256 + 64 +#endif + +#if defined(_MAX_CONNID_ENCODED_LEN_24) +#define MAX_CONNID_ENCODED_LEN 24 +#else +#define MAX_CONNID_ENCODED_LEN 8 +#endif +""" +trailer = """ +#endif /* LAKERS_SHARED_H */ +""" +# Done manually so that the manual parts of the MAX_MESSAGE_SIZE_LEN_xxx etc +# features can be placed after the include guard: +# include_guard = "LAKERS_SHARED_H" cpp_compat = true [defines] "feature = large_buffers" = "LARGE_BUFFERS" +"feature = max_message_size_len_256" = "_MAX_MESSAGE_SIZE_LEN_256" +"feature = max_message_size_len_320" = "_MAX_MESSAGE_SIZE_LEN_320" +"feature = max_message_size_len_384" = "_MAX_MESSAGE_SIZE_LEN_384" +"feature = max_message_size_len_448" = "_MAX_MESSAGE_SIZE_LEN_448" +"feature = max_message_size_len_512" = "_MAX_MESSAGE_SIZE_LEN_512" +"feature = max_message_size_len_1024" = "_MAX_MESSAGE_SIZE_LEN_1024" +"feature = max_kdf_content_len_320" = "_MAX_KDF_CONTENT_LEN_320" +"feature = max_kdf_content_len_384" = "_MAX_KDF_CONTENT_LEN_384" +"feature = max_kdf_content_len_448" = "_MAX_KDF_CONTENT_LEN_448" +"feature = max_kdf_content_len_512" = "_MAX_KDF_CONTENT_LEN_512" +"feature = max_kdf_content_len_1024" = "_MAX_KDF_CONTENT_LEN_1024" +"feature = max_buffer_len_384" = "_MAX_BUFFER_LEN_384" +"feature = max_buffer_len_448" = "_MAX_BUFFER_LEN_448" +"feature = max_buffer_len_512" = "_MAX_BUFFER_LEN_512" +"feature = max_buffer_len_1024" = "_MAX_BUFFER_LEN_1024" +"feature = max_connid_encoded_len_24" = "_MAX_CONNID_ENCODED_LEN_24" [export] include = [ diff --git a/shared/src/lib.rs b/shared/src/lib.rs index ffc7f370..bc0ba5a8 100644 --- a/shared/src/lib.rs +++ b/shared/src/lib.rs @@ -32,6 +32,7 @@ use pyo3::prelude::*; #[cfg(feature = "python-bindings")] mod python_bindings; +// When changing this, beware that it is re-implemented in cbindgen.toml 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") { @@ -64,6 +65,8 @@ 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 +// +// When changing this, beware that it is re-implemented in cbindgen.toml pub const MAX_KDF_CONTEXT_LEN: usize = if cfg!(feature = "max_kdf_content_len_1024") { 1024 } else if cfg!(feature = "max_kdf_content_len_512") { @@ -78,6 +81,8 @@ pub const MAX_KDF_CONTEXT_LEN: usize = if cfg!(feature = "max_kdf_content_len_10 256 }; pub const MAX_KDF_LABEL_LEN: usize = 15; // for "KEYSTREAM_2" + +// When changing this, beware that it is re-implemented in cbindgen.toml pub const MAX_BUFFER_LEN: usize = if cfg!(feature = "max_buffer_len_1024") { 1024 } else if cfg!(feature = "max_buffer_len_512") { @@ -121,6 +126,8 @@ pub const MAX_EAD_SIZE_LEN: usize = 64; /// This length includes the leading CBOR encoding byte(s). // Note that when implementing larger sizes than 24, the encoding will need to use actual CBOR // rather than masking a known short length into a byte. +// +// When changing this, beware that it is re-implemented in cbindgen.toml const MAX_CONNID_ENCODED_LEN: usize = if cfg!(feature = "max_connid_encoded_len_24") { 24 } else {