Skip to content

Commit 216925a

Browse files
author
gojimmypi
committed
Introduce cmake get/set_wolfssl_definitions; Add Kyber and OQS
1 parent f18633a commit 216925a

2 files changed

Lines changed: 157 additions & 11 deletions

File tree

CMakeLists.txt

Lines changed: 87 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# CMakeList.txt
1+
# CMakeLists.txt
22
#
3-
# Copyright (C) 2006-2023 wolfSSL Inc.
3+
# Copyright (C) 2006-2024 wolfSSL Inc.
44
#
55
# This file is part of wolfSSL. (formerly known as CyaSSL)
66
#
@@ -539,16 +539,89 @@ add_option(WOLFSSL_OQS
539539
"Enable integration with the OQS (Open Quantum Safe) liboqs library (default: disabled)"
540540
"no" "yes;no")
541541

542-
if (WOLFSSL_OQS)
543-
find_package(OQS)
542+
# Kyber
543+
add_option(WOLFSSL_KYBER
544+
"Enable the wolfSSL PQ Kyber library (default: disabled)"
545+
"no" "yes;no")
544546

545-
if (OQS_FOUND)
546-
list(APPEND WOLFSSL_LINK_LIBS ${OQS_LIBRARY})
547-
list(APPEND WOLFSSL_INCLUDE_DIRS ${OQS_INCLUDE_DIR})
548-
set(HAVE_LIBOQS 1)
549-
list(APPEND WOLFSSL_DEFINITIONS
550-
"-DHAVE_TLS_EXTENSIONS"
551-
"-DHAVE_LIBOQS")
547+
# Experimental features
548+
add_option(WOLFSSL_EXPERIMENTAL
549+
"Enable experimental features (default: disabled)"
550+
"no" "yes;no")
551+
552+
message(STATUS "Looking for WOLFSSL_EXPERIMENTAL")
553+
if (WOLFSSL_EXPERIMENTAL)
554+
message(STATUS "Looking for WOLFSSL_EXPERIMENTAL - found")
555+
556+
# We've enabled the experimental environment, but let's
557+
# check if any experimental features are also enabled:
558+
set(WOLFSSL_FOUND_EXPERIMENTAL_FEATURE 0)
559+
560+
set_wolfssl_definitions("WOLFSSL_EXPERIMENTAL_SETTINGS" RESUlT)
561+
562+
# Checking for experimental feature: OQS
563+
message(STATUS "Looking for WOLFSSL_OQS")
564+
if (WOLFSSL_OQS)
565+
set(WOLFSSL_FOUND_EXPERIMENTAL_FEATURE 1)
566+
message(STATUS "Looking for WOLFSSL_OQS - found")
567+
568+
message(STATUS "Checking OQS")
569+
find_package(OQS)
570+
if (OQS_FOUND)
571+
message(STATUS "Checking OQS - found")
572+
list(APPEND WOLFSSL_LINK_LIBS ${OQS_LIBRARY})
573+
list(APPEND WOLFSSL_INCLUDE_DIRS ${OQS_INCLUDE_DIR})
574+
575+
set_wolfssl_definitions("HAVE_LIBOQS" RESUlT)
576+
set_wolfssl_definitions("HAVE_TLS_EXTENSIONS" RESUlT)
577+
set_wolfssl_definitions("OPENSSL_EXTRA" RESUlT)
578+
579+
else()
580+
message(STATUS "Checking OQS - not found")
581+
message(STATUS "WARNING: WOLFSSL_OQS enabled but not found: OQS_LIBRARY=${OQS_LIBRARY}, OQS_INCLUDE_DIR=${OQS_INCLUDE_DIR} ")
582+
endif()
583+
else()
584+
message(STATUS "Looking for WOLFSSL_OQS - not found")
585+
endif()
586+
587+
# Checking for experimental feature: Kyber
588+
message(STATUS "Looking for WOLFSSL_KYBER")
589+
if (WOLFSSL_KYBER)
590+
set(WOLFSSL_FOUND_EXPERIMENTAL_FEATURE 1)
591+
592+
message(STATUS "Automatically set related requirements for Kyber:")
593+
set_wolfssl_definitions("WOLFSSL_HAVE_KYBER" RESUlT)
594+
set_wolfssl_definitions("WOLFSSL_WC_KYBER" RESUlT)
595+
set_wolfssl_definitions("WOLFSSL_SHA3" RESUlT)
596+
set_wolfssl_definitions("WOLFSSL_SHAKE128" RESUlT)
597+
set_wolfssl_definitions("WOLFSSL_SHAKE256" RESUlT)
598+
message(STATUS "Looking for WOLFSSL_KYBER - found")
599+
else()
600+
message(STATUS "Looking for WOLFSSL_KYBER - not found")
601+
endif()
602+
603+
# Other experimental feature detection can be added here...
604+
605+
# Were any experimental features found? Display a message.
606+
if(WOLFSSL_FOUND_EXPERIMENTAL_FEATURE)
607+
message(STATUS "WOLFSSL_EXPERIMENTAL enabled, experimental features enabled.")
608+
else()
609+
message(STATUS "Warning: WOLFSSL_EXPERIMENTAL enabled, but no experimental features enabled.")
610+
endif()
611+
612+
# Sanity checks
613+
if(WOLFSSL_OQS AND WOLFSSL_KYBER)
614+
message(FATAL_ERROR "Error: cannot enable both WOLFSSL_OQS and WOLFSSL_KYBER at the same time.")
615+
endif()
616+
617+
else()
618+
# Experimental mode not enabled, but were any experimental features enabled? Error out if so:
619+
message(STATUS "Looking for WOLFSSL_EXPERIMENTAL - not found")
620+
if (WOLFSSL_OQS)
621+
message(FATAL_ERROR "Error: WOLFSSL_OQS requires WOLFSSL_EXPERIMENTAL at this time.")
622+
endif()
623+
if(WOLFSSL_KYBER)
624+
message(FATAL_ERROR "Error: WOLFSSL_KYBER requires WOLFSSL_EXPERIMENTAL at this time.")
552625
endif()
553626
endif()
554627

