Skip to content

Commit 11a4764

Browse files
authored
kem v0.3.0-rc.3 (#2246)
1 parent b5cfb05 commit 11a4764

3 files changed

Lines changed: 8 additions & 66 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

kem/Cargo.toml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "kem"
3-
version = "0.3.0-rc.2"
3+
version = "0.3.0-rc.3"
44
authors = ["RustCrypto Developers"]
55
edition = "2024"
66
rust-version = "1.85"
@@ -25,7 +25,3 @@ getrandom = ["common/getrandom"]
2525

2626
[package.metadata.docs.rs]
2727
all-features = true
28-
29-
# TODO(tarcieri): make README.md an actually valid example
30-
[lib]
31-
doctest = false

kem/README.md

Lines changed: 6 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -7,68 +7,14 @@
77
![Rust Version][rustc-image]
88
[![Project Chat][chat-image]][chat-link]
99

10-
This crate provides a common set of traits for [key encapsulation mechanisms][1]—algorithms for non-interactively establishing secrets between peers. This is intended to be implemented by libraries which produce or contain implementations of key encapsulation mechanisms, and used by libraries which want to produce or consume encapsulated secrets while generically supporting any compatible backend.
10+
## About
1111

12-
The crate exposes two traits, `Encapsulate` and `Decapsulate`, which are both generic over the encapsulated key type and the shared secret type. They are also agnostic about the structure of `Self`. For example, a simple Saber implementation may just impl `Encapsulate` for a single public key:
13-
```rust
14-
// Must make a newtype to implement the trait
15-
struct MyPubkey(SaberPublicKey);
12+
This crate provides a common set of traits for [key encapsulation mechanisms][1]—algorithms for
13+
non-interactively establishing secrets between peers.
1614

17-
impl Encapsulate<SaberEncappedKey, SaberSharedSecret> for MyPubkey {
18-
// Encapsulation is infallible
19-
type Error = !;
20-
21-
fn encapsulate_with_rng<R: TryCryptoRng + ?Sized>(
22-
&self,
23-
csprng: &mut R,
24-
) -> Result<(SaberEncappedKey, SaberSharedSecret), !> {
25-
let (ss, ek) = saber_encapsulate(&csprng, &self.0);
26-
Ok((ek, ss))
27-
}
28-
}
29-
```
30-
And on the other end of complexity, an [X3DH](https://www.signal.org/docs/specifications/x3dh/) implementation might impl `Encapsulate` for a public key bundle plus a sender identity key:
31-
```rust
32-
struct PubkeyBundle {
33-
ik: IdentityPubkey,
34-
spk: SignedPrePubkey,
35-
sig: Signature,
36-
opk: OneTimePrePubkey,
37-
}
38-
39-
// Encap context is the recipient's pubkeys and the sender's identity key
40-
struct EncapContext(PubkeyBundle, IdentityPrivkey);
41-
42-
impl Encapsulate<EphemeralKey, SharedSecret> for EncapContext {
43-
// Encapsulation fails if signature verification fails
44-
type Error = SigError;
45-
46-
fn encapsulate_with_rng<R: TryCryptoRng + ?Sized>(
47-
&self,
48-
csprng: &mut R,
49-
) -> Result<(EphemeralKey, SharedSecret), Self::Error> {
50-
// Make a new ephemeral key. This will be the encapped key
51-
let ek = EphemeralKey::gen(&mut csprng);
52-
53-
// Deconstruct the recipient's pubkey bundle
54-
let PubkeyBundle {
55-
ref ik,
56-
ref spk,
57-
ref sig,
58-
ref opk,
59-
} = self.0;
60-
let my_ik = &self.1;
61-
62-
// Verify the signature
63-
self.0.verify(&sig, &some_sig_pubkey)?;
64-
65-
// Do the X3DH operation to get the shared secret
66-
let shared_secret = x3dh_a(sig, my_ik, spk, &ek, ik, opk)?;
67-
68-
Ok((ek, shared_secret))
69-
}
70-
}
71-
```
15+
This is intended to be implemented by libraries which produce or contain implementations of key
16+
encapsulation mechanisms, and used by libraries which want to produce or consume encapsulated
17+
secrets while generically supporting any compatible backend.
7218

7319
## License
7420

0 commit comments

Comments
 (0)