Proposal: a multi-buffer (multi-message) hashing trait for parallel independent digests
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 32/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Tranquilla
- Stack tecnologico
- rust
- Ambito
- cryptography
Direzione di ricerca
Inizia leggendo digest/src/block_api.rs e confrontando le convenzioni di crypto-common per ParBlocks con l’implementazione di cipher e il dispatch del backend sha2 a cui si fa riferimento nell’issue. Esamina le tre forme di API proposte e le questioni aperte prima di proporre una direzione. Il lavoro è concluso quando i maintainer concordano sul crate, sull’API, sulla rappresentazione delle lane e sull’ambito dell’MVP; non è ancora stato selezionato alcun design.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
The core primitive
We'd like to add a first-class abstraction for hashing N independent messages at once, so an implementation can place one message per SIMD lane and run the compression function across all lanes simultaneously:
Given N independent byte messages, produce their N digests in a single call.
This is the classic "multi-buffer" SHA construction (Gueron–Krasnov, Intel isa-l sha512_mb/sha256_mb). It exploits the fact that the round function has no cross-message dependency, even though it's fully serial within one message — so it's a different axis of parallelism from everything RustCrypto has today.
Why it's missing today (prior art)
As far as we can tell this capability doesn't exist anywhere in RustCrypto, and the existing parallelism is all a different axis:
ParBlocksSizeUser/ParBlocks(crypto-common, used bycipher) is the closest structural match — "process LANES units at once + scalar tail," viaencrypt_par_blocks/encrypt_tail_blocksoverinout::InOutBuf. But it means multiple blocks of one stream, not independent messages.- BLAKE2bp/sp, BLAKE3 tree mode, the sha2 AVX2 backend (#327) are all single-message internal SIMD.
- The hashing core API (
digest/src/block_api.rs) has no par-blocks concept;update_blocksis serial over one message.
So this would be a genuinely new capability on the hashing side, ideally borrowing the cipher-side conventions.
Motivating use case
Parallel Merkle-tree leaf hashing: the leaves are independent, equal-length messages — the ideal multi-buffer workload. (Our concrete driver is a parallel, order-independent launch-measurement for AMD SEV-SNP confidential VMs, but the primitive is general: tree/dedup/storage/packet hashing all want it.) On AMD in particular, SHA-384/512 has no hardware engine, so multi-buffer is the only way to use the SIMD datapath — and it's substantial on the Zen 5 / Turin native 512-bit path.
Design options
A — High-level one-shot trait on top of Digest, runtime dispatch internal (sha2-style):
pub trait MultiDigest: Digest {
fn digest_many(msgs: &[&[u8]], out: &mut [Output<Self>]); // impl detects avx2/avx512, chunks internally
}
B — Backend + driver split mirroring cipher's ParBlocks (compile-time width):
pub trait MultiDigestBackend: OutputSizeUser {
type Lanes: ArraySize; // typenum, like ParBlocksSize
fn digest_lanes(msgs: &Array<&[u8], Lanes>, out: &mut Array<Output<Self>, Lanes>);
fn digest_tail(..); // len < Lanes
}
// + a driver that splits into Lanes-chunks then a scalar tail
C — Streaming multi-lane context (isa-l manager-style): N independent incremental states with submit/flush, handling unequal-length messages that finish at different times. Most general, closest to isa-l, most complex.
| A: one-shot driver | B: backend + driver | C: streaming manager | |
|---|---|---|---|
| Width representation | internal (runtime) | type Lanes: ArraySize |
internal |
| ISA selection | runtime cpufeatures (like sha2) |
compile-time / backend types (like cipher) | runtime |
| Unequal lengths | precondition: equal (scalar tail) | equal per chunk | fully general |
| Streaming/incremental | no (one-shot) | no | yes |
| Complexity to land | low | medium | high |
| Fidelity to existing precedent | sha2 dispatch | cipher ParBlocks |
isa-l only |
Open questions for @tarcieri
- Does a multi-message hashing trait belong in
digest(orcrypto-common, or a new crate), or would you prefer inherent batch methods on individual hashes rather than a shared trait? - Width as a
typenumassociated type (type Lanes: ArraySize, matchingParBlocksSize) vs kept internal with runtimecpufeaturesdispatch (matching howsha2selects backends)? These two precedents point in different directions here. - Is a one-shot, equal-length primitive an acceptable MVP, or do you want the general (unequal-length / streaming) shape from the start?
- I/O convention: caller-provided output slice (à la
inout/InOutBuf), and should inputs reuseInOutBufor just&[&[u8]]? - Naming:
MultiDigest+Lanes(deliberately avoidingPar*, which already means intra-message)?
Happy to prototype whichever direction you prefer — we have a multi-buffer SHA-512/384 (AVX2 4-lane, AVX-512 8-lane) ready to shape to your guidance, with all SHA-2 variants to follow.
- Lingua principale
- Rust
- Stelle
- 756
- Fork
- 256
- Merge medio
- 1h 27m
- PR unite (30g)
- 2
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di RustCrypto/traits
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 52/100
RustCrypto/traits#2487 · 2 commenti ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
RustCrypto/traits#2482 · 5 commenti ·
-
cipher
Difficoltà 4/5 3-5 giorni Idoneità per principianti 38/100
RustCrypto/traits#2424 ·
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
RustCrypto/traits#2401 ·
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
RustCrypto/traits#2366 · 1 commento ·
Tutte le issue di RustCrypto/traits
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
-
bug core
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
-
JIT-compiled number -> Decimal conversion silently overflows instead of raising DECIMAL_OVERFLOW Apertafuzz
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
ClickHouse/ClickHouse#122114 ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 92/100
linebender/vello_svg#90 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100