Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ARIA cipher cmake #6600

Merged
merged 14 commits into from
Sep 19, 2023
Merged

ARIA cipher cmake #6600

merged 14 commits into from
Sep 19, 2023

Conversation

gojimmypi
Copy link
Contributor

@gojimmypi gojimmypi commented Jul 12, 2023

Description

This is an initial cmake PR for the MagicCrypto ARIA cipher suite as a supplement to #6400.

Currently the ARIA build automatically includes the MagicCrypto ciphers when the ARIA_DIR environment
variable is defined with a valid path to the directory structure extracted with tar -xvf MagicCrypto.tar.gz.

Reminder: Copy the contents of the MagicCrypto directory into the root of the wolfssl directory. Otherwise this error is observed during ./configure

configure: error: Error including mcapi_error.h. Please put the MagicCrypto library in /mnt/c/test/wolfssl.

To use cmake, the MagicCrypto directory can be either in the wolfSSL tree, or specified with an environment variable: ARIA_DIR.

Note this PR has since been updated to NOT enable ARIA just because an environment variable ARIA_DIR is defined.

Enable ARIA with -DWOLFSSL_ARIA=yes cmake parameter.

Build wolfSSL

For reference only, here is how to build using make

git clone https://github.com/wolfSSL/wolfssl.git
cd wolfssl
# copy MagicCrypto directory into wolfssl or set LD_LIBRARY_PATH:
# export LD_LIBRARY_PATH=/mnt/c/workspace/MagicCrypto/lib
./autogen.sh
./configure --enable-all --enable-aria
make

Run CMake build

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

mkdir -p out
pushd out
cmake .. -DWOLFSSL_ARIA=yes
cmake --build .

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

# or with grep:
./examples/client/client -e | grep -i ARIA

popd

Fixes zd# n/a

Testing

There's a new ARIA CMake test script that checks:

  • No ARIA Environment Variable, ARIA not enabled.
  • No ARIA Environment Variable, ARIA Enabled
  • ARIA Environment Variable with MagicCrypto in local user directory, ARIA not enabled.
  • ARIA Environment Variable with MagicCrypto in local user directory, ARIA Enabled
  • ARIA Environment Variable with MagicCrypto in wolfssl directory, ARIA not enabled
  • ARIA Environment Variable with MagicCrypto in wolfssl, ARIA Enabled
  • ARIA Environment Variable with bad directory, ARIA not enabled.
  • ARIA Environment Variable with bad directory, ARIA Enabled (failure expected here)

Windows Server Testing:

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

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

mkdir -p out
pushd out
cmake .. -DWOLFSSL_ARIA=yes
cmake --build .

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

popd

Linux Server Testing:

# From the root of the wolfSSL repo:

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

mkdir -p out
pushd out
cmake .. -DWOLFSSL_ARIA=yes
cmake --build .

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

Server:

# reminder this is in the CMake `out` directory, NOT the root of wolfssl that is build with regular make.
# we also do NOT need the `export ARIA_DIR` here, as that's only for CMake building.

./examples/server/server -i -x -v 3 -A ./certs/ca-ecc-cert.pem -k ./certs/ecc-key.pem -c ./certs/intermediate/server-chain-ecc.pem -V -l ECDHE-ECDSA-ARIA128-GCM-SHA256

Client:

./examples/client/client -v 3 -l ECDHE-ECDSA-ARIA128-GCM-SHA256 -A ./certs/ca-ecc-cert.pem -k ./certs/ecc-client-key.pem -c ./certs/intermediate/client-chain-ecc.pem -C

Checklist

  • added tests
  • updated/added doxygen
  • updated appropriate READMEs
  • Updated manual and documentation

Copy link
Contributor

@bandi13 bandi13 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's strange to me that you need to modify .C and .H files to get CMake to build with ARIA. Feels like something is not being set right.

examples/server/server.c Outdated Show resolved Hide resolved
README-aria.md Outdated Show resolved Hide resolved
CMakeLists.txt Outdated
if(BUILD_SHARED_LIBS)
# message(STATUS "ARIA Check: SHARED! ${LIB_SOURCES}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably should remove debug code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

CMakeLists.txt Outdated
list(APPEND WOLFSSL_DEFINITIONS
"-DHAVE_PTHREAD"
# "-DHAVE_PTHREAD"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR should possibly be based on the PTHREAD issue being resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is resolved. I will pull the threading correction to a different PR.

CMakeLists.txt Outdated
cmake_minimum_required(VERSION 3.16)
# set(CMAKE_BINARY_DIR "${CMAKE_BINARY_DIR}/build")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove dead code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

CMakeLists.txt Outdated
"no" "yes;no")

