2024-09-05 21:08:04 +05:30
|
|
|
# Blowfish and Blowfish2 Encryption Algorithm
|
2021-02-16 18:40:18 +05:30
|
|
|
|
2025-12-04 21:13:31 +05:30
|
|
|
[](https://github.com/avinal/blowfish/actions/workflows/cmake.yml)
|
2021-02-16 18:49:51 +05:30
|
|
|
|
2025-12-04 21:13:31 +05:30
|
|
|
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.
|
2021-02-16 18:40:18 +05:30
|
|
|
|
2025-12-04 21:13:31 +05:30
|
|
|
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.
|
2024-09-05 21:08:04 +05:30
|
|
|
|
2021-02-16 18:40:18 +05:30
|
|
|
## About this project
|
|
|
|
|
|
|
|
|
|
This is a C++ implementation of the encryption algorithm.
|
|
|
|
|
|
|
|
|
|
## How to use this in your project?
|
2024-09-05 21:08:04 +05:30
|
|
|
|
2025-12-04 21:13:31 +05:30
|
|
|
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 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.
|
2024-09-05 21:08:04 +05:30
|
|
|
|
2021-02-21 22:58:54 +05:30
|
|
|
```bash
|
|
|
|
|
# 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
|
2025-12-04 21:13:31 +05:30
|
|
|
```
|
|
|
|
|
|
|
|
|
|
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:
|
2024-09-05 21:08:04 +05:30
|
|
|
|
2025-12-04 21:13:31 +05:30
|
|
|
```shell
|
|
|
|
|
cmake --build build --config Debug
|
|
|
|
|
```
|
2021-02-16 18:40:18 +05:30
|
|
|
|
|
|
|
|
## References
|
2024-09-05 21:08:04 +05:30
|
|
|
|
2021-02-16 18:40:18 +05:30
|
|
|
- [Description of a new variable-length key, 64-bit block cipher (Blowfish)](https://link.springer.com/chapter/10.1007/3-540-58108-1_24)
|
|
|
|
|
- [The Blowfish Encryption Algorithm](https://www.schneier.com/academic/blowfish/)
|
2024-09-05 21:08:04 +05:30
|
|
|
- [The Blowfish 2 C Implementation](https://github.com/erwanmilon/blowfish2/)
|