RustCrypto / RustCrypto/traits

kem: `from_seed` and `generate_keypair` use unnecessary memory

Open
#2,482 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
755
Forks
256
Avg merge
1h 27m
Merged PRs (30d)
2

Description

The methods from_seed and generate_keypair both return a Kem::DecapsulationKey and Kem::EncapsulationKey. However, DecapsulationKey already must impl Decapsulator, which returns a &Kem::EncapsulationKey. Meaning the decap key already owns a copy of the encapsulation key! In other words: the encapsulation key output of from_seed and generate_keypair is guaranteed to be redundant. Since this value is measured in the kilobytes, this is no small overhead.

Proposed fix: from_seed should just return a DecapsulationKey. And it's less clear what to do about generate_keypair. Maybe it gets deleted and replaced with generate_decapsulation_key? Seems invasive.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Locate the definitions of from_seed, generate_keypair, Kem::DecapsulationKey, and the Decapsulator trait. Trace callers and tests to determine how the API can stop returning a redundant EncapsulationKey, especially whether generate_keypair should be replaced. Done means the public API and its callers/tests no longer require the unnecessary key copy.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cryptography
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.