FIPS 203(初始公开草案)基于模块格的密钥封装机制标准,使用纯 Rust 编写,适用于服务器、桌面、浏览器和嵌入式应用。源仓库包含演示基准测试、嵌入式目标、恒定时间统计测量、模糊测试、WASM 执行、C FFI 和 Python 绑定的示例。
这个 crate 以纯 Rust 实现了 FIPS 203 草案标准,依赖项最少且为主流,并且不包含任何 unsafe 代码。所有三组安全参数集均得到完整支持并经过测试。该实现以恒定时间运行(rho 除外,rho 是封装密钥的一部分,以明文形式跨信任边界发送),不要求标准库(例如 #[no_std]),无堆分配(例如不需要 alloc),并且可选地暴露 RNG,因此适用于从裸机到各类应用的全部场景。API 已稳定,代码极其注重安全性和正确性;随着标准日益成熟,将进一步实现性能优化。一旦 FIPS 203 出现任何变更,此 crate 将迅速跟进。
有关目标功能的完整描述,请参阅 https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.203.ipd.pdf。
该功能使用起来极其简单,如下例所示。
// Use the desired target parameter set.
use fips203::ml_kem_512; // Could also be ml_kem_768 or ml_kem_1024.
use fips203::traits::{Decaps, Encaps, KeyGen, SerDes};
// Alice runs `try_keygen()` and then serializes the encaps key `ek` for Bob (to bytes).
let (alice_ek, alice_dk) = ml_kem_512::KG::try_keygen().unwrap();
let alice_ek_bytes = alice_ek.into_bytes();
// Alice sends the encaps key `ek_bytes` to Bob.
let bob_ek_bytes = alice_ek_bytes;
// Bob deserializes the encaps `ek_bytes` and then runs `encaps() to get the shared
// secret `ssk` and ciphertext `ct`. He serializes the ciphertext `ct` for Alice (to bytes).
let bob_ek = ml_kem_512::EncapsKey::try_from_bytes(bob_ek_bytes).unwrap();
let (bob_ssk_bytes, bob_ct) = bob_ek.try_encaps().unwrap();
let bob_ct_bytes = bob_ct.into_bytes();
// Bob sends the ciphertext `ct_bytes` to Alice
let alice_ct_bytes = bob_ct_bytes;
// Alice deserializes the ciphertext `ct` and runs `decaps()` with her decaps key
let alice_ct = ml_kem_512::CipherText::try_from_bytes(alice_ct_bytes).unwrap();
let alice_ssk_bytes = alice_dk.try_decaps(&alice_ct).unwrap();
// Alice and Bob will now have the same secret key
assert_eq!(bob_ssk_bytes, alice_ssk_bytes);
Rust 文档 位于下方每个与所需安全参数相对应的 Module 下。
dudect 动态测试进行确认。RNG。内容根据 Apache License Version 2.0 或 MIT license 许可,由您选择。
除非您另有明确说明,否则根据 Apache-2.0 许可证的定义,您有意提交以包含在本作品中的任何贡献,均应按上述双重许可进行,不附加任何额外条款或条件。