Improve GitHub Actions flow and increse Cmake version
Some checks failed
Build and Test / build (Debug, clang) (push) Failing after 18s
Build and Test / build (Debug, gcc) (push) Failing after 17s
Build and Test / build (Release, clang) (push) Failing after 25s
Build and Test / build (Release, gcc) (push) Failing after 17s
Build and Test / sanitize (push) Failing after 3s

- Increased CMake minimum version to 3.30
- added test run in github workflow

Signed-off-by: Avinal Kumar <avinal.xlvii@gmail.com>
This commit is contained in:
2025-12-04 21:13:31 +05:30
parent f9ae6fddfd
commit 9d303b7855
4 changed files with 108 additions and 72 deletions

View File

@@ -1,29 +1,24 @@
name: Build C++ Project name: Build and Test
on: [push, pull_request]
on: [push]
jobs: jobs:
build: build:
name: Build on Ubuntu with GCC runs-on: ubuntu-latest
runs-on: ubuntu-latest # For Gitea, ensure you have a runner with the 'ubuntu-latest' label strategy:
matrix: {compiler: [gcc, clang], build_type: [Release, Debug]}
# Environment variables for the C/C++ compiler
env:
CC: gcc
CXX: g++
steps: steps:
# Step 1: Check out the repository code - uses: actions/checkout@v4
- name: Checkout repository - name: Install deps
uses: actions/checkout@v4 # Updated to the latest version for best practice run: sudo apt-get update && sudo apt-get install -y build-essential cmake
# Note for Gitea: Ensure your instance can access this action or use a native 'git clone' command. - name: Configure
run: cmake -S . -B build -DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
# Step 2: Configure the project and build it - name: Build
- name: Configure and Build run: cmake --build build -j
run: | - name: Run tests
# Configure using CMake. The -B flag creates the 'build' directory. run: ctest --output-on-failure -C ${{ matrix.build_type }} -V
# The build type is now hardcoded to 'Debug'. sanitize:
cmake -B build -DCMAKE_BUILD_TYPE=Debug -DCMAKE_VERBOSE_MAKEFILE=ON . runs-on: ubuntu-latest
steps:
# Build the project using the generated configuration. - uses: actions/checkout@v4
cmake --build build --config Debug - run: cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS="-fsanitize=address,undefined -fno-omit-frame-pointer"
- run: cmake --build build -j
- run: ctest --output-on-failure -C Debug -V

1
.gitignore vendored
View File

@@ -36,3 +36,4 @@
cmake-build-debug cmake-build-debug
build build
.vscode .vscode
.cache

View File

@@ -1,53 +1,54 @@
cmake_minimum_required(VERSION 3.1) cmake_minimum_required(VERSION 3.30)
project(blowfish VERSION 1.0.0 LANGUAGES CXX) project(blowfish VERSION 1.0.0 LANGUAGES CXX)
message(STATUS "CMake version: ${CMAKE_VERSION}")
message(STATUS "Project version: ${PROJECT_VERSION}")
if (NOT CMAKE_CXX_STANDARD) # ===== compiler settings =====
set(CMAKE_CXX_STANDARD 14) set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
elseif (CMAKE_CXX_STANDARD LESS 11)
message(WARNING "CMAKE_CXX_STANDARD has been set to '${CMAKE_CXX_STANDARD}' which is lower than the minimum required standard (c++14).")
endif ()
message(STATUS "Using C++ standard c++${CMAKE_CXX_STANDARD}") set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
message(STATUS "Using C++ standard c++${CMAKE_CXX_STANDARD}")
message (STATUS "CMake version: ${CMAKE_VERSION}") set(BF_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include)
message (STATUS "Project version: ${PROJECT_VERSION}")
set(BLOWFISH_SRC ${PROJECT_SOURCE_DIR}/src/blowfish.cc) # ===== blowfish library =====
set(BLOWFISH2_SRC ${PROJECT_SOURCE_DIR}/src/blowfish2.cc) add_library(blowfish)
source_group(src FILES ${BLOWFISH_SRC} ${BLOWFISH2_SRC}) target_compile_features(blowfish PUBLIC cxx_std_17)
set(BLOWFISH_TEST ${PROJECT_SOURCE_DIR}/tests/Main.cpp) target_sources(blowfish
set(BLOWFISH2_TEST ${PROJECT_SOURCE_DIR}/tests/Main2.cpp) PRIVATE
source_group(tests FILES ${BLOWFISH_TEST} ${BLOWFISH2_TEST}) src/blowfish.cc
PUBLIC FILE_SET HEADERS
set(BLOWFISH_INC ${PROJECT_SOURCE_DIR}/include/blowfish/blowfish.h) BASE_DIRS ${BF_INCLUDE_DIR}
set(BLOWFISH2_INC ${PROJECT_SOURCE_DIR}/include/blowfish/blowfish2.h) FILES include/blowfish/blowfish.h
source_group(include FILES ${BLOWFISH_INC} ${BLOWFISH2_INC})
set(BLOWFISH_DOC
README.md
LICENSE
) )
source_group(doc FILES ${BLOWFISH_DOC})
set(BLOWFISH_SCRIPTS target_include_directories(blowfish PUBLIC ${BF_INCLUDE_DIR})
.gitattributes
.gitignore # ===== blowfish2 library =====
build.sh add_library(blowfish2)
target_compile_features(blowfish2 PUBLIC cxx_std_14)
target_sources(blowfish2
PRIVATE
src/blowfish2.cc
PUBLIC FILE_SET HEADERS
BASE_DIRS ${BF_INCLUDE_DIR}
FILES include/blowfish/blowfish2.h
) )
source_group(scripts FILES ${BLOWFISH_SCRIPTS})
add_library(blowfish ${BLOWFISH_SRC} ${BLOWFISH_INC} ${BLOWFISH_SCRIPTS} ${BLOWFISH_DOC}) target_include_directories(blowfish2 PUBLIC ${BF_INCLUDE_DIR})
add_library(blowfish2 ${BLOWFISH2_SRC} ${BLOWFISH2_INC} ${BLOWFISH_SCRIPTS} ${BLOWFISH_DOC})
target_include_directories(blowfish PUBLIC ${PROJECT_SOURCE_DIR}/include) # ===== Tests =====
target_include_directories(blowfish2 PUBLIC ${PROJECT_SOURCE_DIR}/include) include(CTest)
if(BUILD_TESTING)
add_executable(bf_test ${BLOWFISH_TEST} ${BLOWFISH_SRC} ${BLOWFISH_INC}) add_executable(bf_test tests/Main.cpp)
add_executable(bf2_test ${BLOWFISH2_TEST} ${BLOWFISH2_SRC} ${BLOWFISH2_INC}) target_link_libraries(bf_test PRIVATE blowfish)
add_test(NAME bf_test COMMAND bf_test)
target_include_directories(bf_test PUBLIC ${PROJECT_SOURCE_DIR}/include)
target_include_directories(bf2_test PUBLIC ${PROJECT_SOURCE_DIR}/include)
add_executable(bf2_test tests/Main2.cpp)
target_link_libraries(bf2_test PRIVATE blowfish2)
add_test(NAME bf2_test COMMAND bf2_test)
endif()

