In Blowfish - Fix incorrect F-function byte extraction (critical bug). - Correct key-schedule handling by using `uint8_t` key bytes. - Initialize local variables in `initialize()` to prevent UB. - Improve decrypt loop and XOR usage for clarity and correctness. In Blowfish2 - Zero-initialize P-array and S-boxes to guarantee deterministic state. - Fix incorrect key size comment (448 bits, not 4224 bits). - Improve F-function byte extraction clarity. - Normalize round loop logic and use XOR-assignment. Others - Replace macro `N` with `constexpr N`. - Add `noexcept` to internal operations. - Add `initialize(const uint8_t*, size_t)` overload for binary keys. - Clean up readability and internal consistency across both ciphers. Signed-off-by: Avinal Kumar <avinal.xlvii@gmail.com>
Blowfish and Blowfish2 Encryption Algorithm
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 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
This is a C++ implementation of the encryption algorithm.
How to use this in your project?
- You may fork it and use it like any other source file in your project. You only need blowfish.hpp and blowfish.cpp files. Just modify the header as per your convienence.
- 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.
# In your project root type these commands
git submodule add https://github.com/avinal/blowfish
# considering this addition is your only change
git commit -m "blowfish submodule added"
git push origin main
Add this to your CMakeLists.txt as well.