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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 73 additions & 41 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,79 +8,111 @@ set(CMAKE_CXX_EXTENSIONS OFF)

# Options
option(BUILD_TESTS "Build test suite" ON) # Enable tests
option(BUILD_DOCS "Build docs" OFF)
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)

# Find required packages
find_package(OpenSSL REQUIRED)
find_package(GTest REQUIRED)

# Add nlohmann/json
include(FetchContent)
FetchContent_Declare(
json
URL https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz
# Preprocessing
get_filename_component(RESOURCES_FOLDER_PATH ${CMAKE_CURRENT_SOURCE_DIR}/res ABSOLUTE)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/include/hashsigs-cpp/resources.hpp.in
${CMAKE_CURRENT_SOURCE_DIR}/include/hashsigs-cpp/resources.hpp
)
FetchContent_MakeAvailable(json)

# Set output directories
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)

# Include directories
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/include
${OPENSSL_INCLUDE_DIR}
)
##############
# Dependencies
##############
include(FetchContent)
include(FindPackageMessage)

# Add OpenSSL
find_package(OpenSSL REQUIRED)

# Add fmt
FetchContent_Declare(
fmt
GIT_REPOSITORY https://github.com/fmtlib/fmt
GIT_TAG 407c905e45ad75fc29bf0f9bb7c5c2fd3475976f) # 12.1.0
FetchContent_MakeAvailable(fmt)

################
# Library target
################
add_library(hashsigs
src/wotsplus.cpp
src/keccak.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/wotsplus.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/keccak.cpp
)

target_link_libraries(hashsigs
PRIVATE
target_include_directories(hashsigs PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
)

target_link_libraries(hashsigs PRIVATE
fmt::fmt
OpenSSL::SSL
OpenSSL::Crypto
)

##########
# CLI tool
##########
add_executable(hashsigs_cli
src/hashsigs_cli.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/hashsigs_cli.cpp
)

target_link_libraries(hashsigs_cli
PRIVATE
target_link_libraries(hashsigs_cli PRIVATE
hashsigs
)

###############
# Install rules
install(TARGETS hashsigs
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin
###############
include(GNUInstallDirs)

install(
TARGETS hashsigs
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install(DIRECTORY include/ DESTINATION include)

install(
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING PATTERN "*.hpp" PATTERN "*.h"
)

#######
# Tests
#######
if(BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()

###############
# Documentation
find_package(Doxygen)
if(DOXYGEN_FOUND)
set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile.in)
set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)

configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY)

add_custom_target(docs
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen"
VERBATIM
)
endif()
###############
if(BUILD_DOCS)
message(STATUS "Building docs...")
find_package(Doxygen)
if(Doxygen_FOUND)
set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile.in)
set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)

configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY)

add_custom_target(docs
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen..."
VERBATIM
)
else()
message(STATUS "Doxygen not found.")
endif()
endif()
19 changes: 14 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ make

## Testing

Tests are built by default. To build the library without tests:

```bash
mkdir build
cd build
cmake -DBUILD_TESTS=OFF ..
make
```

Run all tests:

```bash
Expand All @@ -34,21 +43,20 @@ make test
Or run the test executable directly:

```bash
./tests/wotsplus_test
./build/bin/hashsigs_tests
```

For test output and backtrace:

```bash
GTEST_COLOR=1 ./tests/wotsplus_test --gtest_color=yes
GTEST_COLOR=1 ./build/bin/hashsigs_tests --gtest_color=yes
```

## Development Requirements

- CMake 3.10 or higher
- C++17 or higher
- Google Test
- nlohmann/json

## Project Structure

Expand All @@ -58,12 +66,13 @@ GTEST_COLOR=1 ./tests/wotsplus_test --gtest_color=yes
│ ├── constants.hpp
│ ├── public_key.hpp
│ └── wotsplus.hpp
├── res/ # Resource files
└── vectors/
├── src/ # Implementation files
│ ├── keccak.cpp
│ └── wotsplus.cpp
└── tests/ # Test vectors and unit tests
└── tests/ # Unit tests
├── wotsplus_test.cpp
└── test_vectors/
```

## License
Expand Down
Empty file added docs/Doxyfile.in
Empty file.
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions include/hashsigs-cpp/resources.hpp.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <filesystem>

namespace res {

static const std::filesystem::path resources_folder_path = "@RESOURCES_FOLDER_PATH@";

}
File renamed without changes.
6 changes: 4 additions & 2 deletions src/hashsigs_cli.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "../include/keccak.h"
#include "../include/wotsplus.hpp"
#include "hashsigs-cpp/keccak.h"
#include "hashsigs-cpp/wotsplus.hpp"

#include <algorithm>
#include <array>
#include <iomanip>
#include <iostream>
Expand Down
2 changes: 1 addition & 1 deletion src/keccak.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// see http://create.stephan-brumme.com/disclaimer.html
//

#include "keccak.h"
#include "hashsigs-cpp/keccak.h"

// Cross-platform endianness detection
#if defined(__APPLE__)
Expand Down
5 changes: 3 additions & 2 deletions src/wotsplus.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "wotsplus.hpp"
#include "constants.hpp"
#include "hashsigs-cpp/wotsplus.hpp"
#include "hashsigs-cpp/constants.hpp"

#include <algorithm>
#include <cmath>
#include <iostream>
Expand Down
28 changes: 18 additions & 10 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
# Add test executable
add_executable(hashsigs_tests
wotsplus_test.cpp
##############
# Dependencies
##############

# Add GTest
find_package(GTest REQUIRED)

# Add nlohmann/json
FetchContent_Declare(json
URL https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
)
FetchContent_MakeAvailable(json)

# Copy test vectors to build directory
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/test_vectors/wotsplus_keccak256.json
${CMAKE_CURRENT_BINARY_DIR}/wotsplus_keccak256.json
COPYONLY
#################
# Test executable
#################
add_executable(hashsigs_tests
wotsplus_test.cpp
)

# Link against the library and GTest
target_link_libraries(hashsigs_tests
PRIVATE
hashsigs
Expand All @@ -25,4 +33,4 @@ add_test(NAME hashsigs_tests COMMAND hashsigs_tests)
# Set test properties
set_tests_properties(hashsigs_tests PROPERTIES
ENVIRONMENT "GTEST_COLOR=1"
)
)
11 changes: 8 additions & 3 deletions tests/wotsplus_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include "keccak.h"
#include "wotsplus.hpp"
#include "hashsigs-cpp/keccak.h"
#include "hashsigs-cpp/resources.hpp"
#include "hashsigs-cpp/wotsplus.hpp"

#include <filesystem>
#include <fstream>
#include <gtest/gtest.h>
#include <iomanip>
Expand Down Expand Up @@ -145,7 +148,9 @@ TEST(WOTSPlusTest, VerifyValidSignatureWithRandomizationElements) {
}

TEST(WOTSPlusTest, Keccak256TestVectors) {
std::ifstream f("wotsplus_keccak256.json");
std::filesystem::path vectors_file_path{
res::resources_folder_path / "vectors" / "wotsplus_keccak256.json" };
std::ifstream f{ vectors_file_path };
json data = json::parse(f);

WOTSPlus wots(keccak256);
Expand Down