Skip to content
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

Draft: OpenSSL 3 #260

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

Michael-Panic
Copy link

A few days ago, I volunteered to contribute an OpenSSL 3 implementation that doesn't use any functions or types deprecated by OpenSSL 3 in #243. I realized as I was finishing this that I don't actually have a good way of testing this, so it probably shouldn't be merged as-is.

I tried running ./tests/test-all.sh, but many of the tests failed, even without my changes. I suspect my computer isn't set up to properly run the tests, plus there were some comments in there about the tests really only working on openbsd.

But I'm willing to help however I can to figure out how to get this all tested and merged.

…d OpenSSL structs and update the implementation to not use those functions
@wtoorop
Copy link
Member

wtoorop commented Nov 29, 2024

No worries. I'll give it a proper review! Thanks for starting with this anyway!

Copy link
Contributor

@pemensik pemensik left a comment

Choose a reason for hiding this comment

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

I have found some things to change a bit. But overall great work so far, thank for you that!

@@ -792,3 +792,16 @@ b32_pton_extended_hex(const char* src, size_t src_sz,

#endif /* ! HAVE_B32_PTON */

void
ldns_swap_bytes(unsigned char *buf, size_t len)
Copy link
Contributor

@pemensik pemensik Dec 9, 2024

Choose a reason for hiding this comment

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

I would propose to implement endian swapping memcpy. I think all uses of this function first use memcpy, then do swap_bytes on the same data. Could it perhaps swap bytes into target buffer instead and use memcpy if that is not necessary? That way it would not require temp variable usage.

But I am not sure, should it use instead BN_lebin2bn or BN_bin2bn ?

dnssec.c Show resolved Hide resolved
offset += SHA_DIGEST_LENGTH;

memcpy(P, key+offset, length);
ldns_swap_bytes(P, length);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is using own swap.

params[0] =
OSSL_PARAM_construct_BN(OSSL_PKEY_PARAM_FFC_Q, Q, SHA_DIGEST_LENGTH);

params[1] = OSSL_PARAM_construct_BN(OSSL_PKEY_PARAM_FFC_P, P, length);
Copy link
Contributor

Choose a reason for hiding this comment

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

This may have used OSSL_PARAM_set_BN with combination of BN_bin2bn IMO. Is there a reason it were not used for it and own swap implemented?

Copy link
Author

Choose a reason for hiding this comment

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

Yes. This is an unfortunate requirement for OpenSSL3, but all OSSL_PARAMs must be stored in native byte order instead of network byte order. BIGNUMs created by BN_bin2bn and similar functions store the data in network byte order. This effectively makes OSSL_PARAM_set_BN difficult to use on little-endian systems.

I suppose it would be possible to call BN_lebin2bn to create a backwards BIGNUM on little endian systems, but it's a bit strange because you're calling a function designed to take little endian data on big endian data. It's also weird because you'd have to conditionally call the function based on the endianness of the system.

However, I recall trying this when doing work for libssh2 and finding that it didn't work properly. The only solution that worked for me at the time was swapping the buffer and calling OSSL_PARAM_construct_BN.

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