This will make it easier to maintain, as well as easier to create new/alternate implementations of portions of the code (e.g. in Rust). crypto.h is already somewhat neatly partitioned into sections. nickm said that likely appropriate categories for code for the new modules are
I'd suggest structuring this as a series of commits, each of which splits out exactly one piece of functionality from crypto.[ch].
Also, let's review the first commit or two before we do the whole file -- that way, we can discuss our approach without having to throw away a huge amount of work.
I'd suggest that the new modules get names like crypto_rsa, crypto_dh, crypto_stream, ...
I have been working on refactoring OpenSSL management from crypto.[ch] into a smaller module. It is working now and all tests run succesfully. But as nickm said I only uploaded the first commits to get them reviewed.
If everything is fine, then I will upload all related with compilation and dependencies in other files. Check my github branch bug24658-openssl.
Let's rename the new file to crypto_openssl_mgt or crypto_openssl_setup or something? We might someday want to have a crypto_openssl file that is not openssl management, but that contains openssl backends.
free_openssl() is not our usual naming style; something more like crypto_openssl_free_all() would be more like what we usually do.
n_openssl_mutexes and openssl_mutexes should not be globals declared in the header. They should remain static variables. (Doing it like that doesn't work the way you expect in C, I think.)
The functions that used to be static should not become nonstatic, except maybe for setup_openssl_threading(). The others can all be static in their new module, I think?
I have been working on splitting the RSA module from crypto.[ch]. It is working now and all tests pass succesfully, also Travis CI seems happy. I have some notes in order to do the patch easier to review.
crypto.h is included in crypto_rsa.c because we need common functions as memwipe and the digest module. This include should be removed when we split common and digest modules (xof+digest as we decided).
I didn't consider crypto_pk_obsolete_public_hybrid_encrypt() and crypto_pk_obsolete_private_hybrid_decrypt() as part of the RSA module.
crypto_get_rsa_padding_overhead() and crypto_get_rsa_padding() are not static inline anymore, I think we should discuss that.
hm. I like all of this except for the part that makes the contents of crypto_pk_t public. Generally it's better to keep structure contents like this opaque whenever we can.
Two options here would be: moving the crypto_pk_digest functions into crypto_rsa, or making them use crypto_pk_asn1_encode() instead. I tried the latter approach in a squash commit I made on top of bug24658-rsa in my public branch of the same name. Does it look ok to you?