Skip to content

Commit

Permalink
Merge pull request SoftEtherVPN#2022 from siddharth-narayan/built-in-…
Browse files Browse the repository at this point in the history
…post-quantum

Add built in post quantum functionality
  • Loading branch information
chipitsine authored Jul 19, 2024
2 parents 4e8f797 + 67fe99e commit a836b3b
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@
[submodule "src/libhamcore"]
path = src/libhamcore
url = https://github.com/SoftEtherVPN/libhamcore.git
[submodule "src/Mayaqua/3rdparty/oqs-provider"]
path = src/Mayaqua/3rdparty/oqs-provider
url = https://github.com/open-quantum-safe/oqs-provider.git
[submodule "src/Mayaqua/3rdparty/liboqs"]
path = src/Mayaqua/3rdparty/liboqs
url = https://github.com/open-quantum-safe/liboqs.git
2 changes: 2 additions & 0 deletions src/Mayaqua/3rdparty/Findliboqs.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
set(oqs_FOUND TRUE)
add_library(OQS::oqs ALIAS oqs)
1 change: 1 addition & 0 deletions src/Mayaqua/3rdparty/liboqs
Submodule liboqs added at 51ddd3
1 change: 1 addition & 0 deletions src/Mayaqua/3rdparty/oqs-provider
Submodule oqs-provider added at 8f3752
16 changes: 16 additions & 0 deletions src/Mayaqua/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@ set_target_properties(mayaqua

find_package(OpenSSL REQUIRED)

if(OPENSSL_VERSION VERSION_LESS "3") # Disable oqsprovider when OpenSSL version < 3
add_definitions(-DSKIP_OQS_PROVIDER)
else()
set(OQS_BUILD_ONLY_LIB ON CACHE BOOL "Set liboqs to build only the library (no tests)")
set(BUILD_TESTING OFF CACHE BOOL "By setting this to OFF, no tests or examples will be compiled.")
set(OQS_PROVIDER_BUILD_STATIC ON CACHE BOOL "Build a static library instead of a shared library") # Build oqsprovider as a static library (defaults to shared)
list(PREPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/src/Mayaqua/3rdparty/")

add_subdirectory(3rdparty/liboqs)
add_subdirectory(3rdparty/oqs-provider)

target_include_directories(oqsprovider PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/3rdparty/liboqs/include)
set_property(TARGET oqsprovider PROPERTY POSITION_INDEPENDENT_CODE ON)
target_link_libraries(mayaqua PRIVATE oqsprovider)
endif()

include(CheckSymbolExists)

set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR})
Expand Down
12 changes: 11 additions & 1 deletion src/Mayaqua/Encrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
#include <openssl/x509v3.h>
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
#include <openssl/provider.h>
// Static oqsprovider initialization function
#ifndef SKIP_OQS_PROVIDER
extern OSSL_provider_init_fn oqs_provider_init;
#endif
#endif

#ifdef _MSC_VER
Expand Down Expand Up @@ -4005,7 +4009,13 @@ void InitCryptLibrary()
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
ossl_provider_default = OSSL_PROVIDER_load(NULL, "legacy");
ossl_provider_legacy = OSSL_PROVIDER_load(NULL, "default");
ossl_provider_oqsprovider = OSSL_PROVIDER_load(NULL, "oqsprovider");

char *oqs_provider_name = "oqsprovider";
#ifndef SKIP_OQS_PROVIDER
// Registers "oqsprovider" as a provider -- necessary because oqsprovider is built in now.
OSSL_PROVIDER_add_builtin(NULL, oqs_provider_name, oqs_provider_init);
#endif
ossl_provider_oqsprovider = OSSL_PROVIDER_load(NULL, oqs_provider_name);
#endif

ssl_clientcert_index = SSL_get_ex_new_index(0, "struct SslClientCertInfo *", NULL, NULL, NULL);
Expand Down

0 comments on commit a836b3b

Please sign in to comment.