Skip to content

New mlkem lib #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 9, 2025
Merged

New mlkem lib #56

merged 3 commits into from
May 9, 2025

Conversation

Nichokas
Copy link
Owner

@Nichokas Nichokas commented May 9, 2025

This pull request introduces significant updates to the cryptographic implementation, replacing the Kyber library with libcrux_ml_kem and updating the random number generation approach to use rand_chacha, safer than using rand::threaded_rng. It also includes various refactors, test updates, and a new script for generating test vectors.

@Nichokas Nichokas self-assigned this May 9, 2025
@Copilot Copilot AI review requested due to automatic review settings May 9, 2025 17:45
@Nichokas Nichokas linked an issue May 9, 2025 that may be closed by this pull request
@Nichokas Nichokas enabled auto-merge May 9, 2025 17:46
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR migrates the cryptographic implementation from kyberlib to libcrux_ml_kem, updates the random number generation to use rand_chacha, and refactors various areas including tests, benchmarks, and documentation to reflect the new APIs.

  • Migration to libcrux_ml_kem with updated keypair, encapsulation, and decapsulation functions
  • Update of randomness generation using ChaCha20Rng from OS sources for reproducibility
  • Refactoring of API interfaces, test vector generation, and documentation improvements

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/tests.rs Updated tests to use new public key getters and revised keypair construction
src/main.rs Added a new test vector generation script
src/lib.rs Refactored encryption/decryption functions to use fixed-size arrays and new ML-KEM API
src/key_exchange.rs Revised key exchange to adopt libcrux_ml_kem and update key derivation logic
src/encryption.rs Minor documentation and example adjustments in encrypt/decrypt helper functions
benches/kyber_bench.rs Updated benchmarking tests to reflect use of the new ML-KEM key and encapsulation APIs
benches/chacha_bench.rs Modified random number generation in benchmarks to use ChaChaOsRng for consistency
Cargo.toml Removed obsolete dependencies and added libcrux-ml-kem and updated rand_chacha versions
Comments suppressed due to low confidence (1)

src/lib.rs:154

  • The call to mlkem768::decapsulate contains an extraneous trailing comma, which could lead to a syntax error. Please remove the trailing comma.
let shared_secret = mlkem768::decapsulate(server_kp.private_key(), &kyber_ciphertext_array, );

Copy link

codspeed-hq bot commented May 9, 2025

CodSpeed Performance Report

Merging #56 will improve performances by 83.55%

Comparing new-mlkem-lib (83a3015) with master (e168be6)

Summary

⚡ 6 improvements
✅ 9 untouched benchmarks
🆕 3 new benchmarks
⁉️ 3 dropped benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark BASE HEAD Change
⁉️ kyber_decapsulation 228.6 µs N/A N/A
🆕 mlkem_decapsulation N/A 124.9 µs N/A
⁉️ kyber_encapsulation 234.3 µs N/A N/A
🆕 mlkem_encapsulation N/A 117.6 µs N/A
full_decryption_long 278.9 µs 200.4 µs +39.19%
full_decryption_medium 265.9 µs 167.1 µs +59.16%
full_decryption_short 261 µs 152.5 µs +71.12%
full_encryption_long 281.7 µs 179.9 µs +56.62%
full_encryption_medium 271.6 µs 155.2 µs +74.99%
full_encryption_short 266.5 µs 145.2 µs +83.55%
⁉️ kyber_keypair_generation 200.4 µs N/A N/A
🆕 mlkem_keypair_generation N/A 125.3 µs N/A

@Nichokas Nichokas disabled auto-merge May 9, 2025 17:49
@Nichokas Nichokas merged commit b9a1c9b into master May 9, 2025
5 of 6 checks passed
@Nichokas Nichokas deleted the new-mlkem-lib branch May 9, 2025 17:49
@Nichokas Nichokas added enhancement New feature or request dependencies Pull requests that update a dependency file rust Pull requests that update rust code labels Jul 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file enhancement New feature or request rust Pull requests that update rust code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add the libcrux crate to use a more trusted ml-kem implementation
1 participant