Skip to content

Commit

Permalink
ARIA CMake support
Browse files Browse the repository at this point in the history
  • Loading branch information
gojimmypi committed Jul 13, 2023
1 parent 8c012b5 commit a9fd5eb
Show file tree
Hide file tree
Showing 12 changed files with 264 additions and 4 deletions.
60 changes: 60 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,22 @@ if(WOLFSSL_AESCTR AND NOT WOLFSSL_FORTRESS)
"-DWOLFSSL_AES_DIRECT")
endif()

# if we find an ARIA_DIR turn on ARIA support
if ("$ENV{ARIA_DIR}" STREQUAL "")
set(HAVE_ARIA 0)
set(WOLFSSL_ARIA 0)
else()
message(STATUS "Found ARIA_DIR = $ENV{ARIA_DIR}")
message(STATUS "Setting HAVE_ARIA, WOLFSSL_ARIA")
set(HAVE_ARIA 1)
set(WOLFSSL_ARIA 1)
endif()

# ARIA
add_option("WOLFSSL_ARIA"
"Enable wolfSSL ARIA support (default: disabled)"
"no" "yes;no")

# AES-CCM
add_option("WOLFSSL_AESCCM"
"Enable wolfSSL AES-CCM support (default: disabled)"
Expand Down Expand Up @@ -1882,6 +1898,9 @@ if (WOLFSSL_CAAM)
list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_CAAM")
endif()

if (WOLFSSL_ARIA)
list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_ARIA")
endif()

# Generates the BUILD_* flags. These control what source files are included in
# the library. A series of AM_CONDITIONALs handle this in configure.ac.
Expand Down Expand Up @@ -2015,13 +2034,45 @@ set(LIB_SOURCES "")
# in the *.am files.
generate_lib_src_list("${LIB_SOURCES}")
if(BUILD_SHARED_LIBS)
message(STATUS "BUILD_SHARED_LIBS enabled: ${LIB_SOURCES}")
add_library(wolfssl SHARED ${LIB_SOURCES})
else()
message(STATUS "Static Libs: ${LIB_SOURCES}")
add_library(wolfssl STATIC ${LIB_SOURCES})
endif()

add_library(wolfssl::wolfssl ALIAS wolfssl)

if(WOLFSSL_ARIA)
find_package(ARIA)

if (ARIA_FOUND)
# message(STATUS "find_package FOUND ARIA")
else()
message(WARNING "WOLFSSL_ARIA is enabled, but find_package did not find ARIA MagicCrypto")
endif()

list(APPEND WOLFSSL_LINK_LIBS "${ARIA_LIB_FILE}")
list(APPEND WOLFSSL_INCLUDE_DIRS "${ARIA_INCLUDE_DIR}")

# there's also a wolfssl port API to include
include_directories("wolfssl/wolfcrypt/port/aria")
add_library(MagicCrypto_lib
${CMAKE_CURRENT_SOURCE_DIR}/wolfcrypt/src/port/aria/aria-crypt.c
${CMAKE_CURRENT_SOURCE_DIR}/wolfcrypt/src/port/aria/aria-cryptocb.c
)

set_target_properties(MagicCrypto_lib PROPERTIES OUTPUT_NAME "MagicCrypto")
target_link_libraries(MagicCrypto_lib wolfssl)
target_compile_options(MagicCrypto_lib PRIVATE "-DHAVE_ARIA")

set(HAVE_ARIA 1)
list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_ARIA")

message("ARIA Check: WOLFSSL_LINK_LIBS = ${WOLFSSL_LINK_LIBS}")
message("ARIA Check: WOLFSSL_INCLUDE_DIRS = ${WOLFSSL_INCLUDE_DIRS}")
endif()

set_target_properties(wolfssl
PROPERTIES
SOVERSION ${LIBTOOL_SO_VERSION}
Expand Down Expand Up @@ -2297,6 +2348,15 @@ else()
endif()
endif()

if(NOT BUILD_ARIA)
list(APPEND HEADER_EXCLUDE
"MagicCrypto/include/mcapi.h")
list(APPEND HEADER_EXCLUDE
"MagicCrypto/include/mcapi_error.h")
list(APPEND HEADER_EXCLUDE
"MagicCrypto/include/mcapi_type.h")
endif()

if(NOT BUILD_SP)
list(APPEND HEADER_EXCLUDE
"wolfssl/wolfcrypt/sp.h")
Expand Down
92 changes: 92 additions & 0 deletions README_cmake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# wolfSSL CMake notes

The root of the wolfSSL repo contains a [CMakeLists.txt](./CMakeLists.txt) that can be used to compile the
[examples](examples/README.md).

In the simplest form:

```bash
# create a root directory for wolfssl repo
git clone https://github.com/wolfSSL/wolfssl.git
cd wolfssl
./autogen.sh
./configure --enable-all
```

See the [documentation](https://www.wolfssl.com/documentation/manuals/wolfssl/chapter02.html) for more details
on the various `./configure` options.

## Build CMake Examples for Linux


```bash
# From the root of the wolfSSL repo:

mkdir -p out
pushd out
cmake ..
cmake --build .

# View the available ciphers with:
./examples/client/client -e
popd
```

## Build CMake Examples for Windows

```bash
# From the root of the wolfSSL repo:


mkdir -p out
pushd out
cmake ..
cmake --build .

# View the available ciphers with:
./examples/client/client -e
popd
```

## ARIA cipher suite

The ARIA cipher needs a 3rd party source binary, typically called `MagicCrypto.tar.gz`.

When debugging, these environment variables may be helpful:

#### Enable ARIA Cipher for Linux Examples

```bash
# From the root of the wolfSSL repo:

# set to your path
export ARIA_DIR=/mnt/c/workspace/MagicCrypto

mkdir -p out
pushd out
cmake ..
cmake --build .

# View the available ciphers with:
./examples/client/client -e
popd
```

#### Enable ARIA Cipher for Windows Examples

Unzip your `MagicCrypto.tar.gz`, shown here for `C:\workspace\MagicCrypto`

```bash
# set to your path
export ARIA_DIR=c:\\workspace\\MagicCrypto

mkdir -p out
pushd out
cmake ..
cmake --build .

# View the available ciphers with:
./examples/client/client -e
popd
```

6 changes: 6 additions & 0 deletions cmake/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# wolfSSL CMake

This directory contains some supplementary functions for the [CMakeLists.txt](../CMakeLists.txt) in the root.

See also the [README_cmake.md](../README_cmake.md) file.

20 changes: 16 additions & 4 deletions cmake/functions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ function(generate_build_flags)
set(BUILD_DILITHIUM "yes" PARENT_SCOPE)
set(BUILD_EXT_KYBER "yes" PARENT_SCOPE)
endif()
if(WOLFSSL_ARIA OR WOLFSSL_USER_SETTINGS)
message(STATUS "ARIA functions.cmake found WOLFSSL_ARIA")
# we cannot actually build, as we only have pre-compiled bin
set(BUILD_ARIA "yes" PARENT_SCOPE)
endif()
set(BUILD_INLINE ${WOLFSSL_INLINE} PARENT_SCOPE)
if(WOLFSSL_OCSP OR WOLFSSL_USER_SETTINGS)
set(BUILD_OCSP "yes" PARENT_SCOPE)
Expand Down Expand Up @@ -618,12 +623,19 @@ function(generate_lib_src_list LIB_SOURCES)
wolfcrypt/src/wc_port.c
wolfcrypt/src/error.c)

if(BUILD_ARIA)
list(APPEND LIB_SOURCES
wolfcrypt/src/port/aria/aria-crypt.c
wolfcrypt/src/port/aria/aria-cryptocb.c)
endif()



if(NOT BUILD_FIPS_RAND)
list(APPEND LIB_SOURCES
wolfcrypt/src/wc_encrypt.c
wolfcrypt/src/signature.c
wolfcrypt/src/wolfmath.c)
list(APPEND LIB_SOURCES
wolfcrypt/src/wc_encrypt.c
wolfcrypt/src/signature.c
wolfcrypt/src/wolfmath.c)
endif()

if(BUILD_MEMORY)
Expand Down
2 changes: 2 additions & 0 deletions cmake/include.am
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
EXTRA_DIST += cmake/Config.cmake.in
EXTRA_DIST += cmake/config.in
EXTRA_DIST += cmake/functions.cmake
EXTRA_DIST += cmake/modules/FindARIA.cmake
EXTRA_DIST += cmake/modules/FindOQS.cmake

70 changes: 70 additions & 0 deletions cmake/modules/FindARIA.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Filename: FindARIA.cmake
#
# Usage:
# find_package(ARIA [REQUIRED] [QUIET])
#
# Once done this will define:
# ARIA_FOUND - system has ARIA MAgicCrypt0
# ARIA_INCLUDE_DIR - the include directory containing ARIA
# ARIA_LIBRARY - the path to the libARIA library
#

set(ARIA_INCLUDE_DIR)
set(ARIA_LIB_FILE)

# when debugging cmake, ARIA_DIR environment variable can be manually set here:
# set(ENV{ARIA_DIR} "/mnt/c/workspace/MagicCrypto")
# set(ENV{ARIA_DIR} "c:\\workspace\\MagicCrypto")

# Make sure we have a ARIA_DIR encironment variable with the path to MagicCrypto
if ("$ENV{ARIA_DIR}" STREQUAL "")
message(ERROR "ERROR: FindARIA.cmake missing ARIA_DIR value")
message(STATUS "Please set ARIA_DIR environment variable path to your MagicCrypto")
else()
set(ARIA_INCLUDE_DIR "$ENV{ARIA_DIR}/include")
message(STATUS "FindARIA.cmake found ARIA_INCLUDE_DIR = $ENV{ARIA_DIR}")
# set(ARIA_LIBRARY "$ENV{ARIA_INCLUDE_DIR}/lib")
endif()

# Check that the appropriate files exist
find_path(ARIA_INCLUDE_DIR NAMES "mcapi.h" )

if (EXISTS "${ARIA_INCLUDE_DIR}/mcapi.h")
# message("Found ${ARIA_INCLUDE_DIR}/mcapi.h")
else()
message(ERROR "File does not exist at ${ARIA_INCLUDE_DIR}/mcapi.h")
endif()

if(EXISTS "${ARIA_INCLUDE_DIR}/mcapi_error.h")
# message("Found ${ARIA_INCLUDE_DIR}/mcapi_error.h")
else()
message(ERROR "File does not exist at ${ARIA_INCLUDE_DIR}/mcapi_error.h")
endif()

if(EXISTS "${ARIA_INCLUDE_DIR}/mcapi_type.h")
# message("Found ${ARIA_INCLUDE_DIR}/mcapi_type.h")
else()
message(ERROR "File does not exist at $ARIA_INCLUDE_DIR/mcapi_type.h")
endif()

# find_library(ARIA_LIBRARY
# NAMES "libMagicCrypto.so" # this is not the library name, nor is it "MagicCrypto"
# HINTS "$ENV{ARIA_DIR}/lib/libMagicCrypto.so")

if(EXISTS "$ENV{ARIA_DIR}/lib/libMagicCrypto.so")
set(ARIA_LIBRARY "MagicCrypto")
set(ARIA_LIB_FILE "$ENV{ARIA_DIR}/lib/libMagicCrypto.so")
# message(STATUS "ARIA Check: found libMagicCrypto.so via file exists")
endif()

mark_as_advanced(ARIA_INCLUDE_DIR ARIA_LIBRARY)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(ARIA DEFAULT_MSG ARIA_INCLUDE_DIR ARIA_LIBRARY)

# message(STATUS "")
# message(STATUS "ARIA Check: FindARIA.cmake")
# message(STATUS "ARIA Check: ARIA_INCLUDE_DIR: ${ARIA_INCLUDE_DIR}")
# message(STATUS "ARIA Check: ARIA_LIBRARY: ${ARIA_LIBRARY}")
# message(STATUS "ARIA Check: ARIA_FOUND: ${ARIA_FOUND}")
# message(STATUS "ARIA Check: CMAKE_CURRENT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}")
4 changes: 4 additions & 0 deletions examples/client/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ static const char *wolfsentry_config_path = NULL;
static int devId = INVALID_DEVID;
#endif

#ifdef HAVE_ARIA
#include "aria-crypt.h"
#endif

#define DEFAULT_TIMEOUT_SEC 2
#ifndef MAX_NON_BLOCK_SEC
#define MAX_NON_BLOCK_SEC 10
Expand Down
3 changes: 3 additions & 0 deletions examples/echoclient/echoclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@
static int devId = INVALID_DEVID;
#endif

#ifdef HAVE_ARIA
#include "aria-crypt.h"
#endif

void echoclient_test(void* args)
{
Expand Down
4 changes: 4 additions & 0 deletions examples/echoserver/echoserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@
static int devId = INVALID_DEVID;
#endif

#ifdef HAVE_ARIA
#include "aria-crypt.h"
#endif

#define SVR_COMMAND_SIZE 256

static void SignalReady(void* args, word16 port)
Expand Down
4 changes: 4 additions & 0 deletions examples/server/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ static struct group_info group_id_to_text[] = {
static int devId = INVALID_DEVID;
#endif

#ifdef HAVE_ARIA
#include "aria-crypt.h"
#endif

#define DEFAULT_TIMEOUT_SEC 2

/* Note on using port 0: if the server uses port 0 to bind an ephemeral port
Expand Down
2 changes: 2 additions & 0 deletions wolfcrypt/src/port/aria/aria-crypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ size and a key size of 128, 192, or 256 bits.
#include <wolfssl/wolfcrypt/error-crypt.h>
#include <wolfssl/ssl.h>
#include <wolfssl/wolfcrypt/port/aria/aria-crypt.h>
#include <wolfssl/wolfcrypt/aes.h>
#include <wolfssl/error-ssl.h>

/* return 0 on success or WC_INIT_E on failure */
int wc_AriaInitCrypt(wc_Aria* aria, MC_ALGID algo)
Expand Down
1 change: 1 addition & 0 deletions wolfcrypt/src/port/aria/aria-cryptocb.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ size and a key size of 128, 192, or 256 bits.
#include <wolfssl/ssl.h>
#include <wolfssl/wolfcrypt/asn_public.h>
#include <wolfssl/wolfcrypt/port/aria/aria-cryptocb.h>
#include <wolfssl/wolfcrypt/ecc.h>

int wc_AriaInit(void)
{
Expand Down

0 comments on commit a9fd5eb

Please sign in to comment.