Files
blowfish/CMakeLists.txt
T
avinal 1933265148 feat: security fixes and improved test coverages
Security Fixes

  1. Blowfish2 destructor added (blowfish2.h, blowfish2.cc) — zeros PArray and Sboxes on destruction
  2. Secure memory zeroing (blowfish.cc, blowfish2.cc) — both destructors now use volatile pointer writes to prevent compiler elision
  3. Input validation (blowfish.cc, blowfish2.cc) — initialize() now throws std::invalid_argument for null key, empty key, or key > 56 bytes
  4. Copy assignment deleted (blowfish.h) — prevents accidental key material copies
  5. Constants moved inside include guards (blowfish.h, blowfish2.h)

  Code Quality Fixes

  6. Typo fixed — BF_SBOX_INT → BF_SBOX_INIT in blowfish.cc
  7. CMake standard fixed — blowfish2 target now requires cxx_std_17 instead of cxx_std_14

  Test Fixes & Additions

  8. Fixed "no fixed points" bug (test_properties.cpp) — L is no longer always 0
  9. Eric Young KAT vectors (test_vectors.cpp) — 5 official Blowfish test vectors added
  10. Key length tests — min (1 byte), max (56 bytes), and differing lengths
  11. Invalid key rejection tests — empty, over-length, and null keys
  12. Edge-case blocks — all-zero, all-ones, L==R
  13. Key avalanche tests — flipping each key bit produces large ciphertext changes
  14. Cross-instance consistency — same key → same output across instances
  15. Re-initialization tests — different key after re-init produces different output

Assisted-by: Claude Code

Signed-off-by: Avinal Kumar <avinal.xlvii@gmail.com>
2026-04-15 18:21:01 +05:30

73 lines
1.9 KiB
CMake

cmake_minimum_required(VERSION 3.30)
project(blowfish VERSION 1.0.0 LANGUAGES CXX)
message(STATUS "CMake version: ${CMAKE_VERSION}")
message(STATUS "Project version: ${PROJECT_VERSION}")
# ===== compiler settings =====
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
message(STATUS "Using C++ standard c++${CMAKE_CXX_STANDARD}")
set(BF_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include)
# ===== blowfish library =====
add_library(blowfish)
target_compile_features(blowfish PUBLIC cxx_std_17)
target_sources(blowfish
PRIVATE
src/blowfish.cc
PUBLIC FILE_SET HEADERS
BASE_DIRS ${BF_INCLUDE_DIR}
FILES include/blowfish/blowfish.h
)
target_include_directories(blowfish PUBLIC ${BF_INCLUDE_DIR})
# ===== blowfish2 library =====
add_library(blowfish2)
target_compile_features(blowfish2 PUBLIC cxx_std_17)
target_sources(blowfish2
PRIVATE
src/blowfish2.cc
PUBLIC FILE_SET HEADERS
BASE_DIRS ${BF_INCLUDE_DIR}
FILES include/blowfish/blowfish2.h
)
target_include_directories(blowfish2 PUBLIC ${BF_INCLUDE_DIR})
# ===== Tests =====
include(CTest)
if (BUILD_TESTING)
# ---- Blowfish Test ----
add_executable(bf_test
tests/Main.cpp
tests/test_framework.h
tests/test_vectors.cpp
tests/test_roundtrip.cpp
tests/test_avalanche.cpp
tests/test_properties.cpp
)
target_link_libraries(bf_test PRIVATE blowfish)
add_test(NAME BlowfishTests COMMAND bf_test)
# ---- Blowfish2 Test ----
add_executable(bf2_test
tests/Main2.cpp
tests/test_framework.h
tests/bf2_test_vectors.cpp
tests/bf2_test_roundtrip.cpp
tests/bf2_test_avalanche.cpp
tests/bf2_test_properties.cpp
)
target_link_libraries(bf2_test PRIVATE blowfish2)
add_test(NAME Blowfish2Tests COMMAND bf2_test)
endif()