Improving cipher parallelism
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 20/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- rust
调研方向
从链接的 traits PR 354 和现有的 BlockCipher::ParBlocks 抽象开始,然后检查它在 aes 以及 issue 中列出的 SIMD 后端中的使用情况。将提议的 simd-buffers crate 和并行 traits 与 cipher、universal-hash 和 ctr crates 进行比较。完成这项工作需要就设计达成一致,并协调修改受影响的 cipher、hash、AEAD 和 CTR 实现。
由索引模型根据 Issue 内容生成。
描述
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.
- 主要语言
- Rust
- 星标
- 760
- 派生
- 258
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
RustCrypto/traits 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 52/100
RustCrypto/traits#2487 · 2 条评论 ·
-
难度 4/5 3-5 天 新手友好度 45/100
RustCrypto/traits#2482 · 5 条评论 ·
-
难度 5/5 一周以上 新手友好度 32/100
RustCrypto/traits#2478 · 5 条评论 ·
-
cipher
难度 4/5 3-5 天 新手友好度 38/100
RustCrypto/traits#2424 ·
-
难度 5/5 一周以上 新手友好度 25/100
RustCrypto/traits#2401 ·
查看 RustCrypto/traits 的全部 Issue
相似的 Issue
-
documentation
难度 2/5 1-3 小时 新手友好度 78/100
charles-hood/DiagramCraft#73 ·
-
难度 1/5 1-3 小时 新手友好度 78/100
ontologyportal/sigma-rs#200 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
chipsalliance/caliptra-sw#4311 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
`image_generation`: `max_retries` is ignored for OpenAI-compatible providers (always 2 retries)可能已有人在做 @ericz7900 今天认领。 未关闭llm translation
难度 2/5 1-3 小时 新手友好度 77/100
维护者通常 1 天内回复