CMS 3D CMS Logo

Classes | Macros | Typedefs | Functions
blowfish.h File Reference

Go to the source code of this file.

Classes

struct  BCoptions
 
struct  BLOWFISH_CTX
 

Macros

#define DECRYPT   1
 
#define ENCRYPT   0
 
#define endianBig   ((unsigned char)0x45)
 
#define endianLittle   ((unsigned char)0x54)
 
#define INCLUDE_BLOWFISH_DEFINE_H
 
#define MAXKEYBYTES   56 /* 448 bits */
 
#define S_ISREG(x)   (((x)&S_IFMT) == S_IFREG)
 

Typedefs

typedef unsigned int uInt32
 

Functions

void Blowfish_Decrypt (BLOWFISH_CTX *ctx, uInt32 *xl, uInt32 *xr)
 
void Blowfish_Encrypt (BLOWFISH_CTX *ctx, uInt32 *xl, uInt32 *xr)
 
void Blowfish_Init (BLOWFISH_CTX *ctx, unsigned char *key, int keyLen)
 

Macro Definition Documentation

◆ DECRYPT

#define DECRYPT   1

Definition at line 20 of file blowfish.h.

◆ ENCRYPT

#define ENCRYPT   0

Definition at line 19 of file blowfish.h.

◆ endianBig

#define endianBig   ((unsigned char)0x45)

Definition at line 22 of file blowfish.h.

◆ endianLittle

#define endianLittle   ((unsigned char)0x54)

Definition at line 23 of file blowfish.h.

◆ INCLUDE_BLOWFISH_DEFINE_H

#define INCLUDE_BLOWFISH_DEFINE_H

Definition at line 8 of file blowfish.h.

◆ MAXKEYBYTES

#define MAXKEYBYTES   56 /* 448 bits */

Definition at line 37 of file blowfish.h.

◆ S_ISREG

#define S_ISREG (   x)    (((x)&S_IFMT) == S_IFREG)

Definition at line 34 of file blowfish.h.

Typedef Documentation

◆ uInt32

typedef unsigned int uInt32

Definition at line 25 of file blowfish.h.

Function Documentation

◆ Blowfish_Decrypt()

void Blowfish_Decrypt ( BLOWFISH_CTX ctx,
uInt32 xl,
uInt32 xr 
)

Definition at line 207 of file blowfish.cc.

References F(), mps_fire::i, N, BLOWFISH_CTX::P, and groupFilesInBlocks::temp.

Referenced by cond::auth::Cipher::bf_process_alloc().

207  {
208  uInt32 Xl;
209  uInt32 Xr;
210  uInt32 temp;
211  short i;
212 
213  Xl = *xl;
214  Xr = *xr;
215 
216  for (i = N + 1; i > 1; --i) {
217  Xl = Xl ^ ctx->P[i];
218  Xr = F(ctx, Xl) ^ Xr;
219  /* Exchange Xl and Xr */
220  temp = Xl;
221  Xl = Xr;
222  Xr = temp;
223  }
224 
225  /* Exchange Xl and Xr */
226  temp = Xl;
227  Xl = Xr;
228  Xr = temp;
229  Xr = Xr ^ ctx->P[1];
230  Xl = Xl ^ ctx->P[0];
231  *xl = Xl;
232  *xr = Xr;
233 }
unsigned int uInt32
Definition: blowfish.h:25
uInt32 P[16+2]
Definition: blowfish.h:40
#define N
Definition: blowfish.cc:9
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:163

◆ Blowfish_Encrypt()

void Blowfish_Encrypt ( BLOWFISH_CTX ctx,
uInt32 xl,
uInt32 xr 
)

Definition at line 181 of file blowfish.cc.

References F(), mps_fire::i, N, BLOWFISH_CTX::P, and groupFilesInBlocks::temp.

Referenced by cond::auth::Cipher::bf_process_alloc(), and Blowfish_Init().

181  {
182  uInt32 Xl;
183  uInt32 Xr;
184  uInt32 temp;
185  short i;
186 
187  Xl = *xl;
188  Xr = *xr;
189 
190  for (i = 0; i < N; ++i) {
191  Xl = Xl ^ ctx->P[i];
192  Xr = F(ctx, Xl) ^ Xr;
193  temp = Xl;
194  Xl = Xr;
195  Xr = temp;
196  }
197 
198  temp = Xl;
199  Xl = Xr;
200  Xr = temp;
201  Xr = Xr ^ ctx->P[N];
202  Xl = Xl ^ ctx->P[N + 1];
203  *xl = Xl;
204  *xr = Xr;
205 }
unsigned int uInt32
Definition: blowfish.h:25
uInt32 P[16+2]
Definition: blowfish.h:40
#define N
Definition: blowfish.cc:9
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:163

◆ Blowfish_Init()

void Blowfish_Init ( BLOWFISH_CTX ctx,
unsigned char *  key,
int  keyLen 
)

Definition at line 235 of file blowfish.cc.

References Blowfish_Encrypt(), data, mps_fire::i, dqmiolumiharvest::j, dqmdumpme::k, crabWrapper::key, N, ORIG_P, ORIG_S, BLOWFISH_CTX::P, and BLOWFISH_CTX::S.

Referenced by cond::auth::Cipher::Cipher().

235  {
236  int i, j, k;
237  uInt32 data, datal, datar;
238 
239  for (i = 0; i < 4; i++) {
240  for (j = 0; j < 256; j++)
241  ctx->S[i][j] = ORIG_S[i][j];
242  }
243 
244  j = 0;
245 
246  for (i = 0; i < N + 2; ++i) {
247  data = 0x00000000;
248 
249  for (k = 0; k < 4; ++k) {
250  data = (data << 8) | key[j];
251  j = j + 1;
252  if (j >= keyLen)
253  j = 0;
254  }
255 
256  ctx->P[i] = ORIG_P[i] ^ data;
257  }
258 
259  datal = 0x00000000;
260  datar = 0x00000000;
261 
262  for (i = 0; i < N + 2; i += 2) {
263  Blowfish_Encrypt(ctx, &datal, &datar);
264  ctx->P[i] = datal;
265  ctx->P[i + 1] = datar;
266  }
267 
268  for (i = 0; i < 4; ++i) {
269  for (j = 0; j < 256; j += 2) {
270  Blowfish_Encrypt(ctx, &datal, &datar);
271  ctx->S[i][j] = datal;
272  ctx->S[i][j + 1] = datar;
273  }
274  }
275 }
void Blowfish_Encrypt(BLOWFISH_CTX *ctx, uInt32 *xl, uInt32 *xr)
Definition: blowfish.cc:181
uInt32 S[4][256]
Definition: blowfish.h:41
static const uInt32 ORIG_S[4][256]
Definition: blowfish.cc:31
unsigned int uInt32
Definition: blowfish.h:25
uInt32 P[16+2]
Definition: blowfish.h:40
static const uInt32 ORIG_P[16+2]
Definition: blowfish.cc:12
#define N
Definition: blowfish.cc:9
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80