-
Notifications
You must be signed in to change notification settings - Fork 505
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This switches the default cryptographic algorithms implementation to use dlopen libcrypto.so.* rather than linking to it at build time. That way the applications could use their favorite implementation of common cryptographic primitives without pulling in the OpenSSL as a dependency. Signed-off-by: Daiki Ueno <[email protected]>
- Loading branch information
Showing
18 changed files
with
561 additions
and
270 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#define OQS_OSS_DEFINE_FUNC 1 | ||
#include "openssl_shim.h" | ||
|
||
#include <assert.h> | ||
#include <dlfcn.h> | ||
|
||
static void *libcrypto_dlhandle; | ||
|
||
void oqs_ossl_ensure_library(void) { | ||
if (!libcrypto_dlhandle) { | ||
libcrypto_dlhandle = dlopen("libcrypto.so.3", RTLD_NOW | RTLD_GLOBAL); | ||
if (!libcrypto_dlhandle) { | ||
exit(EXIT_FAILURE); | ||
} | ||
} | ||
} | ||
|
||
void oqs_ossl_ensure_function(const char *name, void **funcp) { | ||
void *func = dlsym(libcrypto_dlhandle, name); | ||
if (!func) { | ||
exit(EXIT_FAILURE); | ||
} | ||
*funcp = func; | ||
} | ||
|
||
void oqs_ossl_unload_library(void) { | ||
assert(libcrypto_dlhandle); | ||
dlclose(libcrypto_dlhandle); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include <openssl/err.h> | ||
#include <openssl/evp.h> | ||
#include <openssl/rand.h> | ||
|
||
#ifdef OQS_OSS_DEFINE_FUNC | ||
#define OQS_OSSL_FUNC(name) \ | ||
__typeof__(name)(*_oqs_ossl_##name) | ||
#else | ||
#define OQS_OSSL_FUNC(name) \ | ||
extern __typeof__(name)(*_oqs_ossl_##name) | ||
#endif | ||
|
||
OQS_OSSL_FUNC(ERR_print_errors_fp); | ||
OQS_OSSL_FUNC(EVP_CIPHER_CTX_free); | ||
OQS_OSSL_FUNC(EVP_CIPHER_CTX_new); | ||
OQS_OSSL_FUNC(EVP_CIPHER_CTX_set_padding); | ||
OQS_OSSL_FUNC(EVP_DigestFinalXOF); | ||
OQS_OSSL_FUNC(EVP_DigestFinal_ex); | ||
OQS_OSSL_FUNC(EVP_DigestInit_ex); | ||
OQS_OSSL_FUNC(EVP_DigestUpdate); | ||
OQS_OSSL_FUNC(EVP_EncryptFinal_ex); | ||
OQS_OSSL_FUNC(EVP_EncryptInit_ex); | ||
OQS_OSSL_FUNC(EVP_EncryptUpdate); | ||
OQS_OSSL_FUNC(EVP_MD_CTX_copy_ex); | ||
OQS_OSSL_FUNC(EVP_MD_CTX_free); | ||
OQS_OSSL_FUNC(EVP_MD_CTX_new); | ||
OQS_OSSL_FUNC(EVP_aes_128_ecb); | ||
OQS_OSSL_FUNC(EVP_aes_256_ecb); | ||
OQS_OSSL_FUNC(EVP_aes_256_ctr); | ||
OQS_OSSL_FUNC(EVP_sha256); | ||
OQS_OSSL_FUNC(EVP_sha384); | ||
OQS_OSSL_FUNC(EVP_sha3_256); | ||
OQS_OSSL_FUNC(EVP_sha3_384); | ||
OQS_OSSL_FUNC(EVP_sha3_512); | ||
OQS_OSSL_FUNC(EVP_sha512); | ||
OQS_OSSL_FUNC(EVP_shake128); | ||
OQS_OSSL_FUNC(EVP_shake256); | ||
OQS_OSSL_FUNC(RAND_bytes); | ||
OQS_OSSL_FUNC(RAND_poll); | ||
OQS_OSSL_FUNC(RAND_status); | ||
|
||
void oqs_ossl_ensure_library(void); | ||
|
||
#define OQS_OSSL_ENSURE_FUNCTION(name) \ | ||
oqs_ossl_ensure_function(#name, (void **)&_oqs_ossl_##name) | ||
|
||
void oqs_ossl_ensure_function(const char *name, void **funcp); |
Oops, something went wrong.