|
48 | 48 | # |
49 | 49 | # Read by curve25519-dalek's build.rs via CARGO_CFG_CURVE25519_DALEK_BACKEND. |
50 | 50 | # Verify: cargo build -p encryption -v 2>&1 | grep curve25519_dalek_backend |
| 51 | + |
| 52 | +# poly1305 backend: SOFT, deliberately. Same reasoning as dalek above, but |
| 53 | +# unlike dalek this surface was actually REACHING THE BINARY. |
| 54 | +# |
| 55 | +# `crates/encryption` -> `chacha20poly1305` -> `poly1305`, and poly1305 0.8 |
| 56 | +# auto-selects its AVX2 backend on any x86/x86_64 target unless told otherwise. |
| 57 | +# That backend is 424 `_mm*` intrinsic calls under 30 `unsafe` occurrences in a |
| 58 | +# single file (`src/backend/avx2/helpers.rs`) — over seven times dalek's 57, and |
| 59 | +# a second unaudited SIMD surface beside `ndarray::simd`, which is what the |
| 60 | +# matryoshka pattern exists to prevent. |
| 61 | +# |
| 62 | +# Reachability, not porting: the whole thing is gated behind one cfg — |
| 63 | +# `src/backend.rs`, `#[cfg(all(any(target_arch = "x86", target_arch = "x86_64"), |
| 64 | +# not(poly1305_force_soft)))] pub(crate) mod avx2;` — so the flag below compiles |
| 65 | +# it out without touching a line of crypto. |
| 66 | +# |
| 67 | +# What it costs: the soft backend (poly1305-donna, the same algorithm) instead |
| 68 | +# of the AVX2 one, on the AEAD's MAC. That is a real throughput cost on large |
| 69 | +# payloads and it has NOT been measured here. It is accepted because the |
| 70 | +# alternative is an unaudited intrinsic surface in the crypto path. |
| 71 | +# |
| 72 | +# What it does NOT mean: writing our own Poly1305. Per the operator-ratified |
| 73 | +# doctrine in `.claude/CHACHA20_MATRYOSHKA_PLAN.md` — "RustCrypto owns the |
| 74 | +# algorithm; ndarray owns the SIMD... Rolling your own AEAD (HChaCha20 + |
| 75 | +# Poly1305 + framing) is the footgun; it is forbidden." The sanctioned way to |
| 76 | +# accelerate this later is the chacha20 route: vendor the fork and give |
| 77 | +# RustCrypto's own backend an `ndarray::simd` lane, never a reimplementation. |
| 78 | +# |
| 79 | +# Read by poly1305's src/backend.rs as a plain cfg. |
| 80 | +# Verify: cargo build -p encryption -v 2>&1 | grep poly1305_force_soft |
51 | 81 | [target.'cfg(target_arch = "x86_64")'] |
52 | | -rustflags = ["-Ctarget-cpu=x86-64-v3", "--cfg", "curve25519_dalek_backend=\"serial\""] |
| 82 | +rustflags = [ |
| 83 | + "-Ctarget-cpu=x86-64-v3", |
| 84 | + "--cfg", |
| 85 | + "curve25519_dalek_backend=\"serial\"", |
| 86 | + "--cfg", |
| 87 | + "poly1305_force_soft", |
| 88 | +] |
0 commit comments