Skip to content

Conversation

@jedenastka
Copy link
Contributor

@jedenastka jedenastka commented Sep 11, 2025

SSL_CIPHER_get_protocol_id

This includes both bindings for openssl-sys and high-level bindings for openssl. I wasn't sure whether to use [u8; 2] or u16 for the high-level return type, decided on [u8; 2] for now as it feels more natural, I can change this if u16 (the same as in C) is better.

Copy link
Collaborator

@alex alex left a comment

Choose a reason for hiding this comment

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

can we get a test?

@jedenastka
Copy link
Contributor Author

can we get a test?

Something simple like this is enough?

pub fn protocol_id(&self) -> [u8; 2] {
unsafe {
let id = ffi::SSL_CIPHER_get_protocol_id(self.as_ptr());
id.to_be_bytes()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is big endian always right?

Copy link
Contributor Author

@jedenastka jedenastka Sep 13, 2025

Choose a reason for hiding this comment

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

It definitely should be. Those are two byte constants (they are not defined as u16), moreover TLS is big-endian in general, even if they weren't: https://www.rfc-editor.org/rfc/rfc8446#section-3.1.

OpenSSL could have a bug with this though, I think it's unlikely, but I don't know. Two bytes are received, then they are turned into an integer, which is native-endian - in other words, on little-endian architectures a byte swap is necessary. It seems like on all architectures you test it did properly byte swap as needed, since tests passed, but I don't see a test on PowerPC so who knows. I don't have a big-endian machine to test myself.

Simply said - on big-endian architectures, there should be no byte swap, and on little-endian there should be two byte swaps, which cancel each other out.

Copy link
Contributor

Choose a reason for hiding this comment

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

Building the branch on a sparc64 machine with OpenSSL 3.5 gives:

test ssl::test::cipher_id ... ok

Copy link
Collaborator

@alex alex left a comment

Choose a reason for hiding this comment

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

great, thanks

@alex alex merged commit 88b0686 into rust-openssl:master Sep 13, 2025
86 checks passed
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