Skip to content

Rust wrapper: add mlkem module#9833

Open
holtrop-wolfssl wants to merge 1 commit intowolfSSL:masterfrom
holtrop-wolfssl:rust-ml-kem
Open

Rust wrapper: add mlkem module#9833
holtrop-wolfssl wants to merge 1 commit intowolfSSL:masterfrom
holtrop-wolfssl:rust-ml-kem

Conversation

@holtrop-wolfssl
Copy link
Contributor

Description

Rust wrapper: add mlkem module

Testing

Unit tests

Checklist

  • added tests
  • updated/added doxygen
  • updated appropriate READMEs
  • Updated manual and documentation

@holtrop-wolfssl holtrop-wolfssl self-assigned this Feb 25, 2026
@holtrop-wolfssl
Copy link
Contributor Author

retest this please (ERROR: wolfSSL » PRB-140-3-tests #8576 was deleted)

@holtrop-wolfssl holtrop-wolfssl marked this pull request as ready for review February 26, 2026 13:24
///
/// # Parameters
///
/// * `key_type`: Key type. One of [`MlKem::TYPE_512`], [`MlKem::TYPE_768`],
Copy link
Contributor

Choose a reason for hiding this comment

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

here, just like for the dilithium.rs, I think there should be a check for key_type.
either here or in generate_with_random_ex, making sure that is either 512, 768 or 1024.

if ct.len() != expected_ct_size {
return Err(sys::wolfCrypt_ErrorCodes_BUFFER_E);
}
if ss.len() != Self::SHARED_SECRET_SIZE {
Copy link
Contributor

Choose a reason for hiding this comment

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

here maybe, for consistency, could they both get validated against a runtime query (like it's happening for ct.len()) or both against a rust constant.
so adding a shared_secret_size() for the ss check too or just a brief comment explaining why the constant is used directly.

self.ws_key,
ss.as_mut_ptr(),
ct.as_ptr(),
ct.len() as u32,
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe here (and other places too) I would consider a more idiomatic way of casting something like:
u32::try_from(ct.len()).map_err(|_| ...)? (I think this right way of typing this).

in practice this is just to prevent in case ct.len() is > than u32::MAAX, the cipher text for ml-kem I don't think it can be that big, but just for better practice a better casting would be better I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants