pub enum KeyAgreementAlgorithm {
EcdhP256,
}
Expand description
Key agreement algorithm enumeration.
密钥协商算法枚举。
§Algorithm Selection | 算法选择
Currently supports ECDH P-256, which provides:
- High performance on modern hardware
- Wide compatibility and standardization
- 128-bit security level
- Efficient implementation
目前支持 ECDH P-256,它提供:
- 在现代硬件上的高性能
- 广泛的兼容性和标准化
- 128 位安全级别
- 高效的实现
Variants§
EcdhP256
Elliptic Curve Diffie-Hellman over NIST P-256 curve.
基于 NIST P-256 曲线的椭圆曲线 Diffie-Hellman。
§Properties | 属性
- Curve: NIST P-256 (secp256r1)
- Field Size: 256 bits
- Security Level: 128-bit
- Key Size: 32 bytes
- Shared Secret Size: 32 bytes
§Use Cases | 使用场景
-
TLS/SSL key exchange
-
Secure messaging protocols
-
VPN key establishment
-
IoT device pairing
-
TLS/SSL 密钥交换
-
安全消息协议
-
VPN 密钥建立
-
IoT 设备配对
Implementations§
Source§impl KeyAgreementAlgorithm
impl KeyAgreementAlgorithm
Sourcepub fn build() -> KeyAgreementAlgorithmBuilder
pub fn build() -> KeyAgreementAlgorithmBuilder
Creates a new key agreement algorithm builder.
创建新的密钥协商算法构建器。
§Returns | 返回值
A builder that provides access to different key agreement algorithms. Use the builder methods to select the specific algorithm needed.
提供访问不同密钥协商算法的构建器。 使用构建器方法选择所需的特定算法。
§Examples | 示例
use seal_crypto_wrapper::algorithms::asymmetric::key_agreement::KeyAgreementAlgorithm;
let ecdh = KeyAgreementAlgorithm::build().ecdh_p256();
Source§impl KeyAgreementAlgorithm
impl KeyAgreementAlgorithm
Sourcepub fn into_wrapper(self) -> KeyAgreementAlgorithmWrapper
pub fn into_wrapper(self) -> KeyAgreementAlgorithmWrapper
Converts the algorithm enum into a concrete wrapper implementation.
将算法枚举转换为具体的包装器实现。
§Purpose | 目的
This method creates a wrapper that implements the key agreement algorithm trait, enabling actual cryptographic operations like key pair generation and shared secret derivation with type safety guarantees.
此方法创建一个实现密钥协商算法 trait 的包装器, 启用实际的密码操作,如密钥对生成和共享密钥派生,并提供类型安全保证。
§Returns | 返回值
A KeyAgreementAlgorithmWrapper
that can perform:
- Key pair generation
- Shared secret derivation (key agreement)
- Public key validation
- Algorithm introspection
可以执行以下操作的 KeyAgreementAlgorithmWrapper
:
- 密钥对生成
- 共享密钥派生(密钥协商)
- 公钥验证
- 算法内省
§Examples | 示例
use seal_crypto_wrapper::algorithms::asymmetric::key_agreement::KeyAgreementAlgorithm;
let algorithm = KeyAgreementAlgorithm::build().ecdh_p256();
let ka = algorithm.into_wrapper();
// Generate key pairs for two parties
let alice_keypair = ka.generate_keypair()?;
let bob_keypair = ka.generate_keypair()?;
// Extract keys
let (alice_public, alice_private) = alice_keypair.into_keypair();
let (bob_public, bob_private) = bob_keypair.into_keypair();
// Both parties derive the same shared secret
let alice_shared = ka.agree(&alice_private, &bob_public)?;
let bob_shared = ka.agree(&bob_private, &alice_public)?;
// Verify they match
assert_eq!(alice_shared, bob_shared);
// Use shared secret for key derivation
// (In practice, use a proper KDF like HKDF)
let encryption_key = &alice_shared[..32]; // First 32 bytes
§Security Best Practices | 安全最佳实践
When using the wrapper:
- Validate Public Keys: Always validate received public keys
- Use Ephemeral Keys: Generate new keys for each session
- Proper Key Derivation: Use HKDF or similar to derive actual keys
- Authentication: Combine with signatures for authenticated key exchange
使用包装器时:
- 验证公钥: 始终验证接收到的公钥
- 使用临时密钥: 为每个会话生成新密钥
- 适当的密钥派生: 使用 HKDF 或类似方法派生实际密钥
- 认证: 结合签名进行认证密钥交换
Trait Implementations§
Source§impl<'__de, __Context> BorrowDecode<'__de, __Context> for KeyAgreementAlgorithm
impl<'__de, __Context> BorrowDecode<'__de, __Context> for KeyAgreementAlgorithm
Source§fn borrow_decode<__D: BorrowDecoder<'__de, Context = __Context>>(
decoder: &mut __D,
) -> Result<Self, DecodeError>
fn borrow_decode<__D: BorrowDecoder<'__de, Context = __Context>>( decoder: &mut __D, ) -> Result<Self, DecodeError>
Source§impl Clone for KeyAgreementAlgorithm
impl Clone for KeyAgreementAlgorithm
Source§fn clone(&self) -> KeyAgreementAlgorithm
fn clone(&self) -> KeyAgreementAlgorithm
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more