Improving cipher parallelism
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 20/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bastante claro
- Estado de actividad
- Estancado
- Stack tecnológico
- rust
- Área
- cryptography, performance
Línea de trabajo
Comienza con el PR 354 de traits enlazado y la abstracción BlockCipher::ParBlocks existente; después, inspecciona su uso en aes y en los backends SIMD enumerados en la issue. Compara el crate simd-buffers propuesto y los traits paralelos con los crates cipher, universal-hash y ctr. Se considerará terminado cuando exista un diseño acordado y cambios coordinados en las implementaciones de cipher, hash, AEAD y CTR afectadas.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Taking a step back from https://github.com/RustCrypto/traits/pull/354, I thought it'd be good to look how and where ILP and SIMD parallelism is currently used across the project as a whole, and how that could be improved.
The only place we presently have any sort of parallelism abstraction at the trait-level is BlockCipher::ParBlocks. Otherwise various crates leverage e.g. SIMD internally. Regarding BlockCipher::ParBlocks specifically, the only crate that leverages it is the aes crate.
The following crates have SIMD backends:
Ciphers
aeschacha20
UHFs/"MACs"
polyvalpoly1305
AEADs
In AEADs, we'd like to glue the above crates together in fairly fixed combinations in order to leverage ILP, passing SIMD buffers from ciphers to UHFs for authentication:
aes-gcm/aes-gcm-siv:aes+ghash/polyvalchacha20poly1305:chacha20+poly1305
(also aes-siv and pmac, but this is less of a priority)
In either of these cases there's a single specific buffer type I think it'd be nice for both the cipher implementation and UHF to support in common:
aes-gcm/aes-gcm-siv: "i128x8" i.e.[__m128i; 8]on x86/x86_64chacha20poly1305: "i256x4" i.e.[__m256i; 4]on x86/x86_64
Concrete proposal
My suggestion is to get rid of BlockCipher::ParBlocks and replace it with more general SIMD types and traits designed to work with them, namely:
- Add a new
utilscrate e.g.simd-bufferswhich provides "i128x8" and "i256x4" SIMD buffer types which are backed by__m128i/__m256ion x86/x86_64 and otherwise provide a portable implementation. These types don't need to implement any sort of arithmetic, just provide wrappers for passing data between SIMD implementations. - Add traits to
cipheranduniversal-hashwhich operate on SIMD buffers. - Use SIMD buffers types in the implementations of
aes-gcm,aes-gcm-siv, andchacha20poly1305
cipher API suggestion
I'd suggest adding traits to cipher which use the SIMD buffer types which are useful for both block ciphers and stream ciphers.
I also think it might make sense to use a generic parameter rather than an associated type to permit support for multiple buffer types (e.g. on newer CPUs, "i128x4" might be a better option for AES, but we can support both):
/// Note that for practical purposes, we only need to support block cipher encryption,
/// but there could also be a `BlockDecryptPar` for completeness/consistency.
pub trait BlockEncryptPar<B: SimdBuffer> {
fn encrypt_par(&self, buffer: &mut B);
}
pub trait StreamCipherPar<B: SimdBuffer> {
fn try_apply_keystream_par(&mut self, buffer: &mut B) -> Result<(), LoopError>;
}
universal-hash API suggestion
pub trait UniversalHashPar<B: SimdBuffer> {
fn update_par(&mut self, blocks: &B);
}
SIMD ctr support
Trying to move the end-user facing aes-ctr types into aes has created a very annoying circular dependency between the block-ciphers and stream-ciphers repo. Furthermore, ctr is quite a bit more general now than what the CTR types in the aes crate provide, and also aes doesn't actually provide the CTR "flavors" (Ctr32BE/Ctr32Le) needed by aes-gcm and aes-gcm-siv.
But really, it seems like the main benefit of the implementation in the aes crate is being able to use _mm_xor_si128 to XOR a "i128x8" type.
If we had BlockEncryptPar and StreamCipherPar traits, the ctr crate could glue the two together, accepting a SIMD buffer as input, computing the next buffer of keystream output, and XORing the latter into the former. This would allow ctr to be generally SIMD optimized, and also mean we only have one ctr implementation to worry about instead of a separate one in the AES crate.
- Lenguaje dominante
- Rust
- Estrellas
- 756
- Forks
- 256
- Merge medio
- 1 h 27 min
- PR fusionados (30 d)
- 2
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de RustCrypto/traits
-
try_sign_digest() is confusing. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 52/100
RustCrypto/traits#2487 · 2 comentarios ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 45/100
RustCrypto/traits#2482 · 5 comentarios ·
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 32/100
RustCrypto/traits#2478 · 5 comentarios ·
-
cipher: tracking issue for v0.6 Abiertocipher
Dificultad 4/5 3-5 días Aptitud para principiantes 38/100
RustCrypto/traits#2424 ·
-
`signature` v4 tracking issue Abierto
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
RustCrypto/traits#2401 ·
Todos los issues de RustCrypto/traits
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
TheLarkInn/aipm#2413 ·
-
documentation
Dificultad 1/5 Menos de una hora Aptitud para principiantes 90/100
alexgorbatchev/simple-ptt#15 ·
-
tooling
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
-
todo:ticket
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
taikoxyz/taiko-mono#22168 · 1 comentario ·