@@ -565,6 +638,9 @@ endif()
565638
# - Atomic user record layer
566639
# - Public key callbacks
567640
# - Microchip/Atmel CryptoAuthLib
641+
# - XMSS
642+
# - LMS
643+
# - dual-certs
568644

569645
# AES-CBC
570646
add_option("WOLFSSL_AESCBC"

cmake/functions.cmake

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -941,3 +941,73 @@ function(add_to_options_file DEFINITIONS OPTION_FILE)
941941
endif()
942942
endforeach()
943943
endfunction()
944+
945+
# Function: set_wolfssl_definitions
946+
# Parameter: SEARCH_VALUE The string to search for. (e.g. "WOLFSSL_SHA3")
947+
# Returns: RESULT
948+
#
949+
# Searches WOLFSSL_DEFINITIONS for SEARCH_VALUE
950+
# Returns RESULT = 1 (true) if the search value is found
951+
#
952+
# Ensures setting is only added once and prints status messages.
953+
#
954+
# Also sets a parent (global in cmake file) variable by the same name to 1.
955+
#
956+
# See also get_wolfssl_definitions() for query-only.
957+
#
958+
function(set_wolfssl_definitions SEARCH_VALUE RESULT)
959+
if (${SEARCH_VALUE} STREQUAL "")
960+
message(FATAL_ERROR "Function set_wolfssl_definitions cannot have blank SEARCH_VALUE")
961+
endif()
962+
963+
list(FIND WOLFSSL_DEFINITIONS "${SEARCH_VALUE}" pos)
964+
string(SUBSTRING "${SEARCH_VALUE}" 0 2 PREFIX_VALUE)
965+
966+
if ("${PREFIX_VALUE}" STREQUAL "-D")
967+
message(FATAL_ERROR "Do not specify the -D prefix in set_wolfssl_definitions")
968+
endif()
969+
970+
if(${pos} EQUAL -1)
971+
message(STATUS "${SEARCH_VALUE} not found in WOLFSSL_DEFINITIONS.")
972+
973+
message(STATUS "Enabling ${SEARCH_VALUE}")
974+
list(APPEND WOLFSSL_DEFINITIONS "-D${SEARCH_VALUE}")
975+
set(${SEARCH_VALUE} 1 PARENT_SCOPE)
976+
# override_cache("${SEARCH_VALUE}" "yes") # Need to check that value is settable
977+
set(${RESULT} 1 PARENT_SCOPE)
978+
message(STATUS "Enabling ${SEARCH_VALUE} - success")
979+
980+
else()
981+
message(STATUS "${SEARCH_VALUE} found in WOLFSSL_DEFINITIONS.")
982+
set(${RESULT} 0 PARENT_SCOPE)
983+
endif()
984+
endfunction()
985+
986+
# Function: get_wolfssl_definitions
987+
# Parameter: SEARCH_VALUE The string to search for. (e.g. "WOLFSSL_SHA3")
988+
# Returns: RESULT
989+
#
990+
# Searches WOLFSSL_DEFINITIONS for SEARCH_VALUE
991+
# Returns RESULT = 1 (true) if the search value is found
992+
#
993+
# Unlike set_wolfssl_definitions(), this function only queries the WOLFSSL_DEFINITIONS.
994+
#
995+
function(get_wolfssl_definitions SEARCH_VALUE RESULT)
996+
if (${SEARCH_VALUE} STREQUAL "")
997+
message(FATAL_ERROR "Function get_wolfssl_definitions cannot have blank SEARCH_VALUE")
998+
endif()
999+
1000+
list(FIND WOLFSSL_DEFINITIONS "${SEARCH_VALUE}" pos)
1001+
string(SUBSTRING "${SEARCH_VALUE}" 0 2 PREFIX_VALUE)
1002+
1003+
if ("${PREFIX_VALUE}" STREQUAL "-D")
1004+
message(FATAL_ERROR "Do not specify the -D prefix in get_wolfssl_definitions")
1005+
endif()
1006+
1007+
1008+
if(${pos} EQUAL -1)
1009+
message(STATUS "${SEARCH_VALUE} not found in WOLFSSL_DEFINITIONS.")
1010+
else()
1011+
message(STATUS "${SEARCH_VALUE} found in WOLFSSL_DEFINITIONS.")
1012+
endif()
1013+
endfunction()

0 commit comments

Comments
 (0)