Skip to content

Commit 9426e79

Browse files
committed
bug fixes
1 parent 319afa3 commit 9426e79

70 files changed

Lines changed: 7566 additions & 1030 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.cargo/config.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# TEMPORARY — remove on or after 2026-07-18.
2+
#
3+
# `bitcoinpqc` 0.4.0 (published 2026-07-08) may not be on mirrored registries yet.
4+
# This patch satisfies `version = "0.4"` until mirrors sync (target lift: 2026-07-18).
5+
#
6+
# Lift checklist (on or after 2026-07-18):
7+
# 1. Delete this file.
8+
# 2. `cargo update -p bitcoinpqc`
9+
# 3. `cargo build --features pqc` (should resolve from crates.io with no patch).
10+
#
11+
# Environments that already see `bitcoinpqc` 0.4 on the default index may delete early.
12+
13+
[patch.crates-io]
14+
bitcoinpqc = { git = "https://github.com/cryptoquick/libbitcoinpqc-bindings.git", rev = "7936b56" }
15+
# Monorepo local iteration (optional): `bitcoinpqc = { path = "../libbitcoinpqc-bindings" }`

.cargo/config.toml.example

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,23 @@
77
# cp .cargo/config.toml.example .cargo/config.toml
88

99
[patch."https://github.com/SurmountSystems/bao-tree.git"]
10-
bao-tree = { path = "../bao-tree" }
10+
bao-tree = { path = "../bao-tree" }
11+
12+
# `bitcoinpqc` 0.4 mirror lag: the repo ships `.cargo/config.toml` with a temporary
13+
# `[patch.crates-io]` until 2026-07-18. Delete that file once your index has 0.4.
14+
15+
# Optional: wasm32 tooling notes
16+
#
17+
# CI / `just lint-wasm`: `--no-default-features` (no pqc) — green without a C wasm toolchain.
18+
#
19+
# wasm32 + `pqc`: bitcoinpqc's clang shim lives at
20+
# `../libbitcoinpqc-bindings/wasm/clang-wasm32.sh`. Do **not** set global
21+
# `CC_wasm32-unknown-unknown` to that shim for a full Carbonado build: `zstd-sys`
22+
# then tries to assemble host amd64 `.S` files with the wasm clang and fails.
23+
# Isolate CC for bitcoinpqc only (or wait for dep/build fixes) before enabling
24+
# wasm+pqc in CI.
25+
#
26+
# [target.wasm32-unknown-unknown]
27+
# rustflags = [
28+
# "--cfg", "getrandom_backend=\"wasm_js\"",
29+
# ]

.github/workflows/rust.yaml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,18 @@ jobs:
7777

7878
- uses: Swatinem/rust-cache@v2
7979

80-
- name: Test (native)
81-
run: just test
80+
- name: Test (default features, includes parallel)
81+
run: cargo test
82+
env:
83+
RUST_BACKTRACE: 1
84+
85+
- name: Test (serial FEC path without parallel)
86+
run: cargo test --no-default-features --features "pqc,ots,cli" --test serial_fec_path
87+
env:
88+
RUST_BACKTRACE: 1
89+
90+
- name: Test (all features)
91+
run: cargo test --all-features
8292
env:
8393
RUST_BACKTRACE: 1
8494

AGENTS.md

Lines changed: 42 additions & 33 deletions
Large diffs are not rendered by default.

CHANGELOG.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,25 @@ All notable changes to the Carbonado crate and `carbonado` CLI are documented he
66

77
### Added
88

