1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-05-03 17:27:47 +00:00
sapphire/src/common/Crypt/blowfish.h

84 lines
1.5 KiB
C
Raw Normal View History

2017-12-18 23:10:36 +01:00
#ifndef _BLOWFISH_H
#define _BLOWFISH_H
2017-08-08 13:53:47 +02:00
// blowfish.h interface file for blowfish.cpp
// _THE BLOWFISH ENCRYPTION ALGORITHM_
// by Bruce Schneier
// Revised code--3/20/94
// Converted to C++ class 5/96, Jim Conger
#define MAXKEYBYTES 56 // 448 bits max
#define NPASS 16 // SBox passes
2017-08-08 13:53:47 +02:00
#define DWORD uint32_t
#define WORD unsigned short
#define BYTE uint8_t
2017-08-08 13:53:47 +02:00
class BlowFish
{
private:
DWORD* PArray;
DWORD (* SBoxes)[256];
void Blowfish_encipher( DWORD* xl, DWORD* xr );
void Blowfish_decipher( DWORD* xl, DWORD* xr );
2017-08-08 13:53:47 +02:00
public:
BlowFish();
~BlowFish();
void initialize( BYTE key[], int32_t keybytes );
DWORD GetOutputLength( DWORD lInputLong );
DWORD Encode( BYTE* pInput, BYTE* pOutput, DWORD lSize );
2017-08-08 13:53:47 +02:00
void Decode( BYTE* pInput, BYTE* pOutput, DWORD lSize );
};
2017-08-08 13:53:47 +02:00
// choose a byte order for your hardware
#define ORDER_DCBA // chosing Intel in this case
#ifdef ORDER_DCBA // DCBA - little endian - intel
union aword
{
DWORD dword;
BYTE byte[4];
struct
{
uint32_t byte3:8;
uint32_t byte2:8;
uint32_t byte1:8;
uint32_t byte0:8;
} w;
};
2017-08-08 13:53:47 +02:00
#endif
#ifdef ORDER_ABCD // ABCD - big endian - motorola
union aword {
DWORD dword;
BYTE byte [4];
struct {
uint32_t byte0:8;
uint32_t byte1:8;
uint32_t byte2:8;
uint32_t byte3:8;
} w;
};
2017-08-08 13:53:47 +02:00
#endif
#ifdef ORDER_BADC // BADC - vax
union aword {
DWORD dword;
BYTE byte [4];
struct {
uint32_t byte1:8;
uint32_t byte0:8;
uint32_t byte3:8;
uint32_t byte2:8;
} w;
2017-08-08 13:53:47 +02:00
};
#endif
2017-12-18 23:10:36 +01:00
#endif