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

Initial fetching of MD and Cipher objects from OpenSSL(3) #1431

Merged
merged 5 commits into from
Apr 25, 2023

Conversation

beldmit
Copy link
Contributor

@beldmit beldmit commented Apr 7, 2023

We need init them and free them in one place to avoid threading issues.

  • Does this PR change the input/output behaviour of a cryptographic algorithm (i.e., does it change known answer test values)? (If so, a version bump will be required from x.y.z to x.(y+1).0.)
  • Does this PR change the the list of algorithms available -- either adding, removing, or renaming? Does this PR otherwise change an API? (If so, PRs in oqs-provider, OQS-OpenSSL, OQS-BoringSSL, and OQS-OpenSSH will also need to be ready for review and merge by the time this is merged.)

We need init them and free them in one place to avoid threading
issues.
@beldmit beldmit requested a review from dstebila as a code owner April 7, 2023 14:05
@beldmit
Copy link
Contributor Author

beldmit commented Apr 7, 2023

Related: #1427

Copy link
Member

@baentsch baentsch left a comment

Choose a reason for hiding this comment

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

We need init them and free them in one place to avoid threading issues.

What about using

OQS_API void OQS_init(void) {
for the former and adding a function for the latter? Probably easier than the alternative of adding init and close to all OQS operations.

@beldmit
Copy link
Contributor Author

beldmit commented Apr 7, 2023

Thanks! It's quite reasonable

@baentsch
Copy link
Member

baentsch commented Apr 7, 2023

Thanks! It's quite reasonable

But then again -- is this really sufficient? Are these EVP objects thread-safe? What if someone calls in different threads different OpenSSL APIs, all reaching into oqsprovider which in turn calls back into OpenSSL in this way?

The documentation states

However most OpenSSL data structures are not thread-safe.

@beldmit
Copy link
Contributor Author

beldmit commented Apr 7, 2023

EVP_MD and EVP_CIPHER objects should be thread-safe - they are just sets of callbacks and flags. The problem may happen if the provider providing them is unloaded.

@baentsch
Copy link
Member

baentsch commented Apr 7, 2023

The problem may happen if the provider providing them is unloaded.

Good. I don't see how this should be facilitated by an application that is using liboqs directly: liboqs doesn't make available (doesn't know about :) OSSL_PROVIDER or OSSL_LIB_CTX, so how could an unload happen?

If oqsprovider in turn triggers usage of liboqs what about checking there that a suitable provider for SHA/AES is loaded/available (in the same OSSL_LIB_CTX)? But yikes, then the proposed implementation passing NULL to the EVP_fetch routines doesn't cut it.... :-(

@beldmit beldmit requested a review from xvzcf as a code owner April 7, 2023 17:24
@beldmit
Copy link
Contributor Author

beldmit commented Apr 7, 2023

I groomed the code according my understanding of how it goes.
The tests work for me.

Consequence: OQS_init call becomes mandatory

@beldmit
Copy link
Contributor Author

beldmit commented Apr 7, 2023

At this point I'm waiting for your feedback whether we should follow this direction as a whole or not

Copy link
Member

@baentsch baentsch left a comment

Choose a reason for hiding this comment

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

At this point I'm waiting for your feedback whether we should follow this direction as a whole or not

As far as I'm concerned, it does. The one thing not looking good (also as per CI) is that the ossl_helper functions should be namespaced: Proposal would be "oqs_ossl_xyz" (instead of just "_xyz")

@beldmit
Copy link
Contributor Author

beldmit commented Apr 8, 2023

I will adjust namespace, but also init and free functions must be documented as mandatory...

Copy link
Member

@baentsch baentsch left a comment

Choose a reason for hiding this comment

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

Thank you very much again for your contribution: Very much appreciated! Don't feel stopped to address/comment on the single comments I just made -- but if you have more urgent things to do, we'll follow up accordingly.

@baentsch baentsch changed the title Strawman version of one-time fetching MD objects from OpenSSL ~Strawman version of~ one-time fetching MD objects from OpenSSL Apr 8, 2023
@baentsch baentsch changed the title ~Strawman version of~ one-time fetching MD objects from OpenSSL Initial fetching of MD and Cipher objects from OpenSSL(3) Apr 8, 2023
@beldmit
Copy link
Contributor Author

beldmit commented Apr 8, 2023

I'm going to add OQS_destroy function and call it in the tests. I'd like to finalize this issue if we have an agreement what should be done

@baentsch
Copy link
Member

baentsch commented Apr 8, 2023

I'm going to add OQS_destroy function and call it in the tests. I'd like to finalize this issue if we have an agreement what should be done

Good for me -- provided the comment here, gets updated (making the invocation of OQS_init a requirement for correct use of the library). Thanks again.

@beldmit
Copy link
Contributor Author

beldmit commented Apr 8, 2023

So. I finished what I understood was worth doing. Could you please specify what are the next steps to deal with it? Is there anything to be done by me just now or it can be merged as is and we could move forward?

* This currently only sets the values in the OQS_CPU_EXTENSIONS,
* and so has effect only when OQS_DIST_BUILD is set.
* This currently sets the values in the OQS_CPU_EXTENSIONS
* and prefetches the OpenSSL obejcts if necessary.
Copy link
Member

Choose a reason for hiding this comment

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

nit: typo. Can deal with when doing next doc review. Would also recommend phrasing more strongly along the lines of "Needs to be invoked to ensure proper operation of library."

@baentsch
Copy link
Member

baentsch commented Apr 8, 2023

Is there anything to be done by me just now

Not really. Thanks again for the contribution.

or it can be merged as is and we could move forward?

Yes from my perspective but I leave the merge to another team member (@dstebila : Back again?)

@sahanaprasad07
Copy link

Hi @beldmit , would it make sense to replace EVP_aes_256_ecb() in src/common/rand/rand_nist.c?

@beldmit
Copy link
Contributor Author

beldmit commented Apr 13, 2023

Probably yes, if this code is used multiple times.

src/common/common.h Outdated Show resolved Hide resolved
@dstebila
Copy link
Member

Hi @beldmit , would it make sense to replace EVP_aes_256_ecb() in src/common/rand/rand_nist.c?

Probably yes, if this code is used multiple times.

Okay, done in 87780d2. Will merge once CI passes.

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.

4 participants