if(0)
get_cmake_property(_variableNames VARIABLES)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove debug code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

CMakeLists.txt Outdated Show resolved Hide resolved
CMakeLists.txt Outdated
@@ -1882,6 +1918,9 @@ if (WOLFSSL_CAAM)
list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_CAAM")
endif()

if (WOLFSSL_ARIA)
list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_ARIA")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gut feeling is that this should be HAVE_ARIA instead of WOLFSSL_ARIA.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ooph, good catch!

test-aria.sh Outdated Show resolved Hide resolved
README_cmake_notes.md Outdated Show resolved Hide resolved
README-aria.md Outdated Show resolved Hide resolved
@gojimmypi
Copy link
Contributor Author

I've removed the stray debug info files, added a couple of CMake README files, and put the CMake threading logic change in a separate PR (see #6606).

I've confirmed this now works with Windows CMake (Visual Studio 2022 command prompt). For example the server.exe ends up in out\examples\server\Debug

C:\workspace\wolfssl-gojimmypi-bandi13\out>cmake ..
-- Building for: Visual Studio 17 2022
-- Selecting Windows SDK version 10.0.22000.0 to target Windows 10.0.22621.
-- The C compiler identification is MSVC 19.36.32535.0
-- The ASM compiler identification is MSVC
-- Found assembler: C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/14.36.32532/bin/Hostx64/x64/cl.exe
...etc

A separate issue that may need to be addressed: the Cmake-compiled examples for Windows do not immediately work fresh out of the box.

Trying to run the executable, there's no error message, but nothing happens. This occurs when the wolfSSL dll's are not installed in the system. The current debug environment does not find them in the build directory. If I manually copy them, for example the 4 files created in the \out\debug directory:

         1,158,656 wolfssl.dll
            90,094 wolfssl.exp
           148,848 wolfssl.lib
         2,510,848 wolfssl.pdb

... to each of the respective example output directories: out\examples\client\Debug and out\examples\server\Debug. After this copy, then the Windows examples all work well. Perhaps it would be a good idea for CMake to copy them?

@gojimmypi
Copy link
Contributor Author

As noted in #6606 (comment) there may be a known problem in master unrelated to this PR. I've reverted the WOLFSSL_SINGLE_THREADED change here and squashed the commits.

The result is that all of the examples do not compile successfully with CMake in Windows for the ARIA ciphers.

The test client and server do compile successfully with CMake, in Windows and Linux, with and without the ARIA ciphers.

@gojimmypi gojimmypi marked this pull request as ready for review July 13, 2023 01:03
@gojimmypi gojimmypi requested a review from dgarske July 13, 2023 01:03
@gojimmypi gojimmypi requested review from wolfSSL-Bot and removed request for dgarske August 15, 2023 19:15
@gojimmypi gojimmypi requested review from dgarske and removed request for wolfSSL-Bot August 15, 2023 21:16
@JacobBarthelmeh
Copy link
Contributor

Please check the additional includes in other example files. For example client.c.

@gojimmypi
Copy link
Contributor Author

ok, I've removed all references of the ARIA #include that I added, retested everything, resync from upstream & pushed changes along with squash.

Please let me know if you see anything else that can be improved.

Copy link
Contributor

@dgarske dgarske left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works as described. Just a few minor documentation fixes needed.

@@ -110,6 +110,55 @@

To build with debugging use: `cmake .. -DCMAKE_BUILD_TYPE=Debug`.

In the simplest form:

# create a root directory for wolfssl repo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps not include the ./autogen.sh and ./configure example step for CMake?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yes, good. I removed those lines from the docs.

cmake/README.md Outdated

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix. No longer README_cmake.md.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated that to instead reference the root INSTALL document.

@gojimmypi
Copy link
Contributor Author

All checks pass. @dgarske let me know if you'd prefer I squash the 14 commits in this PR.

@dgarske dgarske merged commit 5830f92 into wolfSSL:master Sep 19, 2023
95 checks passed
@dgarske
Copy link
Contributor

dgarske commented Sep 19, 2023

All checks pass. @dgarske let me know if you'd prefer I squash the 14 commits in this PR.

I squashed on merge. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants