Skip to content

Conversation

@kornelski
Copy link
Collaborator

Includes #470

If C lacks MLKEM APIs, and the mlkem Cargo feature isn't requiring a real MLKEM support, boring-sys will inject an always-failing fallback to allow Rust bindings to fail at run time instead of compile time.

It uses a glob to add the fallback, because Rust always prefers real definitions over globs, so the real definitions will be used if they're available.


fn fail() {
unsafe {
ERR_put_error(
Copy link
Member

Choose a reason for hiding this comment

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

This only records an error, right? Doesn't halt the execution.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah. I've renamed it to just put_error.

Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we panic and halt execution to prevent the thing you worried about?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The void functions I'm worried about panic via unimplemented!(), which will halt the execution one way or another (unwind or abort). Other functions that can report errors do it in the normal way by pushing an error on the stack and returning a failure code (these functions are documented to return 1 on success and 0 otherwise). I wanted this to be most gracefully-degrading as possible.

@kornelski kornelski force-pushed the dummy-mlkem branch 4 times, most recently from 36a547e to fb69e23 Compare February 10, 2026 23:21
_seed: *const u8,
_seed_len: usize,
) -> ::std::os::raw::c_int {
put_error();
Copy link
Member

Choose a reason for hiding this comment

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

We should panic here too because MLKEM1024_private_key_from_seed doesn't error if you give it the right parameters and so an error check could be omitted.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sigh, another C API being one cut corner away from UB and vulnerabilities. I've slapped abort() on all of them.

Copy link
Member

Choose a reason for hiding this comment

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

🙏

_ciphertext_len: usize,
_private_key: *const MLKEM1024_private_key,
) -> ::std::os::raw::c_int {
put_error();
Copy link
Member

Choose a reason for hiding this comment

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

Same.

_seed_len: usize,
) -> ::std::os::raw::c_int {
put_error();
0
Copy link
Member

Choose a reason for hiding this comment

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

Same.

_private_key: *const MLKEM768_private_key,
) -> ::std::os::raw::c_int {
put_error();
0
Copy link
Member

Choose a reason for hiding this comment

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

Same.

public_key: *const MLKEM768_public_key,
) -> ::std::os::raw::c_int {
put_error();
0
Copy link
Member

Choose a reason for hiding this comment

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

Same.

public_key: *const MLKEM1024_public_key,
) -> ::std::os::raw::c_int {
put_error();
0
Copy link
Member

Choose a reason for hiding this comment

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

Same.

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.

2 participants