|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2021 dresden elektronik ingenieurtechnik gmbh. |
| 2 | + * Copyright (c) 2021-2024 dresden elektronik ingenieurtechnik gmbh. |
3 | 3 | * All rights reserved.
|
4 | 4 | *
|
5 | 5 | * The software in this package is published under the terms of the BSD
|
|
17 | 17 | #endif
|
18 | 18 |
|
19 | 19 | #include <array>
|
20 |
| -#include <QLibrary> |
| 20 | +#include <QByteArray> |
| 21 | +#include <QString> |
21 | 22 | #include "random.h"
|
22 | 23 | #include "scrypt.h"
|
| 24 | +#include "deconz/u_library_ex.h" |
23 | 25 |
|
24 | 26 |
|
25 | 27 | #ifdef HAS_OPENSSL
|
@@ -63,35 +65,32 @@ static int wrap_EVP_PKEY_CTX_set_scrypt_p(EVP_PKEY_CTX *ctx, uint64_t p)
|
63 | 65 | */
|
64 | 66 | static int scryptDerive(const char *input, size_t inputLength, std::array<unsigned char, 64> &out, int N, int r, int p, const unsigned char *salt, size_t saltlen)
|
65 | 67 | {
|
66 |
| -#ifdef Q_OS_WIN |
67 |
| - QLibrary libCrypto(QLatin1String("libcrypto-1_1.dll")); |
68 |
| - QLibrary libSsl(QLatin1String("libssl-1_1.dll")); |
69 |
| -#elif defined (__APPLE__) |
70 |
| - QLibrary libCrypto(QLatin1String("../Frameworks/libcrypto.3.dylib")); |
71 |
| - QLibrary libSsl(QLatin1String("../Frameworks/libssl.3.dylib")); |
72 |
| -#else |
73 |
| - QLibrary libCrypto(QLatin1String("crypto")); |
74 |
| - QLibrary libSsl(QLatin1String("ssl")); |
75 |
| -#endif |
| 68 | + void *libCrypto = U_library_open_ex("libcrypto"); |
| 69 | + void *libSsl = U_library_open_ex("libssl"); |
| 70 | + |
| 71 | + if (!libCrypto || !libSsl) |
| 72 | + { |
| 73 | + return -1; |
| 74 | + } |
76 | 75 |
|
77 | 76 | unsigned long openSslVersion = 0;
|
78 | 77 |
|
79 |
| - auto _OpenSSL_version_num = reinterpret_cast<unsigned long (*)(void)>(libCrypto.resolve("OpenSSL_version_num")); |
| 78 | + auto _OpenSSL_version_num = reinterpret_cast<unsigned long (*)(void)>(U_library_symbol(libCrypto, "OpenSSL_version_num")); |
80 | 79 |
|
81 |
| - const auto lib_EVP_PKEY_CTX_new_id = reinterpret_cast<EVP_PKEY_CTX *(*)(int id, ENGINE *e)>(libCrypto.resolve("EVP_PKEY_CTX_new_id")); |
82 |
| - const auto lib_EVP_PKEY_derive_init = reinterpret_cast<int (*)(EVP_PKEY_CTX *ctx)>(libCrypto.resolve("EVP_PKEY_derive_init")); |
83 |
| - lib_EVP_PKEY_CTX_ctrl = reinterpret_cast<int (*)(EVP_PKEY_CTX *ctx, int keytype, int optype, int cmd, int p1, void *p2)>(libCrypto.resolve("EVP_PKEY_CTX_ctrl")); |
84 |
| - lib_EVP_PKEY_CTX_ctrl_uint64 = reinterpret_cast<int (*)(EVP_PKEY_CTX *ctx, int keytype, int optype, int cmd, uint64_t value)>(libCrypto.resolve("EVP_PKEY_CTX_ctrl_uint64")); |
85 |
| - const auto lib_EVP_PKEY_derive = reinterpret_cast<int (*)(EVP_PKEY_CTX *ctx, unsigned char *key, size_t *keylen)>(libCrypto.resolve("EVP_PKEY_derive")); |
86 |
| - const auto lib_EVP_PKEY_CTX_free = reinterpret_cast<void (*)(EVP_PKEY_CTX *ctx)>(libCrypto.resolve("EVP_PKEY_CTX_free")); |
| 80 | + const auto lib_EVP_PKEY_CTX_new_id = reinterpret_cast<EVP_PKEY_CTX *(*)(int id, ENGINE *e)>(U_library_symbol(libCrypto, "EVP_PKEY_CTX_new_id")); |
| 81 | + const auto lib_EVP_PKEY_derive_init = reinterpret_cast<int (*)(EVP_PKEY_CTX *ctx)>(U_library_symbol(libCrypto, "EVP_PKEY_derive_init")); |
| 82 | + lib_EVP_PKEY_CTX_ctrl = reinterpret_cast<int (*)(EVP_PKEY_CTX *ctx, int keytype, int optype, int cmd, int p1, void *p2)>(U_library_symbol(libCrypto, "EVP_PKEY_CTX_ctrl")); |
| 83 | + lib_EVP_PKEY_CTX_ctrl_uint64 = reinterpret_cast<int (*)(EVP_PKEY_CTX *ctx, int keytype, int optype, int cmd, uint64_t value)>(U_library_symbol(libCrypto, "EVP_PKEY_CTX_ctrl_uint64")); |
| 84 | + const auto lib_EVP_PKEY_derive = reinterpret_cast<int (*)(EVP_PKEY_CTX *ctx, unsigned char *key, size_t *keylen)>(U_library_symbol(libCrypto, "EVP_PKEY_derive")); |
| 85 | + const auto lib_EVP_PKEY_CTX_free = reinterpret_cast<void (*)(EVP_PKEY_CTX *ctx)>(U_library_symbol(libCrypto, "EVP_PKEY_CTX_free")); |
87 | 86 |
|
88 |
| - auto lib_EVP_PKEY_CTX_set1_pbe_pass = reinterpret_cast<int (*)(EVP_PKEY_CTX *ctx, const char *pass, int passlen)>(libCrypto.resolve("EVP_PKEY_CTX_set1_pbe_pass")); |
| 87 | + auto lib_EVP_PKEY_CTX_set1_pbe_pass = reinterpret_cast<int (*)(EVP_PKEY_CTX *ctx, const char *pass, int passlen)>(U_library_symbol(libCrypto, "EVP_PKEY_CTX_set1_pbe_pass")); |
89 | 88 |
|
90 |
| - auto lib_EVP_PKEY_CTX_set1_scrypt_salt = reinterpret_cast<int (*)(EVP_PKEY_CTX *ctx, const unsigned char *salt, int saltlen)>(libCrypto.resolve("EVP_PKEY_CTX_set1_scrypt_salt")); |
| 89 | + auto lib_EVP_PKEY_CTX_set1_scrypt_salt = reinterpret_cast<int (*)(EVP_PKEY_CTX *ctx, const unsigned char *salt, int saltlen)>(U_library_symbol(libCrypto, "EVP_PKEY_CTX_set1_scrypt_salt")); |
91 | 90 |
|
92 |
| - auto lib_EVP_PKEY_CTX_set_scrypt_N = reinterpret_cast<int (*)(EVP_PKEY_CTX *ctx, uint64_t n)>(libCrypto.resolve("EVP_PKEY_CTX_set_scrypt_N")); |
93 |
| - auto lib_EVP_PKEY_CTX_set_scrypt_r = reinterpret_cast<int (*)(EVP_PKEY_CTX *ctx, uint64_t r)>(libCrypto.resolve("EVP_PKEY_CTX_set_scrypt_r")); |
94 |
| - auto lib_EVP_PKEY_CTX_set_scrypt_p = reinterpret_cast<int (*)(EVP_PKEY_CTX *ctx, uint64_t p)>(libCrypto.resolve("EVP_PKEY_CTX_set_scrypt_p")); |
| 91 | + auto lib_EVP_PKEY_CTX_set_scrypt_N = reinterpret_cast<int (*)(EVP_PKEY_CTX *ctx, uint64_t n)>(U_library_symbol(libCrypto, "EVP_PKEY_CTX_set_scrypt_N")); |
| 92 | + auto lib_EVP_PKEY_CTX_set_scrypt_r = reinterpret_cast<int (*)(EVP_PKEY_CTX *ctx, uint64_t r)>(U_library_symbol(libCrypto, "EVP_PKEY_CTX_set_scrypt_r")); |
| 93 | + auto lib_EVP_PKEY_CTX_set_scrypt_p = reinterpret_cast<int (*)(EVP_PKEY_CTX *ctx, uint64_t p)>(U_library_symbol(libCrypto, "EVP_PKEY_CTX_set_scrypt_p")); |
95 | 94 |
|
96 | 95 | if (_OpenSSL_version_num)
|
97 | 96 | {
|
|
0 commit comments