beaconcrypt 0.5.2__tar.gz → 0.6.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {beaconcrypt-0.5.2 → beaconcrypt-0.6.1}/Cargo.lock +15 -27
- {beaconcrypt-0.5.2 → beaconcrypt-0.6.1}/Cargo.toml +1 -1
- {beaconcrypt-0.5.2 → beaconcrypt-0.6.1}/PKG-INFO +2 -1
- {beaconcrypt-0.5.2 → beaconcrypt-0.6.1}/beaconcrypt/Cargo.toml +2 -3
- beaconcrypt-0.6.1/beaconcrypt/LICENSE +7 -0
- {beaconcrypt-0.5.2 → beaconcrypt-0.6.1}/beaconcrypt/README.md +15 -6
- {beaconcrypt-0.5.2 → beaconcrypt-0.6.1}/beaconcrypt/bindings.h +5 -0
- {beaconcrypt-0.5.2 → beaconcrypt-0.6.1}/beaconcrypt/build.rs +0 -11
- {beaconcrypt-0.5.2 → beaconcrypt-0.6.1}/beaconcrypt/src/beacon.rs +25 -40
- {beaconcrypt-0.5.2 → beaconcrypt-0.6.1}/beaconcrypt/src/cbinds.rs +8 -16
- {beaconcrypt-0.5.2 → beaconcrypt-0.6.1}/beaconcrypt/src/lib.rs +9 -4
- {beaconcrypt-0.5.2 → beaconcrypt-0.6.1}/beaconcrypt/src/persistence.rs +47 -40
- {beaconcrypt-0.5.2 → beaconcrypt-0.6.1}/beaconcrypt/src/pqxdh.rs +46 -81
- {beaconcrypt-0.5.2 → beaconcrypt-0.6.1}/beaconcrypt/src/ratchet.rs +82 -27
- {beaconcrypt-0.5.2 → beaconcrypt-0.6.1}/beaconcrypt/src/server.rs +67 -24
- {beaconcrypt-0.5.2 → beaconcrypt-0.6.1}/beaconcrypt/src/shared.rs +8 -19
- beaconcrypt-0.6.1/beaconcrypt/src/wire.rs +125 -0
- beaconcrypt-0.6.1/beaconcrypt/tests/common/mod.rs +76 -0
- beaconcrypt-0.6.1/beaconcrypt/tests/message_size.rs +279 -0
- {beaconcrypt-0.5.2 → beaconcrypt-0.6.1}/beaconcrypt/tests/protocol.rs +169 -71
- {beaconcrypt-0.5.2 → beaconcrypt-0.6.1}/beaconcrypt/tests/raw_receive.rs +10 -17
- {beaconcrypt-0.5.2 → beaconcrypt-0.6.1}/beaconcrypt/tests/registration_completion.rs +72 -55
- beaconcrypt-0.6.1/beaconcrypt/tests/registration_response_alias.rs +66 -0
- {beaconcrypt-0.5.2 → beaconcrypt-0.6.1}/beaconcrypt/tests/server.rs +13 -16
- {beaconcrypt-0.5.2 → beaconcrypt-0.6.1}/beaconcrypt-core/src/pqxdh.rs +1 -1
- beaconcrypt-0.6.1/beaconcrypt-parse/Cargo.toml +9 -0
- beaconcrypt-0.6.1/beaconcrypt-parse/README.md +23 -0
- beaconcrypt-0.6.1/beaconcrypt-parse/generated/LICENSE +63 -0
- beaconcrypt-0.6.1/beaconcrypt-parse/generated/README.md +22 -0
- beaconcrypt-0.6.1/beaconcrypt-parse/schema/transport.cddl +10 -0
- beaconcrypt-0.6.1/beaconcrypt-parse/scripts/regenerate.py +116 -0
- beaconcrypt-0.6.1/beaconcrypt-parse/src/generated/cbordetver.rs +579 -0
- beaconcrypt-0.6.1/beaconcrypt-parse/src/generated/cbordetveraux.rs +4939 -0
- beaconcrypt-0.6.1/beaconcrypt-parse/src/generated/transport.rs +3594 -0
- beaconcrypt-0.6.1/beaconcrypt-parse/src/lib.rs +146 -0
- beaconcrypt-0.6.1/beaconcrypt-parse/src/preflight_tests.rs +202 -0
- beaconcrypt-0.6.1/beaconcrypt-parse/src/sizing.rs +127 -0
- beaconcrypt-0.6.1/beaconcrypt-parse/tests/codec.rs +723 -0
- {beaconcrypt-0.5.2 → beaconcrypt-0.6.1}/beaconcrypt.pyi +6 -1
- {beaconcrypt-0.5.2 → beaconcrypt-0.6.1}/pyproject.toml +7 -8
- beaconcrypt-0.5.2/beaconcrypt/src/schema/cryptoframe.capnp +0 -12
- beaconcrypt-0.5.2/beaconcrypt/src/schema/phase1.capnp +0 -12
- beaconcrypt-0.5.2/beaconcrypt/src/schema/phase2.capnp +0 -14
- beaconcrypt-0.5.2/beaconcrypt/tests/registration_response_alias.rs +0 -91
- {beaconcrypt-0.5.2 → beaconcrypt-0.6.1}/LICENSE +0 -0
- {beaconcrypt-0.5.2 → beaconcrypt-0.6.1}/beaconcrypt/examples/rust/README.md +0 -0
- {beaconcrypt-0.5.2 → beaconcrypt-0.6.1}/beaconcrypt/examples/rust/main.rs +0 -0
- {beaconcrypt-0.5.2 → beaconcrypt-0.6.1}/beaconcrypt/src/deser.rs +0 -0
- {beaconcrypt-0.5.2 → beaconcrypt-0.6.1}/beaconcrypt/src/error.rs +0 -0
- {beaconcrypt-0.5.2 → beaconcrypt-0.6.1}/beaconcrypt/src/pybinds.rs +0 -0
- {beaconcrypt-0.5.2 → beaconcrypt-0.6.1}/beaconcrypt/src/ser.rs +0 -0
- {beaconcrypt-0.5.2 → beaconcrypt-0.6.1}/beaconcrypt/tests/beacon.rs +0 -0
- {beaconcrypt-0.5.2 → beaconcrypt-0.6.1}/beaconcrypt/tests/c_persistence.c +0 -0
- {beaconcrypt-0.5.2 → beaconcrypt-0.6.1}/beaconcrypt/tests/construction.rs +0 -0
- {beaconcrypt-0.5.2 → beaconcrypt-0.6.1}/beaconcrypt/tests/record_opening.rs +0 -0
- {beaconcrypt-0.5.2 → beaconcrypt-0.6.1}/beaconcrypt/tests/rooterberg.rs +0 -0
- {beaconcrypt-0.5.2 → beaconcrypt-0.6.1}/beaconcrypt/tests/wycheproof.rs +0 -0
- {beaconcrypt-0.5.2 → beaconcrypt-0.6.1}/beaconcrypt-core/Cargo.toml +0 -0
- {beaconcrypt-0.5.2 → beaconcrypt-0.6.1}/beaconcrypt-core/LICENSE +0 -0
- {beaconcrypt-0.5.2 → beaconcrypt-0.6.1}/beaconcrypt-core/README.md +0 -0
- {beaconcrypt-0.5.2 → beaconcrypt-0.6.1}/beaconcrypt-core/src/commitment.rs +0 -0
- {beaconcrypt-0.5.2 → beaconcrypt-0.6.1}/beaconcrypt-core/src/constants.rs +0 -0
- {beaconcrypt-0.5.2 → beaconcrypt-0.6.1}/beaconcrypt-core/src/lib.rs +0 -0
- {beaconcrypt-0.5.2 → beaconcrypt-0.6.1}/beaconcrypt-core/src/pqxdh/concrete.rs +0 -0
- {beaconcrypt-0.5.2 → beaconcrypt-0.6.1}/beaconcrypt-core/src/ratchet/concrete.rs +0 -0
- {beaconcrypt-0.5.2 → beaconcrypt-0.6.1}/beaconcrypt-core/src/ratchet/control.rs +0 -0
- {beaconcrypt-0.5.2 → beaconcrypt-0.6.1}/beaconcrypt-core/src/ratchet/refined.rs +0 -0
- {beaconcrypt-0.5.2 → beaconcrypt-0.6.1}/beaconcrypt-core/src/ratchet.rs +0 -0
- {beaconcrypt-0.5.2 → beaconcrypt-0.6.1}/beaconcrypt-core/src/record.rs +0 -0
- {beaconcrypt-0.5.2 → beaconcrypt-0.6.1}/beaconcrypt-core/tests/general_registration_admission.rs +0 -0
- /beaconcrypt-0.5.2/beaconcrypt/LICENSE → /beaconcrypt-0.6.1/beaconcrypt-parse/LICENSE-0BSD +0 -0
|
@@ -72,11 +72,10 @@ checksum = "ac07cdecf99051d9a5238b80f35af32cdeba5b336e55d957b318b50137e18da5"
|
|
|
72
72
|
|
|
73
73
|
[[package]]
|
|
74
74
|
name = "beaconcrypt"
|
|
75
|
-
version = "0.
|
|
75
|
+
version = "0.6.1"
|
|
76
76
|
dependencies = [
|
|
77
77
|
"beaconcrypt-core",
|
|
78
|
-
"
|
|
79
|
-
"capnpc",
|
|
78
|
+
"beaconcrypt-parse",
|
|
80
79
|
"cbindgen",
|
|
81
80
|
"libsodium-rs",
|
|
82
81
|
"pyo3",
|
|
@@ -92,6 +91,19 @@ dependencies = [
|
|
|
92
91
|
"zeroize",
|
|
93
92
|
]
|
|
94
93
|
|
|
94
|
+
[[package]]
|
|
95
|
+
name = "beaconcrypt-parse"
|
|
96
|
+
version = "0.1.0"
|
|
97
|
+
|
|
98
|
+
[[package]]
|
|
99
|
+
name = "beaconcrypt-wasm"
|
|
100
|
+
version = "0.6.1"
|
|
101
|
+
dependencies = [
|
|
102
|
+
"beaconcrypt",
|
|
103
|
+
"serde_json",
|
|
104
|
+
"zeroize",
|
|
105
|
+
]
|
|
106
|
+
|
|
95
107
|
[[package]]
|
|
96
108
|
name = "bitflags"
|
|
97
109
|
version = "2.13.2"
|
|
@@ -110,24 +122,6 @@ version = "1.12.1"
|
|
|
110
122
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
111
123
|
checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04"
|
|
112
124
|
|
|
113
|
-
[[package]]
|
|
114
|
-
name = "capnp"
|
|
115
|
-
version = "0.27.2"
|
|
116
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
117
|
-
checksum = "93f7ce2b1b49d58b2b754f9146ef07e3244f9b67e7563bc1292fbd5f01b142f0"
|
|
118
|
-
dependencies = [
|
|
119
|
-
"embedded-io",
|
|
120
|
-
]
|
|
121
|
-
|
|
122
|
-
[[package]]
|
|
123
|
-
name = "capnpc"
|
|
124
|
-
version = "0.27.0"
|
|
125
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
126
|
-
checksum = "82ca16312ddb64529d31c8dc46148671c22e57b80134fa5f17811ad5a6a79492"
|
|
127
|
-
dependencies = [
|
|
128
|
-
"capnp",
|
|
129
|
-
]
|
|
130
|
-
|
|
131
125
|
[[package]]
|
|
132
126
|
name = "cbindgen"
|
|
133
127
|
version = "0.29.4"
|
|
@@ -227,12 +221,6 @@ version = "0.3.9"
|
|
|
227
221
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
228
222
|
checksum = "8b1e3a325bc115f096c8b77bbf027a7c2592230e70be2d985be950d3d5e60ebe"
|
|
229
223
|
|
|
230
|
-
[[package]]
|
|
231
|
-
name = "embedded-io"
|
|
232
|
-
version = "0.7.1"
|
|
233
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
234
|
-
checksum = "9eb1aa714776b75c7e67e1da744b81a129b3ff919c8712b5e1b32252c1f07cc7"
|
|
235
|
-
|
|
236
224
|
[[package]]
|
|
237
225
|
name = "equivalent"
|
|
238
226
|
version = "1.0.3"
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: beaconcrypt
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.6.1
|
|
4
4
|
Classifier: Programming Language :: Rust
|
|
5
5
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
6
6
|
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
7
7
|
License-File: LICENSE
|
|
8
|
+
License-File: beaconcrypt-parse/generated/LICENSE
|
|
8
9
|
Requires-Python: >=3.11
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "beaconcrypt"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.6.1"
|
|
4
4
|
edition = "2024"
|
|
5
5
|
license-file = "LICENSE"
|
|
6
6
|
readme = "README.md"
|
|
@@ -43,7 +43,6 @@ path = "tests/wycheproof.rs"
|
|
|
43
43
|
required-features = ["pqxdh"]
|
|
44
44
|
|
|
45
45
|
[build-dependencies]
|
|
46
|
-
capnpc = "0.27"
|
|
47
46
|
cbindgen = "0.29"
|
|
48
47
|
|
|
49
48
|
[dev-dependencies]
|
|
@@ -53,7 +52,7 @@ serde_json = "1"
|
|
|
53
52
|
|
|
54
53
|
[dependencies]
|
|
55
54
|
beaconcrypt-core = { version = "0.1.1", path = "../beaconcrypt-core" }
|
|
56
|
-
|
|
55
|
+
beaconcrypt-parse = { version = "0.1.0", path = "../beaconcrypt-parse" }
|
|
57
56
|
libsodium-rs = "=0.3.0"
|
|
58
57
|
zeroize = "1.9"
|
|
59
58
|
pyo3 = { version = "0.30.1", features = ["abi3-py311", "experimental-inspect"], optional = true }
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
BSD Zero Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (C) 2026 by 0xd6cb6d73 72226198+0xd6cb6d73@users.noreply.github.com
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
@@ -40,9 +40,9 @@ The ML-KEM public key and ciphertext combined take up ~2.2kb by themselves.
|
|
|
40
40
|
This overhead will grow larger when hybrid signatures are implemented.
|
|
41
41
|
Thankfully, this only affects the registration handshake.
|
|
42
42
|
No subsequent messages are affected, as they only use symmetric cryptography.
|
|
43
|
-
|
|
43
|
+
Follow-on messages use symmetric cryptography with CBOR framing.
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
Earlier builds measured ~6.5MB for the static lib, or ~2MB when building the stdlib with a nightly toolchain. This is largely due to the fact that we need to bring a bunch of rust stuff with us. Unfortunately, most crypto libraries aren't really meant to run in 40KB images, so there's always going to be some floor there. It should however be easy to cut the rust-related stuff by implementing this protocol in C or C++, though you'll still have to pay for the libsodium library.
|
|
46
46
|
|
|
47
47
|
It is very likely that neither the rust nor C interfaces are thread-safe.
|
|
48
48
|
|
|
@@ -58,12 +58,14 @@ I don't use rust a lot, so the code is probably fairly naive. It provides both a
|
|
|
58
58
|
|
|
59
59
|
The reference implementation expects that all beacons are compiled with the server's public key, and that beaconcrypt is initialized with it.
|
|
60
60
|
|
|
61
|
+
Transport uses deterministic CBOR with an inclusive 32 MiB limit on complete encoded messages, including framing, authentication tags, and commitments; plaintext snapshots and JSON state are unaffected. The former Cap'n Proto wire format and public generated Rust modules are removed, so peers and queued messages must use the new [wire format](doc/protocol.md#wire-encoding).
|
|
62
|
+
|
|
61
63
|
Rust, C, Go, and Python support durable full-server state through a caller-supplied snapshot store. Snapshots contain plaintext secrets and are not self-authenticating; the store must protect their integrity and provenance, maintain one rollback-resistant authoritative head, and implement linearizable durable compare-and-swap. Store-backed servers commit accepted receives and other state-changing results before release, while a normally rejected receive preserves the complete state and performs no snapshot encoding or compare-and-swap. The bindings also retain checkpoint-only export and restoration for single-owner applications; those constructors require manual saving after every state-changing operation, and standalone checkpoint files cannot detect rollback. See [server-state persistence](doc/persistence.md) and the runnable examples for [Rust](beaconcrypt/examples/rust/main.rs), [Python](examples/python/main.py), [C](examples/c/main.c), and [Go](examples/go/main.go).
|
|
62
64
|
|
|
63
65
|
## Building
|
|
64
|
-
You will need
|
|
66
|
+
You will need a recent version of Rust; checked-in generated parsers require no schema compiler for normal builds.
|
|
65
67
|
|
|
66
|
-
The
|
|
68
|
+
The Cargo workspace contains the public `beaconcrypt` adapter, `no_std` `beaconcrypt-core` state machines, and [`beaconcrypt-parse`](beaconcrypt-parse/README.md) transport codecs.
|
|
67
69
|
|
|
68
70
|
For windows, I prefer building with stable-gnu for normal usage, and nightly-gnu for release builds. You can find the exact arguments I use to the the static library as small as possible in [release.yml](/.github\workflows\release.yml). The MSVC toolchain is expected to work just as well, I just like mingw.
|
|
69
71
|
|
|
@@ -87,7 +89,7 @@ cargo install --locked cargo-mutants@27.1.0
|
|
|
87
89
|
cargo mutants --workspace --jobs 8
|
|
88
90
|
```
|
|
89
91
|
|
|
90
|
-
The [configuration](.cargo/mutants.toml) exercises
|
|
92
|
+
The [configuration](.cargo/mutants.toml) exercises all three crates through workspace tests and excludes imported generated parser sources, equivalent private-state mutations, and adapters covered by the Go and Python suites. After substantial code additions, every viable mutant must be caught; `mutants.out/missed.txt` and `mutants.out/timeout.txt` must be empty. Finish validation with a complete run without `--iterate`.
|
|
91
93
|
|
|
92
94
|
### Reproducing known-answer test vectors
|
|
93
95
|
|
|
@@ -147,9 +149,16 @@ From python, you can just use the wheels published to pypi, see the [example](ex
|
|
|
147
149
|
|
|
148
150
|
The [C interface](beaconcrypt/src/cbinds.rs) uses opaque role-specific handles; the caller is responsible for their lifetimes and for freeing returned buffers. See the [example](examples/c/main.c) for usage.
|
|
149
151
|
|
|
150
|
-
Go
|
|
152
|
+
Go supports the native CGO bindings and an embedded Wasm backend through wazero,
|
|
153
|
+
using the same import path and public API. Native builds link the Rust library
|
|
154
|
+
built with `gobinds`. Both backends require Go 1.25 or newer. CGO-free builds use a generated guest included in the Go
|
|
155
|
+
release bundle; no binary artifacts are committed to Git. See the
|
|
156
|
+
[Wasm build and release instructions](doc/wasm.md) and the unchanged
|
|
157
|
+
[Go example](examples/go/main.go).
|
|
151
158
|
|
|
152
159
|
# Copyright
|
|
153
160
|
This work is dedicated to the public domain.
|
|
154
161
|
|
|
162
|
+
Imported generated parsers retain their [Apache-2.0 license](beaconcrypt-parse/generated/LICENSE).
|
|
163
|
+
|
|
155
164
|
The C and go bindings, as well as most tests and the GH action code were generated by an LLM. This includes the KAT generation scripts, the ChaCha20-Poly1305 invisible salamanders implementation and its associated documentation.
|
|
@@ -4,22 +4,11 @@ fn main() {
|
|
|
4
4
|
let crate_dir = std::path::PathBuf::from(
|
|
5
5
|
std::env::var_os("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR is set by Cargo"),
|
|
6
6
|
);
|
|
7
|
-
let schema_dir = crate_dir.join("src/schema");
|
|
8
7
|
|
|
9
8
|
if cfg!(windows) {
|
|
10
9
|
println!("cargo:rustc-link-lib=bcrypt");
|
|
11
10
|
}
|
|
12
11
|
|
|
13
|
-
capnpc::CompilerCommand::new()
|
|
14
|
-
.src_prefix(&schema_dir)
|
|
15
|
-
.import_path(&schema_dir)
|
|
16
|
-
//.output_path("src/")
|
|
17
|
-
.file(schema_dir.join("phase1.capnp"))
|
|
18
|
-
.file(schema_dir.join("phase2.capnp"))
|
|
19
|
-
.file(schema_dir.join("cryptoframe.capnp"))
|
|
20
|
-
.run()
|
|
21
|
-
.expect("schema compiler command");
|
|
22
|
-
|
|
23
12
|
//let deps_to_parse = "libsodium_rs";
|
|
24
13
|
//
|
|
25
14
|
let bindings = cbindgen::Builder::new()
|
|
@@ -2,15 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
use crate::pqxdh::{AD_SIZE, derive_root_key_input, shared_secrets, zeroize_shared_secrets};
|
|
4
4
|
use crate::ratchet::{
|
|
5
|
-
RatchetManager, RatchetStatus, decrypt_message_with_ratchet,
|
|
5
|
+
RatchetManager, RatchetStatus, decrypt_message_with_ratchet,
|
|
6
|
+
decrypt_registration_message_with_ratchet, encrypt_message_with_ratchet,
|
|
6
7
|
finish_initial_ratchet_kdf,
|
|
7
8
|
};
|
|
8
9
|
use crate::shared::DhSecret;
|
|
9
|
-
use crate::{phase1_capnp, phase2_capnp};
|
|
10
10
|
use beaconcrypt_core::pqxdh::{self as verified_pqxdh, start_beacon_candidate_ratchet_kdf};
|
|
11
|
-
use
|
|
11
|
+
use beaconcrypt_parse::{InitKex, decode_response};
|
|
12
12
|
use libsodium_rs::{crypto_kem, crypto_kx, crypto_scalarmult, crypto_sign, ensure_init};
|
|
13
|
-
use std::vec;
|
|
14
13
|
|
|
15
14
|
enum BeaconState {
|
|
16
15
|
Fresh {
|
|
@@ -343,18 +342,16 @@ impl ProviderBeacon for Beacon {
|
|
|
343
342
|
one_time_public_key: onetime_public,
|
|
344
343
|
},
|
|
345
344
|
);
|
|
346
|
-
let mut msg = TypedBuilder::<phase1_capnp::init_kex::Owned>::new_default();
|
|
347
|
-
let mut bundle = msg.init_root();
|
|
348
|
-
bundle.set_identity_key(started.message.identity_key());
|
|
349
345
|
let prekey_sig = crypto_sign::sign(started.message.prekey(), self.identity_sk()).ok()?;
|
|
350
|
-
bundle.set_pre_key(&prekey_sig);
|
|
351
346
|
let onetime_sig =
|
|
352
347
|
crypto_sign::sign(started.message.one_time_key(), self.identity_sk()).ok()?;
|
|
353
|
-
bundle.set_one_time_key(&onetime_sig);
|
|
354
348
|
let pq_sig = crypto_sign::sign(started.message.pq_key(), self.identity_sk()).ok()?;
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
349
|
+
let buffer = crate::wire::encode_init(InitKex {
|
|
350
|
+
identity_key: started.message.identity_key(),
|
|
351
|
+
pre_key: &prekey_sig,
|
|
352
|
+
one_time_key: &onetime_sig,
|
|
353
|
+
pq_key: &pq_sig,
|
|
354
|
+
})?;
|
|
358
355
|
|
|
359
356
|
let fallback = BeaconState::Aborted {
|
|
360
357
|
control: verified_pqxdh::beacon_abort_fresh(control),
|
|
@@ -419,16 +416,11 @@ impl ProviderBeacon for Beacon {
|
|
|
419
416
|
),
|
|
420
417
|
_ => return None,
|
|
421
418
|
};
|
|
422
|
-
let
|
|
423
|
-
let typed_reader = TypedReader::<_, phase2_capnp::kex_response::Owned>::new(reader);
|
|
424
|
-
let response = typed_reader.get().ok()?;
|
|
419
|
+
let response = decode_response(bytes)?;
|
|
425
420
|
let kem_ciphertext =
|
|
426
|
-
crypto_kem::mlkem768::Ciphertext::from_bytes(response.
|
|
427
|
-
|
|
428
|
-
let
|
|
429
|
-
crypto_kx::PublicKey::from_bytes(response.get_ephemeral_key().ok()?).ok()?;
|
|
430
|
-
let response_server =
|
|
431
|
-
crypto_sign::PublicKey::from_bytes(response.get_identity_key().ok()?).ok()?;
|
|
421
|
+
crypto_kem::mlkem768::Ciphertext::from_bytes(response.kem_cipher_text).ok()?;
|
|
422
|
+
let ephemeral = crypto_kx::PublicKey::from_bytes(response.ephemeral_key).ok()?;
|
|
423
|
+
let response_server = crypto_sign::PublicKey::from_bytes(response.identity_key).ok()?;
|
|
432
424
|
let server_kex_id = crypto_sign::ed25519_pk_to_curve25519(&response_server).ok()?;
|
|
433
425
|
let beacon_kex_id = crypto_sign::ed25519_sk_to_curve25519(self.identity_sk()).ok()?;
|
|
434
426
|
let kem_shared = crypto_kem::mlkem768::decapsulate(&kem_ciphertext, pq_secret).ok()?;
|
|
@@ -449,7 +441,7 @@ impl ProviderBeacon for Beacon {
|
|
|
449
441
|
.into();
|
|
450
442
|
let mut finish_inputs = verified_pqxdh::BeaconFinishInputs {
|
|
451
443
|
response_server_identity: *response_server.as_bytes(),
|
|
452
|
-
assigned_key_id: response.
|
|
444
|
+
assigned_key_id: response.key_id,
|
|
453
445
|
shared_secrets: shared_secrets(dh1, dh2, dh3, dh4, &kem_shared)?,
|
|
454
446
|
};
|
|
455
447
|
let prepared = verified_pqxdh::beacon_prepare_finish(control, &finish_inputs);
|
|
@@ -459,8 +451,8 @@ impl ProviderBeacon for Beacon {
|
|
|
459
451
|
let pending = start_beacon_candidate_ratchet_kdf(&candidate, derived_secret.as_array());
|
|
460
452
|
let mut ratchet = RatchetManager::from_kernel(finish_initial_ratchet_kdf(pending));
|
|
461
453
|
let associated_data = *candidate.associated_data();
|
|
462
|
-
let decrypted =
|
|
463
|
-
response.
|
|
454
|
+
let decrypted = decrypt_registration_message_with_ratchet(
|
|
455
|
+
response.app_cipher_text,
|
|
464
456
|
candidate.server_key_id(),
|
|
465
457
|
&associated_data,
|
|
466
458
|
&mut ratchet,
|
|
@@ -546,23 +538,16 @@ mod tests {
|
|
|
546
538
|
let frame =
|
|
547
539
|
encrypt_message_with_ratchet(&payload, original.kid, 0, &ad, &mut sender).unwrap();
|
|
548
540
|
assert_eq!(sender.status().send_sequence(), 1);
|
|
549
|
-
let
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
541
|
+
let raw_frame = beaconcrypt_parse::decode_frame(&frame.ciphertext).unwrap();
|
|
542
|
+
let response = decode_response(&original.serialized).unwrap();
|
|
543
|
+
let serialized = crate::wire::encode_response(beaconcrypt_parse::KexResponse {
|
|
544
|
+
identity_key: response.identity_key,
|
|
545
|
+
ephemeral_key: response.ephemeral_key,
|
|
546
|
+
kem_cipher_text: response.kem_cipher_text,
|
|
547
|
+
key_id: original.kid,
|
|
548
|
+
app_cipher_text: raw_frame.cipher_text,
|
|
549
|
+
})
|
|
553
550
|
.unwrap();
|
|
554
|
-
let typed = TypedReader::<_, phase2_capnp::kex_response::Owned>::new(reader);
|
|
555
|
-
let response = typed.get().unwrap();
|
|
556
|
-
let mut builder = TypedBuilder::<phase2_capnp::kex_response::Owned>::new_default();
|
|
557
|
-
let mut changed = builder.init_root();
|
|
558
|
-
changed.set_identity_key(response.get_identity_key().unwrap());
|
|
559
|
-
changed.set_ephemeral_key(response.get_ephemeral_key().unwrap());
|
|
560
|
-
changed.set_kem_cipher_text(response.get_kem_cipher_text().unwrap());
|
|
561
|
-
changed.set_key_id(original.kid);
|
|
562
|
-
changed.set_app_cipher_text(&frame);
|
|
563
|
-
let mut serialized = Vec::new();
|
|
564
|
-
capnp::serialize_packed::write_message(&mut serialized, builder.borrow_inner())
|
|
565
|
-
.unwrap();
|
|
566
551
|
let opened = beacon.finish_registration(&serialized);
|
|
567
552
|
if case == 9 {
|
|
568
553
|
assert_eq!(opened, Some(vec![0x7e]));
|
|
@@ -1176,23 +1176,15 @@ mod tests {
|
|
|
1176
1176
|
let server = create_durable(&state, &destroyed);
|
|
1177
1177
|
let (mut beacon, _) = register(&server);
|
|
1178
1178
|
let inbound = beacon.encrypt_message(b"authentic").unwrap();
|
|
1179
|
-
let
|
|
1180
|
-
|
|
1181
|
-
.unwrap();
|
|
1182
|
-
let original = reader
|
|
1183
|
-
.get_root::<crate::cryptoframe_capnp::crypto_frame::Reader<'_>>()
|
|
1184
|
-
.unwrap();
|
|
1185
|
-
let mut payload = original.get_cipher_text().unwrap().to_vec();
|
|
1179
|
+
let original = beaconcrypt_parse::decode_frame(inbound.as_ref()).unwrap();
|
|
1180
|
+
let mut payload = original.cipher_text.to_vec();
|
|
1186
1181
|
*payload.last_mut().unwrap() ^= 1;
|
|
1187
|
-
let
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
frame.set_cipher_text(&payload);
|
|
1194
|
-
let mut corrupted = Vec::new();
|
|
1195
|
-
capnp::serialize::write_message(&mut corrupted, builder.borrow_inner()).unwrap();
|
|
1182
|
+
let corrupted = crate::wire::encode_frame(beaconcrypt_parse::CryptoFrame {
|
|
1183
|
+
seq: original.seq,
|
|
1184
|
+
key_id: original.key_id,
|
|
1185
|
+
cipher_text: &payload,
|
|
1186
|
+
})
|
|
1187
|
+
.unwrap();
|
|
1196
1188
|
let before = state.lock().unwrap().bytes.clone();
|
|
1197
1189
|
let attempts = state.lock().unwrap().attempts;
|
|
1198
1190
|
assert!(
|
|
@@ -11,6 +11,11 @@ mod ratchet;
|
|
|
11
11
|
#[cfg(feature = "server")]
|
|
12
12
|
mod server;
|
|
13
13
|
mod shared;
|
|
14
|
+
mod wire;
|
|
15
|
+
|
|
16
|
+
/// Maximum complete encoded transport message size in bytes, including all framing.
|
|
17
|
+
pub const MAX_MESSAGE_SIZE: usize = 33_554_432;
|
|
18
|
+
const _: () = assert!(MAX_MESSAGE_SIZE == beaconcrypt_parse::MAX_MESSAGE_SIZE);
|
|
14
19
|
|
|
15
20
|
/// # Safety
|
|
16
21
|
/// This is a horrible hack to compensate for the fact that libsodium 0.2.4 fails to link to `memset_explicit` on Windows when using the GNU toolchain. You probably should not use this
|
|
@@ -80,10 +85,6 @@ pub use server::{
|
|
|
80
85
|
};
|
|
81
86
|
pub use shared::{DH_OUT_LEN, Decrypted, ED25519_SEED_SIZE, Encrypted, KEX_KDF_OUT_LEN, SignType};
|
|
82
87
|
|
|
83
|
-
capnp::generated_code!(pub mod phase1_capnp);
|
|
84
|
-
capnp::generated_code!(pub mod phase2_capnp);
|
|
85
|
-
capnp::generated_code!(pub mod cryptoframe_capnp);
|
|
86
|
-
|
|
87
88
|
#[cfg(any(feature = "cbinds", feature = "gobinds"))]
|
|
88
89
|
mod cbinds;
|
|
89
90
|
|
|
@@ -93,6 +94,10 @@ mod pybinds;
|
|
|
93
94
|
#[cfg(feature = "pybinds")]
|
|
94
95
|
#[pyo3::pymodule]
|
|
95
96
|
mod beaconcrypt {
|
|
97
|
+
/// Maximum complete encoded transport message in bytes; snapshots and JSON state are uncapped.
|
|
98
|
+
#[pymodule_export]
|
|
99
|
+
const MAX_MESSAGE_SIZE: usize = crate::MAX_MESSAGE_SIZE;
|
|
100
|
+
|
|
96
101
|
#[pymodule_export]
|
|
97
102
|
use crate::pybinds::{
|
|
98
103
|
Beacon, EncryptStatePy, PersistenceError, RegResponsePy, Server, SnapshotHeadPy,
|
|
@@ -446,6 +446,9 @@ impl<S: SnapshotStore> PersistentServer<S> {
|
|
|
446
446
|
&mut self,
|
|
447
447
|
buffer: &[u8],
|
|
448
448
|
) -> Result<Option<RegistrationOutput>, PersistenceError> {
|
|
449
|
+
if buffer.len() > beaconcrypt_parse::MAX_MESSAGE_SIZE {
|
|
450
|
+
return self.reject_oversized();
|
|
451
|
+
}
|
|
449
452
|
self.commit(|server| server.get_shared_secret(buffer))
|
|
450
453
|
}
|
|
451
454
|
|
|
@@ -454,6 +457,9 @@ impl<S: SnapshotStore> PersistentServer<S> {
|
|
|
454
457
|
registration: RegistrationOutput,
|
|
455
458
|
data: Option<&[u8]>,
|
|
456
459
|
) -> Result<Option<RegResponse>, PersistenceError> {
|
|
460
|
+
if !self.server.registration_response_fits(data) {
|
|
461
|
+
return self.reject_oversized();
|
|
462
|
+
}
|
|
457
463
|
self.commit(|server| server.build_registration_response(registration, data))
|
|
458
464
|
}
|
|
459
465
|
|
|
@@ -462,6 +468,9 @@ impl<S: SnapshotStore> PersistentServer<S> {
|
|
|
462
468
|
bytes: &[u8],
|
|
463
469
|
kid: u64,
|
|
464
470
|
) -> Result<Option<Encrypted>, PersistenceError> {
|
|
471
|
+
if !self.outgoing_message_fits(bytes.len(), kid) {
|
|
472
|
+
return self.reject_oversized();
|
|
473
|
+
}
|
|
465
474
|
self.commit(|server| server.encrypt_message(bytes, kid))
|
|
466
475
|
}
|
|
467
476
|
|
|
@@ -476,6 +485,9 @@ impl<S: SnapshotStore> PersistentServer<S> {
|
|
|
476
485
|
bytes: &[u8],
|
|
477
486
|
kid: u64,
|
|
478
487
|
) -> Result<Option<SendState>, PersistenceError> {
|
|
488
|
+
if !self.outgoing_message_fits(bytes.len(), kid) {
|
|
489
|
+
return self.reject_oversized();
|
|
490
|
+
}
|
|
479
491
|
self.commit(|server| server.encrypt_and_update(bytes, kid))
|
|
480
492
|
}
|
|
481
493
|
|
|
@@ -493,9 +505,28 @@ impl<S: SnapshotStore> PersistentServer<S> {
|
|
|
493
505
|
bytes: &[u8],
|
|
494
506
|
kid: u64,
|
|
495
507
|
) -> Result<Option<String>, PersistenceError> {
|
|
508
|
+
if !self.outgoing_message_fits(bytes.len(), kid) {
|
|
509
|
+
return self.reject_oversized();
|
|
510
|
+
}
|
|
496
511
|
self.commit(|server| server.encrypt_and_update_json(bytes, kid))
|
|
497
512
|
}
|
|
498
513
|
|
|
514
|
+
fn outgoing_message_fits(&self, plaintext_len: usize, kid: u64) -> bool {
|
|
515
|
+
let sequence = self
|
|
516
|
+
.server
|
|
517
|
+
.ratchet_status(kid)
|
|
518
|
+
.map_or(0, |status| status.send_sequence().saturating_add(1));
|
|
519
|
+
crate::wire::frame_len(plaintext_len, sequence, self.server.identity_key_kid()).is_some()
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
fn reject_oversized<T>(&self) -> Result<Option<T>, PersistenceError> {
|
|
523
|
+
if self.poisoned {
|
|
524
|
+
Err(PersistenceError::Poisoned)
|
|
525
|
+
} else {
|
|
526
|
+
Ok(None)
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
|
|
499
530
|
pub fn decrypt_and_update_json(
|
|
500
531
|
&mut self,
|
|
501
532
|
bytes: &[u8],
|
|
@@ -919,27 +950,15 @@ mod tests {
|
|
|
919
950
|
let _second = beacon.encrypt_message(b"second").unwrap();
|
|
920
951
|
let third = beacon.encrypt_message(b"third").unwrap();
|
|
921
952
|
|
|
922
|
-
let
|
|
923
|
-
|
|
924
|
-
capnp::message::ReaderOptions::new(),
|
|
925
|
-
)
|
|
926
|
-
.unwrap();
|
|
927
|
-
let typed =
|
|
928
|
-
capnp::message::TypedReader::<_, crate::cryptoframe_capnp::crypto_frame::Owned>::new(
|
|
929
|
-
message,
|
|
930
|
-
);
|
|
931
|
-
let frame = typed.get().unwrap();
|
|
932
|
-
let mut ciphertext = frame.get_cipher_text().unwrap().to_vec();
|
|
953
|
+
let frame = beaconcrypt_parse::decode_frame(&third.ciphertext).unwrap();
|
|
954
|
+
let mut ciphertext = frame.cipher_text.to_vec();
|
|
933
955
|
ciphertext[0] ^= 1;
|
|
934
|
-
let
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
corrupted.set_cipher_text(&ciphertext);
|
|
941
|
-
let mut rejected = Vec::new();
|
|
942
|
-
capnp::serialize::write_message(&mut rejected, message.borrow_inner()).unwrap();
|
|
956
|
+
let rejected = crate::wire::encode_frame(beaconcrypt_parse::CryptoFrame {
|
|
957
|
+
seq: frame.seq,
|
|
958
|
+
key_id: frame.key_id,
|
|
959
|
+
cipher_text: &ciphertext,
|
|
960
|
+
})
|
|
961
|
+
.unwrap();
|
|
943
962
|
|
|
944
963
|
let live = persistent.server.serialize_state().unwrap();
|
|
945
964
|
let head = persistent.head();
|
|
@@ -1008,27 +1027,15 @@ mod tests {
|
|
|
1008
1027
|
let full_state = restored.head();
|
|
1009
1028
|
let full_snapshot = restored.store.snapshot.clone();
|
|
1010
1029
|
let target = &frames[RATCHET_MAX_GAP as usize - 1].1;
|
|
1011
|
-
let
|
|
1012
|
-
|
|
1013
|
-
capnp::message::ReaderOptions::new(),
|
|
1014
|
-
)
|
|
1015
|
-
.unwrap();
|
|
1016
|
-
let typed =
|
|
1017
|
-
capnp::message::TypedReader::<_, crate::cryptoframe_capnp::crypto_frame::Owned>::new(
|
|
1018
|
-
message,
|
|
1019
|
-
);
|
|
1020
|
-
let frame = typed.get().unwrap();
|
|
1021
|
-
let mut ciphertext = frame.get_cipher_text().unwrap().to_vec();
|
|
1030
|
+
let frame = beaconcrypt_parse::decode_frame(&target.ciphertext).unwrap();
|
|
1031
|
+
let mut ciphertext = frame.cipher_text.to_vec();
|
|
1022
1032
|
ciphertext[0] ^= 1;
|
|
1023
|
-
let
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
corrupted.set_cipher_text(&ciphertext);
|
|
1030
|
-
let mut rejected = Vec::new();
|
|
1031
|
-
capnp::serialize::write_message(&mut rejected, message.borrow_inner()).unwrap();
|
|
1033
|
+
let rejected = crate::wire::encode_frame(beaconcrypt_parse::CryptoFrame {
|
|
1034
|
+
seq: frame.seq,
|
|
1035
|
+
key_id: frame.key_id,
|
|
1036
|
+
cipher_text: &ciphertext,
|
|
1037
|
+
})
|
|
1038
|
+
.unwrap();
|
|
1032
1039
|
|
|
1033
1040
|
assert!(restored.decrypt_message(&rejected).unwrap().is_none());
|
|
1034
1041
|
assert_eq!(restored.head(), full_state);
|