open-quantum-safe / liboqs

C library for prototyping and experimenting with quantum-resistant cryptography
https://openquantumsafe.org/
Other
1.92k stars 468 forks source link

dlfcn required for windows build #1768

Open andybrucenet opened 7 months ago

andybrucenet commented 7 months ago

Describe the bug When building on windows receive a compile error from src/common/ossl_helpers.c - dlfcn.h is not available on windows

To Reproduce Try to build on windows :)

Expected behavior One of four things:

  1. Provide cross-platform code to load shared libraries (alternative to dlopen / dlclose)
  2. ifdef around #include <dlfcn.h> / dlfcn functions (simply ignore on windows and assume that required libraries are loaded).

  3. Require dlfcn-win32 package with basic instructions on the liboqs github page on how to install (prerequisite).
  4. Auto-install dlfcn-win32 from dlfcn-win32 github page as part of standard build.

Screenshots I even put on a screenshot for you :) liboqs-build-error

Environment (please complete the following information):

Additional context I added logs collected from my run which shows all the configuration occurring. buildliboqs.log''

I worked around the problem as follows:

// ABr: avoid dlfcn on windows
#if !defined(_MSC_VER)
#include <dlfcn.h>
#endif
[...]
static void ensure_symbol(const char *name, void **symp) {
#if !defined(_MSC_VER)
    if (!*symp) {
        void *sym = dlsym(libcrypto_dlhandle, name);
        if (!sym) {
            exit(EXIT_FAILURE);
        }
        *symp = sym;
    }
#endif
}
static void ensure_library(void) {
#if !defined(_MSC_VER)
    if (!libcrypto_dlhandle) {
        libcrypto_dlhandle = dlopen(OQS_OPENSSL_CRYPTO_SONAME,
                                    RTLD_LAZY | RTLD_LOCAL);
        if (!libcrypto_dlhandle) {
            exit(EXIT_FAILURE);
        }
    }

#define ENSURE_SYMBOL(name) \
    ensure_symbol(#name, (void **)&_oqs_ossl_sym_##name)
#define FUNC(ret, name, args, cargs)        \
    ENSURE_SYMBOL(name);
#define VOID_FUNC FUNC
#include "ossl_functions.h"
#undef VOID_FUNC
#undef FUNC
#undef ENSURE_SYMBOL
#endif
}
baentsch commented 7 months ago

Please check PLATFORMS.md: You'll notice limited Windows support for liboqs (we don't have people knowledgeable/interested in that platform for the project). Any contributions via PR welcome!

andybrucenet commented 7 months ago

Just saw this. I'll be happy to put in some code as soon as I get to a stopping point.

On the good news - I have integrated all the defined NIST algos for DSA / KEM on Windows (with my local hacks for now), macOS, iOS, Android, and Linux (glibc 2.34 since a "static" openssl build...still requires a glibc unless yet-more-work is done with musl).

All my tests pass on every platform. I still need to prove interoperability such that when keys are exchanged between different platforms via PEM files that everything works. But so far things is looking good.