beaconcrypt 0.4.3__tar.gz → 0.5.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.4.3 → beaconcrypt-0.5.1}/Cargo.lock +9 -1
- beaconcrypt-0.5.1/Cargo.toml +9 -0
- {beaconcrypt-0.4.3 → beaconcrypt-0.5.1}/PKG-INFO +1 -1
- {beaconcrypt-0.4.3 → beaconcrypt-0.5.1/beaconcrypt}/Cargo.toml +4 -12
- beaconcrypt-0.5.1/beaconcrypt/LICENSE +7 -0
- {beaconcrypt-0.4.3 → beaconcrypt-0.5.1/beaconcrypt}/README.md +35 -10
- beaconcrypt-0.5.1/beaconcrypt/bindings.h +435 -0
- beaconcrypt-0.5.1/beaconcrypt/build.rs +60 -0
- {beaconcrypt-0.4.3 → beaconcrypt-0.5.1/beaconcrypt}/examples/rust/main.rs +78 -12
- beaconcrypt-0.5.1/beaconcrypt/src/beacon.rs +577 -0
- beaconcrypt-0.5.1/beaconcrypt/src/cbinds.rs +1503 -0
- beaconcrypt-0.5.1/beaconcrypt/src/deser.rs +1022 -0
- {beaconcrypt-0.4.3 → beaconcrypt-0.5.1/beaconcrypt}/src/error.rs +10 -0
- {beaconcrypt-0.4.3 → beaconcrypt-0.5.1/beaconcrypt}/src/lib.rs +22 -7
- beaconcrypt-0.5.1/beaconcrypt/src/persistence.rs +1130 -0
- beaconcrypt-0.5.1/beaconcrypt/src/pqxdh.rs +588 -0
- beaconcrypt-0.5.1/beaconcrypt/src/pybinds.rs +559 -0
- beaconcrypt-0.5.1/beaconcrypt/src/ratchet.rs +622 -0
- {beaconcrypt-0.4.3 → beaconcrypt-0.5.1/beaconcrypt}/src/ser.rs +113 -64
- beaconcrypt-0.5.1/beaconcrypt/src/server.rs +533 -0
- {beaconcrypt-0.4.3 → beaconcrypt-0.5.1/beaconcrypt}/src/shared.rs +641 -606
- {beaconcrypt-0.4.3 → beaconcrypt-0.5.1/beaconcrypt}/tests/beacon.rs +3 -6
- beaconcrypt-0.5.1/beaconcrypt/tests/c_persistence.c +176 -0
- beaconcrypt-0.5.1/beaconcrypt/tests/construction.rs +39 -0
- {beaconcrypt-0.4.3 → beaconcrypt-0.5.1/beaconcrypt}/tests/protocol.rs +466 -385
- beaconcrypt-0.5.1/beaconcrypt/tests/raw_receive.rs +164 -0
- beaconcrypt-0.5.1/beaconcrypt/tests/record_opening.rs +157 -0
- beaconcrypt-0.5.1/beaconcrypt/tests/registration_completion.rs +266 -0
- beaconcrypt-0.5.1/beaconcrypt/tests/registration_response_alias.rs +91 -0
- {beaconcrypt-0.4.3 → beaconcrypt-0.5.1/beaconcrypt}/tests/rooterberg.rs +1 -1
- beaconcrypt-0.5.1/beaconcrypt/tests/server.rs +864 -0
- {beaconcrypt-0.4.3 → beaconcrypt-0.5.1/beaconcrypt}/tests/wycheproof.rs +6 -6
- beaconcrypt-0.5.1/beaconcrypt-core/Cargo.toml +21 -0
- beaconcrypt-0.5.1/beaconcrypt-core/LICENSE +7 -0
- beaconcrypt-0.5.1/beaconcrypt-core/README.md +5 -0
- beaconcrypt-0.5.1/beaconcrypt-core/src/commitment.rs +108 -0
- beaconcrypt-0.5.1/beaconcrypt-core/src/constants.rs +1 -0
- beaconcrypt-0.5.1/beaconcrypt-core/src/lib.rs +29 -0
- beaconcrypt-0.5.1/beaconcrypt-core/src/pqxdh/concrete.rs +115 -0
- beaconcrypt-0.5.1/beaconcrypt-core/src/pqxdh.rs +1582 -0
- beaconcrypt-0.5.1/beaconcrypt-core/src/ratchet/concrete.rs +613 -0
- beaconcrypt-0.5.1/beaconcrypt-core/src/ratchet/control.rs +564 -0
- beaconcrypt-0.5.1/beaconcrypt-core/src/ratchet/refined.rs +986 -0
- beaconcrypt-0.5.1/beaconcrypt-core/src/ratchet.rs +1883 -0
- beaconcrypt-0.5.1/beaconcrypt-core/src/record.rs +185 -0
- beaconcrypt-0.5.1/beaconcrypt-core/tests/general_registration_admission.rs +137 -0
- beaconcrypt-0.5.1/beaconcrypt.pyi +103 -0
- {beaconcrypt-0.4.3 → beaconcrypt-0.5.1}/pyproject.toml +5 -1
- beaconcrypt-0.4.3/.cargo/config.toml +0 -1
- beaconcrypt-0.4.3/.github/workflows/codeql.yml +0 -105
- beaconcrypt-0.4.3/.github/workflows/go.yml +0 -140
- beaconcrypt-0.4.3/.github/workflows/python.yml +0 -135
- beaconcrypt-0.4.3/.github/workflows/release.yml +0 -150
- beaconcrypt-0.4.3/.github/workflows/rust.yml +0 -32
- beaconcrypt-0.4.3/.gitignore +0 -77
- beaconcrypt-0.4.3/.gitmodules +0 -6
- beaconcrypt-0.4.3/beaconcrypt.go +0 -417
- beaconcrypt-0.4.3/beaconcrypt.pyi +0 -47
- beaconcrypt-0.4.3/beaconcrypt_test.go +0 -1449
- beaconcrypt-0.4.3/bindings.h +0 -146
- beaconcrypt-0.4.3/build.rs +0 -37
- beaconcrypt-0.4.3/clippy.toml +0 -1
- beaconcrypt-0.4.3/doc/multi-opening-fixture.md +0 -218
- beaconcrypt-0.4.3/doc/persistence.md +0 -95
- beaconcrypt-0.4.3/doc/protocol.md +0 -156
- beaconcrypt-0.4.3/doc/rationale.md +0 -11
- beaconcrypt-0.4.3/doc/rooterberg.md +0 -59
- beaconcrypt-0.4.3/doc/threat_model.md +0 -38
- beaconcrypt-0.4.3/doc/wycheproof.md +0 -56
- beaconcrypt-0.4.3/examples/c/CMakeLists.txt +0 -70
- beaconcrypt-0.4.3/examples/c/README.md +0 -16
- beaconcrypt-0.4.3/examples/c/main.c +0 -326
- beaconcrypt-0.4.3/examples/go/.gitignore +0 -1
- beaconcrypt-0.4.3/examples/go/README.md +0 -11
- beaconcrypt-0.4.3/examples/go/go.mod +0 -7
- beaconcrypt-0.4.3/examples/go/go.sum +0 -0
- beaconcrypt-0.4.3/examples/go/main.go +0 -161
- beaconcrypt-0.4.3/examples/python/.gitignore +0 -2
- beaconcrypt-0.4.3/examples/python/README.md +0 -4
- beaconcrypt-0.4.3/examples/python/main.py +0 -69
- beaconcrypt-0.4.3/examples/python/pyproject.toml +0 -11
- beaconcrypt-0.4.3/go.mod +0 -7
- beaconcrypt-0.4.3/go.sum +0 -4
- beaconcrypt-0.4.3/rustfmt.toml +0 -5
- beaconcrypt-0.4.3/scripts/derive_multi_opening.py +0 -270
- beaconcrypt-0.4.3/scripts/generate_kat_vectors.go +0 -321
- beaconcrypt-0.4.3/scripts/generate_kat_vectors.py +0 -242
- beaconcrypt-0.4.3/scripts/generate_python_stubs.py +0 -47
- beaconcrypt-0.4.3/src/beacon.rs +0 -6
- beaconcrypt-0.4.3/src/cbinds.rs +0 -385
- beaconcrypt-0.4.3/src/deser.rs +0 -775
- beaconcrypt-0.4.3/src/pqxdh.rs +0 -1027
- beaconcrypt-0.4.3/src/pybinds.rs +0 -198
- beaconcrypt-0.4.3/src/server.rs +0 -79
- beaconcrypt-0.4.3/tests/server.rs +0 -308
- beaconcrypt-0.4.3/tests/test_encryption.py +0 -317
- beaconcrypt-0.4.3/tests/test_registration.py +0 -74
- beaconcrypt-0.4.3/tests/test_server_state.py +0 -237
- beaconcrypt-0.4.3/uv.lock +0 -247
- {beaconcrypt-0.4.3 → beaconcrypt-0.5.1}/LICENSE +0 -0
- {beaconcrypt-0.4.3 → beaconcrypt-0.5.1/beaconcrypt}/examples/rust/README.md +0 -0
- {beaconcrypt-0.4.3 → beaconcrypt-0.5.1/beaconcrypt}/src/schema/cryptoframe.capnp +0 -0
- {beaconcrypt-0.4.3 → beaconcrypt-0.5.1/beaconcrypt}/src/schema/phase1.capnp +0 -0
- {beaconcrypt-0.4.3 → beaconcrypt-0.5.1/beaconcrypt}/src/schema/phase2.capnp +0 -0
|
@@ -78,8 +78,9 @@ checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
|
|
|
78
78
|
|
|
79
79
|
[[package]]
|
|
80
80
|
name = "beaconcrypt"
|
|
81
|
-
version = "0.
|
|
81
|
+
version = "0.5.1"
|
|
82
82
|
dependencies = [
|
|
83
|
+
"beaconcrypt-core",
|
|
83
84
|
"capnp",
|
|
84
85
|
"capnpc",
|
|
85
86
|
"cbindgen",
|
|
@@ -90,6 +91,13 @@ dependencies = [
|
|
|
90
91
|
"zeroize",
|
|
91
92
|
]
|
|
92
93
|
|
|
94
|
+
[[package]]
|
|
95
|
+
name = "beaconcrypt-core"
|
|
96
|
+
version = "0.1.0"
|
|
97
|
+
dependencies = [
|
|
98
|
+
"zeroize",
|
|
99
|
+
]
|
|
100
|
+
|
|
93
101
|
[[package]]
|
|
94
102
|
name = "bitflags"
|
|
95
103
|
version = "2.13.1"
|
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "beaconcrypt"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.5.1"
|
|
4
4
|
edition = "2024"
|
|
5
5
|
license-file = "LICENSE"
|
|
6
6
|
readme = "README.md"
|
|
7
7
|
description = "Cryptographic transport for C2 channels"
|
|
8
8
|
rust-version = "1.96"
|
|
9
9
|
repository = "https://github.com/0xd6cb6d73/beaconcrypt"
|
|
10
|
-
exclude = [
|
|
11
|
-
"rooterberg/**",
|
|
12
|
-
"wycheproof/**",
|
|
13
|
-
]
|
|
14
10
|
|
|
15
11
|
[lib]
|
|
16
12
|
name = "beaconcrypt"
|
|
@@ -51,12 +47,14 @@ capnpc = "0.26"
|
|
|
51
47
|
cbindgen = "0.29"
|
|
52
48
|
|
|
53
49
|
[dev-dependencies]
|
|
50
|
+
beaconcrypt-core = { path = "../beaconcrypt-core", features = ["test-utils"] }
|
|
54
51
|
serde = { version = "1", features = ["derive"] }
|
|
55
52
|
serde_json = "1"
|
|
56
53
|
|
|
57
54
|
[dependencies]
|
|
55
|
+
beaconcrypt-core = { version = "0.1.0", path = "../beaconcrypt-core" }
|
|
58
56
|
capnp = "0.26"
|
|
59
|
-
libsodium-rs = "0.2"
|
|
57
|
+
libsodium-rs = "=0.2.4"
|
|
60
58
|
zeroize = "1.9"
|
|
61
59
|
pyo3 = { version = "0.29.0", features = ["abi3-py311", "experimental-inspect"], optional = true }
|
|
62
60
|
serde = { version = "1", features = ["derive"], optional = true }
|
|
@@ -72,12 +70,6 @@ cbinds = ["beacon", "server", "pqxdh"]
|
|
|
72
70
|
pybinds = ["dep:pyo3", "beacon", "server", "pqxdh"]
|
|
73
71
|
all = ["gobinds", "pybinds", "cbinds"]
|
|
74
72
|
|
|
75
|
-
[profile.release]
|
|
76
|
-
strip = true
|
|
77
|
-
lto = true
|
|
78
|
-
codegen-units = 1
|
|
79
|
-
panic = "abort"
|
|
80
|
-
|
|
81
73
|
[package.metadata.maturin]
|
|
82
74
|
name = "beaconcrypt"
|
|
83
75
|
bindings = "pyo3"
|
|
@@ -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.
|
|
@@ -34,31 +34,43 @@ bool transport::send(const std::span<const uint8_t> data) {
|
|
|
34
34
|
In essence, this **only** handles crypto, you still get to do whatever you want on the transport side.
|
|
35
35
|
|
|
36
36
|
## Limitations
|
|
37
|
-
In short: PQ algorithms take a lot more space than classical ones.
|
|
37
|
+
In short: PQ algorithms take a lot more space than classical ones.
|
|
38
|
+
This is unfortunately unavoidable. Therfore, the initial registration handshake will be somewhat large.
|
|
39
|
+
The ML-KEM public key and ciphertext combined take up ~2.2kb by themselves.
|
|
40
|
+
This overhead will grow larger when hybrid signatures are implemented.
|
|
41
|
+
Thankfully, this only affects the registration handshake.
|
|
42
|
+
No subsequent messages are affected, as they only use symmetric cryptography.
|
|
43
|
+
However, this does not impact any follow on messages, for which the only overhead is the captn' proto framing.
|
|
38
44
|
|
|
39
|
-
The reference implementation is large, ~6.5MB for the static lib. It goes down to ~
|
|
45
|
+
The reference implementation is large, ~6.5MB for the static lib. It goes down to ~2MB if building the stdlib ourselves 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 + captn proto libraries.
|
|
40
46
|
|
|
41
|
-
|
|
47
|
+
It is very likely that neither the rust nor C interfaces are thread-safe.
|
|
42
48
|
|
|
43
49
|
# TODOs
|
|
44
|
-
Test the C interface
|
|
50
|
+
Test the C interface.
|
|
51
|
+
|
|
52
|
+
See about adding proofs.
|
|
53
|
+
|
|
54
|
+
Make the server interface thread-safe in rust.
|
|
45
55
|
|
|
46
56
|
# Reference implementation
|
|
47
57
|
I don't use rust a lot, so the code is probably fairly naive. It provides both a beacon and server implementation with C bindings through `cbindgen`. Ideally more bindings would be built on top of that so it can be used in the mythic server-side.
|
|
48
58
|
|
|
49
59
|
The reference implementation expects that all beacons are compiled with the server's public key, and that beaconcrypt is initialized with it.
|
|
50
60
|
|
|
51
|
-
|
|
61
|
+
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).
|
|
52
62
|
|
|
53
63
|
## Building
|
|
54
64
|
You will need [Capn'Proto](https://capnproto.org/install.html) (just the binaries) and a recent version of rust for every build.
|
|
55
65
|
|
|
66
|
+
The repository is a Cargo workspace containing the public `beaconcrypt` adapter and the `no_std` `beaconcrypt-core` state machines.
|
|
67
|
+
|
|
56
68
|
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.
|
|
57
69
|
|
|
58
70
|
Build and run all tests:
|
|
59
71
|
```bash
|
|
60
|
-
cargo test
|
|
61
|
-
cargo build --features gobinds --release --target x86_64-pc-windows-gnu
|
|
72
|
+
cargo test --workspace
|
|
73
|
+
cargo build -p beaconcrypt --features gobinds --release --target x86_64-pc-windows-gnu
|
|
62
74
|
go test -a -count=1 .
|
|
63
75
|
uv run maturin develop --uv
|
|
64
76
|
uv run pytest tests
|
|
@@ -66,6 +78,17 @@ uv run pytest tests
|
|
|
66
78
|
|
|
67
79
|
The `-a` flag is required after rebuilding the Rust static library because Go's build cache does not detect changes to libraries linked through cgo. `-count=1` also prevents reuse of a cached successful test result.
|
|
68
80
|
|
|
81
|
+
### Mutation testing
|
|
82
|
+
|
|
83
|
+
Install `cargo-mutants` 27.1.0 and run the complete workspace mutation suite:
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
cargo install --locked cargo-mutants@27.1.0
|
|
87
|
+
cargo mutants --workspace --jobs 8
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
The [configuration](.cargo/mutants.toml) exercises both crates through workspace tests and documents exclusions for 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
|
+
|
|
69
92
|
### Reproducing known-answer test vectors
|
|
70
93
|
|
|
71
94
|
The fixed cryptographic values used by the Rust known-answer tests can be
|
|
@@ -114,13 +137,15 @@ See [the Rooterberg test documentation](doc/rooterberg.md) for the coverage
|
|
|
114
137
|
matrix, upstream format caveats and update procedure.
|
|
115
138
|
|
|
116
139
|
## Usage
|
|
117
|
-
The reference implementation is a library that can currently be used either from rust, through C FFI, go and python bindings. The C interface is
|
|
140
|
+
The reference implementation is a library that can currently be used either from rust, through C FFI, go and python bindings. The C interface is tested directly and through the Go bindings. Note that 0-length messages are explicitly disallowed by the reference implementation, as my feeling is that such messages have no purpose except testing parser edge cases. The library also doesn't handle chnking of any kind and will try to process entire messages at once in memory. It is expected that the caller should handle chunking itself if that is required.
|
|
141
|
+
|
|
142
|
+
From Rust, usage is mostly just constructing role-specific `Server` and `Beacon` objects. See the [example](beaconcrypt/examples/rust/main.rs) for usage.
|
|
118
143
|
|
|
119
|
-
|
|
144
|
+
Existing Rust callers must replace `BeaconCryptPqxdh` with the appropriate `Server` or `Beacon` type. C callers must use the matching `beaconcrypt_server_free` or `beaconcrypt_beacon_free` and role-specific identity functions; `beaconcrypt_export_state` is now `beaconcrypt_server_export_state`. Server checkpoints are binary snapshots: Go's `NewServerFromState` accepts `[]byte`, and Python's state export and restoration use `bytes` instead of JSON strings. See the persistence documentation for format compatibility and storage requirements.
|
|
120
145
|
|
|
121
146
|
From python, you can just use the wheels published to pypi, see the [example](examples/python/main.py) for usage.
|
|
122
147
|
|
|
123
|
-
The [C interface](src/cbinds.rs)
|
|
148
|
+
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.
|
|
124
149
|
|
|
125
150
|
Go is unfortunately the worst off as the bindings use cgo and therefore building your binary requires being able to link to a version of the library built with the `gobinds` feature. See the [example](examples/go/main.go) for usage.
|
|
126
151
|
|
|
@@ -0,0 +1,435 @@
|
|
|
1
|
+
#ifndef _BEACON_CRYPT_H_
|
|
2
|
+
#define _BEACON_CRYPT_H_
|
|
3
|
+
|
|
4
|
+
/* Generated with cbindgen:0.29.4 */
|
|
5
|
+
|
|
6
|
+
// Do not modify manually.
|
|
7
|
+
|
|
8
|
+
#include <stdarg.h>
|
|
9
|
+
#include <stdbool.h>
|
|
10
|
+
#include <stdint.h>
|
|
11
|
+
#include <stdlib.h>
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
#define beaconcrypt_KDF_STATE_SIZE 32
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* crypto_aead::chacha20poly1305_ietf::KEYBYTES
|
|
19
|
+
*/
|
|
20
|
+
#define beaconcrypt_AEAD_KEY_LEN 32
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* crypto_aead::chacha20poly1305_ietf::NPUBBYTES
|
|
24
|
+
*/
|
|
25
|
+
#define beaconcrypt_AEAD_NONCE_LEN 12
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* crypto_aead::chacha20poly1305_ietf::ABYTES
|
|
29
|
+
*/
|
|
30
|
+
#define beaconcrypt_AEAD_TAG_LEN 16
|
|
31
|
+
|
|
32
|
+
#define beaconcrypt_KDF_RATCHET_OUTPUT_LEN ((beaconcrypt_AEAD_KEY_LEN + beaconcrypt_KDF_STATE_SIZE) + beaconcrypt_AEAD_NONCE_LEN)
|
|
33
|
+
|
|
34
|
+
#define beaconcrypt_RATCHET_MAX_GAP 50
|
|
35
|
+
|
|
36
|
+
#define beaconcrypt_COMMITMENT_SIZE 64
|
|
37
|
+
|
|
38
|
+
#define beaconcrypt_MESSAGE_OVERHEAD (beaconcrypt_COMMITMENT_SIZE + beaconcrypt_AEAD_TAG_LEN)
|
|
39
|
+
|
|
40
|
+
#define beaconcrypt_KEX_KDF_OUT_LEN 32
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* crypto_scalarmult::BYTES
|
|
44
|
+
*/
|
|
45
|
+
#define beaconcrypt_DH_OUT_LEN 32
|
|
46
|
+
|
|
47
|
+
#define beaconcrypt_ED25519_SEED_SIZE 32
|
|
48
|
+
|
|
49
|
+
#define beaconcrypt_STATUS_OK 0
|
|
50
|
+
|
|
51
|
+
#define beaconcrypt_STATUS_REJECTED 1
|
|
52
|
+
|
|
53
|
+
#define beaconcrypt_STATUS_INVALID_ARGUMENT 2
|
|
54
|
+
|
|
55
|
+
#define beaconcrypt_STATUS_MISSING_SNAPSHOT 3
|
|
56
|
+
|
|
57
|
+
#define beaconcrypt_STATUS_INVALID_SNAPSHOT 4
|
|
58
|
+
|
|
59
|
+
#define beaconcrypt_STATUS_NON_CANONICAL_SNAPSHOT 5
|
|
60
|
+
|
|
61
|
+
#define beaconcrypt_STATUS_STALE_GENERATION 6
|
|
62
|
+
|
|
63
|
+
#define beaconcrypt_STATUS_GENERATION_EXHAUSTED 7
|
|
64
|
+
|
|
65
|
+
#define beaconcrypt_STATUS_ENCODING 8
|
|
66
|
+
|
|
67
|
+
#define beaconcrypt_STATUS_OUTPUT_ENCODING 9
|
|
68
|
+
|
|
69
|
+
#define beaconcrypt_STATUS_INITIALIZATION 10
|
|
70
|
+
|
|
71
|
+
#define beaconcrypt_STATUS_DIGEST 11
|
|
72
|
+
|
|
73
|
+
#define beaconcrypt_STATUS_POISONED 12
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Opaque beacon handle exposed by the C API and owned by its caller.
|
|
77
|
+
*/
|
|
78
|
+
typedef struct beaconcrypt_Beacon beaconcrypt_Beacon;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Opaque server handle owned by the C caller.
|
|
82
|
+
*
|
|
83
|
+
* Callers must serialize all access to one handle, including queries and destruction. Store callbacks must not reenter their owning handle.
|
|
84
|
+
*/
|
|
85
|
+
/**
|
|
86
|
+
* Server backed by trusted snapshot storage. Store callbacks must not reenter this server.
|
|
87
|
+
*/
|
|
88
|
+
typedef struct beaconcrypt_Server beaconcrypt_Server;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Heap-allocated byte buffer returned by the C API.
|
|
92
|
+
*
|
|
93
|
+
* A non-empty buffer must be released exactly once with `beaconcrypt_free_buffer`. An empty buffer has a null `ptr` and indicates either empty output or failure, depending on the called function.
|
|
94
|
+
*/
|
|
95
|
+
typedef struct beaconcrypt_Buffer {
|
|
96
|
+
/**
|
|
97
|
+
* Pointer to the first byte, or null when the buffer is empty.
|
|
98
|
+
*/
|
|
99
|
+
uint8_t *ptr;
|
|
100
|
+
/**
|
|
101
|
+
* Number of initialized bytes available through `ptr`.
|
|
102
|
+
*/
|
|
103
|
+
uintptr_t len;
|
|
104
|
+
/**
|
|
105
|
+
* Allocation capacity reserved for `beaconcrypt_free_buffer`; callers must not modify it.
|
|
106
|
+
*/
|
|
107
|
+
uintptr_t cap;
|
|
108
|
+
} beaconcrypt_Buffer;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Non-secret identity of one complete server snapshot. Its digest is not an authenticator.
|
|
112
|
+
*/
|
|
113
|
+
typedef struct beaconcrypt_SnapshotHeadInfo {
|
|
114
|
+
uint8_t lineage[32];
|
|
115
|
+
uint64_t generation;
|
|
116
|
+
uint8_t digest[32];
|
|
117
|
+
} beaconcrypt_SnapshotHeadInfo;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Trusted, rollback-resistant, linearizable durable storage for one server lineage.
|
|
121
|
+
*
|
|
122
|
+
* `load` returns false without calling `sink` for an empty store. Otherwise it calls `sink` synchronously exactly once with nonempty borrowed snapshot bytes and returns true; Rust copies the bytes before `sink` returns. `compare_and_swap` compares the complete current head against `expected` (null means an empty store), validates the successor, and durably stores the exact replacement bytes and head before returning true. The store must protect integrity, provenance and freshness; snapshot bytes and digests do not authenticate themselves.
|
|
123
|
+
*
|
|
124
|
+
* Constructors take ownership of `context` immediately, including on failure. `destroy`, when supplied, runs exactly once after the final callback; otherwise the caller manages the context lifetime. All callbacks and borrowed arguments remain valid until they return, must not unwind, retain borrowed pointers, call the sink after `load` returns, or reenter the owning handle. The caller serializes access to the handle and store.
|
|
125
|
+
*/
|
|
126
|
+
typedef struct beaconcrypt_SnapshotStoreCallbacks {
|
|
127
|
+
void *context;
|
|
128
|
+
bool (*load)(void *context, void *sink_context, void (*sink)(void*, const uint8_t*, uintptr_t));
|
|
129
|
+
bool (*compare_and_swap)(void *context,
|
|
130
|
+
const struct beaconcrypt_SnapshotHeadInfo *expected,
|
|
131
|
+
const uint8_t *replacement,
|
|
132
|
+
uintptr_t replacement_len);
|
|
133
|
+
void (*destroy)(void *context);
|
|
134
|
+
} beaconcrypt_SnapshotStoreCallbacks;
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Result returned after a successful server-side beacon registration.
|
|
138
|
+
*/
|
|
139
|
+
typedef struct beaconcrypt_RegistrationResponse {
|
|
140
|
+
/**
|
|
141
|
+
* Serialized registration response for the beacon.
|
|
142
|
+
*/
|
|
143
|
+
struct beaconcrypt_Buffer response;
|
|
144
|
+
/**
|
|
145
|
+
* Key identifier assigned to the registered beacon.
|
|
146
|
+
*/
|
|
147
|
+
uint64_t key_id;
|
|
148
|
+
} beaconcrypt_RegistrationResponse;
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Message output accompanied by observational ratchet metadata.
|
|
152
|
+
*/
|
|
153
|
+
typedef struct beaconcrypt_EncryptState {
|
|
154
|
+
/**
|
|
155
|
+
* Ciphertext for encryption calls or plaintext for decryption calls.
|
|
156
|
+
*/
|
|
157
|
+
struct beaconcrypt_Buffer data;
|
|
158
|
+
/**
|
|
159
|
+
* Inert plaintext ratchet JSON for observation only.
|
|
160
|
+
* It is secret-bearing, unauthenticated, and not restorable.
|
|
161
|
+
*/
|
|
162
|
+
struct beaconcrypt_Buffer state;
|
|
163
|
+
/**
|
|
164
|
+
* Key identifier used by the ratchet operation.
|
|
165
|
+
*/
|
|
166
|
+
uint64_t key_id;
|
|
167
|
+
/**
|
|
168
|
+
* Ratchet sequence number used by the operation.
|
|
169
|
+
*/
|
|
170
|
+
uint64_t seq;
|
|
171
|
+
} beaconcrypt_EncryptState;
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
#ifdef __cplusplus
|
|
176
|
+
extern "C" {
|
|
177
|
+
#endif // __cplusplus
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Release a byte buffer returned by this API.
|
|
181
|
+
*
|
|
182
|
+
* Passing an empty buffer is allowed. The buffer and its pointer must not be used after this call.
|
|
183
|
+
* The complete allocation is wiped before release. Copies retained by the caller are not erased.
|
|
184
|
+
*/
|
|
185
|
+
void beaconcrypt_free_buffer(struct beaconcrypt_Buffer buffer);
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Create a server with a randomly generated identity key.
|
|
189
|
+
*
|
|
190
|
+
* Returns an owned handle, or null on failure. Release a non-null handle with `beaconcrypt_server_free`.
|
|
191
|
+
*/
|
|
192
|
+
struct beaconcrypt_Server *beaconcrypt_server_new(uint64_t server_kid);
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Create a server with an optional deterministic identity seed.
|
|
196
|
+
*
|
|
197
|
+
* A null pointer or zero length selects a random identity key. A non-empty seed must contain exactly `beaconcrypt_ED25519_SEED_SIZE` readable bytes.
|
|
198
|
+
*
|
|
199
|
+
* Returns an owned handle, or null when creation fails. Release a non-null handle with `beaconcrypt_server_free`.
|
|
200
|
+
*/
|
|
201
|
+
struct beaconcrypt_Server *beaconcrypt_server_new_from_seed(uint64_t server_kid,
|
|
202
|
+
const uint8_t *seed_ptr,
|
|
203
|
+
uintptr_t seed_len);
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Create a server whose results are released only after the store's durable compare-and-swap succeeds.
|
|
207
|
+
*
|
|
208
|
+
* The callbacks take ownership of their context even when construction fails. A null seed or zero seed length selects a random identity. `status_out` may be null; otherwise it receives a `beaconcrypt_STATUS_*` code. Returns null on failure.
|
|
209
|
+
*/
|
|
210
|
+
struct beaconcrypt_Server *beaconcrypt_server_create_with_store(uint64_t server_kid,
|
|
211
|
+
const uint8_t *seed_ptr,
|
|
212
|
+
uintptr_t seed_len,
|
|
213
|
+
struct beaconcrypt_SnapshotStoreCallbacks callbacks,
|
|
214
|
+
uint32_t *status_out);
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Create a durable server under a caller-provisioned 32-byte lineage.
|
|
218
|
+
*
|
|
219
|
+
* Allocate each lineage to exactly one rollback-resistant authoritative store head. Callback context ownership and `status_out` follow `beaconcrypt_server_create_with_store`.
|
|
220
|
+
*/
|
|
221
|
+
struct beaconcrypt_Server *beaconcrypt_server_create_with_store_and_lineage(uint64_t server_kid,
|
|
222
|
+
const uint8_t *seed_ptr,
|
|
223
|
+
uintptr_t seed_len,
|
|
224
|
+
struct beaconcrypt_SnapshotStoreCallbacks callbacks,
|
|
225
|
+
const uint8_t *lineage_ptr,
|
|
226
|
+
uintptr_t lineage_len,
|
|
227
|
+
uint32_t *status_out);
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Restore the trusted current snapshot and durably claim its next generation before returning a live owner.
|
|
231
|
+
*
|
|
232
|
+
* Callback context ownership and `status_out` follow `beaconcrypt_server_create_with_store`. The store must protect snapshot integrity, provenance and freshness and coordinate concurrent owners.
|
|
233
|
+
*/
|
|
234
|
+
struct beaconcrypt_Server *beaconcrypt_server_restore_with_store(struct beaconcrypt_SnapshotStoreCallbacks callbacks,
|
|
235
|
+
uint32_t *status_out);
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Read the owner's current non-secret snapshot head. Returns a status code without changing the last operation's status.
|
|
239
|
+
*/
|
|
240
|
+
uint32_t beaconcrypt_server_head(const struct beaconcrypt_Server *handle,
|
|
241
|
+
struct beaconcrypt_SnapshotHeadInfo *out);
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Query whether a failed commit has fenced this owner. Returns false for null and preserves the last operation's status.
|
|
245
|
+
*/
|
|
246
|
+
bool beaconcrypt_server_is_poisoned(const struct beaconcrypt_Server *handle);
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Return the last server operation's status, or `beaconcrypt_STATUS_INVALID_ARGUMENT` for null.
|
|
250
|
+
* Head, identity and poison-state queries preserve this value; checkpoint export records its own status.
|
|
251
|
+
*/
|
|
252
|
+
uint32_t beaconcrypt_server_last_status(const struct beaconcrypt_Server *handle);
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Parse a snapshot envelope and compute its exact-byte head. This does not authenticate bytes or establish freshness.
|
|
256
|
+
*/
|
|
257
|
+
uint32_t beaconcrypt_snapshot_head(const uint8_t *bytes,
|
|
258
|
+
uintptr_t len,
|
|
259
|
+
struct beaconcrypt_SnapshotHeadInfo *out);
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Check a snapshot's lineage, next generation and exact parent digest against `expected` (null for an empty store).
|
|
263
|
+
*
|
|
264
|
+
* This does not authenticate bytes or make the store atomic. A store must perform this check together with comparison against its trusted current head inside its durable compare-and-swap transaction.
|
|
265
|
+
*/
|
|
266
|
+
uint32_t beaconcrypt_snapshot_validate_successor(const uint8_t *bytes,
|
|
267
|
+
uintptr_t len,
|
|
268
|
+
const struct beaconcrypt_SnapshotHeadInfo *expected,
|
|
269
|
+
struct beaconcrypt_SnapshotHeadInfo *out);
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Restore a server from trusted checkpoint bytes.
|
|
273
|
+
*
|
|
274
|
+
* The caller must reject stale or untrusted checkpoints. These bytes are plaintext and are not cryptographically authenticated.
|
|
275
|
+
*
|
|
276
|
+
* Restoration advances the generation, so export and save the returned handle immediately before using it. Returns an owned handle, or null for invalid state.
|
|
277
|
+
*/
|
|
278
|
+
struct beaconcrypt_Server *beaconcrypt_server_new_from_state(const uint8_t *state_ptr,
|
|
279
|
+
uintptr_t state_len);
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Export the current plaintext checkpoint.
|
|
283
|
+
*
|
|
284
|
+
* Save it immediately after every accepted receive or other state-changing call and before using that call's output.
|
|
285
|
+
* A normal rejected receive leaves the checkpoint unchanged.
|
|
286
|
+
* Returns an empty buffer on failure.
|
|
287
|
+
*/
|
|
288
|
+
struct beaconcrypt_Buffer beaconcrypt_server_export_state(const struct beaconcrypt_Server *handle);
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Create a beacon bound to a server identity public key.
|
|
292
|
+
*
|
|
293
|
+
* `server_pk_ptr` must point to an Ed25519 public key of the length implied by the API constants.
|
|
294
|
+
*
|
|
295
|
+
* Returns an owned handle, or null for absent or incorrectly sized input or a reported initialization/key-generation failure. Release a non-null handle with `beaconcrypt_beacon_free`.
|
|
296
|
+
*/
|
|
297
|
+
struct beaconcrypt_Beacon *beaconcrypt_beacon_new(uint64_t server_kid,
|
|
298
|
+
const uint8_t *server_pk_ptr,
|
|
299
|
+
uintptr_t server_pk_len);
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Release a server handle created by this API.
|
|
303
|
+
*
|
|
304
|
+
* Passing null is allowed. The handle must not be used after this call.
|
|
305
|
+
*/
|
|
306
|
+
void beaconcrypt_server_free(struct beaconcrypt_Server *handle);
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Release a beacon handle created by this API.
|
|
310
|
+
*
|
|
311
|
+
* Passing null is allowed. The handle must not be used after this call.
|
|
312
|
+
*/
|
|
313
|
+
void beaconcrypt_beacon_free(struct beaconcrypt_Beacon *handle);
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Copy the server identity public key into a caller-owned buffer.
|
|
317
|
+
*
|
|
318
|
+
* Returns an empty buffer when `handle` is null.
|
|
319
|
+
*/
|
|
320
|
+
struct beaconcrypt_Buffer beaconcrypt_server_identity_pk(const struct beaconcrypt_Server *handle);
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Copy the beacon identity public key into a caller-owned buffer.
|
|
324
|
+
*
|
|
325
|
+
* Returns an empty buffer when `handle` is null.
|
|
326
|
+
*/
|
|
327
|
+
struct beaconcrypt_Buffer beaconcrypt_beacon_identity_pk(const struct beaconcrypt_Beacon *handle);
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Generate the beacon's serialized registration bundle.
|
|
331
|
+
*
|
|
332
|
+
* Returns an empty buffer when the handle is invalid or the beacon cannot generate a bundle in its current state.
|
|
333
|
+
*/
|
|
334
|
+
struct beaconcrypt_Buffer beaconcrypt_generate_registration(struct beaconcrypt_Beacon *handle);
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Register a beacon and build its initial server response.
|
|
338
|
+
*
|
|
339
|
+
* `msg_ptr` may be null when `msg_len` is zero to omit the initial message. On failure, returns an empty response with key identifier zero.
|
|
340
|
+
*/
|
|
341
|
+
struct beaconcrypt_RegistrationResponse beaconcrypt_register_beacon(struct beaconcrypt_Server *handle,
|
|
342
|
+
const uint8_t *reg_ptr,
|
|
343
|
+
uintptr_t reg_len,
|
|
344
|
+
const uint8_t *msg_ptr,
|
|
345
|
+
uintptr_t msg_len);
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* Finish beacon registration and return the optional initial plaintext message.
|
|
349
|
+
*
|
|
350
|
+
* Returns an empty buffer when the input is invalid, registration fails, or no initial message was supplied.
|
|
351
|
+
*/
|
|
352
|
+
struct beaconcrypt_Buffer beaconcrypt_process_initial_message(struct beaconcrypt_Beacon *handle,
|
|
353
|
+
const uint8_t *ptr,
|
|
354
|
+
uintptr_t len);
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Encrypt a message from the server to the beacon identified by `key_id`.
|
|
358
|
+
*
|
|
359
|
+
* Returns an empty buffer when the handle or input is invalid, the key is unknown, or encryption fails.
|
|
360
|
+
*/
|
|
361
|
+
struct beaconcrypt_Buffer beaconcrypt_encrypt_to_beacon(struct beaconcrypt_Server *handle,
|
|
362
|
+
uint64_t key_id,
|
|
363
|
+
const uint8_t *ptr,
|
|
364
|
+
uintptr_t len);
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Decrypt a beacon-to-server message.
|
|
368
|
+
*
|
|
369
|
+
* Returns an empty buffer when the handle or input is invalid, authentication fails, or the ratchet rejects the message.
|
|
370
|
+
*/
|
|
371
|
+
struct beaconcrypt_Buffer beaconcrypt_decrypt_beacon_message(struct beaconcrypt_Server *handle,
|
|
372
|
+
const uint8_t *ptr,
|
|
373
|
+
uintptr_t len);
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* Encrypt a server-to-beacon message and return observational ratchet metadata.
|
|
377
|
+
*
|
|
378
|
+
* Returns an empty `beaconcrypt_EncryptState` when the operation fails. Persist the server checkpoint before using the returned output.
|
|
379
|
+
*/
|
|
380
|
+
struct beaconcrypt_EncryptState beaconcrypt_encrypt_and_update(struct beaconcrypt_Server *handle,
|
|
381
|
+
uint64_t key_id,
|
|
382
|
+
const uint8_t *ptr,
|
|
383
|
+
uintptr_t len);
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* Encrypt a server-to-beacon message and return the result and ratchet metadata as JSON.
|
|
387
|
+
*
|
|
388
|
+
* Returns an empty buffer when the operation fails. Persist the server checkpoint before using the returned output.
|
|
389
|
+
*/
|
|
390
|
+
struct beaconcrypt_Buffer beaconcrypt_encrypt_and_update_json(struct beaconcrypt_Server *handle,
|
|
391
|
+
uint64_t key_id,
|
|
392
|
+
const uint8_t *ptr,
|
|
393
|
+
uintptr_t len);
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* Decrypt a beacon-to-server message and return observational ratchet metadata.
|
|
397
|
+
*
|
|
398
|
+
* Returns an empty `beaconcrypt_EncryptState` when the operation fails. Persist the server checkpoint before using the returned output.
|
|
399
|
+
*/
|
|
400
|
+
struct beaconcrypt_EncryptState beaconcrypt_decrypt_and_update(struct beaconcrypt_Server *handle,
|
|
401
|
+
const uint8_t *ptr,
|
|
402
|
+
uintptr_t len);
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* Decrypt a beacon-to-server message and return the result and ratchet metadata as JSON.
|
|
406
|
+
*
|
|
407
|
+
* Returns an empty buffer when the operation fails. Persist the server checkpoint before using the returned output.
|
|
408
|
+
*/
|
|
409
|
+
struct beaconcrypt_Buffer beaconcrypt_decrypt_and_update_json(struct beaconcrypt_Server *handle,
|
|
410
|
+
const uint8_t *ptr,
|
|
411
|
+
uintptr_t len);
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* Encrypt a message from the beacon to its server.
|
|
415
|
+
*
|
|
416
|
+
* Returns an empty buffer when the handle or input is invalid or encryption fails.
|
|
417
|
+
*/
|
|
418
|
+
struct beaconcrypt_Buffer beaconcrypt_encrypt_to_server(struct beaconcrypt_Beacon *handle,
|
|
419
|
+
const uint8_t *ptr,
|
|
420
|
+
uintptr_t len);
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* Decrypt a server-to-beacon message.
|
|
424
|
+
*
|
|
425
|
+
* Returns an empty buffer when the handle or input is invalid, authentication fails, or the ratchet rejects the message.
|
|
426
|
+
*/
|
|
427
|
+
struct beaconcrypt_Buffer beaconcrypt_decrypt_server_message(struct beaconcrypt_Beacon *handle,
|
|
428
|
+
const uint8_t *ptr,
|
|
429
|
+
uintptr_t len);
|
|
430
|
+
|
|
431
|
+
#ifdef __cplusplus
|
|
432
|
+
} // extern "C"
|
|
433
|
+
#endif // __cplusplus
|
|
434
|
+
|
|
435
|
+
#endif /* _BEACON_CRYPT_H_ */
|