View File

@@ -1,10 +1,17 @@
# Blowfish and Blowfish2 Encryption Algorithm # Blowfish and Blowfish2 Encryption Algorithm
<p align=center><a href="https://github.com/avinal/blowfish/actions"><img alt="build" src="https://github.com/avinal/blowfish/workflows/build/badge.svg?branch=main"></a><a href="https://github.com/avinal/blowfish/blob/main/LICENSE"><img src="https://img.shields.io/github/license/avinal/blowfish" alt="license"></a></p> [![Build Status](https://github.com/avinal/blowfish/actions/workflows/cmake.yml/badge.svg)](https://github.com/avinal/blowfish/actions/workflows/cmake.yml)
Blowfish is a symmetric block cipher that can be used as a drop-in replacement for DES or IDEA. It takes a variable-length key, from 32 bits to 448 bits, making it ideal for both domestic and exportable use. Blowfish was designed in 1993 by Bruce Schneier as a fast, free alternative to existing encryption algorithms. Since then it has been analyzed considerably, and it is slowly gaining acceptance as a strong encryption algorithm. Blowfish is unpatented and license-free, and is available free for all uses. Blowfish is a symmetric block cipher that can be used as a drop-in replacement for DES or IDEA. It
takes a variable-length key, from 32 bits to 448 bits, making it ideal for both domestic and
exportable use. Blowfish was designed in 1993 by Bruce Schneier as a fast, free alternative to
existing encryption algorithms. Since then it has been analyzed considerably, and it is slowly
gaining acceptance as a strong encryption algorithm. Blowfish is not patented and license-free,
and is available free for all uses.
Blowfish 2 was released in 2005. It has exactly the same design but has twice as many S tables and uses 64-bit integers instead of 32-bit integers. It no longer works on 64-bit blocks but on 128-bit blocks like AES. 128-bit block, 64 rounds, key up to 4224 bits. Blowfish 2 was released in 2005. It has exactly the same design but has twice as many S tables and
uses 64-bit integers instead of 32-bit integers. It no longer works on 64-bit blocks but on 128-bit
blocks like AES. 128-bit block, 64 rounds, key up to 4224 bits.
## About this project ## About this project
@@ -12,8 +19,12 @@ This is a C++ implementation of the encryption algorithm.
## How to use this in your project? ## How to use this in your project?
1. You may fork it and use it like any other source file in your project. You only need [blowfish.hpp](include/blowfish/blowfish.hpp) and [blowfish.cpp](src/blowfish.cpp) files. Just modify the header as per your convienence. 1. You may fork it and use it like any other source file in your project. You only need
2. If you are using CMake, the work is lot easier. You can add this as a git submodule. It isolates your project from this dependency. [blowfish.hpp](include/blowfish/blowfish.hpp) and [blowfish.cpp](src/blowfish.cpp) files. Just
modify the header as per your convenience.
2. If you are using CMake, the work is lot easier. You can add this as a git submodule. It isolates
your project from this dependency.
```bash ```bash
# In your project root type these commands # In your project root type these commands
@@ -21,9 +32,37 @@ This is a C++ implementation of the encryption algorithm.
# considering this addition is your only change # considering this addition is your only change
git commit -m "blowfish submodule added" git commit -m "blowfish submodule added"
git push origin main git push origin main
``` ```
Add this to your CMakeLists.txt as well. Add this to your CMakeLists.txt as well.
## Building
This library has no dependencies on any other code. Just a C++ compiler should be enough to build
this. Although this library is supposed to be used under some other project, sometimes you may need
to build this. Here are the prerequisites:
- [CMake](https://cmake.org/download/)
- [G++](https://gcc.gnu.org/) or [Clang](https://clang.llvm.org/)
- [Make](https://www.gnu.org/software/make/) or [Ninja Build](https://ninja-build.org/) or any other CMake compatible generator.
Here is how I install them on Fedora:
```shell
sudo dnf install clang cmake g++ make ninja-build
```
Configure CMake, enabled debug for development purposes:
```shell
cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Debug
```
Build using configured generator:
```shell
cmake --build build --config Debug
```
## References ## References