Commit 83d2ca7
committed
crypto(matryoshka): vendor chacha20 fork over ndarray::simd::U32x16, retire simd_crypto.rs
The AdaWorldAPI ChaCha20 "matryoshka": RustCrypto owns the cipher; ndarray owns
only the U32x16 ARX lane. The standalone from-scratch `src/simd_crypto.rs` (raw
_mm512_*/u32x4_* intrinsics) is RETIRED and superseded by a one-backend fork.
vendor/chacha20/ — fork of RustCrypto chacha20 0.9.1 (name/version kept for
[patch]; own [workspace] table, excluded from the parent workspace). Upstream
cipher verbatim (state schedule, counter, XChaCha, RNG, soft/sse2/avx2/neon).
The ONE delta:
src/backends/ndarray_simd.rs — the transpose block16 (16 blocks in parallel,
working vector w holds word w of every block across its 16 lanes, counter word
carries lane-index 0..=15) expressed over ndarray::simd::U32x16: every
quarter-round is a pure U32x16 + / ^ / rotate_left, NO cross-lane shuffle, NO
raw intrinsics, NO unsafe (all of that lives once inside ndarray::simd). Wrapped
in RustCrypto's StreamBackend (ParBlocksSize = U16), generic over R.
Selected at compile time under cfg(all(target_arch="x86_64", target_feature=
"avx512f")) via four cfg branches in backends.rs + lib.rs (Tokens / new / dispatch).
The ndarray dep is target.'cfg(target_arch="x86_64")' + default-features=false,
features=["std"] so wasm/aarch64 fork builds never pull ndarray.
[patch.crates-io] chacha20 = { path = "vendor/chacha20" } folds it transitively
under chacha20poly1305 -> encryption with zero change to the AEAD.
Parity — triple-gated, GREEN:
- the fork's own RustCrypto RFC 8439 vectors (chacha20/xchacha20 encryption +
keystream, core, seek) pass THROUGH ndarray_simd under -Ctarget-cpu=x86-64-v4;
- cargo test -p encryption (23 AEAD tests incl. XChaCha20-Poly1305 round-trip,
bit-flip-fails, wrong-key-fails) passes on the default v3 build (RustCrypto
avx2 fallback) and the avx512 build (ndarray_simd).
Retired: deleted src/simd_crypto.rs + tests/chacha20_rustcrypto_parity.rs + the
chacha20="0.9" dev-dep; removed the ndarray::simd::{chacha20_block,
chacha20_keystream, chacha20_state} surface (zero downstream consumers). aead.rs
doc rewritten to the transitive-acceleration framing.
Note: the workspace default is target-cpu=x86-64-v3 (avx2), so ndarray_simd
activates only on an avx512 build; the wasm-fork backend + cross-repo [patch]
propagation (MedCare-rs) are documented follow-ups in
.claude/CHACHA20_MATRYOSHKA_PLAN.md.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K6pT32kk6pnuAAqR3JiYqu1 parent a503291 commit 83d2ca7
26 files changed
Lines changed: 2561 additions & 658 deletions
File tree
- .claude
- crates/encryption/src
- src
- tests
- vendor/chacha20
- src
- backends
- tests
- data
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
39 | 83 | | |
40 | 84 | | |
41 | 85 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
217 | 217 | | |
218 | 218 | | |
219 | 219 | | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | 220 | | |
226 | 221 | | |
227 | 222 | | |
| |||
407 | 402 | | |
408 | 403 | | |
409 | 404 | | |
410 | | - | |
| 405 | + | |
411 | 406 | | |
412 | 407 | | |
413 | 408 | | |
| |||
449 | 444 | | |
450 | 445 | | |
451 | 446 | | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
246 | 246 | | |
247 | 247 | | |
248 | 248 | | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
255 | 253 | | |
256 | 254 | | |
257 | 255 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
682 | 682 | | |
683 | 683 | | |
684 | 684 | | |
685 | | - | |
686 | | - | |
687 | | - | |
688 | | - | |
689 | | - | |
690 | | - | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
691 | 689 | | |
692 | 690 | | |
693 | 691 | | |
| |||
0 commit comments