CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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

#define DECRYPT   1

Definition at line 21 of file blowfish.h.

#define ENCRYPT   0

Definition at line 20 of file blowfish.h.

#define endianBig   ((unsigned char) 0x45)

Definition at line 23 of file blowfish.h.

#define endianLittle   ((unsigned char) 0x54)

Definition at line 24 of file blowfish.h.

#define INCLUDE_BLOWFISH_DEFINE_H

Definition at line 9 of file blowfish.h.

#define MAXKEYBYTES   56 /* 448 bits */

Definition at line 38 of file blowfish.h.

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

Definition at line 35 of file blowfish.h.

Typedef Documentation

typedef unsigned int uInt32

Definition at line 26 of file blowfish.h.

Function Documentation

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

Definition at line 326 of file blowfish.cc.

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

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

327  {
328  uInt32 Xl;
329  uInt32 Xr;
330  uInt32 temp;
331  short i;
332 
333  Xl = *xl;
334  Xr = *xr;
335 
336  for (i = N + 1; i > 1; --i) {
337  Xl = Xl ^ ctx->P[i];
338  Xr = F(ctx, Xl) ^ Xr;
339  /* Exchange Xl and Xr */
340  temp = Xl;
341  Xl = Xr;
342  Xr = temp;
343  }
344 
345  /* Exchange Xl and Xr */
346  temp = Xl;
347  Xl = Xr;
348  Xr = temp;
349  Xr = Xr ^ ctx->P[1];
350  Xl = Xl ^ ctx->P[0];
351  *xl = Xl;
352  *xr = Xr;
353 }
int i
Definition: DBlmapReader.cc:9
unsigned int uInt32
Definition: blowfish.h:26
uInt32 P[16+2]
Definition: blowfish.h:41
#define N
Definition: blowfish.cc:9
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:281
void Blowfish_Encrypt ( BLOWFISH_CTX ctx,
uInt32 xl,
uInt32 xr 
)

Definition at line 299 of file blowfish.cc.

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

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

300  {
301  uInt32 Xl;
302  uInt32 Xr;
303  uInt32 temp;
304  short i;
305 
306  Xl = *xl;
307  Xr = *xr;
308 
309  for (i = 0; i < N; ++i) {
310  Xl = Xl ^ ctx->P[i];
311  Xr = F(ctx, Xl) ^ Xr;
312  temp = Xl;
313  Xl = Xr;
314  Xr = temp;
315  }
316 
317  temp = Xl;
318  Xl = Xr;
319  Xr = temp;
320  Xr = Xr ^ ctx->P[N];
321  Xl = Xl ^ ctx->P[N + 1];
322  *xl = Xl;
323  *xr = Xr;
324 }
int i
Definition: DBlmapReader.cc:9
unsigned int uInt32
Definition: blowfish.h:26
uInt32 P[16+2]
Definition: blowfish.h:41
#define N
Definition: blowfish.cc:9
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:281
void Blowfish_Init ( BLOWFISH_CTX ctx,
unsigned char *  key,
int  keyLen 
)

Definition at line 355 of file blowfish.cc.

References Blowfish_Encrypt(), AlCaHLTBitMon_QueryRunRegistry::data, i, j, relval_2017::k, N, ORIG_P, ORIG_S, BLOWFISH_CTX::P, and BLOWFISH_CTX::S.

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

355  {
356  int i, j, k;
357  uInt32 data, datal, datar;
358 
359  for (i = 0; i < 4; i++) {
360 
361  for (j = 0; j < 256; j++)
362  ctx->S[i][j] = ORIG_S[i][j];
363  }
364 
365  j = 0;
366 
367  for (i = 0; i < N + 2; ++i) {
368  data = 0x00000000;
369 
370  for (k = 0; k < 4; ++k) {
371  data = (data << 8) | key[j];
372  j = j + 1;
373  if (j >= keyLen)
374  j = 0;
375  }
376 
377  ctx->P[i] = ORIG_P[i] ^ data;
378  }
379 
380  datal = 0x00000000;
381  datar = 0x00000000;
382 
383  for (i = 0; i < N + 2; i += 2) {
384  Blowfish_Encrypt(ctx, &datal, &datar);
385  ctx->P[i] = datal;
386  ctx->P[i + 1] = datar;
387  }
388 
389  for (i = 0; i < 4; ++i) {
390 
391  for (j = 0; j < 256; j += 2) {
392  Blowfish_Encrypt(ctx, &datal, &datar);
393  ctx->S[i][j] = datal;
394  ctx->S[i][j + 1] = datar;
395  }
396  }
397 }
int i
Definition: DBlmapReader.cc:9
void Blowfish_Encrypt(BLOWFISH_CTX *ctx, uInt32 *xl, uInt32 *xr)
Definition: blowfish.cc:299
uInt32 S[4][256]
Definition: blowfish.h:42
static const uInt32 ORIG_S[4][256]
Definition: blowfish.cc:20
unsigned int uInt32
Definition: blowfish.h:26
uInt32 P[16+2]
Definition: blowfish.h:41
int j
Definition: DBlmapReader.cc:9
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
static const uInt32 ORIG_P[16+2]
Definition: blowfish.cc:12
#define N
Definition: blowfish.cc:9