diff --git a/BUILD.md b/BUILD.md
index 159436b19..b3c7a591d 100644
--- a/BUILD.md
+++ b/BUILD.md
@@ -1,11 +1,6 @@
-# Build and Installation
+# AOCL Crypto Library Build
-
-
-
-## Build Instruction for Linux Platform
-
-### Building
+### Build Release Configuration
```shell
$ mkdir build
@@ -20,147 +15,74 @@ ar crsT libnew.a libalcp.a libarch_zen3.a libarch_avx2.a
mv libnew.a libalcp.a
```
-#### Enabling Features of AOCL-Crypto
+#### Enabling Features of AOCL Cryptography
1. [Enable Examples - To compile example/demo code.](#example)
-2. [Enable CPUID - To dispatch correct kernel with CPU identification.](#cpuid)
+2. [Enable AOCL-UTILS - To dispatch correct kernel with CPU identification.](#aocl-utils)
3. [Enable DEBUG Build - To compile code in Debug Mode.](#debug)
4. [Enable Address Sanitizer Support ](#asan)
+5. [Enable Bench - To compile bench code.](#bench)
+6. [Enable Tests - To compile test code](#tests)
-
-
-#### Enable Examples
+#### Enable Examples {#example}
To enable examples, append `-DALCP_ENABLE_EXAMPLES=ON` to the cmake configuration command.
```sh
$ cmake -DALCP_ENABLE_EXAMPLES=ON ../
```
-
+#### Enable AOCL-UTILS {#aocl-utils}
-#### Enable CPUID
-
-To enable cpuid, append `-DAOCL_CPUID_INSTALL_DIR=path/to/aocl/cpuid/source` and `-DENABLE_AOCL_CPUID=ON` to the cmake configuration command.
+To enable aocl utils checks, append `-DAOCL_UTILS_INSTALL_DIR=path/to/aocl/utils/source` and `-DENABLE_AOCL_UTILS=ON` to the cmake configuration command.
```bash
-$ cmake -DENABLE_AOCL_CPUID=ON -DAOCL_CPUID_INSTALL_DIR=path/to/aocl/cpuid/source ../
+$ cmake -DENABLE_AOCL_UTILS=ON -DAOCL_UTILS_INSTALL_DIR=path/to/aocl/utils/source ../
```
-
-
-#### Build Debug Configuration
+#### Build Debug Configuration {#debug}
To build in debug mode, append `-DCMAKE_BUILD_TYPE=DEBUG` to the cmake configuration command.
```sh
$ cmake -DCMAKE_BUILD_TYPE=DEBUG ../
```
-
-#### For Compiling with Address Sanitizer Support
+#### For Compiling with Address Sanitizer Support {#asan}
To enable sanitizers (asan, tsan etc), append `-DALCP_SANITIZE=ON` to the cmake configuration command.
```sh
$ cmake -DALCP_SANITIZE=ON ../
```
-
-
-
-## Build Instruction for Windows Platform
-
-### Following software should be installed prior to build AOCL-CRYPTO
-
-- MS Visual Studio (2019 or greater)
-- Clang 15.0 or above
-- Python 3.7 or greater
-- Cmake 3.21 or greater
-- Git
-
-### Environment Setup:
-
-1. Install visual Studio with workload: *Desktop development with c++*
- - Enable Clang/cl tools(required)
-2. If using LLVM/Clang as external toolset:
- - Install LLVM
- - Install plugin: *llvm2019.vsix* :https://marketplace.visualstudio.com/items?itemName=MarekAniola.mangh-llvm2019
- - Install VS19 version 16.10
-3. Add OPENSSL\bin path to 'PATH' environment variables.
-
-### Windows Build with LLVM/Clang:
-
-Using Powershell:
-
-1. Checkout the latest code.
-2. Open the powershell.exe (as administrator)
-3. Set path to current working directory/cmake_source_directory
-
-### Build
-
-`Run from source directory`
-```
-PS > cmake -A [platform: x86/x64] -B [build_directory] [Enable features] -DCMAKE_BUILD_TYPE=[RELEASE] -G "[generator: Visual Studio 17 2022]" -T [toolset:ClangCl/LLVM]
-```
-Default set values:
-- Generator:'Visual Studio Generator'
-- platform: 'x64' if external LLVM toolset use: -T LLVM (otherwise,ClangCl)
-- Available features: EXAMPLES
-
-`Powershell`
+#### Build Benches {#bench}
-* 1. cmake -A x64 -DCMAKE_BUILD_TYPE=RELEASE -B build -T ClangCl
- `-Build binaries will be written to cmake_source_directory/build`
-* 2. cmake --build .\build --config=release
-
-
-### Enabling features of AOCL-Crypto
-
-1. [Enable Examples - To compile example/demo code.](#win-ex)
-2. [Enable CPUID - To dispatch correct kernel with CPU identification.](#win-cpu)
-3. [Enable DEBUG Build - To compile code in Debug Mode.](#win-debug)
-
-
-#### Steps to found binaries/dll's by setting an environment variable
-
-After build,alcp dll's are not found by feature's *.exe.
-Run the batch file, this .bat file set the environment path required by examples.
-```
-PS> scripts\Set_Env_Path.bat
--Restart the powershell & run any feature .exe from build directory or directly.
+To build benchmarking support with alcp library, append `-DALCP_ENABLE_BENCH=ON` to the cmake configuration command.
+```sh
+$ cmake -DALCP_ENABLE_BENCH=ON ../
```
+Benchmarks will be built into `bench/{algorithm_type}/`
+Please look into **[ README.md ](md_bench_README.html)** from bench.
-
-
-#### Enable Examples Append
-
-```
-PS> cmake -DALCP_ENABLE_EXAMPLES=ON -B build
-PS> cmake --build .\build --config=release
+#### Execute Benchmarks
```
-#### Run Examples
-Run from build directory after setting an environment path.
+$ ./bench/{algorithm_type}/bench_{algorithm_type}
```
-$ .\examples\{algorithm_type}\release\{algorithm_type}\*.exe
-```
-
-
-
-#### Enable CPUID Append
+#### Arguments can be provided in above bench as
```
-PS> cmake -DENABLE_AOCL_CPUID=ON -DAOCL_CPUID_INSTALL_DIR=path/to/aocl/cpuid/source -B build
-PS> cmake --build .\build --config=release
+$ ./bench/digest/bench_digest --benchmark_filter=SHA2__
+$ ./bench/digest/bench_digest --benchmark_filter=SHA2_512_16 (runs SHA256 schemes for 16 block size)
+$ ./bench/digest/bench_digest --benchmark_filter=SHA2 (runs for all SHA2 schemes and block sizes)
```
-
-
-#### For Debug Build
+#### Build Tests (using KAT vectors) {#tests}
+To enable tests, append `-DALCP_ENABLE_TESTS=ON` to the cmake configuration command.
+```sh
+$ cmake -DALCP_ENABLE_TESTS=ON ../
```
-PS> cmake -DCMAKE_BUILD_TYPE=DEBUG -B build
-PS> cmake --build .\build --config=debug
-```
+Test executables can be found inside `tests/{algorithm_type}` directory
-#### NOTES:
+For more details see **[README.md](md_tests_README.html)** from tests.
-1. Run *scripts\Set_Env_Path.bat* to set the path of binaries in environment variable.
-2. To Enable examples:
->cmake -A x64 -DALCP_ENABLE_EXAMPLES=ON -DCMAKE_BUILD_TYPE=RELEASE -B build -T ClangCl
-4. Few non-critical warnings are expected in Windows build with Clang while integrating other libs.
+#### Execute Tests
+ ``` shell
+ $ ./tests/{algorithm_type}/test_{algorithm_type}
+ ```
diff --git a/BUILD_Windows.md b/BUILD_Windows.md
new file mode 100644
index 000000000..843d5c451
--- /dev/null
+++ b/BUILD_Windows.md
@@ -0,0 +1,182 @@
+## AOCL Crypto Library Build for Windows
+
+### Following software should be installed prior to build AOCL CRYPTOGRAPHY
+
+- MS Visual Studio (2019 or greater)
+- Clang 15.0 or above
+- Python 3.7 or greater
+- Cmake 3.21 or greater
+- Git
+
+### Environment Setup:
+
+1. Install visual Studio with workload: *Desktop development with c++*
+ - Enable Clang/cl tools(required) & Address Santizer(if require)
+2. If using LLVM/Clang as external toolset:
+ - Install LLVM
+ - Install plugin: *llvm2019.vsix* :https://marketplace.visualstudio.com/items?itemName=MarekAniola.mangh-llvm2019
+ - Install VS19 version 16.10
+
+### Windows Build with LLVM/Clang:
+
+Using Powershell:
+
+1. Checkout the latest code.
+2. Open the powershell.exe (as administrator)
+3. Set path to current working directory/cmake_source_directory
+
+### Build
+
+`Run from source directory`
+```
+PS > cmake -A [platform: x86/x64] -B [build_directory] [Enable features] -DCMAKE_BUILD_TYPE=[RELEASE] -G "[generator: Visual Studio 17 2022]" -T [toolset:ClangCl/LLVM]
+```
+Default set values:
+- Generator:'Visual Studio Generator'
+- platform: 'x64' if external LLVM toolset use: -T LLVM (otherwise,ClangCl)
+- Available features: EXAMPLES, ADDRESS SANITIZER, TESTS, BENCH
+
+`Powershell`
+```
+* 1. cmake -A x64 -DCMAKE_BUILD_TYPE=RELEASE -B build -T ClangCl
+ `-Build binaries will be written to cmake_source_directory/build`
+* 2. cmake --build .\build --config=release
+```
+
+
+### Enabling features of AOCL Cryptography
+
+1. [Enable Examples - To compile example/demo code.](#win-ex)
+2. [Enable AOCL-UTILS - To dispatch correct kernel with CPU identification.](#win-cpu)
+3. [Enable DEBUG Build - To compile code in Debug Mode.](#win-debug)
+4. [Enable Address Sanitizer Support ](#win-asan)
+5. [Enable Bench - To compile bench code.](#win-bench)
+6. [Enable Tests - To compile test code](#win-tests)
+
+
+#### Steps to find binaries/dll's by setting an environment variable
+
+After build, alcp & gtests dll's are not found by feature's *.exe.
+Run the batch file(Set_Env_Path.bat) to set the environment path required by examples, tests & bench.
+```
+PS> scripts\Set_Env_Path.bat
+-Restart the powershell & run any feature .exe from build directory or directly.
+```
+
+
+#### Enable Examples {#win-ex}
+
+```
+PS> cmake -DALCP_ENABLE_EXAMPLES=ON -B build
+PS> cmake --build .\build --config=release
+```
+#### Run Examples
+Run from build directory after setting an environment path.
+```
+$ .\examples\{algorithm_type}\release\{algorithm_type}\*.exe
+```
+
+
+#### Enable AOCL-UTILS {#win-cpu}
+```
+PS> cmake -DENABLE_AOCL_UTILS=ON -DAOCL_UTILS_INSTALL_DIR=path/to/aocl/utils/source -B build
+PS> cmake --build .\build --config=release
+```
+
+
+#### For Debug Build {#win-debug}
+
+```
+PS> cmake -DCMAKE_BUILD_TYPE=DEBUG -B build
+PS> cmake --build .\build --config=debug
+```
+
+#### For Compiling with Address Sanitizer Support {#win-asan}
+
+```
+PS> cmake -DALCP_SANITIZE=ON -B build
+PS> cmake --build .\build --config=release
+```
+
+ Running from build directory
+PS>cd build
+
+#### To Build Tests (using KAT vectors) {#win-tests}
+```
+$ Append the argument '-DALCP_ENABLE_TESTS=ON'
+PS> cmake -DALCP_ENABLE_TESTS=ON ./
+PS> cmake --build . --config=release
+```
+ This will create test executable:
+```
+ .\build\tests\{algorithm_type}\release\*.exe
+```
+#### To Run Tests:
+ ``` PS
+ $ .\tests\{algorithm_type}\release\test_{algorithm_type}
+ ```
+ For running all tests
+```
+PS> ctest -C release
+```
+
+#### Build Benchmarks {#win-bench}
+
+##### To Build Bench
+
+```
+$ Append the argument -DALCP_ENABLE_BENCH=ON
+PS> cmake -DALCP_ENABLE_BENCH=ON ./
+PS> cmake --build . --config=release
+
+```
+ This will create bench executable into:
+```
+ .\build\bench\{algorithm_type}\{build_type}\*.exe
+```
+##### To Run Bench:
+
+```
+$ .\bench\{algorithm_type}\release\bench_{algorithm_type}
+
+```
+##### Arguments can be provided as:
+
+``` PS
+$ .\bench\{algorithm_type}\release\bench_{algorithm_type} --benchmark_filter=SHA2__
+$ .\bench\{algorithm_type}\release\bench_{algorithm_type} --benchmark_filter=SHA2_512 (runs SHA512 schemes for all block size)
+$ .\bench\{algorithm_type}\release\bench_{algorithm_type} --benchmark_filter=SHA2 (runs for all SHA2 schemes and block sizes)
+```
+
+### Enabling compat libs
+
+1. [Enable OpenSSL - To compare performance .](#win-OSSL)
+2. [Enable IPPCP - To dcompare performance.](#win-IPPCP)
+
+### Build after enabling compat libs
+
+#### Building OpenSSL Compatibility Libs {#win-OSSL}
+
+```
+Enabling openSSL
+
+PS> cmake -DENABLE_TESTS_OPENSSL_API=ON -DOPENSSL_INSTALL_DIR=path/to/openssl ./
+PS> cmake --build build --config=release
+```
+
+#### Building IPP-CP Compatibility Libs {#win-IPPCP}
+
+```
+Enabling IPP-Crypto
+PS> cmake -DENABLE_TESTS_IPP_API=ON -DIPP_INSTALL_DIR=path/to/ipp_crypto ./
+PS> cmake --build build --config=release
+```
+
+#### NOTES:
+```
+1. Use '-o' for OpenSSL & '-i' for IPPCP to run tests & bench for them. And also set bin path of compat libs in PATH variable.
+2. Run *scripts\Set_Env_Path.bat* to set the path of binaries in environment variable.
+3. To Enable examples, tests & bench:
+>cmake -A x64 -DALCP_ENABLE_EXAMPLES=ON -DALCP_ENABLE_TESTS=ON -DALCP_ENABLE_BENCH=ON -DCMAKE_BUILD_TYPE=RELEASE -B build -T ClangCl
+4. Few non-critical warnings are expected in Windows build with Clang while integrating other libs.
+```
\ No newline at end of file
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8ecfa9f60..e3fa98b08 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -27,6 +27,9 @@ include(TestBigEndian)
CMAKE_MINIMUM_REQUIRED(VERSION 3.1)
+set(PROJECT_FULL_NAME "AOCL-Cryptography")
+set(PROJECT_NAME "ALCP")
+
SET(CMAKE_MODULE_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/cmake"
# Add default path
@@ -55,8 +58,9 @@ SET(CMAKE_C_STANDARD_REQUIRED TRUE)
SET(CMAKE_CXX_STANDARD_REQUIRED TRUE)
-IF(NOT CMAKE_BUILD_TYPE)
- SET(CMAKE_BUILD_TYPE RELEASE)
+IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
+ message(STATUS "CMAKE_BUILD_TYPE set to Release by default.")
+ SET(CMAKE_BUILD_TYPE "Release")
ENDIF()
IF(ALCP_ENABLE_CLANG_TIDY)
@@ -72,19 +76,41 @@ SET( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
+# Install Options
+OPTION(ALCP_INSTALL_COMBINED_STATIC "INSTALL ALCP+ALCI COMBINED STATIC LIB" OFF)
+
+IF(NOT DEFINED ENABLE_AOCL_UTILS)
+ MESSAGE(STATUS "Enabling utils as it's needs to be enabled for proper dispatching")
+ENDIF()
+
# All the options which are avaiable with ALCP
# These options can be listed with cmake -LH
OPTION(ALCP_ENABLE_DOCS "ENABLE DOCUMENTATION" OFF)
-OPTION(ALCP_ENABLE_DOXYGEN "ENABLE DOXYGEN DOCUMENTATION GENERATION" OFF)
+OPTION(ALCP_ENABLE_DOXYGEN "ENABLE DOXYGEN DOCUMENTATION GENERATION" ON)
OPTION(ALCP_ENABLE_CLANG_TIDY "ENABLE CLANG TIDY" OFF)
-OPTION(ALCP_ENABLE_EXAMPLES "ENABLE EXAMPLES" OFF)
-set(AOCL_RELEASE_VERSION "4.1.0" CACHE STRING "AOCL RELEASE VERSION")
-OPTION(ENABLE_AOCL_CPUID "ENABLE SUPPORT FOR CPUID BASED DISPATCHING" OFF)
-set(AOCL_CPUID_INSTALL_DIR "" CACHE STRING "AOCL CPUID INSTALLED DIRECTORY")
+OPTION(ALCP_ENABLE_TESTS "ENABLE TESTING" OFF)
+OPTION(ALCP_ENABLE_BENCH "ENABLE BENCHMARKING" OFF)
+OPTION(ALCP_ENABLE_EXAMPLES "ENABLE EXAMPLES" ON)
+set(AOCL_RELEASE_VERSION "4.2" CACHE STRING "AOCL RELEASE VERSION")
+OPTION(ENABLE_AOCL_UTILS "ENABLE AOCL UTILS SUPPORT FOR CPUID BASED DISPATCHING" ON)
+set(AOCL_UTILS_INSTALL_DIR "" CACHE STRING "AOCL UTILS INSTALLED DIRECTORY")
set(AOCL_COMPAT_LIBS "" CACHE STRING "COMPATIBILITY LAYER FOR OPENSSL AND IPP")
-set(OPENSSL_INSTALL_DIR "" CACHE STRING "OPENSSL INSTALLED DIRECTORY COMPAT LIBS")
-set(IPP_INSTALL_DIR "" CACHE STRING "IPPCP INSTALLED DIRECTORY FOR BUILDING COMPAT LIBS")
+IF (NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/tests)
+ SET(ALCP_ENABLE_TESTS OFF)
+ MESSAGE(STATUS "Disabling tests")
+ SET (ALCP_ENABLE_BENCH OFF)
+ MESSAGE(STATUS "Disabling bench")
+endif()
+
+# set proj version
+set(PROJECT_VERSION ${AOCL_RELEASE_VERSION})
+
+# Testing/Benchmarking options
+OPTION(ENABLE_TESTS_IPP_API "ENABLE IPP CALLS IN TESTING AND BENCHMARKING" OFF)
+OPTION(ENABLE_TESTS_OPENSSL_API "ENABLE OPENSSL CALLS IN TESTING AND BENCHMARKING" OFF)
+set(OPENSSL_INSTALL_DIR "" CACHE STRING "OPENSSL INSTALLED DIRECTORY FOR TESTING AND BENCHMARKING")
+set(IPP_INSTALL_DIR "" CACHE STRING "IPPCP INSTALLED DIRECTORY FOR TESTING AND BENCHMARKING")
# misc options
OPTION(ALCP_SANITIZE "COMPILE WITH SANITIZER SUPPORT TO DETECT MEMORY ERRORS" OFF)
@@ -135,21 +161,56 @@ IF (ALCP_ENABLE_EXAMPLES)
MESSAGE(STATUS "Building examples")
ENDIF()
+# building tests
+IF (ALCP_ENABLE_TESTS)
+ ENABLE_TESTING()
+ IF (NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/tests)
+ MESSAGE(FATAL_ERROR "Tests folder not found!")
+ ENDIF()
+ ADD_SUBDIRECTORY(tests)
+ MESSAGE(STATUS "Enabling Tests")
+ENDIF()
+
+# building test bench
+IF (ALCP_ENABLE_BENCH)
+ IF (NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/bench)
+ MESSAGE(FATAL_ERROR "Bench folder not found!")
+ ENDIF()
+ ADD_SUBDIRECTORY(bench)
+ MESSAGE(STATUS "Enabling Benchmarks")
+ENDIF()
+
INSTALL(TARGETS alcp)
+# install compat libs if option is passed
+IF (ENABLE_OPENSSL_COMPAT)
+ INSTALL(TARGETS openssl-compat)
+ENDIF()
+IF (ENABLE_IPP_COMPAT)
+ INSTALL(TARGETS ipp-compat)
+ENDIF()
+
INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/include/alcp
TYPE INCLUDE
)
-IF(UNIX)
-# FIXME: SUFIX Debug will be ignored
-INSTALL(FILES ${CMAKE_BINARY_DIR}/libalcp_static.a DESTINATION lib RENAME libalcp.a)
-ENDIF()
+IF(UNIX AND ALCP_INSTALL_COMBINED_STATIC)
+ # FIXME: SUFIX Debug will be ignored
+ INSTALL(FILES ${CMAKE_BINARY_DIR}/libalcp_static.a DESTINATION lib RENAME libalcp.a)
+ELSE()
+ INSTALL(TARGETS alcp_static)
+ENDIF(UNIX AND ALCP_INSTALL_COMBINED_STATIC)
IF (ALCP_ENABLE_EXAMPLES)
# examples which should be part of release package
FILE(GLOB EXAMPLES_FILES_CIPHER
${CMAKE_CURRENT_SOURCE_DIR}/examples/cipher/*.c)
+
+ #FIXME: temporarily disabling this for coverage build, due to a known runtime issue in these examples
+ IF (CMAKE_BUILD_TYPE STREQUAL "Coverage")
+ list(FILTER EXAMPLES_FILES_CIPHER EXCLUDE REGEX "-speed-")
+ ENDIF()
+
FILE(GLOB EXAMPLES_FILES_DIGEST
${CMAKE_CURRENT_SOURCE_DIR}/examples/digest/*.c)
FILE(GLOB EXAMPLES_FILES_MAC
@@ -162,6 +223,8 @@ IF (ALCP_ENABLE_EXAMPLES)
${CMAKE_CURRENT_SOURCE_DIR}/examples/rsa/*.c)
FILE(GLOB EXAMPLES_FILES_VERSION
${CMAKE_CURRENT_SOURCE_DIR}/examples/version/*.c)
+ FILE(GLOB EXAMPLES_FILES_MISC
+ ${CMAKE_CURRENT_SOURCE_DIR}/examples/misc/*.c)
FILE(GLOB EXAMPLES_README
${CMAKE_CURRENT_SOURCE_DIR}/examples/BUILD_Examples.md)
@@ -180,6 +243,9 @@ IF (ALCP_ENABLE_EXAMPLES)
DESTINATION examples/rng)
INSTALL(FILES ${EXAMPLES_FILES_RSA}
DESTINATION examples/rsa)
+ #TODO: do we need to cover this under install?
+ # INSTALL(FILES ${EXAMPLES_FILES_MISC}
+ # DESTINATION examples/misc)
INSTALL(FILES examples/Makefile
DESTINATION .)
INSTALL(FILES ${EXAMPLES_README}
@@ -215,23 +281,30 @@ FUNCTION (GetVars _prefix)
STRING (REGEX MATCHALL "(^|)${_prefix}[A-Za-z0-9_]*" matches "${_vars}")
FOREACH (var ${matches})
IF (${var})
- MESSAGE("${var}=${${var}}")
+ MESSAGE(STATUS "${var}................${${var}}")
ENDIF()
ENDFOREACH()
ENDFUNCTION()
# print cmake vars
-MESSAGE ("CMAKE version: ${CMAKE_VERSION}")
-MESSAGE ("CMAKE Compiler ID: ${CMAKE_CXX_COMPILER_ID}")
-MESSAGE ("CMAKE C COMPILER: ${CMAKE_C_COMPILER}")
-MESSAGE ("CMAKE CXX COMPILER: ${CMAKE_CXX_COMPILER}")
-MESSAGE ("CMAKE C Compiler version: ${CMAKE_C_COMPILER_VERSION}")
-MESSAGE ("CMAKE CXX Compiler version: ${CMAKE_CXX_COMPILER_VERSION}")
-MESSAGE ("CMAKE CXX Flags Release: ${CMAKE_CXX_FLAGS_RELEASE}")
-MESSAGE ("CMAKE CXX Flags Debug: ${CMAKE_CXX_FLAGS_DEBUG}")
-MESSAGE ("CMAKE CXX Flags: ${CMAKE_CXX_FLAGS}")
-MESSAGE ("CMAKE BUILD TYPE: ${CMAKE_BUILD_TYPE}")
-MESSAGE ("CMAKE CXX STANDARD: ${CMAKE_CXX_STANDARD}")
+MESSAGE (STATUS "PROJECT ............................... " ${PROJECT_FULL_NAME})
+MESSAGE (STATUS "PROJECT VERSION ....................... " ${PROJECT_VERSION})
+MESSAGE (STATUS "CMAKE_BINARY_DIR ...................... " ${CMAKE_BINARY_DIR})
+MESSAGE (STATUS "ALCP_CRYPTO_DIR ....................... " ${CMAKE_CURRENT_SOURCE_DIR})
+MESSAGE (STATUS "CMAKE_GENERATOR ....................... " ${CMAKE_GENERATOR})
+MESSAGE (STATUS "CMAKE_C_COMPILER_ID ................... " ${CMAKE_C_COMPILER_ID})
+MESSAGE (STATUS "CMAKE_CXX_COMPILER_ID ................. " ${CMAKE_CXX_COMPILER_ID})
+MESSAGE (STATUS "CMAKE_INSTALL_PREFIX .................. " ${CMAKE_INSTALL_PREFIX})
+MESSAGE (STATUS "CMAKE version ......................... " ${CMAKE_VERSION})
+MESSAGE (STATUS "CMAKE Compiler ID ..................... " ${CMAKE_CXX_COMPILER_ID})
+MESSAGE (STATUS "CMAKE C COMPILER ...................... " ${CMAKE_C_COMPILER})
+MESSAGE (STATUS "CMAKE CXX COMPILER .................... " ${CMAKE_CXX_COMPILER})
+MESSAGE (STATUS "CMAKE C Compiler version .............. " ${CMAKE_C_COMPILER_VERSION})
+MESSAGE (STATUS "CMAKE CXX Compiler version ............ " ${CMAKE_CXX_COMPILER_VERSION})
+MESSAGE (STATUS "CMAKE CXX Flags Release ............... " ${CMAKE_CXX_FLAGS_RELEASE})
+MESSAGE (STATUS "CMAKE CXX Flags Debug: ................ " ${CMAKE_CXX_FLAGS_DEBUG})
+MESSAGE (STATUS "CMAKE BUILD TYPE ...................... " ${CMAKE_BUILD_TYPE})
+MESSAGE (STATUS "CMAKE CXX STANDARD .................... " ${CMAKE_CXX_STANDARD})
# alcp vars
# FIXME: better to have all the below arguments starting with alcp_*,
@@ -239,5 +312,3 @@ GetVars("ALCP_")
GetVars("AOCL_")
GetVars("IPP_")
GetVars("OPENSSL_")
-
-# FixMe:project name and version to be printed..
diff --git a/Combine_build.md b/Combine_build.md
new file mode 100644
index 000000000..8a6371d0c
--- /dev/null
+++ b/Combine_build.md
@@ -0,0 +1,278 @@
+# Build and Installation
+
+To Build AOCL Cryptography for different platforms please refer to the document related to your platform
+ - [ Linux ](#md_BUILD)
+ - [ Windows ](#md_BUILD_Windows)
+
+## Build Instruction for Linux Platform {#md_BUILD}
+
+### Building
+
+```shell
+$ mkdir build
+$ cd build
+$ cmake ../
+```
+
+#### Extra steps for making STATIC library work
+ To generate a single .a file from all the .a files
+```shell
+ar crsT libnew.a libalcp.a libarch_zen3.a libarch_avx2.a
+mv libnew.a libalcp.a
+```
+
+#### Enabling Features of AOCL Cryptography
+
+1. [Enable Examples - To compile example/demo code.](#example)
+2. [Enable AOCL-UTILS - To dispatch correct kernel with CPU identification.](#aocl-utils)
+3. [Enable DEBUG Build - To compile code in Debug Mode.](#debug)
+4. [Enable Address Sanitizer Support ](#asan)
+5. [Enable Bench - To compile bench code.](#bench)
+6. [Enable Tests - To compile test code](#tests)
+
+
+#### Enable Examples {#example}
+
+To enable examples, append `-DALCP_ENABLE_EXAMPLES=ON` to the cmake configuration command.
+```sh
+$ cmake -DALCP_ENABLE_EXAMPLES=ON ../
+```
+
+#### Enable AOCL UTILS checks {#aocl-utils}
+
+To enable aocl utils support, append `-DAOCL_UTILS_INSTALL_DIR=path/to/aocl/utils/source` and `-DENABLE_AOCL_UTILS=ON` to the cmake configuration command.
+```bash
+$ cmake -DENABLE_AOCL_UTILS=ON -DAOCL_UTILS_INSTALL_DIR=path/to/aocl/utils/source ../
+```
+
+#### Build Debug Configuration {#debug}
+
+To build in debug mode, append `-DCMAKE_BUILD_TYPE=DEBUG` to the cmake configuration command.
+```sh
+$ cmake -DCMAKE_BUILD_TYPE=DEBUG ../
+```
+
+#### For Compiling with Address Sanitizer Support {#asan}
+
+To enable sanitizers (asan, tsan etc), append `-DALCP_SANITIZE=ON` to the cmake configuration command.
+```sh
+$ cmake -DALCP_SANITIZE=ON ../
+```
+
+#### Build Benches {#bench}
+
+To build benchmarking support with alcp library, append `-DALCP_ENABLE_BENCH=ON` to the cmake configuration command.
+```sh
+$ cmake -DALCP_ENABLE_BENCH=ON ../
+```
+Benchmarks will be built into `bench/{algorithm_type}/`
+
+Please look into **[ README.md ](md_bench_README.html)** from bench.
+
+#### Execute Benchmarks
+```
+$ ./bench/{algorithm_type}/bench_{algorithm_type}
+```
+#### Arguments can be provided in above bench as
+```
+$ ./bench/digest/bench_digest --benchmark_filter=SHA2__
+$ ./bench/digest/bench_digest --benchmark_filter=SHA2_512_16 (runs SHA256 schemes for 16 block size)
+$ ./bench/digest/bench_digest --benchmark_filter=SHA2 (runs for all SHA2 schemes and block sizes)
+```
+
+#### Build Tests (using KAT vectors, and cross library tests) {#tests}
+To build tests, append `-DALCP_ENABLE_TESTS=ON` to the cmake configuration command.
+```sh
+$ cmake -DALCP_ENABLE_TESTS=ON ../
+```
+Test executables can be found inside `tests/{algorithm_type}` directory
+
+For more details see **[README.md](md_tests_README.html)** from tests.
+
+#### Execute Tests
+ ``` shell
+ $ ./tests/{algorithm_type}/test_{algorithm_type}
+ ```
+
+
+
+
+## Build Instruction for Windows Platform {#md_BUILD_Windows}
+
+### Following software should be installed prior to build AOCL Cryptography
+
+- MS Visual Studio (2019 or greater)
+- Clang 15.0 or above
+- Python 3.7 or greater
+- Cmake 3.21 or greater
+- Git
+
+### Environment Setup:
+
+1. Install visual Studio with workload: *Desktop development with c++*
+ - Enable Clang/cl tools(required) & Address Santizer(if require)
+2. If using LLVM/Clang as external toolset:
+ - Install LLVM
+ - Install plugin: *llvm2019.vsix* :https://marketplace.visualstudio.com/items?itemName=MarekAniola.mangh-llvm2019
+ - Install VS19 version 16.10
+
+### Windows Build with LLVM/Clang:
+
+Using Powershell:
+
+1. Checkout the latest code.
+2. Open the powershell.exe (as administrator)
+3. Set path to current working directory/cmake_source_directory
+
+### Build
+
+`Run from source directory`
+```
+PS > cmake -A [platform: x86/x64] -B [build_directory] [Enable features] -DCMAKE_BUILD_TYPE=[RELEASE] -G "[generator: Visual Studio 17 2022]" -T [toolset:ClangCl/LLVM]
+```
+Default set values:
+- Generator:'Visual Studio Generator'
+- platform: 'x64' if external LLVM toolset use: -T LLVM (otherwise,ClangCl)
+- Available features: EXAMPLES, ADDRESS SANITIZER, TESTS, BENCH
+
+`Powershell`
+```
+* 1. cmake -A x64 -DCMAKE_BUILD_TYPE=RELEASE -B build -T ClangCl
+ `-Build binaries will be written to cmake_source_directory/build`
+* 2. cmake --build .\build --config=release
+```
+
+### Enabling features of AOCL Cryptography
+
+1. [Enable Examples - To compile example/demo code.](#win-ex)
+2. [Enable AOCL-UTILS - To dispatch correct kernel with CPU identification.](#win-cpu)
+3. [Enable DEBUG Build - To compile code in Debug Mode.](#win-debug)
+4. [Enable Address Sanitizer Support ](#win-asan)
+5. [Enable Bench - To compile bench code.](#win-bench)
+6. [Enable Tests - To compile test code](#win-tests)
+
+
+#### Steps to find binaries/dll's by setting an environment variable
+
+After build, alcp & gtests dll's are not found by feature's *.exe.
+Run the batch file(Set_Env_Path.bat) to set the environment path required by examples, tests & bench.
+```
+PS> scripts\Set_Env_Path.bat
+-Restart the powershell & run any feature .exe from build directory or directly.
+```
+
+
+
+#### Enable Examples {#win-ex}
+
+```
+PS> cmake -DALCP_ENABLE_EXAMPLES=ON -B build
+PS> cmake --build .\build --config=release
+```
+#### Run Examples
+Run from build directory after setting an environment path.
+```
+$ .\examples\{algorithm_type}\release\{algorithm_type}\*.exe
+```
+
+
+#### Enable AOCL-UTILS {#win-cpu}
+```
+PS> cmake -DENABLE_AOCL_UTILS=ON -DAOCL_UTILS_INSTALL_DIR=path/to/aocl/utils/source -B build
+PS> cmake --build .\build --config=release
+```
+
+#### For Debug Build {#win-debug}
+
+```
+PS> cmake -DCMAKE_BUILD_TYPE=DEBUG -B build
+PS> cmake --build .\build --config=debug
+```
+
+#### For Compiling with Address Sanitizer Support {#win-asan}
+
+```
+PS> cmake -DALCP_SANITIZE=ON -B build
+PS> cmake --build .\build --config=release
+```
+
+`Running from build directory
+PS>cd build
+
+#### To Build Tests (using KAT vectors) {#win-tests}
+```
+$ Append the argument '-DALCP_ENABLE_TESTS=ON'
+
+PS> cmake -DALCP_ENABLE_TESTS=ON ./
+PS> cmake --build . --config=release
+```
+ This will create test executable:
+```
+ .\build\tests\{algorithm_type}\release\*.exe
+```
+
+#### To Run Tests:
+ ``` PS
+ $ .\tests\{algorithm_type}\release\test_{algorithm_type}
+ ```
+```For running all tests
+PS> ctest -C release
+```
+
+#### Build Benchmarks {#win-bench}
+
+##### To Build Bench
+```
+$ Append the argument -DALCP_ENABLE_BENCH=ON
+PS> cmake -DALCP_ENABLE_BENCH=ON ./
+PS> cmake --build . --config=release
+```
+ This will create bench executable into:
+```
+ .\build\bench\{algorithm_type}\{build_type}\*.exe
+```
+##### To Run Bench:
+```
+$ .\bench\{algorithm_type}\release\bench_{algorithm_type}
+```
+##### Arguments can be provided as:
+
+``` PS
+$ .\bench\{algorithm_type}\release\bench_{algorithm_type} --benchmark_filter=SHA2__
+$ .\bench\{algorithm_type}\release\bench_{algorithm_type} --benchmark_filter=SHA2_512 (runs SHA512 schemes for all block size)
+$ .\bench\{algorithm_type}\release\bench_{algorithm_type} --benchmark_filter=SHA2 (runs for all SHA2 schemes and block sizes)
+```
+
+### Enabling compat libs
+
+
+1. [Enable OpenSSL - To compare performance .](#win-OSSL)
+2. [Enable IPPCP - To compare performance.](#win-IPPCP)
+
+### Build after enabling compat libs
+
+#### Building OpenSSL Compatibility Libs {#win-OSSL}
+
+
+Enabling openSSL
+```
+PS> cmake -DENABLE_TESTS_OPENSSL_API=ON -DOPENSSL_INSTALL_DIR=path/to/openssl ./
+PS> cmake --build build/ --config=release
+```
+
+#### Building IPP-CP Compatibility Libs {#win-IPPCP}
+
+Enabling IPP-Crypto
+```
+PS> cmake -DENABLE_TESTS_IPP_API=ON -DIPP_INSTALL_DIR=path/to/ipp_crypto ./
+PS> cmake --build build/ --config=release
+```
+
+#### NOTES:
+```
+1. Use '-o' for OpenSSL & '-i' for IPPCP to run tests & bench for them. And also set bin path of compat libs in PATH variable.
+2. Run *scripts\Set_Env_Path.bat* to set the path of binaries in environment variable.
+3. To Enable examples, tests & bench:
+>cmake -A x64 -DALCP_ENABLE_EXAMPLES=ON -DALCP_ENABLE_TESTS=ON -DALCP_ENABLE_BENCH=ON -DCMAKE_BUILD_TYPE=RELEASE -B build -T ClangCl
+4. Few non-critical warnings are expected in Windows build with Clang while integrating other libs.
+```
\ No newline at end of file
diff --git a/README.md b/README.md
index dd32b2be3..ff313c9e5 100644
--- a/README.md
+++ b/README.md
@@ -1,10 +1,10 @@
-# About AOCL Crypto
+# About AOCL-Cryptography
-**AOCL-Crypto** is a library consisting of basic cryptographic functions optimized and tuned for AMD Zen™ based microarchitecture. This library provides a unified solution for Cryptographic routines such as AES (Advanced Encryption Standard) encryption/decryption routines (CFB, CTR, CBC, CCM, GCM, OFB, SIV, XTS), SHA (Secure Hash Algorithms) routines (SHA2, SHA3, SHAKE), Message Authentication Code (CMAC, HMAC), ECDH (Elliptic-curve Diffie–Hellman) and RSA (Rivest, Shamir, and Adleman) key generation functions, etc.
+**AOCL-Cryptography** is a library consisting of basic cryptographic functions optimized and tuned for AMD Zen™ based microarchitecture. This library provides a unified solution for Cryptographic routines such as AES (Advanced Encryption Standard) encryption/decryption routines (CFB, CTR, CBC, CCM, GCM, OFB, SIV, XTS), Chacha20 Stream Cipher encryption/decryption routines, SHA (Secure Hash Algorithms) routines (SHA2, SHA3, SHAKE), Message Authentication Code (CMAC, HMAC, Poly1305), ECDH (Elliptic-curve Diffie–Hellman), RSA (Rivest, Shamir, and Adleman) key generation functions, etc.
AOCL Crypto supports a dynamic dispatcher feature that executes the most optimal function variant implemented using Function Multi-versioning thereby offering a single optimized library portable across different x86 CPU architectures. AOCL Crypto framework is developed in C / C++ for Unix and Windows based systems.
INSTALLATION
- For building and installation, please refer to the file [Build.md](./BUILD.md)
CONTACT
-- AOCL Crypto is developed and maintained by AMD. For support of these libraries and the other tools of AMD Zen Software Studio, see https://www.amd.com/en/developer/aocc/compiler-technical-support.html
+- AOCL-Cryptography is developed and maintained by AMD. For support of these libraries and the other tools of AMD Zen Software Studio, see https://www.amd.com/en/developer/aocc/compiler-technical-support.html
diff --git a/bench/CMakeLists.txt b/bench/CMakeLists.txt
new file mode 100644
index 000000000..6c6fd76e4
--- /dev/null
+++ b/bench/CMakeLists.txt
@@ -0,0 +1,37 @@
+ # Copyright (C) 2022-2023, Advanced Micro Devices. All rights reserved.
+ #
+ # Redistribution and use in source and binary forms, with or without
+ # modification, are permitted provided that the following conditions are met:
+ # 1. Redistributions of source code must retain the above copyright notice,
+ # this list of conditions and the following disclaimer.
+ # 2. Redistributions in binary form must reproduce the above copyright notice,
+ # this list of conditions and the following disclaimer in the documentation
+ # and/or other materials provided with the distribution.
+ # 3. Neither the name of the copyright holder nor the names of its contributors
+ # may be used to endorse or promote products derived from this software
+ # without specific prior written permission.
+ #
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ # POSSIBILITY OF SUCH DAMAGE.
+
+set(BENCHMARK_ENABLE_GTEST_TESTS OFF)
+set(BENCHMARK_ENABLE_TESTING OFF)
+set(BENCHMARK_USE_BUNDLED_GTEST OFF)
+ADD_SUBDIRECTORY(digest)
+ADD_SUBDIRECTORY(cipher)
+ADD_SUBDIRECTORY(cipher_experimental)
+ADD_SUBDIRECTORY(hmac)
+ADD_SUBDIRECTORY(cmac)
+ADD_SUBDIRECTORY(poly1305)
+ADD_SUBDIRECTORY(ecdh)
+ADD_SUBDIRECTORY(rsa)
+
diff --git a/bench/README.md b/bench/README.md
new file mode 100644
index 000000000..74cfe4111
--- /dev/null
+++ b/bench/README.md
@@ -0,0 +1,104 @@
+# ALCP Micro Benchmarks
+
+### Building ALCP with Testing framework
+
+1. `git clone [alcp-crypto git url here]`
+2. `cd alcp-crypto`
+3. `cmake -B build -DALCP_ENABLE_EXAMPLES=ON -DALCP_ENABLE_BENCH=ON -DCMAKE_BUILD_TYPE=Release`
+4. `cmake --build build`
+
+> __Note:__ To include IPP, please define `-DENABLE_TESTS_IPP_API=ON -DIPP_INSTALL_DIR=/path/to/ipp_prefix` in step 3.
+> __Note:__ To include OpenSSL, please define `-DENABLE_TESTS_OPENSSL_API=ON -DOPENSSL_INSTALL_DIR=/path/to/openssl_prefix` in step 3.
+
+
+
+
+### Executing Benches
+
+After building ALCP, there should be binary files of each cryptographic algorithm with respective name in base_path = ./bench/{Respective cryptographic algorithm}
+
+To run tests with verbose mode (prints also success)
+
+1. `$cd aocl-crypto/build`
+2. `$./bench/cipher/bench_cipher`
+3. `$./bench/digest/bench_digest`
+
+#### Selecting benchmarks
+
+Example for selecting only "CBC" benchmarks
+
+ `$./bench/cipher/bench_cipher --benchmark_filter="CBC"`
+
+Example for selecting only "SHA256" benchmarks
+
+ `$./bench/digest/bench_digest --benchmark_filter="SHA2_256"`
+
+Always you can use `--help` to know all the command line arguments which can be given to the executable.
+
+#### Supported Benchmarks
+
+##### Cipher
+
+1. AES_CBC (128,192,256)
+2. AES_CTR (128,192,256)
+3. AES_CFB (128,192,256)
+4. AES_OFB (128,192,256)
+5. AES_GCM_MULTI_INIT (128,192,256)
+6. AES_XTS_MULTI_INIT (128,256)
+7. AES_CCM (128,192,256)
+8. AES_SIV (128,192,256)
+9. CHACHA20 (256)
+
+##### Cipher_experimental
+
+1. AES_GCM (128,192,256)
+2. AES_XTS (128,256)
+
+##### Digest
+
+1. SHA2_224
+2. SHA2_256
+3. SHA2_384
+4. SHA2_512
+5. SHA2_512_224
+6. SHA2_512_256
+7. SHA3_224
+8. SHA3_256
+9. SHA3_384
+10. SHA3_512
+11. SHAKE_128
+12. SHAKE_256
+
+##### MAC
+
+1. CMAC_AES_128
+2. CMAC_AES_192
+3. CMAC_AES_256
+4. HMAC_SHA2_224
+5. HMAC_SHA2_256
+6. HMAC_SHA2_384
+7. HMAC_SHA2_512
+8. HMAC_SHA3_224
+9. HMAC_SHA3_256
+10. HMAC_SHA3_384
+11. HMAC_SHA3_512
+12. POLY1305
+
+##### EC
+
+1. ECDH_x25519_GenPubKey
+2. ECDH_x25519_GenSecretKey
+
+##### RSA
+
+1. RSA_EncryptPubKey
+2. RSA_DecryptPvtKey
+
+#### Using IPP
+
+For using IPP just specify `-i` command line argument.
+
+#### Using OpenSSL
+
+For using OpenSSL just specify `-o` command line argument.
+
diff --git a/bench/cipher/CMakeLists.txt b/bench/cipher/CMakeLists.txt
new file mode 100644
index 000000000..0244db7d3
--- /dev/null
+++ b/bench/cipher/CMakeLists.txt
@@ -0,0 +1,118 @@
+ # Copyright (C) 2022-2023, Advanced Micro Devices. All rights reserved.
+ #
+ # Redistribution and use in source and binary forms, with or without
+ # modification, are permitted provided that the following conditions are met:
+ # 1. Redistributions of source code must retain the above copyright notice,
+ # this list of conditions and the following disclaimer.
+ # 2. Redistributions in binary form must reproduce the above copyright notice,
+ # this list of conditions and the following disclaimer in the documentation
+ # and/or other materials provided with the distribution.
+ # 3. Neither the name of the copyright holder nor the names of its contributors
+ # may be used to endorse or promote products derived from this software
+ # without specific prior written permission.
+ #
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ # POSSIBILITY OF SUCH DAMAGE.
+
+INCLUDE(FetchContent)
+FetchContent_Declare(gtest
+ GIT_REPOSITORY https://github.com/google/googletest.git
+ GIT_TAG release-1.12.1)
+FetchContent_MakeAvailable(gtest)
+FetchContent_Declare(benchmark
+ GIT_REPOSITORY https://github.com/google/benchmark.git
+ GIT_TAG v1.6.1)
+FetchContent_MakeAvailable(benchmark)
+
+FILE(GLOB ALC_COMMON_SRC ${CMAKE_SOURCE_DIR}/tests/common/base/*.cc)
+SET(ALC_BASE_FILES ${ALC_BASE_FILES} ${ALC_COMMON_SRC}
+ ${CMAKE_SOURCE_DIR}/tests/cipher/base/alc_cipher.cc
+ ${CMAKE_SOURCE_DIR}/tests/cipher/base/alc_cipher_aead.cc
+ ${CMAKE_SOURCE_DIR}/tests/cipher/base/cipher.cc)
+SET(LIBS ${LIBS} benchmark alcp)
+SET(EXTRA_INCLUDES "")
+
+IF(ENABLE_TESTS_IPP_API)
+ ADD_COMPILE_OPTIONS("-DUSE_IPP")
+ IF(IPP_INSTALL_DIR)
+ MESSAGE(STATUS "IPP_INSTALL_DIR set, overriding fetch path")
+ ELSE(IPP_INSTALL_DIR)
+ SET(IPP_INSTALL_DIR "${CMAKE_SOURCE_DIR}/external")
+ MESSAGE(STATUS "IPP_INSTALL_DIR not set, defaulting to external")
+ ENDIF(IPP_INSTALL_DIR)
+ # If there is IPP, add IPP source and add IPP liberary
+ SET(EXTRA_SOURCES ${EXTRA_SOURCES}
+ ../../tests/cipher/base/ipp_cipher.cc
+ ../../tests/cipher/base/ipp_cipher_aead.cc)
+ IF(UNIX)
+ IF(EXISTS ${IPP_INSTALL_DIR}/lib/intel64/libippcp.so)
+ SET(LIBS ${LIBS} ${IPP_INSTALL_DIR}/lib/intel64/libippcp.so)
+ ELSE(EXISTS ${IPP_INSTALL_DIR}/lib/intel/libippcp.so)
+ SET(LIBS ${LIBS} ${IPP_INSTALL_DIR}/lib/intel/libippcp.so)
+ ENDIF(EXISTS ${IPP_INSTALL_DIR}/lib/intel64/libippcp.so)
+ ENDIF(UNIX)
+ IF(WIN32)
+ IF(EXISTS ${IPP_INSTALL_DIR}/lib/intel64/ippcp.lib)
+ SET(LIBS ${LIBS} ${IPP_INSTALL_DIR}/lib/intel64/ippcp.lib)
+ ELSEIF(EXISTS ${IPP_INSTALL_DIR}/lib/intel/ippcp.lib)
+ SET(LIBS ${LIBS} ${IPP_INSTALL_DIR}/lib/intel/ippcp.lib)
+ ELSE(EXISTS ${IPP_INSTALL_DIR}/lib/ippcp.lib)
+ SET(LIBS ${LIBS} ${IPP_INSTALL_DIR}/lib/ippcp.lib)
+ ENDIF()
+ ENDIF(WIN32)
+ SET(EXTRA_INCLUDES ${EXTRA_INCLUDES} ${IPP_INSTALL_DIR}/include)
+ENDIF(ENABLE_TESTS_IPP_API)
+
+IF(ENABLE_TESTS_OPENSSL_API)
+ ADD_COMPILE_OPTIONS("-DUSE_OSSL")
+ IF(OPENSSL_INSTALL_DIR)
+ MESSAGE(STATUS "OPENSSL_INSTALL_DIR set, overriding fetch path")
+ ELSE(OPENSSL_INSTALL_DIR)
+ SET(OPENSSL_INSTALL_DIR "${CMAKE_SOURCE_DIR}/external")
+ MESSAGE(STATUS "OPENSSL_INSTALL_DIR not set, defaulting to external")
+ ENDIF(OPENSSL_INSTALL_DIR)
+ # If there is OpenSSL, add OpenSSL source and add OpenSSL liberary
+ SET(EXTRA_SOURCES ${EXTRA_SOURCES}
+ ../../tests/cipher/base/openssl_cipher.cc
+ ../../tests/cipher/base/openssl_cipher_aead.cc)
+ IF(UNIX)
+ IF(EXISTS ${OPENSSL_INSTALL_DIR}/lib64/libcrypto.so)
+ SET(LIBS ${LIBS} ${OPENSSL_INSTALL_DIR}/lib64/libcrypto.so)
+ ELSEIF(EXISTS ${OPENSSL_INSTALL_DIR}/lib/libcrypto.so)
+ SET(LIBS ${LIBS} ${OPENSSL_INSTALL_DIR}/lib/libcrypto.so)
+ ELSE()
+ SET(LIBS ${LIBS} ${OPENSSL_INSTALL_DIR}/lib/x86_64-linux-gnu/libcrypto.so)
+ ENDIF()
+ ENDIF(UNIX)
+ IF(WIN32)
+ IF(EXISTS ${OPENSSL_INSTALL_DIR}/lib/libcrypto.lib)
+ INCLUDE_DIRECTORIES(${OPENSSL_INSTALL_DIR}/include)
+ INCLUDE_DIRECTORIES(${OPENSSL_INSTALL_DIR}/bin)
+ SET(LIBS ${LIBS} ${OPENSSL_INSTALL_DIR}/lib/libcrypto.lib)
+ ENDIF()
+ ENDIF(WIN32)
+ SET(EXTRA_INCLUDES ${EXTRA_INCLUDES} ${OPENSSL_INSTALL_DIR}/include)
+ENDIF(ENABLE_TESTS_OPENSSL_API)
+
+ADD_EXECUTABLE(bench_cipher bench_cipher.cc ${ALC_BASE_FILES} ${EXTRA_SOURCES})
+
+TARGET_INCLUDE_DIRECTORIES(bench_cipher PRIVATE
+ "${CMAKE_SOURCE_DIR}/include"
+ "${CMAKE_SOURCE_DIR}/lib/include"
+ "${CMAKE_CURRENT_SOURCE_DIR}/include"
+ "${CMAKE_SOURCE_DIR}/tests/include"
+ "${CMAKE_SOURCE_DIR}/tests/common/include"
+ ${EXTRA_INCLUDES})
+
+TARGET_COMPILE_OPTIONS(bench_cipher PUBLIC ${ALCP_WARNINGS})
+TARGET_LINK_LIBRARIES(bench_cipher ${LIBS})
+
diff --git a/bench/cipher/bench_cipher.cc b/bench/cipher/bench_cipher.cc
new file mode 100644
index 000000000..2666b8b3a
--- /dev/null
+++ b/bench/cipher/bench_cipher.cc
@@ -0,0 +1,943 @@
+/*
+ * Copyright (C) 2023, Advanced Micro Devices. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "benchmarks_cipher.hh"
+#include "cipher/cipher.hh"
+#include "gbench_base.hh"
+#include
+
+#define MAX_BLOCK_SIZE 32768
+#define MAX_KEY_SIZE 256
+
+// Test blocksizes, append more if needed, size is in bytes
+std::vector blocksizes = { 16, 64, 256, 1024, 8192, 16384, 32768 };
+
+int
+Chacha20Cipher(benchmark::State& state,
+ Uint64 blockSize,
+ encrypt_t enc,
+ _alc_cipher_type cipher_type,
+ alc_cipher_mode_t alcpMode,
+ size_t keylen)
+{
+ // Dynamic allocation better for larger sizes
+ std::vector vec_in(blockSize, 0x01);
+ std::vector vec_out(blockSize, 0x21);
+ Uint8 key[keylen / 8];
+ Uint8 iv[16];
+ alcp::testing::CipherBase* cb;
+
+ alcp::testing::AlcpCipherBase acb = alcp::testing::AlcpCipherBase(
+ cipher_type, alcpMode, iv, 12, key, keylen, nullptr, blockSize);
+
+ cb = &acb;
+#ifdef USE_IPP
+ alcp::testing::IPPCipherBase icb = alcp::testing::IPPCipherBase(
+ cipher_type, alcpMode, iv, 12, key, keylen, nullptr, blockSize);
+ if (useipp) {
+ cb = &icb;
+ }
+#endif
+#ifdef USE_OSSL
+ alcp::testing::OpenSSLCipherBase ocb = alcp::testing::OpenSSLCipherBase(
+ cipher_type, alcpMode, iv, 12, key, keylen, nullptr, blockSize);
+ if (useossl) {
+ cb = &ocb;
+ }
+#endif
+ alcp::testing::alcp_dc_ex_t data;
+ data.m_in = &(vec_in[0]);
+ data.m_inl = blockSize;
+ data.m_out = &(vec_out[0]);
+ data.m_outl = blockSize;
+ data.m_iv = iv;
+ data.m_ivl = 16;
+ for (auto _ : state) {
+ if (enc) {
+ if (!cb->encrypt(data)) {
+ state.SkipWithError("BENCH_ENC_FAILURE");
+ }
+
+ } else {
+ if (!cb->decrypt(data)) {
+ state.SkipWithError("BENCH_DEC_FAILURE");
+ }
+ }
+ }
+ state.counters["Speed(Bytes/s)"] = benchmark::Counter(
+ state.iterations() * blockSize, benchmark::Counter::kIsRate);
+ state.counters["BlockSize(Bytes)"] = blockSize;
+
+ return 0;
+}
+
+int
+AesAeadCipher(benchmark::State& state,
+ const Uint64 blockSize,
+ encrypt_t enc,
+ _alc_cipher_type cipher_type,
+ alc_cipher_mode_t alcpMode,
+ size_t keylen)
+{
+ // Allocate with 512 bit alignment
+ alignas(64) Uint8 vec_in_arr[MAX_BLOCK_SIZE] = {};
+ alignas(64) Uint8 vec_out_arr[MAX_BLOCK_SIZE] = {};
+ alignas(16) Uint8 tagBuffer[16] = {};
+ alignas(16) Uint8 key[MAX_KEY_SIZE / 8] = {};
+ alignas(16) Uint8 iv[16] = {};
+ alignas(16) Uint8 ad[16] = {};
+ alignas(16) Uint8 tag[16] = {};
+ alignas(16) Uint8 tkey[MAX_KEY_SIZE / 8] = {};
+ alcp::testing::CipherAeadBase* cb = nullptr;
+
+ alcp::testing::AlcpCipherAeadBase acb = alcp::testing::AlcpCipherAeadBase(
+ cipher_type, alcpMode, iv, 12, key, keylen, tkey, blockSize);
+
+ cb = &acb;
+#ifdef USE_IPP
+ std::unique_ptr icb;
+ if (useipp) {
+ icb = std::make_unique(
+ cipher_type,
+ alcpMode,
+ iv,
+ 12,
+ reinterpret_cast(key),
+ keylen,
+ reinterpret_cast(tkey),
+ blockSize);
+ cb = icb.get();
+ }
+#endif
+#ifdef USE_OSSL
+ std::unique_ptr ocb;
+ if (useossl) {
+ ocb = std::make_unique(
+ cipher_type,
+ alcpMode,
+ iv,
+ 12,
+ reinterpret_cast(key),
+ keylen,
+ reinterpret_cast(tkey),
+ blockSize);
+ cb = ocb.get();
+ }
+#endif
+ alcp::testing::alcp_dca_ex_t data;
+ data.m_in = vec_in_arr;
+ data.m_inl = blockSize;
+ data.m_out = vec_out_arr;
+ data.m_outl = blockSize;
+ data.m_iv = iv;
+ data.m_ivl = 12;
+ data.m_ad = ad;
+ data.m_adl = 16;
+ data.m_tag = tag;
+ data.m_tagl = 16;
+ data.m_tagBuff = tagBuffer;
+ data.m_tkey = tkey;
+ data.m_tkeyl = 16;
+
+ if (!enc
+ && (alcpMode == ALC_AES_MODE_GCM || alcpMode == ALC_AES_MODE_CCM
+ || alcpMode == ALC_AES_MODE_SIV)) {
+ if (!cb->encrypt(data)) {
+ state.SkipWithError("GCM / CCM : BENCH_ENC_FAILURE");
+ }
+ data.m_in = vec_out_arr;
+ data.m_out = vec_in_arr;
+ // TAG is the IV
+ // cb->init(key, keylen);
+ if (alcpMode == ALC_AES_MODE_SIV)
+ memcpy(iv, data.m_tag, 16);
+ }
+
+ for (auto _ : state) {
+ // For OpenSSL GCM and SIV, Reset needs to be called again since tag
+ // needs to be generated each time
+ if ((useossl
+ && (alcpMode == ALC_AES_MODE_GCM
+ || alcpMode == ALC_AES_MODE_SIV))) {
+ if (!cb->init(key, keylen)) {
+ state.SkipWithError("GCM: BENCH_RESET_FAILURE");
+ }
+ }
+ if (enc) {
+ if (!cb->encrypt(data)) {
+ state.SkipWithError("BENCH_ENC_FAILURE");
+ }
+ } else {
+ if (!cb->decrypt(data)) {
+ state.SkipWithError("BENCH_DEC_FAILURE");
+ }
+ }
+ }
+ state.counters["Speed(Bytes/s)"] = benchmark::Counter(
+ state.iterations() * blockSize, benchmark::Counter::kIsRate);
+ state.counters["BlockSize(Bytes)"] = blockSize;
+
+ return 0;
+}
+
+int
+AesCipher(benchmark::State& state,
+ Uint64 blockSize,
+ encrypt_t enc,
+ _alc_cipher_type cipher_type,
+ alc_cipher_mode_t alcpMode,
+ size_t keylen)
+{
+ // Dynamic allocation better for larger sizes
+ std::vector vec_in(blockSize, 0x01);
+ std::vector vec_out(blockSize, 0x21);
+ std::unique_ptr tagBuffer = std::make_unique(16);
+ Uint8 key[keylen / 8];
+ Uint8 iv[16];
+ Uint8 ad[16] = {};
+ Uint8 tag[16];
+ Uint8 tkey[keylen / 8];
+ alcp::testing::CipherBase* cb;
+
+ alcp::testing::AlcpCipherBase acb = alcp::testing::AlcpCipherBase(
+ cipher_type, alcpMode, iv, 12, key, keylen, tkey, blockSize);
+
+ cb = &acb;
+#ifdef USE_IPP
+ alcp::testing::IPPCipherBase icb = alcp::testing::IPPCipherBase(
+ cipher_type, alcpMode, iv, 12, key, keylen, tkey, blockSize);
+ if (useipp) {
+ cb = &icb;
+ }
+#endif
+#ifdef USE_OSSL
+ alcp::testing::OpenSSLCipherBase ocb = alcp::testing::OpenSSLCipherBase(
+ cipher_type, alcpMode, iv, 12, key, keylen, tkey, blockSize);
+ if (useossl) {
+ cb = &ocb;
+ }
+#endif
+ alcp::testing::alcp_dc_ex_t data;
+ data.m_in = &(vec_in[0]);
+ data.m_inl = blockSize;
+ data.m_out = &(vec_out[0]);
+ data.m_outl = blockSize;
+ data.m_iv = iv;
+ data.m_ivl = 16;
+ data.m_tkey = tkey;
+ data.m_tkeyl = 16;
+ for (auto _ : state) {
+ if (enc) {
+ if (!cb->encrypt(data)) {
+ state.SkipWithError("BENCH_ENC_FAILURE");
+ }
+ } else {
+ if (!cb->decrypt(data)) {
+ state.SkipWithError("BENCH_DEC_FAILURE");
+ }
+ }
+ }
+ state.counters["Speed(Bytes/s)"] = benchmark::Counter(
+ state.iterations() * blockSize, benchmark::Counter::kIsRate);
+ state.counters["BlockSize(Bytes)"] = blockSize;
+
+ return 0;
+}
+
+// 128 bit key size
+
+/**
+ * @brief Encrypt
+ *
+ * @param state Google Bench state
+ */
+
+static void
+BENCH_AES_ENCRYPT_CBC_128(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(AesCipher(state,
+ state.range(0),
+ ENCRYPT,
+ ALC_CIPHER_TYPE_AES,
+ ALC_AES_MODE_CBC,
+ 128));
+}
+
+static void
+BENCH_AES_ENCRYPT_CTR_128(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(AesCipher(state,
+ state.range(0),
+ ENCRYPT,
+ ALC_CIPHER_TYPE_AES,
+ ALC_AES_MODE_CTR,
+ 128));
+}
+
+static void
+BENCH_AES_ENCRYPT_OFB_128(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(AesCipher(state,
+ state.range(0),
+ ENCRYPT,
+ ALC_CIPHER_TYPE_AES,
+ ALC_AES_MODE_OFB,
+ 128));
+}
+
+static void
+BENCH_AES_ENCRYPT_CFB_128(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(AesCipher(state,
+ state.range(0),
+ ENCRYPT,
+ ALC_CIPHER_TYPE_AES,
+ ALC_AES_MODE_CFB,
+ 128));
+}
+
+static void
+BENCH_AES_ENCRYPT_GCM_MULTI_INIT_128(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(AesAeadCipher(state,
+ state.range(0),
+ ENCRYPT,
+ ALC_CIPHER_TYPE_AES,
+ ALC_AES_MODE_GCM,
+ 128));
+}
+
+static void
+BENCH_AES_ENCRYPT_CCM_128(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(AesAeadCipher(state,
+ state.range(0),
+ ENCRYPT,
+ ALC_CIPHER_TYPE_AES,
+ ALC_AES_MODE_CCM,
+ 128));
+}
+
+static void
+BENCH_AES_ENCRYPT_XTS_128(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(AesCipher(state,
+ state.range(0),
+ ENCRYPT,
+ ALC_CIPHER_TYPE_AES,
+ ALC_AES_MODE_XTS,
+ 128));
+}
+
+static void
+BENCH_AES_ENCRYPT_SIV_128(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(AesAeadCipher(state,
+ state.range(0),
+ ENCRYPT,
+ ALC_CIPHER_TYPE_AES,
+ ALC_AES_MODE_SIV,
+ 128));
+}
+
+/**
+ * @brief Decrypt
+ *
+ * @param state Google Bench state
+ */
+
+static void
+BENCH_AES_DECRYPT_CBC_128(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(AesCipher(state,
+ state.range(0),
+ DECRYPT,
+ ALC_CIPHER_TYPE_AES,
+ ALC_AES_MODE_CBC,
+ 128));
+}
+
+static void
+BENCH_AES_DECRYPT_CTR_128(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(AesCipher(state,
+ state.range(0),
+ DECRYPT,
+ ALC_CIPHER_TYPE_AES,
+ ALC_AES_MODE_CTR,
+ 128));
+}
+
+static void
+BENCH_AES_DECRYPT_OFB_128(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(AesCipher(state,
+ state.range(0),
+ DECRYPT,
+ ALC_CIPHER_TYPE_AES,
+ ALC_AES_MODE_OFB,
+ 128));
+}
+
+static void
+BENCH_AES_DECRYPT_CFB_128(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(AesCipher(state,
+ state.range(0),
+ DECRYPT,
+ ALC_CIPHER_TYPE_AES,
+ ALC_AES_MODE_CFB,
+ 128));
+}
+
+static void
+BENCH_AES_DECRYPT_GCM_MULTI_INIT_128(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(AesAeadCipher(state,
+ state.range(0),
+ DECRYPT,
+ ALC_CIPHER_TYPE_AES,
+ ALC_AES_MODE_GCM,
+ 128));
+}
+
+static void
+BENCH_AES_DECRYPT_XTS_128(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(AesCipher(state,
+ state.range(0),
+ DECRYPT,
+ ALC_CIPHER_TYPE_AES,
+ ALC_AES_MODE_XTS,
+ 128));
+}
+
+static void
+BENCH_AES_DECRYPT_CCM_128(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(AesAeadCipher(state,
+ state.range(0),
+ DECRYPT,
+ ALC_CIPHER_TYPE_AES,
+ ALC_AES_MODE_CCM,
+ 128));
+}
+
+static void
+BENCH_AES_DECRYPT_SIV_128(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(AesAeadCipher(state,
+ state.range(0),
+ DECRYPT,
+ ALC_CIPHER_TYPE_AES,
+ ALC_AES_MODE_SIV,
+ 128));
+}
+// END 128 bit key size
+
+// 192 bit key size
+
+/**
+ * @brief Encrypt
+ *
+ * @param state Google Bench state
+ */
+
+static void
+BENCH_AES_ENCRYPT_CBC_192(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(AesCipher(state,
+ state.range(0),
+ ENCRYPT,
+ ALC_CIPHER_TYPE_AES,
+ ALC_AES_MODE_CBC,
+ 192));
+}
+
+static void
+BENCH_AES_ENCRYPT_CTR_192(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(AesCipher(state,
+ state.range(0),
+ ENCRYPT,
+ ALC_CIPHER_TYPE_AES,
+ ALC_AES_MODE_CTR,
+ 192));
+}
+
+static void
+BENCH_AES_ENCRYPT_OFB_192(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(AesCipher(state,
+ state.range(0),
+ ENCRYPT,
+ ALC_CIPHER_TYPE_AES,
+ ALC_AES_MODE_OFB,
+ 192));
+}
+
+static void
+BENCH_AES_ENCRYPT_CFB_192(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(AesCipher(state,
+ state.range(0),
+ ENCRYPT,
+ ALC_CIPHER_TYPE_AES,
+ ALC_AES_MODE_CFB,
+ 192));
+}
+
+static void
+BENCH_AES_ENCRYPT_GCM_MULTI_INIT_192(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(AesAeadCipher(state,
+ state.range(0),
+ ENCRYPT,
+ ALC_CIPHER_TYPE_AES,
+ ALC_AES_MODE_GCM,
+ 192));
+}
+
+static void
+BENCH_AES_ENCRYPT_CCM_192(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(AesAeadCipher(state,
+ state.range(0),
+ ENCRYPT,
+ ALC_CIPHER_TYPE_AES,
+ ALC_AES_MODE_CCM,
+ 192));
+}
+
+static void
+BENCH_AES_ENCRYPT_SIV_192(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(AesAeadCipher(state,
+ state.range(0),
+ ENCRYPT,
+ ALC_CIPHER_TYPE_AES,
+ ALC_AES_MODE_SIV,
+ 192));
+}
+
+/**
+ * @brief Decrypt
+ *
+ * @param state Google Bench state
+ */
+
+static void
+BENCH_AES_DECRYPT_CBC_192(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(AesCipher(state,
+ state.range(0),
+ DECRYPT,
+ ALC_CIPHER_TYPE_AES,
+ ALC_AES_MODE_CBC,
+ 192));
+}
+
+static void
+BENCH_AES_DECRYPT_CTR_192(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(AesCipher(state,
+ state.range(0),
+ DECRYPT,
+ ALC_CIPHER_TYPE_AES,
+ ALC_AES_MODE_CTR,
+ 192));
+}
+
+static void
+BENCH_AES_DECRYPT_OFB_192(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(AesCipher(state,
+ state.range(0),
+ DECRYPT,
+ ALC_CIPHER_TYPE_AES,
+ ALC_AES_MODE_OFB,
+ 192));
+}
+
+static void
+BENCH_AES_DECRYPT_CFB_192(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(AesCipher(state,
+ state.range(0),
+ DECRYPT,
+ ALC_CIPHER_TYPE_AES,
+ ALC_AES_MODE_CFB,
+ 192));
+}
+
+static void
+BENCH_AES_DECRYPT_GCM_MULTI_INIT_192(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(AesAeadCipher(state,
+ state.range(0),
+ DECRYPT,
+ ALC_CIPHER_TYPE_AES,
+ ALC_AES_MODE_GCM,
+ 192));
+}
+
+static void
+BENCH_AES_DECRYPT_CCM_192(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(AesAeadCipher(state,
+ state.range(0),
+ DECRYPT,
+ ALC_CIPHER_TYPE_AES,
+ ALC_AES_MODE_CCM,
+ 192));
+}
+
+static void
+BENCH_AES_DECRYPT_SIV_192(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(AesAeadCipher(state,
+ state.range(0),
+ DECRYPT,
+ ALC_CIPHER_TYPE_AES,
+ ALC_AES_MODE_SIV,
+ 192));
+}
+
+// END 192 bit keysize
+
+// 256 bit key size
+
+/**
+ * @brief Encrypt
+ *
+ * @param state Google Bench state
+ */
+
+static void
+BENCH_AES_ENCRYPT_CBC_256(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(AesCipher(state,
+ state.range(0),
+ ENCRYPT,
+ ALC_CIPHER_TYPE_AES,
+ ALC_AES_MODE_CBC,
+ 256));
+}
+
+static void
+BENCH_AES_ENCRYPT_CTR_256(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(AesCipher(state,
+ state.range(0),
+ ENCRYPT,
+ ALC_CIPHER_TYPE_AES,
+ ALC_AES_MODE_CTR,
+ 256));
+}
+
+static void
+BENCH_AES_ENCRYPT_OFB_256(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(AesCipher(state,
+ state.range(0),
+ ENCRYPT,
+ ALC_CIPHER_TYPE_AES,
+ ALC_AES_MODE_OFB,
+ 256));
+}
+
+static void
+BENCH_AES_ENCRYPT_CFB_256(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(AesCipher(state,
+ state.range(0),
+ ENCRYPT,
+ ALC_CIPHER_TYPE_AES,
+ ALC_AES_MODE_CFB,
+ 256));
+}
+
+static void
+BENCH_AES_ENCRYPT_GCM_MULTI_INIT_256(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(AesAeadCipher(state,
+ state.range(0),
+ ENCRYPT,
+ ALC_CIPHER_TYPE_AES,
+ ALC_AES_MODE_GCM,
+ 256));
+}
+
+static void
+BENCH_AES_ENCRYPT_CCM_256(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(AesAeadCipher(state,
+ state.range(0),
+ ENCRYPT,
+ ALC_CIPHER_TYPE_AES,
+ ALC_AES_MODE_CCM,
+ 256));
+}
+
+static void
+BENCH_AES_ENCRYPT_XTS_256(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(AesCipher(state,
+ state.range(0),
+ ENCRYPT,
+ ALC_CIPHER_TYPE_AES,
+ ALC_AES_MODE_XTS,
+ 256));
+}
+
+static void
+BENCH_AES_ENCRYPT_SIV_256(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(AesAeadCipher(state,
+ state.range(0),
+ ENCRYPT,
+ ALC_CIPHER_TYPE_AES,
+ ALC_AES_MODE_SIV,
+ 256));
+}
+
+/**
+ * @brief Decrypt
+ *
+ * @param state Google Bench state
+ */
+
+static void
+BENCH_AES_DECRYPT_CBC_256(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(AesCipher(state,
+ state.range(0),
+ DECRYPT,
+ ALC_CIPHER_TYPE_AES,
+ ALC_AES_MODE_CBC,
+ 256));
+}
+
+static void
+BENCH_AES_DECRYPT_CTR_256(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(AesCipher(state,
+ state.range(0),
+ DECRYPT,
+ ALC_CIPHER_TYPE_AES,
+ ALC_AES_MODE_CTR,
+ 256));
+}
+
+static void
+BENCH_AES_DECRYPT_OFB_256(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(AesCipher(state,
+ state.range(0),
+ DECRYPT,
+ ALC_CIPHER_TYPE_AES,
+ ALC_AES_MODE_OFB,
+ 256));
+}
+
+static void
+BENCH_AES_DECRYPT_CFB_256(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(AesCipher(state,
+ state.range(0),
+ DECRYPT,
+ ALC_CIPHER_TYPE_AES,
+ ALC_AES_MODE_CFB,
+ 256));
+}
+
+static void
+BENCH_AES_DECRYPT_GCM_MULTI_INIT_256(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(AesAeadCipher(state,
+ state.range(0),
+ DECRYPT,
+ ALC_CIPHER_TYPE_AES,
+ ALC_AES_MODE_GCM,
+ 256));
+}
+
+static void
+BENCH_AES_DECRYPT_XTS_256(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(AesCipher(state,
+ state.range(0),
+ DECRYPT,
+ ALC_CIPHER_TYPE_AES,
+ ALC_AES_MODE_XTS,
+ 256));
+}
+
+static void
+BENCH_AES_DECRYPT_CCM_256(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(AesAeadCipher(state,
+ state.range(0),
+ DECRYPT,
+ ALC_CIPHER_TYPE_AES,
+ ALC_AES_MODE_CCM,
+ 256));
+}
+
+static void
+BENCH_AES_DECRYPT_SIV_256(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(AesAeadCipher(state,
+ state.range(0),
+ ENCRYPT,
+ ALC_CIPHER_TYPE_AES,
+ ALC_AES_MODE_SIV,
+ 256));
+}
+// END 256 bit keysize
+
+/* non AES ciphers */
+static void
+BENCH_CHACHA20_ENCRYPT_256(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(Chacha20Cipher(state,
+ state.range(0),
+ ENCRYPT,
+ ALC_CIPHER_TYPE_CHACHA20,
+ ALC_AES_MODE_NONE,
+ 256));
+}
+static void
+BENCH_CHACHA20_DECRYPT_256(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(Chacha20Cipher(state,
+ state.range(0),
+ DECRYPT,
+ ALC_CIPHER_TYPE_CHACHA20,
+ ALC_AES_MODE_NONE,
+ 256));
+}
+
+int
+AddBenchmarks()
+{
+ /* IPPCP doesnt have Chacha20 stream cipher variant yet */
+ if (!useipp) {
+ BENCHMARK(BENCH_CHACHA20_ENCRYPT_256)->ArgsProduct({ blocksizes });
+ BENCHMARK(BENCH_CHACHA20_DECRYPT_256)->ArgsProduct({ blocksizes });
+ }
+ BENCHMARK(BENCH_AES_ENCRYPT_CBC_128)->ArgsProduct({ blocksizes });
+ BENCHMARK(BENCH_AES_ENCRYPT_CTR_128)->ArgsProduct({ blocksizes });
+ BENCHMARK(BENCH_AES_ENCRYPT_OFB_128)->ArgsProduct({ blocksizes });
+ BENCHMARK(BENCH_AES_ENCRYPT_CFB_128)->ArgsProduct({ blocksizes });
+
+ BENCHMARK(BENCH_AES_DECRYPT_CBC_128)->ArgsProduct({ blocksizes });
+ BENCHMARK(BENCH_AES_DECRYPT_CTR_128)->ArgsProduct({ blocksizes });
+ BENCHMARK(BENCH_AES_DECRYPT_OFB_128)->ArgsProduct({ blocksizes });
+ BENCHMARK(BENCH_AES_DECRYPT_CFB_128)->ArgsProduct({ blocksizes });
+
+ BENCHMARK(BENCH_AES_ENCRYPT_CBC_192)->ArgsProduct({ blocksizes });
+ BENCHMARK(BENCH_AES_ENCRYPT_CTR_192)->ArgsProduct({ blocksizes });
+ BENCHMARK(BENCH_AES_ENCRYPT_OFB_192)->ArgsProduct({ blocksizes });
+ BENCHMARK(BENCH_AES_ENCRYPT_CFB_192)->ArgsProduct({ blocksizes });
+
+ BENCHMARK(BENCH_AES_DECRYPT_CBC_192)->ArgsProduct({ blocksizes });
+ BENCHMARK(BENCH_AES_DECRYPT_CTR_192)->ArgsProduct({ blocksizes });
+ BENCHMARK(BENCH_AES_DECRYPT_OFB_192)->ArgsProduct({ blocksizes });
+ BENCHMARK(BENCH_AES_DECRYPT_CFB_192)->ArgsProduct({ blocksizes });
+
+ BENCHMARK(BENCH_AES_ENCRYPT_CBC_256)->ArgsProduct({ blocksizes });
+ BENCHMARK(BENCH_AES_ENCRYPT_CTR_256)->ArgsProduct({ blocksizes });
+ BENCHMARK(BENCH_AES_ENCRYPT_OFB_256)->ArgsProduct({ blocksizes });
+ BENCHMARK(BENCH_AES_ENCRYPT_CFB_256)->ArgsProduct({ blocksizes });
+
+ BENCHMARK(BENCH_AES_DECRYPT_CBC_256)->ArgsProduct({ blocksizes });
+ BENCHMARK(BENCH_AES_DECRYPT_CTR_256)->ArgsProduct({ blocksizes });
+ BENCHMARK(BENCH_AES_DECRYPT_OFB_256)->ArgsProduct({ blocksizes });
+ BENCHMARK(BENCH_AES_DECRYPT_CFB_256)->ArgsProduct({ blocksizes });
+
+ BENCHMARK(BENCH_AES_ENCRYPT_XTS_128)->ArgsProduct({ blocksizes });
+ BENCHMARK(BENCH_AES_DECRYPT_XTS_128)->ArgsProduct({ blocksizes });
+ BENCHMARK(BENCH_AES_ENCRYPT_XTS_256)->ArgsProduct({ blocksizes });
+ BENCHMARK(BENCH_AES_DECRYPT_XTS_256)->ArgsProduct({ blocksizes });
+
+ /* Benchmark of AEAD Ciphers */
+ // GCM Benchmarks
+ BENCHMARK(BENCH_AES_ENCRYPT_GCM_MULTI_INIT_128)
+ ->ArgsProduct({ blocksizes });
+ BENCHMARK(BENCH_AES_DECRYPT_GCM_MULTI_INIT_128)
+ ->ArgsProduct({ blocksizes });
+ BENCHMARK(BENCH_AES_ENCRYPT_GCM_MULTI_INIT_192)
+ ->ArgsProduct({ blocksizes });
+ BENCHMARK(BENCH_AES_DECRYPT_GCM_MULTI_INIT_192)
+ ->ArgsProduct({ blocksizes });
+ BENCHMARK(BENCH_AES_ENCRYPT_GCM_MULTI_INIT_256)
+ ->ArgsProduct({ blocksizes });
+ BENCHMARK(BENCH_AES_DECRYPT_GCM_MULTI_INIT_256)
+ ->ArgsProduct({ blocksizes });
+ // SIV Benchmarks
+ BENCHMARK(BENCH_AES_ENCRYPT_SIV_128)->ArgsProduct({ blocksizes });
+ BENCHMARK(BENCH_AES_DECRYPT_SIV_128)->ArgsProduct({ blocksizes });
+ BENCHMARK(BENCH_AES_ENCRYPT_SIV_192)->ArgsProduct({ blocksizes });
+ BENCHMARK(BENCH_AES_DECRYPT_SIV_192)->ArgsProduct({ blocksizes });
+ BENCHMARK(BENCH_AES_ENCRYPT_SIV_256)->ArgsProduct({ blocksizes });
+ BENCHMARK(BENCH_AES_DECRYPT_SIV_256)->ArgsProduct({ blocksizes });
+ // CCM Benchmarks
+ BENCHMARK(BENCH_AES_ENCRYPT_CCM_128)->ArgsProduct({ blocksizes });
+ BENCHMARK(BENCH_AES_DECRYPT_CCM_128)->ArgsProduct({ blocksizes });
+ BENCHMARK(BENCH_AES_ENCRYPT_CCM_256)->ArgsProduct({ blocksizes });
+ BENCHMARK(BENCH_AES_DECRYPT_CCM_256)->ArgsProduct({ blocksizes });
+ BENCHMARK(BENCH_AES_ENCRYPT_CCM_192)->ArgsProduct({ blocksizes });
+ BENCHMARK(BENCH_AES_DECRYPT_CCM_192)->ArgsProduct({ blocksizes });
+ return 0;
+}
+
+int
+main(int argc, char** argv)
+{
+ parseArgs(&argc, argv);
+#ifndef USE_IPP
+ if (useipp) {
+ alcp::testing::utils::printErrors(
+ "Error IPP not found defaulting to ALCP");
+ }
+#endif
+#ifndef USE_OSSL
+ if (useossl) {
+ alcp::testing::utils::printErrors(
+ "Error OpenSSL not found defaulting to ALCP");
+ }
+#endif
+ AddBenchmarks();
+ ::benchmark::Initialize(&argc, argv);
+ if (::benchmark::ReportUnrecognizedArguments(argc, argv))
+ return 1;
+ ::benchmark::RunSpecifiedBenchmarks();
+
+ return 0;
+}
\ No newline at end of file
diff --git a/bench/cipher/include/benchmarks_cipher.hh b/bench/cipher/include/benchmarks_cipher.hh
new file mode 100644
index 000000000..07f76fb60
--- /dev/null
+++ b/bench/cipher/include/benchmarks_cipher.hh
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2023, Advanced Micro Devices. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+#pragma once
+
+#include "cipher/alc_cipher.hh"
+#include "cipher/alc_cipher_aead.hh"
+#include "cipher/cipher.hh"
+#include
+#include
+#include
+#include
+
+#ifdef USE_IPP
+#include "cipher/ipp_cipher.hh"
+#include "cipher/ipp_cipher_aead.hh"
+#endif
+
+#ifdef USE_OSSL
+#include "cipher/openssl_cipher.hh"
+#include "cipher/openssl_cipher_aead.hh"
+#endif
+
+typedef enum
+{
+ DECRYPT = 0,
+ ENCRYPT = 1,
+
+} encrypt_t;
diff --git a/bench/cipher_experimental/CMakeLists.txt b/bench/cipher_experimental/CMakeLists.txt
new file mode 100644
index 000000000..56e26686f
--- /dev/null
+++ b/bench/cipher_experimental/CMakeLists.txt
@@ -0,0 +1,117 @@
+ # Copyright (C) 2023, Advanced Micro Devices. All rights reserved.
+ #
+ # Redistribution and use in source and binary forms, with or without
+ # modification, are permitted provided that the following conditions are met:
+ # 1. Redistributions of source code must retain the above copyright notice,
+ # this list of conditions and the following disclaimer.
+ # 2. Redistributions in binary form must reproduce the above copyright notice,
+ # this list of conditions and the following disclaimer in the documentation
+ # and/or other materials provided with the distribution.
+ # 3. Neither the name of the copyright holder nor the names of its contributors
+ # may be used to endorse or promote products derived from this software
+ # without specific prior written permission.
+ #
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ # POSSIBILITY OF SUCH DAMAGE.
+
+ INCLUDE(FetchContent)
+ FetchContent_Declare(gtest
+ GIT_REPOSITORY https://github.com/google/googletest.git
+ GIT_TAG release-1.12.1)
+ FetchContent_MakeAvailable(gtest)
+ FetchContent_Declare(benchmark
+ GIT_REPOSITORY https://github.com/google/benchmark.git
+ GIT_TAG v1.6.1)
+ FetchContent_MakeAvailable(benchmark)
+
+
+FILE(GLOB COMMON_SRCS ${CMAKE_SOURCE_DIR}/tests/common/base/*.cc)
+FILE(GLOB ALC_CIPHER_FWK_SRCS ${CMAKE_SOURCE_DIR}/tests/cipher_experimental/framework/alc_*.cc)
+SET(LIBS ${LIBS} benchmark alcp)
+
+SET(EXTRA_SOURCES "")
+SET(EXTRA_INCLUDES "")
+
+IF(ENABLE_TESTS_OPENSSL_API)
+ FILE(GLOB OPENSSL_CIPHER_FWK_SRCS ${CMAKE_SOURCE_DIR}/tests/cipher_experimental/framework/openssl_*.cc)
+ ADD_COMPILE_OPTIONS("-DUSE_OSSL")
+ IF(OPENSSL_INSTALL_DIR)
+ MESSAGE(STATUS "OPENSSL_INSTALL_DIR set, overriding fetch path")
+ ELSE(OPENSSL_INSTALL_DIR)
+ SET(OPENSSL_INSTALL_DIR "${CMAKE_SOURCE_DIR}/external")
+ MESSAGE(STATUS "OPENSSL_INSTALL_DIR not set, defaulting to external")
+ ENDIF(OPENSSL_INSTALL_DIR)
+ # If there is OpenSSL, add OpenSSL source and add OpenSSL liberary
+ SET(EXTRA_SOURCES ${EXTRA_SOURCES}
+ ${OPENSSL_CIPHER_FWK_SRCS})
+ IF(UNIX)
+ IF(EXISTS ${OPENSSL_INSTALL_DIR}/lib64/libcrypto.so)
+ SET(LIBS ${LIBS} ${OPENSSL_INSTALL_DIR}/lib64/libcrypto.so)
+ ELSEIF(EXISTS ${OPENSSL_INSTALL_DIR}/lib/libcrypto.so)
+ SET(LIBS ${LIBS} ${OPENSSL_INSTALL_DIR}/lib/libcrypto.so)
+ ELSE()
+ SET(LIBS ${LIBS} ${OPENSSL_INSTALL_DIR}/lib/x86_64-linux-gnu/libcrypto.so)
+ ENDIF()
+ ENDIF(UNIX)
+ IF(WIN32)
+ IF(EXISTS ${OPENSSL_INSTALL_DIR}/lib/libcrypto.lib)
+ INCLUDE_DIRECTORIES(${OPENSSL_INSTALL_DIR}/include)
+ INCLUDE_DIRECTORIES(${OPENSSL_INSTALL_DIR}/bin)
+ SET(LIBS ${LIBS} ${OPENSSL_INSTALL_DIR}/lib/libcrypto.lib)
+ ENDIF()
+ ENDIF(WIN32)
+ SET(EXTRA_INCLUDES ${EXTRA_INCLUDES} ${OPENSSL_INSTALL_DIR}/include)
+ENDIF(ENABLE_TESTS_OPENSSL_API)
+
+IF(ENABLE_TESTS_IPP_API)
+ FILE(GLOB IPP_CIPHER_FWK_SRCS ${CMAKE_SOURCE_DIR}/tests/cipher_experimental/framework/ipp_*.cc)
+ ADD_COMPILE_OPTIONS("-DUSE_IPP")
+ IF(IPP_INSTALL_DIR)
+ MESSAGE(STATUS "IPP_INSTALL_DIR set, overriding fetch path")
+ ELSE(IPP_INSTALL_DIR)
+ SET(IPP_INSTALL_DIR "${CMAKE_SOURCE_DIR}/external")
+ MESSAGE(STATUS "IPP_INSTALL_DIR not set, defaulting to external")
+ ENDIF(IPP_INSTALL_DIR)
+ # If there is IPP, add IPP source and add IPP liberary
+ SET(EXTRA_SOURCES ${EXTRA_SOURCES}
+ ${IPP_CIPHER_FWK_SRCS})
+ IF(UNIX)
+ IF(EXISTS ${IPP_INSTALL_DIR}/lib/intel64/libippcp.so)
+ SET(LIBS ${LIBS} ${IPP_INSTALL_DIR}/lib/intel64/libippcp.so)
+ ELSE(EXISTS ${IPP_INSTALL_DIR}/lib/intel/libippcp.so)
+ SET(LIBS ${LIBS} ${IPP_INSTALL_DIR}/lib/intel/libippcp.so)
+ ENDIF(EXISTS ${IPP_INSTALL_DIR}/lib/intel64/libippcp.so)
+ ENDIF(UNIX)
+ IF(WIN32)
+ IF(EXISTS ${IPP_INSTALL_DIR}/lib/intel64/ippcp.lib)
+ SET(LIBS ${LIBS} ${IPP_INSTALL_DIR}/lib/intel64/ippcp.lib)
+ ELSEIF(EXISTS ${IPP_INSTALL_DIR}/lib/intel/ippcp.lib)
+ SET(LIBS ${LIBS} ${IPP_INSTALL_DIR}/lib/intel/ippcp.lib)
+ ELSE(EXISTS ${IPP_INSTALL_DIR}/lib/ippcp.lib)
+ SET(LIBS ${LIBS} ${IPP_INSTALL_DIR}/lib/ippcp.lib)
+ ENDIF()
+ ENDIF(WIN32)
+ SET(EXTRA_INCLUDES ${EXTRA_INCLUDES} ${IPP_INSTALL_DIR}/include)
+ENDIF(ENABLE_TESTS_IPP_API)
+
+# FIXME: Move into a function
+ADD_EXECUTABLE(bench_cipher_experimental bench_cipher_experimental.cc ${COMMON_SRCS} ${ALC_CIPHER_FWK_SRCS} ${EXTRA_SOURCES})
+
+TARGET_INCLUDE_DIRECTORIES(bench_cipher_experimental PRIVATE
+"${CMAKE_SOURCE_DIR}/include"
+"${CMAKE_SOURCE_DIR}/lib/include"
+"${CMAKE_SOURCE_DIR}/tests/include"
+"${CMAKE_SOURCE_DIR}/tests/common/include"
+${EXTRA_INCLUDES})
+
+TARGET_COMPILE_OPTIONS(bench_cipher_experimental PUBLIC ${ALCP_WARNINGS})
+TARGET_LINK_LIBRARIES(bench_cipher_experimental ${LIBS})
\ No newline at end of file
diff --git a/bench/cipher_experimental/bench_cipher_experimental.cc b/bench/cipher_experimental/bench_cipher_experimental.cc
new file mode 100644
index 000000000..a87cfe1f1
--- /dev/null
+++ b/bench/cipher_experimental/bench_cipher_experimental.cc
@@ -0,0 +1,455 @@
+/*
+ * Copyright (C) 2023, Advanced Micro Devices. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include
+#include
+
+#include "cipher_experimental/alc_cipher_gcm.hh"
+#include "cipher_experimental/alc_cipher_xts.hh"
+#include "cipher_experimental/factory.hh"
+#include "common/experimental/gtest_essentials.hh"
+#include "utils.hh"
+
+namespace alcp::benchmarking::cipher {
+
+using namespace alcp::testing::cipher;
+using alcp::testing::cipher::ITestCipher;
+
+std::vector blocksizes = { 16, 64, 256, 1024, 8192, 16384, 32768 };
+
+template
+int
+BenchCipherExperimental(benchmark::State& state,
+ const Uint64 cBlockSize,
+ std::unique_ptr iTestCipher,
+ Uint32 keylen,
+ alc_test_init_data_t& dataInit,
+ alc_test_update_data_t& dataUpdate,
+ alc_test_finalize_data_t& dataFinalize)
+{
+ if (iTestCipher == nullptr) {
+ state.SkipWithError(
+ "MicroBench: Library is unavailable at compile time");
+ return -1;
+ }
+
+ // Real benchmark begins here
+ bool no_err = true;
+ no_err &= iTestCipher->init(&dataInit);
+ if (no_err == false) {
+ state.SkipWithError("MicroBench: Initialization failed!");
+ }
+
+ // Benchmark hot path
+ for (auto _ : state) {
+ no_err &= iTestCipher->update(&dataUpdate);
+ if (no_err == false) {
+ state.SkipWithError("MicroBench: Update failed!");
+ }
+ }
+
+ // Cleanup
+ no_err &= iTestCipher->finalize(&dataFinalize);
+ if (no_err == false) {
+ state.SkipWithError("MicroBench: Finalize failed!");
+ }
+
+ state.counters["Speed(Bytes/s)"] = benchmark::Counter(
+ state.iterations() * cBlockSize, benchmark::Counter::kIsRate);
+ state.counters["BlockSize(Bytes)"] = cBlockSize;
+ return 0;
+}
+
+using namespace alcp::testing::cipher::gcm;
+
+template
+int
+BenchGcmCipherExperimental(benchmark::State& state,
+ const Uint64 cBlockSize,
+ std::unique_ptr iTestCipher,
+ Uint32 keylen)
+{
+ alignas(64) Uint8 input_text[cBlockSize];
+ alignas(64) Uint8 output_text[cBlockSize];
+ alignas(32) Uint8 key[keylen / 8];
+ alignas(16) Uint8 iv[16];
+ alignas(16) Uint8 ad[16];
+ alignas(16) Uint8 tag[16];
+ // FIXME: Tkey might be needed for XTS
+
+ alc_test_gcm_init_data_t dataInit;
+ dataInit.m_iv = iv;
+ dataInit.m_iv_len = 12;
+ dataInit.m_aad = ad;
+ dataInit.m_aad_len = 16;
+ dataInit.m_key = key;
+ dataInit.m_key_len = keylen / 8;
+
+ alc_test_gcm_update_data_t dataUpdate;
+ dataUpdate.m_iv = iv;
+ dataUpdate.m_iv_len = 12;
+ dataUpdate.m_output = output_text;
+ dataUpdate.m_output_len = cBlockSize;
+ dataUpdate.m_input = input_text;
+ dataUpdate.m_input_len = cBlockSize;
+
+ alc_test_gcm_finalize_data_t dataFinalize;
+ dataFinalize.m_tag_expected = tag;
+ dataFinalize.m_tag_len = 16;
+ dataFinalize.m_tag = tag;
+ dataFinalize.verified = false;
+
+ if constexpr (encryptor == false) { // Decrypt
+ // Create a vaid data for decryption (mainly tag and ct)
+ std::unique_ptr iTestCipher =
+ std::make_unique>();
+ bool no_err = true;
+ no_err &= iTestCipher->init(&dataInit);
+ if (no_err == false) {
+ state.SkipWithError("MicroBench: Initialization failed for decrypt "
+ "ct,tag generation using encrypt");
+ return -1;
+ }
+ no_err &= iTestCipher->update(&dataUpdate);
+ if (no_err == false) {
+ state.SkipWithError("MicroBench: Update failed for decrypt "
+ "ct,tag generation using encrypt");
+ return -1;
+ }
+ // After encrypting, to decrypt output becomes input
+ dataUpdate.m_input = output_text;
+ dataUpdate.m_output = input_text;
+ no_err &= iTestCipher->finalize(&dataFinalize);
+ if (no_err == false) {
+ state.SkipWithError("MicroBench: Finalize failed for decrypt "
+ "ct,tag generation using encrypt");
+ return -1;
+ }
+ }
+
+ return BenchCipherExperimental(state,
+ cBlockSize,
+ std::move(iTestCipher),
+ keylen,
+ dataInit,
+ dataUpdate,
+ dataFinalize);
+}
+
+using namespace alcp::testing::cipher::xts;
+
+template
+int
+BenchXtsCipherExperimental(benchmark::State& state,
+ const Uint64 cBlockSize,
+ std::unique_ptr iTestCipher,
+ Uint32 keylen)
+{
+ alignas(64) Uint8 input_text[cBlockSize];
+ alignas(64) Uint8 output_text[cBlockSize];
+ alignas(32) Uint8 key[keylen / 8 * 2];
+ alignas(16) Uint8 iv[16];
+ alignas(16) Uint8 ad[16];
+ alignas(16) Uint8 tag[16];
+ int blocks = cBlockSize / 16;
+
+ for (int i = 0; i < keylen / 8 * 2; i++) {
+ key[i] = i;
+ }
+
+ // FIXME: Tkey might be needed for XTS
+
+ alc_test_xts_init_data_t dataInit;
+ dataInit.m_iv = iv;
+ dataInit.m_iv_len = 12;
+ dataInit.m_key = key;
+ dataInit.m_key_len = keylen / 8;
+
+ alc_test_xts_update_data_t dataUpdate;
+ dataUpdate.m_iv = iv;
+ dataUpdate.m_iv_len = 12;
+ dataUpdate.m_output = output_text;
+ dataUpdate.m_output_len = cBlockSize;
+ dataUpdate.m_input = input_text;
+ dataUpdate.m_total_input_len = 100000000;
+ dataUpdate.m_input_len = cBlockSize;
+ dataUpdate.m_aes_block_id = 0;
+
+ alc_test_xts_finalize_data_t dataFinalize;
+ dataFinalize.m_out = dataUpdate.m_output;
+ dataFinalize.m_pt_len = dataUpdate.m_input_len;
+
+ if (iTestCipher == nullptr) {
+ state.SkipWithError(
+ "MicroBench: Library is unavailable at compile time");
+ return -1;
+ }
+
+ // Real benchmark begins here
+ bool no_err = true;
+ no_err &= iTestCipher->init(&dataInit);
+ if (no_err == false) {
+ state.SkipWithError("MicroBench: Initialization failed!");
+ }
+
+ // Benchmark hot path
+ for (auto _ : state) {
+ no_err &= iTestCipher->update(&dataUpdate);
+ if (no_err == false) {
+ state.SkipWithError("MicroBench: Update failed!");
+ }
+ dataUpdate.m_aes_block_id += blocks;
+ }
+
+ // Cleanup
+ no_err &= iTestCipher->finalize(&dataFinalize);
+ if (no_err == false) {
+ state.SkipWithError("MicroBench: Finalize failed!");
+ }
+
+ state.counters["Speed(Bytes/s)"] = benchmark::Counter(
+ state.iterations() * cBlockSize, benchmark::Counter::kIsRate);
+ state.counters["BlockSize(Bytes)"] = cBlockSize;
+ return 0;
+}
+
+} // namespace alcp::benchmarking::cipher
+
+using alcp::testing::cipher::LibrarySelect;
+
+using alcp::benchmarking::cipher::BenchGcmCipherExperimental;
+using alcp::testing::cipher::gcm::GcmCipherFactory;
+
+static void
+BENCH_AES_ENCRYPT_GCM_128(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(BenchGcmCipherExperimental(
+ state,
+ state.range(0),
+ std::move(
+ GcmCipherFactory(static_cast(state.range(1)))),
+ 128));
+}
+
+static void
+BENCH_AES_ENCRYPT_GCM_192(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(BenchGcmCipherExperimental(
+ state,
+ state.range(0),
+ std::move(
+ GcmCipherFactory(static_cast(state.range(1)))),
+ 192));
+}
+
+static void
+BENCH_AES_ENCRYPT_GCM_256(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(BenchGcmCipherExperimental(
+ state,
+ state.range(0),
+ std::move(
+ GcmCipherFactory(static_cast(state.range(1)))),
+ 256));
+}
+
+static void
+BENCH_AES_DECRYPT_GCM_128(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(BenchGcmCipherExperimental(
+ state,
+ state.range(0),
+ std::move(
+ GcmCipherFactory(static_cast(state.range(1)))),
+ 128));
+}
+
+static void
+BENCH_AES_DECRYPT_GCM_192(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(BenchGcmCipherExperimental(
+ state,
+ state.range(0),
+ std::move(
+ GcmCipherFactory(static_cast(state.range(1)))),
+ 192));
+}
+
+static void
+BENCH_AES_DECRYPT_GCM_256(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(BenchGcmCipherExperimental(
+ state,
+ state.range(0),
+ std::move(
+ GcmCipherFactory(static_cast(state.range(1)))),
+ 256));
+}
+
+using alcp::benchmarking::cipher::BenchXtsCipherExperimental;
+using alcp::testing::cipher::xts::XtsCipherFactory;
+
+static void
+BENCH_AES_ENCRYPT_XTS_128(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(BenchXtsCipherExperimental(
+ state,
+ state.range(0),
+ std::move(
+ XtsCipherFactory(static_cast(state.range(1)))),
+ 128));
+}
+
+static void
+BENCH_AES_ENCRYPT_XTS_256(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(BenchXtsCipherExperimental(
+ state,
+ state.range(0),
+ std::move(
+ XtsCipherFactory(static_cast(state.range(1)))),
+ 256));
+}
+
+static void
+BENCH_AES_DECRYPT_XTS_128(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(BenchXtsCipherExperimental(
+ state,
+ state.range(0),
+ std::move(XtsCipherFactory(
+ static_cast(state.range(1)))),
+ 128));
+}
+
+static void
+BENCH_AES_DECRYPT_XTS_256(benchmark::State& state)
+{
+ benchmark::DoNotOptimize(BenchXtsCipherExperimental(
+ state,
+ state.range(0),
+ std::move(XtsCipherFactory(
+ static_cast(state.range(1)))),
+ 256));
+}
+
+using alcp::testing::cipher::CipherFactory;
+using alcp::testing::cipher::LibrarySelect;
+using alcp::testing::utils::ArgsMap;
+using alcp::testing::utils::ParamType;
+using alcp::testing::utils::parseArgs;
+using alcp::testing::utils::printErrors;
+int
+main(int argc, char** argv)
+{
+ std::vector testlibs = {};
+
+ ::benchmark::Initialize(&argc, argv);
+
+ ArgsMap argsMap = parseArgs(argc, argv);
+
+ assert(argsMap["USE_OSSL"].paramType == ParamType::TYPE_BOOL);
+ assert(argsMap["USE_IPP"].paramType == ParamType::TYPE_BOOL);
+ assert(argsMap["USE_ALCP"].paramType == ParamType::TYPE_BOOL);
+
+ if (std::get(argsMap["USE_OSSL"].value) == false
+ && std::get(argsMap["USE_IPP"].value) == false
+ && std::get(argsMap["USE_ALCP"].value) == false) {
+#ifdef USE_IPP
+ testlibs.insert(testlibs.begin(),
+ static_cast(LibrarySelect::IPP));
+#endif
+#ifdef USE_OSSL
+ testlibs.insert(testlibs.begin(),
+ static_cast(LibrarySelect::OPENSSL));
+#endif
+ testlibs.insert(testlibs.begin(),
+ static_cast(LibrarySelect::ALCP));
+ } else {
+ if (std::get(argsMap["USE_ALCP"].value) == true) {
+ testlibs.insert(testlibs.begin(),
+ static_cast(LibrarySelect::ALCP));
+ }
+ if (std::get(argsMap["USE_OSSL"].value) == true) {
+#ifdef USE_OSSL
+ testlibs.insert(testlibs.begin(),
+ static_cast(LibrarySelect::OPENSSL));
+#else
+ printErrors("OpenSSL unavailable at compile time!");
+ return -1;
+#endif
+ }
+ if (std::get(argsMap["USE_IPP"].value) == true) {
+#ifdef USE_IPP
+ testlibs.insert(testlibs.begin(),
+ static_cast(LibrarySelect::IPP));
+#else
+ printErrors("IPP unavailable at compile time!");
+ return -1;
+#endif
+ }
+ }
+
+ // GCM
+ BENCHMARK(BENCH_AES_ENCRYPT_GCM_128)
+ ->ArgsProduct({ alcp::benchmarking::cipher::blocksizes, testlibs });
+
+ BENCHMARK(BENCH_AES_ENCRYPT_GCM_192)
+ ->ArgsProduct({ alcp::benchmarking::cipher::blocksizes, testlibs });
+
+ BENCHMARK(BENCH_AES_ENCRYPT_GCM_256)
+ ->ArgsProduct({ alcp::benchmarking::cipher::blocksizes, testlibs });
+
+ BENCHMARK(BENCH_AES_DECRYPT_GCM_128)
+ ->ArgsProduct({ alcp::benchmarking::cipher::blocksizes, testlibs });
+
+ BENCHMARK(BENCH_AES_DECRYPT_GCM_192)
+ ->ArgsProduct({ alcp::benchmarking::cipher::blocksizes, testlibs });
+
+ BENCHMARK(BENCH_AES_DECRYPT_GCM_256)
+ ->ArgsProduct({ alcp::benchmarking::cipher::blocksizes, testlibs });
+
+ // XTS
+ BENCHMARK(BENCH_AES_ENCRYPT_XTS_128)
+ ->ArgsProduct({ alcp::benchmarking::cipher::blocksizes, testlibs });
+
+ BENCHMARK(BENCH_AES_ENCRYPT_XTS_256)
+ ->ArgsProduct({ alcp::benchmarking::cipher::blocksizes, testlibs });
+
+ BENCHMARK(BENCH_AES_DECRYPT_XTS_128)
+ ->ArgsProduct({ alcp::benchmarking::cipher::blocksizes, testlibs });
+
+ BENCHMARK(BENCH_AES_DECRYPT_XTS_256)
+ ->ArgsProduct({ alcp::benchmarking::cipher::blocksizes, testlibs });
+
+ // if (::benchmark::ReportUnrecognizedArguments(argc, argv))
+ // return 1;
+ ::benchmark::RunSpecifiedBenchmarks();
+
+ return 0;
+}
\ No newline at end of file
diff --git a/bench/cmac/CMakeLists.txt b/bench/cmac/CMakeLists.txt
new file mode 100644
index 000000000..5682c1fab
--- /dev/null
+++ b/bench/cmac/CMakeLists.txt
@@ -0,0 +1,114 @@
+ # Copyright (C) 2023, Advanced Micro Devices. All rights reserved.
+ #
+ # Redistribution and use in source and binary forms, with or without
+ # modification, are permitted provided that the following conditions are met:
+ # 1. Redistributions of source code must retain the above copyright notice,
+ # this list of conditions and the following disclaimer.
+ # 2. Redistributions in binary form must reproduce the above copyright notice,
+ # this list of conditions and the following disclaimer in the documentation
+ # and/or other materials provided with the distribution.
+ # 3. Neither the name of the copyright holder nor the names of its contributors
+ # may be used to endorse or promote products derived from this software
+ # without specific prior written permission.
+ #
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ # POSSIBILITY OF SUCH DAMAGE.
+
+INCLUDE(FetchContent)
+FetchContent_Declare(gtest
+ GIT_REPOSITORY https://github.com/google/googletest.git
+ GIT_TAG release-1.12.1)
+FetchContent_MakeAvailable(gtest)
+FetchContent_Declare(benchmark
+ GIT_REPOSITORY https://github.com/google/benchmark.git
+ GIT_TAG v1.6.1)
+FetchContent_MakeAvailable(benchmark)
+
+FILE(GLOB ALC_COMMON_SRC ${CMAKE_SOURCE_DIR}/tests/common/base/*.cc)
+SET(ALC_BASE_FILES ${ALC_BASE_FILES} ${ALC_COMMON_SRC} ../../tests/cmac/base/alc_cmac.cc ../../tests/cmac/base/cmac.cc)
+SET(LIBS ${LIBS} benchmark alcp)
+SET(EXTRA_INCLUDES "")
+
+IF(ENABLE_TESTS_IPP_API)
+ ADD_COMPILE_OPTIONS("-DUSE_IPP")
+
+ IF(IPP_INSTALL_DIR)
+ MESSAGE(STATUS "IPP_INSTALL_DIR set, overriding fetch path")
+ ELSE(IPP_INSTALL_DIR)
+ SET(IPP_INSTALL_DIR "${CMAKE_SOURCE_DIR}/external")
+ MESSAGE(STATUS "IPP_INSTALL_DIR not set, defaulting to external")
+ ENDIF(IPP_INSTALL_DIR)
+
+ # If there is IPP, add IPP source and add IPP library
+ SET(EXTRA_SOURCES ${EXTRA_SOURCES} ../../tests/cmac/base/ipp_cmac.cc)
+ IF(UNIX)
+ IF(EXISTS ${IPP_INSTALL_DIR}/lib/intel64/libippcp.so)
+ SET(LIBS ${LIBS} ${IPP_INSTALL_DIR}/lib/intel64/libippcp.so)
+ ELSE(EXISTS ${IPP_INSTALL_DIR}/lib/intel/libippcp.so)
+ SET(LIBS ${LIBS} ${IPP_INSTALL_DIR}/lib/intel/libippcp.so)
+ ENDIF(EXISTS ${IPP_INSTALL_DIR}/lib/intel64/libippcp.so)
+ ENDIF(UNIX)
+ IF(WIN32)
+ IF(EXISTS ${IPP_INSTALL_DIR}/lib/intel64/ippcp.lib)
+ set(LIBS ${LIBS} ${IPP_INSTALL_DIR}/lib/intel64/ippcp.lib)
+ ELSEIF(EXISTS ${IPP_INSTALL_DIR}/lib/intel/ippcp.lib)
+ set(LIBS ${LIBS} ${IPP_INSTALL_DIR}/lib/intel/ippcp.lib)
+ ELSE(EXISTS ${IPP_INSTALL_DIR}/lib/ippcp.lib)
+ set(LIBS ${LIBS} ${IPP_INSTALL_DIR}/lib/ippcp.lib)
+ ENDIF()
+ ENDIF(WIN32)
+ SET(EXTRA_INCLUDES ${EXTRA_INCLUDES} ${IPP_INSTALL_DIR}/include)
+ENDIF(ENABLE_TESTS_IPP_API)
+
+IF(ENABLE_TESTS_OPENSSL_API)
+ ADD_COMPILE_OPTIONS("-DUSE_OSSL")
+
+ IF(OPENSSL_INSTALL_DIR)
+ MESSAGE(STATUS "OPENSSL_INSTALL_DIR set, overriding fetch path")
+ ELSE(OPENSSL_INSTALL_DIR)
+ SET(OPENSSL_INSTALL_DIR "${CMAKE_SOURCE_DIR}/external")
+ MESSAGE(STATUS "OPENSSL_INSTALL_DIR not set, defaulting to external")
+ ENDIF(OPENSSL_INSTALL_DIR)
+
+ # If there is OpenSSL, add OpenSSL source and add OpenSSL liberary
+ SET(EXTRA_SOURCES ${EXTRA_SOURCES} ../../tests/cmac/base/openssl_cmac.cc)
+ IF(UNIX)
+ IF(EXISTS ${OPENSSL_INSTALL_DIR}/lib64/libcrypto.so)
+ SET(LIBS ${LIBS} ${OPENSSL_INSTALL_DIR}/lib64/libcrypto.so)
+ ELSEIF(EXISTS ${OPENSSL_INSTALL_DIR}/lib/libcrypto.so)
+ SET(LIBS ${LIBS} ${OPENSSL_INSTALL_DIR}/lib/libcrypto.so)
+ ELSE()
+ SET(LIBS ${LIBS} ${OPENSSL_INSTALL_DIR}/lib/x86_64-linux-gnu/libcrypto.so)
+ ENDIF()
+ ENDIF(UNIX)
+ IF(WIN32)
+ IF(EXISTS ${OPENSSL_INSTALL_DIR}/lib/libcrypto.lib)
+ INCLUDE_DIRECTORIES(${OPENSSL_INSTALL_DIR}/include)
+ INCLUDE_DIRECTORIES(${OPENSSL_INSTALL_DIR}/bin)
+ SET(LIBS ${LIBS} ${OPENSSL_INSTALL_DIR}/lib/libcrypto.lib)
+ ENDIF()
+ ENDIF(WIN32)
+ SET(EXTRA_INCLUDES ${EXTRA_INCLUDES} ${OPENSSL_INSTALL_DIR}/include)
+ENDIF(ENABLE_TESTS_OPENSSL_API)
+
+ADD_EXECUTABLE(bench_cmac bench_cmac.cc ${ALC_BASE_FILES} ${EXTRA_SOURCES})
+
+TARGET_INCLUDE_DIRECTORIES(bench_cmac PRIVATE
+ "${CMAKE_SOURCE_DIR}/include"
+ "${CMAKE_SOURCE_DIR}/lib/include"
+ "${CMAKE_CURRENT_SOURCE_DIR}/include"
+ "${CMAKE_SOURCE_DIR}/tests/include"
+ "${CMAKE_SOURCE_DIR}/tests/common/include"
+ ${EXTRA_INCLUDES})
+
+TARGET_COMPILE_OPTIONS(bench_cmac PUBLIC ${ALCP_WARNINGS})
+TARGET_LINK_LIBRARIES(bench_cmac ${LIBS})
diff --git a/bench/cmac/bench_cmac.cc b/bench/cmac/bench_cmac.cc
new file mode 100644
index 000000000..51811dca3
--- /dev/null
+++ b/bench/cmac/bench_cmac.cc
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2023, Advanced Micro Devices. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "benchmarks_cmac.hh"
+#include "colors.hh"
+#include "gbench_base.hh"
+
+int
+main(int argc, char** argv)
+{
+ parseArgs(&argc, argv);
+#ifndef USE_IPP
+ if (useipp) {
+ std::cout << RED << "Error IPP not found defaulting to ALCP" << RESET
+ << std::endl;
+ }
+#endif
+#ifndef USE_OSSL
+ if (useossl) {
+ std::cout << RED << "Error OpenSSL not found defaulting to ALCP"
+ << RESET << std::endl;
+ }
+#endif
+ AddBenchmarks_Cmac();
+ ::benchmark::Initialize(&argc, argv);
+ if (::benchmark::ReportUnrecognizedArguments(argc, argv))
+ return 1;
+ ::benchmark::RunSpecifiedBenchmarks();
+ return 0;
+}
diff --git a/bench/cmac/include/benchmarks_cmac.hh b/bench/cmac/include/benchmarks_cmac.hh
new file mode 100644
index 000000000..c226cdb68
--- /dev/null
+++ b/bench/cmac/include/benchmarks_cmac.hh
@@ -0,0 +1,145 @@
+/*
+ * Copyright (C) 2023, Advanced Micro Devices. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#pragma once
+#include "cmac/alc_cmac.hh"
+#include "cmac/cmac.hh"
+
+#ifdef USE_IPP
+#include "cmac/ipp_cmac.hh"
+#endif
+
+#ifdef USE_OSSL
+#include "cmac/openssl_cmac.hh"
+#endif
+
+#include "gbench_base.hh"
+#include
+#include
+#include
+#include
+
+using namespace alcp::testing;
+
+/* Valid block sizes for performance comparison */
+std::vector cmac_block_sizes = { 16, 64, 256, 1024, 8192, 16384, 32768 };
+
+/* Valid key sizes for performance comparison */
+std::vector cmac_key_sizes = { 16 };
+
+void inline Cmac_Bench(benchmark::State& state,
+ alc_mac_info_t info,
+ Uint64 block_size,
+ Uint64 KeySize)
+{
+
+ /* MAX len of cmac would be 128 bits */
+ std::vector Cmac(128 / 8, 0);
+ std::vector message(block_size, 0);
+ std::vector Key(KeySize / 8, 0);
+
+ /* Initialize info params based on cmac type */
+ info.mi_type = ALC_MAC_CMAC;
+ info.mi_algoinfo.cmac.cmac_cipher.ci_algo_info.ai_iv = NULL;
+
+ AlcpCmacBase acb(info);
+ CmacBase* cb = &acb;
+ alcp_cmac_data_t data;
+#ifdef USE_IPP
+ IPPCmacBase icb(info);
+ if (useipp) {
+ cb = &icb;
+ }
+#endif
+
+#ifdef USE_OSSL
+ OpenSSLCmacBase ocb(info);
+ if (useossl) {
+ cb = &ocb;
+ }
+#endif
+
+ data.m_msg = &(message[0]);
+ data.m_msg_len = message.size();
+ data.m_cmac = &(Cmac[0]);
+ data.m_cmac_len = Cmac.size();
+ data.m_key = &(Key[0]);
+ data.m_key_len = Key.size();
+
+ if (!cb->init(info, Key)) {
+ state.SkipWithError("Error in cmac init function");
+ }
+ for (auto _ : state) {
+ if (!cb->cmacFunction(data)) {
+ state.SkipWithError("Error in cmac bench function");
+ }
+ }
+ state.counters["Speed(Bytes/s)"] = benchmark::Counter(
+ state.iterations() * block_size, benchmark::Counter::kIsRate);
+ state.counters["BlockSize(Bytes)"] = block_size;
+ return;
+}
+
+/* add all your new benchmarks here */
+/* CMAC AES benchmarks */
+static void
+BENCH_CMAC_AES_128(benchmark::State& state)
+{
+ alc_mac_info_t info;
+ info.mi_algoinfo.cmac.cmac_cipher.ci_type = ALC_CIPHER_TYPE_AES;
+ info.mi_algoinfo.cmac.cmac_cipher.ci_algo_info.ai_mode = ALC_AES_MODE_NONE;
+ Cmac_Bench(state, info, state.range(0), 128);
+}
+
+static void
+BENCH_CMAC_AES_192(benchmark::State& state)
+{
+ alc_mac_info_t info;
+ info.mi_algoinfo.cmac.cmac_cipher.ci_type = ALC_CIPHER_TYPE_AES;
+ info.mi_algoinfo.cmac.cmac_cipher.ci_algo_info.ai_mode = ALC_AES_MODE_NONE;
+ Cmac_Bench(state, info, state.range(0), 192);
+}
+
+static void
+BENCH_CMAC_AES_256(benchmark::State& state)
+{
+ alc_mac_info_t info;
+ info.mi_algoinfo.cmac.cmac_cipher.ci_type = ALC_CIPHER_TYPE_AES;
+ info.mi_algoinfo.cmac.cmac_cipher.ci_algo_info.ai_mode = ALC_AES_MODE_NONE;
+ Cmac_Bench(state, info, state.range(0), 256);
+}
+
+/* add benchmarks */
+int
+AddBenchmarks_Cmac()
+{
+ BENCHMARK(BENCH_CMAC_AES_128)->ArgsProduct({ cmac_block_sizes });
+ BENCHMARK(BENCH_CMAC_AES_192)->ArgsProduct({ cmac_block_sizes });
+ BENCHMARK(BENCH_CMAC_AES_256)->ArgsProduct({ cmac_block_sizes });
+ return 0;
+}
\ No newline at end of file
diff --git a/bench/digest/CMakeLists.txt b/bench/digest/CMakeLists.txt
new file mode 100644
index 000000000..a51ff3461
--- /dev/null
+++ b/bench/digest/CMakeLists.txt
@@ -0,0 +1,114 @@
+ # Copyright (C) 2022-2023, Advanced Micro Devices. All rights reserved.
+ #
+ # Redistribution and use in source and binary forms, with or without
+ # modification, are permitted provided that the following conditions are met:
+ # 1. Redistributions of source code must retain the above copyright notice,
+ # this list of conditions and the following disclaimer.
+ # 2. Redistributions in binary form must reproduce the above copyright notice,
+ # this list of conditions and the following disclaimer in the documentation
+ # and/or other materials provided with the distribution.
+ # 3. Neither the name of the copyright holder nor the names of its contributors
+ # may be used to endorse or promote products derived from this software
+ # without specific prior written permission.
+ #
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ # POSSIBILITY OF SUCH DAMAGE.
+
+INCLUDE(FetchContent)
+FetchContent_Declare(gtest
+ GIT_REPOSITORY https://github.com/google/googletest.git
+ GIT_TAG release-1.12.1)
+FetchContent_MakeAvailable(gtest)
+FetchContent_Declare(benchmark
+ GIT_REPOSITORY https://github.com/google/benchmark.git
+ GIT_TAG v1.6.1)
+FetchContent_MakeAvailable(benchmark)
+
+FILE(GLOB ALC_COMMON_SRC ${CMAKE_SOURCE_DIR}/tests/common/base/*.cc)
+SET(ALC_BASE_FILES ${ALC_BASE_FILES} ${ALC_COMMON_SRC} ../../tests/digest/base/alc_digest.cc ../../tests/digest/base/digest.cc)
+SET(LIBS ${LIBS} benchmark alcp)
+SET(EXTRA_INCLUDES "")
+
+IF(ENABLE_TESTS_IPP_API)
+ ADD_COMPILE_OPTIONS("-DUSE_IPP")
+
+ IF(IPP_INSTALL_DIR)
+ MESSAGE(STATUS "IPP_INSTALL_DIR set, overriding fetch path")
+ ELSE(IPP_INSTALL_DIR)
+ SET(IPP_INSTALL_DIR "${CMAKE_SOURCE_DIR}/external")
+ MESSAGE(STATUS "IPP_INSTALL_DIR not set, defaulting to external")
+ ENDIF(IPP_INSTALL_DIR)
+
+ # If there is IPP, add IPP source and add IPP liberary
+ SET(EXTRA_SOURCES ${EXTRA_SOURCES} ../../tests/digest/base/ipp_digest.cc)
+ IF(UNIX)
+ IF(EXISTS ${IPP_INSTALL_DIR}/lib/intel64/libippcp.so)
+ SET(LIBS ${LIBS} ${IPP_INSTALL_DIR}/lib/intel64/libippcp.so)
+ ELSE(EXISTS ${IPP_INSTALL_DIR}/lib/intel/libippcp.so)
+ SET(LIBS ${LIBS} ${IPP_INSTALL_DIR}/lib/intel/libippcp.so)
+ ENDIF(EXISTS ${IPP_INSTALL_DIR}/lib/intel64/libippcp.so)
+ ENDIF(UNIX)
+ IF(WIN32)
+ IF(EXISTS ${IPP_INSTALL_DIR}/lib/intel64/ippcp.lib)
+ set(LIBS ${LIBS} ${IPP_INSTALL_DIR}/lib/intel64/ippcp.lib)
+ ELSEIF(EXISTS ${IPP_INSTALL_DIR}/lib/intel/ippcp.lib)
+ set(LIBS ${LIBS} ${IPP_INSTALL_DIR}/lib/intel/ippcp.lib)
+ ELSE(EXISTS ${IPP_INSTALL_DIR}/lib/ippcp.lib)
+ set(LIBS ${LIBS} ${IPP_INSTALL_DIR}/lib/ippcp.lib)
+ ENDIF()
+ ENDIF(WIN32)
+ SET(EXTRA_INCLUDES ${EXTRA_INCLUDES} ${IPP_INSTALL_DIR}/include)
+ENDIF(ENABLE_TESTS_IPP_API)
+
+IF(ENABLE_TESTS_OPENSSL_API)
+ ADD_COMPILE_OPTIONS("-DUSE_OSSL")
+
+ IF(OPENSSL_INSTALL_DIR)
+ MESSAGE(STATUS "OPENSSL_INSTALL_DIR set, overriding fetch path")
+ ELSE(OPENSSL_INSTALL_DIR)
+ SET(OPENSSL_INSTALL_DIR "${CMAKE_SOURCE_DIR}/external")
+ MESSAGE(STATUS "OPENSSL_INSTALL_DIR not set, defaulting to external")
+ ENDIF(OPENSSL_INSTALL_DIR)
+
+ # If there is OpenSSL, add OpenSSL source and add OpenSSL liberary
+ SET(EXTRA_SOURCES ${EXTRA_SOURCES} ../../tests/digest/base/openssl_digest.cc)
+ IF(UNIX)
+ IF(EXISTS ${OPENSSL_INSTALL_DIR}/lib64/libcrypto.so)
+ SET(LIBS ${LIBS} ${OPENSSL_INSTALL_DIR}/lib64/libcrypto.so)
+ ELSEIF(EXISTS ${OPENSSL_INSTALL_DIR}/lib/libcrypto.so)
+ SET(LIBS ${LIBS} ${OPENSSL_INSTALL_DIR}/lib/libcrypto.so)
+ ELSE()
+ SET(LIBS ${LIBS} ${OPENSSL_INSTALL_DIR}/lib/x86_64-linux-gnu/libcrypto.so)
+ ENDIF()
+ ENDIF(UNIX)
+ IF(WIN32)
+ IF(EXISTS ${OPENSSL_INSTALL_DIR}/lib/libcrypto.lib)
+ INCLUDE_DIRECTORIES(${OPENSSL_INSTALL_DIR}/include)
+ INCLUDE_DIRECTORIES(${OPENSSL_INSTALL_DIR}/bin)
+ SET(LIBS ${LIBS} ${OPENSSL_INSTALL_DIR}/lib/libcrypto.lib)
+ ENDIF()
+ ENDIF(WIN32)
+ SET(EXTRA_INCLUDES ${EXTRA_INCLUDES} ${OPENSSL_INSTALL_DIR}/include)
+ENDIF(ENABLE_TESTS_OPENSSL_API)
+
+ADD_EXECUTABLE(bench_digest bench_digest.cc ${ALC_BASE_FILES} ${EXTRA_SOURCES})
+
+TARGET_INCLUDE_DIRECTORIES(bench_digest PRIVATE
+ "${CMAKE_SOURCE_DIR}/include"
+ "${CMAKE_SOURCE_DIR}/lib/include"
+ "${CMAKE_CURRENT_SOURCE_DIR}/include"
+ "${CMAKE_SOURCE_DIR}/tests/include"
+ "${CMAKE_SOURCE_DIR}/tests/common/include"
+ ${EXTRA_INCLUDES})
+
+TARGET_COMPILE_OPTIONS(bench_digest PUBLIC ${ALCP_WARNINGS})
+TARGET_LINK_LIBRARIES(bench_digest ${LIBS})
diff --git a/bench/digest/bench_digest.cc b/bench/digest/bench_digest.cc
new file mode 100644
index 000000000..56bea4e7b
--- /dev/null
+++ b/bench/digest/bench_digest.cc
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2023, Advanced Micro Devices. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "benchmarks_digest.hh"
+#include "colors.hh"
+#include "gbench_base.hh"
+
+int
+main(int argc, char** argv)
+{
+ parseArgs(&argc, argv);
+#ifndef USE_IPP
+ if (useipp) {
+ std::cout << RED << "Error IPP not found defaulting to ALCP" << RESET
+ << std::endl;
+ }
+#endif
+#ifndef USE_OSSL
+ if (useossl) {
+ std::cout << RED << "Error OpenSSL not found defaulting to ALCP"
+ << RESET << std::endl;
+ }
+#endif
+ AddBenchmarks();
+ ::benchmark::Initialize(&argc, argv);
+ if (::benchmark::ReportUnrecognizedArguments(argc, argv))
+ return 1;
+ ::benchmark::RunSpecifiedBenchmarks();
+ return 0;
+}
diff --git a/bench/digest/include/benchmarks_digest.hh b/bench/digest/include/benchmarks_digest.hh
new file mode 100644
index 000000000..88149d83d
--- /dev/null
+++ b/bench/digest/include/benchmarks_digest.hh
@@ -0,0 +1,249 @@
+/*
+ * Copyright (C) 2023, Advanced Micro Devices. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#pragma once
+#include "digest/alc_digest.hh"
+#include "digest/digest.hh"
+#include "rng_base.hh"
+
+#ifdef USE_IPP
+#include "digest/ipp_digest.hh"
+#endif
+
+#ifdef USE_OSSL
+#include "digest/openssl_digest.hh"
+#endif
+
+#include "gbench_base.hh"
+#include
+#include
+#include
+#include
+
+using namespace alcp::testing;
+
+std::vector digest_block_sizes = {
+ 16, 64, 256, 1024, 8192, 16384, 32768
+};
+
+void inline Digest_Bench(benchmark::State& state,
+ alc_digest_info_t info,
+ Uint64 block_size)
+{
+ RngBase rb;
+ std::vector msg(block_size);
+ AlcpDigestBase adb(info);
+ DigestBase* db = &adb;
+ alcp_digest_data_t data;
+#ifdef USE_IPP
+ IPPDigestBase idb(info);
+ if (useipp) {
+ db = &idb;
+ }
+#endif
+
+#ifdef USE_OSSL
+ OpenSSLDigestBase odb(info);
+ if (useossl) {
+ db = &odb;
+ }
+#endif
+
+ if (info.dt_mode.dm_sha3 == ALC_SHAKE_128
+ || info.dt_mode.dm_sha3 == ALC_SHAKE_256) {
+
+ if (!db->init(info, info.dt_custom_len)) {
+ state.SkipWithError("Error: Digest base init failed");
+ }
+ /* override digest len for shake cases */
+ data.m_digest_len = info.dt_custom_len;
+ } else {
+ data.m_digest_len = info.dt_len / 8;
+ }
+
+ Uint8 digest[data.m_digest_len];
+ memset(digest, 0, data.m_digest_len * sizeof(Uint8));
+ /* generate random bytes */
+ msg = rb.genRandomBytes(block_size);
+
+ data.m_msg = &(msg[0]);
+ data.m_digest = digest;
+ data.m_msg_len = block_size;
+
+ for (auto _ : state) {
+ if (!db->digest_function(data)) {
+ state.SkipWithError("Error in running digest benchmark:");
+ }
+ db->reset();
+ }
+ state.counters["Speed(Bytes/s)"] = benchmark::Counter(
+ state.iterations() * block_size, benchmark::Counter::kIsRate);
+ state.counters["BlockSize(Bytes)"] = block_size;
+ return;
+}
+
+/* add all your new benchmarks here */
+/* SHA2 benchmarks */
+static void
+BENCH_SHA2_224(benchmark::State& state)
+{
+ alc_digest_info_t info;
+ info.dt_mode.dm_sha2 = ALC_SHA2_224;
+ info.dt_type = ALC_DIGEST_TYPE_SHA2;
+ info.dt_len = ALC_DIGEST_LEN_224;
+ Digest_Bench(state, info, state.range(0));
+}
+static void
+BENCH_SHA2_256(benchmark::State& state)
+{
+ alc_digest_info_t info;
+ info.dt_mode.dm_sha2 = ALC_SHA2_256;
+ info.dt_type = ALC_DIGEST_TYPE_SHA2;
+ info.dt_len = ALC_DIGEST_LEN_256;
+ Digest_Bench(state, info, state.range(0));
+}
+static void
+BENCH_SHA2_384(benchmark::State& state)
+{
+ alc_digest_info_t info;
+ info.dt_mode.dm_sha2 = ALC_SHA2_384;
+ info.dt_type = ALC_DIGEST_TYPE_SHA2;
+ info.dt_len = ALC_DIGEST_LEN_384;
+ Digest_Bench(state, info, state.range(0));
+}
+static void
+BENCH_SHA2_512(benchmark::State& state)
+{
+ alc_digest_info_t info;
+ info.dt_mode.dm_sha2 = ALC_SHA2_512;
+ info.dt_type = ALC_DIGEST_TYPE_SHA2;
+ info.dt_len = ALC_DIGEST_LEN_512;
+ Digest_Bench(state, info, state.range(0));
+}
+/* SHA 512 224 and 256 len*/
+static void
+BENCH_SHA2_512_224(benchmark::State& state)
+{
+ alc_digest_info_t info;
+ info.dt_mode.dm_sha2 = ALC_SHA2_512;
+ info.dt_type = ALC_DIGEST_TYPE_SHA2;
+ info.dt_len = ALC_DIGEST_LEN_224;
+ Digest_Bench(state, info, state.range(0));
+}
+static void
+BENCH_SHA2_512_256(benchmark::State& state)
+{
+ alc_digest_info_t info;
+ info.dt_mode.dm_sha2 = ALC_SHA2_512;
+ info.dt_type = ALC_DIGEST_TYPE_SHA2;
+ info.dt_len = ALC_DIGEST_LEN_256;
+ Digest_Bench(state, info, state.range(0));
+}
+
+/* SHA3 benchmarks */
+static void
+BENCH_SHA3_224(benchmark::State& state)
+{
+ alc_digest_info_t info;
+ info.dt_mode.dm_sha3 = ALC_SHA3_224;
+ info.dt_type = ALC_DIGEST_TYPE_SHA3;
+ info.dt_len = ALC_DIGEST_LEN_224;
+ Digest_Bench(state, info, state.range(0));
+}
+static void
+BENCH_SHA3_256(benchmark::State& state)
+{
+ alc_digest_info_t info;
+ info.dt_mode.dm_sha3 = ALC_SHA3_256;
+ info.dt_type = ALC_DIGEST_TYPE_SHA3;
+ info.dt_len = ALC_DIGEST_LEN_256;
+ Digest_Bench(state, info, state.range(0));
+}
+static void
+BENCH_SHA3_384(benchmark::State& state)
+{
+ alc_digest_info_t info;
+ info.dt_mode.dm_sha3 = ALC_SHA3_384;
+ info.dt_type = ALC_DIGEST_TYPE_SHA3;
+ info.dt_len = ALC_DIGEST_LEN_384;
+ Digest_Bench(state, info, state.range(0));
+}
+static void
+BENCH_SHA3_512(benchmark::State& state)
+{
+ alc_digest_info_t info;
+ info.dt_mode.dm_sha3 = ALC_SHA3_512;
+ info.dt_type = ALC_DIGEST_TYPE_SHA3;
+ info.dt_len = ALC_DIGEST_LEN_512;
+ Digest_Bench(state, info, state.range(0));
+}
+
+/* SHAKE */
+static void
+BENCH_SHAKE_128(benchmark::State& state)
+{
+ alc_digest_info_t info;
+ info.dt_mode.dm_sha3 = ALC_SHAKE_128;
+ info.dt_type = ALC_DIGEST_TYPE_SHA3;
+ info.dt_len = ALC_DIGEST_LEN_CUSTOM;
+ info.dt_custom_len = 256;
+ Digest_Bench(state, info, state.range(0));
+}
+static void
+BENCH_SHAKE_256(benchmark::State& state)
+{
+ alc_digest_info_t info;
+ info.dt_mode.dm_sha3 = ALC_SHAKE_256;
+ info.dt_type = ALC_DIGEST_TYPE_SHA3;
+ info.dt_len = ALC_DIGEST_LEN_CUSTOM;
+ info.dt_custom_len = 256;
+ Digest_Bench(state, info, state.range(0));
+}
+
+/* add benchmarks */
+int
+AddBenchmarks()
+{
+ BENCHMARK(BENCH_SHA2_224)->ArgsProduct({ digest_block_sizes });
+ BENCHMARK(BENCH_SHA2_256)->ArgsProduct({ digest_block_sizes });
+ BENCHMARK(BENCH_SHA2_384)->ArgsProduct({ digest_block_sizes });
+ BENCHMARK(BENCH_SHA2_512)->ArgsProduct({ digest_block_sizes });
+ BENCHMARK(BENCH_SHA2_512_224)->ArgsProduct({ digest_block_sizes });
+ BENCHMARK(BENCH_SHA2_512_256)->ArgsProduct({ digest_block_sizes });
+
+ /* SHA3 is not supported for IPP */
+ if (!useipp) {
+ BENCHMARK(BENCH_SHA3_224)->ArgsProduct({ digest_block_sizes });
+ BENCHMARK(BENCH_SHA3_256)->ArgsProduct({ digest_block_sizes });
+ BENCHMARK(BENCH_SHA3_384)->ArgsProduct({ digest_block_sizes });
+ BENCHMARK(BENCH_SHA3_512)->ArgsProduct({ digest_block_sizes });
+ BENCHMARK(BENCH_SHAKE_128)->ArgsProduct({ digest_block_sizes });
+ BENCHMARK(BENCH_SHAKE_256)->ArgsProduct({ digest_block_sizes });
+ }
+ return 0;
+}
\ No newline at end of file
diff --git a/bench/ecdh/CMakeLists.txt b/bench/ecdh/CMakeLists.txt
new file mode 100644
index 000000000..dd16cc578
--- /dev/null
+++ b/bench/ecdh/CMakeLists.txt
@@ -0,0 +1,128 @@
+ # Copyright (C) 2023, Advanced Micro Devices. All rights reserved.
+ #
+ # Redistribution and use in source and binary forms, with or without
+ # modification, are permitted provided that the following conditions are met:
+ # 1. Redistributions of source code must retain the above copyright notice,
+ # this list of conditions and the following disclaimer.
+ # 2. Redistributions in binary form must reproduce the above copyright notice,
+ # this list of conditions and the following disclaimer in the documentation
+ # and/or other materials provided with the distribution.
+ # 3. Neither the name of the copyright holder nor the names of its contributors
+ # may be used to endorse or promote products derived from this software
+ # without specific prior written permission.
+ #
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ # POSSIBILITY OF SUCH DAMAGE.
+
+INCLUDE(FetchContent)
+FetchContent_Declare(gtest
+ GIT_REPOSITORY https://github.com/google/googletest.git
+ GIT_TAG release-1.12.1)
+FetchContent_MakeAvailable(gtest)
+FetchContent_Declare(benchmark
+ GIT_REPOSITORY https://github.com/google/benchmark.git
+ GIT_TAG v1.6.1)
+FetchContent_MakeAvailable(benchmark)
+
+FILE(GLOB ALC_COMMON_SRC ${CMAKE_SOURCE_DIR}/tests/common/base/*.cc)
+SET(ALC_BASE_FILES ${ALC_BASE_FILES} ${ALC_COMMON_SRC} ../../tests/ecdh/base/alc_ecdh.cc ../../tests/ecdh/base/ecdh.cc)
+SET(LIBS ${LIBS} benchmark alcp)
+SET(EXTRA_INCLUDES "")
+
+IF(ENABLE_TESTS_IPP_API)
+ ADD_COMPILE_OPTIONS("-DUSE_IPP")
+
+ IF(IPP_INSTALL_DIR)
+ MESSAGE(STATUS "IPP_INSTALL_DIR set, overriding fetch path")
+ ELSE(IPP_INSTALL_DIR)
+ SET(IPP_INSTALL_DIR "${CMAKE_SOURCE_DIR}/external")
+ MESSAGE(STATUS "IPP_INSTALL_DIR not set, defaulting to external")
+ ENDIF(IPP_INSTALL_DIR)
+
+ # If there is IPP, add IPP source and add IPP library
+ SET(EXTRA_SOURCES ${EXTRA_SOURCES} ../../tests/ecdh/base/ipp_ecdh.cc)
+ IF(UNIX)
+ IF(EXISTS ${IPP_INSTALL_DIR}/lib/intel64/libippcp.so)
+ SET(LIBS ${LIBS} ${IPP_INSTALL_DIR}/lib/intel64/libippcp.so)
+ ELSE(EXISTS ${IPP_INSTALL_DIR}/lib/intel/libippcp.so)
+ SET(LIBS ${LIBS} ${IPP_INSTALL_DIR}/lib/intel/libippcp.so)
+ ENDIF(EXISTS ${IPP_INSTALL_DIR}/lib/intel64/libippcp.so)
+ # for ECC functions
+ IF(EXISTS ${IPP_INSTALL_DIR}/lib/intel64/libcrypto_mb.so)
+ SET(LIBS ${LIBS} ${IPP_INSTALL_DIR}/lib/intel64/libcrypto_mb.so)
+ ELSE(EXISTS ${IPP_INSTALL_DIR}/lib/intel/libcrypto_mb.so)
+ SET(LIBS ${LIBS} ${IPP_INSTALL_DIR}/lib/intel/libcrypto_mb.so)
+ ENDIF(EXISTS ${IPP_INSTALL_DIR}/lib/intel64/libcrypto_mb.so)
+ ENDIF(UNIX)
+ IF(WIN32)
+ IF(EXISTS ${IPP_INSTALL_DIR}/lib/intel64/ippcp.lib)
+ SET(LIBS ${LIBS} ${IPP_INSTALL_DIR}/lib/intel64/ippcp.lib)
+ ELSEIF(EXISTS ${IPP_INSTALL_DIR}/lib/intel/ippcp.lib)
+ SET(LIBS ${LIBS} ${IPP_INSTALL_DIR}/lib/intel/ippcp.lib)
+ ELSE(EXISTS ${IPP_INSTALL_DIR}/lib/ippcp.lib)
+ SET(LIBS ${LIBS} ${IPP_INSTALL_DIR}/lib/ippcp.lib)
+ ENDIF(EXISTS ${IPP_INSTALL_DIR}/lib/intel64/ippcp.lib)
+ # for ECC functions
+ IF(EXISTS ${IPP_INSTALL_DIR}/lib/intel64/crypto_mb.lib)
+ SET(LIBS ${LIBS} ${IPP_INSTALL_DIR}/lib/intel64/crypto_mb.lib)
+ ELSEIF(EXISTS ${IPP_INSTALL_DIR}/lib/intel/crypto_mb.lib)
+ SET(LIBS ${LIBS} ${IPP_INSTALL_DIR}/lib/intel/crypto_mb.lib)
+ ELSE(EXISTS ${IPP_INSTALL_DIR}/lib/crypto_mb.lib)
+ SET(LIBS ${LIBS} ${IPP_INSTALL_DIR}/lib/crypto_mb.lib)
+ ENDIF(EXISTS ${IPP_INSTALL_DIR}/lib/intel64/crypto_mb.lib)
+ ENDIF(WIN32)
+ SET(EXTRA_INCLUDES ${EXTRA_INCLUDES} ${IPP_INSTALL_DIR}/include)
+ENDIF(ENABLE_TESTS_IPP_API)
+
+IF(ENABLE_TESTS_OPENSSL_API)
+ ADD_COMPILE_OPTIONS("-DUSE_OSSL")
+
+ IF(OPENSSL_INSTALL_DIR)
+ MESSAGE(STATUS "OPENSSL_INSTALL_DIR set, overriding fetch path")
+ ELSE(OPENSSL_INSTALL_DIR)
+ SET(OPENSSL_INSTALL_DIR "${CMAKE_SOURCE_DIR}/external")
+ MESSAGE(STATUS "OPENSSL_INSTALL_DIR not set, defaulting to external")
+ ENDIF(OPENSSL_INSTALL_DIR)
+
+ # If there is OpenSSL, add OpenSSL source and add OpenSSL liberary
+ SET(EXTRA_SOURCES ${EXTRA_SOURCES} ../../tests/ecdh/base/openssl_ecdh.cc)
+ IF(UNIX)
+ IF(EXISTS ${OPENSSL_INSTALL_DIR}/lib64/libcrypto.so)
+ SET(LIBS ${LIBS} ${OPENSSL_INSTALL_DIR}/lib64/libcrypto.so)
+ ELSEIF(EXISTS ${OPENSSL_INSTALL_DIR}/lib/libcrypto.so)
+ SET(LIBS ${LIBS} ${OPENSSL_INSTALL_DIR}/lib/libcrypto.so)
+ ELSE()
+ SET(LIBS ${LIBS} ${OPENSSL_INSTALL_DIR}/lib/x86_64-linux-gnu/libcrypto.so)
+ ENDIF()
+ ENDIF(UNIX)
+ IF(WIN32)
+ IF(EXISTS ${OPENSSL_INSTALL_DIR}/lib/libcrypto.lib)
+ INCLUDE_DIRECTORIES(${OPENSSL_INSTALL_DIR}/include)
+ INCLUDE_DIRECTORIES(${OPENSSL_INSTALL_DIR}/bin)
+ SET(LIBS ${LIBS} ${OPENSSL_INSTALL_DIR}/lib/libcrypto.lib)
+ ENDIF()
+ ENDIF(WIN32)
+ SET(EXTRA_INCLUDES ${EXTRA_INCLUDES} ${OPENSSL_INSTALL_DIR}/include)
+ENDIF(ENABLE_TESTS_OPENSSL_API)
+
+ADD_EXECUTABLE(bench_ecdh bench_ecdh.cc ${ALC_BASE_FILES} ${EXTRA_SOURCES})
+
+TARGET_INCLUDE_DIRECTORIES(bench_ecdh PRIVATE
+ "${CMAKE_SOURCE_DIR}/include"
+ "${CMAKE_SOURCE_DIR}/lib/include"
+ "${CMAKE_CURRENT_SOURCE_DIR}/include"
+ "${CMAKE_SOURCE_DIR}/tests/include"
+ "${CMAKE_SOURCE_DIR}/tests/common/include"
+ ${EXTRA_INCLUDES})
+
+TARGET_COMPILE_OPTIONS(bench_ecdh PUBLIC ${ALCP_WARNINGS})
+TARGET_LINK_LIBRARIES(bench_ecdh ${LIBS})
diff --git a/bench/ecdh/bench_ecdh.cc b/bench/ecdh/bench_ecdh.cc
new file mode 100644
index 000000000..745aee692
--- /dev/null
+++ b/bench/ecdh/bench_ecdh.cc
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2023, Advanced Micro Devices. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "benchmarks_ecdh.hh"
+#include "colors.hh"
+#include "gbench_base.hh"
+
+int
+main(int argc, char** argv)
+{
+ parseArgs(&argc, argv);
+#ifndef USE_IPP
+ if (useipp) {
+ std::cout << RED << "Error IPP not found defaulting to ALCP" << RESET
+ << std::endl;
+ }
+#endif
+#ifndef USE_OSSL
+ if (useossl) {
+ std::cout << RED << "Error OpenSSL not found defaulting to ALCP"
+ << RESET << std::endl;
+ }
+#endif
+ AddBenchmarks_Ecdh();
+ ::benchmark::Initialize(&argc, argv);
+ if (::benchmark::ReportUnrecognizedArguments(argc, argv))
+ return 1;
+ ::benchmark::RunSpecifiedBenchmarks();
+ return 0;
+}
diff --git a/bench/ecdh/include/benchmarks_ecdh.hh b/bench/ecdh/include/benchmarks_ecdh.hh
new file mode 100644
index 000000000..b8fa23730
--- /dev/null
+++ b/bench/ecdh/include/benchmarks_ecdh.hh
@@ -0,0 +1,185 @@
+/*
+ * Copyright (C) 2023, Advanced Micro Devices. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#pragma once
+
+#include "alcp/alcp.h"
+#include "alcp/utils/cpuid.hh"
+#include "ecdh/alc_ecdh.hh"
+#include "ecdh/ecdh.hh"
+#include "gbench_base.hh"
+#include "rng_base.hh"
+#include
+#include
+#include
+
+#ifdef USE_IPP
+#include "ecdh/ipp_ecdh.hh"
+#endif
+
+#ifdef USE_OSSL
+#include "ecdh/openssl_ecdh.hh"
+#endif
+
+using namespace alcp::testing;
+using alcp::utils::CpuId;
+
+typedef enum
+{
+ ECDH_BENCH_GEN_PUB_KEY = 0,
+ ECDH_BENCH_GEN_SECRET_KEY = 1
+} ecdh_bench_opt;
+
+inline int
+ecdh_Bench(benchmark::State& state, alc_ec_info_t info, ecdh_bench_opt opt)
+{
+ std::string LibStr = "";
+
+ /*TODO, Keysize in bytes. might change for other curves */
+ int KeySize = ECDH_KEYSIZE;
+ std::vector Peer1PubKey(KeySize), Peer2PubKey(KeySize),
+ Peer1SharedSecretKey(KeySize), Peer2SharedSecretKey(KeySize);
+
+ alcp_ecdh_data_t data_peer1, data_peer2;
+
+ AlcpEcdhBase aeb_peer1(info);
+ AlcpEcdhBase aeb_peer2(info);
+
+ EcdhBase *Eb_peer1, *Eb_peer2;
+ RngBase rb;
+ Eb_peer1 = &aeb_peer1;
+ Eb_peer2 = &aeb_peer2;
+
+ LibStr = "ALCP";
+
+#ifdef USE_OSSL
+ OpenSSLEcdhBase oeb_peer1(info);
+ OpenSSLEcdhBase oeb_peer2(info);
+ /* Select by default openssl for cross testing if nothing provided*/
+ if (useossl == true) {
+ Eb_peer1 = &oeb_peer1;
+ Eb_peer2 = &oeb_peer2;
+ LibStr = "OpenSSL";
+ }
+#endif
+#ifdef USE_IPP
+ IPPEcdhBase ieb_peer1(info);
+ IPPEcdhBase ieb_peer2(info);
+ if (useipp == true) {
+ // FIXME : skip bench if not running on avx512 architecture
+ if (!CpuId::cpuHasAvx512(alcp::utils::AVX512_F)) {
+ state.SkipWithError(
+ "IPP Ecdh multi-buffer implementations arent supported "
+ "on non-avx512 supported arch,"
+ "skipping benchmarks!");
+ return 0;
+ }
+ Eb_peer1 = &ieb_peer1;
+ Eb_peer2 = &ieb_peer2;
+ LibStr = "IPP";
+ }
+#endif
+
+ std::vector Peer1PvtKey = rb.genRandomBytes(KeySize);
+ std::vector Peer2PvtKey = rb.genRandomBytes(KeySize);
+
+ /* now load this pvtkey pair into both alc, ext data */
+ data_peer1.m_Peer_PvtKey = &(Peer1PvtKey[0]);
+ data_peer2.m_Peer_PvtKey = &(Peer2PvtKey[0]);
+ data_peer1.m_Peer_PvtKeyLen = KeySize;
+ data_peer2.m_Peer_PvtKeyLen = KeySize;
+ data_peer1.m_Peer_PubKey = &(Peer1PubKey[0]);
+ data_peer2.m_Peer_PubKey = &(Peer2PubKey[0]);
+ data_peer1.m_Peer_PubKeyLen = KeySize;
+ data_peer2.m_Peer_PubKeyLen = KeySize;
+ data_peer1.m_Peer_SecretKey = &(Peer1SharedSecretKey[0]);
+ data_peer2.m_Peer_SecretKey = &(Peer2SharedSecretKey[0]);
+
+ /* init wont be benchmarked */
+ if (!Eb_peer1->init(info)) {
+ state.SkipWithError("Error in ECDH init");
+ }
+ if (!Eb_peer2->init(info)) {
+ state.SkipWithError("Error in ECDH init");
+ }
+
+ /* Just benchmark Gen public key */
+ if (opt == ECDH_BENCH_GEN_PUB_KEY) {
+ for (auto _ : state) {
+ if (!Eb_peer1->GeneratePublicKey(data_peer1)) {
+ state.SkipWithError("Error in ECDH GeneratePublicKey");
+ }
+ }
+ } else if (opt == ECDH_BENCH_GEN_SECRET_KEY) {
+ /* this step is needed for computing secret key */
+ if (!Eb_peer1->GeneratePublicKey(data_peer1)) {
+ state.SkipWithError("Error in ECDH GeneratePublicKey");
+ }
+ if (!Eb_peer2->GeneratePublicKey(data_peer2)) {
+ state.SkipWithError("Error in ECDH GeneratePublicKey");
+ }
+ /* to benchmark only Computing secret key */
+ for (auto _ : state) {
+ if (!Eb_peer1->ComputeSecretKey(data_peer1, data_peer2)) {
+ state.SkipWithError("Error in ECDH ComputeSecretKey");
+ }
+ }
+ }
+ state.counters["KeysGen/Sec"] =
+ benchmark::Counter(state.iterations(), benchmark::Counter::kIsRate);
+ return 0;
+}
+
+static void
+BENCH_ECDH_x25519_GenPubKey(benchmark::State& state)
+{
+ alc_ec_info_t info;
+ info.ecCurveId = ALCP_EC_CURVE25519;
+ info.ecCurveType = ALCP_EC_CURVE_TYPE_MONTGOMERY;
+ info.ecPointFormat = ALCP_EC_POINT_FORMAT_UNCOMPRESSED;
+ benchmark::DoNotOptimize(ecdh_Bench(state, info, ECDH_BENCH_GEN_PUB_KEY));
+}
+static void
+BENCH_ECDH_x25519_GenSecretKey(benchmark::State& state)
+{
+ alc_ec_info_t info;
+ info.ecCurveId = ALCP_EC_CURVE25519;
+ info.ecCurveType = ALCP_EC_CURVE_TYPE_MONTGOMERY;
+ info.ecPointFormat = ALCP_EC_POINT_FORMAT_UNCOMPRESSED;
+ benchmark::DoNotOptimize(
+ ecdh_Bench(state, info, ECDH_BENCH_GEN_SECRET_KEY));
+}
+
+/* add new benchmarks here */
+int
+AddBenchmarks_Ecdh()
+{
+ BENCHMARK(BENCH_ECDH_x25519_GenPubKey);
+ BENCHMARK(BENCH_ECDH_x25519_GenSecretKey);
+ return 0;
+}
\ No newline at end of file
diff --git a/bench/hmac/CMakeLists.txt b/bench/hmac/CMakeLists.txt
new file mode 100644
index 000000000..e3517a74c
--- /dev/null
+++ b/bench/hmac/CMakeLists.txt
@@ -0,0 +1,114 @@
+ # Copyright (C) 2023, Advanced Micro Devices. All rights reserved.
+ #
+ # Redistribution and use in source and binary forms, with or without
+ # modification, are permitted provided that the following conditions are met:
+ # 1. Redistributions of source code must retain the above copyright notice,
+ # this list of conditions and the following disclaimer.
+ # 2. Redistributions in binary form must reproduce the above copyright notice,
+ # this list of conditions and the following disclaimer in the documentation
+ # and/or other materials provided with the distribution.
+ # 3. Neither the name of the copyright holder nor the names of its contributors
+ # may be used to endorse or promote products derived from this software
+ # without specific prior written permission.
+ #
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ # POSSIBILITY OF SUCH DAMAGE.
+
+INCLUDE(FetchContent)
+FetchContent_Declare(gtest
+ GIT_REPOSITORY https://github.com/google/googletest.git
+ GIT_TAG release-1.12.1)
+FetchContent_MakeAvailable(gtest)
+FetchContent_Declare(benchmark
+ GIT_REPOSITORY https://github.com/google/benchmark.git
+ GIT_TAG v1.6.1)
+FetchContent_MakeAvailable(benchmark)
+
+FILE(GLOB ALC_COMMON_SRC ${CMAKE_SOURCE_DIR}/tests/common/base/*.cc)
+SET(ALC_BASE_FILES ${ALC_BASE_FILES} ${ALC_COMMON_SRC} ../../tests/hmac/base/alc_hmac.cc ../../tests/hmac/base/hmac.cc)
+SET(LIBS ${LIBS} benchmark alcp)
+SET(EXTRA_INCLUDES "")
+
+IF(ENABLE_TESTS_IPP_API)
+ ADD_COMPILE_OPTIONS("-DUSE_IPP")
+
+ IF(IPP_INSTALL_DIR)
+ MESSAGE(STATUS "IPP_INSTALL_DIR set, overriding fetch path")
+ ELSE(IPP_INSTALL_DIR)
+ SET(IPP_INSTALL_DIR "${CMAKE_SOURCE_DIR}/external")
+ MESSAGE(STATUS "IPP_INSTALL_DIR not set, defaulting to external")
+ ENDIF(IPP_INSTALL_DIR)
+
+ # If there is IPP, add IPP source and add IPP library
+ SET(EXTRA_SOURCES ${EXTRA_SOURCES} ../../tests/hmac/base/ipp_hmac.cc)
+ IF(UNIX)
+ IF(EXISTS ${IPP_INSTALL_DIR}/lib/intel64/libippcp.so)
+ SET(LIBS ${LIBS} ${IPP_INSTALL_DIR}/lib/intel64/libippcp.so)
+ ELSE(EXISTS ${IPP_INSTALL_DIR}/lib/intel/libippcp.so)
+ SET(LIBS ${LIBS} ${IPP_INSTALL_DIR}/lib/intel/libippcp.so)
+ ENDIF(EXISTS ${IPP_INSTALL_DIR}/lib/intel64/libippcp.so)
+ ENDIF(UNIX)
+ IF(WIN32)
+ IF(EXISTS ${IPP_INSTALL_DIR}/lib/intel64/ippcp.lib)
+ set(LIBS ${LIBS} ${IPP_INSTALL_DIR}/lib/intel64/ippcp.lib)
+ ELSEIF(EXISTS ${IPP_INSTALL_DIR}/lib/intel/ippcp.lib)
+ set(LIBS ${LIBS} ${IPP_INSTALL_DIR}/lib/intel/ippcp.lib)
+ ELSE(EXISTS ${IPP_INSTALL_DIR}/lib/ippcp.lib)
+ set(LIBS ${LIBS} ${IPP_INSTALL_DIR}/lib/ippcp.lib)
+ ENDIF()
+ ENDIF(WIN32)
+ SET(EXTRA_INCLUDES ${EXTRA_INCLUDES} ${IPP_INSTALL_DIR}/include)
+ENDIF(ENABLE_TESTS_IPP_API)
+
+IF(ENABLE_TESTS_OPENSSL_API)
+ ADD_COMPILE_OPTIONS("-DUSE_OSSL")
+
+ IF(OPENSSL_INSTALL_DIR)
+ MESSAGE(STATUS "OPENSSL_INSTALL_DIR set, overriding fetch path")
+ ELSE(OPENSSL_INSTALL_DIR)
+ SET(OPENSSL_INSTALL_DIR "${CMAKE_SOURCE_DIR}/external")
+ MESSAGE(STATUS "OPENSSL_INSTALL_DIR not set, defaulting to external")
+ ENDIF(OPENSSL_INSTALL_DIR)
+
+ # If there is OpenSSL, add OpenSSL source and add OpenSSL library
+ SET(EXTRA_SOURCES ${EXTRA_SOURCES} ../../tests/hmac/base/openssl_hmac.cc)
+ IF(UNIX)
+ IF(EXISTS ${OPENSSL_INSTALL_DIR}/lib64/libcrypto.so)
+ SET(LIBS ${LIBS} ${OPENSSL_INSTALL_DIR}/lib64/libcrypto.so)
+ ELSEIF(EXISTS ${OPENSSL_INSTALL_DIR}/lib/libcrypto.so)
+ SET(LIBS ${LIBS} ${OPENSSL_INSTALL_DIR}/lib/libcrypto.so)
+ ELSE()
+ SET(LIBS ${LIBS} ${OPENSSL_INSTALL_DIR}/lib/x86_64-linux-gnu/libcrypto.so)
+ ENDIF()
+ ENDIF(UNIX)
+ IF(WIN32)
+ IF(EXISTS ${OPENSSL_INSTALL_DIR}/lib/libcrypto.lib)
+ INCLUDE_DIRECTORIES(${OPENSSL_INSTALL_DIR}/include)
+ INCLUDE_DIRECTORIES(${OPENSSL_INSTALL_DIR}/bin)
+ SET(LIBS ${LIBS} ${OPENSSL_INSTALL_DIR}/lib/libcrypto.lib)
+ ENDIF()
+ ENDIF(WIN32)
+ SET(EXTRA_INCLUDES ${EXTRA_INCLUDES} ${OPENSSL_INSTALL_DIR}/include)
+ENDIF(ENABLE_TESTS_OPENSSL_API)
+
+ADD_EXECUTABLE(bench_hmac bench_hmac.cc ${ALC_BASE_FILES} ${EXTRA_SOURCES})
+
+TARGET_INCLUDE_DIRECTORIES(bench_hmac PRIVATE
+ "${CMAKE_SOURCE_DIR}/include"
+ "${CMAKE_SOURCE_DIR}/lib/include"
+ "${CMAKE_CURRENT_SOURCE_DIR}/include"
+ "${CMAKE_SOURCE_DIR}/tests/include"
+ "${CMAKE_SOURCE_DIR}/tests/common/include"
+ ${EXTRA_INCLUDES})
+
+TARGET_COMPILE_OPTIONS(bench_hmac PUBLIC ${ALCP_WARNINGS})
+TARGET_LINK_LIBRARIES(bench_hmac ${LIBS})
diff --git a/bench/hmac/bench_hmac.cc b/bench/hmac/bench_hmac.cc
new file mode 100644
index 000000000..88a802e28
--- /dev/null
+++ b/bench/hmac/bench_hmac.cc
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2023, Advanced Micro Devices. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "benchmarks_hmac.hh"
+#include "colors.hh"
+#include "gbench_base.hh"
+
+int
+main(int argc, char** argv)
+{
+ parseArgs(&argc, argv);
+#ifndef USE_IPP
+ if (useipp) {
+ std::cout << RED << "Error IPP not found defaulting to ALCP" << RESET
+ << std::endl;
+ }
+#endif
+#ifndef USE_OSSL
+ if (useossl) {
+ std::cout << RED << "Error OpenSSL not found defaulting to ALCP"
+ << RESET << std::endl;
+ }
+#endif
+ AddBenchmarks();
+ ::benchmark::Initialize(&argc, argv);
+ if (::benchmark::ReportUnrecognizedArguments(argc, argv))
+ return 1;
+ ::benchmark::RunSpecifiedBenchmarks();
+ return 0;
+}
diff --git a/bench/hmac/include/benchmarks_hmac.hh b/bench/hmac/include/benchmarks_hmac.hh
new file mode 100644
index 000000000..1e5dcfe4a
--- /dev/null
+++ b/bench/hmac/include/benchmarks_hmac.hh
@@ -0,0 +1,198 @@
+/*
+ * Copyright (C) 2023, Advanced Micro Devices. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#pragma once
+#include "hmac/alc_hmac.hh"
+#include "hmac/hmac.hh"
+
+#ifdef USE_IPP
+#include "hmac/ipp_hmac.hh"
+#endif
+
+#ifdef USE_OSSL
+#include "hmac/openssl_hmac.hh"
+#endif
+
+#include "gbench_base.hh"
+#include
+#include
+#include
+#include
+
+using namespace alcp::testing;
+
+/* Valid block sizes for performance comparison */
+std::vector hmac_block_sizes = { 16, 64, 256, 1024, 8192, 16384, 32768 };
+
+void inline Hmac_Bench(benchmark::State& state,
+ alc_mac_info_t info,
+ Uint64 block_size,
+ int HmacSize)
+{
+ // In ALCP code, any key size greater than the internal block length of the
+ // SHA used is the hottest path for alcp request. So Using KeySize above
+ // 1024.
+ const int KeySize = 1048;
+ std::vector Hmac(HmacSize / 8, 0);
+ std::vector message(block_size, 0);
+ std::vector Key(KeySize, 0);
+
+ /* Initialize info params based on hmac type */
+ info.mi_type = ALC_MAC_HMAC;
+ info.mi_algoinfo.hmac.hmac_digest.dt_len =
+ static_cast(HmacSize);
+
+ AlcpHmacBase ahb(info);
+ HmacBase* hb = &ahb;
+ alcp_hmac_data_t data;
+#ifdef USE_IPP
+ IPPHmacBase ihb(info);
+ if (useipp) {
+ hb = &ihb;
+ }
+#endif
+
+#ifdef USE_OSSL
+ OpenSSLHmacBase ohb(info);
+ if (useossl) {
+ hb = &ohb;
+ }
+#endif
+
+ data.in.m_msg = &(message[0]);
+ data.in.m_msg_len = message.size();
+ data.out.m_hmac = &(Hmac[0]);
+ data.out.m_hmac_len = Hmac.size();
+ data.in.m_key = &(Key[0]);
+ data.in.m_key_len = Key.size();
+
+ if (!hb->init(info, Key)) {
+ state.SkipWithError("Error in hmac init function");
+ }
+ for (auto _ : state) {
+ if (!hb->Hmac_function(data)) {
+ state.SkipWithError("Error in hmac benchmark function");
+ }
+ if (!hb->reset()) {
+ std::cout << "Error in hmac Reset function" << std::endl;
+ return;
+ }
+ }
+ state.counters["Speed(Bytes/s)"] = benchmark::Counter(
+ state.iterations() * block_size, benchmark::Counter::kIsRate);
+ state.counters["BlockSize(Bytes)"] = block_size;
+ return;
+}
+
+/* add all your new benchmarks here */
+/* SHA2 benchmarks */
+static void
+BENCH_HMAC_SHA2_224(benchmark::State& state)
+{
+ alc_mac_info_t info;
+ info.mi_algoinfo.hmac.hmac_digest.dt_type = ALC_DIGEST_TYPE_SHA2;
+ info.mi_algoinfo.hmac.hmac_digest.dt_mode.dm_sha2 = ALC_SHA2_224;
+ Hmac_Bench(state, info, state.range(0), 224);
+}
+static void
+BENCH_HMAC_SHA2_256(benchmark::State& state)
+{
+ alc_mac_info_t info;
+ info.mi_algoinfo.hmac.hmac_digest.dt_type = ALC_DIGEST_TYPE_SHA2;
+ info.mi_algoinfo.hmac.hmac_digest.dt_mode.dm_sha2 = ALC_SHA2_256;
+ Hmac_Bench(state, info, state.range(0), 256);
+}
+static void
+BENCH_HMAC_SHA2_384(benchmark::State& state)
+{
+ alc_mac_info_t info;
+ info.mi_algoinfo.hmac.hmac_digest.dt_type = ALC_DIGEST_TYPE_SHA2;
+ info.mi_algoinfo.hmac.hmac_digest.dt_mode.dm_sha2 = ALC_SHA2_384;
+ Hmac_Bench(state, info, state.range(0), 384);
+}
+static void
+BENCH_HMAC_SHA2_512(benchmark::State& state)
+{
+ alc_mac_info_t info;
+ info.mi_algoinfo.hmac.hmac_digest.dt_type = ALC_DIGEST_TYPE_SHA2;
+ info.mi_algoinfo.hmac.hmac_digest.dt_mode.dm_sha2 = ALC_SHA2_512;
+ Hmac_Bench(state, info, state.range(0), 512);
+}
+
+/* SHA3 benchmarks */
+static void
+BENCH_HMAC_SHA3_224(benchmark::State& state)
+{
+ alc_mac_info_t info;
+ info.mi_algoinfo.hmac.hmac_digest.dt_type = ALC_DIGEST_TYPE_SHA3;
+ info.mi_algoinfo.hmac.hmac_digest.dt_mode.dm_sha3 = ALC_SHA3_224;
+ Hmac_Bench(state, info, state.range(0), 224);
+}
+static void
+BENCH_HMAC_SHA3_256(benchmark::State& state)
+{
+ alc_mac_info_t info;
+ info.mi_algoinfo.hmac.hmac_digest.dt_type = ALC_DIGEST_TYPE_SHA3;
+ info.mi_algoinfo.hmac.hmac_digest.dt_mode.dm_sha3 = ALC_SHA3_256;
+ Hmac_Bench(state, info, state.range(0), 256);
+}
+static void
+BENCH_HMAC_SHA3_384(benchmark::State& state)
+{
+ alc_mac_info_t info;
+ info.mi_algoinfo.hmac.hmac_digest.dt_type = ALC_DIGEST_TYPE_SHA3;
+ info.mi_algoinfo.hmac.hmac_digest.dt_mode.dm_sha3 = ALC_SHA3_384;
+ Hmac_Bench(state, info, state.range(0), 384);
+}
+static void
+BENCH_HMAC_SHA3_512(benchmark::State& state)
+{
+ alc_mac_info_t info;
+ info.mi_algoinfo.hmac.hmac_digest.dt_type = ALC_DIGEST_TYPE_SHA3;
+ info.mi_algoinfo.hmac.hmac_digest.dt_mode.dm_sha3 = ALC_SHA3_512;
+ Hmac_Bench(state, info, state.range(0), 512);
+}
+
+/* add benchmarks */
+int
+AddBenchmarks()
+{
+ BENCHMARK(BENCH_HMAC_SHA2_224)->ArgsProduct({ hmac_block_sizes });
+ BENCHMARK(BENCH_HMAC_SHA2_256)->ArgsProduct({ hmac_block_sizes });
+ BENCHMARK(BENCH_HMAC_SHA2_384)->ArgsProduct({ hmac_block_sizes });
+ BENCHMARK(BENCH_HMAC_SHA2_512)->ArgsProduct({ hmac_block_sizes });
+
+ /* IPPCP Doesnt support HMAC SHA3 */
+ if (!useipp) {
+ BENCHMARK(BENCH_HMAC_SHA3_224)->ArgsProduct({ hmac_block_sizes });
+ BENCHMARK(BENCH_HMAC_SHA3_256)->ArgsProduct({ hmac_block_sizes });
+ BENCHMARK(BENCH_HMAC_SHA3_384)->ArgsProduct({ hmac_block_sizes });
+ BENCHMARK(BENCH_HMAC_SHA3_512)->ArgsProduct({ hmac_block_sizes });
+ }
+ return 0;
+}
\ No newline at end of file
diff --git a/bench/poly1305/CMakeLists.txt b/bench/poly1305/CMakeLists.txt
new file mode 100644
index 000000000..30a844a10
--- /dev/null
+++ b/bench/poly1305/CMakeLists.txt
@@ -0,0 +1,83 @@
+ # Copyright (C) 2023, Advanced Micro Devices. All rights reserved.
+ #
+ # Redistribution and use in source and binary forms, with or without
+ # modification, are permitted provided that the following conditions are met:
+ # 1. Redistributions of source code must retain the above copyright notice,
+ # this list of conditions and the following disclaimer.
+ # 2. Redistributions in binary form must reproduce the above copyright notice,
+ # this list of conditions and the following disclaimer in the documentation
+ # and/or other materials provided with the distribution.
+ # 3. Neither the name of the copyright holder nor the names of its contributors
+ # may be used to endorse or promote products derived from this software
+ # without specific prior written permission.
+ #
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ # POSSIBILITY OF SUCH DAMAGE.
+
+INCLUDE(FetchContent)
+FetchContent_Declare(gtest
+ GIT_REPOSITORY https://github.com/google/googletest.git
+ GIT_TAG release-1.12.1)
+FetchContent_MakeAvailable(gtest)
+FetchContent_Declare(benchmark
+ GIT_REPOSITORY https://github.com/google/benchmark.git
+ GIT_TAG v1.6.1)
+FetchContent_MakeAvailable(benchmark)
+
+FILE(GLOB ALC_COMMON_SRC ${CMAKE_SOURCE_DIR}/tests/common/base/*.cc)
+SET(ALC_BASE_FILES ${ALC_BASE_FILES} ${ALC_COMMON_SRC} ../../tests/poly1305/base/alc_poly1305.cc ../../tests/poly1305/base/poly1305.cc)
+SET(LIBS ${LIBS} benchmark alcp)
+SET(EXTRA_INCLUDES "")
+
+IF(ENABLE_TESTS_OPENSSL_API)
+ ADD_COMPILE_OPTIONS("-DUSE_OSSL")
+
+ IF(OPENSSL_INSTALL_DIR)
+ MESSAGE(STATUS "OPENSSL_INSTALL_DIR set, overriding fetch path")
+ ELSE(OPENSSL_INSTALL_DIR)
+ SET(OPENSSL_INSTALL_DIR "${CMAKE_SOURCE_DIR}/external")
+ MESSAGE(STATUS "OPENSSL_INSTALL_DIR not set, defaulting to external")
+ ENDIF(OPENSSL_INSTALL_DIR)
+
+ # If there is OpenSSL, add OpenSSL source and add OpenSSL liberary
+ SET(EXTRA_SOURCES ${EXTRA_SOURCES} ../../tests/poly1305/base/openssl_poly1305.cc)
+ IF(UNIX)
+ IF(EXISTS ${OPENSSL_INSTALL_DIR}/lib64/libcrypto.so)
+ SET(LIBS ${LIBS} ${OPENSSL_INSTALL_DIR}/lib64/libcrypto.so)
+ ELSEIF(EXISTS ${OPENSSL_INSTALL_DIR}/lib/libcrypto.so)
+ SET(LIBS ${LIBS} ${OPENSSL_INSTALL_DIR}/lib/libcrypto.so)
+ ELSE()
+ SET(LIBS ${LIBS} ${OPENSSL_INSTALL_DIR}/lib/x86_64-linux-gnu/libcrypto.so)
+ ENDIF()
+ ENDIF(UNIX)
+ IF(WIN32)
+ IF(EXISTS ${OPENSSL_INSTALL_DIR}/lib/libcrypto.lib)
+ INCLUDE_DIRECTORIES(${OPENSSL_INSTALL_DIR}/include)
+ INCLUDE_DIRECTORIES(${OPENSSL_INSTALL_DIR}/bin)
+ SET(LIBS ${LIBS} ${OPENSSL_INSTALL_DIR}/lib/libcrypto.lib)
+ ENDIF()
+ ENDIF(WIN32)
+ SET(EXTRA_INCLUDES ${EXTRA_INCLUDES} ${OPENSSL_INSTALL_DIR}/include)
+ENDIF(ENABLE_TESTS_OPENSSL_API)
+
+ADD_EXECUTABLE(bench_poly1305 bench_poly1305.cc ${ALC_BASE_FILES} ${EXTRA_SOURCES})
+
+TARGET_INCLUDE_DIRECTORIES(bench_poly1305 PRIVATE
+ "${CMAKE_SOURCE_DIR}/include"
+ "${CMAKE_SOURCE_DIR}/lib/include"
+ "${CMAKE_CURRENT_SOURCE_DIR}/include"
+ "${CMAKE_SOURCE_DIR}/tests/include"
+ "${CMAKE_SOURCE_DIR}/tests/common/include"
+ ${EXTRA_INCLUDES})
+
+TARGET_COMPILE_OPTIONS(bench_poly1305 PUBLIC ${ALCP_WARNINGS})
+TARGET_LINK_LIBRARIES(bench_poly1305 ${LIBS})
diff --git a/bench/poly1305/bench_poly1305.cc b/bench/poly1305/bench_poly1305.cc
new file mode 100644
index 000000000..a6fb27d80
--- /dev/null
+++ b/bench/poly1305/bench_poly1305.cc
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2023, Advanced Micro Devices. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "bench_poly1305.hh"
+#include "colors.hh"
+#include "gbench_base.hh"
+
+int
+main(int argc, char** argv)
+{
+ parseArgs(&argc, argv);
+#ifndef USE_OSSL
+ if (useossl) {
+ std::cout << RED << "Error OpenSSL not found defaulting to ALCP"
+ << RESET << std::endl;
+ }
+#endif
+ AddBenchmarks_Poly1305();
+ ::benchmark::Initialize(&argc, argv);
+ if (::benchmark::ReportUnrecognizedArguments(argc, argv))
+ return 1;
+ ::benchmark::RunSpecifiedBenchmarks();
+ return 0;
+}
diff --git a/bench/poly1305/include/bench_poly1305.hh b/bench/poly1305/include/bench_poly1305.hh
new file mode 100644
index 000000000..8c193c433
--- /dev/null
+++ b/bench/poly1305/include/bench_poly1305.hh
@@ -0,0 +1,118 @@
+/*
+ * Copyright (C) 2023, Advanced Micro Devices. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#pragma once
+#include "poly1305/alc_poly1305.hh"
+#include "poly1305/poly1305.hh"
+
+#ifdef USE_IPP
+#include "poly1305/ipp_poly1305.hh"
+#endif
+
+#ifdef USE_OSSL
+#include "poly1305/openssl_poly1305.hh"
+#endif
+
+#include "gbench_base.hh"
+#include
+#include
+#include
+#include
+
+using namespace alcp::testing;
+
+/* Valid block sizes for performance comparison */
+std::vector poly1305_blocksizes = {
+ 16, 64, 256, 1024, 8192, 16384, 32768
+};
+
+void inline Poly1305_Bench(benchmark::State& state,
+ alc_mac_info_t info,
+ Uint64 block_size,
+ Uint64 KeySize)
+{
+
+ /* MAX len of poly1305 would be 128 bits */
+ const int macSize = 16;
+ std::vector poly1305_mac(macSize, 0);
+ std::vector msg(block_size);
+ std::vector Key(KeySize);
+
+ /* Initialize info params based on poly1305 type */
+ info.mi_type = ALC_MAC_POLY1305;
+
+ AlcpPoly1305Base apb(info);
+ Poly1305Base* pb = &apb;
+ alcp_poly1305_data_t data{};
+
+#ifdef USE_OSSL
+ OpenSSLPoly1305Base opb(info);
+ if (useossl) {
+ pb = &opb;
+ }
+#endif
+
+ data.m_msg = &(msg[0]);
+ data.m_msg_len = msg.size();
+ data.m_mac = &(poly1305_mac[0]);
+ data.m_mac_len = poly1305_mac.size();
+ data.m_key = &(Key[0]);
+ data.m_key_len = Key.size();
+
+ if (!pb->init(info, Key)) {
+ state.SkipWithError("Error in poly1305 init function");
+ }
+ for (auto _ : state) {
+ if (!pb->mac(data)) {
+ state.SkipWithError("Error in poly1305 bench function");
+ }
+ }
+ state.counters["Speed(Bytes/s)"] = benchmark::Counter(
+ state.iterations() * block_size, benchmark::Counter::kIsRate);
+ state.counters["BlockSize(Bytes)"] = block_size;
+ return;
+}
+
+/* add all your new benchmarks here */
+/* POLY1305 benchmarks */
+static void
+BENCH_POLY1305(benchmark::State& state)
+{
+ alc_mac_info_t info;
+ Poly1305_Bench(state, info, state.range(0), 32);
+}
+
+/* add benchmarks */
+int
+AddBenchmarks_Poly1305()
+{
+ /* ippcp doesnt have poly1305 mac implementations yet */
+ if (!useipp)
+ BENCHMARK(BENCH_POLY1305)->ArgsProduct({ poly1305_blocksizes });
+ return 0;
+}
\ No newline at end of file
diff --git a/bench/rsa/CMakeLists.txt b/bench/rsa/CMakeLists.txt
new file mode 100644
index 000000000..1567c72c1
--- /dev/null
+++ b/bench/rsa/CMakeLists.txt
@@ -0,0 +1,128 @@
+ # Copyright (C) 2023, Advanced Micro Devices. All rights reserved.
+ #
+ # Redistribution and use in source and binary forms, with or without
+ # modification, are permitted provided that the following conditions are met:
+ # 1. Redistributions of source code must retain the above copyright notice,
+ # this list of conditions and the following disclaimer.
+ # 2. Redistributions in binary form must reproduce the above copyright notice,
+ # this list of conditions and the following disclaimer in the documentation
+ # and/or other materials provided with the distribution.
+ # 3. Neither the name of the copyright holder nor the names of its contributors
+ # may be used to endorse or promote products derived from this software
+ # without specific prior written permission.
+ #
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ # POSSIBILITY OF SUCH DAMAGE.
+
+INCLUDE(FetchContent)
+FetchContent_Declare(gtest
+ GIT_REPOSITORY https://github.com/google/googletest.git
+ GIT_TAG release-1.12.1)
+FetchContent_MakeAvailable(gtest)
+FetchContent_Declare(benchmark
+ GIT_REPOSITORY https://github.com/google/benchmark.git
+ GIT_TAG v1.6.1)
+FetchContent_MakeAvailable(benchmark)
+
+FILE(GLOB ALC_COMMON_SRC ${CMAKE_SOURCE_DIR}/tests/common/base/*.cc)
+SET(ALC_BASE_FILES ${ALC_BASE_FILES} ${ALC_COMMON_SRC} ../../tests/rsa/base/alc_rsa.cc)
+SET(LIBS ${LIBS} benchmark alcp)
+SET(EXTRA_INCLUDES "")
+
+IF(ENABLE_TESTS_IPP_API)
+ ADD_COMPILE_OPTIONS("-DUSE_IPP")
+
+ IF(IPP_INSTALL_DIR)
+ MESSAGE(STATUS "IPP_INSTALL_DIR set, overriding fetch path")
+ ELSE(IPP_INSTALL_DIR)
+ SET(IPP_INSTALL_DIR "${CMAKE_SOURCE_DIR}/external")
+ MESSAGE(STATUS "IPP_INSTALL_DIR not set, defaulting to external")
+ ENDIF(IPP_INSTALL_DIR)
+
+ # If there is IPP, add IPP source and add IPP library
+ SET(EXTRA_SOURCES ${EXTRA_SOURCES} ../../tests/rsa/base/ipp_rsa.cc)
+ IF(UNIX)
+ IF(EXISTS ${IPP_INSTALL_DIR}/lib/intel64/libippcp.so)
+ SET(LIBS ${LIBS} ${IPP_INSTALL_DIR}/lib/intel64/libippcp.so)
+ ELSE(EXISTS ${IPP_INSTALL_DIR}/lib/intel/libippcp.so)
+ SET(LIBS ${LIBS} ${IPP_INSTALL_DIR}/lib/intel/libippcp.so)
+ ENDIF(EXISTS ${IPP_INSTALL_DIR}/lib/intel64/libippcp.so)
+ # for ECC functions
+ IF(EXISTS ${IPP_INSTALL_DIR}/lib/intel64/libcrypto_mb.so)
+ SET(LIBS ${LIBS} ${IPP_INSTALL_DIR}/lib/intel64/libcrypto_mb.so)
+ ELSE(EXISTS ${IPP_INSTALL_DIR}/lib/intel/libcrypto_mb.so)
+ SET(LIBS ${LIBS} ${IPP_INSTALL_DIR}/lib/intel/libcrypto_mb.so)
+ ENDIF(EXISTS ${IPP_INSTALL_DIR}/lib/intel64/libcrypto_mb.so)
+ ENDIF(UNIX)
+ IF(WIN32)
+ IF(EXISTS ${IPP_INSTALL_DIR}/lib/intel64/ippcp.lib)
+ SET(LIBS ${LIBS} ${IPP_INSTALL_DIR}/lib/intel64/ippcp.lib)
+ ELSEIF(EXISTS ${IPP_INSTALL_DIR}/lib/intel/ippcp.lib)
+ SET(LIBS ${LIBS} ${IPP_INSTALL_DIR}/lib/intel/ippcp.lib)
+ ELSE(EXISTS ${IPP_INSTALL_DIR}/lib/ippcp.lib)
+ SET(LIBS ${LIBS} ${IPP_INSTALL_DIR}/lib/ippcp.lib)
+ ENDIF(EXISTS ${IPP_INSTALL_DIR}/lib/intel64/ippcp.lib)
+ # for ECC functions
+ IF(EXISTS ${IPP_INSTALL_DIR}/lib/intel64/crypto_mb.lib)
+ SET(LIBS ${LIBS} ${IPP_INSTALL_DIR}/lib/intel64/crypto_mb.lib)
+ ELSEIF(EXISTS ${IPP_INSTALL_DIR}/lib/intel/crypto_mb.lib)
+ SET(LIBS ${LIBS} ${IPP_INSTALL_DIR}/lib/intel/crypto_mb.lib)
+ ELSE(EXISTS ${IPP_INSTALL_DIR}/lib/crypto_mb.lib)
+ SET(LIBS ${LIBS} ${IPP_INSTALL_DIR}/lib/crypto_mb.lib)
+ ENDIF(EXISTS ${IPP_INSTALL_DIR}/lib/intel64/crypto_mb.lib)
+ ENDIF(WIN32)
+ SET(EXTRA_INCLUDES ${EXTRA_INCLUDES} ${IPP_INSTALL_DIR}/include)
+ENDIF(ENABLE_TESTS_IPP_API)
+
+IF(ENABLE_TESTS_OPENSSL_API)
+ ADD_COMPILE_OPTIONS("-DUSE_OSSL")
+
+ IF(OPENSSL_INSTALL_DIR)
+ MESSAGE(STATUS "OPENSSL_INSTALL_DIR set, overriding fetch path")
+ ELSE(OPENSSL_INSTALL_DIR)
+ SET(OPENSSL_INSTALL_DIR "${CMAKE_SOURCE_DIR}/external")
+ MESSAGE(STATUS "OPENSSL_INSTALL_DIR not set, defaulting to external")
+ ENDIF(OPENSSL_INSTALL_DIR)
+
+ # If there is OpenSSL, add OpenSSL source and add OpenSSL liberary
+ SET(EXTRA_SOURCES ${EXTRA_SOURCES} ../../tests/rsa/base/openssl_rsa.cc)
+ IF(UNIX)
+ IF(EXISTS ${OPENSSL_INSTALL_DIR}/lib64/libcrypto.so)
+ SET(LIBS ${LIBS} ${OPENSSL_INSTALL_DIR}/lib64/libcrypto.so)
+ ELSEIF(EXISTS ${OPENSSL_INSTALL_DIR}/lib/libcrypto.so)
+ SET(LIBS ${LIBS} ${OPENSSL_INSTALL_DIR}/lib/libcrypto.so)
+ ELSE()
+ SET(LIBS ${LIBS} ${OPENSSL_INSTALL_DIR}/lib/x86_64-linux-gnu/libcrypto.so)
+ ENDIF()
+ ENDIF(UNIX)
+ IF(WIN32)
+ IF(EXISTS ${OPENSSL_INSTALL_DIR}/lib/libcrypto.lib)
+ INCLUDE_DIRECTORIES(${OPENSSL_INSTALL_DIR}/include)
+ INCLUDE_DIRECTORIES(${OPENSSL_INSTALL_DIR}/bin)
+ SET(LIBS ${LIBS} ${OPENSSL_INSTALL_DIR}/lib/libcrypto.lib)
+ ENDIF()
+ ENDIF(WIN32)
+ SET(EXTRA_INCLUDES ${EXTRA_INCLUDES} ${OPENSSL_INSTALL_DIR}/include)
+ENDIF(ENABLE_TESTS_OPENSSL_API)
+
+ADD_EXECUTABLE(bench_rsa bench_rsa.cc ${ALC_BASE_FILES} ${EXTRA_SOURCES})
+
+TARGET_INCLUDE_DIRECTORIES(bench_rsa PRIVATE
+ "${CMAKE_SOURCE_DIR}/include"
+ "${CMAKE_SOURCE_DIR}/lib/include"
+ "${CMAKE_CURRENT_SOURCE_DIR}/include"
+ "${CMAKE_SOURCE_DIR}/tests/include"
+ "${CMAKE_SOURCE_DIR}/tests/common/include"
+ ${EXTRA_INCLUDES})
+
+TARGET_COMPILE_OPTIONS(bench_rsa PUBLIC ${ALCP_WARNINGS})
+TARGET_LINK_LIBRARIES(bench_rsa ${LIBS})
diff --git a/bench/rsa/bench_rsa.cc b/bench/rsa/bench_rsa.cc
new file mode 100644
index 000000000..4c8ecdbea
--- /dev/null
+++ b/bench/rsa/bench_rsa.cc
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2023, Advanced Micro Devices. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "benchmarks_rsa.hh"
+#include "colors.hh"
+#include "gbench_base.hh"
+
+int
+main(int argc, char** argv)
+{
+ parseArgs(&argc, argv);
+#ifndef USE_IPP
+ if (useipp) {
+ std::cout << RED << "Error IPP not found defaulting to ALCP" << RESET
+ << std::endl;
+ }
+#endif
+#ifndef USE_OSSL
+ if (useossl) {
+ std::cout << RED << "Error OpenSSL not found defaulting to ALCP"
+ << RESET << std::endl;
+ }
+#endif
+ AddBenchmarks_rsa();
+ ::benchmark::Initialize(&argc, argv);
+ if (::benchmark::ReportUnrecognizedArguments(argc, argv))
+ return 1;
+ ::benchmark::RunSpecifiedBenchmarks();
+ return 0;
+}
diff --git a/bench/rsa/include/benchmarks_rsa.hh b/bench/rsa/include/benchmarks_rsa.hh
new file mode 100644
index 000000000..613b14d38
--- /dev/null
+++ b/bench/rsa/include/benchmarks_rsa.hh
@@ -0,0 +1,245 @@
+/*
+ * Copyright (C) 2023, Advanced Micro Devices. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#pragma once
+
+#include "alcp/alcp.h"
+#include "gbench_base.hh"
+#include "rng_base.hh"
+#include "rsa/alc_rsa.hh"
+#include "rsa/rsa.hh"
+#include
+#include
+#include
+
+#ifdef USE_IPP
+#include "rsa/ipp_rsa.hh"
+#endif
+
+#ifdef USE_OSSL
+#include "rsa/openssl_rsa.hh"
+#endif
+
+using namespace alcp::testing;
+
+typedef enum
+{
+ RSA_BENCH_ENC_PUB_KEY = 0,
+ RSA_BENCH_DEC_PVT_KEY = 1
+} rsa_bench_opt;
+
+std::vector rsa_key_sizes = { 1024, 2048 };
+
+/* bench function */
+inline int
+Rsa_Bench(benchmark::State& state,
+ rsa_bench_opt opt,
+ int padding_mode,
+ int KeySize,
+ const alc_digest_info_t dinfo,
+ const alc_digest_info_t mgfinfo)
+{
+ int InputSize;
+ /* Keysize is in bits */
+ KeySize = KeySize / 8;
+ alcp_rsa_data_t data;
+
+ AlcpRsaBase arb;
+ std::string LibStr = "ALCP";
+ RsaBase* rb;
+ RngBase rngb;
+
+ rb = &arb;
+
+#ifdef USE_OSSL
+ OpenSSLRsaBase orb;
+ if (useossl == true) {
+ rb = &orb;
+ LibStr = "OpenSSL";
+ }
+#endif
+
+#ifdef USE_IPP
+ IPPRsaBase irb;
+ if (useipp == true) {
+ rb = &irb;
+ LibStr = "IPP";
+ }
+#endif
+
+ if (padding_mode == 1) {
+ rb->m_padding_mode = ALCP_TEST_RSA_PADDING;
+ /* input size should be 0 to m_key_size - 2 * m_hash_len - 2*/
+ if (KeySize == 128) {
+ InputSize = 62;
+ } else
+ InputSize = 47;
+ } else {
+ rb->m_padding_mode = ALCP_TEST_RSA_NO_PADDING;
+ InputSize = KeySize;
+ }
+ /*FIXME: keeping input const for now, a valid data for now */
+ std::vector input_data(InputSize, 30);
+ std::vector encrypted_data(KeySize);
+ std::vector decrypted_data(KeySize);
+ std::vector PubKeyKeyMod(KeySize);
+
+ data.m_msg = &(input_data[0]);
+ data.m_pub_key_mod = &(PubKeyKeyMod[0]);
+ data.m_encrypted_data = &(encrypted_data[0]);
+ data.m_decrypted_data = &(decrypted_data[0]);
+ data.m_msg_len = input_data.size();
+ data.m_key_len = KeySize;
+
+ rb->m_key_len = KeySize;
+ rb->m_digest_info = dinfo;
+ rb->m_mgf_info = mgfinfo;
+ rb->m_hash_len = dinfo.dt_len / 8;
+
+ /* seed and label for padding mode */
+ std::vector seed(rb->m_hash_len);
+ data.m_pseed = &(seed[0]);
+ std::vector label(5);
+ data.m_label = &(label[0]);
+ data.m_label_size = label.size();
+
+ if (!rb->init()) {
+ state.SkipWithError("Error in RSA init");
+ }
+ if (!rb->SetPublicKey(data)) {
+ state.SkipWithError("Error in RSA SetPublicKey");
+ }
+ if (!rb->SetPrivateKey(data)) {
+ state.SkipWithError("Error in RSA SetPrivateKey");
+ }
+
+ if (opt == RSA_BENCH_ENC_PUB_KEY) {
+ for (auto _ : state) {
+ if (0 != rb->EncryptPubKey(data)) {
+ state.SkipWithError("Error in RSA EncryptPubKey");
+ }
+ }
+ } else if (opt == RSA_BENCH_DEC_PVT_KEY) {
+ /* encrypt, then benchmark only dec pvt key */
+ if (0 != rb->EncryptPubKey(data)) {
+ state.SkipWithError("Error in RSA EncryptPubKey");
+ }
+ /* benchmark only this */
+ for (auto _ : state) {
+ if (0 != rb->DecryptPvtKey(data)) {
+ state.SkipWithError("Error in RSA DecryptPvtKey");
+ }
+ }
+ }
+
+ std::string sResultUnit = (opt == RSA_BENCH_ENC_PUB_KEY) ? "Encryptions/Sec"
+ : (opt == RSA_BENCH_DEC_PVT_KEY)
+ ? "Decryptions/Sec"
+ : "";
+ state.counters[sResultUnit] =
+ benchmark::Counter(state.iterations(), benchmark::Counter::kIsRate);
+ return 0;
+}
+
+static void
+BENCH_RSA_DecryptPvtKey_Padding(benchmark::State& state)
+{
+ alc_digest_info_t dinfo, mgfinfo;
+ dinfo.dt_mode.dm_sha2 = ALC_SHA2_256;
+ dinfo.dt_len = ALC_DIGEST_LEN_256;
+ dinfo.dt_type = ALC_DIGEST_TYPE_SHA2;
+ mgfinfo = dinfo;
+ benchmark::DoNotOptimize(Rsa_Bench(state,
+ RSA_BENCH_DEC_PVT_KEY,
+ ALCP_TEST_RSA_PADDING,
+ state.range(0),
+ dinfo,
+ mgfinfo));
+}
+
+static void
+BENCH_RSA_DecryptPvtKey_NoPadding(benchmark::State& state)
+{
+ alc_digest_info_t dinfo, mgfinfo;
+ dinfo.dt_mode.dm_sha2 = ALC_SHA2_256;
+ dinfo.dt_len = ALC_DIGEST_LEN_256;
+ dinfo.dt_type = ALC_DIGEST_TYPE_SHA2;
+ mgfinfo = dinfo;
+ benchmark::DoNotOptimize(Rsa_Bench(state,
+ RSA_BENCH_DEC_PVT_KEY,
+ ALCP_TEST_RSA_NO_PADDING,
+ state.range(0),
+ dinfo,
+ mgfinfo));
+}
+
+static void
+BENCH_RSA_EncryptPubKey_Padding(benchmark::State& state)
+{
+ alc_digest_info_t dinfo, mgfinfo;
+ dinfo.dt_mode.dm_sha2 = ALC_SHA2_256;
+ dinfo.dt_len = ALC_DIGEST_LEN_256;
+ dinfo.dt_type = ALC_DIGEST_TYPE_SHA2;
+ mgfinfo = dinfo;
+ benchmark::DoNotOptimize(Rsa_Bench(state,
+ RSA_BENCH_ENC_PUB_KEY,
+ ALCP_TEST_RSA_PADDING,
+ state.range(0),
+ dinfo,
+ mgfinfo));
+}
+
+static void
+BENCH_RSA_EncryptPubKey_NoPadding(benchmark::State& state)
+{
+ alc_digest_info_t dinfo, mgfinfo;
+ dinfo.dt_mode.dm_sha2 = ALC_SHA2_256;
+ dinfo.dt_len = ALC_DIGEST_LEN_256;
+ dinfo.dt_type = ALC_DIGEST_TYPE_SHA2;
+ mgfinfo = dinfo;
+ benchmark::DoNotOptimize(Rsa_Bench(state,
+ RSA_BENCH_ENC_PUB_KEY,
+ ALCP_TEST_RSA_NO_PADDING,
+ state.range(0),
+ dinfo,
+ mgfinfo));
+}
+
+/* add new benchmarks here */
+int
+AddBenchmarks_rsa()
+{
+ BENCHMARK(BENCH_RSA_EncryptPubKey_NoPadding)
+ ->ArgsProduct({ rsa_key_sizes });
+ BENCHMARK(BENCH_RSA_DecryptPvtKey_NoPadding)
+ ->ArgsProduct({ rsa_key_sizes });
+ BENCHMARK(BENCH_RSA_EncryptPubKey_Padding)->ArgsProduct({ rsa_key_sizes });
+ BENCHMARK(BENCH_RSA_DecryptPvtKey_Padding)->ArgsProduct({ rsa_key_sizes });
+
+ return 0;
+}
\ No newline at end of file
diff --git a/cmake/AlcpConfig.cmake b/cmake/AlcpConfig.cmake
index 7793f9732..6a48bfe77 100644
--- a/cmake/AlcpConfig.cmake
+++ b/cmake/AlcpConfig.cmake
@@ -41,7 +41,7 @@ FUNCTION(GEN_CONF)
INVERTBOOLEAN("ALCP_CONFIG_LITTLE_ENDIAN" ALCP_CONFIG_LITTLE_ENDIAN)
# Keeping Command line variable same.
- SET(ALCP_ENABLE_AOCL_CPUID ${ENABLE_AOCL_CPUID})
+ SET(ALCP_ENABLE_AOCL_UTILS ${ENABLE_AOCL_UTILS})
IF (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
SET(COMPILER_IS_CLANG ON)
@@ -68,6 +68,26 @@ FUNCTION(GEN_CONF)
ENDIF()
ENDIF(ALCP_BUILD_OS_WINDOWS)
+
+ # CPUID OVERRIDE FLAGS
+ IF(ALCP_CPUID_FORCE)
+ IF(${ALCP_CPUID_FORCE} STREQUAL "ZEN")
+ SET(ALCP_CPUID_DISABLE_AVX512 ON)
+ SET(ALCP_CPUID_DISABLE_VAES ON)
+ SET(ALCP_CPUID_FORCE_ZEN ON)
+ ELSEIF(${ALCP_CPUID_FORCE} STREQUAL "ZEN2")
+ SET(ALCP_CPUID_DISABLE_AVX512 ON)
+ SET(ALCP_CPUID_DISABLE_VAES ON)
+ SET(ALCP_CPUID_FORCE_ZEN2 ON)
+ ELSEIF(${ALCP_CPUID_FORCE} STREQUAL "ZEN3")
+ SET(ALCP_CPUID_DISABLE_AVX512 ON)
+ SET(ALCP_CPUID_FORCE_ZEN3 ON)
+ ELSEIF(${ALCP_CPUID_FORCE} STREQUAL "ZEN4")
+ SET(ALCP_CPUID_DISABLE_ZEN ON)
+ SET(ALCP_CPUID_FORCE_ZEN4 ON)
+ ENDIF()
+ ENDIF(ALCP_CPUID_FORCE)
+
# CONFIGURE A HEADER FILE TO PASS SOME OF THE CMAKE SETTINGS
# TO THE SOURCE CODE
IF(ALCP_BUILD_OS_LINUX)
@@ -76,4 +96,5 @@ FUNCTION(GEN_CONF)
IF(ALCP_BUILD_OS_WINDOWS)
configure_file(${CMAKE_SOURCE_DIR}/include/alcp/config.h.in ${CMAKE_SOURCE_DIR}/include/config.h WIN32)
ENDIF(ALCP_BUILD_OS_WINDOWS)
+
ENDFUNCTION()
diff --git a/cmake/AlcpTests.cmake b/cmake/AlcpTests.cmake
index 42538870c..c860716b0 100644
--- a/cmake/AlcpTests.cmake
+++ b/cmake/AlcpTests.cmake
@@ -118,7 +118,9 @@ function(alcp_cc_test testName)
if(${ALCP_MODULE} STREQUAL "Cipher")
SET(TEST_COMMON_SRC ${TEST_COMMON_SRC}
${CMAKE_SOURCE_DIR}/tests/cipher/base/alc_cipher.cc
+ ${CMAKE_SOURCE_DIR}/tests/cipher/base/alc_cipher_aead.cc
${CMAKE_SOURCE_DIR}/tests/cipher/base/cipher.cc
+ ${UNIT_TEST_COMMON_SRCS}
)
endif()
@@ -143,6 +145,7 @@ function(alcp_cc_test testName)
target_include_directories(${_target_name} PRIVATE ${CMAKE_SOURCE_DIR}/tests/include)
target_include_directories(${_target_name} PRIVATE ${CMAKE_SOURCE_DIR}/tests/common/include)
target_include_directories(${_target_name} PRIVATE ${CMAKE_SOURCE_DIR}/lib/include)
+ target_include_directories(${_target_name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/common/include)
#set_property(TARGET ${_target_name}
# PROPERTY FOLDER "${alcp_IDE_FOLDER}/Tests")
diff --git a/cmake/AlcpUtils.cmake b/cmake/AlcpUtils.cmake
index 0a5d7eb89..da58f55d4 100644
--- a/cmake/AlcpUtils.cmake
+++ b/cmake/AlcpUtils.cmake
@@ -1,4 +1,4 @@
-# Copyright (C) 2022-2023, Advanced Micro Devices. All rights reserved.
+# Copyright (C) 2023, Advanced Micro Devices. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
diff --git a/cmake/CompilerLinux.cmake b/cmake/CompilerLinux.cmake
index 3e071e7c8..d9a821dbc 100644
--- a/cmake/CompilerLinux.cmake
+++ b/cmake/CompilerLinux.cmake
@@ -110,7 +110,7 @@ endfunction(alcp_get_arch_cflags_zen)
# lib/arch/zen3 Compile Flags
function(alcp_get_arch_cflags_zen3)
set(ARCH_COMPILE_FLAGS
- -fPIC -march=znver3 -mavx -mavx2 -maes -mvaes -mpclmul -mvpclmulqdq
+ -O3 -fPIC -march=znver3 -mavx -mavx2 -maes -mvaes -mpclmul -mvpclmulqdq
CACHE INTERNAL ""
)
set(ARCH_COMPILE_FLAGS ${ARCH_COMPILE_FLAGS} PARENT_SCOPE)
@@ -134,12 +134,17 @@ function(alcp_get_arch_cflags_zen4)
endfunction(alcp_get_arch_cflags_zen4)
# misc options
-# TO DO:
-# these sanitizer options are currently defined for gcc
-# Maybe different for clang!!
-
-# if address sanitizer used
+# sanitizer options
function(alcp_add_sanitize_flags)
+ # memory sanitizer supported only by clang
+ set (ALCP_SANITIZE_OPTIONS_CLANG
+ -fsanitize=memory
+ -fsanitize-memory-track-origins
+ -fPIC
+ -fno-omit-frame-pointer
+ CACHE INTERNAL ""
+ )
+
set(ALCP_OPTIONS_SANITIZE
-fsanitize=address
-fsanitize=undefined
@@ -147,9 +152,18 @@ function(alcp_add_sanitize_flags)
-fsanitize=pointer-compare
CACHE INTERNAL ""
)
- link_libraries(asan)
- add_compile_options(${ALCP_OPTIONS_SANITIZE})
- add_link_options(${ALCP_OPTIONS_SANITIZE})
+
+ # now check compiler and link to asan libs
+ add_compile_definitions(ALCP_COMPILE_OPTIONS_SANITIZE)
+
+ if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
+ link_libraries(asan)
+ add_compile_options(${ALCP_OPTIONS_SANITIZE})
+ add_link_options(${ALCP_OPTIONS_SANITIZE})
+ elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
+ add_compile_options(${ALCP_SANITIZE_OPTIONS_CLANG})
+ add_link_options(${ALCP_SANITIZE_OPTIONS_CLANG})
+ endif()
endfunction(alcp_add_sanitize_flags)
# coverage
diff --git a/cmake/CompilerWin.cmake b/cmake/CompilerWin.cmake
index a8af4ea9a..1bf640102 100644
--- a/cmake/CompilerWin.cmake
+++ b/cmake/CompilerWin.cmake
@@ -1,4 +1,4 @@
- # Copyright (C) 2021-2023, Advanced Micro Devices. All rights reserved.
+ # Copyright (C) 2022-2023, Advanced Micro Devices. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
@@ -111,9 +111,20 @@ function(alcp_add_sanitize_flags)
set(ALCP_OPTIONS_SANITIZE
-fsanitize=address
-fsanitize=undefined
+ -fsanitize=nullability
CACHE INTERNAL ""
)
- add_compile_options(${ALCP_OPTIONS_SANITIZE} -fno-sanitize=address)
- link_libraries(clang_rt.asan_dynamic-x86_64 clang_rt.asan_dynamic_runtime_thunk-x86_64)
- add_link_options(/wholearchive:clang_rt.asan_dynamic_runtime_thunk-x86_64.lib)
-endfunction(alcp_add_sanitize_flags)
\ No newline at end of file
+ link_libraries(clang_rt.asan_dynamic-x86_64)
+ add_compile_options(${ALCP_OPTIONS_SANITIZE} -fno-sanitize=address /Zi /Od)
+endfunction(alcp_add_sanitize_flags)
+
+#coverage
+function(alcp_add_coverage_flags)
+ set(ALCP_CFLAGS_COV
+ --coverage
+ CACHE INTERNAL ""
+ )
+ link_libraries(clang_rt.profile-x86_64.lib)
+ set(CMAKE_CXX_OUTPUT_EXTENSION_REPLACE ON)
+ add_compile_options(${ALCP_CFLAGS_COV} /Od)
+endfunction(alcp_add_coverage_flags)
\ No newline at end of file
diff --git a/cmake/IntegrationTests.cmake b/cmake/IntegrationTests.cmake
new file mode 100644
index 000000000..1f13b6621
--- /dev/null
+++ b/cmake/IntegrationTests.cmake
@@ -0,0 +1,148 @@
+# Copyright (C) 2023, Advanced Micro Devices. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+# 1. Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+# 3. Neither the name of the copyright holder nor the names of its contributors
+# may be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+INCLUDE(FetchContent)
+INCLUDE(GoogleTest)
+FetchContent_Declare(gtest
+ GIT_REPOSITORY https://github.com/google/googletest.git
+ GIT_TAG release-1.12.1)
+FetchContent_MakeAvailable(gtest)
+
+FILE(GLOB COMMON_SRCS ${CMAKE_SOURCE_DIR}/tests/common/base/*.cc)
+# SET(COMMON_SRCS ${COMMON_SRCS} PARENT_SCOPE)
+
+SET(LIBS ${LIBS} gtest alcp)
+
+SET(ALCP_TEST_INCLUDES "${CMAKE_SOURCE_DIR}/include"
+ "${CMAKE_SOURCE_DIR}/lib/include"
+ "${CMAKE_SOURCE_DIR}/tests/include"
+ "${CMAKE_SOURCE_DIR}/tests/common/include"
+ )
+
+IF (POLICY CMP0079) # Visibility
+ cmake_policy(SET CMP0079 NEW)
+ENDIF (POLICY CMP0079)
+
+IF(WIN32)
+target_link_libraries(gmock PUBLIC gtest)
+target_link_libraries(gmock_main PUBLIC gtest_main)
+ENDIF()
+
+function(add_openssl)
+ IF(ENABLE_TESTS_OPENSSL_API)
+ ADD_COMPILE_OPTIONS("-DUSE_OSSL")
+
+ IF(OPENSSL_INSTALL_DIR)
+ MESSAGE(STATUS "OPENSSL_INSTALL_DIR set, overriding fetch path")
+ ELSE(OPENSSL_INSTALL_DIR)
+ SET(OPENSSL_INSTALL_DIR "${CMAKE_SOURCE_DIR}/external")
+ MESSAGE(STATUS "OPENSSL_INSTALL_DIR not set, defaulting to external")
+ ENDIF(OPENSSL_INSTALL_DIR)
+
+ # If there is OpenSSL, add OpenSSL source and add OpenSSL liberary
+ SET(OPENSSL_SOURCES ${OPENSSL_CIPHER_FWK_SRCS} PARENT_SCOPE)
+ IF(UNIX)
+ IF(EXISTS ${OPENSSL_INSTALL_DIR}/lib64/libcrypto.so)
+ SET(OPENSSL_LIBS ${OPENSSL_LIBS} ${OPENSSL_INSTALL_DIR}/lib64/libcrypto.so)
+ ELSEIF(EXISTS ${OPENSSL_INSTALL_DIR}/lib/libcrypto.so)
+ SET(OPENSSL_LIBS ${OPENSSL_LIBS} ${OPENSSL_INSTALL_DIR}/lib/libcrypto.so)
+ ELSE()
+ SET(OPENSSL_LIBS ${OPENSSL_LIBS} ${OPENSSL_INSTALL_DIR}/lib/x86_64-linux-gnu/libcrypto.so)
+ ENDIF()
+ ENDIF(UNIX)
+ IF(WIN32)
+ IF(EXISTS ${OPENSSL_INSTALL_DIR}/lib/libcrypto.lib)
+ INCLUDE_DIRECTORIES(${OPENSSL_INSTALL_DIR}/include)
+ INCLUDE_DIRECTORIES(${OPENSSL_INSTALL_DIR}/bin)
+ SET(OPENSSL_LIBS ${OPENSSL_LIBS} ${OPENSSL_INSTALL_DIR}/lib/libcrypto.lib)
+ ENDIF()
+ ENDIF(WIN32)
+ SET(OPENSSL_INCLUDES ${OPENSSL_INSTALL_DIR}/include PARENT_SCOPE)
+ SET(OPENSSL_LIBS ${OPENSSL_LIBS} PARENT_SCOPE)
+ ENDIF(ENABLE_TESTS_OPENSSL_API)
+endfunction(add_openssl)
+
+function(add_ipp)
+ IF(ENABLE_TESTS_IPP_API)
+ ADD_COMPILE_OPTIONS("-DUSE_IPP")
+
+ IF(IPP_INSTALL_DIR)
+ MESSAGE(STATUS "IPP_INSTALL_DIR set, overriding fetch path")
+ ELSE(IPP_INSTALL_DIR)
+ SET(IPP_INSTALL_DIR "${CMAKE_SOURCE_DIR}/external")
+ MESSAGE(STATUS "IPP_INSTALL_DIR not set, defaulting to external")
+ ENDIF(IPP_INSTALL_DIR)
+
+ # If there is IPP, add IPP source and add IPP liberary
+ SET(IPP_SOURCES ${IPP_CIPHER_FWK_SRCS} PARENT_SCOPE)
+ IF(UNIX)
+ IF(EXISTS ${IPP_INSTALL_DIR}/lib/intel64/libippcp.so)
+ SET(IPP_LIBS ${IPP_LIBS} ${IPP_INSTALL_DIR}/lib/intel64/libippcp.so)
+ ELSE(EXISTS ${IPP_INSTALL_DIR}/lib/intel/libippcp.so)
+ SET(IPP_LIBS ${IPP_LIBS} ${IPP_INSTALL_DIR}/lib/intel/libippcp.so)
+ ENDIF(EXISTS ${IPP_INSTALL_DIR}/lib/intel64/libippcp.so)
+ ENDIF(UNIX)
+ IF(WIN32)
+ IF(EXISTS ${IPP_INSTALL_DIR}/lib/intel64/ippcp.lib)
+ set(IPP_LIBS ${IPP_LIBS} ${IPP_INSTALL_DIR}/lib/intel64/ippcp.lib)
+ ELSEIF(EXISTS ${IPP_INSTALL_DIR}/lib/intel/ippcp.lib)
+ set(IPP_LIBS ${IPP_LIBS} ${IPP_INSTALL_DIR}/lib/intel/ippcp.lib)
+ ELSE(EXISTS ${IPP_INSTALL_DIR}/lib/ippcp.lib)
+ set(IPP_LIBS ${IPP_LIBS} ${IPP_INSTALL_DIR}/lib/ippcp.lib)
+ ENDIF()
+ ENDIF(WIN32)
+ SET(IPP_INCLUDES ${IPP_INSTALL_DIR}/include PARENT_SCOPE)
+ SET(IPP_LIBS ${IPP_LIBS} PARENT_SCOPE)
+ ENDIF(ENABLE_TESTS_IPP_API)
+endfunction(add_ipp)
+
+# Function to dynamically generate compilation of each test cases
+FUNCTION(AES_TEST TYPE MOD)
+ ADD_EXECUTABLE(aes_${MOD}_experimental_${TYPE} test_${MOD}_${TYPE}.cc
+ ${COMMON_SRCS}
+ ${ALC_CIPHER_FWK_SRCS}
+ ${EXTRA_SOURCES}
+ ${OPENSSL_SOURCES}
+ ${IPP_SOURCES})
+ # Below code must be enabled once we merge completely
+ # Depending on the person, they are gonna run from root dir or binary directory
+ # Link dataset to the root dir
+ # FILE(CREATE_LINK ${CMAKE_CURRENT_SOURCE_DIR}/dataset/dataset_${MOD}.csv ${CMAKE_BINARY_DIR}/dataset_${MOD}.csv SYMBOLIC)
+
+ # Link dataset to the actual place of test binary
+ # FILE(CREATE_LINK ${CMAKE_CURRENT_SOURCE_DIR}/dataset/dataset_${MOD}.csv ${CMAKE_CURRENT_BINARY_DIR}/dataset_${MOD}.csv SYMBOLIC)
+
+ TARGET_INCLUDE_DIRECTORIES(aes_${MOD}_experimental_${TYPE} PRIVATE
+ ${ALCP_TEST_INCLUDES}
+ ${OPENSSL_INCLUDES}
+ ${IPP_INCLUDES})
+
+ TARGET_COMPILE_OPTIONS(aes_${MOD}_experimental_${TYPE} PUBLIC ${ALCP_WARNINGS})
+ TARGET_LINK_LIBRARIES(aes_${MOD}_experimental_${TYPE} ${LIBS}
+ ${OPENSSL_LIBS}
+ ${IPP_LIBS})
+ gtest_add_tests(TARGET aes_${MOD}_experimental_${TYPE}
+ TEST_SUFFIX .${MOD})
+ENDFUNCTION()
\ No newline at end of file
diff --git a/cmake/doxygen.cmake b/cmake/doxygen.cmake
index 4ce7e86d6..15fea8417 100644
--- a/cmake/doxygen.cmake
+++ b/cmake/doxygen.cmake
@@ -1,4 +1,4 @@
-# Copyright (C) 2021-2023, Advanced Micro Devices. All rights reserved.
+# Copyright (C) 2023, Advanced Micro Devices. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt
index 6fab71aa8..1127cba89 100644
--- a/docs/CMakeLists.txt
+++ b/docs/CMakeLists.txt
@@ -1,4 +1,4 @@
- # Copyright (C) 2022-2023, Advanced Micro Devices. All rights reserved.
+ # Copyright (C) 2021-2023, Advanced Micro Devices. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
@@ -39,6 +39,5 @@ IF( (NOT PDFLATEX) OR (NOT PANDOC) )
ENDIF()
MESSAGE(FATAL_ERROR "PANDOC OR PDFLATEX is missing, documentation cannot be built!")
ELSE()
- add_subdirectory(internal)
add_subdirectory(compat)
ENDIF()
\ No newline at end of file
diff --git a/docs/ReleaseNotes.txt b/docs/ReleaseNotes.txt
index 1d47d419a..d1dcd8c44 100644
--- a/docs/ReleaseNotes.txt
+++ b/docs/ReleaseNotes.txt
@@ -1,11 +1,11 @@
(C) 2022-2023 Advanced Micro Devices, Inc. All Rights Reserved.
-AOCL Crypto - Release Notes - AOCL version 4.1
-----------------------------------------------
+AOCL Cryptography - Release Notes - AOCL version 4.2
+----------------------------------------------------
AOCL Crypto Contents
--------------------
-AOCL-Crypto is a library consisting of basic cryptographic functions
+AOCL Cryptography is a library consisting of basic cryptographic functions
optimized for AMD Zen microarchitecture. This library has multiple
implementations of different cryptographic algorithms which is given below:
-- AES cryptographic encryption / decryption routines
@@ -13,22 +13,22 @@ implementations of different cryptographic algorithms which is given below:
-- MAC (Cipher and Hash based) routines
-- ECDH x25519 Key exchange functions
-- RSA Encrypt/Decrypt functions.
+-- Chacha20 stream cipher functions.
+-- Poly1305 MAC functions.
-Highlights of AOCL Crypto version 4.1
---------------------------------------
--- Improvements in AES-GCM encrypt/decrypt routines for zen4 architecture
--- Improved SHA3 digest routines including SHAKE128 and 256 schemes
--- AES CCM encrypt/decrypt routines
--- HMAC SHA2 and SHA3 routines
--- AES CMAC routines for key sizes (128, 192, and 256)
--- AES SIV routines
--- ECDH x25519 key exchange functions: Generate Public Key and Compute Secret Key
--- RSA Functions: Encrypt Text with public key and Decrypt with private key
- (Note: Only non-padded mode is supported in 4.1 release)
--- Dynamic dispatch on different architectures support (using AOCL-Utils 4.1 library)
--- Windows support
+Highlights of AOCL Crypto version 4.2
+-------------------------------------
+-- Poly1305 MAC algorithm
+-- Chacha20 Stream Cipher algorithm
+-- RSA improved encryption/decryption functions for 1024,2048 bit key sizes and OAEP Padding support
+-- Architectural improvements in AES Cipher: Split algorithms into AEAD and Non-AEAD
+-- AES-XTS: Block number based encryption / decryption
+-- Performance improvements in AES cipher (GCM, CTR, XTS, CFB, CBC) encrypt/decrypt algorithms for zen4 architecture
+-- Performance improvements in Digest SHA2-512, SHA2-256 and dependent algorithms
+-- IPP and OpenSSL compat support for more AEAD APIs
+-- IPP Compat support for MAC
+-- Extended IPP Compat support for XTS
+-- Bug fixes in static library generation
+-- Improved dynamic dispatcher
-Known issues in 4.1:
---------------------
--- ECDH, Digest(SHA2) and HMAC(SHA2) functions are not stable on pre-avx2 architectures
--- ALCP Compat libraries support compilation only with GCC
+Known issues: Failures while running OpenSSL applications using OpenSSL Compat (Provider) library.
diff --git a/docs/compat/ipp.md b/docs/compat/ipp.md
index ce71d7a75..82045d06c 100644
--- a/docs/compat/ipp.md
+++ b/docs/compat/ipp.md
@@ -1,7 +1,6 @@
---
title: AOCL Crypto IPP Plugin Documentation
subtitle: IPP Plugin Documentation
-author: Abhiram S
subject: "markdown"
keywords: [books,programming]
language: en-US
@@ -62,7 +61,7 @@ Key algorithms supported by IPP-CP are as follows.
To read more about IPP-CP click [here](https://github.com/intel/ipp-crypto/blob/develop/README.md)
-Currently used version of IPP-CP is `ipp-crypto_2021_6` when this document was written.
+Currently used version of IPP-CP is `ipp-crypto_2021_8` when this document was written.
## Usage of IPP-Plugin - Brief
@@ -72,12 +71,12 @@ To build examples, simply invoke ```make -j``` from the root of the package dire
Set LD_LIBRARY_PATH properly to lib directory in the package to avoid loader issues while executing.
Executables for examples should be found in bin directory after make is successful.
-For more information please read [BUILD_Examples.md](BUILD_Examples.md)
+For more information please read [BUILD_Examples.md](../../examples/BUILD_Examples.md)
### Preloading IPP-Compat Lib
``` bash
-export LD_LIBRARY_PATH=/path/where/libalcp/is:$LD_LIBRARY_PATH
+export LD_LIBRARY_PATH=/path/to/libalcp.so:$LD_LIBRARY_PATH
LD_PRELOAD=/path/to/libipp-compat.so ./program_to_run
```
@@ -85,5 +84,5 @@ LD_PRELOAD=/path/to/libipp-compat.so ./program_to_run
* Preload Path should be the .so file itself.
* Any command can follow LD_PRELOAD.
-It is explained better in [Preloading_IPP] (Preloading IPP-CP wrapper plugin)
+For more details, please refer to [Preloading_IPP] (Preloading IPP-CP wrapper plugin)
diff --git a/docs/compat/ipp.pdf b/docs/compat/ipp.pdf
index 52a125b73..5155cb549 100644
Binary files a/docs/compat/ipp.pdf and b/docs/compat/ipp.pdf differ
diff --git a/docs/compat/ipp/01-Preloading.md b/docs/compat/ipp/01-Preloading.md
index dbc4cd5e6..78a689e09 100644
--- a/docs/compat/ipp/01-Preloading.md
+++ b/docs/compat/ipp/01-Preloading.md
@@ -22,7 +22,7 @@ In order to preload globally there is a config file `/etc/ld.so.preload` this fi
Example /etc/ld.so.preload
-```config
+```bash
/path/to/somelib.so
/path/to/someotherlib.so
```
diff --git a/docs/compat/openssl.md b/docs/compat/openssl.md
index 0456a633e..7be081740 100644
--- a/docs/compat/openssl.md
+++ b/docs/compat/openssl.md
@@ -1,7 +1,6 @@
---
title: AOCL Crypto OpenSSL Provider Documentation
subtitle: OpenSSL Plugin Documentation
-author: Abhiram S
subject: "markdown"
keywords: [books,programming]
language: en-US
@@ -24,9 +23,9 @@ colorlinks: true
* SSH - Secure Shell Host
-* Cipher Suit - A set of algorithms which can be used to exchange keys, verify integrity, and provide authenticity.
+* Cipher Suite - A set of algorithms which can be used to exchange keys, verify integrity, and provide authenticity.
-* Kernel - Piece of code which is doing all the core parts and takes most amount of time in the library.
+* Kernel - Piece of code which performs/executes all the core tasks and takes most amount of time in the library.
* Plugin - A foreign piece of code which can be used to extend a program/library.
* Provider - Another name for plugin used by OpenSSL.
* Benchmarking - Performance analysis of a program.
@@ -39,13 +38,13 @@ colorlinks: true
## About OpenSSL
-OpenSSL is an opensource SSL library which supports various encryption decryption standards as well as cipher suits. OpenSSL is used in well known programs such as Nginx, SSH etc. Most of the OpenSSL kernels have a hardware optimized version of the it inside it.
-Sometimes users of OpenSSL might reqire more optimized versions of the kernels, for this perticular purpose OpenSSL has a plugin infrastructure which will allow anyone to write plugins called as providers. This is the interface which is used by AOCL-Crypto to interface with the OpenSSL infrastructure.
+OpenSSL is an opensource SSL library which supports various encryption decryption standards as well as cipher suites. OpenSSL is used in well known programs such as Nginx, SSH etc. Most of the OpenSSL kernels have a hardware optimized version inside it.
+Sometimes users of OpenSSL might reqire more optimized versions of the kernels, for this particular purpose OpenSSL has a plugin infrastructure which will allow anyone to write plugins called as providers. This is the interface which is used by ALCP to communicate with the OpenSSL infrastructure.
### Using OpenSSL-Compat Lib
ALCP support for OpenSSL is provided by a provider. Provider lib name is ```libopenssl-compat.so```. Please configure openssl to use provider by default or setup provider loading inside application itself.
- To bench with the provider, use the following example assuming you are executing command from the root of the package directory.
+ To bench with the provider, use the following example assuming you are executing command from the root of the package (extracted tarball) directory.
```openssl speed -provider-path $PWD/lib -provider libopenssl-compat -evp aes-128-gcm```
diff --git a/docs/compat/openssl.pdf b/docs/compat/openssl.pdf
index 6d3b17fc5..1ec0887a1 100644
Binary files a/docs/compat/openssl.pdf and b/docs/compat/openssl.pdf differ
diff --git a/docs/compat/openssl/02-configuration.md b/docs/compat/openssl/02-configuration.md
index 48e9099ff..089b5b4ce 100644
--- a/docs/compat/openssl/02-configuration.md
+++ b/docs/compat/openssl/02-configuration.md
@@ -11,16 +11,24 @@ openssl_conf = openssl_init
providers = provider_sect
[provider_sect]
-default = default_sect
alcp = alcp_sect
+default = default_sect
+base = base_sect
[default_sect]
+activate = 1
[alcp_sect]
module = /path/to/libopenssl-compat.so
activate = 1
+
+[base_sect]
+activate = 1
```
+List of currently loaded OpenSSL provider can viewed using `openssl list -providers`.
+
+Above configuration will allow you to offload functionalities if supported by AOCL-Cryptography. OpenSSL will still dispatch to it's own implementation for ones we have not implemented yet.
To find out where openssl looks for `openssl.cnf`, type the command ```openssl info -configdir```.
### Code taking advantage of configuration
diff --git a/docs/examples/CMakeLists.txt b/docs/examples/CMakeLists.txt
index f839ccdbd..1dbde7e84 100644
--- a/docs/examples/CMakeLists.txt
+++ b/docs/examples/CMakeLists.txt
@@ -1,4 +1,4 @@
- # Copyright (C) 2022-2023, Advanced Micro Devices. All rights reserved.
+ # Copyright (C) 2021-2023, Advanced Micro Devices. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
diff --git a/docs/resources/Main_Page.md b/docs/resources/Main_Page.md
index b9d1f031b..8e913d439 100644
--- a/docs/resources/Main_Page.md
+++ b/docs/resources/Main_Page.md
@@ -1,34 +1,33 @@
-# Welcome to AOCL-Crypto
+# Welcome to AOCL-Cryptography
-**AOCL-Crypto** is a library consisting of basic cryptographic functions optimized and tuned for AMD Zen™ based microarchitecture. This library provides a unified solution for Cryptographic routines such as AES (Advanced Encryption Standard) encryption/decryption routines (CFB, CTR, CBC, CCM, GCM, OFB, SIV, XTS), SHA (Secure Hash Algorithms) routines (SHA2, SHA3, SHAKE), Message Authentication Code (CMAC, HMAC), ECDH (Elliptic-curve Diffie–Hellman) and RSA (Rivest, Shamir, and Adleman) key generation functions, etc.
+**AOCL-Cryptography** is a library consisting of basic cryptographic functions optimized and tuned for AMD Zen™ based microarchitecture. This library provides a unified solution for Cryptographic routines such as AES (Advanced Encryption Standard) encryption/decryption routines (CFB, CTR, CBC, CCM, GCM, OFB, SIV, XTS), Chacha20 Stream Cipher routines, SHA (Secure Hash Algorithms) routines (SHA2, SHA3, SHAKE), Message Authentication Code (CMAC, HMAC, Poly1305 MAC), ECDH (Elliptic-curve Diffie–Hellman), RSA (Rivest, Shamir, and Adleman) key generation functions, etc.
-- For building, please refer to [BUILD.md](md_BUILD.html)
+- For building, please refer to [Build.md](md_BUILD.html)
----
-
-## Table of Content
+## Table of contents
* [Introduction](#Introduction)
- * [Build and Installation](#Build)
+ * [Getting Started](#Getting-Started)
* [Examples](#Example)
* [Contact Us](#Contact)
-
-
-## Introduction
+## Introduction {#Introduction}
- AOCL Crypto supports a dynamic dispatcher feature that executes the most optimal function variant implemented using Function Multi-versioning thereby offering a single optimized library portable across different x86 CPU architectures.
-AOCL Crypto framework is developed in C / C++ for Unix and Windows based systems. Below are details of AOCL Crypto APIs and Supports
+ AOCL-Cryptography supports a dynamic dispatcher feature that executes the most optimal function variant implemented using Function Multi-versioning thereby offering a single optimized library portable across different x86 CPU architectures.
+AOCL Crypto framework is developed in C / C++ for Unix and Windows based systems. A test suite is provided for validation and performance benchmarking for the supported Ciphers, Digest, MAC, EC, and RSA APIs. The test suite also supports the benchmarking of IPP and Openssl different methods like AES cryptographic encryption / decryption, SHA2, SHA3 and other algorithms. Below are details of AOCL Crypto APIs and supported features
-### Cipher
+### Cipher
```
-AES
+AES - Block Cipher algorithms
AES Encrypt / Decrypt routines which will support the following cipher schemes:
- CBC, CFB, OFB, CTR, GCM, XTS, CCM, SIV.
+
+Chacha20 - Stream Cipher algorithms
+
```
- Click to know about more about [AOCL Cipher API](group__cipher.html)
@@ -44,7 +43,7 @@ SHA2
SHA3
Digest routines for the following schemes:
- - SHA3_224, SHA3_256, SHA3_384, SHA3_512, SHAKE_128, SHAKE_256
+ - SHA3_224, SHA3_256, SHA3_384, SHA3_512, SHAKE_128, SHAKE_256
```
- Click to know more about [AOCL Digest API](group__digest.html)
@@ -78,6 +77,9 @@ CMAC
MAC routines for the following schemes:
- CMAC - AES (for key size 128,192 and 256)
+
+Poly 1305 MAC routines
+
```
- Click to know more about [AOCL MAC API](group__mac.html)
@@ -108,25 +110,22 @@ RNG
- Click to know more about [AOCL RNG API](group__rng.html)
-
-
-
-
-## Build and Installation
-
-To Build AOCL-Crypto for Different Platforms Please refer to the document
- - [ BUILD ](md_BUILD.html#md_BUILD)
+## Getting Started with AOCL-Cryptography {#Getting-Started}
-
+### Quick Starter
+* [AOCL-Cryptography Linux Quick Starter](md_docs_resources_Quick_Start.html)
-## Example
+### Building
-Here is a Demo Code Example on how to use Cipher:
+To Build AOCL-Cryptography for different platform please refer to the document related to your platform
+ - [ Linux ](md_Combine_build.html#md_BUILD)
+ - [ Windows ](md_Combine_build.html#md_BUILD_Windows)
-\include{lineno} cipher/aes-cfb.c
+### Examples {#Example}
-
+To build and run the examples, please refer to the document
+ - [Examples](md_examples_BUILD_Examples.html#md_examples_BUILD_Examples)
-## CONTACTS
+## CONTACTS {#Contact}
-AOCL Crypto is developed and maintained by AMD. For support of these libraries and the other tools of AMD Zen Software Studio, see https://www.amd.com/en/developer/aocc/compiler-technical-support.html
\ No newline at end of file
+AOCL Cryptography is developed and maintained by AMD. For support of these libraries and the other tools of AMD Zen Software Studio, see https://www.amd.com/en/developer/aocc/compiler-technical-support.html
\ No newline at end of file
diff --git a/docs/resources/Quick_Start.md b/docs/resources/Quick_Start.md
new file mode 100644
index 000000000..6b7e6279f
--- /dev/null
+++ b/docs/resources/Quick_Start.md
@@ -0,0 +1,426 @@
+# AOCL-Cryptography Quick Starter for Linux
+
+AOCL-Cryptography is a powerful and flexible cryptography library from AOCL.
+This guide is meant for people who want to get this library setup without going through all the nitty gritty of cmake, linux and prerequisite setup.
+
+This guide will only focus on Ubuntu-22.04 as its a popular and desktop and server OS. In future this guide might get extended to other operating systems as well.
+
+**Note: Below AOCL-Cryptography will be shortened to the repository name AOCL-Crypto.**
+
+
+## Building, installing and running examples from source
+
+### Installing Prerequisites
+Some packages which are required for AOCL-Cryptography can be installed with below commands
+
+```bash
+sudo apt update # Sync repository information
+sudo apt install git # To clone github repositories
+sudo apt install libssl-dev # For openssl
+sudo apt install make # Build system
+sudo apt install cmake # Build system generator
+sudo apt install p7zip-full # Re-archive static libs
+sudo apt install gcc-12 g++-12 # Compiler
+```
+
+What is given above should be sufficient for most users but if your OS did not come with a working install of `sudo`, you can install it by running `apt install sudo` as root. Make sure repository list is upto date.
+
+### Cloning Repositories
+
+There are mainly two repositories which are needed, one being `aocl-crypto` and the other which is a dependency named `aocl-utils`. `AOCL-Utils` provide the means to correctly identify the CPU. This is a necessary dependency to ensure optimal performance of `AOCL-Crypto`. Both of these repositories can be cloned with below command
+
+```bash
+git clone https://github.com/amd/aocl-crypto.git -b aocl-4.2
+git clone https://github.com/amd/aocl-utils.git -b aocl-4.2
+```
+
+Please ensure that you are running the above commands from a directory where you have write access.
+
+### Building AOCL-Utils
+
+Cloned repository has the latest released version of AOCL-Utils. AOCL-Utils is built using CMake build system generator. AOCL-Utils have a lot of configurations which you can enable/disable. Below command has what is minimum necessary to make it work optimally.
+
+```bash
+# Save current working directory
+pushd .
+
+# Setup build directory
+cd aocl-utils
+mkdir build
+cd build
+
+# Configure AOCL-Utils with make build system.
+export CC=gcc-12; export CXX=g++-12
+cmake ../ -DCMAKE_INSTALL_PREFIX=install -DCMAKE_BUILD_TYPE=Release -DALCI_DOCS=OFF
+
+# Build the project with all available threads.
+make -j $(nproc --all)
+
+# Install the project into build/install directory
+make install
+
+# Revert back to the original working directory.
+popd
+```
+
+### Building AOCL-Cryptography
+
+Cloned repository has the latest released version of AOCL-Cryptography. AOCL-Cryptography is built using CMake build system generator. AOCL-Utils have a lot of configurations which you can enable/disable. Below command has what is minimum necessary to make it work optimally.
+
+```bash
+# Save current working directory
+pushd .
+
+# Setup build directory
+cd aocl-crypto
+mkdir build
+cd build
+
+# Configure AOCL-Cryptography with make build system.
+export CC=gcc-12; export CXX=g++-12
+echo "Running \"cmake ../ -DALCP_ENABLE_EXAMPLES=ON \
+-DOPENSSL_INSTALL_DIR=/usr \
+-DCMAKE_INSTALL_PREFIX=$PWD/install \
+-DENABLE_AOCL_UTILS=ON \
+-DAOCL_UTILS_INSTALL_DIR=$PWD/../../aocl-utils/build/install\""
+cmake ../ -DALCP_ENABLE_EXAMPLES=ON \
+ -DOPENSSL_INSTALL_DIR=/usr \
+ -DCMAKE_INSTALL_PREFIX=$PWD/install \
+ -DENABLE_AOCL_UTILS=ON \
+ -DAOCL_UTILS_INSTALL_DIR=$PWD/../../aocl-utils/build/install
+
+# Build the project with all available threads.
+make -j $(nproc --all)
+
+# Install the project into build/install directory
+make install
+
+# Revert back to the original working directory.
+popd
+```
+
+### Executing Examples
+
+To execute the examples, loader has to find the library to load. For this both AOCL-Utils and AOCL-Cryptography's library path has to be added into `LD_LIBRARY_PATH`. Once this is added we can execute any executable which is compiled with AOCL-Cryptography. To show proof of the concept `aes-cfb` example can be executed.
+
+```bash
+# Save current working directory
+pushd .
+
+# Setup environment
+export LD_LIBRARY_PATH=$PWD/aocl-utils/build/install/lib:$PWD/aocl-utils/build/install/lib64:$LD_LIBRARY_PATH
+export LD_LIBRARY_PATH=$PWD/aocl-crypto/build/install/lib:$PWD/aocl-crypto/build/install/lib64:$LD_LIBRARY_PATH
+
+# Get into build directory
+cd aocl-crypto/build
+
+# Execute the CFB Example
+$PWD/examples/cipher/aes-cfb
+
+# Revert back to the original working directory.
+popd
+```
+
+### Single script to do all the above
+
+To end with, here is a script which runs everything. Feel free to save this script somewhere as a .sh file and execute it. As always please ensure you do have write access to the current working directory.
+
+```bash
+#!/usr/bin/env bash
+
+# This file is supposed to be a guide to compile AOCL-Cryptography with examples
+# from source.
+# It should only require minimal interaction from user.
+# All functions in this file should be straight forward and minimal.
+# For detailed info please take a look at BUILD.md located in the root of
+# AOCL-Cryptography source code directory.
+
+# Global Variables to be modifed depending on repo location
+AOCL_CRYPTO_REPO="https://github.com/amd/aocl-crypto.git"
+AOCL_UTILS_REPO="https://github.com/amd/aocl-utils.git"
+AOCL_BRANCH="aocl-4.2"
+
+# Function to check if lsb_release is installed
+ensure_lsb_release(){
+ type lsb_release > /dev/null
+ if [ $? -ne 0 ]; then
+ echo "lsb_release not found!"
+ exit -1;
+ else
+ echo "lsb_release found"
+ fi
+}
+
+# Function to check if OS is ubuntu with a specific version
+detect_ubuntu(){
+ lsb_release --id | grep "Ubuntu" > /dev/null
+ if [ $? -eq 0 ]; then
+ # Detected Ubuntu
+ echo "Detected Ubuntu"
+ lsb_release --release | grep $1 > /dev/null
+ if [ $? -eq 0 ]; then
+ echo "Detected OS Release Version $1"
+ return 0
+ fi
+ fi
+ return 1 # Return error
+}
+
+# Function to exit with an error if some execution failed
+quit_if_status_not_zero(){
+ if [ $1 -ne 0 ]; then
+ echo "Command returned error"
+ exit -1
+ fi
+}
+
+# Function to install all packages, OS indipendant (eventually)
+ensure_packages(){
+ detect_ubuntu 22.04
+ if [ $? -eq 0 ]; then
+ echo "Running \"sudo apt update\""
+ sudo apt update # Sync repository information
+ quit_if_status_not_zero $?
+ echo "Running \"sudo install git\""
+ sudo apt install git # To clone github repositories
+ quit_if_status_not_zero $?
+ echo "Running \"sudo install libssl-dev\""
+ sudo apt install libssl-dev # For openssl
+ quit_if_status_not_zero $?
+ echo "Running \"sudo install make\""
+ sudo apt install make # Build system
+ quit_if_status_not_zero $?
+ echo "Running \"sudo install cmake\""
+ sudo apt install cmake # Build system generator
+ quit_if_status_not_zero $?
+ echo "Running \"sudo install p7zip-full\""
+ sudo apt install p7zip-full # Re-archive static libs
+ quit_if_status_not_zero $?
+ echo "Running \"sudo install gcc-12 g++-12\""
+ sudo apt install gcc-12 g++-12 # Compiler
+ quit_if_status_not_zero $?
+ return 0
+ fi
+ # detect_rhel 8
+ # if [ $? -eq 1 ]; then
+ # sudo yum install...
+ # ...
+ # return 1
+ echo "OS support check failed!"
+ exit -1
+}
+
+# Function to make sure what this script writes don't already exist
+ensure_no_directory_conflict(){
+ # Check if aocl-crypto directory already exists
+ if [[ -d aocl-crypto || -f aocl-crypto ]]; then
+ echo "aocl-crypto exists!"
+ echo "Please run \"rm -rf aocl-crypto\""
+ exit -1
+ fi
+ # Check if aocl-utils directory already exists
+ if [[ -d aocl-utils || -f aocl-utils ]]; then
+ echo "aocl-utils exists!"
+ echo "Please run \"rm -rf aocl-utils\""
+ exit -1
+ fi
+}
+
+# Function to clone the repo both aocl-utils and aocl-crypto.
+clone_repos(){
+
+ # Clone AOCL-Cryptography
+ echo "Running \"git clone $AOCL_CRYPTO_REPO -b $AOCL_BRANCH\""
+ git clone $AOCL_CRYPTO_REPO -b $AOCL_BRANCH
+ quit_if_status_not_zero $?
+
+ sleep 1
+
+ # Clone AOCL-Utils
+ echo "Running \"git clone $AOCL_UTILS_REPO -b $AOCL_BRANCH\""
+ git clone $AOCL_UTILS_REPO -b $AOCL_BRANCH
+ quit_if_status_not_zero $?
+
+}
+
+# Function to build aocl-utils with minimal configuration
+compile_aocl_utils(){
+
+ pushd .
+ echo "cd into aocl-utils"
+ cd aocl-utils
+ echo "creating build directory"
+ mkdir build
+ echo "cd into build directory"
+ cd build
+ echo "Setting GCC-12 as the compiler"
+ export CC=gcc-12; export CXX=g++-12
+ echo "Running \"cmake ../ -DCMAKE_INSTALL_PREFIX=$PWD/install -DCMAKE_BUILD_TYPE=Release -DALCI_DOCS=OFF\""
+ cmake ../ -DCMAKE_INSTALL_PREFIX=install -DCMAKE_BUILD_TYPE=Release -DALCI_DOCS=OFF
+ echo "Running \"make -j $(nproc --all)\""
+ make -j $(nproc --all)
+ quit_if_status_not_zero $?
+ make install
+ quit_if_status_not_zero $?
+ popd
+
+}
+
+# Function to build AOCL-Cryptography with minimal configuration
+compile_aocl_crypto(){
+
+ pushd .
+ echo "cd into aocl-crypto"
+ cd aocl-crypto
+ echo "creating build directory"
+ mkdir build
+ echo "cd into build directory"
+ cd build
+ echo "Setting GCC-12 as the compiler"
+ export CC=gcc-12; export CXX=g++-12
+ echo "Running \"cmake ../ -DALCP_ENABLE_EXAMPLES=ON \
+-DOPENSSL_INSTALL_DIR=/usr \
+-DCMAKE_INSTALL_PREFIX=$PWD/install \
+-DENABLE_AOCL_UTILS=ON \
+-DAOCL_UTILS_INSTALL_DIR=$PWD/../../aocl-utils/build/install\""
+ cmake ../ -DALCP_ENABLE_EXAMPLES=ON \
+ -DOPENSSL_INSTALL_DIR=/usr \
+ -DCMAKE_INSTALL_PREFIX=$PWD/install \
+ -DENABLE_AOCL_UTILS=ON \
+ -DAOCL_UTILS_INSTALL_DIR=$PWD/../../aocl-utils/build/install
+ echo "Running \"make -j $(nproc --all)\""
+ make -j $(nproc --all)
+ quit_if_status_not_zero $?
+ make install
+ quit_if_status_not_zero $?
+ popd
+
+}
+
+# Function to show how to execute an example properly
+run_example_cfb(){
+
+ pushd .
+ echo "Exporting library paths for loader"
+ # Update loader with aocl-utils lib
+ export LD_LIBRARY_PATH=$PWD/aocl-utils/build/install/lib:$PWD/aocl-utils/build/install/lib64:$LD_LIBRARY_PATH
+ # Update loader with aocl-crypto lib
+ export LD_LIBRARY_PATH=$PWD/aocl-crypto/build/install/lib:$PWD/aocl-crypto/build/install/lib64:$LD_LIBRARY_PATH
+ echo "cd into aocl-crypto/build"
+ cd aocl-crypto/build
+ echo "Executing \"$PWD/examples/cipher/aes-cfb\""
+ $PWD/examples/cipher/aes-cfb
+ quit_if_status_not_zero $?
+ echo "Executed Successfully!, output above"
+ popd
+
+}
+
+# Make sure we dont destroy anything
+ensure_no_directory_conflict
+# Make sure we can detect the OS
+ensure_lsb_release
+# Make sure all the needed packages (dependancies) are installed
+ensure_packages
+# Clone Utils and Crypto
+clone_repos
+# Build Utils and Install it into a prefix inside build directory
+compile_aocl_utils
+# Build Crypto and Install it into a prefix inside the build directory
+compile_aocl_crypto
+# Run an example to show that, its indeed working.
+run_example_cfb
+```
+
+## Setting up Application Development Environment
+
+As AOCL-Cryptography is a C/C++ library you can write a C/C++ application with AOCL-Cryptography and accelerate the cryptographic performance.
+
+AOCL-Cryptography interacts with applications using C-API. In future for C++ a native API will be exposed reducing the complexity and increasing the flexibility of the API.
+
+### Exporting Environment Variables
+```bash
+# Adding AOCL-Utils into environment variables
+export LD_LIBRARY_PATH="aocl-utils/build/install/lib:aocl-utils/build/install/lib64:$LD_LIBRARY_PATH"
+export LIBRARY_PATH="aocl-utils/build/install/lib:aocl-utils/build/install/lib64:$LIBRARY_PATH"
+export C_INCLUDE_PATH="aocl-utils/build/install/include:$C_INCLUDE_PATH"
+export CPLUS_INCLUDE_PATH="aocl-utils/build/install/include:$CPLUS_INCLUDE_PATH"
+
+# Adding AOCL-Cryptography into environment variables
+export LD_LIBRARY_PATH="aocl-crypto/build/install/lib:aocl-crypto/build/install/lib64:$LD_LIBRARY_PATH"
+export LIBRARY_PATH="aocl-crypto/build/install/lib:aocl-crypto/build/install/lib64:$LIBRARY_PATH"
+export C_INCLUDE_PATH="aocl-crypto/build/install/include:$C_INCLUDE_PATH"
+export CPLUS_INCLUDE_PATH="aocl-crypto/build/install/include:$CPLUS_INCLUDE_PATH"
+```
+
+### Sample application to show version
+
+Copy and paste this into a terminal, it will create a file named `version.c`
+```bash
+cat << EOF > version.c
+#include
+#include
+
+int
+main()
+{
+ // Call alcp_get_version function which returns a string
+ printf("ALCP_VERSION_IS: %s\n", alcp_get_version());
+ return 0;
+}
+EOF
+```
+
+#### Compiling the application
+
+As you have already run the `Exporting Environment Variables` code snippet, building becomes very simple.
+
+```bash
+gcc version.c -o version -lalcp -laoclutils
+```
+
+#### Execute the application
+
+```bash
+./version
+```
+
+### Single script to setup the example application
+
+As always to end with, here is a script which builds and executes application. Feel free to modify it as you please for your own application.
+
+```bash
+# Adding AOCL-Utils into environment variables
+export LD_LIBRARY_PATH="aocl-utils/build/install/lib:aocl-utils/build/install/lib64:$LD_LIBRARY_PATH"
+export LIBRARY_PATH="aocl-utils/build/install/lib:aocl-utils/build/install/lib64:$LIBRARY_PATH"
+export C_INCLUDE_PATH="aocl-utils/build/install/include:$C_INCLUDE_PATH"
+export CPLUS_INCLUDE_PATH="aocl-utils/build/install/include:$CPLUS_INCLUDE_PATH"
+
+# Adding AOCL-Cryptography into environment variables
+export LD_LIBRARY_PATH="aocl-crypto/build/install/lib:aocl-crypto/build/install/lib64:$LD_LIBRARY_PATH"
+export LIBRARY_PATH="aocl-crypto/build/install/lib:aocl-crypto/build/install/lib64:$LIBRARY_PATH"
+export C_INCLUDE_PATH="aocl-crypto/build/install/include:$C_INCLUDE_PATH"
+export CPLUS_INCLUDE_PATH="aocl-crypto/build/install/include:$CPLUS_INCLUDE_PATH"
+
+# Write the sample Application
+cat << EOF > version.c
+#include
+#include
+
+int
+main()
+{
+ // Call alcp_get_version function which returns a string
+ printf("ALCP_VERSION_IS: %s\n", alcp_get_version());
+ return 0;
+}
+EOF
+
+# Compile the application
+gcc version.c -o version -lalcp -laoclutils
+
+# Execute the application
+./version
+```
+
+Now you got AOCL-Cryptography setup for development, Enjoy :-).
diff --git a/docs/resources/Related_Pages.md b/docs/resources/Related_Pages.md
index 9c3918005..626bee6ee 100644
--- a/docs/resources/Related_Pages.md
+++ b/docs/resources/Related_Pages.md
@@ -15,3 +15,11 @@
* [AES Encryption Demo Example](md_docs_examples_aes_cfb_nopadding.html)
+##### Tests
+
+* [ALCP Micro Tests](md_tests_README.html)
+
+##### BenchMarks
+
+* [ALCP Micro Benchmarks](md_bench_README.html)
+
diff --git a/doxygen/config.doxy b/doxygen/config.doxy
index 41d21413a..c25220602 100644
--- a/doxygen/config.doxy
+++ b/doxygen/config.doxy
@@ -22,8 +22,7 @@
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
-
-# Doxyfile 1.9.6
+# Doxyfile 1.9.8
# This file describes the settings to be used by the documentation system
# doxygen (www.doxygen.org) for a project.
@@ -67,7 +66,7 @@ DOXYFILE_ENCODING = UTF-8
# title of most generated pages and in a few other places.
# The default value is: My Project.
-PROJECT_NAME = AOCL-Crypto
+PROJECT_NAME = AOCL-Cryptography
# The PROJECT_NUMBER tag can be used to enter a project or revision number. This
# could be handy for archiving the generated documentation or if some version
@@ -308,7 +307,7 @@ TAB_SIZE = 4
# with the commands \{ and \} for these it is advised to use the version @{ and
# @} or use a double escape (\\{ and \\})
-ALIASES =
+ALIASES =
# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources
# only. Doxygen will then generate output that is more tailored for C. For
@@ -388,6 +387,17 @@ MARKDOWN_SUPPORT = YES
TOC_INCLUDE_HEADINGS = 5
+# The MARKDOWN_ID_STYLE tag can be used to specify the algorithm used to
+# generate identifiers for the Markdown headings. Note: Every identifier is
+# unique.
+# Possible values are: DOXYGEN use a fixed 'autotoc_md' string followed by a
+# sequence number starting at 0 and GITHUB use the lower case version of title
+# with any whitespace replaced by '-' and punctuation characters removed.
+# The default value is: DOXYGEN.
+# This tag requires that the tag MARKDOWN_SUPPORT is set to YES.
+
+MARKDOWN_ID_STYLE = DOXYGEN
+
# When enabled doxygen tries to link words that correspond to documented
# classes, or namespaces to their corresponding documentation. Such a link can
# be prevented in individual cases by putting a % sign in front of the word or
@@ -512,6 +522,14 @@ LOOKUP_CACHE_SIZE = 0
NUM_PROC_THREADS = 1
+# If the TIMESTAMP tag is set different from NO then each generated page will
+# contain the date or date and time when the page was generated. Setting this to
+# NO can help when comparing the output of multiple runs.
+# Possible values are: YES, NO, DATETIME and DATE.
+# The default value is: NO.
+
+TIMESTAMP = NO
+
#---------------------------------------------------------------------------
# Build related configuration options
#---------------------------------------------------------------------------
@@ -897,7 +915,14 @@ WARN_IF_UNDOC_ENUM_VAL = NO
# a warning is encountered. If the WARN_AS_ERROR tag is set to FAIL_ON_WARNINGS
# then doxygen will continue running as if WARN_AS_ERROR tag is set to NO, but
# at the end of the doxygen process doxygen will return with a non-zero status.
-# Possible values are: NO, YES and FAIL_ON_WARNINGS.
+# If the WARN_AS_ERROR tag is set to FAIL_ON_WARNINGS_PRINT then doxygen behaves
+# like FAIL_ON_WARNINGS but in case no WARN_LOGFILE is defined doxygen will not
+# write the warning messages in between other messages but write them at the end
+# of a run, in case a WARN_LOGFILE is defined the warning messages will be
+# besides being in the defined file also be shown at the end of a run, unless
+# the WARN_LOGFILE is defined as - i.e. standard output (stdout) in that case
+# the behavior will remain as with the setting FAIL_ON_WARNINGS.
+# Possible values are: NO, YES, FAIL_ON_WARNINGS and FAIL_ON_WARNINGS_PRINT.
# The default value is: NO.
WARN_AS_ERROR = NO
@@ -947,10 +972,15 @@ WARN_LOGFILE =
# FIXME: Move all README to docs directory so directory hierarchy is not
# shown in doxygen docs
INPUT = BUILD.md \
+ BUILD_Windows.md \
+ Combine_build.md \
docs/examples \
+ scripts/helper \
lib/compat/ipp/README.md \
lib/compat/openssl/README.md \
docs/resources \
+ tests/README.md \
+ bench/README.md \
examples/BUILD_Examples.md \
include/alcp
@@ -986,12 +1016,12 @@ INPUT_FILE_ENCODING =
# Note the list of default checked file patterns might differ from the list of
# default file extension mappings.
#
-# If left blank the following patterns are tested:*.c, *.cc, *.cxx, *.cpp,
-# *.c++, *.java, *.ii, *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h,
-# *.hh, *.hxx, *.hpp, *.h++, *.l, *.cs, *.d, *.php, *.php4, *.php5, *.phtml,
-# *.inc, *.m, *.markdown, *.md, *.mm, *.dox (to be provided as doxygen C
-# comment), *.py, *.pyw, *.f90, *.f95, *.f03, *.f08, *.f18, *.f, *.for, *.vhd,
-# *.vhdl, *.ucf, *.qsf and *.ice.
+# If left blank the following patterns are tested:*.c, *.cc, *.cxx, *.cxxm,
+# *.cpp, *.cppm, *.c++, *.c++m, *.java, *.ii, *.ixx, *.ipp, *.i++, *.inl, *.idl,
+# *.ddl, *.odl, *.h, *.hh, *.hxx, *.hpp, *.h++, *.ixx, *.l, *.cs, *.d, *.php,
+# *.php4, *.php5, *.phtml, *.inc, *.m, *.markdown, *.md, *.mm, *.dox (to be
+# provided as doxygen C comment), *.py, *.pyw, *.f90, *.f95, *.f03, *.f08,
+# *.f18, *.f, *.for, *.vhd, *.vhdl, *.ucf, *.qsf and *.ice.
FILE_PATTERNS = *.c \
*.cc \
@@ -1054,7 +1084,7 @@ RECURSIVE = YES
# Note that relative paths are relative to the directory from which doxygen is
# run.
-EXCLUDE =
+EXCLUDE =
# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or
# directories that are symbolic links (a Unix file system feature) are excluded
@@ -1070,16 +1100,13 @@ EXCLUDE_SYMLINKS = NO
# Note that the wildcards are matched against the file with absolute path, so to
# exclude all test directories for example use the pattern */test/*
-EXCLUDE_PATTERNS =
+EXCLUDE_PATTERNS =
# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names
# (namespaces, classes, functions, etc.) that should be excluded from the
# output. The symbol name can be a fully qualified name, a word, or if the
# wildcard * is used, a substring. Examples: ANamespace, AClass,
# ANamespace::AClass, ANamespace::*Test
-#
-# Note that the wildcards are matched against the file with absolute path, so to
-# exclude all test directories use the pattern */test/*
EXCLUDE_SYMBOLS = _*
@@ -1265,46 +1292,6 @@ USE_HTAGS = NO
VERBATIM_HEADERS = NO
-# If the CLANG_ASSISTED_PARSING tag is set to YES then doxygen will use the
-# clang parser (see:
-# http://clang.llvm.org/) for more accurate parsing at the cost of reduced
-# performance. This can be particularly helpful with template rich C++ code for
-# which doxygen's built-in parser lacks the necessary type information.
-# Note: The availability of this option depends on whether or not doxygen was
-# generated with the -Duse_libclang=ON option for CMake.
-# The default value is: NO.
-
-CLANG_ASSISTED_PARSING = NO
-
-# If the CLANG_ASSISTED_PARSING tag is set to YES and the CLANG_ADD_INC_PATHS
-# tag is set to YES then doxygen will add the directory of each input to the
-# include path.
-# The default value is: YES.
-# This tag requires that the tag CLANG_ASSISTED_PARSING is set to YES.
-
-CLANG_ADD_INC_PATHS = YES
-
-# If clang assisted parsing is enabled you can provide the compiler with command
-# line options that you would normally use when invoking the compiler. Note that
-# the include paths will already be set by doxygen for the files and directories
-# specified with INPUT and INCLUDE_PATH.
-# This tag requires that the tag CLANG_ASSISTED_PARSING is set to YES.
-
-CLANG_OPTIONS =
-
-# If clang assisted parsing is enabled you can provide the clang parser with the
-# path to the directory containing a file called compile_commands.json. This
-# file is the compilation database (see:
-# http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html) containing the
-# options used when the source files were built. This is equivalent to
-# specifying the -p option to a clang tool, such as clang-check. These options
-# will then be passed to the parser. Any options specified with CLANG_OPTIONS
-# will be added as well.
-# Note: The availability of this option depends on whether or not doxygen was
-# generated with the -Duse_libclang=ON option for CMake.
-
-CLANG_DATABASE_PATH =
-
#---------------------------------------------------------------------------
# Configuration options related to the alphabetical class index
#---------------------------------------------------------------------------
@@ -1462,15 +1449,6 @@ HTML_COLORSTYLE_SAT = 100
HTML_COLORSTYLE_GAMMA = 80
-# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML
-# page will contain the date and time when the page was generated. Setting this
-# to YES can help to show when doxygen was last run and thus if the
-# documentation is up to date.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-HTML_TIMESTAMP = NO
-
# If the HTML_DYNAMIC_MENUS tag is set to YES then the generated HTML
# documentation will contain a main index with vertical navigation menus that
# are dynamically created via JavaScript. If disabled, the navigation index will
@@ -1490,6 +1468,13 @@ HTML_DYNAMIC_MENUS = YES
HTML_DYNAMIC_SECTIONS = NO
+# If the HTML_CODE_FOLDING tag is set to YES then classes and functions can be
+# dynamically folded and expanded in the generated HTML source code.
+# The default value is: YES.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_CODE_FOLDING = YES
+
# With HTML_INDEX_NUM_ENTRIES one can control the preferred number of entries
# shown in the various tree structured indices initially; the user can expand
# and collapse entries dynamically later on. Doxygen will expand the tree to
@@ -1620,6 +1605,16 @@ BINARY_TOC = NO
TOC_EXPAND = NO
+# The SITEMAP_URL tag is used to specify the full URL of the place where the
+# generated documentation will be placed on the server by the user during the
+# deployment of the documentation. The generated sitemap is called sitemap.xml
+# and placed on the directory specified by HTML_OUTPUT. In case no SITEMAP_URL
+# is specified no sitemap is generated. For information about the sitemap
+# protocol see https://www.sitemaps.org
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+SITEMAP_URL =
+
# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and
# QHP_VIRTUAL_FOLDER are set, an additional index file will be generated that
# can be used as input for Qt's qhelpgenerator to generate a Qt Compressed Help
@@ -2108,9 +2103,16 @@ PDF_HYPERLINKS = YES
USE_PDFLATEX = YES
-# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \batchmode
-# command to the generated LaTeX files. This will instruct LaTeX to keep running
-# if errors occur, instead of asking the user for help.
+# The LATEX_BATCHMODE tag signals the behavior of LaTeX in case of an error.
+# Possible values are: NO same as ERROR_STOP, YES same as BATCH, BATCH In batch
+# mode nothing is printed on the terminal, errors are scrolled as if is
+# hit at every error; missing files that TeX tries to input or request from
+# keyboard input (\read on a not open input stream) cause the job to abort,
+# NON_STOP In nonstop mode the diagnostic message will appear on the terminal,
+# but there is no possibility of user interaction just like in batch mode,
+# SCROLL In scroll mode, TeX will stop only for missing files to input or if
+# keyboard input is necessary and ERROR_STOP In errorstop mode, TeX will stop at
+# each error, asking for user intervention.
# The default value is: NO.
# This tag requires that the tag GENERATE_LATEX is set to YES.
@@ -2131,14 +2133,6 @@ LATEX_HIDE_INDICES = NO
LATEX_BIB_STYLE = plain
-# If the LATEX_TIMESTAMP tag is set to YES then the footer of each generated
-# page will contain the date and time when the page was generated. Setting this
-# to NO can help when comparing the output of multiple runs.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_LATEX is set to YES.
-
-LATEX_TIMESTAMP = NO
-
# The LATEX_EMOJI_DIRECTORY tag is used to specify the (relative or absolute)
# path from which the emoji images will be read. If a relative path is entered,
# it will be relative to the LATEX_OUTPUT directory. If left blank the
@@ -2304,7 +2298,7 @@ DOCBOOK_OUTPUT = docbook
#---------------------------------------------------------------------------
# If the GENERATE_AUTOGEN_DEF tag is set to YES, doxygen will generate an
-# AutoGen Definitions (see http://autogen.sourceforge.net/) file that captures
+# AutoGen Definitions (see https://autogen.sourceforge.net/) file that captures
# the structure of the code including all documentation. Note that this feature
# is still experimental and incomplete at the moment.
# The default value is: NO.
@@ -2315,6 +2309,28 @@ GENERATE_AUTOGEN_DEF = NO
# Configuration options related to Sqlite3 output
#---------------------------------------------------------------------------
+# If the GENERATE_SQLITE3 tag is set to YES doxygen will generate a Sqlite3
+# database with symbols found by doxygen stored in tables.
+# The default value is: NO.
+
+GENERATE_SQLITE3 = NO
+
+# The SQLITE3_OUTPUT tag is used to specify where the Sqlite3 database will be
+# put. If a relative path is entered the value of OUTPUT_DIRECTORY will be put
+# in front of it.
+# The default directory is: sqlite3.
+# This tag requires that the tag GENERATE_SQLITE3 is set to YES.
+
+SQLITE3_OUTPUT = sqlite3
+
+# The SQLITE3_OVERWRITE_DB tag is set to YES, the existing doxygen_sqlite3.db
+# database file will be recreated with each doxygen run. If set to NO, doxygen
+# will warn if an a database file is already found and not modify it.
+# The default value is: YES.
+# This tag requires that the tag GENERATE_SQLITE3 is set to YES.
+
+SQLITE3_RECREATE_DB = YES
+
#---------------------------------------------------------------------------
# Configuration options related to the Perl module output
#---------------------------------------------------------------------------
@@ -2412,8 +2428,8 @@ INCLUDE_FILE_PATTERNS =
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
PREDEFINED = ALCP_API_EXPORT= \
- typedef= \
- "{ ... }="
+ typedef= \
+ "{ ... }="
# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this
# tag can be used to specify a list of macro names that should be expanded. The
@@ -2451,7 +2467,7 @@ SKIP_FUNCTION_MACROS = YES
# the path). If a tag file is not located in the directory in which doxygen is
# run, you must also specify the path to the tagfile here.
-TAGFILES = build/doxygen/html/group__group1.html
+TAGFILES =
# When a file name is specified after GENERATE_TAGFILE, doxygen will create a
# tag file that is based on the input files it reads. See section "Linking to
@@ -2459,15 +2475,15 @@ TAGFILES = build/doxygen/html/group__group1.html
GENERATE_TAGFILE =
-# If the ALLEXTERNALS tag is set to YES, all external class will be listed in
-# the class index. If set to NO, only the inherited external classes will be
-# listed.
+# If the ALLEXTERNALS tag is set to YES, all external classes and namespaces
+# will be listed in the class and namespace index. If set to NO, only the
+# inherited external classes will be listed.
# The default value is: NO.
ALLEXTERNALS = NO
# If the EXTERNAL_GROUPS tag is set to YES, all external groups will be listed
-# in the modules index. If set to NO, only the current project's groups will be
+# in the topic index. If set to NO, only the current project's groups will be
# listed.
# The default value is: YES.
@@ -2481,16 +2497,9 @@ EXTERNAL_GROUPS = YES
EXTERNAL_PAGES = YES
#---------------------------------------------------------------------------
-# Configuration options related to the dot tool
+# Configuration options related to diagram generator tools
#---------------------------------------------------------------------------
-# You can include diagrams made with dia in doxygen documentation. Doxygen will
-# then run dia to produce the diagram and insert it in the documentation. The
-# DIA_PATH tag allows you to specify the directory where the dia binary resides.
-# If left empty dia is assumed to be found in the default search path.
-
-DIA_PATH =
-
# If set to YES the inheritance and collaboration graphs will hide inheritance
# and usage relations if the target is undocumented or is not a class.
# The default value is: YES.
@@ -2499,7 +2508,7 @@ HIDE_UNDOC_RELATIONS = NO
# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is
# available from the path. This tool is part of Graphviz (see:
-# http://www.graphviz.org/), a graph visualization toolkit from AT&T and Lucent
+# https://www.graphviz.org/), a graph visualization toolkit from AT&T and Lucent
# Bell Labs. The other options in this section have no effect if this option is
# set to NO
# The default value is: NO.
@@ -2552,13 +2561,15 @@ DOT_NODE_ATTR = "shape=box,height=0.2,width=0.4"
DOT_FONTPATH =
-# If the CLASS_GRAPH tag is set to YES (or GRAPH) then doxygen will generate a
-# graph for each documented class showing the direct and indirect inheritance
-# relations. In case HAVE_DOT is set as well dot will be used to draw the graph,
-# otherwise the built-in generator will be used. If the CLASS_GRAPH tag is set
-# to TEXT the direct and indirect inheritance relations will be shown as texts /
-# links.
-# Possible values are: NO, YES, TEXT and GRAPH.
+# If the CLASS_GRAPH tag is set to YES or GRAPH or BUILTIN then doxygen will
+# generate a graph for each documented class showing the direct and indirect
+# inheritance relations. In case the CLASS_GRAPH tag is set to YES or GRAPH and
+# HAVE_DOT is enabled as well, then dot will be used to draw the graph. In case
+# the CLASS_GRAPH tag is set to YES and HAVE_DOT is disabled or if the
+# CLASS_GRAPH tag is set to BUILTIN, then the built-in generator will be used.
+# If the CLASS_GRAPH tag is set to TEXT the direct and indirect inheritance
+# relations will be shown as texts / links.
+# Possible values are: NO, YES, TEXT, GRAPH and BUILTIN.
# The default value is: YES.
CLASS_GRAPH = YES
@@ -2566,15 +2577,21 @@ CLASS_GRAPH = YES
# If the COLLABORATION_GRAPH tag is set to YES then doxygen will generate a
# graph for each documented class showing the direct and indirect implementation
# dependencies (inheritance, containment, and class references variables) of the
-# class with other documented classes.
+# class with other documented classes. Explicit enabling a collaboration graph,
+# when COLLABORATION_GRAPH is set to NO, can be accomplished by means of the
+# command \collaborationgraph. Disabling a collaboration graph can be
+# accomplished by means of the command \hidecollaborationgraph.
# The default value is: YES.
# This tag requires that the tag HAVE_DOT is set to YES.
COLLABORATION_GRAPH = YES
# If the GROUP_GRAPHS tag is set to YES then doxygen will generate a graph for
-# groups, showing the direct groups dependencies. See also the chapter Grouping
-# in the manual.
+# groups, showing the direct groups dependencies. Explicit enabling a group
+# dependency graph, when GROUP_GRAPHS is set to NO, can be accomplished by means
+# of the command \groupgraph. Disabling a directory graph can be accomplished by
+# means of the command \hidegroupgraph. See also the chapter Grouping in the
+# manual.
# The default value is: YES.
# This tag requires that the tag HAVE_DOT is set to YES.
@@ -2634,7 +2651,9 @@ TEMPLATE_RELATIONS = NO
# If the INCLUDE_GRAPH, ENABLE_PREPROCESSING and SEARCH_INCLUDES tags are set to
# YES then doxygen will generate a graph for each documented file showing the
# direct and indirect include dependencies of the file with other documented
-# files.
+# files. Explicit enabling an include graph, when INCLUDE_GRAPH is is set to NO,
+# can be accomplished by means of the command \includegraph. Disabling an
+# include graph can be accomplished by means of the command \hideincludegraph.
# The default value is: YES.
# This tag requires that the tag HAVE_DOT is set to YES.
@@ -2643,7 +2662,10 @@ INCLUDE_GRAPH = YES
# If the INCLUDED_BY_GRAPH, ENABLE_PREPROCESSING and SEARCH_INCLUDES tags are
# set to YES then doxygen will generate a graph for each documented file showing
# the direct and indirect include dependencies of the file with other documented
-# files.
+# files. Explicit enabling an included by graph, when INCLUDED_BY_GRAPH is set
+# to NO, can be accomplished by means of the command \includedbygraph. Disabling
+# an included by graph can be accomplished by means of the command
+# \hideincludedbygraph.
# The default value is: YES.
# This tag requires that the tag HAVE_DOT is set to YES.
@@ -2683,7 +2705,10 @@ GRAPHICAL_HIERARCHY = YES
# If the DIRECTORY_GRAPH tag is set to YES then doxygen will show the
# dependencies a directory has on other directories in a graphical way. The
# dependency relations are determined by the #include relations between the
-# files in the directories.
+# files in the directories. Explicit enabling a directory graph, when
+# DIRECTORY_GRAPH is set to NO, can be accomplished by means of the command
+# \directorygraph. Disabling a directory graph can be accomplished by means of
+# the command \hidedirectorygraph.
# The default value is: YES.
# This tag requires that the tag HAVE_DOT is set to YES.
@@ -2699,7 +2724,7 @@ DIR_GRAPH_MAX_DEPTH = 1
# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images
# generated by dot. For an explanation of the image formats see the section
# output formats in the documentation of the dot tool (Graphviz (see:
-# http://www.graphviz.org/)).
+# https://www.graphviz.org/)).
# Note: If you choose svg you need to set HTML_FILE_EXTENSION to xhtml in order
# to make the SVG files visible in IE 9+ (other browsers do not have this
# requirement).
@@ -2727,7 +2752,7 @@ INTERACTIVE_SVG = YES
# found. If left blank, it is assumed the dot tool can be found in the path.
# This tag requires that the tag HAVE_DOT is set to YES.
-DOT_PATH =
+DOT_PATH =
# The DOTFILE_DIRS tag can be used to specify one or more directories that
# contain dot files that are included in the documentation (see the \dotfile
@@ -2736,11 +2761,12 @@ DOT_PATH =
DOTFILE_DIRS =
-# The MSCFILE_DIRS tag can be used to specify one or more directories that
-# contain msc files that are included in the documentation (see the \mscfile
-# command).
+# You can include diagrams made with dia in doxygen documentation. Doxygen will
+# then run dia to produce the diagram and insert it in the documentation. The
+# DIA_PATH tag allows you to specify the directory where the dia binary resides.
+# If left empty dia is assumed to be found in the default search path.
-MSCFILE_DIRS =
+DIA_PATH =
# The DIAFILE_DIRS tag can be used to specify one or more directories that
# contain dia files that are included in the documentation (see the \diafile
@@ -2817,3 +2843,19 @@ GENERATE_LEGEND = YES
# The default value is: YES.
DOT_CLEANUP = YES
+
+# You can define message sequence charts within doxygen comments using the \msc
+# command. If the MSCGEN_TOOL tag is left empty (the default), then doxygen will
+# use a built-in version of mscgen tool to produce the charts. Alternatively,
+# the MSCGEN_TOOL tag can also specify the name an external tool. For instance,
+# specifying prog as the value, doxygen will call the tool as prog -T
+# -o . The external tool should support
+# output file formats "png", "eps", "svg", and "ismap".
+
+MSCGEN_TOOL =
+
+# The MSCFILE_DIRS tag can be used to specify one or more directories that
+# contain msc files that are included in the documentation (see the \mscfile
+# command).
+
+MSCFILE_DIRS =
diff --git a/examples/BUILD_Examples.md b/examples/BUILD_Examples.md
index b3c8865c6..7defaa5a5 100644
--- a/examples/BUILD_Examples.md
+++ b/examples/BUILD_Examples.md
@@ -1,21 +1,86 @@
-# Build and Run Crypto Examples from the AOCL Crypto release package
+# Build and run AOCL-Cryptography examples
-## Build
-Download the tar package from [amd-crypto](https://www.amd.com/en/developer/aocl/cryptography.html) (under the downloads section).
+The example snippets can be found in the source code and the package under `aocl-crypto/examples/`
-
-cd amd-crypto;
-make;
-export LD_LIBRARY_PATH=$PWD/lib:$LD_LIBRARY_PATH;
-
+**An example [snippet](https://github.com/amd/aocl-crypto/blob/main/examples/cipher/aes-cfb.c) for AES CFB Cipher**
-## NOTE:
-To compile and run the examples from the AOCL installed directory
-cd /amd-crypto/;
-export C_INCLUDE_PATH=/include/$C_INCLUDE_PATH;
+To compile AOCL-Cryptography with examples, refer to
+ - [ Linux ](md_Combine_build.html#md_BUILD)
+ - [ Windows ](md_Combine_build.html#md_BUILD_Windows)
+
+The examples executables for each module will be generated in aocl-crypto/build/examples/
+
+**NOTE:**
+The AOCL-Cryptography has a dependency on OpenSSL libcrypto library and also AOCL Utils library.
+Please make sure the below paths are added to the environment variables
+
+[//]: # (There are spaces intentionaly left to break line below)
+
+**Execute Examples On Linux OS**
+Export the following paths:
+
+```bash
+export LIBRARY_PATH=\:$LIBRARY_PATH;
+export LIBRARY_PATH=\:$LIBRARY_PATH;
+export LD_LIBRARY_PATH=\:$LD_LIBRARY_PATH;
+export LD_LIBRARY_PATH=\:$LD_LIBRARY_PATH;
+```
+
+Now to run any executable:
+`./examples/cipher/aes-cfb`
+
+
+**Execute Examples On Windows OS**
+Run the script:
+`.\scripts\Set_Env_Path.bat`
+
+
+Now to run any executable:
+`.\examples\cipher\release\aes-cfb.exe`
+
+
+## Build and Run AOCL-Cryptography examples from the AOCL Crypto release package (Linux)
+
+**Download the tar package from https://www.amd.com/en/developer/aocl/cryptography.html (under the downloads section)**
+
+**NOTE:**
+The AOCL-Cryptography library has a dependency on OpenSSL libcrypto library and also AOCL Utils library.
+Please make sure these library paths are added to the environment variables LIBRARY_PATH and LD_LIBRARY_PATH
+
+Also, please ensure the variable OPENSSL_INSTALL_DIR is set.
+`export OPENSSL_INSTALL_DIR=\;`
+
+
+**To run the examples linking to AOCL-Cryptography shared library:**
+
+```bash
+# Ensure OpenSSL is available with linker
+export LIBRARY_PATH=/path/to/openssl_install/lib:$LIBRARY_PATH;
+# Ensure AOCL-Utils is available with linker
+export LIBRARY_PATH=/path/to/aocl-utils/lib:$LIBRARY_PATH;
+# Ensure OpenSSL is available with loader
+export LD_LIBRARY_PATH=/path/to/openssl_install/lib:$LD_LIBRARY_PATH;
+# Ensure AOCL-Utils is available with loader
+export LD_LIBRARY_PATH=/path/to/aocl-utils/lib:$LD_LIBRARY_PATH;
+cd amd-crypto;
+make;
+```
+
+
+**To run the examples linking to AOCL-Cryptography static library:**
+
+```bash
+cd amd-crypto;
+make LIB_TYPE=static;
+```
+
+
+## To compile and run the examples from the AOCL-Cryptography installed directory:
+```bash
+cd /path/to/amd-crypto;
+export C_INCLUDE_PATH=$PWD/include:$C_INCLUDE_PATH;
make -j;
+```
-## Run the Examples:
-
-$PWD/bin/cipher/aes-speed-cipher;
-
+**Run the Examples:**
+`./bin/cipher/aes-cfb;`
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index 6b986584e..13451e306 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -41,6 +41,8 @@ ADD_SUBDIRECTORY(mac)
ADD_SUBDIRECTORY(rsa)
+ADD_SUBDIRECTORY(misc)
+
ADD_SUBDIRECTORY(version)
LINK_LIBRARIES(alcp)
diff --git a/examples/Makefile b/examples/Makefile
index 92d2ef8d5..b3c62a768 100644
--- a/examples/Makefile
+++ b/examples/Makefile
@@ -26,9 +26,6 @@
# Output directory
OBJ := bin
-# Default compiler
-CC := gcc
-
# link to static or shared lib
LIB_TYPE = dynamic #default value
@@ -43,7 +40,7 @@ LFLAGS := -L $(LIB_DIR) -lalcp -laoclutils
# if linking to static lib
ifeq ($(LIB_TYPE), static)
- LFLAGS = -L$(LIB_DIR) -l:libalcp.a -lstdc++ -lcrypto
+ LFLAGS = -no-pie -L$(LIB_DIR) -L$(OPENSSL_INSTALL_DIR) -Wl,-Bstatic -l:libalcp.a -l:libaoclutils.a -lcrypto -Wl,-Bdynamic -lcrypto -lstdc++ -lpthread -ldl
endif
# Add more targets as they come.
@@ -55,7 +52,7 @@ TARGETS := cipher/aes-cfb cipher/aes-speed-cipher cipher/aes-speed-gcm cipher/ae
rng/rng-demo \
mac/hmac mac/cmac \
ecdh/x25519_example \
- rsa/rsa_peer rsa/rsa_encrypt rsa/rsa_decrypt \
+ rsa/rsa_peer rsa/rsa_encrypt rsa/rsa_decrypt rsa/rsa_2048 rsa/rsa_oaep rsa/rsa_oaep_2048 \
version/version-demo
.PHONY: all
@@ -63,7 +60,7 @@ TARGETS := cipher/aes-cfb cipher/aes-speed-cipher cipher/aes-speed-gcm cipher/ae
all: banner create build
banner:
- @echo "Building examples for AOCL-Crypto"
+ @echo "Building examples for AOCL Cryptography"
create:
@mkdir -p $(OBJ)/cipher
diff --git a/examples/cipher/CMakeLists.txt b/examples/cipher/CMakeLists.txt
index 125e13214..27a5e280a 100644
--- a/examples/cipher/CMakeLists.txt
+++ b/examples/cipher/CMakeLists.txt
@@ -23,11 +23,6 @@
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
-#INCLUDE_DIRECTORIES(
-# ${CMAKE_SOURCE_DIR}/include
-# ${CMAKE_SOURCE_DIR}/lib/include
-# )
-
ADD_EXAMPLE(aes-cfb aes-cfb.c)
ADD_EXAMPLE(aes-gcm aes-gcm.c)
@@ -38,8 +33,11 @@ ADD_EXAMPLE(aes-ccm aes-ccm.c)
ADD_EXAMPLE(aes-siv aes-siv.c)
+ADD_EXAMPLE(chacha20 chacha20.c)
+
ADD_EXAMPLE(aes-speed-cipher aes-speed-cipher.c)
ADD_EXAMPLE(aes-speed-gcm aes-speed-gcm.c)
+
diff --git a/examples/cipher/aes-ccm.c b/examples/cipher/aes-ccm.c
index 1441dec10..9276c6284 100644
--- a/examples/cipher/aes-ccm.c
+++ b/examples/cipher/aes-ccm.c
@@ -39,22 +39,14 @@ static alc_cipher_handle_t handle;
char*
bytesToHexString(unsigned char* bytes, int length);
-void
+int
create_demo_session(const Uint8* key, const Uint8* iv, const Uint32 key_len)
{
alc_error_t err;
const int err_size = 256;
Uint8 err_buf[err_size];
- /*
- const alc_key_info_t kinfo = {
- .type = ALC_KEY_TYPE_SYMMETRIC,
- .fmt = ALC_KEY_FMT_RAW,
- .key = key,
- .len = key_len,
- };
- */
- alc_cipher_info_t cinfo = {
+ alc_cipher_aead_info_t cinfo = {
.ci_type = ALC_CIPHER_TYPE_AES,
.ci_algo_info = {
.ai_mode = ALC_AES_MODE_CCM,
@@ -77,68 +69,29 @@ create_demo_session(const Uint8* key, const Uint8* iv, const Uint32 key_len)
*
* This query call is provided to support fallback mode for applications
*/
- err = alcp_cipher_supported(&cinfo);
+ err = alcp_cipher_aead_supported(&cinfo);
if (alcp_is_error(err)) {
printf("Error: not supported \n");
alcp_error_str(err, err_buf, err_size);
- return;
+ return -1;
}
printf("supported succeeded\n");
/*
* Application is expected to allocate for context
*/
- handle.ch_context = malloc(alcp_cipher_context_size(&cinfo));
- // if (!ctx)
- // return;
+ handle.ch_context = malloc(alcp_cipher_aead_context_size(&cinfo));
+ if (!handle.ch_context)
+ return -1;
/* Request a context with cinfo */
- err = alcp_cipher_request(&cinfo, &handle);
+ err = alcp_cipher_aead_request(&cinfo, &handle);
if (alcp_is_error(err)) {
printf("Error: unable to request \n");
alcp_error_str(err, err_buf, err_size);
- return;
+ return -1;
}
printf("request succeeded\n");
-}
-
-void
-encrypt_demo(const Uint8* plaintxt,
- const Uint32 len, /* for both 'plaintxt' and 'ciphertxt' */
- Uint8* ciphertxt,
- const Uint8* iv)
-{
- alc_error_t err;
- const int err_size = 256;
- Uint8 err_buf[err_size];
-
- err = alcp_cipher_encrypt(&handle, plaintxt, ciphertxt, len, iv);
- if (alcp_is_error(err)) {
- printf("Error: unable to encrypt \n");
- alcp_error_str(err, err_buf, err_size);
- return;
- }
-
- printf("encrypt succeeded\n");
-}
-
-void
-decrypt_demo(const Uint8* ciphertxt,
- const Uint32 len, /* for both 'plaintxt' and 'ciphertxt' */
- Uint8* plaintxt,
- const Uint8* iv)
-{
- alc_error_t err;
- const int err_size = 256;
- Uint8 err_buf[err_size];
-
- err = alcp_cipher_decrypt(&handle, ciphertxt, plaintxt, len, iv);
- if (alcp_is_error(err)) {
- printf("Error: unable decrypt \n");
- alcp_error_str(err, err_buf, err_size);
- return;
- }
-
- printf("decrypt succeeded\n");
+ return 0;
}
static Uint8* sample_plaintxt =
@@ -204,7 +157,7 @@ alloc_and_test()
}
/* CCM: Authenticated Encryption demo */
-void
+int
aclp_aes_ccm_encrypt_demo(
const Uint8* plaintxt,
const Uint32 len, /* Describes both 'plaintxt' and 'ciphertxt' */
@@ -221,48 +174,50 @@ aclp_aes_ccm_encrypt_demo(
Uint8 err_buf[err_size];
// set tag length
- err = alcp_cipher_set_tag_length(&handle, tagLen);
+ err = alcp_cipher_aead_set_tag_length(&handle, tagLen);
if (alcp_is_error(err)) {
printf("Error: unable getting tag \n");
alcp_error_str(err, err_buf, err_size);
- return;
+ return -1;
}
// CCM init
- err = alcp_cipher_set_iv(&handle, ivLen, iv);
+ err = alcp_cipher_aead_set_iv(&handle, ivLen, iv);
if (alcp_is_error(err)) {
printf("Error: unable ccm encrypt init \n");
alcp_error_str(err, err_buf, err_size);
- return;
+ return -1;
}
// Additional Data
- err = alcp_cipher_set_aad(&handle, ad, adLen);
+ err = alcp_cipher_aead_set_aad(&handle, ad, adLen);
if (alcp_is_error(err)) {
printf("Error: unable ccm add data processing \n");
alcp_error_str(err, err_buf, err_size);
- return;
+ return -1;
}
// CCM encrypt
- err = alcp_cipher_encrypt_update(&handle, plaintxt, ciphertxt, len, iv);
+ err =
+ alcp_cipher_aead_encrypt_update(&handle, plaintxt, ciphertxt, len, iv);
if (alcp_is_error(err)) {
printf("Error: unable encrypt \n");
alcp_error_str(err, err_buf, err_size);
- return;
+ return -1;
}
// get tag
- err = alcp_cipher_get_tag(&handle, tag, tagLen);
+ err = alcp_cipher_aead_get_tag(&handle, tag, tagLen);
if (alcp_is_error(err)) {
printf("Error: unable getting tag \n");
alcp_error_str(err, err_buf, err_size);
- return;
+ return -1;
}
+ return 0;
}
/* CCM: Authenticated Decryption demo */
-void
+int
aclp_aes_ccm_decrypt_demo(const Uint8* ciphertxt,
const Uint32 len,
Uint8* plaintxt,
@@ -279,43 +234,44 @@ aclp_aes_ccm_decrypt_demo(const Uint8* ciphertxt,
Uint8 tagDecrypt[16];
// set tag length
- err = alcp_cipher_set_tag_length(&handle, tagLen);
+ err = alcp_cipher_aead_set_tag_length(&handle, tagLen);
if (alcp_is_error(err)) {
printf("Error: unable getting tag \n");
alcp_error_str(err, err_buf, err_size);
- return;
+ return -1;
}
// GCM init
- err = alcp_cipher_set_iv(&handle, ivLen, iv);
+ err = alcp_cipher_aead_set_iv(&handle, ivLen, iv);
if (alcp_is_error(err)) {
printf("Error: unable gcm decrypt init \n");
alcp_error_str(err, err_buf, err_size);
- return;
+ return -1;
}
// Additional Data
- err = alcp_cipher_set_aad(&handle, ad, adLen);
+ err = alcp_cipher_aead_set_aad(&handle, ad, adLen);
if (alcp_is_error(err)) {
printf("Error: unable gcm add data processing \n");
alcp_error_str(err, err_buf, err_size);
- return;
+ return -1;
}
// GCM decrypt
- err = alcp_cipher_decrypt_update(&handle, ciphertxt, plaintxt, len, iv);
+ err =
+ alcp_cipher_aead_decrypt_update(&handle, ciphertxt, plaintxt, len, iv);
if (alcp_is_error(err)) {
printf("Error: unable decrypt \n");
alcp_error_str(err, err_buf, err_size);
- return;
+ return -1;
}
// get tag
- err = alcp_cipher_get_tag(&handle, tagDecrypt, tagLen);
+ err = alcp_cipher_aead_get_tag(&handle, tagDecrypt, tagLen);
if (alcp_is_error(err)) {
printf("Error: unable getting tag \n");
alcp_error_str(err, err_buf, err_size);
- return;
+ return -1;
}
char* hex_tagDecrypt = bytesToHexString(tagDecrypt, 14);
@@ -333,28 +289,34 @@ aclp_aes_ccm_decrypt_demo(const Uint8* ciphertxt,
if (isTagMatched == false) {
printf("\n tag mismatched, input encrypted data is not trusthworthy ");
memset(plaintxt, 0, len);
+ return -1;
}
+ return 0;
}
int
main(void)
{
+ int retval = 0;
Uint8 sample_output[512] = { 0 };
Uint8 sample_tag_output[17] = { 0 };
assert(sizeof(sample_plaintxt) < sizeof(sample_output));
- create_demo_session(sample_key, sample_iv, sizeof(sample_key) * 8);
-
- aclp_aes_ccm_encrypt_demo(sample_plaintxt,
- strlen((const char*)sample_plaintxt),
- sample_ciphertxt,
- sample_iv,
- sizeof(sample_iv),
- sample_ad,
- strlen((const char*)sample_ad),
- sample_tag_output,
- 14);
+ retval = create_demo_session(sample_key, sample_iv, sizeof(sample_key) * 8);
+ if (retval != 0)
+ goto out;
+ retval = aclp_aes_ccm_encrypt_demo(sample_plaintxt,
+ strlen((const char*)sample_plaintxt),
+ sample_ciphertxt,
+ sample_iv,
+ sizeof(sample_iv),
+ sample_ad,
+ strlen((const char*)sample_ad),
+ sample_tag_output,
+ 14);
+ if (retval != 0)
+ goto out;
int size = strlen((const char*)sample_plaintxt);
@@ -372,26 +334,30 @@ main(void)
free(hex_sample_input);
free(hex_sample_tag_output);
- aclp_aes_ccm_decrypt_demo(sample_ciphertxt,
- size,
- sample_output,
- sample_iv,
- sizeof(sample_iv),
- sample_ad,
- strlen((const char*)sample_ad),
- sample_tag_output,
- 14);
-
+ retval = aclp_aes_ccm_decrypt_demo(sample_ciphertxt,
+ size,
+ sample_output,
+ sample_iv,
+ sizeof(sample_iv),
+ sample_ad,
+ strlen((const char*)sample_ad),
+ sample_tag_output,
+ 14);
+ if (retval != 0)
+ goto out;
printf("sample_output: %s\n", sample_output);
// /*
// * Complete the transaction
// */
- alcp_cipher_finish(&handle);
+ alcp_cipher_aead_finish(&handle);
free(handle.ch_context);
return 0;
+
+out:
+ return -1;
}
/* LocalWords: decrypt Crypto AOCL
diff --git a/examples/cipher/aes-cfb.c b/examples/cipher/aes-cfb.c
index 595889dd5..e5e01e094 100644
--- a/examples/cipher/aes-cfb.c
+++ b/examples/cipher/aes-cfb.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2022-2023, Advanced Micro Devices. All rights reserved.
+ * Copyright (C) 2021-2023, Advanced Micro Devices. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -48,7 +48,7 @@ dump_hex(Uint8* value, size_t size)
printf("\n");
}
-void
+int
create_demo_session(alc_cipher_handle_p handle,
const Uint8* key,
const Uint8* iv,
@@ -94,7 +94,7 @@ create_demo_session(alc_cipher_handle_p handle,
// Memory allocation failure checking
if (handle->ch_context == NULL) {
printf("Error: Memory Allocation Failed!\n");
- exit(-1);
+ goto out;
}
/* Request a context with cinfo */
@@ -104,16 +104,16 @@ create_demo_session(alc_cipher_handle_p handle,
goto out;
}
printf("Request Succeeded\n");
- return;
+ return 0;
// Incase of error, program execution will come here
out:
alcp_error_str(err, err_buf, cErrSize);
printf("%s\n", err_buf);
- return;
+ return -1;
}
-void
+int
encrypt_demo(alc_cipher_handle_p handle,
const Uint8* plaintxt,
const Uint32 len, /* for both 'plaintxt' and 'ciphertxt' */
@@ -129,13 +129,14 @@ encrypt_demo(alc_cipher_handle_p handle,
printf("Error: Unable to Encrypt \n");
alcp_error_str(err, err_buf, err_size);
printf("%s\n", err_buf);
- return;
+ return -1;
}
printf("Encrypt succeeded\n");
+ return 0;
}
-void
+int
decrypt_demo(alc_cipher_handle_p handle,
const Uint8* ciphertxt,
const Uint32 len, /* for both 'plaintxt' and 'ciphertxt' */
@@ -151,10 +152,11 @@ decrypt_demo(alc_cipher_handle_p handle,
printf("Error: Unable to Decrypt \n");
alcp_error_str(err, err_buf, err_size);
printf("%s\n", err_buf);
- return;
+ return -1;
}
printf("Decrypt Succeeded\n");
+ return 0;
}
// Plain text to encrypt, it should be 128bits (16bytes) multiple.
@@ -183,6 +185,7 @@ static Uint8 sample_ciphertxt[512] = {
int
main(void)
{
+ int retval = 0;
// Buffer to write plain text into.
// It should have size greater than or equal to the plaintext.
Uint8 sample_output[512] = { 0 };
@@ -194,21 +197,28 @@ main(void)
// Create the handle, this handle will be used for encrypt and decrypt
// operations
alc_cipher_handle_t handle;
- create_demo_session(&handle, sample_key, sample_iv, ALC_KEY_LEN_128);
+ retval =
+ create_demo_session(&handle, sample_key, sample_iv, ALC_KEY_LEN_128);
+ if (retval != 0)
+ goto out;
// Encrypt the plaintext into the ciphertext
- encrypt_demo(&handle,
- sample_plaintxt,
- cPlaintextSize, /* len of 'plaintxt' and 'ciphertxt' */
- sample_ciphertxt,
- sample_iv);
-
+ retval =
+ encrypt_demo(&handle,
+ sample_plaintxt,
+ cPlaintextSize, /* len of 'plaintxt' and 'ciphertxt' */
+ sample_ciphertxt,
+ sample_iv);
+ if (retval != 0)
+ goto out;
printf("CipherText:");
dump_hex(sample_ciphertxt, cCiphertextSize);
// Decrypt the ciphertext into the plaintext.
- decrypt_demo(
+ retval = decrypt_demo(
&handle, sample_ciphertxt, cCiphertextSize, sample_output, sample_iv);
+ if (retval != 0)
+ goto out;
printf("Decrypted Text: %s\n", sample_output);
/*
@@ -220,6 +230,8 @@ main(void)
free(handle.ch_context);
return 0;
+out:
+ return -1;
}
/* LocalWords: decrypt Crypto AOCL
diff --git a/examples/cipher/aes-gcm.c b/examples/cipher/aes-gcm.c
index 3676b8a76..f3ec4dd8c 100644
--- a/examples/cipher/aes-gcm.c
+++ b/examples/cipher/aes-gcm.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2022-2023, Advanced Micro Devices. All rights reserved.
+ * Copyright (C) 2023, Advanced Micro Devices. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -322,7 +322,7 @@ static Uint8 test_ad[TEST_VECTOR_COUNT][48] = {{0xe7, 0xe5, 0xe6, 0xf8, 0xda, 0x
// clang-format on
-void
+int
create_aes_session(Uint8* key,
Uint8* iv,
const Uint32 key_len,
@@ -336,19 +336,11 @@ create_aes_session(Uint8* key,
0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xf, 0xf,
};
- alc_key_info_t kinfo = {
- .type = ALC_KEY_TYPE_SYMMETRIC,
- .fmt = ALC_KEY_FMT_RAW,
- .key = tweakKey,
- .len = key_len,
- };
-
- alc_cipher_info_t cinfo = {
+ alc_cipher_aead_info_t cinfo = {
.ci_type = ALC_CIPHER_TYPE_AES,
.ci_algo_info = {
.ai_mode = mode,
.ai_iv = iv,
- .ai_xts = &kinfo,
},
/* No padding, Not Implemented yet*/
//.pad = ALC_CIPHER_PADDING_NONE,
@@ -362,37 +354,38 @@ create_aes_session(Uint8* key,
/*
* Check if the current cipher is supported,
- * optional call, alcp_cipher_request() will anyway return
+ * optional call, alcp_cipher_aead_request() will anyway return
* ALC_ERR_NOSUPPORT error.
*
* This query call is provided to support fallback mode for applications
*/
- err = alcp_cipher_supported(&cinfo);
+ err = alcp_cipher_aead_supported(&cinfo);
if (alcp_is_error(err)) {
printf("Error: not supported \n");
alcp_error_str(err, err_buf, err_size);
- return;
+ return -1;
}
/*
* Application is expected to allocate for context
*/
- handle.ch_context = malloc(alcp_cipher_context_size(&cinfo));
- // if (!ctx)
- // return;
+ handle.ch_context = malloc(alcp_cipher_aead_context_size(&cinfo));
+ if (!handle.ch_context)
+ return -1;
/* Request a context with cinfo */
- err = alcp_cipher_request(&cinfo, &handle);
+ err = alcp_cipher_aead_request(&cinfo, &handle);
if (alcp_is_error(err)) {
printf("Error: unable to request \n");
alcp_error_str(err, err_buf, err_size);
- return;
+ return -1;
}
+ return 0;
}
/* GCM: Authenticated Encryption demo */
-void
-aclp_aes_gcm_encrypt_demo(
+int
+alcp_aes_gcm_encrypt_demo(
const Uint8* plaintxt,
const Uint32 len, /* Describes both 'plaintxt' and 'ciphertxt' */
Uint8* ciphertxt,
@@ -408,41 +401,43 @@ aclp_aes_gcm_encrypt_demo(
Uint8 err_buf[err_size];
// GCM init
- err = alcp_cipher_set_iv(&handle, ivLen, iv);
+ err = alcp_cipher_aead_set_iv(&handle, ivLen, iv);
if (alcp_is_error(err)) {
printf("Error: unable gcm encrypt init \n");
alcp_error_str(err, err_buf, err_size);
- return;
+ return -1;
}
// Additional Data
- err = alcp_cipher_set_aad(&handle, ad, adLen);
+ err = alcp_cipher_aead_set_aad(&handle, ad, adLen);
if (alcp_is_error(err)) {
printf("Error: unable gcm add data processing \n");
alcp_error_str(err, err_buf, err_size);
- return;
+ return -1;
}
// GCM encrypt
- err = alcp_cipher_encrypt_update(&handle, plaintxt, ciphertxt, len, iv);
+ err =
+ alcp_cipher_aead_encrypt_update(&handle, plaintxt, ciphertxt, len, iv);
if (alcp_is_error(err)) {
printf("Error: unable encrypt \n");
alcp_error_str(err, err_buf, err_size);
- return;
+ return -1;
}
// get tag
- err = alcp_cipher_get_tag(&handle, tag, tagLen);
+ err = alcp_cipher_aead_get_tag(&handle, tag, tagLen);
if (alcp_is_error(err)) {
printf("Error: unable getting tag \n");
alcp_error_str(err, err_buf, err_size);
- return;
+ return -1;
}
+ return 0;
}
/* GCM: Authenticated Decryption demo */
-void
-aclp_aes_gcm_decrypt_demo(const Uint8* ciphertxt,
+int
+alcp_aes_gcm_decrypt_demo(const Uint8* ciphertxt,
const Uint32 len,
Uint8* plaintxt,
Uint8* iv,
@@ -458,35 +453,36 @@ aclp_aes_gcm_decrypt_demo(const Uint8* ciphertxt,
Uint8 tagDecrypt[16];
// GCM init
- err = alcp_cipher_set_iv(&handle, ivLen, iv);
+ err = alcp_cipher_aead_set_iv(&handle, ivLen, iv);
if (alcp_is_error(err)) {
printf("Error: unable gcm encrypt init \n");
alcp_error_str(err, err_buf, err_size);
- return;
+ return -1;
}
// Additional Data
- err = alcp_cipher_set_aad(&handle, ad, adLen);
+ err = alcp_cipher_aead_set_aad(&handle, ad, adLen);
if (alcp_is_error(err)) {
printf("Error: unable gcm add data processing \n");
alcp_error_str(err, err_buf, err_size);
- return;
+ return -1;
}
// GCM decrypt
- err = alcp_cipher_decrypt_update(&handle, ciphertxt, plaintxt, len, iv);
+ err =
+ alcp_cipher_aead_decrypt_update(&handle, ciphertxt, plaintxt, len, iv);
if (alcp_is_error(err)) {
printf("Error: unable decrypt \n");
alcp_error_str(err, err_buf, err_size);
- return;
+ return -1;
}
// get tag
- err = alcp_cipher_get_tag(&handle, tagDecrypt, tagLen);
+ err = alcp_cipher_aead_get_tag(&handle, tagDecrypt, tagLen);
if (alcp_is_error(err)) {
printf("Error: unable getting tag \n");
alcp_error_str(err, err_buf, err_size);
- return;
+ return -1;
}
bool isTagMatched = true;
@@ -501,12 +497,14 @@ aclp_aes_gcm_decrypt_demo(const Uint8* ciphertxt,
// printf("\n tag mismatched, input encrypted data is not trusthworthy
// ");
memset(plaintxt, 0, len);
+ return -1;
}
+ return 0;
}
/* Function takes input data from standard test vector for specific test number
* & validates tag generated.*/
-void
+int
gcm_selftest(Uint8* inputText, // plaintext
Uint32 inputLen, // input length
Uint8* cipherText, // ciphertext output
@@ -514,6 +512,7 @@ gcm_selftest(Uint8* inputText, // plaintext
int i,
Uint8 testNumber)
{
+ int retval = 0;
unsigned int keybits;
Uint8 key[32];
int ret = 0;
@@ -571,8 +570,10 @@ gcm_selftest(Uint8* inputText, // plaintext
create_aes_session(key, iv, keybits, m);
// Encrypt
- aclp_aes_gcm_encrypt_demo(
+ retval = alcp_aes_gcm_encrypt_demo(
inputText, inputLen, cipherText, iv, ivLen, ad, adLen, tag, tagLen);
+ if (retval != 0)
+ goto out;
printf("\nGCM-Encrypt ");
printText(cipherText, inputLen, "cipherTxt", verboseprint);
@@ -584,17 +585,21 @@ gcm_selftest(Uint8* inputText, // plaintext
}
// Decrypt
- aclp_aes_gcm_decrypt_demo(
+ retval = alcp_aes_gcm_decrypt_demo(
cipherText, inputLen, outputText, iv, ivLen, ad, adLen, tag, tagLen);
+ if (retval != 0)
+ goto out;
printf("\nGCM-Decrypt ");
printText(outputText, inputLen, "outputTxt", verboseprint);
printText(tag, tagLen, "tagDec ", verboseprint);
if (memcmp(test_tag[testNumber], tag, (long unsigned int)tagLen) != 0) {
printf("\n\t\t\t\t Encrypt Tag mismatch: Test FAILED \n");
+ goto out;
}
if (memcmp(inputText, outputText, (long unsigned int)inputLen) != 0) {
printf("\n\t\t\t\t input->enc->dec->input FAILED \n");
+ goto out;
} else {
printf("\t test PASSED ");
}
@@ -602,7 +607,7 @@ gcm_selftest(Uint8* inputText, // plaintext
/*
* Complete the transaction
*/
- alcp_cipher_finish(&handle);
+ alcp_cipher_aead_finish(&handle);
free(handle.ch_context);
if (outputText) {
@@ -617,12 +622,17 @@ gcm_selftest(Uint8* inputText, // plaintext
if (ad) {
free(ad);
}
+ return 0;
+
+out:
+ return -1;
}
// Demo of GCM with std testor vectors
int
runGCMAutoTest()
{
+ int retval = 0;
Uint8* inputText;
Uint8* cipherText;
@@ -653,12 +663,15 @@ runGCMAutoTest()
}
// run full path demo for specific aes mode
- gcm_selftest(inputText,
- inputLen, /* len of both 'plaintxt' and 'ciphertxt' */
- cipherText,
- ALC_AES_MODE_GCM,
- keySizeItr,
- testNumber);
+ retval =
+ gcm_selftest(inputText,
+ inputLen, /* len of both 'plaintxt' and 'ciphertxt' */
+ cipherText,
+ ALC_AES_MODE_GCM,
+ keySizeItr,
+ testNumber);
+ if (retval != 0)
+ return retval;
// its time to free!
if (inputText) {
diff --git a/examples/cipher/aes-siv.c b/examples/cipher/aes-siv.c
index 9a78ce0a2..3943db73a 100644
--- a/examples/cipher/aes-siv.c
+++ b/examples/cipher/aes-siv.c
@@ -54,7 +54,7 @@ create_demo_session(const Uint8* key_cmac,
kinfo.key = key_ctr;
kinfo.len = key_len;
- alc_cipher_info_t cinfo = {
+ alc_cipher_aead_info_t cinfo = {
.ci_type = ALC_CIPHER_TYPE_AES,
.ci_algo_info = {
.ai_mode = ALC_AES_MODE_SIV,
@@ -73,12 +73,12 @@ create_demo_session(const Uint8* key_cmac,
/*
* Check if the current cipher is supported,
- * optional call, alcp_cipher_request() will anyway return
+ * optional call, alcp_cipher_aead_request() will anyway return
* ALC_ERR_NOSUPPORT error.
*
* This query call is provided to support fallback mode for applications
*/
- err = alcp_cipher_supported(&cinfo);
+ err = alcp_cipher_aead_supported(&cinfo);
if (alcp_is_error(err)) {
printf("Error: not supported \n");
alcp_error_str(err, err_buf, err_size);
@@ -88,12 +88,12 @@ create_demo_session(const Uint8* key_cmac,
/*
* Application is expected to allocate for context
*/
- handle.ch_context = malloc(alcp_cipher_context_size(&cinfo));
+ handle.ch_context = malloc(alcp_cipher_aead_context_size(&cinfo));
// if (!ctx)
// return;
/* Request a context with cinfo */
- err = alcp_cipher_request(&cinfo, &handle);
+ err = alcp_cipher_aead_request(&cinfo, &handle);
if (alcp_is_error(err)) {
printf("Error: unable to request \n");
alcp_error_str(err, err_buf, err_size);
@@ -116,7 +116,7 @@ encrypt_demo(const Uint8* plaintxt,
const int err_size = 256;
Uint8 err_buf[err_size];
- err = alcp_cipher_set_aad(&handle, aad, aad_len);
+ err = alcp_cipher_aead_set_aad(&handle, aad, aad_len);
if (alcp_is_error(err)) {
printf("Error: unable to encrypt \n");
alcp_error_str(err, err_buf, err_size);
@@ -124,21 +124,21 @@ encrypt_demo(const Uint8* plaintxt,
}
// IV is not needed for encrypt, but still should not be NullPtr
- err = alcp_cipher_encrypt(&handle, plaintxt, ciphertxt, len, iv);
+ err = alcp_cipher_aead_encrypt(&handle, plaintxt, ciphertxt, len, iv);
if (alcp_is_error(err)) {
printf("Error: unable to encrypt \n");
alcp_error_str(err, err_buf, err_size);
return false;
}
- err = alcp_cipher_get_tag(&handle, iv, 16);
+ err = alcp_cipher_aead_get_tag(&handle, iv, 16);
if (alcp_is_error(err)) {
printf("Error: unable to encrypt \n");
alcp_error_str(err, err_buf, err_size);
return false;
}
- alcp_cipher_finish(&handle);
+ alcp_cipher_aead_finish(&handle);
free(handle.ch_context);
@@ -159,21 +159,21 @@ decrypt_demo(const Uint8* ciphertxt,
const int err_size = 256;
Uint8 err_buf[err_size];
- err = alcp_cipher_set_aad(&handle, aad, aad_len);
+ err = alcp_cipher_aead_set_aad(&handle, aad, aad_len);
if (alcp_is_error(err)) {
printf("Error: unable to encrypt \n");
alcp_error_str(err, err_buf, err_size);
return false;
}
- err = alcp_cipher_decrypt(&handle, ciphertxt, plaintxt, len, iv);
+ err = alcp_cipher_aead_decrypt(&handle, ciphertxt, plaintxt, len, iv);
if (alcp_is_error(err)) {
printf("Error: unable decrypt \n");
alcp_error_str(err, err_buf, err_size);
return false;
}
- alcp_cipher_finish(&handle);
+ alcp_cipher_aead_finish(&handle);
free(handle.ch_context);
diff --git a/examples/cipher/aes-speed-cipher.c b/examples/cipher/aes-speed-cipher.c
index e17cf44b5..df57cee96 100644
--- a/examples/cipher/aes-speed-cipher.c
+++ b/examples/cipher/aes-speed-cipher.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2022-2023, Advanced Micro Devices. All rights reserved.
+ * Copyright (C) 2023, Advanced Micro Devices. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -130,19 +130,12 @@ create_aes_session(Uint8* key,
0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xf, 0xf,
};
- alc_key_info_t kinfo = {
- .type = ALC_KEY_TYPE_SYMMETRIC,
- .fmt = ALC_KEY_FMT_RAW,
- .key = tweakKey,
- .len = key_len,
- };
alc_cipher_info_t cinfo = {
.ci_type = ALC_CIPHER_TYPE_AES,
.ci_algo_info = {
.ai_mode = mode,
.ai_iv = iv,
- .ai_xts = &kinfo,
},
/* No padding, Not Implemented yet*/
//.pad = ALC_CIPHER_PADDING_NONE,
diff --git a/examples/cipher/aes-speed-gcm.c b/examples/cipher/aes-speed-gcm.c
index 1fcb69e31..8efb2ade1 100644
--- a/examples/cipher/aes-speed-gcm.c
+++ b/examples/cipher/aes-speed-gcm.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2022-2023, Advanced Micro Devices. All rights reserved.
+ * Copyright (C) 2023, Advanced Micro Devices. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -123,24 +123,12 @@ create_aes_session(Uint8* key,
alc_error_t err;
const int err_size = 256;
Uint8 err_buf[err_size];
- Uint8 tweakKey[16] = {
- 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
- 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xf, 0xf,
- };
-
- alc_key_info_t kinfo = {
- .type = ALC_KEY_TYPE_SYMMETRIC,
- .fmt = ALC_KEY_FMT_RAW,
- .key = tweakKey,
- .len = key_len,
- };
- alc_cipher_info_t cinfo = {
+ alc_cipher_aead_info_t cinfo = {
.ci_type = ALC_CIPHER_TYPE_AES,
.ci_algo_info = {
.ai_mode = mode,
.ai_iv = iv,
- .ai_xts = &kinfo,
},
/* No padding, Not Implemented yet*/
//.pad = ALC_CIPHER_PADDING_NONE,
@@ -159,7 +147,7 @@ create_aes_session(Uint8* key,
*
* This query call is provided to support fallback mode for applications
*/
- err = alcp_cipher_supported(&cinfo);
+ err = alcp_cipher_aead_supported(&cinfo);
if (alcp_is_error(err)) {
printf("Error: not supported \n");
alcp_error_str(err, err_buf, err_size);
@@ -169,12 +157,12 @@ create_aes_session(Uint8* key,
/*
* Application is expected to allocate for context
*/
- handle.ch_context = malloc(alcp_cipher_context_size(&cinfo));
+ handle.ch_context = malloc(alcp_cipher_aead_context_size(&cinfo));
// if (!ctx)
// return;
/* Request a context with cinfo */
- err = alcp_cipher_request(&cinfo, &handle);
+ err = alcp_cipher_aead_request(&cinfo, &handle);
if (alcp_is_error(err)) {
printf("Error: unable to request \n");
alcp_error_str(err, err_buf, err_size);
@@ -200,7 +188,7 @@ aclp_aes_gcm_encrypt_demo(
Uint8 err_buf[err_size];
// GCM init
- err = alcp_cipher_set_iv(&handle, ivLen, iv);
+ err = alcp_cipher_aead_set_iv(&handle, ivLen, iv);
if (alcp_is_error(err)) {
printf("Error: unable gcm encrypt init \n");
alcp_error_str(err, err_buf, err_size);
@@ -208,23 +196,43 @@ aclp_aes_gcm_encrypt_demo(
}
// Additional Data
- err = alcp_cipher_set_aad(&handle, ad, adLen);
+ err = alcp_cipher_aead_set_aad(&handle, ad, adLen);
if (alcp_is_error(err)) {
printf("Error: unable gcm add data processing \n");
alcp_error_str(err, err_buf, err_size);
return;
}
- // GCM encrypt
- err = alcp_cipher_encrypt_update(&handle, plaintxt, ciphertxt, len, iv);
- if (alcp_is_error(err)) {
- printf("Error: unable encrypt \n");
- alcp_error_str(err, err_buf, err_size);
- return;
+ totalTimeElapsed = 0.0;
+ for (int k = 0; k < 100000000; k++) { // 100000000
+ ALCP_CRYPT_TIMER_START
+
+ // GCM encrypt
+ err = alcp_cipher_aead_encrypt_update(
+ &handle, plaintxt, ciphertxt, len, iv);
+ if (alcp_is_error(err)) {
+ printf("Error: unable encrypt \n");
+ alcp_error_str(err, err_buf, err_size);
+ return;
+ }
+
+ alcp_get_time(0, "Encrypt time");
+
+ // plaintxt += len;
+ // ciphertxt += len;
+
+ if (totalTimeElapsed > .5) {
+ printf(
+ "\t : %6.3lf GB Encrypted per second with block size "
+ "(%5d bytes) ",
+ (double)(((k / 1000.0) * len) / (totalTimeElapsed * 1000000.0)),
+ len);
+ break;
+ }
}
// get tag
- err = alcp_cipher_get_tag(&handle, tag, tagLen);
+ err = alcp_cipher_aead_get_tag(&handle, tag, tagLen);
if (alcp_is_error(err)) {
printf("Error: unable getting tag \n");
alcp_error_str(err, err_buf, err_size);
@@ -250,7 +258,7 @@ aclp_aes_gcm_decrypt_demo(const Uint8* ciphertxt,
Uint8 tagDecrypt[16];
// GCM init
- err = alcp_cipher_set_iv(&handle, ivLen, iv);
+ err = alcp_cipher_aead_set_iv(&handle, ivLen, iv);
if (alcp_is_error(err)) {
printf("Error: unable gcm encrypt init \n");
alcp_error_str(err, err_buf, err_size);
@@ -258,42 +266,51 @@ aclp_aes_gcm_decrypt_demo(const Uint8* ciphertxt,
}
// Additional Data
- err = alcp_cipher_set_aad(&handle, ad, adLen);
+ err = alcp_cipher_aead_set_aad(&handle, ad, adLen);
if (alcp_is_error(err)) {
printf("Error: unable gcm add data processing \n");
alcp_error_str(err, err_buf, err_size);
return;
}
- // GCM decrypt
- err = alcp_cipher_decrypt_update(&handle, ciphertxt, plaintxt, len, iv);
- if (alcp_is_error(err)) {
- printf("Error: unable decrypt \n");
- alcp_error_str(err, err_buf, err_size);
- return;
+ totalTimeElapsed = 0.0;
+ for (int k = 0; k < 100000000; k++) {
+ ALCP_CRYPT_TIMER_START
+
+ // GCM decrypt
+ err = alcp_cipher_aead_decrypt_update(
+ &handle, ciphertxt, plaintxt, len, iv);
+ if (alcp_is_error(err)) {
+ printf("Error: unable decrypt \n");
+ alcp_error_str(err, err_buf, err_size);
+ return;
+ }
+
+ alcp_get_time(0, "Decrypt time");
+
+ // plaintxt += len;
+ // ciphertxt += len;
+
+ if (totalTimeElapsed > .5) {
+ printf(
+ "\t : %6.3lf GB Decrypted per second with block size "
+ "(%5d bytes) ",
+ (double)(((k / 1000.0) * len) / (totalTimeElapsed * 1000000.0)),
+ len);
+ break;
+ }
}
// get tag
- err = alcp_cipher_get_tag(&handle, tagDecrypt, tagLen);
+ err = alcp_cipher_aead_get_tag(&handle, tagDecrypt, tagLen);
if (alcp_is_error(err)) {
printf("Error: unable getting tag \n");
alcp_error_str(err, err_buf, err_size);
return;
}
- bool isTagMatched = true;
-
- for (int i = 0; i < tagLen; i++) {
- if (tagDecrypt[i] != tag[i]) {
- isTagMatched = isTagMatched & false;
- }
- }
-
- if (isTagMatched == false) {
- // printf("\n tag mismatched, input encrypted data is not trusthworthy
- // ");
- memset(plaintxt, 0, len);
- }
+ // encrypt and decrypt tag will not match, since inputText, cipherText and
+ // outputText are overwritten multiple times. So we avoid tag matching part.
}
/*
@@ -357,55 +374,14 @@ encrypt_decrypt_demo(Uint8* inputText, // plaintext
create_aes_session(key, iv, keybits, m);
- totalTimeElapsed = 0.0;
- for (int k = 0; k < 100000000; k++) {
- ALCP_CRYPT_TIMER_START
-
- aclp_aes_gcm_encrypt_demo(
- inputText, inputLen, cipherText, iv, ivLen, ad, adLen, tag, tagLen);
-
- alcp_get_time(0, "Encrypt time");
-
- if (totalTimeElapsed > .5) {
- printf("\t : %6.3lf GB Encrypted per second with block size "
- "(%5d bytes) ",
- (double)(((k / 1000.0) * inputLen)
- / (totalTimeElapsed * 1000000.0)),
- inputLen);
- break;
- }
- }
-
- // Decrypt section
- totalTimeElapsed = 0.0;
- for (int k = 0; k < 100000000; k++) {
- ALCP_CRYPT_TIMER_START
-
- aclp_aes_gcm_decrypt_demo(cipherText,
- inputLen,
- outputText,
- iv,
- ivLen,
- ad,
- adLen,
- tag,
- tagLen);
+ // same inputText, cipherText and outputText buffer is used multiple times
+ // to measure speed, so inputText and outputText after decrypt will not
+ // match.
+ aclp_aes_gcm_encrypt_demo(
+ inputText, inputLen, cipherText, iv, ivLen, ad, adLen, tag, tagLen);
- alcp_get_time(0, "Decrypt time");
-
- if (totalTimeElapsed > .5) {
- printf("\t : %6.3lf GB Decrypted per second with block size "
- "(%5d bytes) ",
- (double)(((k / 1000.0) * inputLen)
- / (totalTimeElapsed * 1000000.0)),
- inputLen);
- break;
- }
- }
-
- if (memcmp(inputText, outputText, (long unsigned int)inputLen) != 0) {
- printf("\n\t\t\t\t input->enc->dec->input FAILED \n");
- }
+ aclp_aes_gcm_decrypt_demo(
+ cipherText, inputLen, outputText, iv, ivLen, ad, adLen, tag, tagLen);
/*
* Complete the transaction
diff --git a/examples/cipher/aes-xts.c b/examples/cipher/aes-xts.c
index 9d4fc3002..c3f6d84fc 100644
--- a/examples/cipher/aes-xts.c
+++ b/examples/cipher/aes-xts.c
@@ -50,31 +50,18 @@
static alc_cipher_handle_t handle;
void
-create_demo_session(const Uint8* key,
- const Uint8* tweak_key,
- const Uint8* iv,
- const Uint32 key_len)
+create_demo_session(const Uint8* key, const Uint8* iv, const Uint32 key_len)
{
alc_error_t err;
const int err_size = 256;
Uint8 err_buf[err_size];
- alc_key_info_t kinfo = {
- .type = ALC_KEY_TYPE_SYMMETRIC,
- .fmt = ALC_KEY_FMT_RAW,
- .key = tweak_key,
- .len = key_len,
- };
-
alc_cipher_info_t cinfo = {
.ci_type = ALC_CIPHER_TYPE_AES,
.ci_algo_info = {
.ai_mode = ALC_AES_MODE_XTS,
.ai_iv = iv,
- .ai_xts = {
- .xi_tweak_key = &kinfo,
- }
},
/* No padding, Not Implemented yet*/
//.pad = ALC_CIPHER_PADDING_NONE,
@@ -165,15 +152,15 @@ static Uint8* sample_plaintxt = (Uint8*)"A paragraph is a series of sentences "
"that is longer than a few sentences "
"should be organized into paragraphs.";
+// clang-format off
static const Uint8 sample_key[] = {
0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf,
-};
-
-static const Uint8 sample_tweak_key[] = {
- 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
+ // Tweak Key
+ 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xf, 0xf,
};
+// clang-format on
static const Uint8 sample_iv[] = {
0xf, 0x0, 0xe, 0x1, 0xd, 0x2, 0xc, 0x3,
@@ -247,8 +234,8 @@ main(void)
int pt_size = strlen((const char*)sample_plaintxt);
assert(sizeof(sample_plaintxt) < sizeof(sample_output));
- create_demo_session(
- sample_key, sample_tweak_key, sample_iv, sizeof(sample_key) * 8);
+ // Tweak Key is appended to Sample Key
+ create_demo_session(sample_key, sample_iv, (sizeof(sample_key) / 2) * 8);
#ifdef DEBUG
printf("plain text with size %d: \n", pt_size);
diff --git a/examples/cipher/chacha20.c b/examples/cipher/chacha20.c
new file mode 100644
index 000000000..311921a3f
--- /dev/null
+++ b/examples/cipher/chacha20.c
@@ -0,0 +1,241 @@
+/*
+ * Copyright (C) 2023, Advanced Micro Devices. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include
+#include /* for malloc */
+#include
+
+#include
+
+static inline void
+dump_hex(Uint8* value, size_t size)
+{
+ printf("{ ");
+ for (int i = 0; i < size; i++) {
+ printf("0x%02x", *value);
+ value++;
+ if (i != (size - 1)) {
+ printf(", ");
+ } else {
+ printf(" }");
+ }
+ }
+ printf("\n");
+}
+
+int
+create_demo_session(alc_cipher_handle_p handle,
+ const Uint8* key,
+ const Uint8* iv,
+ Uint64 ivlength,
+ const alc_key_len_t cKeyLen)
+{
+ alc_error_t err;
+ const int cErrSize = 256;
+ Uint8 err_buf[cErrSize];
+
+ alc_cipher_info_t cinfo = {
+ .ci_type = ALC_CIPHER_TYPE_CHACHA20, // Using Chacha20 Stream Cipher
+ .ci_key_info =
+ {
+ .type = ALC_KEY_TYPE_SYMMETRIC,
+ .fmt = ALC_KEY_FMT_RAW,
+ .key = key,
+ .len = cKeyLen,
+ },
+ .ci_algo_info = {
+ .ai_iv = iv, // For Chacha20, IV has to be a combination of counter 32
+ // bits in little endian) followed by nonce(96 bits).
+ // Counter will get incremented internally for each 64
+ // bytes of input message
+ .iv_length = ivlength // For Chacha20, IV length must be 128 bits
+ }};
+
+ /*
+ * Check if the current cipher is supported,
+ * optional call, alcp_cipher_request() will anyway return
+ * ALC_ERROR_NOT_SUPPORTED error.
+ *
+ * This query call is provided to support fallback mode for applications
+ */
+ err = alcp_cipher_supported(&cinfo);
+ if (alcp_is_error(err)) {
+ printf("Error: Not Supported \n");
+ goto out;
+ }
+ printf("Support succeeded\n");
+
+ /*
+ * Application is expected to allocate for context
+ */
+ handle->ch_context = malloc(alcp_cipher_context_size(&cinfo));
+
+ // Memory allocation failure checking
+ if (handle->ch_context == NULL) {
+ printf("Error: Memory Allocation Failed!\n");
+ goto out;
+ }
+
+ /* Request a context with cinfo */
+ err = alcp_cipher_request(&cinfo, handle);
+ if (alcp_is_error(err)) {
+ printf("Error: Unable to Request \n");
+ goto out;
+ }
+ printf("Request Succeeded\n");
+ return 0;
+
+// Incase of error, program execution will come here
+out:
+ alcp_error_str(err, err_buf, cErrSize);
+ printf("%s\n", err_buf);
+ return -1;
+}
+
+int
+encrypt_demo(alc_cipher_handle_p handle,
+ const Uint8* iv,
+ const Uint8* plaintxt,
+ const Uint32 len, /* for both 'plaintxt' and 'ciphertxt' */
+ Uint8* ciphertxt)
+{
+ alc_error_t err;
+ const int err_size = 256;
+ Uint8 err_buf[err_size];
+
+ err = alcp_cipher_encrypt(handle, plaintxt, ciphertxt, len, iv);
+ if (alcp_is_error(err)) {
+ printf("Error: Unable to Encrypt \n");
+ alcp_error_str(err, err_buf, err_size);
+ printf("%s\n", err_buf);
+ return -1;
+ }
+
+ printf("Encrypt succeeded\n");
+ return 0;
+}
+
+int
+decrypt_demo(alc_cipher_handle_p handle,
+ const Uint8* iv,
+ const Uint8* ciphertxt,
+ const Uint32 len, /* for both 'plaintxt' and 'ciphertxt' */
+ Uint8* plaintxt)
+{
+ alc_error_t err;
+ const int err_size = 256;
+ Uint8 err_buf[err_size];
+
+ err = alcp_cipher_decrypt(handle, ciphertxt, plaintxt, len, iv);
+ if (alcp_is_error(err)) {
+ printf("Error: Unable to Decrypt \n");
+ alcp_error_str(err, err_buf, err_size);
+ printf("%s\n", err_buf);
+ return -1;
+ }
+
+ printf("Decrypt Succeeded\n");
+ return 0;
+}
+
+// Plain text to encrypt, it can be any size since Chacha20 is a stream cipher.
+static Uint8 sample_plaintxt[] =
+ "Happy and Fantastic New Year from AOCL Crypto !!";
+
+// Chacha20 Key needs to be 256 bits
+static const Uint8 sample_key[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
+ 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d,
+ 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14,
+ 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b,
+ 0x1c, 0x1d, 0x1e, 0x1f };
+
+// IV must be 128 bits and should be a combination of Counter (32 bits) and
+// Nonce (96 bits). Counter Should be in Little Endian order. For example, in
+// the below IV, counter=0x00000001,nonce=0x0000004a0000000000000000
+static const Uint8 iv[16] = {
+ 1, 0, 0, 0, 0, 0, 0, 0x4a, 0, 0, 0, 0, 0, 0, 0, 0
+};
+
+// Buffer to write encrypted message into
+// It should have size greater than or equal to plaintext as there is no padding
+static Uint8 sample_ciphertxt[sizeof(sample_plaintxt)];
+int
+main(void)
+{
+ int retval = 0;
+ // Buffer to write plain text into.
+ // It should have size greater than or equal to the plaintext.
+ Uint8 sample_output[512] = { 0 };
+ const int cPlaintextSize = strlen((const char*)sample_plaintxt);
+ const int cCiphertextSize = cPlaintextSize; // No padding
+ const Uint64 ivlen = sizeof(iv) * 8;
+ const Uint64 keylen = sizeof(sample_key) * 8;
+
+ printf("Input Text: %s\n", sample_plaintxt);
+
+ // Create the handle, this handle will be used for encrypt and decrypt
+ // operations
+ alc_cipher_handle_t handle;
+ retval = create_demo_session(&handle, sample_key, iv, ivlen, keylen);
+ if (retval != 0)
+ goto out;
+
+ // Encrypt the plaintext into the ciphertext
+ retval =
+ encrypt_demo(&handle,
+ iv,
+ sample_plaintxt,
+ cPlaintextSize, /* len of 'plaintxt' and 'ciphertxt' */
+ sample_ciphertxt);
+ if (retval != 0)
+ goto out;
+ printf("CipherText:");
+ dump_hex(sample_ciphertxt, cCiphertextSize);
+
+ // Decrypt the ciphertext into the plaintext.
+ retval = decrypt_demo(
+ &handle, iv, sample_ciphertxt, cCiphertextSize, sample_output);
+ if (retval != 0)
+ goto out;
+ printf("Decrypted Text: %s\n", sample_output);
+
+ /*
+ * Complete the transaction
+ */
+ alcp_cipher_finish(&handle);
+
+ // Free the memory allocated by create_demo_session.
+ free(handle.ch_context);
+
+ return 0;
+out:
+ return -1;
+}
+
+/* LocalWords: decrypt Crypto AOCL
+ */
diff --git a/examples/digest/sha2_224_example.c b/examples/digest/sha2_224_example.c
index b2c62b26f..37242a383 100644
--- a/examples/digest/sha2_224_example.c
+++ b/examples/digest/sha2_224_example.c
@@ -166,13 +166,16 @@ main(void)
num_chunks = STRING_VECTORS[i].num_chunks;
alc_error_t err = create_demo_session();
-
- if (!alcp_is_error(err)) {
- err = hash_demo(sample_input,
+ if (alcp_is_error(err)) {
+ return -1;
+ }
+ err = hash_demo(sample_input,
strlen((const char*)sample_input),
sample_output,
sizeof(sample_output),
num_chunks);
+ if (alcp_is_error(err)) {
+ return -1;
}
// check if the outputs are matching
@@ -183,6 +186,7 @@ main(void)
if (strcmp(expected_output, output_string)) {
printf("=== FAILED ==== \n");
printf("Expected output : %s\n", expected_output);
+ return -1;
} else {
printf("=== Passed ===\n");
}
diff --git a/examples/digest/sha2_256_example.c b/examples/digest/sha2_256_example.c
index b0005efe0..a490bdc56 100644
--- a/examples/digest/sha2_256_example.c
+++ b/examples/digest/sha2_256_example.c
@@ -170,13 +170,16 @@ main(void)
num_chunks = STRING_VECTORS[i].num_chunks;
alc_error_t err = create_demo_session();
-
- if (!alcp_is_error(err)) {
- err = hash_demo(sample_input,
+ if (alcp_is_error(err)) {
+ return -1;
+ }
+ err = hash_demo(sample_input,
strlen((const char*)sample_input),
sample_output,
sizeof(sample_output),
num_chunks);
+ if (alcp_is_error(err)) {
+ return -1;
}
// check if the outputs are matching
@@ -187,6 +190,7 @@ main(void)
if (strcmp(expected_output, output_string)) {
printf("=== FAILED ==== \n");
printf("Expected output : %s\n", expected_output);
+ return -1;
} else {
printf("=== Passed ===\n");
}
diff --git a/examples/digest/sha2_384_example.c b/examples/digest/sha2_384_example.c
index a62b3e76a..f64b5c9aa 100644
--- a/examples/digest/sha2_384_example.c
+++ b/examples/digest/sha2_384_example.c
@@ -194,13 +194,16 @@ main(void)
num_chunks = STRING_VECTORS[i].num_chunks;
alc_error_t err = create_demo_session();
-
- if (!alcp_is_error(err)) {
- err = hash_demo(sample_input,
+ if (alcp_is_error(err)) {
+ return -1;
+ }
+ err = hash_demo(sample_input,
strlen((const char*)sample_input),
sample_output,
sizeof(sample_output),
num_chunks);
+ if (alcp_is_error(err)) {
+ return -1;
}
// check if the outputs are matching
@@ -211,6 +214,7 @@ main(void)
if (strcmp(expected_output, output_string)) {
printf("=== FAILED ==== \n");
printf("Expected output : %s\n", expected_output);
+ return -1;
} else {
printf("=== Passed ===\n");
}
diff --git a/examples/digest/sha2_512_example.c b/examples/digest/sha2_512_example.c
index ce885450a..8c6f767b2 100644
--- a/examples/digest/sha2_512_example.c
+++ b/examples/digest/sha2_512_example.c
@@ -219,13 +219,16 @@ main(void)
num_chunks = STRING_VECTORS[i].num_chunks;
alc_error_t err = create_demo_session();
-
- if (!alcp_is_error(err)) {
- err = hash_demo(sample_input,
+ if (alcp_is_error(err)) {
+ return -1;
+ }
+ err = hash_demo(sample_input,
strlen((const char*)sample_input),
sample_output,
sizeof(sample_output),
num_chunks);
+ if (alcp_is_error(err)) {
+ return -1;
}
// check if the outputs are matching
@@ -236,6 +239,7 @@ main(void)
if (strcmp(expected_output, output_string)) {
printf("=== FAILED ==== \n");
printf("Expected output : %s\n", expected_output);
+ return -1;
} else {
printf("=== Passed ===\n");
}
diff --git a/examples/digest/sha3_224_example.c b/examples/digest/sha3_224_example.c
index b5d533b73..a7c2f035f 100644
--- a/examples/digest/sha3_224_example.c
+++ b/examples/digest/sha3_224_example.c
@@ -90,6 +90,7 @@ hash_demo(const Uint8* src,
err = alcp_digest_copy(&s_dg_handle, output, out_size);
if (alcp_is_error(err)) {
printf("Unable to copy digest\n");
+ goto out;
}
out:
@@ -238,13 +239,17 @@ main(void)
num_chunks = STRING_VECTORS[i].num_chunks;
alc_error_t err = create_demo_session();
+ if (alcp_is_error(err)) {
+ return -1;
+ }
- if (!alcp_is_error(err)) {
- err = hash_demo(sample_input,
+ err = hash_demo(sample_input,
strlen((const char*)sample_input),
sample_output,
sizeof(sample_output),
num_chunks);
+ if (alcp_is_error(err)) {
+ return -1;
}
// check if the outputs are matching
@@ -255,6 +260,7 @@ main(void)
if (strcmp(expected_output, output_string)) {
printf("=== FAILED ==== \n");
printf("Expected output : %s\n", expected_output);
+ return -1;
} else {
printf("=== Passed ===\n");
}
diff --git a/examples/digest/sha3_256_example.c b/examples/digest/sha3_256_example.c
index 22be88c5a..a26e77b7f 100644
--- a/examples/digest/sha3_256_example.c
+++ b/examples/digest/sha3_256_example.c
@@ -234,13 +234,16 @@ main(void)
num_chunks = STRING_VECTORS[i].num_chunks;
alc_error_t err = create_demo_session();
-
- if (!alcp_is_error(err)) {
- err = hash_demo(sample_input,
+ if (alcp_is_error(err)) {
+ return -1;
+ }
+ err = hash_demo(sample_input,
strlen((const char*)sample_input),
sample_output,
sizeof(sample_output),
num_chunks);
+ if (alcp_is_error(err)) {
+ return -1;
}
// check if the outputs are matching
@@ -251,6 +254,7 @@ main(void)
if (strcmp(expected_output, output_string)) {
printf("=== FAILED ==== \n");
printf("Expected output : %s\n", expected_output);
+ return -1;
} else {
printf("=== Passed ===\n");
}
diff --git a/examples/digest/sha3_384_example.c b/examples/digest/sha3_384_example.c
index 77c66e183..bb62fd217 100644
--- a/examples/digest/sha3_384_example.c
+++ b/examples/digest/sha3_384_example.c
@@ -256,13 +256,16 @@ main(void)
num_chunks = STRING_VECTORS[i].num_chunks;
alc_error_t err = create_demo_session();
-
- if (!alcp_is_error(err)) {
- err = hash_demo(sample_input,
+ if (alcp_is_error(err)) {
+ return -1;
+ }
+ err = hash_demo(sample_input,
strlen((const char*)sample_input),
sample_output,
sizeof(sample_output),
num_chunks);
+ if (alcp_is_error(err)) {
+ return -1;
}
// check if the outputs are matching
@@ -273,6 +276,7 @@ main(void)
if (strcmp(expected_output, output_string)) {
printf("=== FAILED ==== \n");
printf("Expected output : %s\n", expected_output);
+ return -1;
} else {
printf("=== Passed ===\n");
}
diff --git a/examples/digest/sha3_512_example.c b/examples/digest/sha3_512_example.c
index 440984758..fce7314a7 100644
--- a/examples/digest/sha3_512_example.c
+++ b/examples/digest/sha3_512_example.c
@@ -252,13 +252,16 @@ main(void)
num_chunks = STRING_VECTORS[i].num_chunks;
alc_error_t err = create_demo_session();
-
- if (!alcp_is_error(err)) {
- err = hash_demo(sample_input,
+ if (alcp_is_error(err)) {
+ return -1;
+ }
+ err = hash_demo(sample_input,
strlen((const char*)sample_input),
sample_output,
sizeof(sample_output),
num_chunks);
+ if (alcp_is_error(err)) {
+ return -1;
}
// check if the outputs are matching
@@ -269,6 +272,7 @@ main(void)
if (strcmp(expected_output, output_string)) {
printf("=== FAILED ==== \n");
printf("Expected output : %s\n", expected_output);
+ return -1;
} else {
printf("=== Passed ===\n");
}
diff --git a/examples/digest/shake_128_example.c b/examples/digest/shake_128_example.c
index cc5805a2b..462666efc 100644
--- a/examples/digest/shake_128_example.c
+++ b/examples/digest/shake_128_example.c
@@ -284,13 +284,16 @@ main(void)
output_string = malloc(hash_size * 2 + 1);
alc_error_t err = create_demo_session(hash_size);
-
- if (!alcp_is_error(err)) {
- err = hash_demo(sample_input,
+ if (alcp_is_error(err)) {
+ return -1;
+ }
+ err = hash_demo(sample_input,
strlen((const char*)sample_input),
sample_output,
hash_size,
num_chunks);
+ if (alcp_is_error(err)) {
+ return -1;
}
// check if the outputs are matching
@@ -302,6 +305,7 @@ main(void)
if (strcmp(expected_output, output_string)) {
printf("=== FAILED ==== \n");
printf("Expected output : %s\n", expected_output);
+ return -1;
} else {
printf("=== Passed ===\n");
}
diff --git a/examples/digest/shake_256_example.c b/examples/digest/shake_256_example.c
index 84ff8b316..62f625946 100644
--- a/examples/digest/shake_256_example.c
+++ b/examples/digest/shake_256_example.c
@@ -280,13 +280,16 @@ main(void)
sample_output = malloc(hash_size);
output_string = malloc(hash_size * 2 + 1);
alc_error_t err = create_demo_session(hash_size);
-
- if (!alcp_is_error(err)) {
- err = hash_demo(sample_input,
+ if (alcp_is_error(err)) {
+ return -1;
+ }
+ err = hash_demo(sample_input,
strlen((const char*)sample_input),
sample_output,
hash_size,
num_chunks);
+ if (alcp_is_error(err)) {
+ return -1;
}
// check if the outputs are matching
@@ -298,6 +301,7 @@ main(void)
if (strcmp(expected_output, output_string)) {
printf("=== FAILED ==== \n");
printf("Expected output : %s\n", expected_output);
+ return -1;
} else {
printf("=== Passed ===\n");
}
diff --git a/examples/ecdh/CMakeLists.txt b/examples/ecdh/CMakeLists.txt
index 50d586c1a..0fc6e0d06 100644
--- a/examples/ecdh/CMakeLists.txt
+++ b/examples/ecdh/CMakeLists.txt
@@ -23,4 +23,5 @@
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
- ADD_EXAMPLE(x25519_example x25519_example.c)
\ No newline at end of file
+ ADD_EXAMPLE(x25519_example x25519_example.c)
+ ADD_EXAMPLE(p256_example p256_example.c)
\ No newline at end of file
diff --git a/examples/ecdh/p256_example.c b/examples/ecdh/p256_example.c
new file mode 100644
index 000000000..017a32098
--- /dev/null
+++ b/examples/ecdh/p256_example.c
@@ -0,0 +1,129 @@
+/*
+ * Copyright (C) 2023, Advanced Micro Devices. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "alcp/ec.h"
+#include "alcp/ecdh.h"
+
+#define POINT_SIZE 32
+#define PVT_KEY_SIZE POINT_SIZE
+#define PUB_KEY_SIZE POINT_SIZE * 2
+#define SCRT_KEY_SIZE POINT_SIZE
+
+static const Uint8 cPeer1PrivkData[PVT_KEY_SIZE] = {
+ 0x7d, 0x7d, 0xc5, 0xf7, 0x1e, 0xb2, 0x9d, 0xda, 0xf8, 0x0d, 0x62,
+ 0x14, 0x63, 0x2e, 0xea, 0xe0, 0x3d, 0x90, 0x58, 0xaf, 0x1f, 0xb6,
+ 0xd2, 0x2e, 0xd8, 0x0b, 0xad, 0xb6, 0x2b, 0xc1, 0xa5, 0x34
+};
+
+static const Uint8 cPeer2PublicData[PUB_KEY_SIZE] = {
+ 0x70, 0x0c, 0x48, 0xf7, 0x7f, 0x56, 0x58, 0x4c, // X
+ 0x5c, 0xc6, 0x32, 0xca, 0x65, 0x64, 0x0d, 0xb9, 0x1b, 0x6b, 0xac, 0xce,
+ 0x3a, 0x4d, 0xf6, 0xb4, 0x2c, 0xe7, 0xcc, 0x83, 0x88, 0x33, 0xd2, 0x87,
+ 0xdb, 0x71, 0xe5, 0x09, 0xe3, 0xfd, 0x9b, 0x06, // Y
+ 0x0d, 0xdb, 0x20, 0xba, 0x5c, 0x51, 0xdc, 0xc5, 0x94, 0x8d, 0x46, 0xfb,
+ 0xf6, 0x40, 0xdf, 0xe0, 0x44, 0x17, 0x82, 0xca, 0xb8, 0x5f, 0xa4, 0xac
+};
+
+static const Uint8 cExpectedSecretKey[SCRT_KEY_SIZE] = {
+ 0x46, 0xfc, 0x62, 0x10, 0x64, 0x20, 0xff, 0x01, 0x2e, 0x54, 0xa4,
+ 0x34, 0xfb, 0xdd, 0x2d, 0x25, 0xcc, 0xc5, 0x85, 0x20, 0x60, 0x56,
+ 0x1e, 0x68, 0x04, 0x0d, 0xd7, 0x77, 0x89, 0x97, 0xbd, 0x7b
+};
+
+static alc_error_t
+create_demo_session(alc_ec_handle_t* s_ec_handle)
+{
+ alc_error_t err;
+
+ alc_ec_info_t ecinfo = {
+ .ecCurveId = ALCP_EC_SECP256R1,
+ .ecCurveType = ALCP_EC_CURVE_TYPE_SHORT_WEIERSTRASS,
+ .ecPointFormat = ALCP_EC_POINT_FORMAT_UNCOMPRESSED,
+ };
+
+ Uint64 size = alcp_ec_context_size(&ecinfo);
+ s_ec_handle->context = malloc(size);
+
+ err = alcp_ec_request(&ecinfo, s_ec_handle);
+
+ return err;
+}
+
+static alc_error_t
+p256_demo(alc_ec_handle_t* ps_ec_handle_peer)
+{
+ alc_error_t err;
+ Uint8 p_secret_key1[SCRT_KEY_SIZE];
+ Uint64 key_length;
+
+ // Set the private key
+ printf("Setting Private Key for Peer 1\n");
+ err = alcp_ec_set_privatekey(ps_ec_handle_peer, cPeer1PrivkData);
+ if (err != ALC_ERROR_NONE) {
+ printf("\n peer1 private key set failed");
+ return err;
+ }
+
+ // Compute the secret key
+ printf("Setting Public Key for Peer 2 and generating secret key\n");
+ err = alcp_ec_get_secretkey(
+ ps_ec_handle_peer, p_secret_key1, cPeer2PublicData, &key_length);
+ if (err != ALC_ERROR_NONE) {
+ printf("\n peer1 secretkey computation failed");
+ return err;
+ }
+
+ // Verify the secret key is expected one
+ if (memcmp(p_secret_key1, cExpectedSecretKey, key_length) == 0) {
+ err = ALC_ERROR_NONE;
+ printf("Success: Secret Key matches!\n");
+ } else {
+ printf("Failure: Secret Key mismatch!\n");
+ }
+ return err;
+}
+
+int
+main(void)
+{
+ alc_ec_handle_t s_ec_handle_peer1;
+ alc_error_t err = create_demo_session(&s_ec_handle_peer1);
+ err = p256_demo(&s_ec_handle_peer1);
+ if (alcp_is_error(err))
+ return -1;
+ alcp_ec_finish(&s_ec_handle_peer1);
+ free(s_ec_handle_peer1.context);
+
+ return 0;
+}
diff --git a/examples/ecdh/x25519_example.c b/examples/ecdh/x25519_example.c
index 40668a35a..0bd21a51a 100644
--- a/examples/ecdh/x25519_example.c
+++ b/examples/ecdh/x25519_example.c
@@ -84,6 +84,12 @@ x25519_demo(alc_ec_handle_t* ps_ec_handle_peer1,
/* Peer 1 */
Uint8 publicKeyData1[SIZE_KEY_X25519];
+ err = alcp_ec_set_privatekey(ps_ec_handle_peer1, peer1_privk_data);
+ if (err != ALC_ERROR_NONE) {
+ printf("\n peer1 private key set failed");
+ return err;
+ }
+
err = alcp_ec_get_publickey(
ps_ec_handle_peer1, publicKeyData1, peer1_privk_data);
if (err != ALC_ERROR_NONE) {
@@ -95,6 +101,13 @@ x25519_demo(alc_ec_handle_t* ps_ec_handle_peer1,
/* Peer 2 */
Uint8 publicKeyData2[SIZE_KEY_X25519];
+
+ err = alcp_ec_set_privatekey(ps_ec_handle_peer2, peer2_privk_data);
+ if (err != ALC_ERROR_NONE) {
+ printf("\n peer2 private key set failed");
+ return err;
+ }
+
err = alcp_ec_get_publickey(
ps_ec_handle_peer2, publicKeyData2, peer2_privk_data);
if (err != ALC_ERROR_NONE) {
@@ -141,14 +154,17 @@ main(void)
{
alc_ec_handle_t s_ec_handle_peer1;
alc_error_t err = create_demo_session(&s_ec_handle_peer1);
+ if (alcp_is_error(err))
+ return -1;
alc_ec_handle_t s_ec_handle_peer2;
err = create_demo_session(&s_ec_handle_peer2);
+ if (alcp_is_error(err))
+ return -1;
- if (!alcp_is_error(err)) {
- err = x25519_demo(&s_ec_handle_peer1, &s_ec_handle_peer2);
- }
-
+ err = x25519_demo(&s_ec_handle_peer1, &s_ec_handle_peer2);
+ if (alcp_is_error(err))
+ return -1;
alcp_ec_finish(&s_ec_handle_peer1);
free(s_ec_handle_peer1.context);
diff --git a/examples/mac/CMakeLists.txt b/examples/mac/CMakeLists.txt
index cb5ed9f78..3844cecf2 100644
--- a/examples/mac/CMakeLists.txt
+++ b/examples/mac/CMakeLists.txt
@@ -30,3 +30,4 @@
ADD_EXAMPLE(hmac hmac.c)
ADD_EXAMPLE(cmac cmac.c)
+ADD_EXAMPLE(poly1305 poly1305.c)
diff --git a/examples/mac/cmac.c b/examples/mac/cmac.c
index 0bd7678f3..49ce92a93 100644
--- a/examples/mac/cmac.c
+++ b/examples/mac/cmac.c
@@ -133,10 +133,9 @@ displayResults(char* hmac_string,
printf("\n");
}
-void
+int
demo_cmac()
{
-
alc_error_t err;
Uint8 key[] = { 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6,
@@ -170,6 +169,7 @@ demo_cmac()
err = run_cmac(&macinfo, cipherText, sizeof(cipherText), mac, mac_size);
if (err != ALC_ERROR_NONE) {
printf("Error in CMAC\n");
+ return -1;
} else {
displayResults("CMAC",
@@ -182,12 +182,16 @@ demo_cmac()
expectedMac,
sizeof(expectedMac));
}
+ return 0;
}
int
main(int argc, char const* argv[])
{
- demo_cmac();
+ if (demo_cmac() != 0)
+ goto out;
return 0;
+out:
+ return -1;
}
diff --git a/examples/mac/hmac.c b/examples/mac/hmac.c
index 9be0ba5e3..b0bd1c05a 100644
--- a/examples/mac/hmac.c
+++ b/examples/mac/hmac.c
@@ -64,7 +64,7 @@ run_hmac(const alc_mac_info_p macInfo,
{
alc_error_t err = ALC_ERROR_NONE;
- err = alcp_mac_supported(macInfo);
+ err = alcp_mac_supported(macInfo);
if (err == ALC_ERROR_NONE) {
handle.ch_context = malloc(alcp_mac_context_size(macInfo));
} else {
@@ -120,7 +120,7 @@ displayResults(char* hmac_string,
printf(" : ");
printf("\n\t");
printf("KEY = \t\t");
- printHashAsHexString(key, keylen);
+ printHashAsHexString(key, keylen / 8);
printf("\n\t");
printf("CipherText = \t");
printHashAsHexString(cipherText, cipherTextLen);
@@ -141,7 +141,7 @@ displayResults(char* hmac_string,
printf("\n");
}
-void
+int
demo_Hmac_Sha256()
{
@@ -188,7 +188,7 @@ demo_Hmac_Sha256()
err = run_hmac(&macinfo, cipherText, sizeof(cipherText), mac, mac_size);
if (err != ALC_ERROR_NONE) {
printf("Error Occurred in HMAC SHA2-256\n");
-
+ return -1;
} else {
displayResults("HMAC SHA2-256",
@@ -201,9 +201,10 @@ demo_Hmac_Sha256()
expectedMac,
sizeof(expectedMac));
}
+ return 0;
}
-void
+int
demo_Hmac_Sha224()
{
@@ -259,6 +260,7 @@ demo_Hmac_Sha224()
err = run_hmac(&macinfo, cipherText, sizeof(cipherText), mac, mac_size);
if (err != ALC_ERROR_NONE) {
printf("Error Occurred in HMAC SHA2-224\n");
+ return -1;
} else {
@@ -272,9 +274,10 @@ demo_Hmac_Sha224()
expectedMac,
sizeof(expectedMac));
}
+ return 0;
}
-void
+int
demo_Hmac_Sha512()
{
alc_error_t err;
@@ -337,6 +340,7 @@ demo_Hmac_Sha512()
err = run_hmac(&macinfo, cipherText, sizeof(cipherText), mac, mac_size);
if (err != ALC_ERROR_NONE) {
printf("Error Occurred in HMAC SHA2-512\n");
+ return -1;
} else {
@@ -350,8 +354,9 @@ demo_Hmac_Sha512()
expectedMac,
sizeof(expectedMac));
}
+ return 0;
}
-void
+int
demo_Hmac_Sha3_224()
{
alc_error_t err;
@@ -393,7 +398,7 @@ demo_Hmac_Sha3_224()
err = run_hmac(&macinfo, cipherText, sizeof(cipherText), mac, mac_size);
if (err != ALC_ERROR_NONE) {
printf("Error Occurred in HMAC SHA3-224\n");
-
+ return -1;
} else {
displayResults("HMAC SHA3-224",
@@ -406,9 +411,10 @@ demo_Hmac_Sha3_224()
expectedMac,
sizeof(expectedMac));
}
+ return 0;
}
-void
+int
demo_Hmac_Sha3_256()
{
Uint8 key[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
@@ -452,7 +458,7 @@ demo_Hmac_Sha3_256()
run_hmac(&macinfo, cipherText, sizeof(cipherText), mac, mac_size);
if (err != ALC_ERROR_NONE) {
printf("Error Occurred in HMAC SHA3-256\n");
-
+ return -1;
} else {
displayResults("HMAC SHA3-256",
@@ -465,8 +471,9 @@ demo_Hmac_Sha3_256()
expectedMac,
sizeof(expectedMac));
}
+ return 0;
}
-void
+int
demo_Hmac_Sha3_512()
{
Uint8 key[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
@@ -517,7 +524,7 @@ demo_Hmac_Sha3_512()
run_hmac(&macinfo, cipherText, sizeof(cipherText), mac, mac_size);
if (err != ALC_ERROR_NONE) {
printf("Error Occurred in HMAC SHA3-512\n");
-
+ return -1;
} else {
displayResults("HMAC SHA3-512",
@@ -530,9 +537,10 @@ demo_Hmac_Sha3_512()
expectedMac,
sizeof(expectedMac));
}
+ return 0;
}
-void
+int
demo_Hmac_Sha384()
{
Uint8 key[] = { 0x5e, 0xab, 0x0d, 0xfa, 0x27, 0x31, 0x12, 0x60, 0xd7, 0xbd,
@@ -590,7 +598,7 @@ demo_Hmac_Sha384()
run_hmac(&macinfo, cipherText, sizeof(cipherText), mac, mac_size);
if (err != ALC_ERROR_NONE) {
printf("Error Occurred in HMAC SHA2-384\n");
-
+ return -1;
} else {
displayResults("HMAC SHA2-384",
@@ -603,9 +611,10 @@ demo_Hmac_Sha384()
expectedMac,
sizeof(expectedMac));
}
+ return 0;
}
-void
+int
demo_Hmac_Sha3_384()
{
Uint8 key[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
@@ -652,7 +661,7 @@ demo_Hmac_Sha3_384()
run_hmac(&macinfo, cipherText, sizeof(cipherText), mac, mac_size);
if (err != ALC_ERROR_NONE) {
printf("Error Occurred in HMAC SHA3-384\n");
-
+ return -1;
} else {
displayResults("HMAC SHA3-384",
@@ -665,9 +674,10 @@ demo_Hmac_Sha3_384()
expectedMac,
sizeof(expectedMac));
}
+ return 0;
}
-void
+int
demo_Hmac_Sha3_384_Reset()
{
Uint8 key[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
@@ -716,23 +726,27 @@ demo_Hmac_Sha3_384_Reset()
err = alcp_mac_request(&handle, &macinfo);
if (alcp_is_error(err)) {
printf("Error Occurred on MAC Request");
+ return -1;
}
// Update can be called multiple times with smaller chunks of the cipherText
err = alcp_mac_update(&handle, cipherText, sizeof(cipherText));
if (alcp_is_error(err)) {
printf("Error Occurred on MAC Update\n");
+ return -1;
}
// At this point if we need to we can reset and reuse with the same key
err = alcp_mac_reset(&handle);
if (alcp_is_error(err)) {
printf("Error Occurred on MAC Reset\n");
+ return -1;
}
// Update can be called multiple times with smaller chunks of the cipherText
err = alcp_mac_update(&handle, cipherText, sizeof(cipherText));
if (alcp_is_error(err)) {
printf("Error Occurred on MAC Update\n");
+ return -1;
}
// In Finalize code, last remaining buffer can be provided if any exists
@@ -740,10 +754,12 @@ demo_Hmac_Sha3_384_Reset()
err = alcp_mac_finalize(&handle, NULL, 0);
if (alcp_is_error(err)) {
printf("Error Occurred on MAC Finalize\n");
+ return -1;
}
err = alcp_mac_copy(&handle, mac, mac_size);
if (alcp_is_error(err)) {
printf("Error Occurred while Copying MAC\n");
+ return -1;
}
alcp_mac_finish(&handle);
free(handle.ch_context);
@@ -757,25 +773,33 @@ demo_Hmac_Sha3_384_Reset()
sizeof(mac),
expectedMac,
sizeof(expectedMac));
+ return 0;
}
int
main(int argc, char const* argv[])
{
// SHA-2 Based HMAC
- demo_Hmac_Sha224();
- demo_Hmac_Sha256();
- demo_Hmac_Sha384();
- demo_Hmac_Sha512();
-
- // SHA-3 BASED HMAC
- demo_Hmac_Sha3_224();
- demo_Hmac_Sha3_256();
- demo_Hmac_Sha3_384();
- demo_Hmac_Sha3_512();
-
- // Reset Demo
- demo_Hmac_Sha3_384_Reset();
+ if (demo_Hmac_Sha224() != 0)
+ goto out;
+ if (demo_Hmac_Sha256() != 0)
+ goto out;
+ if (demo_Hmac_Sha384() != 0)
+ goto out;
+ if (demo_Hmac_Sha512() != 0)
+ goto out;
+ if (demo_Hmac_Sha3_224() != 0)
+ goto out;
+ if (demo_Hmac_Sha3_256() != 0)
+ goto out;
+ if (demo_Hmac_Sha3_384() != 0)
+ goto out;
+ if (demo_Hmac_Sha3_512() != 0)
+ goto out;
+ if (demo_Hmac_Sha3_384_Reset() != 0)
+ goto out;
return 0;
+out:
+ return -1;
}
diff --git a/examples/mac/poly1305.c b/examples/mac/poly1305.c
new file mode 100644
index 000000000..5b7a044b9
--- /dev/null
+++ b/examples/mac/poly1305.c
@@ -0,0 +1,127 @@
+/*
+ * Copyright (C) 2023, Advanced Micro Devices. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS!
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "alcp/alcp.h"
+#include
+#include
+#include
+
+static alc_mac_handle_t handle;
+
+alc_error_t
+poly1305_demo(const alc_mac_info_p macInfo,
+ Uint8* data,
+ Uint32 dataLen,
+ Uint8* mac,
+ Uint32 mac_size)
+{
+
+ alc_error_t err = ALC_ERROR_NONE;
+
+ err = alcp_mac_supported(macInfo);
+
+ if (err == ALC_ERROR_NONE) {
+ handle.ch_context = malloc(alcp_mac_context_size(macInfo));
+ } else {
+ printf("Information provided is unsupported\n");
+ return err;
+ }
+ printf("Support Success!\n");
+
+ err = alcp_mac_request(&handle, macInfo);
+ if (alcp_is_error(err)) {
+ printf("Error Occurred on MAC Request - %lu\n", err);
+ return err;
+ }
+ printf("Request Success!\n");
+ // Update can be called multiple times with smaller chunks of the data
+ err = alcp_mac_update(&handle, data, dataLen);
+ if (alcp_is_error(err)) {
+ printf("Error Occurred on MAC Update\n");
+ return err;
+ }
+ printf("Mac Generation Success!\n");
+ // In Finalize code, last remaining buffer can be provided if any exists
+ // with its size
+ err = alcp_mac_finalize(&handle, NULL, 0);
+ if (alcp_is_error(err)) {
+ printf("Error Occurred on MAC Finalize\n");
+ return err;
+ }
+ printf("Finalized!\n");
+ err = alcp_mac_copy(&handle, mac, mac_size);
+ if (alcp_is_error(err)) {
+ printf("Error Occurred while Copying MAC\n");
+ return err;
+ }
+ printf("Mac Copy Success!\n");
+ alcp_mac_finish(&handle);
+ free(handle.ch_context);
+ return err;
+}
+
+int
+main(int argc, char const* argv[])
+{
+ alc_error_t err;
+
+ Uint8 key[32] = { 0x85, 0xd6, 0xbe, 0x78, 0x57, 0x55, 0x6d, 0x33,
+ 0x7f, 0x44, 0x52, 0xfe, 0x42, 0xd5, 0x06, 0xa8,
+ 0x01, 0x03, 0x80, 0x8a, 0xfb, 0x0d, 0xb2, 0xfd,
+ 0x4a, 0xbf, 0xf6, 0xaf, 0x41, 0x49, 0xf5, 0x1b };
+
+ Uint8 data[16] = { 0x43, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x67, 0x72,
+ 0x61, 0x70, 0x68, 0x69, 0x63, 0x20, 0x46, 0x6f };
+
+ Uint8 expectedMac[] = { 0xfd, 0x86, 0x1c, 0x71, 0x84, 0xf9, 0x8f, 0x45,
+ 0xdc, 0x6d, 0x5b, 0x4d, 0xc6, 0xc0, 0x81, 0xe4 };
+
+ const alc_key_info_t kinfo = { .type = ALC_KEY_TYPE_SYMMETRIC,
+ .fmt = ALC_KEY_FMT_RAW,
+ .algo = ALC_KEY_ALG_MAC,
+ .len = sizeof(key) * 8,
+ .key = key };
+
+ alc_mac_info_t macinfo = { .mi_type = ALC_MAC_POLY1305,
+ .mi_keyinfo = kinfo };
+
+ Uint64 mac_size = 16;
+ Uint8 mac[mac_size];
+ err = poly1305_demo(&macinfo, data, sizeof(data), mac, mac_size);
+ if (err != ALC_ERROR_NONE) {
+ printf("Error in CMAC\n");
+ return -1;
+ } else {
+ if (memcmp(mac, expectedMac, mac_size) == 0) {
+ printf("Poly1305 verified!\n");
+ } else {
+ printf("Poly1305 failure!\n");
+ }
+ }
+ return 0;
+}
diff --git a/examples/misc/CMakeLists.txt b/examples/misc/CMakeLists.txt
new file mode 100644
index 000000000..7078e4149
--- /dev/null
+++ b/examples/misc/CMakeLists.txt
@@ -0,0 +1,53 @@
+ # Copyright (C) 2022-2023, Advanced Micro Devices. All rights reserved.
+ #
+ # Redistribution and use in source and binary forms, with or without
+ # modification, are permitted provided that the following conditions are met:
+ # 1. Redistributions of source code must retain the above copyright notice,
+ # this list of conditions and the following disclaimer.
+ # 2. Redistributions in binary form must reproduce the above copyright notice,
+ # this list of conditions and the following disclaimer in the documentation
+ # and/or other materials provided with the distribution.
+ # 3. Neither the name of the copyright holder nor the names of its contributors
+ # may be used to endorse or promote products derived from this software
+ # without specific prior written permission.
+ #
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ # POSSIBILITY OF SUCH DAMAGE.
+
+
+ ADD_EXAMPLE ( test_logger logger.cc)
+
+TARGET_INCLUDE_DIRECTORIES ( test_logger PRIVATE
+ ${CMAKE_SOURCE_DIR}/lib/include )
+
+TARGET_INCLUDE_DIRECTORIES ( test_logger-static PRIVATE
+ ${CMAKE_SOURCE_DIR}/lib/include )
+
+ADD_EXAMPLE ( test_cpuid cpuid.cc)
+
+TARGET_INCLUDE_DIRECTORIES ( test_cpuid PRIVATE
+ ${CMAKE_SOURCE_DIR}/lib/include
+ ${CMAKE_SOURCE_DIR}/tests/common/include )
+
+TARGET_INCLUDE_DIRECTORIES ( test_cpuid-static PRIVATE
+ ${CMAKE_SOURCE_DIR}/lib/include
+ ${CMAKE_SOURCE_DIR}/tests/common/include )
+
+ADD_EXAMPLE ( filecrypt filecrypt.cc)
+
+TARGET_INCLUDE_DIRECTORIES ( filecrypt PRIVATE
+ ${CMAKE_SOURCE_DIR}/lib/include
+ ${CMAKE_SOURCE_DIR}/tests/common/include )
+
+TARGET_INCLUDE_DIRECTORIES ( filecrypt-static PRIVATE
+ ${CMAKE_SOURCE_DIR}/lib/include
+ ${CMAKE_SOURCE_DIR}/tests/common/include )
\ No newline at end of file
diff --git a/examples/misc/cpuid.cc b/examples/misc/cpuid.cc
new file mode 100644
index 000000000..6d00e7ba7
--- /dev/null
+++ b/examples/misc/cpuid.cc
@@ -0,0 +1,131 @@
+/*
+ * Copyright (C) 2023, Advanced Micro Devices. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "alcp/utils/cpuid.hh"
+#include
+
+using alcp::utils::CpuId;
+
+#define GREEN "\033[0;32m"
+#define RED "\033[0;31m"
+#define RESET "\033[0m"
+
+void
+printBoolMsg(const std::string& msg, bool val)
+{
+ if (val) {
+ std::cout << GREEN;
+ } else {
+ std::cout << RED;
+ }
+ std::cout << "\t" << msg << ":";
+ if (val) {
+ std::cout << "YES";
+ } else {
+ std::cout << "NO";
+ }
+ std::cout << RESET << std::endl;
+}
+
+void
+checkAVX512Support()
+{
+ std::cout << "======AVX512 FLAGS=======" << std::endl;
+ printBoolMsg("AVX512F", CpuId::cpuHasAvx512f());
+ printBoolMsg("AVX512BW", CpuId::cpuHasAvx512bw());
+ printBoolMsg("AVX512DQ", CpuId::cpuHasAvx512dq());
+}
+
+void
+checkAVX2Support()
+{
+ std::cout << "======AVX2 FLAGS=======" << std::endl;
+ printBoolMsg("AVX2", CpuId::cpuHasAvx2());
+}
+
+void
+checkAESSupport()
+{
+ std::cout << "======AES FLAGS=======" << std::endl;
+ printBoolMsg("AESNI", CpuId::cpuHasAesni());
+ printBoolMsg("VAES", CpuId::cpuHasVaes());
+}
+
+void
+checkSHASupport()
+{
+ std::cout << "======SHA FLAGS=======" << std::endl;
+ printBoolMsg("SHANI", CpuId::cpuHasShani());
+}
+
+void
+checkRandSupport()
+{
+ std::cout << "======Rand FLAGS=======" << std::endl;
+ printBoolMsg("RDRAND", CpuId::cpuHasRdRand());
+ printBoolMsg("RDSEED", CpuId::cpuHasRdSeed());
+}
+
+void
+checkAdxSupport()
+{
+ std::cout << "======ADX FLAGS=======" << std::endl;
+ printBoolMsg("ADX", CpuId::cpuHasAdx());
+}
+
+void
+checkBmi2Support()
+{
+ std::cout << "======BMI FLAGS=======" << std::endl;
+ printBoolMsg("BMI2", CpuId::cpuHasBmi2());
+}
+
+void
+checkAMDSupport()
+{
+ std::cout << "======AMD FLAGS=======" << std::endl;
+ printBoolMsg("ZEN1", CpuId::cpuIsZen1());
+ printBoolMsg("ZEN2", CpuId::cpuIsZen2());
+ printBoolMsg("ZEN3", CpuId::cpuIsZen3());
+ printBoolMsg("ZEN4", CpuId::cpuIsZen4());
+}
+
+int
+main()
+{
+ checkAMDSupport();
+ checkAESSupport();
+ checkSHASupport();
+ checkRandSupport();
+ checkAVX2Support();
+ checkAVX512Support();
+ checkAdxSupport();
+ checkBmi2Support();
+
+ return 0;
+}
\ No newline at end of file
diff --git a/examples/misc/filecrypt.cc b/examples/misc/filecrypt.cc
new file mode 100644
index 000000000..ff951d10c
--- /dev/null
+++ b/examples/misc/filecrypt.cc
@@ -0,0 +1,523 @@
+/*
+ * Copyright (C) 2023, Advanced Micro Devices. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include
+#include
+#include
+#include
+#include