Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/configs/multi-arch.json
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,15 @@
"CFLAGS=-O2"],
"check": false,
"run": [["env", "QEMU_LD_PREFIX=/usr/arm-linux-gnueabihf", "./wolfcrypt/test/testwolfcrypt"]]},
{"name": "armhf-gcm-intmul-32only", "minutes": 1.5,
"cc": "ccache arm-linux-gnueabihf-gcc",
"comment": "GCM_INT_MUL GHASH with only 32x32->32 multiplies (GCM_IM_32), the M-profile-without-DSP default; the armhf builds above run the default 32x32->64 one (GCM_IM_32W). Streaming and SIV use the same multiply.",
"configure": ["--host=arm-linux-gnueabihf", "--enable-cryptonly",
"--enable-aesgcm=intmul", "--enable-aesgcm-stream", "--enable-aesgcm-siv",
"--disable-examples", "--disable-shared",
"CPPFLAGS=-DGCM_INT_MUL_32_ONLY", "CFLAGS=-O2"],
"check": false,
"run": [["env", "QEMU_LD_PREFIX=/usr/arm-linux-gnueabihf", "./wolfcrypt/test/testwolfcrypt"]]},
{"name": "riscv64-enable-sp-4096", "minutes": 1.5,
"cc": "ccache riscv64-linux-gnu-gcc",
"comment": "--enable-sp=4096 sets WOLFSSL_SP_NO_2048, but the SP assembly 4096-bit code calls the 2048-bit functions, so settings.h has to undo it.",
Expand Down
21 changes: 21 additions & 0 deletions .wolfssl_known_macro_extras
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ AES_CR_CPHASE_Msk
AES_CR_GCMPH_Msk
AES_CR_NPBLB_Msk
AES_GCM_GMULT_NCT
AES_GCM_GMULT_NO_CACHE_RESIST
AES_ICR_CCF
AES_ISR_CCF
AES_SR_CCF
Expand Down Expand Up @@ -362,6 +363,7 @@ FSL_FEATURE_SOC_MMCAU_COUNT
FSL_FEATURE_SOC_RNG_COUNT
FSL_FEATURE_SOC_TRNG_COUNT
FUSION_RTOS
GCM_INT_MUL_32_ONLY
GENERATE_MACHINE_PARSEABLE_REPORT
GE_P3_TOBYTES_IMPL
GOAHEAD_WS
Expand Down Expand Up @@ -1326,6 +1328,7 @@ XSECURE_CACHE_DISABLE
XYIELD
_ABI64
_ABIO64
_ARCH_PPC
_ARCH_PPC64
_ARCH_PWR8
_CALL_ELF
Expand Down Expand Up @@ -1369,9 +1372,17 @@ __ARCH_STRNCPY_NO_REDIRECT
__ARCH_STRSTR_NO_REDIRECT
__ARMEB__
__ARM_ARCH
__ARM_ARCH_4T__
__ARM_ARCH_4__
__ARM_ARCH_5E__
__ARM_ARCH_5TEJ__
__ARM_ARCH_5TE__
__ARM_ARCH_5T__
__ARM_ARCH_5__
__ARM_ARCH_6M__
__ARM_ARCH_7EM__
__ARM_ARCH_7M__
__ARM_ARCH_8M_BASE__
__ARM_ARCH_PROFILE
__ARM_FEATURE_CRYPTO
__ARM_FEATURE_DSP
Expand Down Expand Up @@ -1434,6 +1445,7 @@ __MICROBLAZE__
__MINGW32__
__MINGW64_VERSION_MAJOR
__MINGW64__
__MSP430__
__MSYS__
__MWERKS__
__NT__
Expand All @@ -1443,6 +1455,7 @@ __PIC__
__PIE__
__POWER9_VECTOR__
__POWERPC__
__PPC64__
__PPC__
__PPU
__QNXNTO__
Expand Down Expand Up @@ -1473,6 +1486,10 @@ __STRICT_ANSI__
__SUNPRO_C
__SUNPRO_CC
__SVR4
__TARGET_ARCH_6S_M
__TARGET_ARCH_6_M
__TARGET_ARCH_7_M
__TARGET_ARCH_ARM
__TASKING__
__TI_COMPILER_VERSION__
__TMS320C2000__
Expand Down Expand Up @@ -1513,13 +1530,17 @@ __linux__
__llvm__
__mips
__mips64
__mips__
__mips_isa_rev
__must_check
__powerpc64__
__powerpc__
__ppc64__
__ppc__
__riscv
__riscv_mul
__riscv_xlen
__riscv_zkt
__s390x__
__sparc
__sparc64__
Expand Down
110 changes: 106 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,7 @@ if(WOLFSSL_HARDEN)
list(APPEND WOLFSSL_DEFINITIONS "-DWC_RSA_BLINDING")
endif()
else()
list(APPEND WOLFSSL_DEFINITIONS "-DWC_NO_HARDEN")
list(APPEND WOLFSSL_DEFINITIONS "-DWC_NO_HARDEN" "-DWC_NO_CACHE_RESISTANT")
Comment thread
Frauschi marked this conversation as resolved.
Resolved
endif()

# AES table cache-line touching: aes.c turns it on for RISC-V by default, and
Expand Down Expand Up @@ -1659,18 +1659,32 @@ endif()
# AES-GCM
add_option("WOLFSSL_AESGCM"
"Enable wolfSSL AES-GCM support (default: enabled)"
"yes" "yes;no;table;small;word32;4bit")
"yes" "yes;no;table;small;word;word32;4bit;intmul")

# leanpsk and leantls don't need gcm
if(WOLFSSL_LEAN_PSK OR (WOLFSSL_LEAN_TLS AND NOT WOLFSSL_TLS13))
override_cache(WOLFSSL_AESGCM "no")
endif()

if(WOLFSSL_AESGCM AND CMAKE_C_BYTE_ORDER STREQUAL "LITTLE_ENDIAN")
override_cache(WOLFSSL_AESGCM "4bit")
# Default GHASH implementation, as configure: FIPS modules before v7 don't
# have GCM_INT_MUL and keep the 4-bit table. Otherwise settings.h's choice is
# recorded in options.h once all options are known (see "Default GHASH
# implementation: when none is chosen" below).
set(_wolfssl_gcm_default_ghash FALSE)
if("${WOLFSSL_AESGCM}" STREQUAL "yes")
if(WOLFSSL_FIPS AND ("${FIPS_VERSION}" MATCHES "^(v1|v2|rand|v5|v6)"))
override_cache(WOLFSSL_AESGCM "4bit")
elseif(NOT WOLFSSL_LOW_RESOURCE)
set(_wolfssl_gcm_default_ghash TRUE)
endif()
endif()

if(WOLFSSL_AESGCM)
if("${WOLFSSL_AESGCM}" STREQUAL "word")
list(APPEND WOLFSSL_DEFINITIONS "-DGCM_WORD64")
override_cache(WOLFSSL_AESGCM "yes")
endif()

if("${WOLFSSL_AESGCM}" STREQUAL "word32")
list(APPEND WOLFSSL_DEFINITIONS "-DGCM_WORD32")
override_cache(WOLFSSL_AESGCM "yes")
Expand All @@ -1691,6 +1705,18 @@ if(WOLFSSL_AESGCM)
override_cache(WOLFSSL_AESGCM "yes")
endif()

if("${WOLFSSL_AESGCM}" STREQUAL "intmul")
# The Arm assembly GHASH is built on the 4-bit table.
if("${CMAKE_C_FLAGS};${WOLFSSL_DEFINITIONS}" MATCHES
"(^|[ ;])-DWOLFSSL_ARMASM([ ;=]|$)")
message(FATAL_ERROR "WOLFSSL_AESGCM=intmul can't be used with "
"WOLFSSL_ARMASM: the Arm assembly GHASH uses the 4-bit table "
"(WOLFSSL_AESGCM=4bit).")
endif()
list(APPEND WOLFSSL_DEFINITIONS "-DGCM_INT_MUL")
Comment thread
SparkiDev marked this conversation as resolved.
Resolved
override_cache(WOLFSSL_AESGCM "yes")
endif()

list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_AESGCM")
endif()

Expand Down Expand Up @@ -4814,6 +4840,82 @@ if(WOLFSSL_PPC64_ASM AND WOLFSSL_ASM)
list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_PPC64_ASM")
endif()

