Skip to content

Commit

Permalink
BLECrypt: Widen search for crypto library
Browse files Browse the repository at this point in the history
Some users are constrained about where they can
run the executable. Widen the search to include
the LD_LIBRARY_PATH.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
  • Loading branch information
aescolar committed May 16, 2023
1 parent 57f0f65 commit ff79a92
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/HW_models/BLECrypt_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,23 @@ static blecrypt_packet_decrypt_f blecrypt_packet_decrypt;
static blecrypt_aes_128_f blecrypt_aes_128;

void BLECrypt_if_enable_real_encryption(bool mode) {
if ( mode ) { //if they try to enable it
//attempt to load the libCrypto
if ( mode ) { //if the user tries to enable it
//Attempt to load libCrypto
char lib_name[128];
char *error;
snprintf(lib_name,128,"../lib/libCryptov1.so"); //relative to bin folder
snprintf(lib_name,128,"../lib/libCryptov1.so"); //Relative to the working directory which is expected to be the bin folder
LibCryptoHandle = dlopen(lib_name, RTLD_NOW);
if (!LibCryptoHandle) {
bs_trace_warning_line("%s\n",dlerror());
bs_trace_warning_line("Could not open the libcrypto library, is it compiled? => disabling real encryption\n");
Real_encryption_enabled = false;
return;
if (!LibCryptoHandle) { //Not found
snprintf(lib_name,128,"libCryptov1.so"); //Let's see if the user set LD_LIBRARY_PATH
LibCryptoHandle = dlopen(lib_name, RTLD_NOW);
if (!LibCryptoHandle) {
bs_trace_warning_line("%s\n",dlerror());
bs_trace_warning_line("Could not find the libCrypto library neither in ../lib or in LD_LIBRARY_PATH, is it compiled? => disabling real encryption\n");
Real_encryption_enabled = false;
return;
} else {
bs_trace_info_line(3, "This executable assumes the working directory is BabbleSim's bin/ folder, but it is not. libCrypto was found anyhow\n");
}
}
if ((error = dlerror()) != NULL) {
bs_trace_error_line("%s\n",error);
Expand Down

0 comments on commit ff79a92

Please sign in to comment.