9+
- **`bitcoinpqc` 0.4:** migrate from crates.io `libbitcoinpqc` 0.1 to `bitcoinpqc` 0.4 (WASM-capable bindings). SLH-DSA parameter set is now **SHA2-128s** (`SLH_DSA_SHA2_128S`); SHAKE-128s sidecars from dev builds are incompatible — re-sign if needed. Temporary `.cargo/config.toml` `[patch.crates-io]` — delete on or after **2026-07-18** once registry mirrors sync.
10+
- **Phase 3 CPU parallelism (`parallel` feature, default on):** scoped fork-join RS parity generation in `FecInboardEncoder::take_stripe` (`src/stream/parallel.rs`); `ParallelConfig::max_threads` caps per-wave workers; output bit-identical to serial `rs.encode`. WASM compiles with `parallel` but stays serial at runtime. Disable with `--no-default-features` for serial-only builds. Tests: `tests/parallel_determinism.rs` (default), `tests/serial_fec_path.rs` (no-`parallel` CI gate); bench: `benches/parallel_bench.rs`. Documented in `doc/STREAMING_PARALLELISM.md` § Phase 3.
11+
- **Phase 2 async I/O adapter (optional `async` feature):** `stream_decode_async` (`AsyncRead``AsyncWrite` inboard decode), `stream::io` pipeline traits (`PipelineSource`/`PipelineSink`, `AsyncPipelineSource`/`AsyncPipelineSink`), `BoundedCopyTruncation` for sync-aligned truncation errors. Disk spool bridge preserves MAC-before-decrypt; `async-tokio` offloads sync pipeline via `spawn_blocking`. WASM returns `NotImplemented`. Tests: `tests/streaming_async.rs` (`cargo test --features async`).
912
- **Adamantine 1.0 directory envelope:** magic `ADAMANTINE10\n` (version in magic); 19-byte header with u8 flags (`REQUIRE_OTS` only). New module `adamantine_payload` (rkyv + centralized Bao bundle). Dev `ADAMANTINE2\n` rejected.
10-
- **Heterogeneous segment formats:** `directory/format_policy` with `infer` heuristic (compressible → c6/c7, incompressible → c4/c5); `SegmentFormatPolicy` Auto/Force*; `FilepackEntry.segment_format`; `SegmentRef.bao_outboard_offset/len`.
13+
- **Heterogeneous FEC segment formats:** `directory/format_policy` with `infer` heuristic (compressible → c14/c15, incompressible → c12/c13); `SegmentFormatPolicy` Auto/Force*; `FilepackEntry.segment_format`; `SegmentRef` verification + `fec_parity` bundle indices.
1114
- **Catalog OTS trailer:** optional `[COTS][u32 len][proof]` after inboard catalog bytes (stable Bao root).
1215
- **Filepack CBOR interop:** `FilepackManifest::from_filepack_cbor`, `from_packed`, `to_filepack_cbor`; `FilepackSegmentMap`; DoS limits on CBOR flatten. Error: `InvalidFilepackCbor`.
1316
- **New errors:** `InvalidAdamantineFlags`, `SegmentFormatMismatch`.
1417

1518
### Changed
1619

20+
- **M1 pipeline memory (hard break):** non-FEC verification decode (c6) uses `SeekWriteAt` over the post-preprocess spool (O(chunk) RAM; no full logical `Vec`). FEC verification uses `FecInboardWriteAt::finish_into` (stream logical bytes without a second full logical buffer; shard buffers remain O(FEC body) under segment-wide RS geometry). See `doc/STREAMING_PARALLELISM.md`.
21+
- **M2 outboard verify memory:** `stream_verification_outboard_verify` uses `PostOrderOutboard` + `ReadAt` (on-demand hash pairs) instead of copying the full sidecar into `PostOrderMemOutboard`. Streaming outboard decode keeps the sidecar on a disk spool.
22+
- **S5 scrub verify oracle:** `scrub` pre-check uses `verify_inboard_keyed` (`DiscardWriteAt` sink) instead of buffer `verification()` full-body staging; `scrub_outboard` pre-check uses `stream_verification_outboard_verify` with `io::sink()`. Memory tiers in `doc/STREAMING_PARALLELISM.md`.
23+
- **S4 streaming inboard decode:** `stream_decode` / `stream_decode_buffer` stream keyed Bao verify into `WriteAt` sinks without staging the encoded body; `decode_stream` and `file::decode` share the same Bao/FEC path. Memory tiers documented in `doc/STREAMING_PARALLELISM.md`.
1724
- **Directory archive layout (clean break):** inboard catalog c14/c15 only; bare segment mains; no directory `.out`/`.par`/`.ots` sidecars; Bao outboard centralized in Adam payload. Removed `DirectoryLayout`, homogeneous segment format, directory `--inboard`/`--outboard`/`--format` CLI flags.
1825
- **CLI directory output:** defaults to `{input}-archive/`; never `.`.
19-
- **Directory format generalization superseded:** catalog locked to c14/c15; segments heterogeneous c4–c7.
26+
- **Directory segment FEC (clean break):** catalog locked to c14/c15; segments heterogeneous c12–c15 (Verification+FEC); legacy c4–c7 rejected. Centralized bundle holds verification outboard + FEC parity per segment.
27+
- **Keyed verification KDF domain:** `blake3::derive_key("carbonado-v2/verification", &[format])` replaces `"carbonado-v2/bao"` (breaks keyed roots vs pre-2.1.0). Public API: `crypto::carbonado_verification_key`.
2028
- **Directory manifest API rename (Phase 1):** `PackIndex``FilepackManifest`, `PackEntry``FilepackEntry`, `PackSegmentRef``SegmentRef`, module `pack_index``filepack_manifest`. rkyv wire layout unchanged; on-disk archives remain compatible.
2129
- **Error variant rename (breaking):** `InvalidPackIndex``InvalidFilepackManifest`. No enum alias is provided.
2230
- **Narrowed error taxonomy:** OTS proof size failures → `InvalidOtsProof`; Adamantine oversized `payload_len``InvalidAdamantinePayloadTooLarge`; directory decode integrity failures → `SegmentMainLenMismatch`, `ContentBlake3Mismatch`, `OutputPathEscape`, `OtsFeatureRequired`, `OtsProofRequired`.

