feat: add blowfish2 128 bit implementation

- regular blowfish only uses 64 bits
- blowfish2 uses 128 bits like AES

Signed-off-by: Avinal Kumar <avinal.xlvii@gmail.com>
This commit is contained in:
2024-09-05 21:08:04 +05:30
parent b6931e3196
commit 960c48573e
10 changed files with 968 additions and 41 deletions
+6 -8
View File
@@ -1,19 +1,17 @@
/*
* @file blowfish.hpp
* @author Avinal Kumar
* @since February 15, 2021
*
* Blowfish Algorithm Header File
*/
// SPDX-FileCopyrightText: 2024 Avinal Kumar avinal.xlvii@gmail.com
// SPDX-License-Identifier: MIT
// Original Blowfish Algorithm copyright:
// SPDX-FileCopyrightText: 1997 Paul Kocher
#include <algorithm>
#include <array>
#include <cstdint>
#include <string>
#define MAXKEYBYTES 56 // 448 bits max
#define N 16
#if !defined(BLOWFISH_BLOWFISH_H_)
#define BLOWFISH_BLOWFISH_H_
+35
View File
@@ -0,0 +1,35 @@
// SPDX-FileCopyrightText: 2024 Avinal Kumar avinal.xlvii@gmail.com
// SPDX-License-Identifier: MIT
// Original Blowfish 2 Algorithm copyright:
// SPDX-FileCopyrightText: 2005 Alexander Pukall
#include <algorithm>
#include <array>
#include <cstdint>
#include <string>
#define MAXKEYBYTES 56 // 4224 bits max
#define N 64
#if !defined(BLOWFISH_BLOWFISH2_H_)
#define BLOWFISH_BLOWFISH2_H_
class Blowfish2 {
private:
std::array<uint64_t, N + 2> PArray;
std::array<std::array<uint64_t, 256>, 8> Sboxes;
uint64_t F(uint64_t x);
public:
Blowfish2() {}
Blowfish2(std::string const &key);
Blowfish2(Blowfish2 const &) = delete;
void initialize(std::string const &key);
void encrypt(uint64_t &xl, uint64_t &xr);
void decrypt(uint64_t &xl, uint64_t &xr);
};
#endif // BLOWFISH_BLOWFISH2_H_