# Default GHASH implementation: when none is chosen, settings.h picks it from
# the cache-resistance options and the CPU, whose compiler macros (__ARM_ARCH,
# __riscv_zkt, ...) depend on flags like -march, and aes.h picks the
# GCM_INT_MUL multiply variant the same way. Compile them with the library's
# compiler, flags and definitions to get the choices, and record them in
# options.h: the Gcm layout depends on them, so an application built with other
# CPU flags still agrees with the library. As configure does.
if("${WOLFSSL_DEFINITIONS}" MATCHES "(^|;)-DGCM_INT_MUL(;|$)")
set(_wolfssl_gcm_int_mul TRUE)
else()
set(_wolfssl_gcm_int_mul FALSE)
endif()
if((_wolfssl_gcm_default_ghash OR _wolfssl_gcm_int_mul) AND
NOT WOLFSSL_USER_SETTINGS)
include(CMakePushCheckState)
cmake_push_check_state(RESET)
string(TOUPPER "${CMAKE_BUILD_TYPE}" _wolfssl_build_type)
set(CMAKE_REQUIRED_FLAGS "${CMAKE_C_FLAGS_${_wolfssl_build_type}}")
if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
string(APPEND CMAKE_REQUIRED_FLAGS " -Wno-error")
endif()
set(CMAKE_REQUIRED_DEFINITIONS ${WOLFSSL_DEFINITIONS})
set(CMAKE_REQUIRED_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}")
set(CMAKE_REQUIRED_QUIET TRUE)
set(_wolfssl_gcm_ghash "")
if(_wolfssl_gcm_default_ghash)
foreach(_wolfssl_ghash GCM_INT_MUL GCM_SMALL GCM_TABLE_4BIT)
unset(WOLFSSL_GCM_DEFAULT_${_wolfssl_ghash} CACHE)
check_c_source_compiles("
#include <wolfssl/wolfcrypt/settings.h>
#ifndef ${_wolfssl_ghash}
#error not the default GHASH
#endif
int main(void) { return 0; }" WOLFSSL_GCM_DEFAULT_${_wolfssl_ghash})
if(WOLFSSL_GCM_DEFAULT_${_wolfssl_ghash})
set(_wolfssl_gcm_ghash ${_wolfssl_ghash})
break()
endif()
endforeach()
if(_wolfssl_gcm_ghash)
message(STATUS "Default AES-GCM GHASH: ${_wolfssl_gcm_ghash}")
else()
message(STATUS "Default AES-GCM GHASH: not determined, settings.h chooses at build time")
endif()
endif()
# The GCM_INT_MUL multiply variant sizes Gcm too, whether GCM_INT_MUL was
# chosen or is the default.
set(_wolfssl_gcm_im "")
if((_wolfssl_gcm_int_mul OR _wolfssl_gcm_ghash STREQUAL "GCM_INT_MUL") AND
NOT "${WOLFSSL_DEFINITIONS}" MATCHES "(^|;)-DGCM_IM_(64|32W|32)(;|$)")
foreach(_wolfssl_im GCM_IM_64 GCM_IM_32W GCM_IM_32)
unset(WOLFSSL_GCM_VARIANT_${_wolfssl_im} CACHE)
check_c_source_compiles("
#include <wolfssl/wolfcrypt/settings.h>
#include <wolfssl/wolfcrypt/aes.h>
#ifndef ${_wolfssl_im}
#error not the GCM_INT_MUL multiply variant
#endif
int main(void) { return 0; }" WOLFSSL_GCM_VARIANT_${_wolfssl_im})
if(WOLFSSL_GCM_VARIANT_${_wolfssl_im})
set(_wolfssl_gcm_im ${_wolfssl_im})
break()
endif()
endforeach()
if(_wolfssl_gcm_im)
message(STATUS "GCM_INT_MUL multiply variant: ${_wolfssl_gcm_im}")
else()
message(STATUS "GCM_INT_MUL multiply variant: not determined, aes.h chooses at build time")
endif()
endif()
cmake_pop_check_state()
foreach(_wolfssl_def ${_wolfssl_gcm_ghash} ${_wolfssl_gcm_im})
list(APPEND WOLFSSL_DEFINITIONS "-D${_wolfssl_def}")
endforeach()
endif()

# All options are declared by this point; report any force_option() that no
# add_option() consumed (would otherwise be a silent no-op).
wolfssl_warn_unconsumed_forces()
Expand Down
14 changes: 14 additions & 0 deletions cmake/options.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ extern "C" {
#cmakedefine GCM_TABLE_4BIT
#undef GCM_WORD32
#cmakedefine GCM_WORD32
#undef GCM_WORD64
#cmakedefine GCM_WORD64
#undef GCM_INT_MUL
#cmakedefine GCM_INT_MUL
#undef GCM_INT_MUL_32_ONLY
#cmakedefine GCM_INT_MUL_32_ONLY
#undef GCM_IM_64
#cmakedefine GCM_IM_64
#undef GCM_IM_32W
#cmakedefine GCM_IM_32W
#undef GCM_IM_32
#cmakedefine GCM_IM_32
#undef HAVE___UINT128_T
#cmakedefine HAVE___UINT128_T 1
#undef HAVE_AES_KEYWRAP
Expand Down Expand Up @@ -267,6 +279,8 @@ extern "C" {
#cmakedefine WC_ECC_NONBLOCK
#undef WC_NO_ASYNC_THREADING
#cmakedefine WC_NO_ASYNC_THREADING
#undef WC_NO_CACHE_RESISTANT
#cmakedefine WC_NO_CACHE_RESISTANT
#undef WC_NO_HARDEN
#cmakedefine WC_NO_HARDEN
#undef WC_NO_HASHDRBG
Expand Down
Loading
Loading