Cargo.toml

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "carbonado"
33
edition = "2021"
44
version = "2.0.0"
55
license = "MIT"
6-
description = "An apocalypse-resistant data storage format for the truly paranoid. Fully symmetric AES-256-CTR + HMAC-SHA512 (EtM) container. Callers supply high-entropy master keys; passphrase KDF (e.g. Argon2id) is caller responsibility. SLH-DSA signatures are provided only as sidecars (via libbitcoinpqc). Clean cryptographic break from ECIES — v1 encrypted archives require external migration."
6+
description = "An apocalypse-resistant data storage format for the truly paranoid. Fully symmetric AES-256-CTR + HMAC-SHA512 (EtM) container. Callers supply high-entropy master keys; passphrase KDF (e.g. Argon2id) is caller responsibility. SLH-DSA signatures are provided only as sidecars (via `bitcoinpqc`). Clean cryptographic break from ECIES — v1 encrypted archives require external migration."
77
documentation = "https://docs.rs/carbonado"
88
homepage = "https://github.com/bitmask-stack/carbonado"
99
repository = "https://github.com/bitmask-stack/carbonado.git"
@@ -32,6 +32,8 @@ bao = "0.13"
3232
# We set default-features = false because the fork's defaults pull in tokio/fs/etc
3333
# which are not needed (we only use sync keyed) and break some cross/wasm targets.
3434
bao_tree = { package = "bao-tree", git = "https://github.com/SurmountSystems/bao-tree.git", branch = "76-keyed-bao", default-features = false, features = ["validate"] }
35+
futures-lite = { version = "2", optional = true, default-features = false, features = ["std"] }
36+
tokio = { version = "1", features = ["rt"], optional = true }
3537
bitmask-enum = "2.1.0"
3638
log = "0.4.19"
3739
serde = { version = "1.0.164", features = ["derive"] }
@@ -74,34 +76,52 @@ ctr = "0.9"
7476
hmac = "0.12"
7577
sha2 = "0.10"
7678
getrandom = { version = "0.2", features = ["js"] }
77-
libbitcoinpqc = { version = "0.1", optional = true }
79+
# bitcoinpqc 0.4 (WASM-capable build.rs); SLH-DSA-SHA2-128s sidecars.
80+
# Local mirror lag: `.cargo/config.toml` patches 0.4 until 2026-07-18 (see lift checklist there).
81+
bitcoinpqc = { version = "0.4", optional = true }
7882

7983
# Note: ecies + libsecp256k1-core + nostr + secp256k1 removed (clean break from old ECIES design and Nostr bech32/npub helpers).
8084
# Future quantum-resistant key formats (qpub etc.) will be handled separately.
8185

8286
[features]
83-
default = ["pqc", "ots", "cli"]
84-
pqc = ["dep:libbitcoinpqc"]
87+
default = ["pqc", "ots", "cli", "parallel"]
88+
pqc = ["dep:bitcoinpqc"]
8589
# OpenTimestamps stub stamping (offline/testable; no network calendar in default build).
8690
ots = []
8791
# `carbonado` CLI binary (encode/decode/key). Disable for library-only dependency trees.
8892
cli = ["dep:clap", "dep:bip39", "dep:directories"]
8993
# `gen-carbonado-man` — regenerate roff pages under doc/man/ (`just gen-man`).
9094
man-gen = ["cli", "dep:clap_mangen"]
95+
# Async I/O adapter layer (Phase 2): `stream_decode_async` and pipeline I/O traits.
96+
# `bao_tree/tokio_fsm` is reserved for future async Bao FSM paths — no crate code references it yet.
97+
async = ["dep:futures-lite", "bao_tree/tokio_fsm"]
98+
# Optional Tokio: `stream_decode_async` offloads sync pipeline to `spawn_blocking` (not required for trait defs).
99+
async-tokio = ["async", "dep:tokio"]
100+
# CPU parallelism (Phase 3): fork-join RS parity encode via `std::thread::scope` (std only; on by default).
101+
# Disable with `--no-default-features` for library-only trees that want serial `rs.encode` only.
102+
parallel = []
91103

92104
[dev-dependencies]
93105
anyhow = "1.0.71"
106+
sha2 = "0.10"
107+
serde_json = "1"
94108
pretty_env_logger = "0.5.0"
95109
rand = "0.8.5"
96110
wasm-bindgen-test = "0.3.37"
97111
criterion = { version = "0.5", features = ["html_reports"] }
98112
proptest = "1"
99113
tiny_http = "0.12"
114+
tokio = { version = "1", features = ["rt", "macros"] }
100115

101116
[[bench]]
102117
name = "crypto_bench"
103118
harness = false
104119

120+
[[bench]]
121+
name = "parallel_bench"
122+
harness = false
123+
required-features = ["parallel"]
124+
105125
# Primary CLI: `cargo install carbonado` or `cargo install --path . --bin carbonado`
106126
[[bin]]
107127
name = "carbonado"

0 commit comments

Comments
 (0)